@graffy/core 0.16.20-alpha.7 → 0.16.20-alpha.9

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 +30 -20
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.7",
5
+ "version": "0.16.20-alpha.9",
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.7",
20
- "@graffy/stream": "0.16.20-alpha.7",
19
+ "@graffy/common": "0.16.20-alpha.9",
20
+ "@graffy/stream": "0.16.20-alpha.9",
21
21
  "debug": "^4.3.7"
22
22
  }
23
23
  }
package/types/index.d.ts CHANGED
@@ -7,7 +7,11 @@ export type AnyObject = Record<string, any>;
7
7
  type AnyFunction = (...args: any[]) => any;
8
8
 
9
9
  // biome-ignore lint/suspicious/noExplicitAny: Keys can be anything.
10
- type Key = any;
10
+ export type Key = any;
11
+ export type RangeKey =
12
+ | { $all: boolean }
13
+ | { $first: number }
14
+ | { $last: number };
11
15
 
12
16
  // biome-ignore lint/suspicious/noExplicitAny: Any value is for results.
13
17
  type AnyValue = any;
@@ -36,14 +40,16 @@ export default class Graffy<S> {
36
40
  options?: GraffyReadOptions,
37
41
  ): Promise<ReadResult<S, Q>>;
38
42
 
39
- // Generic one, when the path is not known at compile time.
40
- // Should we have this?
41
- //
42
- // read<Q extends AnyProjection>(
43
- // path: string | Key[],
44
- // projection: Q,
45
- // options?: GraffyReadOptions,
46
- // ): Promise<BlindReadResult<Q>>;
43
+ // Generic mode, when the path is not known at compile time, but projection is.
44
+ read<Q extends AnyProjection>(
45
+ path: string | Key[],
46
+ projection: Q,
47
+ options?: GraffyReadOptions,
48
+ ): Promise<BlindReadResult<Q>>;
49
+
50
+ // Consider also:
51
+ // 1. Read when path is known at compile time but projection is not?
52
+ // 2. Read when neither path nor projection is known at compile time?
47
53
 
48
54
  on: AnyFunction;
49
55
  call: AnyFunction;
@@ -97,7 +103,9 @@ type ReadResult<S, Q> = S extends GraffyCollection<AnyObject>
97
103
  ? Q extends Array<infer QItem>
98
104
  ? ResultArray<PlainReadResult<S[string], QItem> & { $key: Key }> // Array $key
99
105
  : Q extends { $key: Key }
100
- ? ResultArray<PlainReadResult<S[string], Q> & { $key: Key }> // Single $key
106
+ ? Q extends { $key: string }
107
+ ? { [key in Q['$key']]: PlainReadResult<S, Q> }
108
+ : ResultArray<PlainReadResult<S[string], Q> & { $key: Key }> // Single $key
101
109
  : { [K in keyof Q]: PlainReadResult<S[string], Q[K]> } // Object form
102
110
  : PlainReadResult<S, Q>;
103
111
 
@@ -107,15 +115,17 @@ type PlainReadResult<S, Q> = Q extends AnyObject
107
115
  : S;
108
116
 
109
117
  // What can we tell about ReadResult when schema isn’t known?
110
- // type BlindReadResult<Q> = Q extends Array<infer QItem>
111
- // ? ResultArray<BlindPlainReadResult<QItem>>
112
- // : Q extends { $key: Key }
113
- // ? ResultArray<BlindPlainReadResult<Q>>
114
- // : BlindPlainReadResult<Q>;
115
-
116
- // // Ignore $key in Q
117
- // type BlindPlainReadResult<Q> = Q extends AnyObject
118
- // ? { [K in keyof Q]: BlindReadResult<Q[K]> }
119
- // : AnyValue;
118
+ type BlindReadResult<Q> = Q extends Array<infer QItem>
119
+ ? ResultArray<BlindPlainReadResult<QItem>>
120
+ : Q extends { $key: Key }
121
+ ? Q extends { $key: string }
122
+ ? { [key in Q['$key']]: BlindPlainReadResult<Q> }
123
+ : ResultArray<BlindPlainReadResult<Q>>
124
+ : BlindPlainReadResult<Q>;
125
+
126
+ // Ignore $key in Q
127
+ type BlindPlainReadResult<Q> = Q extends AnyObject
128
+ ? { [K in keyof Q]: BlindReadResult<Q[K]> }
129
+ : AnyValue;
120
130
 
121
131
  type GraffyReadOptions = AnyObject;