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

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