qweery 0.0.2 → 0.0.3
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/README.md +21 -0
- package/dist/index.cjs +135 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -40
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +55 -40
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +134 -74
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ npm install qweery
|
|
|
12
12
|
- Typescript first design, ensuring type safety and autocompletion.
|
|
13
13
|
- ORM-like querying.
|
|
14
14
|
- Chainable API for building complex queries.
|
|
15
|
+
- Fast? I don't really know.
|
|
15
16
|
|
|
16
17
|
## Usage
|
|
17
18
|
|
|
@@ -81,4 +82,24 @@ console.log(
|
|
|
81
82
|
);
|
|
82
83
|
|
|
83
84
|
// Output: [{ name: 'Charlie', age: 35 }]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
console.log(
|
|
89
|
+
qweery
|
|
90
|
+
// name.includes('a') || age > 30
|
|
91
|
+
.where({
|
|
92
|
+
name: {
|
|
93
|
+
includes: 'a'
|
|
94
|
+
},
|
|
95
|
+
$OR: {
|
|
96
|
+
age: { greaterThan: 30 }
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
.skip(0)
|
|
100
|
+
.take(10)
|
|
101
|
+
.toArray()
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// Output: [{ name: 'Charlie', age: 35 }, { name: 'David', age: 28 }]
|
|
84
105
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,137 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
+
//#region src/classes/Primitive.ts
|
|
4
|
+
var Primitive = class Primitive {
|
|
5
|
+
static satisfiesValue(value, options) {
|
|
6
|
+
if (Primitive.isDefined(options.equals) && value !== options.equals) return false;
|
|
7
|
+
if (Primitive.isDefined(options.notEquals) && value === options.notEquals) return false;
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
static statisfiesString(value, options) {
|
|
11
|
+
if (options.caseInsensitive) value = value.toLowerCase();
|
|
12
|
+
if (!this.satisfiesValue(value, options)) return false;
|
|
13
|
+
if (Primitive.isDefined(options.startsWith) && !value.startsWith(options.startsWith)) return false;
|
|
14
|
+
if (Primitive.isDefined(options.endsWith) && !value.endsWith(options.endsWith)) return false;
|
|
15
|
+
if (Primitive.isDefined(options.includes) && !value.includes(options.includes)) return false;
|
|
16
|
+
if (Primitive.isDefined(options.matches) && !options.matches.test(value)) return false;
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
static statisfiesNumerical(value, options) {
|
|
20
|
+
value = Primitive.normalizeNumericalValue(value);
|
|
21
|
+
if (Primitive.isDefined(options.equals) && value !== Primitive.normalizeNumericalValue(options.equals)) return false;
|
|
22
|
+
if (Primitive.isDefined(options.notEquals) && value === Primitive.normalizeNumericalValue(options.notEquals)) return false;
|
|
23
|
+
if (Primitive.isDefined(options.greaterThan) && value <= Primitive.normalizeNumericalValue(options.greaterThan)) return false;
|
|
24
|
+
if (Primitive.isDefined(options.greaterThanOrEqual) && value < Primitive.normalizeNumericalValue(options.greaterThanOrEqual)) return false;
|
|
25
|
+
if (Primitive.isDefined(options.lessThan) && value >= Primitive.normalizeNumericalValue(options.lessThan)) return false;
|
|
26
|
+
if (Primitive.isDefined(options.lessThanOrEqual) && value > Primitive.normalizeNumericalValue(options.lessThanOrEqual)) return false;
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
static statisfiesArray(value, options) {
|
|
30
|
+
if (!this.satisfiesValue(value, options)) return false;
|
|
31
|
+
if (Primitive.isDefined(options.includesEvery) && !options.includesEvery.every((item) => value.includes(item))) return false;
|
|
32
|
+
if (Primitive.isDefined(options.includesSome) && !options.includesSome.some((item) => value.includes(item))) return false;
|
|
33
|
+
if (Primitive.isDefined(options.includesNone) && options.includesNone.some((item) => value.includes(item))) return false;
|
|
34
|
+
if (Primitive.isDefined(options.length) && !Primitive.statisfiesNumerical(value.length, options.length)) return false;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
(function(_Primitive) {
|
|
39
|
+
function normalizeNumericalValue(value) {
|
|
40
|
+
return value instanceof Date ? value.getTime() : value;
|
|
41
|
+
}
|
|
42
|
+
_Primitive.normalizeNumericalValue = normalizeNumericalValue;
|
|
43
|
+
function isNumerical(value) {
|
|
44
|
+
return typeof value === "number" || typeof value === "bigint" || value instanceof Date;
|
|
45
|
+
}
|
|
46
|
+
_Primitive.isNumerical = isNumerical;
|
|
47
|
+
function isDefined(value) {
|
|
48
|
+
return value !== void 0;
|
|
49
|
+
}
|
|
50
|
+
_Primitive.isDefined = isDefined;
|
|
51
|
+
})(Primitive || (Primitive = {}));
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/classes/Where.ts
|
|
55
|
+
var Where = class Where {
|
|
56
|
+
data;
|
|
57
|
+
constructor(data) {
|
|
58
|
+
this.data = Array.from(data);
|
|
59
|
+
}
|
|
60
|
+
filter(options) {
|
|
61
|
+
return this.data.filter((_, index) => this.satisfiesItem(options, index));
|
|
62
|
+
}
|
|
63
|
+
satisfiesItem(options, index) {
|
|
64
|
+
const item = this.data.at(index);
|
|
65
|
+
if (!item) return false;
|
|
66
|
+
let value = true;
|
|
67
|
+
for (const key in options) {
|
|
68
|
+
if (Where.isLogicalOperator(key)) {
|
|
69
|
+
const conditions = options[key];
|
|
70
|
+
switch (key) {
|
|
71
|
+
case "$NOT":
|
|
72
|
+
value = value && !(Array.isArray(conditions) ? conditions.every((condition) => this.satisfiesItem(condition, index)) : this.satisfiesItem(conditions, index));
|
|
73
|
+
break;
|
|
74
|
+
case "$AND":
|
|
75
|
+
value = value && (Array.isArray(conditions) ? conditions.every((condition) => this.satisfiesItem(condition, index)) : this.satisfiesItem(conditions, index));
|
|
76
|
+
break;
|
|
77
|
+
case "$OR":
|
|
78
|
+
value = Array.isArray(conditions) ? value && conditions.some((condition) => this.satisfiesItem(condition, index)) : value || this.satisfiesItem(conditions, index);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const filter = options[key];
|
|
84
|
+
const itemValue = item[key];
|
|
85
|
+
if (filter instanceof Function) {
|
|
86
|
+
value = value && filter(itemValue, item, index, this.data);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (typeof filter === "object") {
|
|
90
|
+
if (typeof itemValue === "string") {
|
|
91
|
+
value = value && Primitive.statisfiesString(itemValue, filter);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(itemValue)) {
|
|
95
|
+
value = value && Primitive.statisfiesArray(itemValue, filter);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (Primitive.isNumerical(itemValue)) {
|
|
99
|
+
value = value && Primitive.statisfiesNumerical(itemValue, filter);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
value = value && Primitive.satisfiesValue(itemValue, filter);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
value = value && itemValue === filter;
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
(function(_Where) {
|
|
111
|
+
function isLogicalOperator(value) {
|
|
112
|
+
return value === "$AND" || value === "$OR" || value === "$NOT";
|
|
113
|
+
}
|
|
114
|
+
_Where.isLogicalOperator = isLogicalOperator;
|
|
115
|
+
})(Where || (Where = {}));
|
|
116
|
+
new Where([
|
|
117
|
+
{
|
|
118
|
+
name: "Alice",
|
|
119
|
+
age: 30,
|
|
120
|
+
sports: ["Football", "Basketball"]
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "Bob",
|
|
124
|
+
age: 25,
|
|
125
|
+
sports: ["Football", "Basketball"]
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "Charlie",
|
|
129
|
+
age: 35,
|
|
130
|
+
sports: ["Football", "Basketball"]
|
|
131
|
+
}
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
3
135
|
//#region src/classes/Qweery.ts
|
|
4
136
|
var Qweery = class Qweery {
|
|
5
137
|
data;
|
|
@@ -7,13 +139,13 @@ var Qweery = class Qweery {
|
|
|
7
139
|
this.data = Array.from(data);
|
|
8
140
|
}
|
|
9
141
|
query(options) {
|
|
10
|
-
let result = this.data.filter(
|
|
142
|
+
let result = new Where(this.data).filter(options.where || {});
|
|
11
143
|
if (options.skip) result = result.slice(options.skip);
|
|
12
144
|
if (options.limit) result = result.slice(0, options.limit);
|
|
13
145
|
return result;
|
|
14
146
|
}
|
|
15
147
|
where(options) {
|
|
16
|
-
return new Qweery(this.data.filter(
|
|
148
|
+
return new Qweery(new Where(this.data).filter(options || {}));
|
|
17
149
|
}
|
|
18
150
|
skip(count) {
|
|
19
151
|
return new Qweery(this.data.slice(count));
|
|
@@ -33,85 +165,8 @@ var Qweery = class Qweery {
|
|
|
33
165
|
toArray() {
|
|
34
166
|
return this.data;
|
|
35
167
|
}
|
|
36
|
-
isItemMatch(index, options) {
|
|
37
|
-
const item = this.data.at(index);
|
|
38
|
-
if (!item) return false;
|
|
39
|
-
const keys = Object.keys(options);
|
|
40
|
-
for (const key of keys) {
|
|
41
|
-
if (key.toString().startsWith("$") || options[key] === void 0) continue;
|
|
42
|
-
let value;
|
|
43
|
-
if (typeof options[key] === "function") value = options[key](item[key], item, index, this.data);
|
|
44
|
-
else if (typeof options[key] === "object") if (typeof item[key] === "string") value = this.evaluateStringOperator(index, key, options[key]);
|
|
45
|
-
else if (typeof item[key] === "number" || typeof item[key] === "bigint" || item[key] instanceof Date) value = this.evaluateNumericalOperator(index, key, options[key]);
|
|
46
|
-
else if (Array.isArray(item[key])) value = this.evaluateArrayOperator(index, key, options[key]);
|
|
47
|
-
else value = this.evaluateValueOperator(index, key, options[key]);
|
|
48
|
-
else value = item[key] === options[key];
|
|
49
|
-
if (!value) return false;
|
|
50
|
-
}
|
|
51
|
-
return this.evaluateLogicalOperator(index, options);
|
|
52
|
-
}
|
|
53
|
-
evaluateLogicalOperator(index, options) {
|
|
54
|
-
if (options.$NOT) {
|
|
55
|
-
for (const option of Array.isArray(options.$NOT) ? options.$NOT : [options.$NOT]) if (this.isItemMatch(index, option)) return false;
|
|
56
|
-
}
|
|
57
|
-
if (options.$AND) {
|
|
58
|
-
for (const option of Array.isArray(options.$AND) ? options.$AND : [options.$AND]) if (!this.isItemMatch(index, option)) return false;
|
|
59
|
-
}
|
|
60
|
-
if (options.$OR) {
|
|
61
|
-
let hasMatch = false;
|
|
62
|
-
for (const option of Array.isArray(options.$OR) ? options.$OR : [options.$OR]) if (this.isItemMatch(index, option)) {
|
|
63
|
-
hasMatch = true;
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
if (!hasMatch) return false;
|
|
67
|
-
}
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
evaluateValueOperator(index, property, operator) {
|
|
71
|
-
if ("equals" in operator && operator.equals !== this.data[index][property]) return false;
|
|
72
|
-
if ("notEquals" in operator && operator.notEquals === this.data[index][property]) return false;
|
|
73
|
-
return this.evaluateLogicalOperator(index, operator);
|
|
74
|
-
}
|
|
75
|
-
evaluateNumericalOperator(index, property, operator) {
|
|
76
|
-
if (!this.evaluateValueOperator(index, property, operator)) return false;
|
|
77
|
-
const value = Qweery.normalizeNumericalValue(this.data[index][property]);
|
|
78
|
-
if (operator.greaterThan !== void 0 && !(value > Qweery.normalizeNumericalValue(operator.greaterThan))) return false;
|
|
79
|
-
if (operator.greaterThanOrEqual !== void 0 && !(value >= Qweery.normalizeNumericalValue(operator.greaterThanOrEqual))) return false;
|
|
80
|
-
if (operator.lessThan !== void 0 && !(value < Qweery.normalizeNumericalValue(operator.lessThan))) return false;
|
|
81
|
-
if (operator.lessThanOrEqual !== void 0 && !(value <= Qweery.normalizeNumericalValue(operator.lessThanOrEqual))) return false;
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
evaluateStringOperator(index, property, operator) {
|
|
85
|
-
if (!this.evaluateValueOperator(index, property, operator)) return false;
|
|
86
|
-
let value = this.data[index][property];
|
|
87
|
-
if (operator.caseInsensitive) value = value.toLowerCase();
|
|
88
|
-
if (operator.includes && !value.includes(operator.caseInsensitive ? operator.includes.toLowerCase() : operator.includes)) return false;
|
|
89
|
-
if (operator.startsWith && !value.startsWith(operator.caseInsensitive ? operator.startsWith.toLowerCase() : operator.startsWith)) return false;
|
|
90
|
-
if (operator.endsWith && !value.endsWith(operator.caseInsensitive ? operator.endsWith.toLowerCase() : operator.endsWith)) return false;
|
|
91
|
-
if (operator.matches && !operator.matches.test(value)) return false;
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
evaluateArrayOperator(index, property, operator) {
|
|
95
|
-
if (!this.evaluateValueOperator(index, property, operator)) return false;
|
|
96
|
-
const value = this.data[index][property];
|
|
97
|
-
if ("includesEvery" in operator && operator.includesEvery?.every((v) => value.includes(v))) return true;
|
|
98
|
-
if ("includesSome" in operator && operator.includesSome?.some((v) => value.includes(v))) return true;
|
|
99
|
-
if ("includesNone" in operator && operator.includesNone?.every((v) => !value.includes(v))) return true;
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
168
|
};
|
|
103
|
-
(function(_Qweery) {
|
|
104
|
-
function normalizeNumericalValue(value) {
|
|
105
|
-
return value instanceof Date ? value.getTime() : value;
|
|
106
|
-
}
|
|
107
|
-
_Qweery.normalizeNumericalValue = normalizeNumericalValue;
|
|
108
|
-
})(Qweery || (Qweery = {}));
|
|
109
169
|
|
|
110
170
|
//#endregion
|
|
111
|
-
|
|
112
|
-
enumerable: true,
|
|
113
|
-
get: function () {
|
|
114
|
-
return Qweery;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
171
|
+
exports.Qweery = Qweery;
|
|
117
172
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/classes/Qweery.ts"],"sourcesContent":["import type { ValueOrArray } from '../helpers/types.js';\n\nexport class Qweery<T extends Qweery.Object> {\n public readonly data: T[];\n\n constructor(data: Iterable<T>) {\n this.data = Array.from(data);\n }\n\n public query(options: {\n where?: Qweery.WhereOptions<T>;\n skip?: number;\n limit?: number;\n }): T[] {\n let result = this.data.filter((_, index) => options.where ? this.isItemMatch(index, options.where) : true);\n\n if (options.skip) {\n result = result.slice(options.skip);\n }\n\n if (options.limit) {\n result = result.slice(0, options.limit);\n }\n\n return result;\n }\n\n public where(options: Qweery.WhereOptions<T>): Qweery<T> {\n return new Qweery(this.data.filter((_, index) => this.isItemMatch(index, options)));\n }\n\n public skip(count: number): Qweery<T> {\n return new Qweery(this.data.slice(count));\n }\n\n public take(count: number): Qweery<T> {\n return new Qweery(this.data.slice(0, count));\n }\n\n public count(): number {\n return this.data.length;\n }\n\n public first(): T|undefined {\n return this.data[0];\n }\n\n public last(): T|undefined {\n return this.data[this.data.length - 1];\n }\n\n public toArray(): T[] {\n return this.data;\n }\n\n private isItemMatch(index: number, options: Qweery.WhereOptions<T>): boolean {\n const item = this.data.at(index);\n if (!item) return false\n\n const keys = Object.keys(options) as (keyof T)[];\n\n for (const key of keys) {\n if (key.toString().startsWith('$') || options[key] === undefined) continue;\n\n let value: boolean;\n\n if (typeof options[key] === 'function') {\n value = options[key](item[key], item, index, this.data);\n } else if (typeof options[key] === 'object') {\n if (typeof item[key] === 'string') {\n value = this.evaluateStringOperator(\n index,\n key,\n options[key] as Qweery.WhereOptionStringOperators<T, Qweery.StringPrimitive>\n );\n } else if (\n typeof item[key] === 'number' ||\n typeof item[key] === 'bigint' ||\n item[key] instanceof Date\n ) {\n value = this.evaluateNumericalOperator(\n index,\n key,\n options[key] as Qweery.WhereOptionNumericalOperators<T, Qweery.NumericalPrimitive>\n );\n } else if (Array.isArray(item[key])) {\n value = this.evaluateArrayOperator(\n index,\n key,\n options[key] as Qweery.WhereOptionArrayOperators<T, Qweery.ArrayPrimitive>\n );\n } else {\n value = this.evaluateValueOperator(\n index,\n key,\n options[key] as Qweery.WhereOptionValueOperators<T, any>\n );\n }\n } else {\n value = item[key] === options[key];\n }\n\n if (!value) return false;\n }\n\n return this.evaluateLogicalOperator(index, options);\n }\n\n private evaluateLogicalOperator(index: number, options: Qweery.WhereOptionLogicalOperators<T>): boolean {\n let value = true;\n\n if (options.$NOT) {\n for (const option of Array.isArray(options.$NOT) ? options.$NOT : [options.$NOT]) {\n if (this.isItemMatch(index, option)) return false;\n }\n }\n\n if (options.$AND) {\n for (const option of Array.isArray(options.$AND) ? options.$AND : [options.$AND]) {\n if (!this.isItemMatch(index, option)) return false;\n }\n }\n\n if (options.$OR) {\n let hasMatch = false;\n\n for (const option of Array.isArray( options.$OR) ? options.$OR : [ options.$OR]) {\n if (this.isItemMatch(index, option)) {\n hasMatch = true;\n break;\n }\n }\n\n if (!hasMatch) return false;\n }\n\n return true;\n }\n\n private evaluateValueOperator(index: number, property: keyof T, operator: Qweery.WhereOptionValueOperators<T, any>): boolean {\n if ('equals' in operator && operator.equals !== this.data[index][property]) {\n return false;\n }\n\n if ('notEquals' in operator && operator.notEquals === this.data[index][property]) {\n return false;\n }\n\n return true && this.evaluateLogicalOperator(index, operator);\n }\n\n private evaluateNumericalOperator(index: number, property: keyof T, operator: Qweery.WhereOptionNumericalOperators<T, Qweery.NumericalPrimitive>): boolean {\n if (!this.evaluateValueOperator(index, property, operator)) return false;\n\n const value = Qweery.normalizeNumericalValue(this.data[index][property] as Qweery.NumericalPrimitive);\n\n if (operator.greaterThan !== undefined && !(value > Qweery.normalizeNumericalValue(operator.greaterThan))) {\n return false;\n }\n\n if (operator.greaterThanOrEqual !== undefined && !(value >= Qweery.normalizeNumericalValue(operator.greaterThanOrEqual))) {\n return false;\n }\n\n if (operator.lessThan !== undefined && !(value < Qweery.normalizeNumericalValue(operator.lessThan))) {\n return false;\n }\n\n if (operator.lessThanOrEqual !== undefined && !(value <= Qweery.normalizeNumericalValue(operator.lessThanOrEqual))) {\n return false;\n }\n\n return true;\n }\n\n private evaluateStringOperator(index: number, property: keyof T, operator: Qweery.WhereOptionStringOperators<T, Qweery.StringPrimitive>): boolean {\n if (!this.evaluateValueOperator(index, property, operator)) return false;\n\n let value = this.data[index][property] as Qweery.StringPrimitive;\n\n if (operator.caseInsensitive) {\n value = value.toLowerCase();\n }\n\n if (\n operator.includes &&\n !value.includes(\n operator.caseInsensitive\n ? operator.includes.toLowerCase()\n : operator.includes\n )\n ) {\n return false;\n }\n\n if (\n operator.startsWith && \n !value.startsWith(\n operator.caseInsensitive\n ? operator.startsWith.toLowerCase()\n : operator.startsWith\n )\n ) {\n return false;\n }\n\n if (\n operator.endsWith &&\n !value.endsWith(\n operator.caseInsensitive\n ? operator.endsWith.toLowerCase()\n : operator.endsWith\n )\n ) {\n return false;\n }\n\n if (operator.matches && !operator.matches.test(value)) {\n return false;\n }\n\n return true;\n }\n\n private evaluateArrayOperator(index: number, property: keyof T, operator: Qweery.WhereOptionArrayOperators<T, Qweery.ArrayPrimitive>): boolean {\n if (!this.evaluateValueOperator(index, property, operator)) return false;\n\n const value = this.data[index][property] as Qweery.ArrayPrimitive;\n\n if ('includesEvery' in operator && operator.includesEvery?.every(v => value.includes(v))) {\n return true;\n }\n\n if ('includesSome' in operator && operator.includesSome?.some(v => value.includes(v))) {\n return true;\n }\n\n if ('includesNone' in operator && operator.includesNone?.every(v => !value.includes(v))) {\n return true;\n }\n\n return true;\n }\n}\n\nexport namespace Qweery {\n export type Object = object;\n export type StringPrimitive = string;\n export type NumericalPrimitive = number|bigint|Date;\n export type ArrayPrimitive = Array<any>|ReadonlyArray<any>;\n\n export type WhereOptionKeys<T extends Object> = {\n [K in keyof T]?:\n |T[K]\n |((value: T[K], object: T, index: number, array: T[]) => boolean)\n |WhereOptionValueOperatorsType<T, T[K]>;\n }\n\n export type WhereOptionValueOperatorsType<T extends Object, V> = V extends StringPrimitive\n ? WhereOptionStringOperators<T, V>\n : V extends NumericalPrimitive\n ? WhereOptionNumericalOperators<T, V>\n : V extends ArrayPrimitive\n ? WhereOptionArrayOperators<T, V>\n : WhereOptionValueOperators<T, V>\n\n export interface WhereOptionLogicalOperators<T extends Object> {\n $AND?: ValueOrArray<WhereOptions<T>>;\n $OR?: ValueOrArray<WhereOptions<T>>;\n $NOT?: ValueOrArray<WhereOptions<T>>;\n }\n\n export interface WhereOptionValueOperators<T extends Object, V> extends WhereOptionLogicalOperators<T> {\n equals?: V;\n notEquals?: V;\n }\n\n export interface WhereOptionNumericalOperators<T extends Object, V extends NumericalPrimitive> extends WhereOptionValueOperators<T, V> {\n greaterThan?: V;\n greaterThanOrEqual?: V;\n lessThan?: V;\n lessThanOrEqual?: V;\n }\n\n export interface WhereOptionStringOperators<T extends Object, V extends StringPrimitive> extends WhereOptionValueOperators<T, V> {\n includes?: V;\n startsWith?: V;\n endsWith?: V;\n caseInsensitive?: boolean;\n matches?: RegExp;\n }\n\n export interface WhereOptionArrayOperators<T extends Object, V extends ArrayPrimitive> extends WhereOptionValueOperators<T, V> {\n includesEvery?: V[number][];\n includesSome?: V[number][];\n includesNone?: V[number][];\n }\n\n export type WhereOptions<T extends Object> = WhereOptionKeys<T> & WhereOptionLogicalOperators<T>;\n\n export function normalizeNumericalValue(value: Qweery.NumericalPrimitive): number|bigint {\n return value instanceof Date ? value.getTime() : value;\n }\n}"],"mappings":";;;AAEA,IAAa,SAAb,MAAa,OAAgC;CACzC,AAAgB;CAEhB,YAAY,MAAmB;AAC3B,OAAK,OAAO,MAAM,KAAK,KAAK;;CAGhC,AAAO,MAAM,SAIL;EACJ,IAAI,SAAS,KAAK,KAAK,QAAQ,GAAG,UAAU,QAAQ,QAAQ,KAAK,Y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S,cAAc,OAAM,MAAK,CAAC,MAAM,SAAS,EAAE,CAAC,CACnF,QAAO;AAGX,SAAO;;;;CA2DJ,SAAS,wBAAwB,OAAiD;AACrF,SAAO,iBAAiB,OAAO,MAAM,SAAS,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/classes/Primitive.ts","../src/classes/Where.ts","../src/classes/Qweery.ts"],"sourcesContent":["export class Primitive {\n public static satisfiesValue<T>(value: T, options: Primitive.Filters<T>): boolean {\n if (Primitive.isDefined(options.equals) && value !== options.equals) {\n return false;\n }\n\n if (Primitive.isDefined(options.notEquals) && value === options.notEquals) {\n return false;\n }\n\n return true;\n }\n\n public static statisfiesString(value: Primitive.String, options: Primitive.StringFilters<Primitive.String>): boolean {\n if (options.caseInsensitive) value = value.toLowerCase();\n\n if (!this.satisfiesValue(value, options)) {\n return false;\n }\n\n if (Primitive.isDefined(options.startsWith) && !value.startsWith(options.startsWith)) {\n return false;\n }\n\n if (Primitive.isDefined(options.endsWith) && !value.endsWith(options.endsWith)) {\n return false;\n }\n\n if (Primitive.isDefined(options.includes) && !value.includes(options.includes)) {\n return false;\n }\n\n if (Primitive.isDefined(options.matches) && !options.matches.test(value)) {\n return false;\n }\n\n return true;\n }\n\n public static statisfiesNumerical(value: Primitive.Numerical, options: Primitive.NumericalFilters<Primitive.Numerical>): boolean {\n value = Primitive.normalizeNumericalValue(value);\n\n if (Primitive.isDefined(options.equals) && value !== Primitive.normalizeNumericalValue(options.equals)) {\n return false;\n }\n\n if (Primitive.isDefined(options.notEquals) && value === Primitive.normalizeNumericalValue(options.notEquals)) {\n return false;\n }\n\n if (Primitive.isDefined(options.greaterThan) && value <= Primitive.normalizeNumericalValue(options.greaterThan)) {\n return false;\n }\n\n if (Primitive.isDefined(options.greaterThanOrEqual) && value < Primitive.normalizeNumericalValue(options.greaterThanOrEqual)) {\n return false;\n }\n\n if (Primitive.isDefined(options.lessThan) && value >= Primitive.normalizeNumericalValue(options.lessThan)) {\n return false;\n }\n\n if (Primitive.isDefined(options.lessThanOrEqual) && value > Primitive.normalizeNumericalValue(options.lessThanOrEqual)) {\n return false;\n }\n\n return true;\n }\n\n public static statisfiesArray(value: Primitive.Array, options: Primitive.ArrayFilters<Primitive.Array>): boolean {\n if (!this.satisfiesValue(value, options)) {\n return false;\n }\n\n if (Primitive.isDefined(options.includesEvery) && !options.includesEvery.every(item => value.includes(item))) {\n return false;\n }\n\n if (Primitive.isDefined(options.includesSome) && !options.includesSome.some(item => value.includes(item))) {\n return false;\n }\n\n if (Primitive.isDefined(options.includesNone) && options.includesNone.some(item => value.includes(item))) {\n return false;\n }\n\n if (Primitive.isDefined(options.length) && !Primitive.statisfiesNumerical(value.length, options.length)) {\n return false;\n }\n\n return true;\n }\n}\n\nexport namespace Primitive {\n export function normalizeNumericalValue(value: Primitive.Numerical): number|bigint {\n return value instanceof Date ? value.getTime() : value;\n }\n\n export function isNumerical(value: unknown): value is Primitive.Numerical {\n return typeof value === 'number' || typeof value === 'bigint' || value instanceof Date;\n }\n\n export function isDefined<T>(value: T): value is Exclude<T, undefined> {\n return value !== undefined;\n }\n\n export type String = string;\n export type Numerical = number|bigint|Date;\n export type Array = any[]|readonly any[];\n\n export type FilterType<V> = V extends String\n ? StringFilters<V>\n : V extends Numerical\n ? NumericalFilters<V>\n : V extends Array\n ? ArrayFilters<V>\n : Filters<V>;\n\n export interface Filters<V>{\n equals?: V;\n notEquals?: V;\n }\n\n export interface NumericalFilters<V extends Numerical> extends Filters<V> {\n greaterThan?: V;\n greaterThanOrEqual?: V;\n lessThan?: V;\n lessThanOrEqual?: V;\n }\n\n export interface StringFilters<V extends String> extends Filters<V> {\n includes?: V;\n startsWith?: V;\n endsWith?: V;\n caseInsensitive?: boolean;\n matches?: RegExp;\n }\n\n export interface ArrayFilters<V extends Array> extends Filters<V> {\n includesEvery?: V[number][];\n includesSome?: V[number][];\n includesNone?: V[number][];\n length?: NumericalFilters<number>;\n }\n}","import type { ValueOrArray } from '../helpers/types.js';\nimport { Primitive } from './Primitive.js';\nimport type { Qweery } from './Qweery.js';\n\nexport class Where<T extends Qweery.Object> {\n public readonly data: T[];\n\n public constructor(data: Iterable<T>) {\n this.data = Array.from(data);\n }\n\n public filter(options: Where.Options<T>): T[] {\n return this.data.filter((_, index) => this.satisfiesItem(options, index));\n }\n\n public satisfiesItem(options: Where.Options<T>, index: number): boolean {\n const item = this.data.at(index);\n if (!item) return false;\n\n let value = true;\n\n for (const key in options) {\n if (Where.isLogicalOperator(key)) {\n const conditions = options[key as keyof T] as ValueOrArray<Where.Options<T>>;\n\n switch (key) {\n case '$NOT':\n value = value && !(\n Array.isArray(conditions)\n ? conditions.every(condition => this.satisfiesItem(condition, index))\n : this.satisfiesItem(conditions, index)\n );\n break;\n case '$AND':\n value = value && (\n Array.isArray(conditions)\n ? conditions.every(condition => this.satisfiesItem(condition, index))\n : this.satisfiesItem(conditions, index)\n );\n break;\n case '$OR':\n value = Array.isArray(conditions)\n ? value && conditions.some(condition => this.satisfiesItem(condition, index))\n : value || this.satisfiesItem(conditions, index);\n break;\n }\n\n continue;\n }\n\n\n const filter = options[key as keyof T] as Where.Filter<T, keyof T>;\n const itemValue = item[key as keyof T];\n\n if (filter instanceof Function) {\n value = value && filter(itemValue, item, index, this.data);\n continue;\n }\n\n if (typeof filter === 'object') {\n if (typeof itemValue === 'string') {\n value = value && Primitive.statisfiesString(itemValue, filter as Primitive.StringFilters<Primitive.String>);\n continue;\n }\n\n if (Array.isArray(itemValue)) {\n value = value && Primitive.statisfiesArray(itemValue, filter as Primitive.ArrayFilters<Primitive.Array>);\n continue;\n }\n\n if (Primitive.isNumerical(itemValue)) {\n value = value && Primitive.statisfiesNumerical(itemValue, filter as Primitive.NumericalFilters<Primitive.Numerical>);\n continue;\n }\n\n value = value && Primitive.satisfiesValue(itemValue, filter as Primitive.Filters<any>);\n continue;\n }\n\n value = value && (itemValue === filter);\n }\n\n return value;\n }\n}\n\nexport namespace Where {\n export type KeyFilters<T extends Qweery.Object> = {\n [K in keyof T]?: Filter<T, K>;\n }\n\n export type Filter<T extends Qweery.Object, K extends keyof T> = \n |T[K]\n |((value: T[K], object: T, index: number, array: T[]) => boolean)\n |(Primitive.FilterType<T[K]> & LogicalOperators<T>)\n\n export interface LogicalOperators<T extends Qweery.Object> extends Partial<Record<'$AND'|'$OR'|'$NOT', ValueOrArray<Options<T>>>>{\n //\n }\n\n export type Options<T extends Qweery.Object> = KeyFilters<T> & LogicalOperators<T>;\n\n export function isLogicalOperator(value: unknown): value is keyof LogicalOperators<any> {\n return value === '$AND' || value === '$OR' || value === '$NOT';\n }\n}\n\nconst w = new Where([\n { name: 'Alice', age: 30, sports: ['Football', 'Basketball'] },\n { name: 'Bob', age: 25, sports: ['Football', 'Basketball'] },\n { name: 'Charlie', age: 35, sports: ['Football', 'Basketball'] }\n]);","import { Where } from './Where.js';\n\nexport class Qweery<T extends Qweery.Object> {\n protected readonly data: T[];\n\n constructor(data: Iterable<T>) {\n this.data = Array.from(data);\n }\n\n public query(options: {\n where?: Where.Options<T>;\n skip?: number;\n limit?: number;\n }): T[] {\n\n let result = new Where(this.data).filter(options.where || {});\n\n if (options.skip) {\n result = result.slice(options.skip);\n }\n\n if (options.limit) {\n result = result.slice(0, options.limit);\n }\n\n return result;\n }\n\n public where(options: Where.Options<T>): Qweery<T> {\n return new Qweery(new Where(this.data).filter(options || {}));\n }\n\n public skip(count: number): Qweery<T> {\n return new Qweery(this.data.slice(count));\n }\n\n public take(count: number): Qweery<T> {\n return new Qweery(this.data.slice(0, count));\n }\n\n public count(): number {\n return this.data.length;\n }\n\n public first(): T|undefined {\n return this.data[0];\n }\n\n public last(): T|undefined {\n return this.data[this.data.length - 1];\n }\n\n public toArray(): T[] {\n return this.data;\n }\n}\n\nexport namespace Qweery {\n export type Object = object;\n}"],"mappings":";;;AAAA,IAAa,YAAb,MAAa,UAAU;CACnB,OAAc,eAAkB,OAAU,SAAwC;AAC9E,MAAI,UAAU,UAAU,QAAQ,OAAO,I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KAAK;EAAI,QAAQ,CAAC,YAAY,aAAa;EAAE;CACnE,CAAC;;;;AC7GF,IAAa,SAAb,MAAa,OAAgC;CACzC,AAAmB;CAEnB,YAAY,MAAmB;AAC3B,OAAK,OAAO,MAAM,KAAK,KAAK;;CAGhC,AAAO,MAAM,SAIL;EAEJ,IAAI,SAAS,IAAI,MAAM,KAAK,KAAK,CAAC,OAAO,QAAQ,SAAS,EAAE,CAAC;AAE7D,MAAI,QAAQ,KACR,UAAS,OAAO,MAAM,QAAQ,KAAK;AAGvC,MAAI,QAAQ,MACR,UAAS,OAAO,MAAM,GAAG,QAAQ,MAAM;AAG3C,SAAO;;CAGX,AAAO,MAAM,SAAsC;AAC/C,SAAO,IAAI,OAAO,IAAI,MAAM,KAAK,KAAK,CAAC,OAAO,WAAW,EAAE,CAAC,CAAC;;CAGjE,AAAO,KAAK,OAA0B;AAClC,SAAO,IAAI,OAAO,KAAK,KAAK,MAAM,MAAM,CAAC;;CAG7C,AAAO,KAAK,OAA0B;AAClC,SAAO,IAAI,OAAO,KAAK,KAAK,MAAM,GAAG,MAAM,CAAC;;CAGhD,AAAO,QAAgB;AACnB,SAAO,KAAK,KAAK;;CAGrB,AAAO,QAAqB;AACxB,SAAO,KAAK,KAAK;;CAGrB,AAAO,OAAoB;AACvB,SAAO,KAAK,KAAK,KAAK,KAAK,SAAS;;CAGxC,AAAO,UAAe;AAClB,SAAO,KAAK"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,65 +1,80 @@
|
|
|
1
1
|
//#region src/helpers/types.d.ts
|
|
2
2
|
type ValueOrArray<T> = T | T[];
|
|
3
3
|
//#endregion
|
|
4
|
-
//#region src/classes/
|
|
5
|
-
declare class
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
skip?: number;
|
|
11
|
-
limit?: number;
|
|
12
|
-
}): T[];
|
|
13
|
-
where(options: Qweery.WhereOptions<T>): Qweery<T>;
|
|
14
|
-
skip(count: number): Qweery<T>;
|
|
15
|
-
take(count: number): Qweery<T>;
|
|
16
|
-
count(): number;
|
|
17
|
-
first(): T | undefined;
|
|
18
|
-
last(): T | undefined;
|
|
19
|
-
toArray(): T[];
|
|
20
|
-
private isItemMatch;
|
|
21
|
-
private evaluateLogicalOperator;
|
|
22
|
-
private evaluateValueOperator;
|
|
23
|
-
private evaluateNumericalOperator;
|
|
24
|
-
private evaluateStringOperator;
|
|
25
|
-
private evaluateArrayOperator;
|
|
4
|
+
//#region src/classes/Primitive.d.ts
|
|
5
|
+
declare class Primitive {
|
|
6
|
+
static satisfiesValue<T>(value: T, options: Primitive.Filters<T>): boolean;
|
|
7
|
+
static statisfiesString(value: Primitive.String, options: Primitive.StringFilters<Primitive.String>): boolean;
|
|
8
|
+
static statisfiesNumerical(value: Primitive.Numerical, options: Primitive.NumericalFilters<Primitive.Numerical>): boolean;
|
|
9
|
+
static statisfiesArray(value: Primitive.Array, options: Primitive.ArrayFilters<Primitive.Array>): boolean;
|
|
26
10
|
}
|
|
27
|
-
declare namespace
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type
|
|
32
|
-
type
|
|
33
|
-
type
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
$OR?: ValueOrArray<WhereOptions<T>>;
|
|
37
|
-
$NOT?: ValueOrArray<WhereOptions<T>>;
|
|
38
|
-
}
|
|
39
|
-
interface WhereOptionValueOperators<T extends Object, V> extends WhereOptionLogicalOperators<T> {
|
|
11
|
+
declare namespace Primitive {
|
|
12
|
+
function normalizeNumericalValue(value: Primitive.Numerical): number | bigint;
|
|
13
|
+
function isNumerical(value: unknown): value is Primitive.Numerical;
|
|
14
|
+
function isDefined<T>(value: T): value is Exclude<T, undefined>;
|
|
15
|
+
type String = string;
|
|
16
|
+
type Numerical = number | bigint | Date;
|
|
17
|
+
type Array = any[] | readonly any[];
|
|
18
|
+
type FilterType<V> = V extends String ? StringFilters<V> : V extends Numerical ? NumericalFilters<V> : V extends Array ? ArrayFilters<V> : Filters<V>;
|
|
19
|
+
interface Filters<V> {
|
|
40
20
|
equals?: V;
|
|
41
21
|
notEquals?: V;
|
|
42
22
|
}
|
|
43
|
-
interface
|
|
23
|
+
interface NumericalFilters<V extends Numerical> extends Filters<V> {
|
|
44
24
|
greaterThan?: V;
|
|
45
25
|
greaterThanOrEqual?: V;
|
|
46
26
|
lessThan?: V;
|
|
47
27
|
lessThanOrEqual?: V;
|
|
48
28
|
}
|
|
49
|
-
interface
|
|
29
|
+
interface StringFilters<V extends String> extends Filters<V> {
|
|
50
30
|
includes?: V;
|
|
51
31
|
startsWith?: V;
|
|
52
32
|
endsWith?: V;
|
|
53
33
|
caseInsensitive?: boolean;
|
|
54
34
|
matches?: RegExp;
|
|
55
35
|
}
|
|
56
|
-
interface
|
|
36
|
+
interface ArrayFilters<V extends Array> extends Filters<V> {
|
|
57
37
|
includesEvery?: V[number][];
|
|
58
38
|
includesSome?: V[number][];
|
|
59
39
|
includesNone?: V[number][];
|
|
40
|
+
length?: NumericalFilters<number>;
|
|
60
41
|
}
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/classes/Where.d.ts
|
|
45
|
+
declare class Where<T extends Qweery.Object> {
|
|
46
|
+
readonly data: T[];
|
|
47
|
+
constructor(data: Iterable<T>);
|
|
48
|
+
filter(options: Where.Options<T>): T[];
|
|
49
|
+
satisfiesItem(options: Where.Options<T>, index: number): boolean;
|
|
50
|
+
}
|
|
51
|
+
declare namespace Where {
|
|
52
|
+
type KeyFilters<T extends Qweery.Object> = { [K in keyof T]?: Filter<T, K> };
|
|
53
|
+
type Filter<T extends Qweery.Object, K extends keyof T> = T[K] | ((value: T[K], object: T, index: number, array: T[]) => boolean) | (Primitive.FilterType<T[K]> & LogicalOperators<T>);
|
|
54
|
+
interface LogicalOperators<T extends Qweery.Object> extends Partial<Record<'$AND' | '$OR' | '$NOT', ValueOrArray<Options<T>>>> {}
|
|
55
|
+
type Options<T extends Qweery.Object> = KeyFilters<T> & LogicalOperators<T>;
|
|
56
|
+
function isLogicalOperator(value: unknown): value is keyof LogicalOperators<any>;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/classes/Qweery.d.ts
|
|
60
|
+
declare class Qweery<T extends Qweery.Object> {
|
|
61
|
+
protected readonly data: T[];
|
|
62
|
+
constructor(data: Iterable<T>);
|
|
63
|
+
query(options: {
|
|
64
|
+
where?: Where.Options<T>;
|
|
65
|
+
skip?: number;
|
|
66
|
+
limit?: number;
|
|
67
|
+
}): T[];
|
|
68
|
+
where(options: Where.Options<T>): Qweery<T>;
|
|
69
|
+
skip(count: number): Qweery<T>;
|
|
70
|
+
take(count: number): Qweery<T>;
|
|
71
|
+
count(): number;
|
|
72
|
+
first(): T | undefined;
|
|
73
|
+
last(): T | undefined;
|
|
74
|
+
toArray(): T[];
|
|
75
|
+
}
|
|
76
|
+
declare namespace Qweery {
|
|
77
|
+
type Object = object;
|
|
63
78
|
}
|
|
64
79
|
//#endregion
|
|
65
80
|
export { Qweery, ValueOrArray };
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/helpers/types.ts","../src/classes/Qweery.ts"],"mappings":";KAAY,YAAA,MAAkB,CAAA,GAAE,CAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/helpers/types.ts","../src/classes/Primitive.ts","../src/classes/Where.ts","../src/classes/Qweery.ts"],"mappings":";KAAY,YAAA,MAAkB,CAAA,GAAE,CAAA;;;cCAnB,SAAA;EAAA,OACK,cAAA,GAAA,CAAkB,KAAA,EAAO,CAAA,EAAG,OAAA,EAAS,SAAA,CAAU,OAAA,CAAQ,CAAA;EAAA,OAYvD,gBAAA,CAAiB,KAAA,EAAO,SAAA,CAAU,MAAA,EAAQ,OAAA,EAAS,SAAA,CAAU,aAAA,CAAc,SAAA,CAAU,MAAA;EA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AM,OAAA,CAAQ,CAAA,IAAK,MAAA,CAAO,CAAA;EAIzC,IAAA,CAAK,KAAA,WAAgB,MAAA,CAAO,CAAA;EAI5B,IAAA,CAAK,KAAA,WAAgB,MAAA,CAAO,CAAA;EAI5B,KAAA,CAAA;EAIA,KAAA,CAAA,GAAS,CAAA;EAIT,IAAA,CAAA,GAAQ,CAAA;EAIR,OAAA,CAAA,GAAW,CAAA;AAAA;AAAA,kBAKL,MAAA;EAAA,KACD,MAAA;AAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,65 +1,80 @@
|
|
|
1
1
|
//#region src/helpers/types.d.ts
|
|
2
2
|
type ValueOrArray<T> = T | T[];
|
|
3
3
|
//#endregion
|
|
4
|
-
//#region src/classes/
|
|
5
|
-
declare class
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
skip?: number;
|
|
11
|
-
limit?: number;
|
|
12
|
-
}): T[];
|
|
13
|
-
where(options: Qweery.WhereOptions<T>): Qweery<T>;
|
|
14
|
-
skip(count: number): Qweery<T>;
|
|
15
|
-
take(count: number): Qweery<T>;
|
|
16
|
-
count(): number;
|
|
17
|
-
first(): T | undefined;
|
|
18
|
-
last(): T | undefined;
|
|
19
|
-
toArray(): T[];
|
|
20
|
-
private isItemMatch;
|
|
21
|
-
private evaluateLogicalOperator;
|
|
22
|
-
private evaluateValueOperator;
|
|
23
|
-
private evaluateNumericalOperator;
|
|
24
|
-
private evaluateStringOperator;
|
|
25
|
-
private evaluateArrayOperator;
|
|
4
|
+
//#region src/classes/Primitive.d.ts
|
|
5
|
+
declare class Primitive {
|
|
6
|
+
static satisfiesValue<T>(value: T, options: Primitive.Filters<T>): boolean;
|
|
7
|
+
static statisfiesString(value: Primitive.String, options: Primitive.StringFilters<Primitive.String>): boolean;
|
|
8
|
+
static statisfiesNumerical(value: Primitive.Numerical, options: Primitive.NumericalFilters<Primitive.Numerical>): boolean;
|
|
9
|
+
static statisfiesArray(value: Primitive.Array, options: Primitive.ArrayFilters<Primitive.Array>): boolean;
|
|
26
10
|
}
|
|
27
|
-
declare namespace
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type
|
|
32
|
-
type
|
|
33
|
-
type
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
$OR?: ValueOrArray<WhereOptions<T>>;
|
|
37
|
-
$NOT?: ValueOrArray<WhereOptions<T>>;
|
|
38
|
-
}
|
|
39
|
-
interface WhereOptionValueOperators<T extends Object, V> extends WhereOptionLogicalOperators<T> {
|
|
11
|
+
declare namespace Primitive {
|
|
12
|
+
function normalizeNumericalValue(value: Primitive.Numerical): number | bigint;
|
|
13
|
+
function isNumerical(value: unknown): value is Primitive.Numerical;
|
|
14
|
+
function isDefined<T>(value: T): value is Exclude<T, undefined>;
|
|
15
|
+
type String = string;
|
|
16
|
+
type Numerical = number | bigint | Date;
|
|
17
|
+
type Array = any[] | readonly any[];
|
|
18
|
+
type FilterType<V> = V extends String ? StringFilters<V> : V extends Numerical ? NumericalFilters<V> : V extends Array ? ArrayFilters<V> : Filters<V>;
|
|
19
|
+
interface Filters<V> {
|
|
40
20
|
equals?: V;
|
|
41
21
|
notEquals?: V;
|
|
42
22
|
}
|
|
43
|
-
interface
|
|
23
|
+
interface NumericalFilters<V extends Numerical> extends Filters<V> {
|
|
44
24
|
greaterThan?: V;
|
|
45
25
|
greaterThanOrEqual?: V;
|
|
46
26
|
lessThan?: V;
|
|
47
27
|
lessThanOrEqual?: V;
|
|
48
28
|
}
|
|
49
|
-
interface
|
|
29
|
+
interface StringFilters<V extends String> extends Filters<V> {
|
|
50
30
|
includes?: V;
|
|
51
31
|
startsWith?: V;
|
|
52
32
|
endsWith?: V;
|
|
53
33
|
caseInsensitive?: boolean;
|
|
54
34
|
matches?: RegExp;
|
|
55
35
|
}
|
|
56
|
-
interface
|
|
36
|
+
interface ArrayFilters<V extends Array> extends Filters<V> {
|
|
57
37
|
includesEvery?: V[number][];
|
|
58
38
|
includesSome?: V[number][];
|
|
59
39
|
includesNone?: V[number][];
|
|
40
|
+
length?: NumericalFilters<number>;
|
|
60
41
|
}
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/classes/Where.d.ts
|
|
45
|
+
declare class Where<T extends Qweery.Object> {
|
|
46
|
+
readonly data: T[];
|
|
47
|
+
constructor(data: Iterable<T>);
|
|
48
|
+
filter(options: Where.Options<T>): T[];
|
|
49
|
+
satisfiesItem(options: Where.Options<T>, index: number): boolean;
|
|
50
|
+
}
|
|
51
|
+
declare namespace Where {
|
|
52
|
+
type KeyFilters<T extends Qweery.Object> = { [K in keyof T]?: Filter<T, K> };
|
|
53
|
+
type Filter<T extends Qweery.Object, K extends keyof T> = T[K] | ((value: T[K], object: T, index: number, array: T[]) => boolean) | (Primitive.FilterType<T[K]> & LogicalOperators<T>);
|
|
54
|
+
interface LogicalOperators<T extends Qweery.Object> extends Partial<Record<'$AND' | '$OR' | '$NOT', ValueOrArray<Options<T>>>> {}
|
|
55
|
+
type Options<T extends Qweery.Object> = KeyFilters<T> & LogicalOperators<T>;
|
|
56
|
+
function isLogicalOperator(value: unknown): value is keyof LogicalOperators<any>;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/classes/Qweery.d.ts
|
|
60
|
+
declare class Qweery<T extends Qweery.Object> {
|
|
61
|
+
protected readonly data: T[];
|
|
62
|
+
constructor(data: Iterable<T>);
|
|
63
|
+
query(options: {
|
|
64
|
+
where?: Where.Options<T>;
|
|
65
|
+
skip?: number;
|
|
66
|
+
limit?: number;
|
|
67
|
+
}): T[];
|
|
68
|
+
where(options: Where.Options<T>): Qweery<T>;
|
|
69
|
+
skip(count: number): Qweery<T>;
|
|
70
|
+
take(count: number): Qweery<T>;
|
|
71
|
+
count(): number;
|
|
72
|
+
first(): T | undefined;
|
|
73
|
+
last(): T | undefined;
|
|
74
|
+
toArray(): T[];
|
|
75
|
+
}
|
|
76
|
+
declare namespace Qweery {
|
|
77
|
+
type Object = object;
|
|
63
78
|
}
|
|
64
79
|
//#endregion
|
|
65
80
|
export { Qweery, ValueOrArray };
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/helpers/types.ts","../src/classes/Qweery.ts"],"mappings":";KAAY,YAAA,MAAkB,CAAA,GAAE,CAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/helpers/types.ts","../src/classes/Primitive.ts","../src/classes/Where.ts","../src/classes/Qweery.ts"],"mappings":";KAAY,YAAA,MAAkB,CAAA,GAAE,CAAA;;;cCAnB,SAAA;EAAA,OACK,cAAA,GAAA,CAAkB,KAAA,EAAO,CAAA,EAAG,OAAA,EAAS,SAAA,CAAU,OAAA,CAAQ,CAAA;EAAA,OAYvD,gBAAA,CAAiB,KAAA,EAAO,SAAA,CAAU,MAAA,EAAQ,OAAA,EAAS,SAAA,CAAU,aAAA,CAAc,SAAA,CAAU,MAAA;EAAA,OA0BrF,mBAAA,CAAoB,KAAA,EAAO,SAAA,CAAU,SAAA,EAAW,OAAA,EAAS,SAAA,CAAU,gBAAA,CAAiB,SAAA,CAAU,SAAA;EAAA,OA8B9F,eAAA,CAAgB,KAAA,EAAO,SAAA,CAAU,KAAA,EAAO,OAAA,EAAS,SAAA,CAAU,YAAA,CAAa,SAAA,CAAU,KAAA;AAAA;AAAA,kBAyBnF,SAAA;EAAA,SACG,uBAAA,CAAwB,KAAA,EAAO,SAAA,CAAU,SAAA;EAAA,SAIzC,WAAA,CAAY,KAAA,YAAiB,KAAA,IAAS,SAAA,CAAU,SAAA;EAAA,SAIhD,SAAA,GAAA,CAAa,KAAA,EAAO,CAAA,GAAI,KAAA,IAAS,OAAA,CAAQ,CAAA;EAAA,KAI7C,MAAA;EAAA,KACA,SAAA,qBAA0B,IAAA;EAAA,KAC1B,KAAA;EAAA,KAEA,UAAA,MAAgB,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,EAAQ,CAAA,EAAG,KAAA,UAAe,KAAA,EAAO,CAAA,mBAC/C,SAAA,CAAU,UAAA,CAAW,CAAA,CAAE,CAAA,KAAM,gBAAA,CAAiB,CAAA;EAAA,UAEnC,gBAAA,WAA2B,MAAA,CAAO,MAAA,UAAgB,OAAA,CAAQ,MAAA,0BAA4B,YAAA,CAAa,OAAA,CAAQ,CAAA;EAAA,KAIhH,OAAA,WAAkB,MAAA,CAAO,MAAA,IAAU,UAAA,CAAW,CAAA,IAAK,gBAAA,CAAiB,CAAA;EAAA,SAEhE,iBAAA,CAAkB,KAAA,YAAiB,KAAA,UAAe,gBAAA;AAAA;;;cCpGzD,MAAA,WAAiB,MAAA,CAAO,MAAA;EAAA,mBACd,IAAA,EAAM,CAAA;cAEb,IAAA,EAAM,QAAA,CAAS,CAAA;EAIpB,KAAA,CAAM,OAAA;IACT,KAAA,GAAQ,KAAA,CAAM,OAAA,CAAQ,CAAA;IACtB,IAAA;IACA,KAAA;EAAA,IACA,CAAA;EAeG,KAAA,CAAM,OAAA,EAAS,KAAA,CAAM,OAAA,CAAQ,CAAA,IAAK,MAAA,CAAO,CAAA;EAIzC,IAAA,CAAK,KAAA,WAAgB,MAAA,CAAO,CAAA;EAI5B,IAAA,CAAK,KAAA,WAAgB,MAAA,CAAO,CAAA;EAI5B,KAAA,CAAA;EAIA,KAAA,CAAA,GAAS,CAAA;EAIT,IAAA,CAAA,GAAQ,CAAA;EAIR,OAAA,CAAA,GAAW,CAAA;AAAA;AAAA,kBAKL,MAAA;EAAA,KACD,MAAA;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,135 @@
|
|
|
1
|
+
//#region src/classes/Primitive.ts
|
|
2
|
+
var Primitive = class Primitive {
|
|
3
|
+
static satisfiesValue(value, options) {
|
|
4
|
+
if (Primitive.isDefined(options.equals) && value !== options.equals) return false;
|
|
5
|
+
if (Primitive.isDefined(options.notEquals) && value === options.notEquals) return false;
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
static statisfiesString(value, options) {
|
|
9
|
+
if (options.caseInsensitive) value = value.toLowerCase();
|
|
10
|
+
if (!this.satisfiesValue(value, options)) return false;
|
|
11
|
+
if (Primitive.isDefined(options.startsWith) && !value.startsWith(options.startsWith)) return false;
|
|
12
|
+
if (Primitive.isDefined(options.endsWith) && !value.endsWith(options.endsWith)) return false;
|
|
13
|
+
if (Primitive.isDefined(options.includes) && !value.includes(options.includes)) return false;
|
|
14
|
+
if (Primitive.isDefined(options.matches) && !options.matches.test(value)) return false;
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
static statisfiesNumerical(value, options) {
|
|
18
|
+
value = Primitive.normalizeNumericalValue(value);
|
|
19
|
+
if (Primitive.isDefined(options.equals) && value !== Primitive.normalizeNumericalValue(options.equals)) return false;
|
|
20
|
+
if (Primitive.isDefined(options.notEquals) && value === Primitive.normalizeNumericalValue(options.notEquals)) return false;
|
|
21
|
+
if (Primitive.isDefined(options.greaterThan) && value <= Primitive.normalizeNumericalValue(options.greaterThan)) return false;
|
|
22
|
+
if (Primitive.isDefined(options.greaterThanOrEqual) && value < Primitive.normalizeNumericalValue(options.greaterThanOrEqual)) return false;
|
|
23
|
+
if (Primitive.isDefined(options.lessThan) && value >= Primitive.normalizeNumericalValue(options.lessThan)) return false;
|
|
24
|
+
if (Primitive.isDefined(options.lessThanOrEqual) && value > Primitive.normalizeNumericalValue(options.lessThanOrEqual)) return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
static statisfiesArray(value, options) {
|
|
28
|
+
if (!this.satisfiesValue(value, options)) return false;
|
|
29
|
+
if (Primitive.isDefined(options.includesEvery) && !options.includesEvery.every((item) => value.includes(item))) return false;
|
|
30
|
+
if (Primitive.isDefined(options.includesSome) && !options.includesSome.some((item) => value.includes(item))) return false;
|
|
31
|
+
if (Primitive.isDefined(options.includesNone) && options.includesNone.some((item) => value.includes(item))) return false;
|
|
32
|
+
if (Primitive.isDefined(options.length) && !Primitive.statisfiesNumerical(value.length, options.length)) return false;
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
(function(_Primitive) {
|
|
37
|
+
function normalizeNumericalValue(value) {
|
|
38
|
+
return value instanceof Date ? value.getTime() : value;
|
|
39
|
+
}
|
|
40
|
+
_Primitive.normalizeNumericalValue = normalizeNumericalValue;
|
|
41
|
+
function isNumerical(value) {
|
|
42
|
+
return typeof value === "number" || typeof value === "bigint" || value instanceof Date;
|
|
43
|
+
}
|
|
44
|
+
_Primitive.isNumerical = isNumerical;
|
|
45
|
+
function isDefined(value) {
|
|
46
|
+
return value !== void 0;
|
|
47
|
+
}
|
|
48
|
+
_Primitive.isDefined = isDefined;
|
|
49
|
+
})(Primitive || (Primitive = {}));
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/classes/Where.ts
|
|
53
|
+
var Where = class Where {
|
|
54
|
+
data;
|
|
55
|
+
constructor(data) {
|
|
56
|
+
this.data = Array.from(data);
|
|
57
|
+
}
|
|
58
|
+
filter(options) {
|
|
59
|
+
return this.data.filter((_, index) => this.satisfiesItem(options, index));
|
|
60
|
+
}
|
|
61
|
+
satisfiesItem(options, index) {
|
|
62
|
+
const item = this.data.at(index);
|
|
63
|
+
if (!item) return false;
|
|
64
|
+
let value = true;
|
|
65
|
+
for (const key in options) {
|
|
66
|
+
if (Where.isLogicalOperator(key)) {
|
|
67
|
+
const conditions = options[key];
|
|
68
|
+
switch (key) {
|
|
69
|
+
case "$NOT":
|
|
70
|
+
value = value && !(Array.isArray(conditions) ? conditions.every((condition) => this.satisfiesItem(condition, index)) : this.satisfiesItem(conditions, index));
|
|
71
|
+
break;
|
|
72
|
+
case "$AND":
|
|
73
|
+
value = value && (Array.isArray(conditions) ? conditions.every((condition) => this.satisfiesItem(condition, index)) : this.satisfiesItem(conditions, index));
|
|
74
|
+
break;
|
|
75
|
+
case "$OR":
|
|
76
|
+
value = Array.isArray(conditions) ? value && conditions.some((condition) => this.satisfiesItem(condition, index)) : value || this.satisfiesItem(conditions, index);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const filter = options[key];
|
|
82
|
+
const itemValue = item[key];
|
|
83
|
+
if (filter instanceof Function) {
|
|
84
|
+
value = value && filter(itemValue, item, index, this.data);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (typeof filter === "object") {
|
|
88
|
+
if (typeof itemValue === "string") {
|
|
89
|
+
value = value && Primitive.statisfiesString(itemValue, filter);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (Array.isArray(itemValue)) {
|
|
93
|
+
value = value && Primitive.statisfiesArray(itemValue, filter);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (Primitive.isNumerical(itemValue)) {
|
|
97
|
+
value = value && Primitive.statisfiesNumerical(itemValue, filter);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
value = value && Primitive.satisfiesValue(itemValue, filter);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
value = value && itemValue === filter;
|
|
104
|
+
}
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
(function(_Where) {
|
|
109
|
+
function isLogicalOperator(value) {
|
|
110
|
+
return value === "$AND" || value === "$OR" || value === "$NOT";
|
|
111
|
+
}
|
|
112
|
+
_Where.isLogicalOperator = isLogicalOperator;
|
|
113
|
+
})(Where || (Where = {}));
|
|
114
|
+
new Where([
|
|
115
|
+
{
|
|
116
|
+
name: "Alice",
|
|
117
|
+
age: 30,
|
|
118
|
+
sports: ["Football", "Basketball"]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "Bob",
|
|
122
|
+
age: 25,
|
|
123
|
+
sports: ["Football", "Basketball"]
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "Charlie",
|
|
127
|
+
age: 35,
|
|
128
|
+
sports: ["Football", "Basketball"]
|
|
129
|
+
}
|
|
130
|
+
]);
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
1
133
|
//#region src/classes/Qweery.ts
|
|
2
134
|
var Qweery = class Qweery {
|
|
3
135
|
data;
|
|
@@ -5,13 +137,13 @@ var Qweery = class Qweery {
|
|
|
5
137
|
this.data = Array.from(data);
|
|
6
138
|
}
|
|
7
139
|
query(options) {
|
|
8
|
-
let result = this.data.filter(
|
|
140
|
+
let result = new Where(this.data).filter(options.where || {});
|
|
9
141
|
if (options.skip) result = result.slice(options.skip);
|
|
10
142
|
if (options.limit) result = result.slice(0, options.limit);
|
|
11
143
|
return result;
|
|
12
144
|
}
|
|
13
145
|
where(options) {
|
|
14
|
-
return new Qweery(this.data.filter(
|
|
146
|
+
return new Qweery(new Where(this.data).filter(options || {}));
|
|
15
147
|
}
|
|
16
148
|
skip(count) {
|
|
17
149
|
return new Qweery(this.data.slice(count));
|
|
@@ -31,79 +163,7 @@ var Qweery = class Qweery {
|
|
|
31
163
|
toArray() {
|
|
32
164
|
return this.data;
|
|
33
165
|
}
|
|
34
|
-
isItemMatch(index, options) {
|
|
35
|
-
const item = this.data.at(index);
|
|
36
|
-
if (!item) return false;
|
|
37
|
-
const keys = Object.keys(options);
|
|
38
|
-
for (const key of keys) {
|
|
39
|
-
if (key.toString().startsWith("$") || options[key] === void 0) continue;
|
|
40
|
-
let value;
|
|
41
|
-
if (typeof options[key] === "function") value = options[key](item[key], item, index, this.data);
|
|
42
|
-
else if (typeof options[key] === "object") if (typeof item[key] === "string") value = this.evaluateStringOperator(index, key, options[key]);
|
|
43
|
-
else if (typeof item[key] === "number" || typeof item[key] === "bigint" || item[key] instanceof Date) value = this.evaluateNumericalOperator(index, key, options[key]);
|
|
44
|
-
else if (Array.isArray(item[key])) value = this.evaluateArrayOperator(index, key, options[key]);
|
|
45
|
-
else value = this.evaluateValueOperator(index, key, options[key]);
|
|
46
|
-
else value = item[key] === options[key];
|
|
47
|
-
if (!value) return false;
|
|
48
|
-
}
|
|
49
|
-
return this.evaluateLogicalOperator(index, options);
|
|
50
|
-
}
|
|
51
|
-
evaluateLogicalOperator(index, options) {
|
|
52
|
-
if (options.$NOT) {
|
|
53
|
-
for (const option of Array.isArray(options.$NOT) ? options.$NOT : [options.$NOT]) if (this.isItemMatch(index, option)) return false;
|
|
54
|
-
}
|
|
55
|
-
if (options.$AND) {
|
|
56
|
-
for (const option of Array.isArray(options.$AND) ? options.$AND : [options.$AND]) if (!this.isItemMatch(index, option)) return false;
|
|
57
|
-
}
|
|
58
|
-
if (options.$OR) {
|
|
59
|
-
let hasMatch = false;
|
|
60
|
-
for (const option of Array.isArray(options.$OR) ? options.$OR : [options.$OR]) if (this.isItemMatch(index, option)) {
|
|
61
|
-
hasMatch = true;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
if (!hasMatch) return false;
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
evaluateValueOperator(index, property, operator) {
|
|
69
|
-
if ("equals" in operator && operator.equals !== this.data[index][property]) return false;
|
|
70
|
-
if ("notEquals" in operator && operator.notEquals === this.data[index][property]) return false;
|
|
71
|
-
return this.evaluateLogicalOperator(index, operator);
|
|
72
|
-
}
|
|
73
|
-
evaluateNumericalOperator(index, property, operator) {
|
|
74
|
-
if (!this.evaluateValueOperator(index, property, operator)) return false;
|
|
75
|
-
const value = Qweery.normalizeNumericalValue(this.data[index][property]);
|
|
76
|
-
if (operator.greaterThan !== void 0 && !(value > Qweery.normalizeNumericalValue(operator.greaterThan))) return false;
|
|
77
|
-
if (operator.greaterThanOrEqual !== void 0 && !(value >= Qweery.normalizeNumericalValue(operator.greaterThanOrEqual))) return false;
|
|
78
|
-
if (operator.lessThan !== void 0 && !(value < Qweery.normalizeNumericalValue(operator.lessThan))) return false;
|
|
79
|
-
if (operator.lessThanOrEqual !== void 0 && !(value <= Qweery.normalizeNumericalValue(operator.lessThanOrEqual))) return false;
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
evaluateStringOperator(index, property, operator) {
|
|
83
|
-
if (!this.evaluateValueOperator(index, property, operator)) return false;
|
|
84
|
-
let value = this.data[index][property];
|
|
85
|
-
if (operator.caseInsensitive) value = value.toLowerCase();
|
|
86
|
-
if (operator.includes && !value.includes(operator.caseInsensitive ? operator.includes.toLowerCase() : operator.includes)) return false;
|
|
87
|
-
if (operator.startsWith && !value.startsWith(operator.caseInsensitive ? operator.startsWith.toLowerCase() : operator.startsWith)) return false;
|
|
88
|
-
if (operator.endsWith && !value.endsWith(operator.caseInsensitive ? operator.endsWith.toLowerCase() : operator.endsWith)) return false;
|
|
89
|
-
if (operator.matches && !operator.matches.test(value)) return false;
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
evaluateArrayOperator(index, property, operator) {
|
|
93
|
-
if (!this.evaluateValueOperator(index, property, operator)) return false;
|
|
94
|
-
const value = this.data[index][property];
|
|
95
|
-
if ("includesEvery" in operator && operator.includesEvery?.every((v) => value.includes(v))) return true;
|
|
96
|
-
if ("includesSome" in operator && operator.includesSome?.some((v) => value.includes(v))) return true;
|
|
97
|
-
if ("includesNone" in operator && operator.includesNone?.every((v) => !value.includes(v))) return true;
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
166
|
};
|
|
101
|
-
(function(_Qweery) {
|
|
102
|
-
function normalizeNumericalValue(value) {
|
|
103
|
-
return value instanceof Date ? value.getTime() : value;
|
|
104
|
-
}
|
|
105
|
-
_Qweery.normalizeNumericalValue = normalizeNumericalValue;
|
|
106
|
-
})(Qweery || (Qweery = {}));
|
|
107
167
|
|
|
108
168
|
//#endregion
|
|
109
169
|
export { Qweery };
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/classes/Qweery.ts"],"sourcesContent":["import type { ValueOrArray } from '../helpers/types.js';\n\nexport class Qweery<T extends Qweery.Object> {\n public readonly data: T[];\n\n constructor(data: Iterable<T>) {\n this.data = Array.from(data);\n }\n\n public query(options: {\n where?: Qweery.WhereOptions<T>;\n skip?: number;\n limit?: number;\n }): T[] {\n let result = this.data.filter((_, index) => options.where ? this.isItemMatch(index, options.where) : true);\n\n if (options.skip) {\n result = result.slice(options.skip);\n }\n\n if (options.limit) {\n result = result.slice(0, options.limit);\n }\n\n return result;\n }\n\n public where(options: Qweery.WhereOptions<T>): Qweery<T> {\n return new Qweery(this.data.filter((_, index) => this.isItemMatch(index, options)));\n }\n\n public skip(count: number): Qweery<T> {\n return new Qweery(this.data.slice(count));\n }\n\n public take(count: number): Qweery<T> {\n return new Qweery(this.data.slice(0, count));\n }\n\n public count(): number {\n return this.data.length;\n }\n\n public first(): T|undefined {\n return this.data[0];\n }\n\n public last(): T|undefined {\n return this.data[this.data.length - 1];\n }\n\n public toArray(): T[] {\n return this.data;\n }\n\n private isItemMatch(index: number, options: Qweery.WhereOptions<T>): boolean {\n const item = this.data.at(index);\n if (!item) return false\n\n const keys = Object.keys(options) as (keyof T)[];\n\n for (const key of keys) {\n if (key.toString().startsWith('$') || options[key] === undefined) continue;\n\n let value: boolean;\n\n if (typeof options[key] === 'function') {\n value = options[key](item[key], item, index, this.data);\n } else if (typeof options[key] === 'object') {\n if (typeof item[key] === 'string') {\n value = this.evaluateStringOperator(\n index,\n key,\n options[key] as Qweery.WhereOptionStringOperators<T, Qweery.StringPrimitive>\n );\n } else if (\n typeof item[key] === 'number' ||\n typeof item[key] === 'bigint' ||\n item[key] instanceof Date\n ) {\n value = this.evaluateNumericalOperator(\n index,\n key,\n options[key] as Qweery.WhereOptionNumericalOperators<T, Qweery.NumericalPrimitive>\n );\n } else if (Array.isArray(item[key])) {\n value = this.evaluateArrayOperator(\n index,\n key,\n options[key] as Qweery.WhereOptionArrayOperators<T, Qweery.ArrayPrimitive>\n );\n } else {\n value = this.evaluateValueOperator(\n index,\n key,\n options[key] as Qweery.WhereOptionValueOperators<T, any>\n );\n }\n } else {\n value = item[key] === options[key];\n }\n\n if (!value) return false;\n }\n\n return this.evaluateLogicalOperator(index, options);\n }\n\n private evaluateLogicalOperator(index: number, options: Qweery.WhereOptionLogicalOperators<T>): boolean {\n let value = true;\n\n if (options.$NOT) {\n for (const option of Array.isArray(options.$NOT) ? options.$NOT : [options.$NOT]) {\n if (this.isItemMatch(index, option)) return false;\n }\n }\n\n if (options.$AND) {\n for (const option of Array.isArray(options.$AND) ? options.$AND : [options.$AND]) {\n if (!this.isItemMatch(index, option)) return false;\n }\n }\n\n if (options.$OR) {\n let hasMatch = false;\n\n for (const option of Array.isArray( options.$OR) ? options.$OR : [ options.$OR]) {\n if (this.isItemMatch(index, option)) {\n hasMatch = true;\n break;\n }\n }\n\n if (!hasMatch) return false;\n }\n\n return true;\n }\n\n private evaluateValueOperator(index: number, property: keyof T, operator: Qweery.WhereOptionValueOperators<T, any>): boolean {\n if ('equals' in operator && operator.equals !== this.data[index][property]) {\n return false;\n }\n\n if ('notEquals' in operator && operator.notEquals === this.data[index][property]) {\n return false;\n }\n\n return true && this.evaluateLogicalOperator(index, operator);\n }\n\n private evaluateNumericalOperator(index: number, property: keyof T, operator: Qweery.WhereOptionNumericalOperators<T, Qweery.NumericalPrimitive>): boolean {\n if (!this.evaluateValueOperator(index, property, operator)) return false;\n\n const value = Qweery.normalizeNumericalValue(this.data[index][property] as Qweery.NumericalPrimitive);\n\n if (operator.greaterThan !== undefined && !(value > Qweery.normalizeNumericalValue(operator.greaterThan))) {\n return false;\n }\n\n if (operator.greaterThanOrEqual !== undefined && !(value >= Qweery.normalizeNumericalValue(operator.greaterThanOrEqual))) {\n return false;\n }\n\n if (operator.lessThan !== undefined && !(value < Qweery.normalizeNumericalValue(operator.lessThan))) {\n return false;\n }\n\n if (operator.lessThanOrEqual !== undefined && !(value <= Qweery.normalizeNumericalValue(operator.lessThanOrEqual))) {\n return false;\n }\n\n return true;\n }\n\n private evaluateStringOperator(index: number, property: keyof T, operator: Qweery.WhereOptionStringOperators<T, Qweery.StringPrimitive>): boolean {\n if (!this.evaluateValueOperator(index, property, operator)) return false;\n\n let value = this.data[index][property] as Qweery.StringPrimitive;\n\n if (operator.caseInsensitive) {\n value = value.toLowerCase();\n }\n\n if (\n operator.includes &&\n !value.includes(\n operator.caseInsensitive\n ? operator.includes.toLowerCase()\n : operator.includes\n )\n ) {\n return false;\n }\n\n if (\n operator.startsWith && \n !value.startsWith(\n operator.caseInsensitive\n ? operator.startsWith.toLowerCase()\n : operator.startsWith\n )\n ) {\n return false;\n }\n\n if (\n operator.endsWith &&\n !value.endsWith(\n operator.caseInsensitive\n ? operator.endsWith.toLowerCase()\n : operator.endsWith\n )\n ) {\n return false;\n }\n\n if (operator.matches && !operator.matches.test(value)) {\n return false;\n }\n\n return true;\n }\n\n private evaluateArrayOperator(index: number, property: keyof T, operator: Qweery.WhereOptionArrayOperators<T, Qweery.ArrayPrimitive>): boolean {\n if (!this.evaluateValueOperator(index, property, operator)) return false;\n\n const value = this.data[index][property] as Qweery.ArrayPrimitive;\n\n if ('includesEvery' in operator && operator.includesEvery?.every(v => value.includes(v))) {\n return true;\n }\n\n if ('includesSome' in operator && operator.includesSome?.some(v => value.includes(v))) {\n return true;\n }\n\n if ('includesNone' in operator && operator.includesNone?.every(v => !value.includes(v))) {\n return true;\n }\n\n return true;\n }\n}\n\nexport namespace Qweery {\n export type Object = object;\n export type StringPrimitive = string;\n export type NumericalPrimitive = number|bigint|Date;\n export type ArrayPrimitive = Array<any>|ReadonlyArray<any>;\n\n export type WhereOptionKeys<T extends Object> = {\n [K in keyof T]?:\n |T[K]\n |((value: T[K], object: T, index: number, array: T[]) => boolean)\n |WhereOptionValueOperatorsType<T, T[K]>;\n }\n\n export type WhereOptionValueOperatorsType<T extends Object, V> = V extends StringPrimitive\n ? WhereOptionStringOperators<T, V>\n : V extends NumericalPrimitive\n ? WhereOptionNumericalOperators<T, V>\n : V extends ArrayPrimitive\n ? WhereOptionArrayOperators<T, V>\n : WhereOptionValueOperators<T, V>\n\n export interface WhereOptionLogicalOperators<T extends Object> {\n $AND?: ValueOrArray<WhereOptions<T>>;\n $OR?: ValueOrArray<WhereOptions<T>>;\n $NOT?: ValueOrArray<WhereOptions<T>>;\n }\n\n export interface WhereOptionValueOperators<T extends Object, V> extends WhereOptionLogicalOperators<T> {\n equals?: V;\n notEquals?: V;\n }\n\n export interface WhereOptionNumericalOperators<T extends Object, V extends NumericalPrimitive> extends WhereOptionValueOperators<T, V> {\n greaterThan?: V;\n greaterThanOrEqual?: V;\n lessThan?: V;\n lessThanOrEqual?: V;\n }\n\n export interface WhereOptionStringOperators<T extends Object, V extends StringPrimitive> extends WhereOptionValueOperators<T, V> {\n includes?: V;\n startsWith?: V;\n endsWith?: V;\n caseInsensitive?: boolean;\n matches?: RegExp;\n }\n\n export interface WhereOptionArrayOperators<T extends Object, V extends ArrayPrimitive> extends WhereOptionValueOperators<T, V> {\n includesEvery?: V[number][];\n includesSome?: V[number][];\n includesNone?: V[number][];\n }\n\n export type WhereOptions<T extends Object> = WhereOptionKeys<T> & WhereOptionLogicalOperators<T>;\n\n export function normalizeNumericalValue(value: Qweery.NumericalPrimitive): number|bigint {\n return value instanceof Date ? value.getTime() : value;\n }\n}"],"mappings":";AAEA,IAAa,SAAb,MAAa,OAAgC;CACzC,AAAgB;CAEhB,YAAY,MAAmB;AAC3B,OAAK,OAAO,MAAM,KAAK,KAAK;;CAGhC,AAAO,MAAM,SAIL;EACJ,IAAI,SAAS,KAAK,KAAK,QAAQ,GAAG,UAAU,QAAQ,QAAQ,KAAK,YAAY,OAAO,QAAQ,MAAM,GAAG,KAAK;AAE1G,MAAI,QAAQ,KACR,UAAS,OAAO,MAAM,QAAQ,KAAK;AAGvC,MAAI,QAAQ,MACR,UAAS,OAAO,MAAM,GAAG,QAAQ,MAAM;AAG3C,SAAO;;CAGX,AAAO,MAAM,SAA4C;AACrD,SAAO,IAAI,OAAO,KAAK,KAAK,QAAQ,GAAG,UAAU,KAAK,YAAY,OAAO,QAA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AAwB,SAAS,gBAAgB,EAC7G,QAAO;AAGX,SAAO;;CAGX,AAAQ,uBAAuB,OAAe,UAAmB,UAAiF;AAC9I,MAAI,CAAC,KAAK,sBAAsB,OAAO,UAAU,SAAS,CAAE,QAAO;EAEnE,IAAI,QAAQ,KAAK,KAAK,OAAO;AAE7B,MAAI,SAAS,gBACT,SAAQ,MAAM,aAAa;AAG/B,MACI,SAAS,YACT,CAAC,MAAM,SACH,SAAS,kBACP,SAAS,SAAS,aAAa,GAC/B,SAAS,SACd,CAED,QAAO;AAGX,MACI,SAAS,cACT,CAAC,MAAM,WACH,SAAS,kBACH,SAAS,WAAW,aAAa,GACjC,SAAS,WAClB,CAED,QAAO;AAGX,MACI,SAAS,YACT,CAAC,MAAM,SACH,SAAS,kBACH,SAAS,SAAS,aAAa,GAC/B,SAAS,SAClB,CAED,QAAO;AAGX,MAAI,SAAS,WAAW,CAAC,SAAS,QAAQ,KAAK,MAAM,CACjD,QAAO;AAGX,SAAO;;CAGX,AAAQ,sBAAsB,OAAe,UAAmB,UAA+E;AAC3I,MAAI,CAAC,KAAK,sBAAsB,OAAO,UAAU,SAAS,CAAE,QAAO;EAEnE,MAAM,QAAQ,KAAK,KAAK,OAAO;AAE/B,MAAI,mBAAmB,YAAY,SAAS,eAAe,OAAM,MAAK,MAAM,SAAS,EAAE,CAAC,CACpF,QAAO;AAGX,MAAI,kBAAkB,YAAY,SAAS,cAAc,MAAK,MAAK,MAAM,SAAS,EAAE,CAAC,CACjF,QAAO;AAGX,MAAI,kBAAkB,YAAY,SAAS,cAAc,OAAM,MAAK,CAAC,MAAM,SAAS,EAAE,CAAC,CACnF,QAAO;AAGX,SAAO;;;;CA2DJ,SAAS,wBAAwB,OAAiD;AACrF,SAAO,iBAAiB,OAAO,MAAM,SAAS,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/classes/Primitive.ts","../src/classes/Where.ts","../src/classes/Qweery.ts"],"sourcesContent":["export class Primitive {\n public static satisfiesValue<T>(value: T, options: Primitive.Filters<T>): boolean {\n if (Primitive.isDefined(options.equals) && value !== options.equals) {\n return false;\n }\n\n if (Primitive.isDefined(options.notEquals) && value === options.notEquals) {\n return false;\n }\n\n return true;\n }\n\n public static statisfiesString(value: Primitive.String, options: Primitive.StringFilters<Primitive.String>): boolean {\n if (options.caseInsensitive) value = value.toLowerCase();\n\n if (!this.satisfiesValue(value, options)) {\n return false;\n }\n\n if (Primitive.isDefined(options.startsWith) && !value.startsWith(options.startsWith)) {\n return false;\n }\n\n if (Primitive.isDefined(options.endsWith) && !value.endsWith(options.endsWith)) {\n return false;\n }\n\n if (Primitive.isDefined(options.includes) && !value.includes(options.includes)) {\n return false;\n }\n\n if (Primitive.isDefined(options.matches) && !options.matches.test(value)) {\n return false;\n }\n\n return true;\n }\n\n public static statisfiesNumerical(value: Primitive.Numerical, options: Primitive.NumericalFilters<Primitive.Numerical>): boolean {\n value = Primitive.normalizeNumericalValue(value);\n\n if (Primitive.isDefined(options.equals) && value !== Primitive.normalizeNumericalValue(options.equals)) {\n return false;\n }\n\n if (Primitive.isDefined(options.notEquals) && value === Primitive.normalizeNumericalValue(options.notEquals)) {\n return false;\n }\n\n if (Primitive.isDefined(options.greaterThan) && value <= Primitive.normalizeNumericalValue(options.greaterThan)) {\n return false;\n }\n\n if (Primitive.isDefined(options.greaterThanOrEqual) && value < Primitive.normalizeNumericalValue(options.greaterThanOrEqual)) {\n return false;\n }\n\n if (Primitive.isDefined(options.lessThan) && value >= Primitive.normalizeNumericalValue(options.lessThan)) {\n return false;\n }\n\n if (Primitive.isDefined(options.lessThanOrEqual) && value > Primitive.normalizeNumericalValue(options.lessThanOrEqual)) {\n return false;\n }\n\n return true;\n }\n\n public static statisfiesArray(value: Primitive.Array, options: Primitive.ArrayFilters<Primitive.Array>): boolean {\n if (!this.satisfiesValue(value, options)) {\n return false;\n }\n\n if (Primitive.isDefined(options.includesEvery) && !options.includesEvery.every(item => value.includes(item))) {\n return false;\n }\n\n if (Primitive.isDefined(options.includesSome) && !options.includesSome.some(item => value.includes(item))) {\n return false;\n }\n\n if (Primitive.isDefined(options.includesNone) && options.includesNone.some(item => value.includes(item))) {\n return false;\n }\n\n if (Primitive.isDefined(options.length) && !Primitive.statisfiesNumerical(value.length, options.length)) {\n return false;\n }\n\n return true;\n }\n}\n\nexport namespace Primitive {\n export function normalizeNumericalValue(value: Primitive.Numerical): number|bigint {\n return value instanceof Date ? value.getTime() : value;\n }\n\n export function isNumerical(value: unknown): value is Primitive.Numerical {\n return typeof value === 'number' || typeof value === 'bigint' || value instanceof Date;\n }\n\n export function isDefined<T>(value: T): value is Exclude<T, undefined> {\n return value !== undefined;\n }\n\n export type String = string;\n export type Numerical = number|bigint|Date;\n export type Array = any[]|readonly any[];\n\n export type FilterType<V> = V extends String\n ? StringFilters<V>\n : V extends Numerical\n ? NumericalFilters<V>\n : V extends Array\n ? ArrayFilters<V>\n : Filters<V>;\n\n export interface Filters<V>{\n equals?: V;\n notEquals?: V;\n }\n\n export interface NumericalFilters<V extends Numerical> extends Filters<V> {\n greaterThan?: V;\n greaterThanOrEqual?: V;\n lessThan?: V;\n lessThanOrEqual?: V;\n }\n\n export interface StringFilters<V extends String> extends Filters<V> {\n includes?: V;\n startsWith?: V;\n endsWith?: V;\n caseInsensitive?: boolean;\n matches?: RegExp;\n }\n\n export interface ArrayFilters<V extends Array> extends Filters<V> {\n includesEvery?: V[number][];\n includesSome?: V[number][];\n includesNone?: V[number][];\n length?: NumericalFilters<number>;\n }\n}","import type { ValueOrArray } from '../helpers/types.js';\nimport { Primitive } from './Primitive.js';\nimport type { Qweery } from './Qweery.js';\n\nexport class Where<T extends Qweery.Object> {\n public readonly data: T[];\n\n public constructor(data: Iterable<T>) {\n this.data = Array.from(data);\n }\n\n public filter(options: Where.Options<T>): T[] {\n return this.data.filter((_, index) => this.satisfiesItem(options, index));\n }\n\n public satisfiesItem(options: Where.Options<T>, index: number): boolean {\n const item = this.data.at(index);\n if (!item) return false;\n\n let value = true;\n\n for (const key in options) {\n if (Where.isLogicalOperator(key)) {\n const conditions = options[key as keyof T] as ValueOrArray<Where.Options<T>>;\n\n switch (key) {\n case '$NOT':\n value = value && !(\n Array.isArray(conditions)\n ? conditions.every(condition => this.satisfiesItem(condition, index))\n : this.satisfiesItem(conditions, index)\n );\n break;\n case '$AND':\n value = value && (\n Array.isArray(conditions)\n ? conditions.every(condition => this.satisfiesItem(condition, index))\n : this.satisfiesItem(conditions, index)\n );\n break;\n case '$OR':\n value = Array.isArray(conditions)\n ? value && conditions.some(condition => this.satisfiesItem(condition, index))\n : value || this.satisfiesItem(conditions, index);\n break;\n }\n\n continue;\n }\n\n\n const filter = options[key as keyof T] as Where.Filter<T, keyof T>;\n const itemValue = item[key as keyof T];\n\n if (filter instanceof Function) {\n value = value && filter(itemValue, item, index, this.data);\n continue;\n }\n\n if (typeof filter === 'object') {\n if (typeof itemValue === 'string') {\n value = value && Primitive.statisfiesString(itemValue, filter as Primitive.StringFilters<Primitive.String>);\n continue;\n }\n\n if (Array.isArray(itemValue)) {\n value = value && Primitive.statisfiesArray(itemValue, filter as Primitive.ArrayFilters<Primitive.Array>);\n continue;\n }\n\n if (Primitive.isNumerical(itemValue)) {\n value = value && Primitive.statisfiesNumerical(itemValue, filter as Primitive.NumericalFilters<Primitive.Numerical>);\n continue;\n }\n\n value = value && Primitive.satisfiesValue(itemValue, filter as Primitive.Filters<any>);\n continue;\n }\n\n value = value && (itemValue === filter);\n }\n\n return value;\n }\n}\n\nexport namespace Where {\n export type KeyFilters<T extends Qweery.Object> = {\n [K in keyof T]?: Filter<T, K>;\n }\n\n export type Filter<T extends Qweery.Object, K extends keyof T> = \n |T[K]\n |((value: T[K], object: T, index: number, array: T[]) => boolean)\n |(Primitive.FilterType<T[K]> & LogicalOperators<T>)\n\n export interface LogicalOperators<T extends Qweery.Object> extends Partial<Record<'$AND'|'$OR'|'$NOT', ValueOrArray<Options<T>>>>{\n //\n }\n\n export type Options<T extends Qweery.Object> = KeyFilters<T> & LogicalOperators<T>;\n\n export function isLogicalOperator(value: unknown): value is keyof LogicalOperators<any> {\n return value === '$AND' || value === '$OR' || value === '$NOT';\n }\n}\n\nconst w = new Where([\n { name: 'Alice', age: 30, sports: ['Football', 'Basketball'] },\n { name: 'Bob', age: 25, sports: ['Football', 'Basketball'] },\n { name: 'Charlie', age: 35, sports: ['Football', 'Basketball'] }\n]);","import { Where } from './Where.js';\n\nexport class Qweery<T extends Qweery.Object> {\n protected readonly data: T[];\n\n constructor(data: Iterable<T>) {\n this.data = Array.from(data);\n }\n\n public query(options: {\n where?: Where.Options<T>;\n skip?: number;\n limit?: number;\n }): T[] {\n\n let result = new Where(this.data).filter(options.where || {});\n\n if (options.skip) {\n result = result.slice(options.skip);\n }\n\n if (options.limit) {\n result = result.slice(0, options.limit);\n }\n\n return result;\n }\n\n public where(options: Where.Options<T>): Qweery<T> {\n return new Qweery(new Where(this.data).filter(options || {}));\n }\n\n public skip(count: number): Qweery<T> {\n return new Qweery(this.data.slice(count));\n }\n\n public take(count: number): Qweery<T> {\n return new Qweery(this.data.slice(0, count));\n }\n\n public count(): number {\n return this.data.length;\n }\n\n public first(): T|undefined {\n return this.data[0];\n }\n\n public last(): T|undefined {\n return this.data[this.data.length - 1];\n }\n\n public toArray(): T[] {\n return this.data;\n }\n}\n\nexport namespace Qweery {\n export type Object = object;\n}"],"mappings":";AAAA,IAAa,YAAb,MAAa,UAAU;CACnB,OAAc,eAAkB,OAAU,SAAwC;AAC9E,MAAI,UAAU,UAAU,QAAQ,OAAO,IAAI,UAAU,QAAQ,OACzD,QAAO;AAGX,MAAI,UAAU,UAAU,QAAQ,UAAU,IAAI,UAAU,QAAQ,UAC5D,QAAO;AAGX,SAAO;;CAGX,OAAc,iBAAiB,OAAyB,SAA6D;AACjH,MAAI,QAAQ,gBAAiB,SAAQ,MAAM,aAAa;AAExD,MAAI,CAAC,KAAK,eAAe,OAAO,QAAQ,CACpC,QAAO;AAGX,MAAI,UAAU,UAAU,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