@graffy/core 0.16.20-alpha.2 → 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 +50 -42
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.2",
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.2",
20
- "@graffy/stream": "0.16.20-alpha.2",
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,9 +1,15 @@
1
- export type JsonObject = Record<string, unknown>;
1
+ export type AnyLeaf = string | number | boolean | null;
2
2
 
3
- type Key = unknown;
3
+ // biome-ignore lint/suspicious/noExplicitAny: This is used to match concrete types in "extends" expressions.
4
+ export type AnyObject = Record<string, any>;
4
5
 
5
- // biome-ignore lint/suspicious/noExplicitAny: "Unknown" prevents assigning a concrete type to this parameter.
6
- export type GraffyCollection<CollectionSchema extends Record<string, any>> = {
6
+ // biome-ignore lint/suspicious/noExplicitAny: Function for which types are not yet defined.
7
+ type AnyFunction = (...args: any[]) => any;
8
+
9
+ // biome-ignore lint/suspicious/noExplicitAny: Keys can be anything.
10
+ type Key = any;
11
+
12
+ export type GraffyCollection<CollectionSchema extends AnyObject> = {
7
13
  [name: string]: CollectionSchema;
8
14
  } & { __brand: 'GraffyCollection' };
9
15
 
@@ -21,55 +27,57 @@ export default class Graffy<S> {
21
27
  options?: GraffyReadOptions,
22
28
  ): Promise<ReadResult<S, Q>>;
23
29
 
24
- // biome-ignore lint/suspicious/noExplicitAny: TODO: add typings
25
- on: (...any) => any;
26
- // biome-ignore lint/suspicious/noExplicitAny: TODO: add typings
27
- call: (...any) => any;
28
- // biome-ignore lint/suspicious/noExplicitAny: TODO: add typings
29
- use: (...any) => any;
30
- // biome-ignore lint/suspicious/noExplicitAny: TODO: add typings
31
- onRead: (...any) => any;
32
- // biome-ignore lint/suspicious/noExplicitAny: TODO: add typings
33
- onWrite: (...any) => any;
34
- // biome-ignore lint/suspicious/noExplicitAny: TODO: add typings
35
- onWatch: (...any) => any;
36
- // biome-ignore lint/suspicious/noExplicitAny: TODO: add typings
37
- write: (...any) => any;
38
- // biome-ignore lint/suspicious/noExplicitAny: TODO: add typings
39
- watch: (...any) => any;
30
+ on: AnyFunction;
31
+ call: AnyFunction;
32
+ use: AnyFunction;
33
+ onRead: AnyFunction;
34
+ onWrite: AnyFunction;
35
+ onWatch: AnyFunction;
36
+ write: AnyFunction;
37
+ watch: AnyFunction;
40
38
  }
41
39
 
42
- export type PathOf<S> = S extends GraffyCollection<BuildObject>
43
- ? string | Key
44
- : S extends JsonObject
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
+
44
+ export type PathOf<S> = S extends GraffyCollection<AnyObject>
45
+ ? Key
46
+ : S extends AnyObject
45
47
  ? keyof S | [keyof S, ...PathOf<S[keyof S]>[]]
46
48
  : never;
47
49
 
48
- export type Descend<S, P> = S extends GraffyCollection<BuildObject>
50
+ type Get<S, K> = S extends GraffyCollection<AnyObject>
49
51
  ? S[string]
50
- : P extends keyof S
51
- ? S[P]
52
- : P extends [keyof S]
53
- ? S[P[0]]
54
- : P extends [keyof S, ...infer R]
55
- ? Descend<S[P[0]], R>
56
- : S;
52
+ : K extends keyof S
53
+ ? S[K]
54
+ : never;
55
+
56
+ export type Descend<S, P> = P extends [Key]
57
+ ? Get<S, P[0]>
58
+ : P extends [Key, ...infer R]
59
+ ? Descend<Get<S, P[0]>, R>
60
+ : Get<S, P>;
57
61
 
58
- export type Project<S> = S extends GraffyCollection<BuildObject>
59
- ?
60
- | (Project<S[string]> & { $key: Key })
61
- | (Project<S[string]> & { $key: Key })[]
62
- : S extends JsonObject
63
- ? Partial<{ [K in keyof S]: Project<S[K]> }>
64
- : 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;
65
71
 
66
72
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
67
73
  type ResultArray<R> = R[] & { $page: any; $next: any; $prev: any };
68
74
 
69
- type ReadResult<S, Q> = S extends GraffyCollection<BuildObject>
70
- ? (S[string] & { $key: Key }) | ResultArray<S[string] & { $key: Key }>
71
- : S extends JsonObject
75
+ type ReadResult<S, Q> = S extends GraffyCollection<AnyObject>
76
+ ? Q extends Array<AnyObject> | { $key: Key }
77
+ ? ResultArray<S[string] & { $key: Key }>
78
+ : S[string] & { $key: Key }
79
+ : S extends AnyObject
72
80
  ? { [K in keyof S & keyof Q]: ReadResult<S[K], Q[K]> }
73
81
  : S;
74
82
 
75
- type GraffyReadOptions = JsonObject;
83
+ type GraffyReadOptions = AnyObject;