/
Nymph.types.ts
175 lines (133 loc) · 4.94 KB
/
Nymph.types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { EntityConstructor, EntityInterface } from './Entity.types';
export type NymphOptions = {
/**
* The URL of your Nymph REST server.
*/
restUrl: string;
/**
* The URL of your Nymph PubSub server.
*/
pubsubUrl?: string;
/**
* A fetch implementation.
*/
fetch?: WindowOrWorkerGlobalScope['fetch'];
/**
* A WebSocket implementation.
*/
WebSocket?: typeof WebSocket;
/**
* Whether to not output status messages to the console.
*/
noConsole?: boolean;
/**
* Don't automatically try to connect to PubSub server.
*/
noAutoconnect?: boolean;
/**
* Use a WeakRef based cache of entities.
*
* This ensures all entities returned are the same instance if they have the
* same class and GUID. This also means that whenever an entity is returned
* from the server, the single instance in memory will be refreshed. This
* could have annoying results, like destroying dirty data (the dreaded
* triple-D).
*
* This could also be a potential source of memory leaks. Although the
* entities themselves are referenced weakly so they get garbage collected,
* the GUID used as a key and the WeakRef object itself are not weak
* references, so not destroyed when the instance is garbage collected.
*
* However, even with these caveats, this might help you if you have a big app
* with the same entities stored in several different places in memory. This
* can help to synchronize them correctly and avoid data conflicts.
*/
weakCache?: boolean;
};
export type EventType = 'request' | 'response';
export type RequestCallback = (url: string, options: RequestInit) => void;
export type ResponseCallback = (response: Response, text: string) => void;
export type Options<T extends EntityConstructor = EntityConstructor> = {
class: T;
limit?: number;
offset?: number;
reverse?: boolean;
sort?: 'cdate' | 'mdate' | string;
return?: 'entity' | 'guid' | 'count';
skipCache?: boolean;
};
export type Clause<C> = C | Exclude<C, undefined>[];
export type OrWithTime<T> = T | [string, null, string];
type PrimitiveSelector = {
guid?: string;
'!guid'?: PrimitiveSelector['guid'];
tag?: string;
'!tag'?: PrimitiveSelector['tag'];
defined?: string;
'!defined'?: PrimitiveSelector['defined'];
truthy?: string;
'!truthy'?: PrimitiveSelector['truthy'];
equal?: [string, any];
'!equal'?: PrimitiveSelector['equal'];
contain?: [string, any];
'!contain'?: PrimitiveSelector['contain'];
match?: [string, string];
'!match'?: PrimitiveSelector['match'];
imatch?: [string, string];
'!imatch'?: PrimitiveSelector['imatch'];
like?: [string, string];
'!like'?: PrimitiveSelector['like'];
ilike?: [string, string];
'!ilike'?: PrimitiveSelector['ilike'];
gt?: [string, number];
'!gt'?: PrimitiveSelector['gt'];
gte?: [string, number];
'!gte'?: PrimitiveSelector['gte'];
lt?: [string, number];
'!lt'?: PrimitiveSelector['lt'];
lte?: [string, number];
'!lte'?: PrimitiveSelector['lte'];
ref?: [string, EntityInterface | string];
'!ref'?: PrimitiveSelector['ref'];
qref?: [string, [Options, ...PrimitiveSelector[]]];
'!qref'?: PrimitiveSelector['qref'];
selector?: PrimitiveSelector;
'!selector'?: PrimitiveSelector['selector'];
};
export type Selector = {
type: '&' | '|' | '!&' | '!|';
guid?: Clause<PrimitiveSelector['guid']>;
'!guid'?: Clause<PrimitiveSelector['guid']>;
tag?: Clause<PrimitiveSelector['tag']>;
'!tag'?: Clause<PrimitiveSelector['tag']>;
defined?: Clause<PrimitiveSelector['defined']>;
'!defined'?: Clause<PrimitiveSelector['defined']>;
truthy?: Clause<PrimitiveSelector['truthy']>;
'!truthy'?: Clause<PrimitiveSelector['truthy']>;
equal?: Clause<OrWithTime<PrimitiveSelector['equal']>>;
'!equal'?: Clause<OrWithTime<PrimitiveSelector['equal']>>;
contain?: Clause<OrWithTime<PrimitiveSelector['contain']>>;
'!contain'?: Clause<OrWithTime<PrimitiveSelector['contain']>>;
match?: Clause<PrimitiveSelector['match']>;
'!match'?: Clause<PrimitiveSelector['match']>;
imatch?: Clause<PrimitiveSelector['imatch']>;
'!imatch'?: Clause<PrimitiveSelector['imatch']>;
like?: Clause<PrimitiveSelector['like']>;
'!like'?: Clause<PrimitiveSelector['like']>;
ilike?: Clause<PrimitiveSelector['ilike']>;
'!ilike'?: Clause<PrimitiveSelector['ilike']>;
gt?: Clause<OrWithTime<PrimitiveSelector['gt']>>;
'!gt'?: Clause<OrWithTime<PrimitiveSelector['gt']>>;
gte?: Clause<OrWithTime<PrimitiveSelector['gte']>>;
'!gte'?: Clause<OrWithTime<PrimitiveSelector['gte']>>;
lt?: Clause<OrWithTime<PrimitiveSelector['lt']>>;
'!lt'?: Clause<OrWithTime<PrimitiveSelector['lt']>>;
lte?: Clause<OrWithTime<PrimitiveSelector['lte']>>;
'!lte'?: Clause<OrWithTime<PrimitiveSelector['lte']>>;
ref?: Clause<PrimitiveSelector['ref']>;
'!ref'?: Clause<PrimitiveSelector['ref']>;
qref?: Clause<[string, [Options, ...Selector[]]]>;
'!qref'?: Selector['qref'];
selector?: Clause<Selector>;
'!selector'?: Selector['selector'];
};