@ciwergrp/nuxid 1.18.0 → 1.19.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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
3
  "configKey": "nuxid",
4
- "version": "1.18.0",
4
+ "version": "1.19.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -18,6 +18,25 @@ const normalizeCursorValue = (value) => {
18
18
  }
19
19
  return String(value);
20
20
  };
21
+ const resolveItemKeyValue = (item, itemKey) => {
22
+ const normalizedKey = normalizeString(itemKey, "");
23
+ if (!normalizedKey || !item || typeof item !== "object") {
24
+ return void 0;
25
+ }
26
+ const record = item;
27
+ if (Object.prototype.hasOwnProperty.call(record, normalizedKey)) {
28
+ return record[normalizedKey];
29
+ }
30
+ if (!normalizedKey.includes(".")) {
31
+ return record[normalizedKey];
32
+ }
33
+ return normalizedKey.split(".").reduce((current, segment) => {
34
+ if (current === null || current === void 0) {
35
+ return void 0;
36
+ }
37
+ return current[segment];
38
+ }, item);
39
+ };
21
40
  const cloneResponse = (response) => ({
22
41
  ...response,
23
42
  data: [...response.data]
@@ -124,9 +143,9 @@ export const mergeCursorResponse = (current, next, itemKey) => {
124
143
  return cloneResponse(next);
125
144
  }
126
145
  const knownKeys = new Set(
127
- current.data.map((item) => item?.[itemKey])
146
+ current.data.map((item) => resolveItemKeyValue(item, itemKey))
128
147
  );
129
- const newItems = next.data.filter((item) => !knownKeys.has(item?.[itemKey]));
148
+ const newItems = next.data.filter((item) => !knownKeys.has(resolveItemKeyValue(item, itemKey)));
130
149
  return {
131
150
  ...next,
132
151
  data: [...current.data, ...newItems]
@@ -393,9 +412,9 @@ export async function useCursorHttp(url, options) {
393
412
  );
394
413
  if (data.value) {
395
414
  const existingIds = new Set(
396
- data.value.data.map((item) => item?.[normalizeString(itemKey, "id")])
415
+ data.value.data.map((item) => resolveItemKeyValue(item, normalizeString(itemKey, "id")))
397
416
  );
398
- const newItems = response.data.filter((item) => !existingIds.has(item?.[normalizeString(itemKey, "id")]));
417
+ const newItems = response.data.filter((item) => !existingIds.has(resolveItemKeyValue(item, normalizeString(itemKey, "id"))));
399
418
  if (newItems.length > 0) {
400
419
  data.value = {
401
420
  ...response,
@@ -28,7 +28,7 @@ const result = await useCursorHttp(url, options?)
28
28
  - `meta` (object): response meta keys.
29
29
  - `meta.cursorKey` (string): key for the next cursor.
30
30
  - `meta.hasMoreKey` (string): key for more data.
31
- - `itemKey` (string): unique item id to dedupe polls. Default: `id`.
31
+ - `itemKey` (string): unique item id to dedupe polls. Supports dot paths like `customer.id`. Default: `id`.
32
32
  - `cursorParam` (string): query param for cursor. Default: `cursor`.
33
33
 
34
34
  ## Returns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "description": "All-in-one essential modules for Nuxt",
5
5
  "repository": {
6
6
  "type": "git",