@graffiti-garden/implementation-local 0.6.0 → 0.6.1

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.
@@ -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_;
@@ -373,64 +373,63 @@ class GraffitiLocalDatabase {
373
373
  endKeySuffix
374
374
  };
375
375
  }
376
- discoverMeta(channels, schema, session, ifModifiedSince) {
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 showTombstones = ifModifiedSince !== void 0;
382
- const repeater = (
383
- // @ts-ignore
384
- new Repeater(async (push, stop) => {
385
- const validate = compileGraffitiObjectSchema(await this.ajv, schema);
386
- const processedIds = /* @__PURE__ */ new Set();
387
- for (const channel of channels) {
388
- const keyPrefix = encodeURIComponent(channel) + "/";
389
- const startkey = keyPrefix + startKeySuffix;
390
- const endkey = keyPrefix + endKeySuffix;
391
- const result = await (await this.db).query(
392
- "indexes/objectsPerChannelAndLastModified",
393
- { startkey, endkey, include_docs: true }
394
- );
395
- for (const row of result.rows) {
396
- const doc = row.doc;
397
- if (!doc) continue;
398
- if (!showTombstones && doc.tombstone) continue;
399
- const object = this.extractGraffitiObject(doc);
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
- discover = (...args) => {
431
- return this.discoverMeta(...args);
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,86 @@ class GraffitiLocalDatabase {
438
437
  const keyPrefix = encodeURIComponent(session.actor) + "/";
439
438
  const startkey = keyPrefix + startKeySuffix;
440
439
  const endkey = keyPrefix + endKeySuffix;
441
- const showTombstones = ifModifiedSince !== void 0;
442
- const repeater = (
443
- // @ts-ignore
444
- new Repeater(async (push, stop) => {
445
- const validate = compileGraffitiObjectSchema(await this.ajv, schema);
446
- const result = await (await this.db).query(
447
- "indexes/orphansPerActorAndLastModified",
448
- {
449
- startkey,
450
- endkey,
451
- include_docs: true
452
- }
453
- );
454
- for (const row of result.rows) {
455
- const doc = row.doc;
456
- if (!doc) continue;
457
- if (!showTombstones && doc.tombstone) continue;
458
- if (!ifModifiedSince || doc.lastModified > ifModifiedSince) {
459
- ifModifiedSince = doc.lastModified;
460
- }
461
- const object = this.extractGraffitiObject(doc);
462
- if (validate(object)) {
463
- await push({
464
- value: object,
465
- ...doc.tombstone ? { tombstone: true } : {}
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
+ async *discoverContinue(args, ifModifiedSince) {
454
+ const iterator = this.discoverMeta(args, ifModifiedSince);
455
+ while (true) {
456
+ const result = await iterator.next();
457
+ if (result.done) {
458
+ const ifModifiedSince2 = result.value;
459
+ return {
460
+ continue: () => this.discoverContinue(args, ifModifiedSince2),
461
+ cursor: ""
462
+ };
463
+ }
464
+ yield result.value;
465
+ }
466
+ }
467
+ discover = (...args) => {
468
+ const iterator = this.discoverMeta(args);
469
+ const this_ = this;
470
+ return async function* () {
471
+ while (true) {
472
+ const result = await iterator.next();
473
+ if (result.done) {
474
+ return {
475
+ continue: () => this_.discoverContinue(args, result.value),
476
+ cursor: ""
477
+ };
468
478
  }
469
- stop();
470
- const cursor = "recover-orphans:" + JSON.stringify({
471
- schema,
472
- actor: session.actor,
473
- ifModifiedSince
474
- });
479
+ if (result.value.tombstone) continue;
480
+ yield result.value;
481
+ }
482
+ }();
483
+ };
484
+ async *recoverContinue(args, ifModifiedSince) {
485
+ const iterator = this.recoverOrphansMeta(args, ifModifiedSince);
486
+ while (true) {
487
+ const result = await iterator.next();
488
+ if (result.done) {
489
+ const ifModifiedSince2 = result.value;
475
490
  return {
476
- cursor,
477
- continue: () => this.continueStream(cursor, session)
491
+ continue: () => this.recoverContinue(args, ifModifiedSince2),
492
+ cursor: ""
478
493
  };
479
- })
480
- );
481
- return repeater;
494
+ }
495
+ yield result.value;
496
+ }
482
497
  }
483
498
  recoverOrphans = (...args) => {
484
- return this.recoverOrphansMeta(...args);
499
+ const iterator = this.recoverOrphansMeta(args);
500
+ const this_ = this;
501
+ return async function* () {
502
+ while (true) {
503
+ const result = await iterator.next();
504
+ if (result.done) {
505
+ return {
506
+ continue: () => this_.recoverContinue(args, result.value),
507
+ cursor: ""
508
+ };
509
+ }
510
+ if (result.value.tombstone) continue;
511
+ yield result.value;
512
+ }
513
+ }();
485
514
  };
486
515
  channelStats = (session) => {
487
- const repeater = new Repeater(async (push, stop) => {
516
+ const this_ = this;
517
+ return async function* () {
488
518
  const keyPrefix = encodeURIComponent(session.actor) + "/";
489
- const result = await (await this.db).query("indexes/channelStatsPerActor", {
519
+ const result = await (await this_.db).query("indexes/channelStatsPerActor", {
490
520
  startkey: keyPrefix,
491
521
  endkey: keyPrefix + "\uFFFF",
492
522
  reduce: true,
@@ -498,57 +528,18 @@ class GraffitiLocalDatabase {
498
528
  const { count, max: lastModified } = row.value;
499
529
  if (typeof count !== "number" || typeof lastModified !== "number")
500
530
  continue;
501
- await push({
531
+ yield {
502
532
  value: {
503
533
  channel: decodeURIComponent(channelEncoded),
504
534
  count,
505
535
  lastModified
506
536
  }
507
- });
537
+ };
508
538
  }
509
- stop();
510
- const cursor = "channel-stats";
511
- return {
512
- cursor,
513
- continue: () => this.continueStream(
514
- cursor,
515
- session
516
- )
517
- };
518
- });
519
- return repeater;
539
+ }();
520
540
  };
521
- continueStream = (cursor, session) => {
522
- if (cursor === "channel-stats") {
523
- if (!session) {
524
- throw new GraffitiErrorForbidden(
525
- "You must be logged in to continue the stream"
526
- );
527
- }
528
- return this.channelStats(session);
529
- } else if (cursor.startsWith("recover-orphans:")) {
530
- const { schema, actor, ifModifiedSince } = JSON.parse(
531
- cursor.slice("recover-orphans:".length)
532
- );
533
- if (!session || session.actor !== actor) {
534
- throw new GraffitiErrorForbidden(
535
- "You must be logged in as the actor same actor who started the stream"
536
- );
537
- }
538
- return this.recoverOrphansMeta(schema, session, ifModifiedSince);
539
- } else if (cursor.startsWith("discover:")) {
540
- const { channels, schema, actor, ifModifiedSince } = JSON.parse(
541
- cursor.slice("discover:".length)
542
- );
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
- } else {
550
- throw new GraffitiErrorNotFound("Cursor not found");
551
- }
541
+ continueObjectStream = (cursor, session) => {
542
+ throw new GraffitiErrorNotFound("Cursor not found");
552
543
  };
553
544
  }
554
545
  export {
@@ -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,IAAI;AAAA,UACb,eAAe;AAAA,UACf;AAAA,QACF;AACA,cAAM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AAA,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 { 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 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 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: \"\",\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: \"\",\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 async *recoverContinue<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: () => this.recoverContinue<Schema>(args, ifModifiedSince),\n cursor: \"\",\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_.recoverContinue<(typeof args)[0]>(args, result.value),\n cursor: \"\",\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 // TODO: Implement this\n throw new GraffitiErrorNotFound(\"Cursor not found\");\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,uBAAuB;AAQtB,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,IAAI;AAAA,UACb,eAAe;AAAA,UACf;AAAA,QACF;AACA,cAAM,GAEH,IAAI;AAAA,UACH,KAAK;AAAA,UACL,OAAO;AAAA,YACL,kCAAkC;AAAA,cAChC,KAAK,SAAU,QAAqC;AAClD,sBAAM,qBAAqB,OAAO,aAC/B,SAAS,EACT,SAAS,IAAI,GAAG;AACnB,uBAAO,SAAS,QAAQ,SAAU,SAAS;AACzC,wBAAM,KACJ,mBAAmB,OAAO,IAAI,MAAM;AAEtC,uBAAK,EAAE;AAAA,gBACT,CAAC;AAAA,cACH,EAAE,SAAS;AAAA,YACb;AAAA,YACA,gCAAgC;AAAA,cAC9B,KAAK,SAAU,QAAqC;AAClD,oBAAI,OAAO,SAAS,WAAW,GAAG;AAChC,wBAAM,qBAAqB,OAAO,aAC/B,SAAS,EACT,SAAS,IAAI,GAAG;AACnB,wBAAM,KACJ,mBAAmB,OAAO,KAAK,IAC/B,MACA;AAEF,uBAAK,EAAE;AAAA,gBACT;AAAA,cACF,EAAE,SAAS;AAAA,YACb;AAAA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,MAAM,SAAS,KAAK;AACnC,YAAI,OAAO,MAAM;AACf,iBAAO;AAAA,YACL,UAAU,MACR,MAAM,gBAAkC,MAAM,OAAO,KAAK;AAAA,YAC5D,QAAQ;AAAA,UACV;AAAA,QACF;AAEA,YAAI,OAAO,MAAM,UAAW;AAC5B,cAAM,OAAO;AAAA,MACf;AAAA,IACF,EAAG;AAAA,EACL;AAAA,EAEA,eAAyC,CAAC,YAAY;AACpD,UAAM,QAAQ;AACd,WAAQ,mBAAmB;AACzB,YAAM,YAAY,mBAAmB,QAAQ,KAAK,IAAI;AACtD,YAAM,SAAS,OACb,MAAM,MAAM,IACZ,MAAM,gCAAgC;AAAA,QACtC,UAAU;AAAA,QACV,QAAQ,YAAY;AAAA,QACpB,QAAQ;AAAA,QACR,OAAO;AAAA,MACT,CAAC;AACD,iBAAW,OAAO,OAAO,MAAM;AAC7B,cAAM,iBAAiB,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC;AAC3C,YAAI,OAAO,mBAAmB,SAAU;AACxC,cAAM,EAAE,OAAO,KAAK,aAAa,IAAI,IAAI;AACzC,YAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB;AACvD;AACF,cAAM;AAAA,UACJ,OAAO;AAAA,YACL,SAAS,mBAAmB,cAAc;AAAA,YAC1C;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,EAAG;AAAA,EACL;AAAA,EAEA,uBAAyD,CACvD,QACA,YACG;AAEH,UAAM,IAAI,sBAAsB,kBAAkB;AAAA,EACpD;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
- continueStream;
18
+ continueObjectStream;
19
19
  constructor(options) {
20
20
  super();
21
21
  const graffitiPouchDbBase = new GraffitiLocalDatabase(options);
@@ -26,9 +26,18 @@ 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.continueStream = graffitiPouchDbBase.continueStream.bind(graffitiPouchDbBase);
29
+ this.continueObjectStream = graffitiPouchDbBase.continueObjectStream.bind(graffitiPouchDbBase);
30
30
  }
31
31
  }
32
+ function myFunction(flag) {
33
+ if (!flag) {
34
+ return "Hello";
35
+ } else {
36
+ return 42;
37
+ }
38
+ }
39
+ const a = myFunction(false);
40
+ const b = myFunction(true);
32
41
  export {
33
42
  GraffitiLocal
34
43
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["import { Graffiti, type GraffitiSession } from \"@graffiti-garden/api\";\nimport { GraffitiLocalSessionManager } from \"./session-manager.js\";\nimport {\n GraffitiLocalDatabase,\n type GraffitiLocalOptions,\n} from \"./database.js\";\n\nexport type { GraffitiLocalOptions };\n\n/**\n * A local implementation of the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * based on [PouchDB](https://pouchdb.com/). PouchDb will automatically persist data in a local\n * database, either in the browser or in Node.js.\n * It can also be configured to work with an external [CouchDB](https://couchdb.apache.org/) server,\n * although using it with a remote server will not be secure.\n */\nexport class GraffitiLocal extends Graffiti {\n protected sessionManagerLocal = new GraffitiLocalSessionManager();\n login = this.sessionManagerLocal.login.bind(this.sessionManagerLocal);\n logout = this.sessionManagerLocal.logout.bind(this.sessionManagerLocal);\n sessionEvents = this.sessionManagerLocal.sessionEvents;\n\n put: Graffiti[\"put\"];\n get: Graffiti[\"get\"];\n patch: Graffiti[\"patch\"];\n delete: Graffiti[\"delete\"];\n discover: Graffiti[\"discover\"];\n recoverOrphans: Graffiti[\"recoverOrphans\"];\n channelStats: Graffiti[\"channelStats\"];\n continueStream: Graffiti[\"continueStream\"];\n\n constructor(options?: GraffitiLocalOptions) {\n super();\n\n const graffitiPouchDbBase = new GraffitiLocalDatabase(options);\n\n this.put = graffitiPouchDbBase.put.bind(graffitiPouchDbBase);\n this.get = graffitiPouchDbBase.get.bind(graffitiPouchDbBase);\n this.patch = graffitiPouchDbBase.patch.bind(graffitiPouchDbBase);\n this.delete = graffitiPouchDbBase.delete.bind(graffitiPouchDbBase);\n this.discover = graffitiPouchDbBase.discover.bind(graffitiPouchDbBase);\n this.recoverOrphans =\n graffitiPouchDbBase.recoverOrphans.bind(graffitiPouchDbBase);\n this.channelStats =\n graffitiPouchDbBase.channelStats.bind(graffitiPouchDbBase);\n this.continueStream =\n graffitiPouchDbBase.continueStream.bind(graffitiPouchDbBase);\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,gBAAsC;AAC/C,SAAS,mCAAmC;AAC5C;AAAA,EACE;AAAA,OAEK;AAWA,MAAM,sBAAsB,SAAS;AAAA,EAChC,sBAAsB,IAAI,4BAA4B;AAAA,EAChE,QAAQ,KAAK,oBAAoB,MAAM,KAAK,KAAK,mBAAmB;AAAA,EACpE,SAAS,KAAK,oBAAoB,OAAO,KAAK,KAAK,mBAAmB;AAAA,EACtE,gBAAgB,KAAK,oBAAoB;AAAA,EAEzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,SAAgC;AAC1C,UAAM;AAEN,UAAM,sBAAsB,IAAI,sBAAsB,OAAO;AAE7D,SAAK,MAAM,oBAAoB,IAAI,KAAK,mBAAmB;AAC3D,SAAK,MAAM,oBAAoB,IAAI,KAAK,mBAAmB;AAC3D,SAAK,QAAQ,oBAAoB,MAAM,KAAK,mBAAmB;AAC/D,SAAK,SAAS,oBAAoB,OAAO,KAAK,mBAAmB;AACjE,SAAK,WAAW,oBAAoB,SAAS,KAAK,mBAAmB;AACrE,SAAK,iBACH,oBAAoB,eAAe,KAAK,mBAAmB;AAC7D,SAAK,eACH,oBAAoB,aAAa,KAAK,mBAAmB;AAC3D,SAAK,iBACH,oBAAoB,eAAe,KAAK,mBAAmB;AAAA,EAC/D;AACF;",
4
+ "sourcesContent": ["import { Graffiti, type GraffitiSession } from \"@graffiti-garden/api\";\nimport { GraffitiLocalSessionManager } from \"./session-manager.js\";\nimport {\n GraffitiLocalDatabase,\n type GraffitiLocalOptions,\n} from \"./database.js\";\n\nexport type { GraffitiLocalOptions };\n\n/**\n * A local implementation of the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * based on [PouchDB](https://pouchdb.com/). PouchDb will automatically persist data in a local\n * database, either in the browser or in Node.js.\n * It can also be configured to work with an external [CouchDB](https://couchdb.apache.org/) server,\n * although using it with a remote server will not be secure.\n */\nexport class GraffitiLocal extends Graffiti {\n protected sessionManagerLocal = new GraffitiLocalSessionManager();\n login = this.sessionManagerLocal.login.bind(this.sessionManagerLocal);\n logout = this.sessionManagerLocal.logout.bind(this.sessionManagerLocal);\n sessionEvents = this.sessionManagerLocal.sessionEvents;\n\n put: Graffiti[\"put\"];\n get: Graffiti[\"get\"];\n patch: Graffiti[\"patch\"];\n delete: Graffiti[\"delete\"];\n discover: Graffiti[\"discover\"];\n recoverOrphans: Graffiti[\"recoverOrphans\"];\n channelStats: Graffiti[\"channelStats\"];\n continueObjectStream: Graffiti[\"continueObjectStream\"];\n\n constructor(options?: GraffitiLocalOptions) {\n super();\n\n const graffitiPouchDbBase = new GraffitiLocalDatabase(options);\n\n this.put = graffitiPouchDbBase.put.bind(graffitiPouchDbBase);\n this.get = graffitiPouchDbBase.get.bind(graffitiPouchDbBase);\n this.patch = graffitiPouchDbBase.patch.bind(graffitiPouchDbBase);\n this.delete = graffitiPouchDbBase.delete.bind(graffitiPouchDbBase);\n this.discover = graffitiPouchDbBase.discover.bind(graffitiPouchDbBase);\n this.recoverOrphans =\n graffitiPouchDbBase.recoverOrphans.bind(graffitiPouchDbBase);\n this.channelStats =\n graffitiPouchDbBase.channelStats.bind(graffitiPouchDbBase);\n this.continueObjectStream =\n graffitiPouchDbBase.continueObjectStream.bind(graffitiPouchDbBase);\n }\n}\n\nfunction myFunction<T extends boolean>(\n flag: T,\n): T extends true ? string : number {\n if (!flag) {\n return \"Hello\" as T extends true ? string : number;\n } else {\n return 42 as T extends true ? string : number;\n }\n}\n// Usage\nconst a = myFunction(false); // Type is number\nconst b = myFunction(true); // Type is string\n"],
5
+ "mappings": "AAAA,SAAS,gBAAsC;AAC/C,SAAS,mCAAmC;AAC5C;AAAA,EACE;AAAA,OAEK;AAWA,MAAM,sBAAsB,SAAS;AAAA,EAChC,sBAAsB,IAAI,4BAA4B;AAAA,EAChE,QAAQ,KAAK,oBAAoB,MAAM,KAAK,KAAK,mBAAmB;AAAA,EACpE,SAAS,KAAK,oBAAoB,OAAO,KAAK,KAAK,mBAAmB;AAAA,EACtE,gBAAgB,KAAK,oBAAoB;AAAA,EAEzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,SAAgC;AAC1C,UAAM;AAEN,UAAM,sBAAsB,IAAI,sBAAsB,OAAO;AAE7D,SAAK,MAAM,oBAAoB,IAAI,KAAK,mBAAmB;AAC3D,SAAK,MAAM,oBAAoB,IAAI,KAAK,mBAAmB;AAC3D,SAAK,QAAQ,oBAAoB,MAAM,KAAK,mBAAmB;AAC/D,SAAK,SAAS,oBAAoB,OAAO,KAAK,mBAAmB;AACjE,SAAK,WAAW,oBAAoB,SAAS,KAAK,mBAAmB;AACrE,SAAK,iBACH,oBAAoB,eAAe,KAAK,mBAAmB;AAC7D,SAAK,eACH,oBAAoB,aAAa,KAAK,mBAAmB;AAC3D,SAAK,uBACH,oBAAoB,qBAAqB,KAAK,mBAAmB;AAAA,EACrE;AACF;AAEA,SAAS,WACP,MACkC;AAClC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAEA,MAAM,IAAI,WAAW,KAAK;AAC1B,MAAM,IAAI,WAAW,IAAI;",
6
6
  "names": []
7
7
  }
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ export declare class GraffitiLocal extends Graffiti {
24
24
  discover: Graffiti["discover"];
25
25
  recoverOrphans: Graffiti["recoverOrphans"];
26
26
  channelStats: Graffiti["channelStats"];
27
- continueStream: Graffiti["continueStream"];
27
+ continueObjectStream: Graffiti["continueObjectStream"];
28
28
  constructor(options?: GraffitiLocalOptions);
29
29
  }
30
30
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAErC;;;;;;GAMG;AACH,qBAAa,aAAc,SAAQ,QAAQ;IACzC,SAAS,CAAC,mBAAmB,8BAAqC;IAClE,KAAK;aA+BkvsB,CAAC;aAA6iB,CAAC;wBA/BhutB;IACtE,MAAM,8CAAkE;IACxE,aAAa,cAA0C;IAEvD,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrB,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrB,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzB,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC3B,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC/B,cAAc,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC3C,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IACvC,cAAc,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;gBAE/B,OAAO,CAAC,EAAE,oBAAoB;CAiB3C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAErC;;;;;;GAMG;AACH,qBAAa,aAAc,SAAQ,QAAQ;IACzC,SAAS,CAAC,mBAAmB,8BAAqC;IAClE,KAAK;aA4Cy3sB,CAAC;aAA6iB,CAAC;wBA5Cv2tB;IACtE,MAAM,8CAAkE;IACxE,aAAa,cAA0C;IAEvD,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrB,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrB,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzB,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC3B,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC/B,cAAc,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC3C,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IACvC,oBAAoB,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC;gBAE3C,OAAO,CAAC,EAAE,oBAAoB;CAiB3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graffiti-garden/implementation-local",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "A local implementation of the Graffiti API using PouchDB",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -82,7 +82,6 @@
82
82
  },
83
83
  "dependencies": {
84
84
  "@graffiti-garden/api": "^0.6.0",
85
- "@repeaterjs/repeater": "^3.0.6",
86
85
  "@types/pouchdb": "^6.4.2",
87
86
  "ajv": "^8.17.1",
88
87
  "fast-json-patch": "^3.1.1",