@graffy/core 0.16.20-alpha.8 → 0.16.20
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.
- package/package.json +4 -4
- package/types/Core.d.ts +5 -0
- package/types/Graffy.d.ts +33 -0
- package/types/index.d.ts +2 -127
- package/types/shift.d.ts +3 -0
- package/types/validate.d.ts +2 -0
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
|
|
5
|
+
"version": "0.16.20",
|
|
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
|
|
20
|
-
"@graffy/stream": "0.16.20
|
|
21
|
-
"debug": "^4.3.
|
|
19
|
+
"@graffy/common": "0.16.20",
|
|
20
|
+
"@graffy/stream": "0.16.20",
|
|
21
|
+
"debug": "^4.3.3"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/types/Core.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { unchanged } from "./shift.js";
|
|
2
|
+
declare class Graffy {
|
|
3
|
+
constructor(path?: any[], core?: Core);
|
|
4
|
+
core: Core;
|
|
5
|
+
path: any[];
|
|
6
|
+
on(type: any, ...args: any[]): void;
|
|
7
|
+
onRead(...args: any[]): void;
|
|
8
|
+
onWatch(...args: any[]): void;
|
|
9
|
+
onWrite(...args: any[]): void;
|
|
10
|
+
use(...args: any[]): void;
|
|
11
|
+
call(type: any, payload: any, options?: {}): any;
|
|
12
|
+
read(...args: any[]): Promise<any>;
|
|
13
|
+
watch(...args: any[]): {
|
|
14
|
+
debugId: any;
|
|
15
|
+
next: () => any;
|
|
16
|
+
return(value: any): Promise<{
|
|
17
|
+
value: any;
|
|
18
|
+
done: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
throw(error: any): Promise<{
|
|
21
|
+
value: any;
|
|
22
|
+
done: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
[Symbol.asyncIterator](): /*elided*/ any;
|
|
25
|
+
};
|
|
26
|
+
write(...args: any[]): Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
declare namespace Graffy {
|
|
29
|
+
export { unchanged };
|
|
30
|
+
}
|
|
31
|
+
export default Graffy;
|
|
32
|
+
import Core from './Core.js';
|
|
33
|
+
import { unchanged } from './shift.js';
|
package/types/index.d.ts
CHANGED
|
@@ -1,127 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
// biome-ignore lint/suspicious/noExplicitAny: This is used to match concrete types in "extends" expressions.
|
|
4
|
-
export type AnyObject = Record<string, any>;
|
|
5
|
-
|
|
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
|
-
export type Key = any;
|
|
11
|
-
export type RangeKey =
|
|
12
|
-
| { $all: boolean }
|
|
13
|
-
| { $first: number }
|
|
14
|
-
| { $last: number };
|
|
15
|
-
|
|
16
|
-
// biome-ignore lint/suspicious/noExplicitAny: Any value is for results.
|
|
17
|
-
type AnyValue = any;
|
|
18
|
-
|
|
19
|
-
type AnyProjection =
|
|
20
|
-
| boolean
|
|
21
|
-
| { $key: Key }
|
|
22
|
-
| { [key: string]: AnyProjection }
|
|
23
|
-
| AnyProjection[];
|
|
24
|
-
|
|
25
|
-
export type GraffyCollection<CollectionSchema extends AnyObject> = {
|
|
26
|
-
[name: string]: CollectionSchema;
|
|
27
|
-
} & { __brand: 'GraffyCollection' };
|
|
28
|
-
|
|
29
|
-
// The parameter should be the Schema of the entire store. Use the "GraffyCollection"
|
|
30
|
-
// type to define the schema of a collection.
|
|
31
|
-
export default class Graffy<S> {
|
|
32
|
-
read<P extends PathOf<S>, Q extends Project<Descend<S, P>>>(
|
|
33
|
-
path: P,
|
|
34
|
-
projection: Q,
|
|
35
|
-
options?: GraffyReadOptions,
|
|
36
|
-
): Promise<ReadResult<Descend<S, P>, Q>>;
|
|
37
|
-
|
|
38
|
-
read<Q extends Project<S>>(
|
|
39
|
-
projection: Q,
|
|
40
|
-
options?: GraffyReadOptions,
|
|
41
|
-
): Promise<ReadResult<S, Q>>;
|
|
42
|
-
|
|
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?
|
|
53
|
-
|
|
54
|
-
on: AnyFunction;
|
|
55
|
-
call: AnyFunction;
|
|
56
|
-
use: AnyFunction;
|
|
57
|
-
onRead: AnyFunction;
|
|
58
|
-
onWrite: AnyFunction;
|
|
59
|
-
onWatch: AnyFunction;
|
|
60
|
-
write: AnyFunction;
|
|
61
|
-
watch: AnyFunction;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// TODO: To avoid the "too deep" error, these need to be tail-recursive.
|
|
65
|
-
// This may be possible with an "accummulator" type parameter.
|
|
66
|
-
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#tail-recursion-elimination-on-conditional-types
|
|
67
|
-
|
|
68
|
-
export type PathOf<S> = S extends GraffyCollection<AnyObject>
|
|
69
|
-
? Key
|
|
70
|
-
: S extends AnyObject
|
|
71
|
-
? keyof S | [keyof S, ...PathOf<S[keyof S]>[]]
|
|
72
|
-
: never;
|
|
73
|
-
|
|
74
|
-
type Get<S, K> = S extends GraffyCollection<AnyObject>
|
|
75
|
-
? S[string]
|
|
76
|
-
: K extends keyof S
|
|
77
|
-
? S[K]
|
|
78
|
-
: never;
|
|
79
|
-
|
|
80
|
-
export type Descend<S, P> = P extends [Key]
|
|
81
|
-
? Get<S, P[0]>
|
|
82
|
-
: P extends [Key, ...infer R]
|
|
83
|
-
? Descend<Get<S, P[0]>, R>
|
|
84
|
-
: Get<S, P>;
|
|
85
|
-
|
|
86
|
-
export type Project<S> = S extends AnyLeaf
|
|
87
|
-
? boolean
|
|
88
|
-
: S extends GraffyCollection<AnyObject>
|
|
89
|
-
?
|
|
90
|
-
| { [key: string]: Project<S[string]> } // Object form
|
|
91
|
-
| (Project<S[string]> & { $key: Key }) // Single $key
|
|
92
|
-
| (Project<S[string]> & { $key: Key })[] // Array $key
|
|
93
|
-
: S extends AnyObject
|
|
94
|
-
? 'string' extends keyof S // No named properties?
|
|
95
|
-
? AnyProjection
|
|
96
|
-
: Partial<{ [K in keyof S]: Project<S[K]> }> | boolean
|
|
97
|
-
: never;
|
|
98
|
-
|
|
99
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
100
|
-
type ResultArray<R> = R[] & { $page: any; $next: any; $prev: any };
|
|
101
|
-
|
|
102
|
-
type ReadResult<S, Q> = S extends GraffyCollection<AnyObject>
|
|
103
|
-
? Q extends Array<infer QItem>
|
|
104
|
-
? ResultArray<PlainReadResult<S[string], QItem> & { $key: Key }> // Array $key
|
|
105
|
-
: Q extends { $key: Key }
|
|
106
|
-
? ResultArray<PlainReadResult<S[string], Q> & { $key: Key }> // Single $key
|
|
107
|
-
: { [K in keyof Q]: PlainReadResult<S[string], Q[K]> } // Object form
|
|
108
|
-
: PlainReadResult<S, Q>;
|
|
109
|
-
|
|
110
|
-
// Ignore $key in Q
|
|
111
|
-
type PlainReadResult<S, Q> = Q extends AnyObject
|
|
112
|
-
? { [K in keyof S & keyof Q]: ReadResult<S[K], Q[K]> }
|
|
113
|
-
: S;
|
|
114
|
-
|
|
115
|
-
// What can we tell about ReadResult when schema isn’t known?
|
|
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;
|
|
126
|
-
|
|
127
|
-
type GraffyReadOptions = AnyObject;
|
|
1
|
+
export default Graffy;
|
|
2
|
+
import Graffy from './Graffy.js';
|
package/types/shift.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export function wrapProvider(fn: any, decodedPath: any, isRead: any): (payload: any, options: any, next: any) => Promise<any>;
|
|
2
|
+
export function shiftGen(fn: any, path: any): (payload: any, options: any, next: any) => AsyncGenerator<any, void, any>;
|
|
3
|
+
export const unchanged: unique symbol;
|