@fjell/core 4.4.72 → 4.4.73

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.js CHANGED
@@ -316,7 +316,9 @@ var locKeyArrayToItemKey = (lka) => {
316
316
  const comKey = { kt: priKey.kt, pk: priKey.pk, loc: locs };
317
317
  return comKey;
318
318
  } else {
319
- throw new Error("locKeyArrayToItemKey: lka is undefined or empty");
319
+ throw new Error(
320
+ "locKeyArrayToItemKey: lka is undefined or empty. Expected non-empty LocKeyArray. Suggestion: Ensure you are passing a valid location key array, not undefined/null/empty array."
321
+ );
320
322
  }
321
323
  };
322
324
  var isValidPriKey = (key) => {
@@ -818,17 +820,43 @@ var abbrevCondition = (condition) => {
818
820
  var logger5 = logger_default.get("validation", "ItemValidator");
819
821
  var validatePKForItem = (item, pkType) => {
820
822
  if (!item) {
821
- logger5.error("Validating PK, Item is undefined", { item });
822
- throw new Error("Validating PK, Item is undefined");
823
+ logger5.error("Item validation failed - item is undefined", {
824
+ component: "core",
825
+ operation: "validatePK",
826
+ expectedType: pkType,
827
+ item,
828
+ suggestion: "Ensure the operation returns a valid item object, not undefined/null"
829
+ });
830
+ throw new Error(
831
+ `Item validation failed: item is undefined. Expected item of type '${pkType}'. This usually indicates a database operation returned null/undefined unexpectedly.`
832
+ );
823
833
  }
824
834
  if (!item.key) {
825
- logger5.error("Validating PK, Item does not have a key", { item });
826
- throw new Error("Validating PK, Item does not have a key");
835
+ logger5.error("Item validation failed - item missing key", {
836
+ component: "core",
837
+ operation: "validatePK",
838
+ expectedType: pkType,
839
+ item,
840
+ suggestion: "Ensure the item has a valid key property with kt and pk fields"
841
+ });
842
+ throw new Error(
843
+ `Item validation failed: item does not have a key property. Expected key with type '${pkType}'. Item: ${JSON.stringify(item)}. This indicates a database processing error.`
844
+ );
827
845
  }
828
846
  const keyTypeArray = toKeyTypeArray(item.key);
829
847
  if (keyTypeArray[0] !== pkType) {
830
- logger5.error("Key Type Array Mismatch", { keyTypeArray, pkType });
831
- throw new Error(`Item does not have the correct primary key type. Expected ${pkType}, got ${keyTypeArray[0]}`);
848
+ logger5.error("Key type mismatch during validation", {
849
+ component: "core",
850
+ operation: "validatePK",
851
+ expectedType: pkType,
852
+ actualType: keyTypeArray[0],
853
+ keyTypeArray,
854
+ itemKey: item.key,
855
+ suggestion: `Ensure the item key has kt: '${pkType}', not '${keyTypeArray[0]}'`
856
+ });
857
+ throw new Error(
858
+ `Item has incorrect primary key type. Expected '${pkType}', got '${keyTypeArray[0]}'. Key: ${JSON.stringify(item.key)}. This indicates a data model mismatch.`
859
+ );
832
860
  }
833
861
  return item;
834
862
  };
@@ -842,19 +870,57 @@ var validatePK = (input, pkType) => {
842
870
  var validateKeys = (item, keyTypes) => {
843
871
  logger5.trace("Checking Return Type", { item });
844
872
  if (!item) {
845
- throw new Error("validating keys, item is undefined");
873
+ logger5.error("Key validation failed - item is undefined", {
874
+ component: "core",
875
+ operation: "validateKeys",
876
+ expectedKeyTypes: keyTypes,
877
+ suggestion: "Ensure the operation returns a valid item object, not undefined/null"
878
+ });
879
+ throw new Error(
880
+ `Key validation failed: item is undefined. Expected item with key types [${keyTypes.join(", ")}]. This usually indicates a database operation returned null/undefined unexpectedly.`
881
+ );
846
882
  }
847
883
  if (!item.key) {
848
- throw new Error("validating keys, item does not have a key: " + JSON.stringify(item));
884
+ logger5.error("Key validation failed - item missing key", {
885
+ component: "core",
886
+ operation: "validateKeys",
887
+ expectedKeyTypes: keyTypes,
888
+ item: JSON.stringify(item),
889
+ suggestion: "Ensure the item has a valid key property"
890
+ });
891
+ throw new Error(
892
+ `Key validation failed: item does not have a key property. Expected key with types [${keyTypes.join(", ")}]. Item: ${JSON.stringify(item)}. This indicates a database processing error.`
893
+ );
849
894
  }
850
895
  const keyTypeArray = toKeyTypeArray(item.key);
851
896
  if (keyTypeArray.length !== keyTypes.length) {
852
- throw new Error(`Item does not have the correct number of keys. Expected ${keyTypes.length}, but got ${keyTypeArray.length}`);
897
+ logger5.error("Key hierarchy depth mismatch", {
898
+ component: "core",
899
+ operation: "validateKeys",
900
+ expectedKeyTypes: keyTypes,
901
+ expectedDepth: keyTypes.length,
902
+ actualKeyTypes: keyTypeArray,
903
+ actualDepth: keyTypeArray.length,
904
+ itemKey: item.key,
905
+ suggestion: `Check coordinate definition. Expected hierarchy depth of ${keyTypes.length}, got ${keyTypeArray.length}`
906
+ });
907
+ throw new Error(
908
+ `Item has incorrect key hierarchy depth. Expected ${keyTypes.length} levels [${keyTypes.join(" > ")}], but got ${keyTypeArray.length} levels [${keyTypeArray.join(" > ")}]. Key: ${JSON.stringify(item.key)}. This indicates a coordinate/hierarchy mismatch.`
909
+ );
853
910
  }
854
911
  const match = JSON.stringify(keyTypeArray) === JSON.stringify(keyTypes);
855
912
  if (!match) {
856
- logger5.error("Key Type Array Mismatch", { keyTypeArray, thisKeyTypes: keyTypes });
857
- throw new Error(`Item does not have the correct key types. Expected [${keyTypes.join(", ")}], but got [${keyTypeArray.join(", ")}]`);
913
+ logger5.error("Key Type Array Mismatch", {
914
+ component: "core",
915
+ operation: "validateKeys",
916
+ expectedKeyTypes: keyTypes,
917
+ actualKeyTypes: keyTypeArray,
918
+ itemKey: item.key,
919
+ suggestion: `Ensure item key matches expected hierarchy: [${keyTypes.join(" > ")}]`
920
+ });
921
+ throw new Error(
922
+ `Item has incorrect key types. Expected [${keyTypes.join(" > ")}], but got [${keyTypeArray.join(" > ")}]. Key: ${JSON.stringify(item.key)}. This indicates a data model mismatch.`
923
+ );
858
924
  }
859
925
  return item;
860
926
  };
@@ -1317,7 +1383,7 @@ var ValidationError = class extends ActionError {
1317
1383
  // Will be filled by wrapper
1318
1384
  details: {
1319
1385
  validOptions,
1320
- suggestedAction,
1386
+ suggestedAction: suggestedAction || (validOptions && validOptions.length > 0 ? `Valid options are: ${validOptions.join(", ")}. Please use one of these values.` : "Check the validation requirements and ensure all fields meet the required format, type, and constraints."),
1321
1387
  retryable: true,
1322
1388
  conflictingValue,
1323
1389
  fieldErrors
@@ -1345,7 +1411,10 @@ var NotFoundError = class extends ActionError {
1345
1411
  itemType,
1346
1412
  key: typeof key === "object" ? key : { primary: key }
1347
1413
  },
1348
- details: { retryable: false },
1414
+ details: {
1415
+ suggestedAction: "Verify the item ID/key is correct, check if the item was deleted, or create the item if it should exist.",
1416
+ retryable: false
1417
+ },
1349
1418
  technical: {
1350
1419
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
1351
1420
  }
@@ -1363,7 +1432,7 @@ var BusinessLogicError = class extends ActionError {
1363
1432
  operation: { type: "action", name: "", params: {} },
1364
1433
  context: { itemType: "" },
1365
1434
  details: {
1366
- suggestedAction,
1435
+ suggestedAction: suggestedAction || "Review the business logic requirements and ensure all conditions are met before retrying.",
1367
1436
  retryable
1368
1437
  },
1369
1438
  technical: {
@@ -1434,6 +1503,7 @@ var DuplicateError = class extends ActionError {
1434
1503
  }
1435
1504
  },
1436
1505
  details: {
1506
+ suggestedAction: duplicateField ? `An item with this ${duplicateField} already exists. Use a different ${duplicateField} value or update the existing item.` : "An item with this key already exists. Use a different key or update the existing item using upsert.",
1437
1507
  retryable: false,
1438
1508
  conflictingValue: duplicateField
1439
1509
  },
@@ -1884,7 +1954,17 @@ function createAllWrapper(coordinate, implementation, wrapperOptions = {}) {
1884
1954
  validateLocations(locations, coordinate, operationName);
1885
1955
  if (allOptions && "limit" in allOptions && allOptions.limit != null) {
1886
1956
  if (!Number.isInteger(allOptions.limit) || allOptions.limit < 1) {
1887
- throw new Error(`[${operationName}] limit must be a positive integer, got: ${allOptions.limit}`);
1957
+ logger10.error(`Invalid limit parameter in ${operationName}`, {
1958
+ component: "core",
1959
+ wrapper: "createAllWrapper",
1960
+ operation: operationName,
1961
+ limit: allOptions.limit,
1962
+ limitType: typeof allOptions.limit,
1963
+ suggestion: "Use a positive integer (1, 2, 3, ...) for limit parameter"
1964
+ });
1965
+ throw new Error(
1966
+ `[${operationName}] limit must be a positive integer, got: ${allOptions.limit} (${typeof allOptions.limit}). Suggestion: Use limit: 10 or similar positive integer value.`
1967
+ );
1888
1968
  }
1889
1969
  }
1890
1970
  if (allOptions && "offset" in allOptions && allOptions.offset != null) {
@@ -1955,8 +2035,27 @@ function createGetWrapper(coordinate, implementation, options = {}) {
1955
2035
  throw options.onError(error, context);
1956
2036
  }
1957
2037
  if (error instanceof NotFoundError) {
2038
+ logger11.debug(`[${operationName}] Item not found`, {
2039
+ component: "core",
2040
+ wrapper: "createGetWrapper",
2041
+ operation: operationName,
2042
+ key: JSON.stringify(key),
2043
+ itemType: coordinate.kta[0],
2044
+ note: "This is expected behavior when item does not exist"
2045
+ });
1958
2046
  throw error;
1959
2047
  }
2048
+ logger11.error(`[${operationName}] Operation failed in wrapper`, {
2049
+ component: "core",
2050
+ wrapper: "createGetWrapper",
2051
+ operation: operationName,
2052
+ key: JSON.stringify(key),
2053
+ itemType: coordinate.kta[0],
2054
+ errorType: error.constructor?.name,
2055
+ errorMessage: error.message,
2056
+ suggestion: "Check key validity, database connectivity, and implementation error handling",
2057
+ coordinate: JSON.stringify(coordinate)
2058
+ });
1960
2059
  throw new Error(
1961
2060
  `[${operationName}] Operation failed: ${error.message}`,
1962
2061
  { cause: error }
@@ -2009,6 +2108,18 @@ Received: ${Array.isArray(item) ? "array" : typeof item}`
2009
2108
  };
2010
2109
  throw wrapperOptions.onError(error, context);
2011
2110
  }
2111
+ logger12.error(`[${operationName}] Operation failed in wrapper`, {
2112
+ component: "core",
2113
+ wrapper: "createCreateWrapper",
2114
+ operation: operationName,
2115
+ itemType: coordinate.kta[0],
2116
+ hasKey: createOptions && "key" in createOptions,
2117
+ hasLocations: createOptions && "locations" in createOptions,
2118
+ errorType: error.constructor?.name,
2119
+ errorMessage: error.message,
2120
+ suggestion: "Check validation rules, required fields, unique constraints, and database connectivity",
2121
+ coordinate: JSON.stringify(coordinate)
2122
+ });
2012
2123
  throw new Error(
2013
2124
  `[${operationName}] Operation failed: ${error.message}`,
2014
2125
  { cause: error }
@@ -2133,6 +2244,17 @@ function createRemoveWrapper(coordinate, implementation, options = {}) {
2133
2244
  };
2134
2245
  throw options.onError(error, context);
2135
2246
  }
2247
+ logger15.error(`[${operationName}] Operation failed in wrapper`, {
2248
+ component: "core",
2249
+ wrapper: "createRemoveWrapper",
2250
+ operation: operationName,
2251
+ key: JSON.stringify(key),
2252
+ itemType: coordinate.kta[0],
2253
+ errorType: error.constructor?.name,
2254
+ errorMessage: error.message,
2255
+ suggestion: "Check item exists, delete permissions, referential integrity, and database connectivity",
2256
+ coordinate: JSON.stringify(coordinate)
2257
+ });
2136
2258
  throw new Error(
2137
2259
  `[${operationName}] Operation failed: ${error.message}`,
2138
2260
  { cause: error }
@@ -2315,6 +2437,19 @@ function createActionWrapper(coordinate, implementation, options = {}) {
2315
2437
  };
2316
2438
  throw options.onError(error, context);
2317
2439
  }
2440
+ logger18.error(`[${operationName}] Action failed in wrapper`, {
2441
+ component: "core",
2442
+ wrapper: "createActionWrapper",
2443
+ operation: operationName,
2444
+ action,
2445
+ key: JSON.stringify(key),
2446
+ params: JSON.stringify(params),
2447
+ itemType: coordinate.kta[0],
2448
+ errorType: error.constructor?.name,
2449
+ errorMessage: error.message,
2450
+ suggestion: "Check action name is valid, item exists, and action implementation",
2451
+ coordinate: JSON.stringify(coordinate)
2452
+ });
2318
2453
  throw new Error(
2319
2454
  `[${operationName}] Action "${action}" failed: ${error.message}`,
2320
2455
  { cause: error }
@@ -296,17 +296,43 @@ Received: '${key.kt}'`
296
296
  var logger4 = logger_default.get("validation", "ItemValidator");
297
297
  var validatePKForItem = (item, pkType) => {
298
298
  if (!item) {
299
- logger4.error("Validating PK, Item is undefined", { item });
300
- throw new Error("Validating PK, Item is undefined");
299
+ logger4.error("Item validation failed - item is undefined", {
300
+ component: "core",
301
+ operation: "validatePK",
302
+ expectedType: pkType,
303
+ item,
304
+ suggestion: "Ensure the operation returns a valid item object, not undefined/null"
305
+ });
306
+ throw new Error(
307
+ `Item validation failed: item is undefined. Expected item of type '${pkType}'. This usually indicates a database operation returned null/undefined unexpectedly.`
308
+ );
301
309
  }
302
310
  if (!item.key) {
303
- logger4.error("Validating PK, Item does not have a key", { item });
304
- throw new Error("Validating PK, Item does not have a key");
311
+ logger4.error("Item validation failed - item missing key", {
312
+ component: "core",
313
+ operation: "validatePK",
314
+ expectedType: pkType,
315
+ item,
316
+ suggestion: "Ensure the item has a valid key property with kt and pk fields"
317
+ });
318
+ throw new Error(
319
+ `Item validation failed: item does not have a key property. Expected key with type '${pkType}'. Item: ${JSON.stringify(item)}. This indicates a database processing error.`
320
+ );
305
321
  }
306
322
  const keyTypeArray = toKeyTypeArray(item.key);
307
323
  if (keyTypeArray[0] !== pkType) {
308
- logger4.error("Key Type Array Mismatch", { keyTypeArray, pkType });
309
- throw new Error(`Item does not have the correct primary key type. Expected ${pkType}, got ${keyTypeArray[0]}`);
324
+ logger4.error("Key type mismatch during validation", {
325
+ component: "core",
326
+ operation: "validatePK",
327
+ expectedType: pkType,
328
+ actualType: keyTypeArray[0],
329
+ keyTypeArray,
330
+ itemKey: item.key,
331
+ suggestion: `Ensure the item key has kt: '${pkType}', not '${keyTypeArray[0]}'`
332
+ });
333
+ throw new Error(
334
+ `Item has incorrect primary key type. Expected '${pkType}', got '${keyTypeArray[0]}'. Key: ${JSON.stringify(item.key)}. This indicates a data model mismatch.`
335
+ );
310
336
  }
311
337
  return item;
312
338
  };
@@ -320,19 +346,57 @@ var validatePK = (input, pkType) => {
320
346
  var validateKeys = (item, keyTypes) => {
321
347
  logger4.trace("Checking Return Type", { item });
322
348
  if (!item) {
323
- throw new Error("validating keys, item is undefined");
349
+ logger4.error("Key validation failed - item is undefined", {
350
+ component: "core",
351
+ operation: "validateKeys",
352
+ expectedKeyTypes: keyTypes,
353
+ suggestion: "Ensure the operation returns a valid item object, not undefined/null"
354
+ });
355
+ throw new Error(
356
+ `Key validation failed: item is undefined. Expected item with key types [${keyTypes.join(", ")}]. This usually indicates a database operation returned null/undefined unexpectedly.`
357
+ );
324
358
  }
325
359
  if (!item.key) {
326
- throw new Error("validating keys, item does not have a key: " + JSON.stringify(item));
360
+ logger4.error("Key validation failed - item missing key", {
361
+ component: "core",
362
+ operation: "validateKeys",
363
+ expectedKeyTypes: keyTypes,
364
+ item: JSON.stringify(item),
365
+ suggestion: "Ensure the item has a valid key property"
366
+ });
367
+ throw new Error(
368
+ `Key validation failed: item does not have a key property. Expected key with types [${keyTypes.join(", ")}]. Item: ${JSON.stringify(item)}. This indicates a database processing error.`
369
+ );
327
370
  }
328
371
  const keyTypeArray = toKeyTypeArray(item.key);
329
372
  if (keyTypeArray.length !== keyTypes.length) {
330
- throw new Error(`Item does not have the correct number of keys. Expected ${keyTypes.length}, but got ${keyTypeArray.length}`);
373
+ logger4.error("Key hierarchy depth mismatch", {
374
+ component: "core",
375
+ operation: "validateKeys",
376
+ expectedKeyTypes: keyTypes,
377
+ expectedDepth: keyTypes.length,
378
+ actualKeyTypes: keyTypeArray,
379
+ actualDepth: keyTypeArray.length,
380
+ itemKey: item.key,
381
+ suggestion: `Check coordinate definition. Expected hierarchy depth of ${keyTypes.length}, got ${keyTypeArray.length}`
382
+ });
383
+ throw new Error(
384
+ `Item has incorrect key hierarchy depth. Expected ${keyTypes.length} levels [${keyTypes.join(" > ")}], but got ${keyTypeArray.length} levels [${keyTypeArray.join(" > ")}]. Key: ${JSON.stringify(item.key)}. This indicates a coordinate/hierarchy mismatch.`
385
+ );
331
386
  }
332
387
  const match = JSON.stringify(keyTypeArray) === JSON.stringify(keyTypes);
333
388
  if (!match) {
334
- logger4.error("Key Type Array Mismatch", { keyTypeArray, thisKeyTypes: keyTypes });
335
- throw new Error(`Item does not have the correct key types. Expected [${keyTypes.join(", ")}], but got [${keyTypeArray.join(", ")}]`);
389
+ logger4.error("Key Type Array Mismatch", {
390
+ component: "core",
391
+ operation: "validateKeys",
392
+ expectedKeyTypes: keyTypes,
393
+ actualKeyTypes: keyTypeArray,
394
+ itemKey: item.key,
395
+ suggestion: `Ensure item key matches expected hierarchy: [${keyTypes.join(" > ")}]`
396
+ });
397
+ throw new Error(
398
+ `Item has incorrect key types. Expected [${keyTypes.join(" > ")}], but got [${keyTypeArray.join(" > ")}]. Key: ${JSON.stringify(item.key)}. This indicates a data model mismatch.`
399
+ );
336
400
  }
337
401
  return item;
338
402
  };
@@ -518,7 +582,7 @@ var ValidationError = class extends ActionError {
518
582
  // Will be filled by wrapper
519
583
  details: {
520
584
  validOptions,
521
- suggestedAction,
585
+ suggestedAction: suggestedAction || (validOptions && validOptions.length > 0 ? `Valid options are: ${validOptions.join(", ")}. Please use one of these values.` : "Check the validation requirements and ensure all fields meet the required format, type, and constraints."),
522
586
  retryable: true,
523
587
  conflictingValue,
524
588
  fieldErrors
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fjell/core",
3
3
  "description": "Core Item and Key Framework for Fjell",
4
- "version": "4.4.72",
4
+ "version": "4.4.73",
5
5
  "keywords": [
6
6
  "core",
7
7
  "fjell"