@graffy/core 0.16.20-alpha.6 → 0.16.20-alpha.8

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 +24 -14
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.6",
5
+ "version": "0.16.20-alpha.8",
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.6",
20
- "@graffy/stream": "0.16.20-alpha.6",
19
+ "@graffy/common": "0.16.20-alpha.8",
20
+ "@graffy/stream": "0.16.20-alpha.8",
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;
@@ -15,7 +19,7 @@ type AnyValue = any;
15
19
  type AnyProjection =
16
20
  | boolean
17
21
  | { $key: Key }
18
- | Record<string, AnyProjection>
22
+ | { [key: string]: AnyProjection }
19
23
  | AnyProjection[];
20
24
 
21
25
  export type GraffyCollection<CollectionSchema extends AnyObject> = {
@@ -36,13 +40,17 @@ 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.
43
+ // Generic mode, when the path is not known at compile time, but projection is.
40
44
  read<Q extends AnyProjection>(
41
45
  path: string | Key[],
42
46
  projection: Q,
43
47
  options?: GraffyReadOptions,
44
48
  ): Promise<BlindReadResult<Q>>;
45
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?
53
+
46
54
  on: AnyFunction;
47
55
  call: AnyFunction;
48
56
  use: AnyFunction;
@@ -83,7 +91,9 @@ export type Project<S> = S extends AnyLeaf
83
91
  | (Project<S[string]> & { $key: Key }) // Single $key
84
92
  | (Project<S[string]> & { $key: Key })[] // Array $key
85
93
  : S extends AnyObject
86
- ? Partial<{ [K in keyof S]: Project<S[K]> }> | boolean
94
+ ? 'string' extends keyof S // No named properties?
95
+ ? AnyProjection
96
+ : Partial<{ [K in keyof S]: Project<S[K]> }> | boolean
87
97
  : never;
88
98
 
89
99
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -103,15 +113,15 @@ type PlainReadResult<S, Q> = Q extends AnyObject
103
113
  : S;
104
114
 
105
115
  // What can we tell about ReadResult when schema isn’t known?
106
- type BlindReadResult<Q> = Q extends Array<infer QItem>
107
- ? ResultArray<BlindPlainReadResult<QItem>>
108
- : Q extends { $key: Key }
109
- ? ResultArray<BlindPlainReadResult<Q>>
110
- : BlindPlainReadResult<Q>;
111
-
112
- // Ignore $key in Q
113
- type BlindPlainReadResult<Q> = Q extends AnyObject
114
- ? { [K in keyof Q]: BlindReadResult<Q[K]> }
115
- : AnyValue;
116
+ // type BlindReadResult<Q> = Q extends Array<infer QItem>
117
+ // ? ResultArray<BlindPlainReadResult<QItem>>
118
+ // : Q extends { $key: Key }
119
+ // ? ResultArray<BlindPlainReadResult<Q>>
120
+ // : BlindPlainReadResult<Q>;
121
+
122
+ // // Ignore $key in Q
123
+ // type BlindPlainReadResult<Q> = Q extends AnyObject
124
+ // ? { [K in keyof Q]: BlindReadResult<Q[K]> }
125
+ // : AnyValue;
116
126
 
117
127
  type GraffyReadOptions = AnyObject;