crelte 0.5.0-beta.5 → 0.5.1
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/dist/queries/vars.d.ts +14 -14
- package/dist/queries/vars.d.ts.map +1 -1
- package/dist/queries/vars.js +28 -26
- package/package.json +1 -1
- package/src/queries/vars.ts +33 -27
package/dist/queries/vars.d.ts
CHANGED
|
@@ -3,19 +3,6 @@ export declare const vars: {
|
|
|
3
3
|
any: () => QueryVar<any>;
|
|
4
4
|
number: () => QueryVar<number>;
|
|
5
5
|
string: () => QueryVar<string>;
|
|
6
|
-
id: () => QueryVar<number>;
|
|
7
|
-
ids: () => QueryVar<number[]>;
|
|
8
|
-
siteId: () => QueryVar<number>;
|
|
9
|
-
};
|
|
10
|
-
export type ValidIf<T> = (v: T, cs: ServerRouter) => boolean;
|
|
11
|
-
export declare class QueryVar<T = any> {
|
|
12
|
-
private name;
|
|
13
|
-
private type;
|
|
14
|
-
private flagNullable;
|
|
15
|
-
private validIfFn;
|
|
16
|
-
constructor();
|
|
17
|
-
string(): QueryVar<string>;
|
|
18
|
-
number(): QueryVar<number>;
|
|
19
6
|
/**
|
|
20
7
|
* Id is almost the same as number but will also parse
|
|
21
8
|
* strings, but only allow non negative integers
|
|
@@ -25,7 +12,7 @@ export declare class QueryVar<T = any> {
|
|
|
25
12
|
* you need to validate the response to make sure filters
|
|
26
13
|
* with this id returned something
|
|
27
14
|
*/
|
|
28
|
-
id()
|
|
15
|
+
id: () => QueryVar<number>;
|
|
29
16
|
/**
|
|
30
17
|
* Ids is an array of ids
|
|
31
18
|
* it will also convert a single id to an array with one element
|
|
@@ -43,6 +30,19 @@ export declare class QueryVar<T = any> {
|
|
|
43
30
|
* To mitigate this you could do a second query with the filtered
|
|
44
31
|
* ids in the field, and check if the return matches the length.
|
|
45
32
|
*/
|
|
33
|
+
ids: () => QueryVar<number[]>;
|
|
34
|
+
siteId: () => QueryVar<number>;
|
|
35
|
+
};
|
|
36
|
+
export type ValidIf<T> = (v: T, cs: ServerRouter) => boolean;
|
|
37
|
+
export declare class QueryVar<T = any> {
|
|
38
|
+
private name;
|
|
39
|
+
private type;
|
|
40
|
+
private flagNullable;
|
|
41
|
+
private validIfFn;
|
|
42
|
+
constructor();
|
|
43
|
+
string(): QueryVar<string>;
|
|
44
|
+
number(): QueryVar<number>;
|
|
45
|
+
id(): QueryVar<number>;
|
|
46
46
|
ids(): QueryVar<number[]>;
|
|
47
47
|
nullable(): QueryVar<T | null>;
|
|
48
48
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vars.d.ts","sourceRoot":"","sources":["../../src/queries/vars.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,2BAA2B,CAAC;AAErD,eAAO,MAAM,IAAI;eACP,QAAQ,CAAC,GAAG,CAAC;kBACV,QAAQ,CAAC,MAAM,CAAC;kBAChB,QAAQ,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"vars.d.ts","sourceRoot":"","sources":["../../src/queries/vars.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,2BAA2B,CAAC;AAErD,eAAO,MAAM,IAAI;eACP,QAAQ,CAAC,GAAG,CAAC;kBACV,QAAQ,CAAC,MAAM,CAAC;kBAChB,QAAQ,CAAC,MAAM,CAAC;IAE5B;;;;;;;;OAQG;cACK,QAAQ,CAAC,MAAM,CAAC;IAExB;;;;;;;;;;;;;;;;OAgBG;eACM,QAAQ,CAAC,MAAM,EAAE,CAAC;kBAEf,QAAQ,CAAC,MAAM,CAAC;CAM5B,CAAC;AAIF,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,YAAY,KAAK,OAAO,CAAC;AAE7D,qBAAa,QAAQ,CAAC,CAAC,GAAG,GAAG;IAC5B,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,IAAI,CAA6C;IACzD,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,SAAS,CAAa;;IAS9B,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC;IAK1B,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC;IAK1B,EAAE,IAAI,QAAQ,CAAC,MAAM,CAAC;IAKtB,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;IAKzB,QAAQ,IAAI,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC;IAK9B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;IAKpC,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,YAAY,GAAG,CAAC,GAAG,IAAI;IAqE9C;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC;IAKpC,YAAY;CACZ;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,QAAQ,CAEhD"}
|
package/dist/queries/vars.js
CHANGED
|
@@ -2,7 +2,33 @@ export const vars = {
|
|
|
2
2
|
any: () => new QueryVar(),
|
|
3
3
|
number: () => new QueryVar().number(),
|
|
4
4
|
string: () => new QueryVar().string(),
|
|
5
|
+
/**
|
|
6
|
+
* Id is almost the same as number but will also parse
|
|
7
|
+
* strings, but only allow non negative integers
|
|
8
|
+
*
|
|
9
|
+
* ## Warning
|
|
10
|
+
* Ids are not automatically safe to be cached
|
|
11
|
+
* you need to validate the response to make sure filters
|
|
12
|
+
* with this id returned something
|
|
13
|
+
*/
|
|
5
14
|
id: () => new QueryVar().id(),
|
|
15
|
+
/**
|
|
16
|
+
* Ids is an array of ids
|
|
17
|
+
* it will also convert a single id to an array with one element
|
|
18
|
+
* the returned array will **never be empty**, but might be null if
|
|
19
|
+
* allowed. Id's are always non negative integers
|
|
20
|
+
*
|
|
21
|
+
* ## Warning
|
|
22
|
+
* Ids are not automatically safe to be cached, it is also not
|
|
23
|
+
* enough to just check if the filter returned some results.
|
|
24
|
+
* Since for example a `relatedTo` filter works like an `or` and
|
|
25
|
+
* not an `and` meaning if you request ids `[1,2,3]` and
|
|
26
|
+
* only 1 and 3 have related entries you will get results
|
|
27
|
+
* even though id 2 did not return anything.
|
|
28
|
+
*
|
|
29
|
+
* To mitigate this you could do a second query with the filtered
|
|
30
|
+
* ids in the field, and check if the return matches the length.
|
|
31
|
+
*/
|
|
6
32
|
ids: () => new QueryVar().ids(),
|
|
7
33
|
siteId: () => new QueryVar()
|
|
8
34
|
.number()
|
|
@@ -27,36 +53,10 @@ export class QueryVar {
|
|
|
27
53
|
this.type = 'number';
|
|
28
54
|
return this;
|
|
29
55
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Id is almost the same as number but will also parse
|
|
32
|
-
* strings, but only allow non negative integers
|
|
33
|
-
*
|
|
34
|
-
* ## Warning
|
|
35
|
-
* Ids are not automatically safe to be cached
|
|
36
|
-
* you need to validate the response to make sure filters
|
|
37
|
-
* with this id returned something
|
|
38
|
-
*/
|
|
39
56
|
id() {
|
|
40
57
|
this.type = 'id';
|
|
41
58
|
return this;
|
|
42
59
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Ids is an array of ids
|
|
45
|
-
* it will also convert a single id to an array with one element
|
|
46
|
-
* the returned array will **never be empty**, but might be null if
|
|
47
|
-
* allowed. Id's are always non negative integers
|
|
48
|
-
*
|
|
49
|
-
* ## Warning
|
|
50
|
-
* Ids are not automatically safe to be cached, it is also not
|
|
51
|
-
* enough to just check if the filter returned some results.
|
|
52
|
-
* Since for example a `relatedTo` filter works like an `or` and
|
|
53
|
-
* not an `and` meaning if you request ids `[1,2,3]` and
|
|
54
|
-
* only 1 and 3 have related entries you will get results
|
|
55
|
-
* even though id 2 did not return anything.
|
|
56
|
-
*
|
|
57
|
-
* To mitigate this you could do a second query with the filtered
|
|
58
|
-
* ids in the field, and check if the return matches the length.
|
|
59
|
-
*/
|
|
60
60
|
ids() {
|
|
61
61
|
this.type = 'ids';
|
|
62
62
|
return this;
|
|
@@ -115,6 +115,8 @@ export class QueryVar {
|
|
|
115
115
|
v = v.map(v => (typeof v === 'string' ? parseInt(v) : v));
|
|
116
116
|
if (!v.every(isValidId))
|
|
117
117
|
throw new Error(`variable ${this.name} is not a list of valid ids`);
|
|
118
|
+
// make unique and sort by number
|
|
119
|
+
v = Array.from(new Set(v)).sort((a, b) => a - b);
|
|
118
120
|
break;
|
|
119
121
|
default:
|
|
120
122
|
throw new Error('uknown type ' + this.type);
|
package/package.json
CHANGED
package/src/queries/vars.ts
CHANGED
|
@@ -4,8 +4,37 @@ export const vars = {
|
|
|
4
4
|
any: (): QueryVar<any> => new QueryVar(),
|
|
5
5
|
number: (): QueryVar<number> => new QueryVar().number(),
|
|
6
6
|
string: (): QueryVar<string> => new QueryVar().string(),
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Id is almost the same as number but will also parse
|
|
10
|
+
* strings, but only allow non negative integers
|
|
11
|
+
*
|
|
12
|
+
* ## Warning
|
|
13
|
+
* Ids are not automatically safe to be cached
|
|
14
|
+
* you need to validate the response to make sure filters
|
|
15
|
+
* with this id returned something
|
|
16
|
+
*/
|
|
7
17
|
id: (): QueryVar<number> => new QueryVar().id(),
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Ids is an array of ids
|
|
21
|
+
* it will also convert a single id to an array with one element
|
|
22
|
+
* the returned array will **never be empty**, but might be null if
|
|
23
|
+
* allowed. Id's are always non negative integers
|
|
24
|
+
*
|
|
25
|
+
* ## Warning
|
|
26
|
+
* Ids are not automatically safe to be cached, it is also not
|
|
27
|
+
* enough to just check if the filter returned some results.
|
|
28
|
+
* Since for example a `relatedTo` filter works like an `or` and
|
|
29
|
+
* not an `and` meaning if you request ids `[1,2,3]` and
|
|
30
|
+
* only 1 and 3 have related entries you will get results
|
|
31
|
+
* even though id 2 did not return anything.
|
|
32
|
+
*
|
|
33
|
+
* To mitigate this you could do a second query with the filtered
|
|
34
|
+
* ids in the field, and check if the return matches the length.
|
|
35
|
+
*/
|
|
8
36
|
ids: (): QueryVar<number[]> => new QueryVar().ids(),
|
|
37
|
+
|
|
9
38
|
siteId: (): QueryVar<number> =>
|
|
10
39
|
new QueryVar()
|
|
11
40
|
.number()
|
|
@@ -41,37 +70,11 @@ export class QueryVar<T = any> {
|
|
|
41
70
|
return this as unknown as QueryVar<number>;
|
|
42
71
|
}
|
|
43
72
|
|
|
44
|
-
/**
|
|
45
|
-
* Id is almost the same as number but will also parse
|
|
46
|
-
* strings, but only allow non negative integers
|
|
47
|
-
*
|
|
48
|
-
* ## Warning
|
|
49
|
-
* Ids are not automatically safe to be cached
|
|
50
|
-
* you need to validate the response to make sure filters
|
|
51
|
-
* with this id returned something
|
|
52
|
-
*/
|
|
53
73
|
id(): QueryVar<number> {
|
|
54
74
|
this.type = 'id';
|
|
55
75
|
return this as unknown as QueryVar<number>;
|
|
56
76
|
}
|
|
57
77
|
|
|
58
|
-
/**
|
|
59
|
-
* Ids is an array of ids
|
|
60
|
-
* it will also convert a single id to an array with one element
|
|
61
|
-
* the returned array will **never be empty**, but might be null if
|
|
62
|
-
* allowed. Id's are always non negative integers
|
|
63
|
-
*
|
|
64
|
-
* ## Warning
|
|
65
|
-
* Ids are not automatically safe to be cached, it is also not
|
|
66
|
-
* enough to just check if the filter returned some results.
|
|
67
|
-
* Since for example a `relatedTo` filter works like an `or` and
|
|
68
|
-
* not an `and` meaning if you request ids `[1,2,3]` and
|
|
69
|
-
* only 1 and 3 have related entries you will get results
|
|
70
|
-
* even though id 2 did not return anything.
|
|
71
|
-
*
|
|
72
|
-
* To mitigate this you could do a second query with the filtered
|
|
73
|
-
* ids in the field, and check if the return matches the length.
|
|
74
|
-
*/
|
|
75
78
|
ids(): QueryVar<number[]> {
|
|
76
79
|
this.type = 'ids';
|
|
77
80
|
return this as unknown as QueryVar<number[]>;
|
|
@@ -147,6 +150,9 @@ export class QueryVar<T = any> {
|
|
|
147
150
|
throw new Error(
|
|
148
151
|
`variable ${this.name} is not a list of valid ids`,
|
|
149
152
|
);
|
|
153
|
+
|
|
154
|
+
// make unique and sort by number
|
|
155
|
+
v = Array.from(new Set(v as number[])).sort((a, b) => a - b);
|
|
150
156
|
break;
|
|
151
157
|
|
|
152
158
|
default:
|
|
@@ -176,6 +182,6 @@ export function isQueryVar(v: any): v is QueryVar {
|
|
|
176
182
|
}
|
|
177
183
|
|
|
178
184
|
// does not do string to number conversion
|
|
179
|
-
function isValidId(id: any):
|
|
185
|
+
function isValidId(id: any): id is number {
|
|
180
186
|
return typeof id === 'number' && Number.isInteger(id) && id >= 0;
|
|
181
187
|
}
|