@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/index.umd.js CHANGED
@@ -1973,6 +1973,13 @@
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 @@
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 @@
2099
2107
  listProperties: ["displayName", "email", "roles", "createdAt"],
2100
2108
  propertiesOrder: ["id", "email", "displayName", "roles", "createdAt"]
2101
2109
  };
2102
- function mapOperator(op) {
2103
- switch (op) {
2104
- case "==":
2105
- return "eq";
2106
- case "!=":
2107
- return "neq";
2108
- case ">":
2109
- return "gt";
2110
- case ">=":
2111
- return "gte";
2112
- case "<":
2113
- return "lt";
2114
- case "<=":
2115
- return "lte";
2116
- case "array-contains":
2117
- return "cs";
2118
- case "array-contains-any":
2119
- return "csa";
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 @@
2130
2133
  params = {
2131
2134
  where: {}
2132
2135
  };
2133
- /**
2134
- * Add a filter condition to your query.
2135
- * @example
2136
- * client.collection('users').where('age', '>=', 18).find()
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 mappedOp = mapOperator(operator);
2143
- let formattedValue = value;
2144
- if (Array.isArray(value) && ["in", "nin", "cs", "csa"].includes(mappedOp)) {
2145
- formattedValue = `(${value.join(",")})`;
2146
- } else if (value === null) {
2147
- formattedValue = "null";
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 @@
2248
2258
  filter[field] = ["==", rawValue];
2249
2259
  continue;
2250
2260
  }
2251
- if (Array.isArray(rawValue) && rawValue.length === 2) {
2252
- const [rawOp, val] = rawValue;
2253
- const mappedOp = operatorMap[rawOp] ?? "==";
2254
- filter[field] = [mappedOp, val];
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 @@
2389
2402
  });
2390
2403
  } : void 0,
2391
2404
  // Fluent Query Builder
2392
- where(column, operator, value) {
2393
- return new QueryBuilder(accessor).where(column, operator, value);
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);
@@ -2439,6 +2456,7 @@
2439
2456
  exports2.DEFAULT_ONE_OF_VALUE = DEFAULT_ONE_OF_VALUE;
2440
2457
  exports2.QueryBuilder = QueryBuilder;
2441
2458
  exports2.addInitialSlash = addInitialSlash;
2459
+ exports2.and = and;
2442
2460
  exports2.applyPropertyConditions = applyPropertyConditions;
2443
2461
  exports2.buildAdditionalFieldDelegate = buildAdditionalFieldDelegate;
2444
2462
  exports2.buildCollection = buildCollection;
@@ -2456,6 +2474,7 @@
2456
2474
  exports2.canEditEntity = canEditEntity;
2457
2475
  exports2.canReadCollection = canReadCollection;
2458
2476
  exports2.checkOperation = checkOperation;
2477
+ exports2.cond = cond;
2459
2478
  exports2.createRelationRef = createRelationRef;
2460
2479
  exports2.createRelationRefWithData = createRelationRefWithData;
2461
2480
  exports2.defaultUsersCollection = defaultUsersCollection;
@@ -2487,6 +2506,7 @@
2487
2506
  exports2.isPropertyBuilder = isPropertyBuilder;
2488
2507
  exports2.isReadOnly = isReadOnly;
2489
2508
  exports2.normalizeToEntityRelation = normalizeToEntityRelation;
2509
+ exports2.or = or;
2490
2510
  exports2.registerConditionOperations = registerConditionOperations;
2491
2511
  exports2.removeInitialAndTrailingSlashes = removeInitialAndTrailingSlashes;
2492
2512
  exports2.removeInitialSlash = removeInitialSlash;