@graffiti-garden/implementation-local 0.5.1 → 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.
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Graffiti } from "@graffiti-garden/api";
1
+ import { Graffiti, type GraffitiSession } from "@graffiti-garden/api";
2
2
  import { GraffitiLocalSessionManager } from "./session-manager.js";
3
3
  import {
4
4
  GraffitiLocalDatabase,
@@ -27,6 +27,7 @@ export class GraffitiLocal extends Graffiti {
27
27
  discover: Graffiti["discover"];
28
28
  recoverOrphans: Graffiti["recoverOrphans"];
29
29
  channelStats: Graffiti["channelStats"];
30
+ continueObjectStream: Graffiti["continueObjectStream"];
30
31
 
31
32
  constructor(options?: GraffitiLocalOptions) {
32
33
  super();
@@ -42,5 +43,20 @@ export class GraffitiLocal extends Graffiti {
42
43
  graffitiPouchDbBase.recoverOrphans.bind(graffitiPouchDbBase);
43
44
  this.channelStats =
44
45
  graffitiPouchDbBase.channelStats.bind(graffitiPouchDbBase);
46
+ this.continueObjectStream =
47
+ graffitiPouchDbBase.continueObjectStream.bind(graffitiPouchDbBase);
45
48
  }
46
49
  }
50
+
51
+ function myFunction<T extends boolean>(
52
+ flag: T,
53
+ ): T extends true ? string : number {
54
+ if (!flag) {
55
+ return "Hello" as T extends true ? string : number;
56
+ } else {
57
+ return 42 as T extends true ? string : number;
58
+ }
59
+ }
60
+ // Usage
61
+ const a = myFunction(false); // Type is number
62
+ const b = myFunction(true); // Type is string
package/src/utilities.ts CHANGED
@@ -15,8 +15,8 @@ import type {
15
15
  import type { Ajv } from "ajv";
16
16
  import type { applyPatch } from "fast-json-patch";
17
17
 
18
- export function unpackLocationOrUri(locationOrUri: GraffitiObjectUrl | string) {
19
- return typeof locationOrUri === "string" ? locationOrUri : locationOrUri.url;
18
+ export function unpackObjectUrl(url: string | GraffitiObjectUrl) {
19
+ return typeof url === "string" ? url : url.url;
20
20
  }
21
21
 
22
22
  export function randomBase64(numBytes: number = 24) {
@@ -28,18 +28,6 @@ export function randomBase64(numBytes: number = 24) {
28
28
  return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/\=+$/, "");
29
29
  }
30
30
 
31
- export function isObjectNewer(
32
- left: GraffitiObjectBase,
33
- right: GraffitiObjectBase,
34
- ) {
35
- return (
36
- left.lastModified > right.lastModified ||
37
- (left.lastModified === right.lastModified &&
38
- !left.tombstone &&
39
- right.tombstone)
40
- );
41
- }
42
-
43
31
  export function applyGraffitiPatch<Prop extends keyof GraffitiPatch>(
44
32
  apply: typeof applyPatch,
45
33
  prop: Prop,