@pc-nexus/storage 0.5.0-next.24 → 0.5.0-next.25
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.
|
@@ -12,7 +12,7 @@ export interface LogicalConditionBuilder<Schema = Document, FieldChains extends
|
|
|
12
12
|
type LimitComparisonConditionBuilder<Schema = Document, FieldChains extends KeyChains<Schema> = KeyChains<Schema>, CurrentLevel extends CurrentLevelType<Schema> = RootLevelType<Schema>, V = TypeAtKeyChain<Schema, FieldChains>, FieldType = TypeAtKeyChain<Schema, FieldChains>> = FieldType extends number ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "eq" | "ne" | "exists" | "gt" | "gte" | "lt" | "lte"> : FieldType extends string ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "eq" | "ne" | "exists" | "contains" | "notContains"> : FieldType extends boolean ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "eq" | "ne" | "exists"> : FieldType extends any[] ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "contains" | "notContains" | "eq" | "ne" | "exists"> : FieldType extends Document ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "eq" | "ne" | "exists"> : never;
|
|
13
13
|
export type ComparisonConditionBuilderReturnType<Schema = Document, FieldChains extends KeyChains<Schema> = KeyChains<Schema>, CurrentLevel extends CurrentLevelType<Schema> = RootLevelType<Schema>, V = TypeAtKeyChain<Schema, FieldChains>> = LogicalConditionBuilder<Schema, never, CurrentLevel, V> & LimitComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>;
|
|
14
14
|
export interface ComparisonConditionBuilder<Schema = Document, FieldChains extends KeyChains<Schema> = KeyChains<Schema>, CurrentLevel extends CurrentLevelType<Schema> = RootLevelType<Schema>, V = TypeAtKeyChain<Schema, FieldChains>> {
|
|
15
|
-
eq(value: ValueAlternativeType<V>, options?: EqOptions<QueryOperator.
|
|
15
|
+
eq(value: ValueAlternativeType<V>, options?: EqOptions<QueryOperator.EQ>): ComparisonConditionBuilderReturnType<Schema, FieldChains, CurrentLevel, V>;
|
|
16
16
|
ne(value: ValueAlternativeType<V>, options?: Omit<EqOptions, "queryOperator">): ComparisonConditionBuilderReturnType<Schema, FieldChains, CurrentLevel, V>;
|
|
17
17
|
gt(value: ValueAlternativeType<V>, options?: RangeOptions): ComparisonConditionBuilderReturnType<Schema, FieldChains, CurrentLevel, V>;
|
|
18
18
|
gte(value: ValueAlternativeType<V>, options?: RangeOptions): ComparisonConditionBuilderReturnType<Schema, FieldChains, CurrentLevel, V>;
|
|
@@ -26,7 +26,7 @@ export declare class InnerConditionBuilder<Schema = Record<string, any>, FieldCh
|
|
|
26
26
|
private updateQuery;
|
|
27
27
|
field<TFieldChains extends FieldChains>(field: TFieldChains): InnerConditionBuilder<Schema, TFieldChains, CurrentLevel>;
|
|
28
28
|
resetFieldConditions(): this;
|
|
29
|
-
eq<OP extends QueryOperator.
|
|
29
|
+
eq<OP extends QueryOperator.EQ | QueryOperator.NE | QueryOperator.GT | QueryOperator.GTE | QueryOperator.LTE | QueryOperator.LT | QueryOperator.Contains | QueryOperator.NotContains = QueryOperator.EQ>(value: ValueAlternativeType<V>, { queryOperator, ...options }?: EqOptions<OP>): this;
|
|
30
30
|
ne(value: ValueAlternativeType<V>, options?: Omit<EqOptions, "queryOperator">): this;
|
|
31
31
|
gte(value: ValueAlternativeType<V>, { ...options }?: RangeOptions): this;
|
|
32
32
|
gt(value: ValueAlternativeType<V>, { ...options }?: RangeOptions): this;
|
|
@@ -6,7 +6,7 @@ export class InnerConditionBuilder {
|
|
|
6
6
|
baseOptions = { ignoreUndefined: false, keepNaN: false };
|
|
7
7
|
get currentField() {
|
|
8
8
|
if (!this._field) {
|
|
9
|
-
throw new NexusInnerError(NexusCode.
|
|
9
|
+
throw new NexusInnerError(NexusCode.InvalidInput, NexusInnerErrorType.StorageConditionBuilder, `No field specified for condition`);
|
|
10
10
|
}
|
|
11
11
|
return this._field;
|
|
12
12
|
}
|
|
@@ -76,7 +76,7 @@ export class InnerConditionBuilder {
|
|
|
76
76
|
assertAtRootLevel() {
|
|
77
77
|
if (!this.isAtRootLevel()) {
|
|
78
78
|
const logicalOp = this.currentLevel[logicalOpSymbol];
|
|
79
|
-
throw new NexusInnerError(NexusCode.
|
|
79
|
+
throw new NexusInnerError(NexusCode.InvalidInput, NexusInnerErrorType.StorageConditionBuilder, `there is still remaining "${logicalOp}" logical operator opened`);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
assertAtLogicalLevel(expect) {
|
|
@@ -84,11 +84,11 @@ export class InnerConditionBuilder {
|
|
|
84
84
|
const isRootLevel = _.isNil(logicalOp);
|
|
85
85
|
if (expect) {
|
|
86
86
|
if (logicalOp !== expect) {
|
|
87
|
-
throw new NexusInnerError(NexusCode.
|
|
87
|
+
throw new NexusInnerError(NexusCode.InvalidInput, NexusInnerErrorType.StorageConditionBuilder, `there is no "${expect}" logical operator opened`);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
else if (isRootLevel) {
|
|
91
|
-
throw new NexusInnerError(NexusCode.
|
|
91
|
+
throw new NexusInnerError(NexusCode.InvalidInput, NexusInnerErrorType.StorageConditionBuilder, `there is no any logical operator opened`);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
logicalClosure(logicalOp, closure) {
|
|
@@ -125,10 +125,10 @@ export class InnerConditionBuilder {
|
|
|
125
125
|
return that;
|
|
126
126
|
}
|
|
127
127
|
and(closure) {
|
|
128
|
-
return this.logicalClosure(LogicalOperator.
|
|
128
|
+
return this.logicalClosure(LogicalOperator.And, closure);
|
|
129
129
|
}
|
|
130
130
|
or(closure) {
|
|
131
|
-
return this.logicalClosure(LogicalOperator.
|
|
131
|
+
return this.logicalClosure(LogicalOperator.Or, closure);
|
|
132
132
|
}
|
|
133
133
|
shouldReserveValue(value, options) {
|
|
134
134
|
options = { ...this.baseOptions, ...options };
|
|
@@ -186,7 +186,7 @@ export class InnerConditionBuilder {
|
|
|
186
186
|
}
|
|
187
187
|
return this;
|
|
188
188
|
}
|
|
189
|
-
eq(value, { queryOperator = QueryOperator.
|
|
189
|
+
eq(value, { queryOperator = QueryOperator.EQ, ...options } = {}) {
|
|
190
190
|
const field = this.currentField;
|
|
191
191
|
if (!this.shouldReserveValue(value, options)) {
|
|
192
192
|
return this;
|
|
@@ -195,35 +195,35 @@ export class InnerConditionBuilder {
|
|
|
195
195
|
return this;
|
|
196
196
|
}
|
|
197
197
|
ne(value, options = {}) {
|
|
198
|
-
return this.eq(value, { ...options, queryOperator: QueryOperator.
|
|
198
|
+
return this.eq(value, { ...options, queryOperator: QueryOperator.NE });
|
|
199
199
|
}
|
|
200
200
|
gte(value, { ...options } = {}) {
|
|
201
|
-
this.eq(value, { queryOperator: QueryOperator.
|
|
201
|
+
this.eq(value, { queryOperator: QueryOperator.GTE, ...options });
|
|
202
202
|
return this;
|
|
203
203
|
}
|
|
204
204
|
gt(value, { ...options } = {}) {
|
|
205
|
-
this.eq(value, { queryOperator: QueryOperator.
|
|
205
|
+
this.eq(value, { queryOperator: QueryOperator.GT, ...options });
|
|
206
206
|
return this;
|
|
207
207
|
}
|
|
208
208
|
lte(value, { ...options } = {}) {
|
|
209
|
-
this.eq(value, { queryOperator: QueryOperator.
|
|
209
|
+
this.eq(value, { queryOperator: QueryOperator.LTE, ...options });
|
|
210
210
|
return this;
|
|
211
211
|
}
|
|
212
212
|
lt(value, { ...options } = {}) {
|
|
213
|
-
this.eq(value, { queryOperator: QueryOperator.
|
|
213
|
+
this.eq(value, { queryOperator: QueryOperator.LT, ...options });
|
|
214
214
|
return this;
|
|
215
215
|
}
|
|
216
216
|
contains(value, { ...options } = {}) {
|
|
217
|
-
this.eq(value, { queryOperator: QueryOperator.
|
|
217
|
+
this.eq(value, { queryOperator: QueryOperator.Contains, ...options });
|
|
218
218
|
return this;
|
|
219
219
|
}
|
|
220
220
|
notContains(value, { ...options } = {}) {
|
|
221
|
-
this.eq(value, { queryOperator: QueryOperator.
|
|
221
|
+
this.eq(value, { queryOperator: QueryOperator.NotContains, ...options });
|
|
222
222
|
return this;
|
|
223
223
|
}
|
|
224
224
|
exists(exists = true) {
|
|
225
225
|
const field = this.currentField;
|
|
226
|
-
this.updateQuery(field, { [QueryOperator.
|
|
226
|
+
this.updateQuery(field, { [QueryOperator.Exists]: !!exists });
|
|
227
227
|
return this;
|
|
228
228
|
}
|
|
229
229
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pc-nexus/storage",
|
|
3
|
-
"version": "0.5.0-next.
|
|
3
|
+
"version": "0.5.0-next.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"type": "module",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@pc-nexus/internal": "0.5.0-next.
|
|
33
|
+
"@pc-nexus/internal": "0.5.0-next.25",
|
|
34
34
|
"lodash": "^4.17.21"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {},
|