@rebasepro/common 0.2.5 → 0.4.0
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/data/query_builder.d.ts +6 -2
- package/dist/index.es.js +62 -42
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +62 -42
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/collections/default-collections.ts +5 -0
- package/src/data/buildRebaseData.ts +22 -8
- package/src/data/query_builder.ts +37 -27
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { FindResponse, CollectionAccessor, QueryBuilderInterface, FilterOperator } from "@rebasepro/types";
|
|
1
|
+
import { FindResponse, CollectionAccessor, QueryBuilderInterface, FilterOperator, LogicalCondition, WhereValue, FilterCondition } from "@rebasepro/types";
|
|
2
|
+
export declare function or(...conditions: (FilterCondition | LogicalCondition)[]): LogicalCondition;
|
|
3
|
+
export declare function and(...conditions: (FilterCondition | LogicalCondition)[]): LogicalCondition;
|
|
4
|
+
export declare function cond(column: string, operator: FilterOperator, value: unknown): FilterCondition;
|
|
2
5
|
export declare class QueryBuilder<M extends Record<string, unknown> = Record<string, unknown>> implements QueryBuilderInterface<M> {
|
|
3
6
|
private collection;
|
|
4
7
|
private params;
|
|
@@ -8,7 +11,8 @@ export declare class QueryBuilder<M extends Record<string, unknown> = Record<str
|
|
|
8
11
|
* @example
|
|
9
12
|
* client.collection('users').where('age', '>=', 18).find()
|
|
10
13
|
*/
|
|
11
|
-
where
|
|
14
|
+
where<K extends keyof M & string>(column: K, operator: FilterOperator, value: WhereValue<M[K]>): this;
|
|
15
|
+
where(logicalCondition: LogicalCondition): this;
|
|
12
16
|
/**
|
|
13
17
|
* Order the results by a specific column.
|
|
14
18
|
* @example
|
package/dist/index.es.js
CHANGED
|
@@ -1973,6 +1973,13 @@ const defaultUsersCollection = {
|
|
|
1973
1973
|
group: "Settings",
|
|
1974
1974
|
openEntityMode: "dialog",
|
|
1975
1975
|
disableDefaultActions: ["copy"],
|
|
1976
|
+
securityRules: [{
|
|
1977
|
+
operation: "select",
|
|
1978
|
+
roles: ["admin"]
|
|
1979
|
+
}, {
|
|
1980
|
+
operations: ["insert", "update", "delete"],
|
|
1981
|
+
roles: ["admin"]
|
|
1982
|
+
}],
|
|
1976
1983
|
sort: ["createdAt", "desc"],
|
|
1977
1984
|
properties: {
|
|
1978
1985
|
id: {
|
|
@@ -2079,6 +2086,7 @@ const defaultUsersCollection = {
|
|
|
2079
2086
|
name: "Created At",
|
|
2080
2087
|
type: "date",
|
|
2081
2088
|
columnName: "created_at",
|
|
2089
|
+
autoValue: "on_create",
|
|
2082
2090
|
ui: {
|
|
2083
2091
|
readOnly: true
|
|
2084
2092
|
}
|
|
@@ -2099,29 +2107,24 @@ const defaultUsersCollection = {
|
|
|
2099
2107
|
listProperties: ["displayName", "email", "roles", "createdAt"],
|
|
2100
2108
|
propertiesOrder: ["id", "email", "displayName", "roles", "createdAt"]
|
|
2101
2109
|
};
|
|
2102
|
-
function
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
case "not-in":
|
|
2121
|
-
return "nin";
|
|
2122
|
-
default:
|
|
2123
|
-
return op;
|
|
2124
|
-
}
|
|
2110
|
+
function or(...conditions) {
|
|
2111
|
+
return {
|
|
2112
|
+
type: "or",
|
|
2113
|
+
conditions
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
function and(...conditions) {
|
|
2117
|
+
return {
|
|
2118
|
+
type: "and",
|
|
2119
|
+
conditions
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
function cond(column, operator, value) {
|
|
2123
|
+
return {
|
|
2124
|
+
column,
|
|
2125
|
+
operator,
|
|
2126
|
+
value
|
|
2127
|
+
};
|
|
2125
2128
|
}
|
|
2126
2129
|
class QueryBuilder {
|
|
2127
2130
|
constructor(collection) {
|
|
@@ -2130,23 +2133,30 @@ class QueryBuilder {
|
|
|
2130
2133
|
params = {
|
|
2131
2134
|
where: {}
|
|
2132
2135
|
};
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
where(column, operator, value) {
|
|
2136
|
+
where(columnOrCondition, operator, value) {
|
|
2137
|
+
if (typeof columnOrCondition === "object" && columnOrCondition !== null && "type" in columnOrCondition) {
|
|
2138
|
+
this.params.logical = columnOrCondition;
|
|
2139
|
+
return this;
|
|
2140
|
+
}
|
|
2139
2141
|
if (!this.params.where) {
|
|
2140
2142
|
this.params.where = {};
|
|
2141
2143
|
}
|
|
2142
|
-
const
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2144
|
+
const column = columnOrCondition;
|
|
2145
|
+
const condition = [operator, value];
|
|
2146
|
+
const existing = this.params.where[column];
|
|
2147
|
+
if (existing === void 0) {
|
|
2148
|
+
this.params.where[column] = condition;
|
|
2149
|
+
} else if (Array.isArray(existing) && existing.length > 0 && Array.isArray(existing[0])) {
|
|
2150
|
+
this.params.where[column].push(condition);
|
|
2151
|
+
} else {
|
|
2152
|
+
let firstCondition;
|
|
2153
|
+
if (Array.isArray(existing) && existing.length === 2 && typeof existing[0] === "string") {
|
|
2154
|
+
firstCondition = existing;
|
|
2155
|
+
} else {
|
|
2156
|
+
firstCondition = ["==", existing];
|
|
2157
|
+
}
|
|
2158
|
+
this.params.where[column] = [firstCondition, condition];
|
|
2148
2159
|
}
|
|
2149
|
-
this.params.where[column] = mappedOp === "eq" ? String(formattedValue) : `${mappedOp}.${formattedValue}`;
|
|
2150
2160
|
return this;
|
|
2151
2161
|
}
|
|
2152
2162
|
/**
|
|
@@ -2248,10 +2258,13 @@ function convertWhereToFilter(where) {
|
|
|
2248
2258
|
filter[field] = ["==", rawValue];
|
|
2249
2259
|
continue;
|
|
2250
2260
|
}
|
|
2251
|
-
if (Array.isArray(rawValue)
|
|
2252
|
-
const [
|
|
2253
|
-
const
|
|
2254
|
-
|
|
2261
|
+
if (Array.isArray(rawValue)) {
|
|
2262
|
+
const conditions = Array.isArray(rawValue[0]) ? rawValue : [rawValue];
|
|
2263
|
+
const mappedConditions = conditions.map(([rawOp, val]) => {
|
|
2264
|
+
const mappedOp = operatorMap[rawOp] ?? "==";
|
|
2265
|
+
return [mappedOp, val];
|
|
2266
|
+
});
|
|
2267
|
+
filter[field] = Array.isArray(rawValue[0]) ? mappedConditions : mappedConditions[0];
|
|
2255
2268
|
continue;
|
|
2256
2269
|
}
|
|
2257
2270
|
if (typeof rawValue === "string") {
|
|
@@ -2389,8 +2402,12 @@ function createDriverAccessor(driver, slug) {
|
|
|
2389
2402
|
});
|
|
2390
2403
|
} : void 0,
|
|
2391
2404
|
// Fluent Query Builder
|
|
2392
|
-
where(
|
|
2393
|
-
|
|
2405
|
+
where(columnOrCondition, operator, value) {
|
|
2406
|
+
const builder = new QueryBuilder(accessor);
|
|
2407
|
+
if (typeof columnOrCondition === "object") {
|
|
2408
|
+
return builder.where(columnOrCondition);
|
|
2409
|
+
}
|
|
2410
|
+
return builder.where(columnOrCondition, operator, value);
|
|
2394
2411
|
},
|
|
2395
2412
|
orderBy(column, ascending) {
|
|
2396
2413
|
return new QueryBuilder(accessor).orderBy(column, ascending);
|
|
@@ -2440,6 +2457,7 @@ export {
|
|
|
2440
2457
|
DEFAULT_ONE_OF_VALUE,
|
|
2441
2458
|
QueryBuilder,
|
|
2442
2459
|
addInitialSlash,
|
|
2460
|
+
and,
|
|
2443
2461
|
applyPropertyConditions,
|
|
2444
2462
|
buildAdditionalFieldDelegate,
|
|
2445
2463
|
buildCollection,
|
|
@@ -2457,6 +2475,7 @@ export {
|
|
|
2457
2475
|
canEditEntity,
|
|
2458
2476
|
canReadCollection,
|
|
2459
2477
|
checkOperation,
|
|
2478
|
+
cond,
|
|
2460
2479
|
createRelationRef,
|
|
2461
2480
|
createRelationRefWithData,
|
|
2462
2481
|
defaultUsersCollection,
|
|
@@ -2488,6 +2507,7 @@ export {
|
|
|
2488
2507
|
isPropertyBuilder,
|
|
2489
2508
|
isReadOnly,
|
|
2490
2509
|
normalizeToEntityRelation,
|
|
2510
|
+
or,
|
|
2491
2511
|
registerConditionOperations,
|
|
2492
2512
|
removeInitialAndTrailingSlashes,
|
|
2493
2513
|
removeInitialSlash,
|