@fjell/core 4.4.6 → 4.4.12

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.
Files changed (41) hide show
  1. package/README.md +227 -0
  2. package/dist/cjs/index.js +5 -0
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/item/IQUtils.js +20 -1
  5. package/dist/cjs/item/IQUtils.js.map +1 -1
  6. package/dist/cjs/item/IUtils.js.map +1 -1
  7. package/dist/cjs/key/KUtils.js +100 -1
  8. package/dist/cjs/key/KUtils.js.map +1 -1
  9. package/dist/esm/index.js +1 -1
  10. package/dist/esm/item/IQUtils.js +2 -2
  11. package/dist/esm/item/IQUtils.js.map +1 -1
  12. package/dist/esm/item/IUtils.js.map +1 -1
  13. package/dist/esm/key/KUtils.js +96 -2
  14. package/dist/esm/key/KUtils.js.map +1 -1
  15. package/dist/index.cjs +120 -2
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/key/KUtils.d.ts +7 -2
  18. package/dist/keys.d.ts +3 -3
  19. package/docs/README.md +53 -0
  20. package/docs/index.html +18 -0
  21. package/docs/package.json +35 -0
  22. package/docs/public/README.md +227 -0
  23. package/docs/public/api.md +230 -0
  24. package/docs/public/basic-usage.ts +293 -0
  25. package/docs/public/examples-README.md +147 -0
  26. package/docs/public/fjell-icon.svg +1 -0
  27. package/docs/public/package.json +56 -0
  28. package/docs/public/pano.png +0 -0
  29. package/docs/src/App.css +1178 -0
  30. package/docs/src/App.tsx +684 -0
  31. package/docs/src/index.css +38 -0
  32. package/docs/src/main.tsx +10 -0
  33. package/docs/tsconfig.node.json +14 -0
  34. package/docs/vitest.config.ts +14 -0
  35. package/examples/README.md +147 -0
  36. package/examples/basic-usage.ts +293 -0
  37. package/package.json +10 -9
  38. package/src/item/IQUtils.ts +3 -3
  39. package/src/item/IUtils.ts +1 -1
  40. package/src/key/KUtils.ts +114 -6
  41. package/src/keys.ts +3 -3
package/src/key/KUtils.ts CHANGED
@@ -3,14 +3,122 @@ import {
3
3
  ComKey,
4
4
  LocKey,
5
5
  LocKeyArray,
6
- PriKey,
7
- UUID
6
+ PriKey
8
7
  } from "@/keys";
9
8
 
10
9
  import LibLogger from "@/logger";
11
10
 
12
11
  const logger = LibLogger.get('KUtils');
13
12
 
13
+ // Normalize a key value to string for consistent comparison and hashing
14
+ const normalizeKeyValue = (value: string | number): string => {
15
+ return String(value);
16
+ };
17
+
18
+ // Normalized hash function for Dictionary that converts pk/lk values to strings
19
+ export const createNormalizedHashFunction = <T>() => {
20
+ return (key: T): string => {
21
+ if (typeof key === 'object' && key !== null) {
22
+ // Create a normalized version of the key with string values
23
+ const normalizedKey = JSON.parse(JSON.stringify(key));
24
+
25
+ // Normalize pk values
26
+ if ('pk' in normalizedKey && (normalizedKey.pk !== undefined && normalizedKey.pk !== null)) {
27
+ normalizedKey.pk = normalizeKeyValue(normalizedKey.pk);
28
+ }
29
+
30
+ // Normalize lk values
31
+ if ('lk' in normalizedKey && (normalizedKey.lk !== undefined && normalizedKey.lk !== null)) {
32
+ normalizedKey.lk = normalizeKeyValue(normalizedKey.lk);
33
+ }
34
+
35
+ // Normalize loc array lk values
36
+ if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
37
+ normalizedKey.loc = normalizedKey.loc.map((locItem: any) => {
38
+ if (locItem && 'lk' in locItem && (locItem.lk !== undefined && locItem.lk !== null)) {
39
+ return { ...locItem, lk: normalizeKeyValue(locItem.lk) };
40
+ }
41
+ return locItem;
42
+ });
43
+ }
44
+
45
+ return JSON.stringify(normalizedKey);
46
+ }
47
+ return JSON.stringify(key);
48
+ };
49
+ };
50
+
51
+ // Normalized comparison functions
52
+ export const isPriKeyEqualNormalized = <
53
+ S extends string,
54
+ >(a: PriKey<S>, b: PriKey<S>): boolean => {
55
+ logger.trace('isPriKeyEqualNormalized', { a, b });
56
+ return a && b &&
57
+ normalizeKeyValue(a.pk) === normalizeKeyValue(b.pk) &&
58
+ a.kt === b.kt;
59
+ };
60
+
61
+ export const isLocKeyEqualNormalized = <
62
+ L1 extends string,
63
+ L2 extends string = never,
64
+ L3 extends string = never,
65
+ L4 extends string = never,
66
+ L5 extends string = never
67
+ >(a: LocKey<L1 | L2 | L3 | L4 | L5>, b: LocKey<L1 | L2 | L3 | L4 | L5>): boolean => {
68
+ logger.trace('isLocKeyEqualNormalized', { a, b });
69
+ return a && b &&
70
+ normalizeKeyValue(a.lk) === normalizeKeyValue(b.lk) &&
71
+ a.kt === b.kt;
72
+ };
73
+
74
+ export const isComKeyEqualNormalized = <
75
+ S extends string,
76
+ L1 extends string = never,
77
+ L2 extends string = never,
78
+ L3 extends string = never,
79
+ L4 extends string = never,
80
+ L5 extends string = never
81
+ >(a: ComKey<S, L1, L2, L3, L4, L5>, b: ComKey<S, L1, L2, L3, L4, L5>): boolean => {
82
+ logger.trace('isComKeyEqualNormalized', { a, b });
83
+ if (a && b && isPriKeyEqualNormalized({ kt: a.kt, pk: a.pk } as PriKey<S>, { kt: b.kt, pk: b.pk } as PriKey<S>)) {
84
+ if (a.loc.length === b.loc.length) {
85
+ for (let i = 0; i < a.loc.length; i++) {
86
+ if (!isLocKeyEqualNormalized<L1, L2, L3, L4, L5>(a.loc[i], b.loc[i])) {
87
+ return false;
88
+ }
89
+ }
90
+ return true;
91
+ } else {
92
+ return false;
93
+ }
94
+ } else {
95
+ return false;
96
+ }
97
+ };
98
+
99
+ export const isItemKeyEqualNormalized = <
100
+ S extends string,
101
+ L1 extends string = never,
102
+ L2 extends string = never,
103
+ L3 extends string = never,
104
+ L4 extends string = never,
105
+ L5 extends string = never
106
+ >(a: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, b: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): boolean => {
107
+ logger.trace('isItemKeyEqualNormalized', { a, b });
108
+ if (isComKey(a) && isComKey(b)) {
109
+ return isComKeyEqualNormalized(a as ComKey<S, L1, L2, L3, L4, L5>, b as ComKey<S, L1, L2, L3, L4, L5>);
110
+ } else if (isPriKey(a) && isPriKey(b)) {
111
+ if (isComKey(a) || isComKey(b)) {
112
+ return false;
113
+ } else {
114
+ return isPriKeyEqualNormalized(a as PriKey<S>, b as PriKey<S>);
115
+ }
116
+ } else {
117
+ return false;
118
+ }
119
+ };
120
+
121
+ // Original comparison functions (kept for backward compatibility)
14
122
  export const isItemKeyEqual = <
15
123
  S extends string,
16
124
  L1 extends string = never,
@@ -31,7 +139,7 @@ export const isItemKeyEqual = <
31
139
  } else {
32
140
  return false;
33
141
  }
34
- }
142
+ };
35
143
 
36
144
  export const isPriKeyEqual = <
37
145
  S extends string,
@@ -135,13 +243,13 @@ export const generateKeyArray = <
135
243
 
136
244
  // TODO: Exactly the same as in ContainedItemLib
137
245
  export const constructPriKey = <S extends string>(
138
- pk: string | PriKey<S>,
246
+ pk: string | number | PriKey<S>,
139
247
  kt: S,
140
248
  ) => {
141
249
  logger.trace('constructPriKey', { pk, kt });
142
250
  let pri: PriKey<S>;
143
- if (typeof pk === 'string') {
144
- pri = { kt: kt as S, pk: pk as UUID };
251
+ if (typeof pk === 'string' || typeof pk === 'number') {
252
+ pri = { kt: kt as S, pk: pk };
145
253
  } else {
146
254
  pri = pk;
147
255
  }
package/src/keys.ts CHANGED
@@ -10,7 +10,7 @@ export interface ComKey<
10
10
  L5 extends string = never
11
11
  > {
12
12
  readonly kt: S,
13
- readonly pk: UUID | string,
13
+ readonly pk: UUID | string | number,
14
14
  readonly loc: LocKeyArray<L1, L2, L3, L4, L5>
15
15
  };
16
16
 
@@ -18,14 +18,14 @@ export interface PriKey<
18
18
  S extends string,
19
19
  > {
20
20
  readonly kt: S,
21
- readonly pk: UUID | string,
21
+ readonly pk: UUID | string | number,
22
22
  };
23
23
 
24
24
  export interface LocKey<
25
25
  L extends string
26
26
  > {
27
27
  readonly kt: L,
28
- readonly lk: UUID | string
28
+ readonly lk: UUID | string | number
29
29
  };
30
30
  export type LocKeyArray<
31
31
  L1 extends string = never,