@taruvi/refine-providers 1.3.4-beta.2 → 1.3.4-beta.4

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 CHANGED
@@ -115,23 +115,26 @@ List `getList` filters use an explicit **`TaruviListFilters`** shape:
115
115
 
116
116
  Legacy Refine **`CrudFilter[]`** is still accepted: all field leaves → flat array; a single root `and`/`or` object → logical object; mixed lists fall back to the JSON tree. Bracket keys from `convertRefineFilters` remain for helpers / Storage flatten mode.
117
117
 
118
- Full support for Refine filter operators:
118
+ Use **`TaruviCrudOperator`** / **`TaruviFieldFilter`** for type-safe filters (including PostgreSQL range/array ops and `search`). Pass them to Refine hooks with **`toRefineFilters()`** — Refine’s `CrudOperators` type is narrower than the runtime set.
119
119
 
120
120
  ```tsx
121
+ import { useList } from "@refinedev/core";
122
+ import { toRefineFilters } from "@taruvi/refine-providers";
123
+
121
124
  const { data } = useList({
122
125
  resource: "posts",
123
- filters: [
126
+ filters: toRefineFilters([
124
127
  { field: "status", operator: "eq", value: "published" },
125
128
  { field: "views", operator: "gte", value: 100 },
129
+ { field: "slot", operator: "roverlaps", value: "[2024-01-01,2024-12-31)" },
126
130
  { field: "title", operator: "containss", value: "refine" },
127
- { field: "category", operator: "in", value: ["tech", "news"] },
128
- ],
131
+ ]),
129
132
  });
130
133
  ```
131
134
 
132
135
  **Refine → backend operator mapping (important):**
133
136
 
134
- Wire suffixes match the platform (`contains` = case-insensitive, `containss` = case-sensitive). Refine aliases map to the same tokens, e.g. `icontains` → `contains`. See `REFINE_OPERATOR_MAP` in [`src/utils.ts`](src/utils.ts).
137
+ Wire suffixes match the platform (`contains` = case-insensitive, `containss` = case-sensitive). Refine aliases map to the same tokens, e.g. `icontains` → `contains`. See `REFINE_OPERATOR_MAP` in [`src/filterTypes.ts`](src/filterTypes.ts). Details: [docs/filters.md](docs/filters.md).
135
138
 
136
139
  **More operators:**
137
140
 
package/dist/index.cjs CHANGED
@@ -11,9 +11,9 @@ var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
11
11
 
12
12
  // package.json
13
13
  var package_default = {
14
- version: "1.3.4-beta.2"};
14
+ version: "1.3.4-beta.4"};
15
15
 
16
- // src/utils.ts
16
+ // src/filterTypes.ts
17
17
  var REFINE_OPERATOR_MAP = {
18
18
  // Equality
19
19
  eq: "",
@@ -76,6 +76,18 @@ var REFINE_OPERATOR_MAP = {
76
76
  ilike: "ilike",
77
77
  search: "search"
78
78
  };
79
+ function hasTaruviOperator(operator) {
80
+ return operator in REFINE_OPERATOR_MAP;
81
+ }
82
+ function taruviOperatorSuffix(operator) {
83
+ if (!hasTaruviOperator(operator)) return void 0;
84
+ return REFINE_OPERATOR_MAP[operator];
85
+ }
86
+ function toRefineFilters(filters) {
87
+ return filters;
88
+ }
89
+
90
+ // src/utils.ts
79
91
  var COMMA_VALUE_OPERATORS = /* @__PURE__ */ new Set([
80
92
  "in",
81
93
  "nin",
@@ -112,7 +124,7 @@ function isFlatFilterList(filters) {
112
124
  if (leaf.value === void 0 || leaf.value === null && leaf.operator !== "null") {
113
125
  return false;
114
126
  }
115
- if (REFINE_OPERATOR_MAP[leaf.operator] === void 0) {
127
+ if (!hasTaruviOperator(leaf.operator)) {
116
128
  return false;
117
129
  }
118
130
  return true;
@@ -149,7 +161,7 @@ function collectFlatLeaves(filters) {
149
161
  if (leaf.value === void 0 || leaf.value === null && leaf.operator !== "null") {
150
162
  continue;
151
163
  }
152
- if (REFINE_OPERATOR_MAP[leaf.operator] === void 0) {
164
+ if (!hasTaruviOperator(leaf.operator)) {
153
165
  console.warn(`Unknown Refine operator: ${leaf.operator}`);
154
166
  return false;
155
167
  }
@@ -165,7 +177,7 @@ function collectFlatLeaves(filters) {
165
177
  return leaves;
166
178
  }
167
179
  function refineOperatorToBackendKey(operator) {
168
- const suffix = REFINE_OPERATOR_MAP[operator];
180
+ const suffix = taruviOperatorSuffix(operator);
169
181
  if (suffix === void 0) return operator;
170
182
  return suffix === "" ? "eq" : suffix;
171
183
  }
@@ -182,7 +194,7 @@ function encodeLeafFlat(field, operator, value, params) {
182
194
  if (value === void 0 || value === null && operator !== "null") {
183
195
  return;
184
196
  }
185
- const suffix = REFINE_OPERATOR_MAP[operator];
197
+ const suffix = taruviOperatorSuffix(operator);
186
198
  if (suffix === void 0) {
187
199
  console.warn(`Unknown Refine operator: ${operator}`);
188
200
  return;
@@ -208,7 +220,7 @@ function encodeCrudFilterBracket(filter, path, out) {
208
220
  if (value === void 0 || value === null && operator !== "null") {
209
221
  return;
210
222
  }
211
- const suffix = REFINE_OPERATOR_MAP[operator];
223
+ const suffix = taruviOperatorSuffix(operator);
212
224
  if (suffix === void 0) {
213
225
  console.warn(`Unknown Refine operator: ${operator}`);
214
226
  return;
@@ -235,7 +247,7 @@ function crudFilterToBackendNodeOrNull(filter) {
235
247
  if (leaf.value === void 0 || leaf.value === null && leaf.operator !== "null") {
236
248
  return null;
237
249
  }
238
- if (REFINE_OPERATOR_MAP[leaf.operator] === void 0) {
250
+ if (!hasTaruviOperator(leaf.operator)) {
239
251
  console.warn(`Unknown Refine operator: ${leaf.operator}`);
240
252
  return null;
241
253
  }
@@ -373,7 +385,7 @@ function formatHaving(having) {
373
385
  if (value === void 0 || value === null && operator !== "null") {
374
386
  continue;
375
387
  }
376
- const suffix = REFINE_OPERATOR_MAP[operator];
388
+ const suffix = taruviOperatorSuffix(operator);
377
389
  if (suffix === void 0) {
378
390
  console.warn(`Unknown operator in having clause: ${operator}`);
379
391
  continue;
@@ -385,15 +397,6 @@ function formatHaving(having) {
385
397
  }
386
398
  return params.length > 0 ? params.join(",") : void 0;
387
399
  }
388
- function handleError(error) {
389
- if (error instanceof Error) {
390
- throw error;
391
- }
392
- if (typeof error === "object" && error !== null && "message" in error) {
393
- throw new Error(String(error.message));
394
- }
395
- throw new Error("Unknown error occurred");
396
- }
397
400
 
398
401
  // src/dataProvider.ts
399
402
  function applyAggregations(query, meta) {
@@ -446,7 +449,7 @@ function applyFilters(query, filters) {
446
449
  }
447
450
  function applySorters(query, sorters) {
448
451
  const ordering = convertRefineSorters(sorters);
449
- return ordering ? query.orderBy(ordering) : query;
452
+ return ordering ? query.sort(ordering) : query;
450
453
  }
451
454
  function applyPagination(query, pagination) {
452
455
  if (!pagination || pagination.mode === "off") return query;
@@ -475,7 +478,7 @@ function applySearchAndFields(query, meta) {
475
478
  return result;
476
479
  }
477
480
  function isGraphQuery(meta) {
478
- return !!(meta?.format || meta?.graph_types || meta?.include || meta?.depth);
481
+ return !!(meta?.format || meta?.relationship_type || meta?.include || meta?.depth);
479
482
  }
480
483
  function buildGraphQuery(client, tableName, meta, recordId) {
481
484
  let query = new sdk.Database(client).from(tableName);
@@ -483,7 +486,7 @@ function buildGraphQuery(client, tableName, meta, recordId) {
483
486
  if (meta?.format) query = query.format(meta.format);
484
487
  if (meta?.include) query = query.include(meta.include);
485
488
  if (meta?.depth) query = query.depth(meta.depth);
486
- if (meta?.graph_types) query = query.types(meta.graph_types);
489
+ if (meta?.relationship_type) query = query.types(meta.relationship_type);
487
490
  return query;
488
491
  }
489
492
  function dataProvider(client) {
@@ -715,7 +718,9 @@ function storageDataProvider(client) {
715
718
  return { data: { id: path } };
716
719
  },
717
720
  getApiUrl: () => baseApiUrl,
718
- getMany: async () => ({ data: [] }),
721
+ getMany: async () => {
722
+ throw new Error("getMany is not supported for storage resources");
723
+ },
719
724
  createMany: async (params) => {
720
725
  const { resource, variables, meta } = params;
721
726
  const taruviMeta = meta;
@@ -725,7 +730,7 @@ function storageDataProvider(client) {
725
730
  const fileMetadatas = files.map((_, i) => metadatas[i] || {});
726
731
  const response = await new sdk.Storage(client).from(bucket).upload({ files, paths: filePaths, metadatas: fileMetadatas }).execute();
727
732
  const uploaded = response.data?.successful?.map((s) => s.object) ?? [];
728
- return { data: uploaded.length > 0 ? uploaded[0] : response.data };
733
+ return { data: uploaded.length > 0 ? uploaded : [response.data] };
729
734
  },
730
735
  deleteMany: async (params) => {
731
736
  const { resource, ids, meta } = params;
@@ -1167,6 +1172,7 @@ function analyticsDataProvider(client) {
1167
1172
  }
1168
1173
  };
1169
1174
  }
1175
+ var isBrowser = typeof window !== "undefined";
1170
1176
  exports._cachedUser = null;
1171
1177
  function authProvider(client) {
1172
1178
  const auth = new sdk.Auth(client);
@@ -1236,11 +1242,15 @@ function authProvider(client) {
1236
1242
  return null;
1237
1243
  }
1238
1244
  const user = response.data ?? response;
1239
- exports._cachedUser = user;
1245
+ if (isBrowser) exports._cachedUser = user;
1240
1246
  return user;
1241
1247
  },
1242
1248
  getPermissions: async () => {
1243
- const user = exports._cachedUser;
1249
+ let user = isBrowser ? exports._cachedUser : null;
1250
+ if (!user) {
1251
+ const response = await auth.getCurrentUser();
1252
+ user = response ? response.data ?? response : null;
1253
+ }
1244
1254
  if (!user) {
1245
1255
  return null;
1246
1256
  }
@@ -1254,13 +1264,14 @@ function authProvider(client) {
1254
1264
  }
1255
1265
  };
1256
1266
  }
1267
+ var isBrowser2 = typeof window !== "undefined";
1257
1268
  function accessControlProvider(client, options) {
1258
1269
  const policy = new sdk.Policy(client);
1259
1270
  const auth = new sdk.Auth(client);
1260
1271
  const { batchDelayMs = 50 } = options ?? {};
1261
1272
  const permissionLoader = new DataLoader__default.default(
1262
1273
  async (checks) => {
1263
- let currentUser = exports._cachedUser;
1274
+ let currentUser = isBrowser2 ? exports._cachedUser : null;
1264
1275
  if (!currentUser) {
1265
1276
  try {
1266
1277
  const response = await auth.getCurrentUser();
@@ -1373,12 +1384,14 @@ exports.encodeCrudFilterBracket = encodeCrudFilterBracket;
1373
1384
  exports.encodeFlatFilterListToParams = encodeFlatFilterListToParams;
1374
1385
  exports.formatRefineLeafValue = formatRefineLeafValue;
1375
1386
  exports.functionsDataProvider = functionsDataProvider;
1376
- exports.handleError = handleError;
1387
+ exports.hasTaruviOperator = hasTaruviOperator;
1377
1388
  exports.isFlatFilterList = isFlatFilterList;
1378
1389
  exports.isLogicalCrudFilter = isLogicalCrudFilter;
1379
1390
  exports.normalizeTaruviListFilters = normalizeTaruviListFilters;
1380
1391
  exports.refineOperatorToBackendKey = refineOperatorToBackendKey;
1381
1392
  exports.storageDataProvider = storageDataProvider;
1393
+ exports.taruviOperatorSuffix = taruviOperatorSuffix;
1394
+ exports.toRefineFilters = toRefineFilters;
1382
1395
  exports.userDataProvider = userDataProvider;
1383
1396
  //# sourceMappingURL=index.cjs.map
1384
1397
  //# sourceMappingURL=index.cjs.map