@graffiti-garden/wrapper-synchronize 0.2.3 → 1.0.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/dist/esm/index.js CHANGED
@@ -1,22 +1,24 @@
1
- import { Graffiti } from "@graffiti-garden/api";
2
- import { Repeater } from "@repeaterjs/repeater";
3
1
  import {
4
- applyGraffitiPatch,
2
+ GraffitiErrorNotFound,
5
3
  compileGraffitiObjectSchema,
6
4
  isActorAllowedGraffitiObject,
7
5
  maskGraffitiObject,
8
6
  unpackObjectUrl
9
- } from "@graffiti-garden/implementation-local/utilities";
10
- class GraffitiSynchronize extends Graffiti {
7
+ } from "@graffiti-garden/api";
8
+ import { Repeater } from "@repeaterjs/repeater";
9
+ class GraffitiSynchronize {
11
10
  ajv_;
12
- applyPatch_;
13
11
  graffiti;
14
12
  callbacks = /* @__PURE__ */ new Set();
15
13
  options;
16
- channelStats;
17
14
  login;
18
15
  logout;
19
16
  sessionEvents;
17
+ postMedia;
18
+ getMedia;
19
+ deleteMedia;
20
+ actorToHandle;
21
+ handleToActor;
20
22
  get ajv() {
21
23
  if (!this.ajv_) {
22
24
  this.ajv_ = (async () => {
@@ -26,52 +28,42 @@ class GraffitiSynchronize extends Graffiti {
26
28
  }
27
29
  return this.ajv_;
28
30
  }
29
- get applyPatch() {
30
- if (!this.applyPatch_) {
31
- this.applyPatch_ = (async () => {
32
- const { applyPatch } = await import("fast-json-patch");
33
- return applyPatch;
34
- })();
35
- }
36
- return this.applyPatch_;
37
- }
38
31
  /**
39
32
  * Wraps a Graffiti API instance to provide the synchronize methods.
40
33
  * The GraffitiSyncrhonize class rather than the Graffiti class
41
34
  * must be used for all functions for the synchronize methods to work.
42
35
  */
43
36
  constructor(graffiti, options) {
44
- super();
45
37
  this.options = options ?? {};
46
38
  this.graffiti = graffiti;
47
- this.channelStats = graffiti.channelStats.bind(graffiti);
48
39
  this.login = graffiti.login.bind(graffiti);
49
40
  this.logout = graffiti.logout.bind(graffiti);
50
41
  this.sessionEvents = graffiti.sessionEvents;
42
+ this.postMedia = graffiti.postMedia.bind(graffiti);
43
+ this.getMedia = graffiti.getMedia.bind(graffiti);
44
+ this.deleteMedia = graffiti.deleteMedia.bind(graffiti);
45
+ this.actorToHandle = graffiti.actorToHandle.bind(graffiti);
46
+ this.handleToActor = graffiti.handleToActor.bind(graffiti);
51
47
  }
52
- synchronize(matchObject, channels, schema, session) {
53
- const seenUrls = /* @__PURE__ */ new Set();
48
+ synchronize(matchObject, channels, schema, session, seenUrls = /* @__PURE__ */ new Set()) {
54
49
  const repeater = new Repeater(
55
50
  async (push, stop) => {
56
51
  const validate = compileGraffitiObjectSchema(await this.ajv, schema);
57
- const callback = (oldObjectRaw, newObjectRaw) => {
58
- for (const objectRaw of [newObjectRaw, oldObjectRaw]) {
59
- if (objectRaw?.tombstone) {
60
- if (seenUrls.has(objectRaw.object.url)) {
61
- push(objectRaw);
62
- }
63
- } else if (objectRaw && matchObject(objectRaw.object) && (this.options.omniscient || isActorAllowedGraffitiObject(objectRaw.object, session))) {
64
- const object = JSON.parse(
65
- JSON.stringify(objectRaw.object)
66
- );
67
- if (!this.options.omniscient) {
68
- maskGraffitiObject(object, channels, session);
69
- }
70
- if (validate(object)) {
71
- push({ object });
72
- seenUrls.add(object.url);
73
- break;
74
- }
52
+ const callback = (objectUpdate) => {
53
+ if (objectUpdate?.tombstone) {
54
+ if (seenUrls.has(objectUpdate.object.url)) {
55
+ push(objectUpdate);
56
+ }
57
+ } else if (objectUpdate && matchObject(objectUpdate.object) && (this.options.omniscient || isActorAllowedGraffitiObject(objectUpdate.object, session))) {
58
+ const object = JSON.parse(
59
+ JSON.stringify(objectUpdate.object)
60
+ );
61
+ if (!this.options.omniscient) {
62
+ maskGraffitiObject(object, channels, session);
63
+ }
64
+ if (validate(object)) {
65
+ push({ object });
66
+ seenUrls.add(object.url);
75
67
  }
76
68
  }
77
69
  };
@@ -80,12 +72,14 @@ class GraffitiSynchronize extends Graffiti {
80
72
  this.callbacks.delete(callback);
81
73
  }
82
74
  );
83
- return repeater;
75
+ return (async function* () {
76
+ for await (const i of repeater) yield i;
77
+ })();
84
78
  }
85
79
  /**
86
80
  * This method has the same signature as {@link discover} but listens for
87
- * changes made via {@link put}, {@link patch}, and {@link delete} or
88
- * fetched from {@link get}, {@link discover}, and {@link recoverOrphans}
81
+ * changes made via {@link post} and {@link delete} or
82
+ * fetched from {@link get}, {@link discover}, and {@link continueDiscover}
89
83
  * and then streams appropriate changes to provide a responsive and
90
84
  * consistent user experience.
91
85
  *
@@ -93,10 +87,9 @@ class GraffitiSynchronize extends Graffiti {
93
87
  * and will not terminate unless the user calls the `return` method on the iterator
94
88
  * or `break`s out of the loop.
95
89
  *
96
- * @group Synchronize Methods
90
+ * @group 0 - Synchronize Methods
97
91
  */
98
- synchronizeDiscover(...args) {
99
- const [channels, schema, session] = args;
92
+ synchronizeDiscover(channels, schema, session) {
100
93
  function matchObject(object) {
101
94
  return object.channels.some((channel) => channels.includes(channel));
102
95
  }
@@ -104,43 +97,28 @@ class GraffitiSynchronize extends Graffiti {
104
97
  }
105
98
  /**
106
99
  * This method has the same signature as {@link get} but
107
- * listens for changes made via {@link put}, {@link patch}, and {@link delete} or
108
- * fetched from {@link get}, {@link discover}, and {@link recoverOrphans} and then
100
+ * listens for changes made via {@link post}, and {@link delete} or
101
+ * fetched from {@link get}, {@link discover}, and {@link continueDiscover} and then
109
102
  * streams appropriate changes to provide a responsive and consistent user experience.
110
103
  *
111
104
  * Unlike {@link get}, which returns a single result, this method continuously
112
105
  * listens for changes which are output as an asynchronous stream, similar
113
106
  * to {@link discover}.
114
107
  *
115
- * @group Synchronize Methods
108
+ * @group 0 - Synchronize Methods
116
109
  */
117
- synchronizeGet(...args) {
118
- const [objectUrl, schema, session] = args;
110
+ synchronizeGet(objectUrl, schema, session) {
119
111
  const url = unpackObjectUrl(objectUrl);
120
112
  function matchObject(object) {
121
113
  return object.url === url;
122
114
  }
123
- return this.synchronize(matchObject, [], schema, session);
124
- }
125
- /**
126
- * This method has the same signature as {@link recoverOrphans} but
127
- * listens for changes made via
128
- * {@link put}, {@link patch}, and {@link delete} or fetched from
129
- * {@link get}, {@link discover}, and {@link recoverOrphans} and then
130
- * streams appropriate changes to provide a responsive and consistent user experience.
131
- *
132
- * Unlike {@link recoverOrphans}, this method continuously listens for changes
133
- * and will not terminate unless the user calls the `return` method on the iterator
134
- * or `break`s out of the loop.
135
- *
136
- * @group Synchronize Methods
137
- */
138
- synchronizeRecoverOrphans(...args) {
139
- const [schema, session] = args;
140
- function matchObject(object) {
141
- return object.actor === session.actor && object.channels.length === 0;
142
- }
143
- return this.synchronize(matchObject, [], schema, session);
115
+ return this.synchronize(
116
+ matchObject,
117
+ [],
118
+ schema,
119
+ session,
120
+ /* @__PURE__ */ new Set([url])
121
+ );
144
122
  }
145
123
  /**
146
124
  * Streams changes made to *any* object in *any* channel
@@ -151,115 +129,92 @@ class GraffitiSynchronize extends Graffiti {
151
129
  *
152
130
  * Be careful using this method. Without additional filters it can
153
131
  * expose the user to content out of context.
132
+ *
133
+ * @group 0 - Synchronize Methods
154
134
  */
155
135
  synchronizeAll(schema, session) {
156
136
  return this.synchronize(() => true, [], schema, session);
157
137
  }
158
- async synchronizeDispatch(oldObject, newObject, waitForListeners = false) {
138
+ async synchronizeDispatch(objectUpdate, waitForListeners = false) {
159
139
  for (const callback of this.callbacks) {
160
- callback(oldObject, newObject);
140
+ callback(objectUpdate);
161
141
  }
162
142
  if (waitForListeners) {
163
143
  await new Promise((resolve) => setTimeout(resolve, 0));
164
144
  }
165
145
  }
166
146
  get = async (...args) => {
167
- const object = await this.graffiti.get(...args);
168
- this.synchronizeDispatch({ object });
147
+ try {
148
+ const object = await this.graffiti.get(...args);
149
+ this.synchronizeDispatch({ object });
150
+ return object;
151
+ } catch (error) {
152
+ if (error instanceof GraffitiErrorNotFound) {
153
+ this.synchronizeDispatch({
154
+ tombstone: true,
155
+ object: { url: unpackObjectUrl(args[0]) }
156
+ });
157
+ }
158
+ throw error;
159
+ }
160
+ };
161
+ post = async (...args) => {
162
+ const object = await this.graffiti.post(...args);
163
+ await this.synchronizeDispatch({ object }, true);
169
164
  return object;
170
165
  };
171
- put = async (...args) => {
172
- const oldObject = await this.graffiti.put(...args);
173
- const partialObject = args[0];
174
- const newObject = {
175
- ...oldObject,
176
- value: partialObject.value,
177
- channels: partialObject.channels,
178
- allowed: partialObject.allowed
166
+ delete = async (...args) => {
167
+ const update = {
168
+ tombstone: true,
169
+ object: { url: unpackObjectUrl(args[0]) }
179
170
  };
180
- await this.synchronizeDispatch(
181
- {
182
- tombstone: true,
183
- object: oldObject
184
- },
185
- {
186
- object: newObject
187
- },
188
- true
189
- );
190
- return oldObject;
191
- };
192
- patch = async (...args) => {
193
- const oldObject = await this.graffiti.patch(...args);
194
- const newObject = { ...oldObject };
195
- for (const prop of ["value", "channels", "allowed"]) {
196
- applyGraffitiPatch(await this.applyPatch, prop, args[0], newObject);
171
+ try {
172
+ const oldObject = await this.graffiti.delete(...args);
173
+ await this.synchronizeDispatch(update, true);
174
+ return oldObject;
175
+ } catch (error) {
176
+ if (error instanceof GraffitiErrorNotFound) {
177
+ await this.synchronizeDispatch(update, true);
178
+ }
179
+ throw error;
197
180
  }
198
- await this.synchronizeDispatch(
199
- {
200
- tombstone: true,
201
- object: oldObject
202
- },
203
- {
204
- object: newObject
205
- },
206
- true
207
- );
208
- return oldObject;
209
- };
210
- delete = async (...args) => {
211
- const oldObject = await this.graffiti.delete(...args);
212
- await this.synchronizeDispatch(
213
- {
214
- tombstone: true,
215
- object: oldObject
216
- },
217
- void 0,
218
- true
219
- );
220
- return oldObject;
221
181
  };
222
182
  objectStreamContinue(iterator) {
223
183
  const this_ = this;
224
- return async function* () {
184
+ return (async function* () {
225
185
  while (true) {
226
186
  const result = await iterator.next();
227
187
  if (result.done) {
228
188
  const { continue: continue_, cursor } = result.value;
229
189
  return {
230
- continue: () => this_.objectStreamContinue(continue_()),
190
+ continue: (session) => this_.objectStreamContinue(continue_(session)),
231
191
  cursor
232
192
  };
233
193
  }
234
194
  if (!result.value.error) {
235
- this_.synchronizeDispatch(
236
- result.value
237
- );
195
+ this_.synchronizeDispatch(result.value);
238
196
  }
239
197
  yield result.value;
240
198
  }
241
- }();
199
+ })();
242
200
  }
243
201
  objectStream(iterator) {
244
202
  const wrapped = this.objectStreamContinue(iterator);
245
- return async function* () {
203
+ return (async function* () {
246
204
  while (true) {
247
205
  const result = await wrapped.next();
248
206
  if (result.done) return result.value;
249
207
  if (result.value.error || !result.value.tombstone) yield result.value;
250
208
  }
251
- }();
209
+ })();
252
210
  }
253
211
  discover = (...args) => {
254
212
  const iterator = this.graffiti.discover(...args);
255
213
  return this.objectStream(iterator);
256
214
  };
257
- recoverOrphans = (...args) => {
258
- const iterator = this.graffiti.recoverOrphans(...args);
259
- return this.objectStream(iterator);
260
- };
261
- continueObjectStream = (...args) => {
262
- return this.graffiti.continueObjectStream(...args);
215
+ continueDiscover = (...args) => {
216
+ const iterator = this.graffiti.continueDiscover(...args);
217
+ return this.objectStreamContinue(iterator);
263
218
  };
264
219
  }
265
220
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["import type Ajv from \"ajv\";\nimport { Graffiti } from \"@graffiti-garden/api\";\nimport type {\n GraffitiSession,\n JSONSchema,\n GraffitiObjectStream,\n GraffitiObjectStreamContinueEntry,\n GraffitiObjectStreamContinue,\n GraffitiObject,\n} from \"@graffiti-garden/api\";\nimport type { GraffitiObjectBase } from \"@graffiti-garden/api\";\nimport { Repeater } from \"@repeaterjs/repeater\";\nimport type { applyPatch } from \"fast-json-patch\";\nimport {\n applyGraffitiPatch,\n compileGraffitiObjectSchema,\n isActorAllowedGraffitiObject,\n maskGraffitiObject,\n unpackObjectUrl,\n} from \"@graffiti-garden/implementation-local/utilities\";\nexport type * from \"@graffiti-garden/api\";\n\nexport type GraffitiSynchronizeCallback = (\n oldObject: GraffitiObjectStreamContinueEntry<{}>,\n newObject?: GraffitiObjectStreamContinueEntry<{}>,\n) => void;\n\nexport interface GraffitiSynchronizeOptions {\n /**\n * Allows synchronize to listen to all objects, not just those\n * that the session is allowed to see. This is useful to get a\n * global view of all Graffiti objects passsing through the system,\n * for example to build a client-side cache. Additional mechanisms\n * should be in place to ensure that users do not see objects or\n * properties they are not allowed to see.\n *\n * Default: `false`\n */\n omniscient?: boolean;\n}\n\n/**\n * Wraps the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * so that changes made or received in one part of an application\n * are automatically routed to other parts of the application.\n * This is an important tool for building responsive\n * and consistent user interfaces, and is built upon to make\n * the [Graffiti Vue Plugin](https://vue.graffiti.garden/variables/GraffitiPlugin.html)\n * and possibly other front-end libraries in the future.\n *\n * Specifically, it provides the following *synchronize*\n * methods for each of the following API methods:\n *\n * | API Method | Synchronize Method |\n * |------------|--------------------|\n * | {@link get} | {@link synchronizeGet} |\n * | {@link discover} | {@link synchronizeDiscover} |\n * | {@link recoverOrphans} | {@link synchronizeRecoverOrphans} |\n *\n * Whenever a change is made via {@link put}, {@link patch}, and {@link delete} or\n * received from {@link get}, {@link discover}, and {@link recoverOrphans},\n * those changes are forwarded to the appropriate synchronize method.\n * Each synchronize method returns an iterator that streams these changes\n * continually until the user calls `return` on the iterator or `break`s out of the loop,\n * allowing for live updates without additional polling.\n *\n * Example 1: Suppose a user publishes a post using {@link put}. If the feed\n * displaying that user's posts is using {@link synchronizeDiscover} to listen for changes,\n * then the user's new post will instantly appear in their feed, giving the UI a\n * responsive feel.\n *\n * Example 2: Suppose one of a user's friends changes their name. As soon as the\n * user's application receives one notice of that change (using {@link get}\n * or {@link discover}), then {@link synchronizeDiscover} listeners can be used to update\n * all instance's of that friend's name in the user's application instantly,\n * providing a consistent user experience.\n *\n * @groupDescription Synchronize Methods\n * This group contains methods that listen for changes made via\n * {@link put}, {@link patch}, and {@link delete} or fetched from\n * {@link get}, {@link discover}, and {@link recoverOrphans} and then\n * streams appropriate changes to provide a responsive and consistent user experience.\n */\nexport class GraffitiSynchronize extends Graffiti {\n protected ajv_: Promise<Ajv> | undefined;\n protected applyPatch_: Promise<typeof applyPatch> | undefined;\n protected readonly graffiti: Graffiti;\n protected readonly callbacks = new Set<GraffitiSynchronizeCallback>();\n protected readonly options: GraffitiSynchronizeOptions;\n\n channelStats: Graffiti[\"channelStats\"];\n login: Graffiti[\"login\"];\n logout: Graffiti[\"logout\"];\n sessionEvents: Graffiti[\"sessionEvents\"];\n\n get ajv() {\n if (!this.ajv_) {\n this.ajv_ = (async () => {\n const { default: Ajv } = await import(\"ajv\");\n return new Ajv({ strict: false });\n })();\n }\n return this.ajv_;\n }\n\n 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 /**\n * Wraps a Graffiti API instance to provide the synchronize methods.\n * The GraffitiSyncrhonize class rather than the Graffiti class\n * must be used for all functions for the synchronize methods to work.\n */\n constructor(\n /**\n * The [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * instance to wrap.\n */\n graffiti: Graffiti,\n options?: GraffitiSynchronizeOptions,\n ) {\n super();\n this.options = options ?? {};\n this.graffiti = graffiti;\n this.channelStats = graffiti.channelStats.bind(graffiti);\n this.login = graffiti.login.bind(graffiti);\n this.logout = graffiti.logout.bind(graffiti);\n this.sessionEvents = graffiti.sessionEvents;\n }\n\n protected synchronize<Schema extends JSONSchema>(\n matchObject: (object: GraffitiObjectBase) => boolean,\n channels: string[],\n schema: Schema,\n session?: GraffitiSession | null,\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n const seenUrls = new Set<string>();\n\n const repeater = new Repeater<GraffitiObjectStreamContinueEntry<Schema>>(\n async (push, stop) => {\n const validate = compileGraffitiObjectSchema(await this.ajv, schema);\n const callback: GraffitiSynchronizeCallback = (\n oldObjectRaw,\n newObjectRaw,\n ) => {\n for (const objectRaw of [newObjectRaw, oldObjectRaw]) {\n if (objectRaw?.tombstone) {\n if (seenUrls.has(objectRaw.object.url)) {\n push(objectRaw);\n }\n } else if (\n objectRaw &&\n matchObject(objectRaw.object) &&\n (this.options.omniscient ||\n isActorAllowedGraffitiObject(objectRaw.object, session))\n ) {\n // Deep clone the object to prevent mutation\n const object = JSON.parse(\n JSON.stringify(objectRaw.object),\n ) as GraffitiObject<{}>;\n if (!this.options.omniscient) {\n maskGraffitiObject(object, channels, session);\n }\n if (validate(object)) {\n push({ object });\n seenUrls.add(object.url);\n break;\n }\n }\n }\n };\n\n this.callbacks.add(callback);\n await stop;\n this.callbacks.delete(callback);\n },\n );\n\n return repeater;\n }\n\n /**\n * This method has the same signature as {@link discover} but listens for\n * changes made via {@link put}, {@link patch}, and {@link delete} or\n * fetched from {@link get}, {@link discover}, and {@link recoverOrphans}\n * and then streams appropriate changes to provide a responsive and\n * consistent user experience.\n *\n * Unlike {@link discover}, this method continuously listens for changes\n * and will not terminate unless the user calls the `return` method on the iterator\n * or `break`s out of the loop.\n *\n * @group Synchronize Methods\n */\n synchronizeDiscover<Schema extends JSONSchema>(\n ...args: Parameters<typeof Graffiti.prototype.discover<Schema>>\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n const [channels, schema, session] = args;\n function matchObject(object: GraffitiObjectBase) {\n return object.channels.some((channel) => channels.includes(channel));\n }\n return this.synchronize<Schema>(matchObject, channels, schema, session);\n }\n\n /**\n * This method has the same signature as {@link get} but\n * listens for changes made via {@link put}, {@link patch}, and {@link delete} or\n * fetched from {@link get}, {@link discover}, and {@link recoverOrphans} and then\n * streams appropriate changes to provide a responsive and consistent user experience.\n *\n * Unlike {@link get}, which returns a single result, this method continuously\n * listens for changes which are output as an asynchronous stream, similar\n * to {@link discover}.\n *\n * @group Synchronize Methods\n */\n synchronizeGet<Schema extends JSONSchema>(\n ...args: Parameters<typeof Graffiti.prototype.get<Schema>>\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n const [objectUrl, schema, session] = args;\n const url = unpackObjectUrl(objectUrl);\n function matchObject(object: GraffitiObjectBase) {\n return object.url === url;\n }\n return this.synchronize<Schema>(matchObject, [], schema, session);\n }\n\n /**\n * This method has the same signature as {@link recoverOrphans} but\n * listens for changes made via\n * {@link put}, {@link patch}, and {@link delete} or fetched from\n * {@link get}, {@link discover}, and {@link recoverOrphans} and then\n * streams appropriate changes to provide a responsive and consistent user experience.\n *\n * Unlike {@link recoverOrphans}, this method continuously listens for changes\n * and will not terminate unless the user calls the `return` method on the iterator\n * or `break`s out of the loop.\n *\n * @group Synchronize Methods\n */\n synchronizeRecoverOrphans<Schema extends JSONSchema>(\n ...args: Parameters<typeof Graffiti.prototype.recoverOrphans<Schema>>\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n const [schema, session] = args;\n function matchObject(object: GraffitiObjectBase) {\n return object.actor === session.actor && object.channels.length === 0;\n }\n return this.synchronize<Schema>(matchObject, [], schema, session);\n }\n\n /**\n * Streams changes made to *any* object in *any* channel\n * and made by *any* user. You may want to use it in conjuction with\n * {@link GraffitiSynchronizeOptions.omniscient} to get a global view\n * of all Graffiti objects passing through the system. This is useful\n * for building a client-side cache, for example.\n *\n * Be careful using this method. Without additional filters it can\n * expose the user to content out of context.\n */\n synchronizeAll<Schema extends JSONSchema>(\n schema: Schema,\n session?: GraffitiSession | null,\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n return this.synchronize<Schema>(() => true, [], schema, session);\n }\n\n protected async synchronizeDispatch(\n oldObject: GraffitiObjectStreamContinueEntry<{}>,\n newObject?: GraffitiObjectStreamContinueEntry<{}>,\n waitForListeners = false,\n ) {\n for (const callback of this.callbacks) {\n callback(oldObject, newObject);\n }\n if (waitForListeners) {\n // Wait for the listeners to receive\n // their objects, before returning the operation\n // that triggered them.\n //\n // This is important for mutators (put, patch, delete)\n // to ensure the application state has been updated\n // everywhere before returning, giving consistent\n // feedback to the user that the operation has completed.\n //\n // The opposite is true for accessors (get, discover, recoverOrphans),\n // where it is a weird user experience to call `get`\n // in one place and have the application update\n // somewhere else first. It is also less efficient.\n //\n // The hack is simply to await one \"macro task cycle\".\n // We need to wait for this cycle rather than using\n // `await push` in the callback, because it turns out\n // that `await push` won't resolve until the following\n // .next() call of the iterator, so if only\n // one .next() is called, this dispatch will hang.\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n }\n\n get: Graffiti[\"get\"] = async (...args) => {\n const object = await this.graffiti.get(...args);\n this.synchronizeDispatch({ object });\n return object;\n };\n\n put: Graffiti[\"put\"] = async (...args) => {\n const oldObject = await this.graffiti.put<{}>(...args);\n const partialObject = args[0];\n const newObject: GraffitiObjectBase = {\n ...oldObject,\n value: partialObject.value,\n channels: partialObject.channels,\n allowed: partialObject.allowed,\n };\n await this.synchronizeDispatch(\n {\n tombstone: true,\n object: oldObject,\n },\n {\n object: newObject,\n },\n true,\n );\n return oldObject;\n };\n\n patch: Graffiti[\"patch\"] = async (...args) => {\n const oldObject = await this.graffiti.patch(...args);\n const newObject: GraffitiObjectBase = { ...oldObject };\n for (const prop of [\"value\", \"channels\", \"allowed\"] as const) {\n applyGraffitiPatch(await this.applyPatch, prop, args[0], newObject);\n }\n await this.synchronizeDispatch(\n {\n tombstone: true,\n object: oldObject,\n },\n {\n object: newObject,\n },\n true,\n );\n return oldObject;\n };\n\n delete: Graffiti[\"delete\"] = async (...args) => {\n const oldObject = await this.graffiti.delete(...args);\n await this.synchronizeDispatch(\n {\n tombstone: true,\n object: oldObject,\n },\n undefined,\n true,\n );\n return oldObject;\n };\n\n protected objectStreamContinue<Schema extends JSONSchema>(\n iterator: GraffitiObjectStreamContinue<Schema>,\n ): GraffitiObjectStreamContinue<Schema> {\n const this_ = this;\n return (async function* () {\n while (true) {\n const result = await iterator.next();\n if (result.done) {\n const { continue: continue_, cursor } = result.value;\n return {\n continue: () => this_.objectStreamContinue<Schema>(continue_()),\n cursor,\n };\n }\n if (!result.value.error) {\n this_.synchronizeDispatch(\n result.value as GraffitiObjectStreamContinueEntry<{}>,\n );\n }\n yield result.value;\n }\n })();\n }\n\n protected objectStream<Schema extends JSONSchema>(\n iterator: GraffitiObjectStream<Schema>,\n ): GraffitiObjectStream<Schema> {\n const wrapped = this.objectStreamContinue<Schema>(iterator);\n return (async function* () {\n // Filter out the tombstones for type safety\n while (true) {\n const result = await wrapped.next();\n if (result.done) return result.value;\n if (result.value.error || !result.value.tombstone) yield result.value;\n }\n })();\n }\n\n discover: Graffiti[\"discover\"] = (...args) => {\n const iterator = this.graffiti.discover(...args);\n return this.objectStream<(typeof args)[1]>(iterator);\n };\n\n recoverOrphans: Graffiti[\"recoverOrphans\"] = (...args) => {\n const iterator = this.graffiti.recoverOrphans(...args);\n return this.objectStream<(typeof args)[0]>(iterator);\n };\n\n continueObjectStream: Graffiti[\"continueObjectStream\"] = (...args) => {\n // TODO!!\n return this.graffiti.continueObjectStream(...args);\n };\n}\n"],
5
- "mappings": "AACA,SAAS,gBAAgB;AAUzB,SAAS,gBAAgB;AAEzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAgEA,MAAM,4BAA4B,SAAS;AAAA,EACtC;AAAA,EACA;AAAA,EACS;AAAA,EACA,YAAY,oBAAI,IAAiC;AAAA,EACjD;AAAA,EAEnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,IAAI,MAAM;AACR,QAAI,CAAC,KAAK,MAAM;AACd,WAAK,QAAQ,YAAY;AACvB,cAAM,EAAE,SAAS,IAAI,IAAI,MAAM,OAAO,KAAK;AAC3C,eAAO,IAAI,IAAI,EAAE,QAAQ,MAAM,CAAC;AAAA,MAClC,GAAG;AAAA,IACL;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,aAAa;AACf,QAAI,CAAC,KAAK,aAAa;AACrB,WAAK,eAAe,YAAY;AAC9B,cAAM,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AA,MACA;AAAA,MACA;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEU,qBACR,UACsC;AACtC,UAAM,QAAQ;AACd,WAAQ,mBAAmB;AACzB,aAAO,MAAM;AACX,cAAM,SAAS,MAAM,SAAS,KAAK;AACnC,YAAI,OAAO,MAAM;AACf,gBAAM,EAAE,UAAU,WAAW,OAAO,IAAI,OAAO;AAC/C,iBAAO;AAAA,YACL,UAAU,MAAM,MAAM,qBAA6B,UAAU,CAAC;AAAA,YAC9D;AAAA,UACF;AAAA,QACF;AACA,YAAI,CAAC,OAAO,MAAM,OAAO;AACvB,gBAAM;AAAA,YACJ,OAAO;AAAA,UACT;AAAA,QACF;AACA,cAAM,OAAO;AAAA,MACf;AAAA,IACF,EAAG;AAAA,EACL;AAAA,EAEU,aACR,UAC8B;AAC9B,UAAM,UAAU,KAAK,qBAA6B,QAAQ;AAC1D,WAAQ,mBAAmB;AAEzB,aAAO,MAAM;AACX,cAAM,SAAS,MAAM,QAAQ,KAAK;AAClC,YAAI,OAAO,KAAM,QAAO,OAAO;AAC/B,YAAI,OAAO,MAAM,SAAS,CAAC,OAAO,MAAM,UAAW,OAAM,OAAO;AAAA,MAClE;AAAA,IACF,EAAG;AAAA,EACL;AAAA,EAEA,WAAiC,IAAI,SAAS;AAC5C,UAAM,WAAW,KAAK,SAAS,SAAS,GAAG,IAAI;AAC/C,WAAO,KAAK,aAA+B,QAAQ;AAAA,EACrD;AAAA,EAEA,iBAA6C,IAAI,SAAS;AACxD,UAAM,WAAW,KAAK,SAAS,eAAe,GAAG,IAAI;AACrD,WAAO,KAAK,aAA+B,QAAQ;AAAA,EACrD;AAAA,EAEA,uBAAyD,IAAI,SAAS;AAEpE,WAAO,KAAK,SAAS,qBAAqB,GAAG,IAAI;AAAA,EACnD;AACF;",
4
+ "sourcesContent": ["import type Ajv from \"ajv\";\nimport type {\n Graffiti,\n GraffitiSession,\n JSONSchema,\n GraffitiObjectBase,\n GraffitiObjectStream,\n GraffitiObjectStreamContinueEntry,\n GraffitiObjectStreamContinue,\n GraffitiObjectUrl,\n} from \"@graffiti-garden/api\";\nimport {\n GraffitiErrorNotFound,\n compileGraffitiObjectSchema,\n isActorAllowedGraffitiObject,\n maskGraffitiObject,\n unpackObjectUrl,\n} from \"@graffiti-garden/api\";\nimport { Repeater } from \"@repeaterjs/repeater\";\nexport type * from \"@graffiti-garden/api\";\n\nexport type GraffitiSynchronizeCallback = (\n object: GraffitiObjectStreamContinueEntry<{}>,\n) => void;\n\nexport interface GraffitiSynchronizeOptions {\n /**\n * Allows synchronize to listen to all objects, not just those\n * that the session is allowed to see. This is useful to get a\n * global view of all Graffiti objects passsing through the system,\n * for example to build a client-side cache. Additional mechanisms\n * should be in place to ensure that users do not see objects or\n * properties they are not allowed to see.\n *\n * Default: `false`\n */\n omniscient?: boolean;\n}\n\n/**\n * Wraps the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * so that changes made or received in one part of an application\n * are automatically routed to other parts of the application.\n * This is an important tool for building responsive\n * and consistent user interfaces, and is built upon to make\n * the [Graffiti Vue Plugin](https://vue.graffiti.garden/variables/GraffitiPlugin.html)\n * and possibly other front-end libraries in the future.\n *\n * [See a live example](/example).\n *\n * Specifically, this library provides the following *synchronize*\n * methods to correspond with each of the following Graffiti API methods:\n *\n * | API Method | Synchronize Method |\n * |------------|--------------------|\n * | {@link get} | {@link synchronizeGet} |\n * | {@link discover} | {@link synchronizeDiscover} |\n *\n * Whenever a change is made via {@link post} and {@link delete} or\n * received from {@link get}, {@link discover}, and {@link continueDiscover},\n * those changes are forwarded to the appropriate synchronize method.\n * Each synchronize method returns an iterator that streams these changes\n * continually until the user calls `return` on the iterator or `break`s out of the loop,\n * allowing for live updates without additional polling.\n *\n * Example 1: Suppose a user publishes a post using {@link post}. If the feed\n * displaying that user's posts is using {@link synchronizeDiscover} to listen for changes,\n * then the user's new post will instantly appear in their feed, giving the UI a\n * responsive feel.\n *\n * Example 2: Suppose one of a user's friends changes their name. As soon as the\n * user's application receives one notice of that change (using {@link get}\n * or {@link discover}), then {@link synchronizeDiscover} listeners can be used to update\n * all instance's of that friend's name in the user's application instantly,\n * providing a consistent user experience.\n *\n * Additionally, the library supplies a {@link synchronizeAll} method that can be used\n * to stream all the Graffiti changes that an application is aware of, which can be used\n * for caching or history building.\n *\n * The source code for this library is [available on GitHub](https://github.com/graffiti-garden/wrapper-synchronize/).\n *\n * @groupDescription 0 - Synchronize Methods\n * This group contains methods that listen for changes made via\n * {@link post}, and {@link delete} or fetched from\n * {@link get}, {@link discover}, or {@link continueDiscover} and then\n * streams appropriate changes to provide a responsive and consistent user experience.\n */\nexport class GraffitiSynchronize implements Graffiti {\n protected ajv_: Promise<Ajv> | undefined;\n protected readonly graffiti: Graffiti;\n protected readonly callbacks = new Set<GraffitiSynchronizeCallback>();\n protected readonly options: GraffitiSynchronizeOptions;\n\n login: Graffiti[\"login\"];\n logout: Graffiti[\"logout\"];\n sessionEvents: Graffiti[\"sessionEvents\"];\n postMedia: Graffiti[\"postMedia\"];\n getMedia: Graffiti[\"getMedia\"];\n deleteMedia: Graffiti[\"deleteMedia\"];\n actorToHandle: Graffiti[\"actorToHandle\"];\n handleToActor: Graffiti[\"handleToActor\"];\n\n protected get ajv() {\n if (!this.ajv_) {\n this.ajv_ = (async () => {\n const { default: Ajv } = await import(\"ajv\");\n return new Ajv({ strict: false });\n })();\n }\n return this.ajv_;\n }\n\n /**\n * Wraps a Graffiti API instance to provide the synchronize methods.\n * The GraffitiSyncrhonize class rather than the Graffiti class\n * must be used for all functions for the synchronize methods to work.\n */\n constructor(\n /**\n * The [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * instance to wrap.\n */\n graffiti: Graffiti,\n options?: GraffitiSynchronizeOptions,\n ) {\n this.options = options ?? {};\n this.graffiti = graffiti;\n this.login = graffiti.login.bind(graffiti);\n this.logout = graffiti.logout.bind(graffiti);\n this.sessionEvents = graffiti.sessionEvents;\n this.postMedia = graffiti.postMedia.bind(graffiti);\n this.getMedia = graffiti.getMedia.bind(graffiti);\n this.deleteMedia = graffiti.deleteMedia.bind(graffiti);\n this.actorToHandle = graffiti.actorToHandle.bind(graffiti);\n this.handleToActor = graffiti.handleToActor.bind(graffiti);\n }\n\n protected synchronize<Schema extends JSONSchema>(\n matchObject: (object: GraffitiObjectBase) => boolean,\n channels: string[],\n schema: Schema,\n session?: GraffitiSession | null,\n seenUrls: Set<string> = new Set<string>(),\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n const repeater = new Repeater<GraffitiObjectStreamContinueEntry<Schema>>(\n async (push, stop) => {\n const validate = compileGraffitiObjectSchema(await this.ajv, schema);\n const callback: GraffitiSynchronizeCallback = (objectUpdate) => {\n if (objectUpdate?.tombstone) {\n if (seenUrls.has(objectUpdate.object.url)) {\n push(objectUpdate);\n }\n } else if (\n objectUpdate &&\n matchObject(objectUpdate.object) &&\n (this.options.omniscient ||\n isActorAllowedGraffitiObject(objectUpdate.object, session))\n ) {\n // Deep clone the object to prevent mutation\n const object = JSON.parse(\n JSON.stringify(objectUpdate.object),\n ) as GraffitiObjectBase;\n if (!this.options.omniscient) {\n maskGraffitiObject(object, channels, session);\n }\n if (validate(object)) {\n push({ object });\n seenUrls.add(object.url);\n }\n }\n };\n\n this.callbacks.add(callback);\n await stop;\n this.callbacks.delete(callback);\n },\n );\n\n return (async function* () {\n for await (const i of repeater) yield i;\n })();\n }\n\n /**\n * This method has the same signature as {@link discover} but listens for\n * changes made via {@link post} and {@link delete} or\n * fetched from {@link get}, {@link discover}, and {@link continueDiscover}\n * and then streams appropriate changes to provide a responsive and\n * consistent user experience.\n *\n * Unlike {@link discover}, this method continuously listens for changes\n * and will not terminate unless the user calls the `return` method on the iterator\n * or `break`s out of the loop.\n *\n * @group 0 - Synchronize Methods\n */\n synchronizeDiscover<Schema extends JSONSchema>(\n channels: string[],\n schema: Schema,\n session?: GraffitiSession | null,\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n function matchObject(object: GraffitiObjectBase) {\n return object.channels.some((channel) => channels.includes(channel));\n }\n return this.synchronize<Schema>(matchObject, channels, schema, session);\n }\n\n /**\n * This method has the same signature as {@link get} but\n * listens for changes made via {@link post}, and {@link delete} or\n * fetched from {@link get}, {@link discover}, and {@link continueDiscover} and then\n * streams appropriate changes to provide a responsive and consistent user experience.\n *\n * Unlike {@link get}, which returns a single result, this method continuously\n * listens for changes which are output as an asynchronous stream, similar\n * to {@link discover}.\n *\n * @group 0 - Synchronize Methods\n */\n synchronizeGet<Schema extends JSONSchema>(\n objectUrl: string | GraffitiObjectUrl,\n schema: Schema,\n session?: GraffitiSession | null | undefined,\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n const url = unpackObjectUrl(objectUrl);\n function matchObject(object: GraffitiObjectBase) {\n return object.url === url;\n }\n return this.synchronize<Schema>(\n matchObject,\n [],\n schema,\n session,\n new Set<string>([url]),\n );\n }\n\n /**\n * Streams changes made to *any* object in *any* channel\n * and made by *any* user. You may want to use it in conjuction with\n * {@link GraffitiSynchronizeOptions.omniscient} to get a global view\n * of all Graffiti objects passing through the system. This is useful\n * for building a client-side cache, for example.\n *\n * Be careful using this method. Without additional filters it can\n * expose the user to content out of context.\n *\n * @group 0 - Synchronize Methods\n */\n synchronizeAll<Schema extends JSONSchema>(\n schema: Schema,\n session?: GraffitiSession | null,\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n return this.synchronize<Schema>(() => true, [], schema, session);\n }\n\n protected async synchronizeDispatch(\n objectUpdate: GraffitiObjectStreamContinueEntry<{}>,\n waitForListeners = false,\n ) {\n for (const callback of this.callbacks) {\n callback(objectUpdate);\n }\n if (waitForListeners) {\n // Wait for the listeners to receive\n // their objects, before returning the operation\n // that triggered them.\n //\n // This is important for mutators (put, patch, delete)\n // to ensure the application state has been updated\n // everywhere before returning, giving consistent\n // feedback to the user that the operation has completed.\n //\n // The opposite is true for accessors (get, discover, recoverOrphans),\n // where it is a weird user experience to call `get`\n // in one place and have the application update\n // somewhere else first. It is also less efficient.\n //\n // The hack is simply to await one \"macro task cycle\".\n // We need to wait for this cycle rather than using\n // `await push` in the callback, because it turns out\n // that `await push` won't resolve until the following\n // .next() call of the iterator, so if only\n // one .next() is called, this dispatch will hang.\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n }\n\n get: Graffiti[\"get\"] = async (...args) => {\n try {\n const object = await this.graffiti.get(...args);\n this.synchronizeDispatch({ object });\n return object;\n } catch (error) {\n if (error instanceof GraffitiErrorNotFound) {\n this.synchronizeDispatch({\n tombstone: true,\n object: { url: unpackObjectUrl(args[0]) },\n });\n }\n throw error;\n }\n };\n\n post: Graffiti[\"post\"] = async (...args) => {\n // @ts-ignore\n const object = await this.graffiti.post(...args);\n await this.synchronizeDispatch({ object }, true);\n return object;\n };\n\n delete: Graffiti[\"delete\"] = async (...args) => {\n const update = {\n tombstone: true,\n object: { url: unpackObjectUrl(args[0]) },\n } as const;\n try {\n const oldObject = await this.graffiti.delete(...args);\n await this.synchronizeDispatch(update, true);\n return oldObject;\n } catch (error) {\n if (error instanceof GraffitiErrorNotFound) {\n await this.synchronizeDispatch(update, true);\n }\n throw error;\n }\n };\n\n protected objectStreamContinue<Schema extends JSONSchema>(\n iterator: GraffitiObjectStreamContinue<Schema>,\n ): GraffitiObjectStreamContinue<Schema> {\n const this_ = this;\n return (async function* () {\n while (true) {\n const result = await iterator.next();\n if (result.done) {\n const { continue: continue_, cursor } = result.value;\n return {\n continue: (session?: GraffitiSession | null) =>\n this_.objectStreamContinue<Schema>(continue_(session)),\n cursor,\n };\n }\n if (!result.value.error) {\n this_.synchronizeDispatch(result.value);\n }\n yield result.value;\n }\n })();\n }\n\n protected objectStream<Schema extends JSONSchema>(\n iterator: GraffitiObjectStream<Schema>,\n ): GraffitiObjectStream<Schema> {\n const wrapped = this.objectStreamContinue<Schema>(iterator);\n return (async function* () {\n // Filter out the tombstones for type safety\n while (true) {\n const result = await wrapped.next();\n if (result.done) return result.value;\n if (result.value.error || !result.value.tombstone) yield result.value;\n }\n })();\n }\n\n discover: Graffiti[\"discover\"] = (...args) => {\n const iterator = this.graffiti.discover(...args);\n return this.objectStream<(typeof args)[1]>(iterator);\n };\n\n continueDiscover: Graffiti[\"continueDiscover\"] = (...args) => {\n const iterator = this.graffiti.continueDiscover(...args);\n return this.objectStreamContinue<{}>(iterator);\n };\n}\n"],
5
+ "mappings": "AAWA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AAsElB,MAAM,oBAAwC;AAAA,EACzC;AAAA,EACS;AAAA,EACA,YAAY,oBAAI,IAAiC;AAAA,EACjD;AAAA,EAEnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,IAAc,MAAM;AAClB,QAAI,CAAC,KAAK,MAAM;AACd,WAAK,QAAQ,YAAY;AACvB,cAAM,EAAE,SAAS,IAAI,IAAI,MAAM,OAAO,KAAK;AAC3C,eAAO,IAAI,IAAI,EAAE,QAAQ,MAAM,CAAC;AAAA,MAClC,GAAG;AAAA,IACL;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAKE,UACA,SACA;AACA,SAAK,UAAU,WAAW,CAAC;AAC3B,SAAK,WAAW;AAChB,SAAK,QAAQ,SAAS,MAAM,KAAK,QAAQ;AACzC,SAAK,SAAS,SAAS,OAAO,KAAK,QAAQ;AAC3C,SAAK,gBAAgB,SAAS;AAC9B,SAAK,YAAY,SAAS,UAAU,KAAK,QAAQ;AACjD,SAAK,WAAW,SAAS,SAAS,KAAK,QAAQ;AAC/C,SAAK,cAAc,SAAS,YAAY,KAAK,QAAQ;AACrD,SAAK,gBAAgB,SAAS,cAAc,KAAK,QAAQ;AACzD,SAAK,gBAAgB,SAAS,cAAc,KAAK,QAAQ;AAAA,EAC3D;AA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AK,SAAS,iBAAiB,GAAG,IAAI;AACvD,WAAO,KAAK,qBAAyB,QAAQ;AAAA,EAC/C;AACF;",
6
6
  "names": []
7
7
  }
package/dist/index.d.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  import type Ajv from "ajv";
2
- import { Graffiti } from "@graffiti-garden/api";
3
- import type { GraffitiSession, JSONSchema, GraffitiObjectStream, GraffitiObjectStreamContinueEntry, GraffitiObjectStreamContinue } from "@graffiti-garden/api";
4
- import type { GraffitiObjectBase } from "@graffiti-garden/api";
5
- import type { applyPatch } from "fast-json-patch";
2
+ import type { Graffiti, GraffitiSession, JSONSchema, GraffitiObjectBase, GraffitiObjectStream, GraffitiObjectStreamContinueEntry, GraffitiObjectStreamContinue, GraffitiObjectUrl } from "@graffiti-garden/api";
6
3
  export type * from "@graffiti-garden/api";
7
- export type GraffitiSynchronizeCallback = (oldObject: GraffitiObjectStreamContinueEntry<{}>, newObject?: GraffitiObjectStreamContinueEntry<{}>) => void;
4
+ export type GraffitiSynchronizeCallback = (object: GraffitiObjectStreamContinueEntry<{}>) => void;
8
5
  export interface GraffitiSynchronizeOptions {
9
6
  /**
10
7
  * Allows synchronize to listen to all objects, not just those
@@ -27,23 +24,24 @@ export interface GraffitiSynchronizeOptions {
27
24
  * the [Graffiti Vue Plugin](https://vue.graffiti.garden/variables/GraffitiPlugin.html)
28
25
  * and possibly other front-end libraries in the future.
29
26
  *
30
- * Specifically, it provides the following *synchronize*
31
- * methods for each of the following API methods:
27
+ * [See a live example](/example).
28
+ *
29
+ * Specifically, this library provides the following *synchronize*
30
+ * methods to correspond with each of the following Graffiti API methods:
32
31
  *
33
32
  * | API Method | Synchronize Method |
34
33
  * |------------|--------------------|
35
34
  * | {@link get} | {@link synchronizeGet} |
36
35
  * | {@link discover} | {@link synchronizeDiscover} |
37
- * | {@link recoverOrphans} | {@link synchronizeRecoverOrphans} |
38
36
  *
39
- * Whenever a change is made via {@link put}, {@link patch}, and {@link delete} or
40
- * received from {@link get}, {@link discover}, and {@link recoverOrphans},
37
+ * Whenever a change is made via {@link post} and {@link delete} or
38
+ * received from {@link get}, {@link discover}, and {@link continueDiscover},
41
39
  * those changes are forwarded to the appropriate synchronize method.
42
40
  * Each synchronize method returns an iterator that streams these changes
43
41
  * continually until the user calls `return` on the iterator or `break`s out of the loop,
44
42
  * allowing for live updates without additional polling.
45
43
  *
46
- * Example 1: Suppose a user publishes a post using {@link put}. If the feed
44
+ * Example 1: Suppose a user publishes a post using {@link post}. If the feed
47
45
  * displaying that user's posts is using {@link synchronizeDiscover} to listen for changes,
48
46
  * then the user's new post will instantly appear in their feed, giving the UI a
49
47
  * responsive feel.
@@ -54,24 +52,32 @@ export interface GraffitiSynchronizeOptions {
54
52
  * all instance's of that friend's name in the user's application instantly,
55
53
  * providing a consistent user experience.
56
54
  *
57
- * @groupDescription Synchronize Methods
55
+ * Additionally, the library supplies a {@link synchronizeAll} method that can be used
56
+ * to stream all the Graffiti changes that an application is aware of, which can be used
57
+ * for caching or history building.
58
+ *
59
+ * The source code for this library is [available on GitHub](https://github.com/graffiti-garden/wrapper-synchronize/).
60
+ *
61
+ * @groupDescription 0 - Synchronize Methods
58
62
  * This group contains methods that listen for changes made via
59
- * {@link put}, {@link patch}, and {@link delete} or fetched from
60
- * {@link get}, {@link discover}, and {@link recoverOrphans} and then
63
+ * {@link post}, and {@link delete} or fetched from
64
+ * {@link get}, {@link discover}, or {@link continueDiscover} and then
61
65
  * streams appropriate changes to provide a responsive and consistent user experience.
62
66
  */
63
- export declare class GraffitiSynchronize extends Graffiti {
67
+ export declare class GraffitiSynchronize implements Graffiti {
64
68
  protected ajv_: Promise<Ajv> | undefined;
65
- protected applyPatch_: Promise<typeof applyPatch> | undefined;
66
69
  protected readonly graffiti: Graffiti;
67
70
  protected readonly callbacks: Set<GraffitiSynchronizeCallback>;
68
71
  protected readonly options: GraffitiSynchronizeOptions;
69
- channelStats: Graffiti["channelStats"];
70
72
  login: Graffiti["login"];
71
73
  logout: Graffiti["logout"];
72
74
  sessionEvents: Graffiti["sessionEvents"];
73
- get ajv(): Promise<Ajv>;
74
- get applyPatch(): Promise<typeof applyPatch>;
75
+ postMedia: Graffiti["postMedia"];
76
+ getMedia: Graffiti["getMedia"];
77
+ deleteMedia: Graffiti["deleteMedia"];
78
+ actorToHandle: Graffiti["actorToHandle"];
79
+ handleToActor: Graffiti["handleToActor"];
80
+ protected get ajv(): Promise<Ajv>;
75
81
  /**
76
82
  * Wraps a Graffiti API instance to provide the synchronize methods.
77
83
  * The GraffitiSyncrhonize class rather than the Graffiti class
@@ -83,11 +89,11 @@ export declare class GraffitiSynchronize extends Graffiti {
83
89
  * instance to wrap.
84
90
  */
85
91
  graffiti: Graffiti, options?: GraffitiSynchronizeOptions);
86
- protected synchronize<Schema extends JSONSchema>(matchObject: (object: GraffitiObjectBase) => boolean, channels: string[], schema: Schema, session?: GraffitiSession | null): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>;
92
+ protected synchronize<Schema extends JSONSchema>(matchObject: (object: GraffitiObjectBase) => boolean, channels: string[], schema: Schema, session?: GraffitiSession | null, seenUrls?: Set<string>): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>;
87
93
  /**
88
94
  * This method has the same signature as {@link discover} but listens for
89
- * changes made via {@link put}, {@link patch}, and {@link delete} or
90
- * fetched from {@link get}, {@link discover}, and {@link recoverOrphans}
95
+ * changes made via {@link post} and {@link delete} or
96
+ * fetched from {@link get}, {@link discover}, and {@link continueDiscover}
91
97
  * and then streams appropriate changes to provide a responsive and
92
98
  * consistent user experience.
93
99
  *
@@ -95,36 +101,22 @@ export declare class GraffitiSynchronize extends Graffiti {
95
101
  * and will not terminate unless the user calls the `return` method on the iterator
96
102
  * or `break`s out of the loop.
97
103
  *
98
- * @group Synchronize Methods
104
+ * @group 0 - Synchronize Methods
99
105
  */
100
- synchronizeDiscover<Schema extends JSONSchema>(...args: Parameters<typeof Graffiti.prototype.discover<Schema>>): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>;
106
+ synchronizeDiscover<Schema extends JSONSchema>(channels: string[], schema: Schema, session?: GraffitiSession | null): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>;
101
107
  /**
102
108
  * This method has the same signature as {@link get} but
103
- * listens for changes made via {@link put}, {@link patch}, and {@link delete} or
104
- * fetched from {@link get}, {@link discover}, and {@link recoverOrphans} and then
109
+ * listens for changes made via {@link post}, and {@link delete} or
110
+ * fetched from {@link get}, {@link discover}, and {@link continueDiscover} and then
105
111
  * streams appropriate changes to provide a responsive and consistent user experience.
106
112
  *
107
113
  * Unlike {@link get}, which returns a single result, this method continuously
108
114
  * listens for changes which are output as an asynchronous stream, similar
109
115
  * to {@link discover}.
110
116
  *
111
- * @group Synchronize Methods
117
+ * @group 0 - Synchronize Methods
112
118
  */
113
- synchronizeGet<Schema extends JSONSchema>(...args: Parameters<typeof Graffiti.prototype.get<Schema>>): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>;
114
- /**
115
- * This method has the same signature as {@link recoverOrphans} but
116
- * listens for changes made via
117
- * {@link put}, {@link patch}, and {@link delete} or fetched from
118
- * {@link get}, {@link discover}, and {@link recoverOrphans} and then
119
- * streams appropriate changes to provide a responsive and consistent user experience.
120
- *
121
- * Unlike {@link recoverOrphans}, this method continuously listens for changes
122
- * and will not terminate unless the user calls the `return` method on the iterator
123
- * or `break`s out of the loop.
124
- *
125
- * @group Synchronize Methods
126
- */
127
- synchronizeRecoverOrphans<Schema extends JSONSchema>(...args: Parameters<typeof Graffiti.prototype.recoverOrphans<Schema>>): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>;
119
+ synchronizeGet<Schema extends JSONSchema>(objectUrl: string | GraffitiObjectUrl, schema: Schema, session?: GraffitiSession | null | undefined): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>;
128
120
  /**
129
121
  * Streams changes made to *any* object in *any* channel
130
122
  * and made by *any* user. You may want to use it in conjuction with
@@ -134,17 +126,17 @@ export declare class GraffitiSynchronize extends Graffiti {
134
126
  *
135
127
  * Be careful using this method. Without additional filters it can
136
128
  * expose the user to content out of context.
129
+ *
130
+ * @group 0 - Synchronize Methods
137
131
  */
138
132
  synchronizeAll<Schema extends JSONSchema>(schema: Schema, session?: GraffitiSession | null): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>;
139
- protected synchronizeDispatch(oldObject: GraffitiObjectStreamContinueEntry<{}>, newObject?: GraffitiObjectStreamContinueEntry<{}>, waitForListeners?: boolean): Promise<void>;
133
+ protected synchronizeDispatch(objectUpdate: GraffitiObjectStreamContinueEntry<{}>, waitForListeners?: boolean): Promise<void>;
140
134
  get: Graffiti["get"];
141
- put: Graffiti["put"];
142
- patch: Graffiti["patch"];
135
+ post: Graffiti["post"];
143
136
  delete: Graffiti["delete"];
144
137
  protected objectStreamContinue<Schema extends JSONSchema>(iterator: GraffitiObjectStreamContinue<Schema>): GraffitiObjectStreamContinue<Schema>;
145
138
  protected objectStream<Schema extends JSONSchema>(iterator: GraffitiObjectStream<Schema>): GraffitiObjectStream<Schema>;
146
139
  discover: Graffiti["discover"];
147
- recoverOrphans: Graffiti["recoverOrphans"];
148
- continueObjectStream: Graffiti["continueObjectStream"];
140
+ continueDiscover: Graffiti["continueDiscover"];
149
141
  }
150
142
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,iCAAiC,EACjC,4BAA4B,EAE7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAQlD,mB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