@graffy/core 0.16.20-alpha.3 → 0.16.20-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/types/index.d.ts +18 -8
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graffy/core",
3
3
  "description": "The main module for Graffy, a library for intuitive real-time data APIs.",
4
4
  "author": "aravind (https://github.com/aravindet)",
5
- "version": "0.16.20-alpha.3",
5
+ "version": "0.16.20-alpha.4",
6
6
  "main": "./index.cjs",
7
7
  "exports": {
8
8
  "import": "./index.mjs",
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "license": "Apache-2.0",
18
18
  "dependencies": {
19
- "@graffy/common": "0.16.20-alpha.3",
20
- "@graffy/stream": "0.16.20-alpha.3",
19
+ "@graffy/common": "0.16.20-alpha.4",
20
+ "@graffy/stream": "0.16.20-alpha.4",
21
21
  "debug": "^4.3.7"
22
22
  }
23
23
  }
package/types/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export type AnyLeaf = string | number | boolean | null;
2
+
1
3
  // biome-ignore lint/suspicious/noExplicitAny: This is used to match concrete types in "extends" expressions.
2
4
  export type AnyObject = Record<string, any>;
3
5
 
@@ -35,6 +37,10 @@ export default class Graffy<S> {
35
37
  watch: AnyFunction;
36
38
  }
37
39
 
40
+ // TODO: To avoid the "too deep" error, these need to be tail-recursive.
41
+ // This may be possible with an "accummulator" type parameter.
42
+ // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#tail-recursion-elimination-on-conditional-types
43
+
38
44
  export type PathOf<S> = S extends GraffyCollection<AnyObject>
39
45
  ? Key
40
46
  : S extends AnyObject
@@ -53,19 +59,23 @@ export type Descend<S, P> = P extends [Key]
53
59
  ? Descend<Get<S, P[0]>, R>
54
60
  : Get<S, P>;
55
61
 
56
- export type Project<S> = S extends GraffyCollection<AnyObject>
57
- ?
58
- | (Project<S[string]> & { $key: Key })
59
- | (Project<S[string]> & { $key: Key })[]
60
- : S extends AnyObject
61
- ? Partial<{ [K in keyof S]: Project<S[K]> }>
62
- : boolean;
62
+ export type Project<S> = S extends AnyLeaf
63
+ ? boolean
64
+ : S extends GraffyCollection<AnyObject>
65
+ ?
66
+ | (Project<S[string]> & { $key: Key })
67
+ | (Project<S[string]> & { $key: Key })[]
68
+ : S extends AnyObject
69
+ ? Partial<{ [K in keyof S]: Project<S[K]> }> | boolean
70
+ : never;
63
71
 
64
72
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
65
73
  type ResultArray<R> = R[] & { $page: any; $next: any; $prev: any };
66
74
 
67
75
  type ReadResult<S, Q> = S extends GraffyCollection<AnyObject>
68
- ? (S[string] & { $key: Key }) | ResultArray<S[string] & { $key: Key }>
76
+ ? Q extends Array<AnyObject> | { $key: Key }
77
+ ? ResultArray<S[string] & { $key: Key }>
78
+ : S[string] & { $key: Key }
69
79
  : S extends AnyObject
70
80
  ? { [K in keyof S & keyof Q]: ReadResult<S[K], Q[K]> }
71
81
  : S;