@fjell/core 4.4.3 → 4.4.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fjell/core",
3
3
  "description": "Core Items for Fjell",
4
- "version": "4.4.3",
4
+ "version": "4.4.5",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/cjs/index.js",
7
7
  "module": "./dist/esm/index.js",
@@ -14,30 +14,30 @@
14
14
  },
15
15
  "type": "module",
16
16
  "dependencies": {
17
- "@fjell/logging": "^4.4.2",
17
+ "@fjell/logging": "^4.4.4",
18
18
  "deepmerge": "^4.3.1",
19
19
  "flatted": "^3.3.3",
20
20
  "luxon": "^3.6.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@eslint/eslintrc": "^3.3.1",
24
- "@eslint/js": "^9.29.0",
25
- "@swc/core": "^1.12.1",
26
- "@tsconfig/recommended": "^1.0.9",
24
+ "@eslint/js": "^9.30.0",
25
+ "@swc/core": "^1.12.7",
26
+ "@tsconfig/recommended": "^1.0.10",
27
27
  "@types/luxon": "^3.6.2",
28
- "@typescript-eslint/eslint-plugin": "^8.34.1",
29
- "@typescript-eslint/parser": "^8.34.1",
30
- "@vitest/coverage-v8": "3.1.4",
31
- "concurrently": "^9.1.2",
28
+ "@typescript-eslint/eslint-plugin": "^8.35.0",
29
+ "@typescript-eslint/parser": "^8.35.0",
30
+ "@vitest/coverage-v8": "3.2.4",
31
+ "concurrently": "^9.2.0",
32
32
  "copyfiles": "^2.4.1",
33
- "eslint": "^9.29.0",
33
+ "eslint": "^9.30.0",
34
34
  "rimraf": "^6.0.1",
35
35
  "tsc-alias": "^1.8.16",
36
36
  "typescript": "^5.8.3",
37
- "vite": "^6.3.5",
37
+ "vite": "^7.0.0",
38
38
  "vite-plugin-dts": "^4.5.4",
39
39
  "vite-plugin-node": "^5.0.1",
40
- "vitest": "3.1.4"
40
+ "vitest": "3.2.4"
41
41
  },
42
42
  "repository": {
43
43
  "type": "git",
@@ -1,3 +1,5 @@
1
+ /* eslint-disable indent */
2
+ /* eslint-disable max-len */
1
3
  import { Item } from "@/items";
2
4
  import { isComKey, isPriKey, toKeyTypeArray } from "@/key/KUtils";
3
5
  import { AllItemTypeArrays, ComKey, PriKey } from "@/keys";
@@ -6,42 +8,48 @@ import LibLogger from '@/logger';
6
8
 
7
9
  const logger = LibLogger.get('IUtils');
8
10
 
9
- export const validatePK = <
11
+ const validatePKForItem = <
10
12
  S extends string,
11
13
  L1 extends string = never,
12
14
  L2 extends string = never,
13
15
  L3 extends string = never,
14
16
  L4 extends string = never,
15
- L5 extends string = never
16
- >(input: Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[], pkType: S):
17
- Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[] => {
17
+ L5 extends string = never,
18
+ >(item: Item<S, L1, L2, L3, L4, L5>, pkType: S): Item<S, L1, L2, L3, L4, L5> => {
19
+ if (!item) {
20
+ logger.error('Validating PK, Item is undefined', { item });
21
+ throw new Error('Validating PK, Item is undefined');
22
+ }
23
+ if (!item.key) {
24
+ logger.error('Validating PK, Item does not have a key', { item });
25
+ throw new Error('Validating PK, Item does not have a key');
26
+ }
18
27
 
28
+ const keyTypeArray = toKeyTypeArray(item.key as ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>);
29
+ if (keyTypeArray[0] !== pkType) {
30
+ logger.error('Key Type Array Mismatch', { keyTypeArray, pkType });
31
+ throw new Error(`Item does not have the correct primary key type. Expected ${pkType}, got ${keyTypeArray[0]}`);
32
+ }
33
+ return item;
34
+ };
35
+
36
+ export const validatePK = <
37
+ S extends string,
38
+ L1 extends string = never,
39
+ L2 extends string = never,
40
+ L3 extends string = never,
41
+ L4 extends string = never,
42
+ L5 extends string = never,
43
+ >(
44
+ input: Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[],
45
+ pkType: S,
46
+ ): Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[] => {
19
47
  logger.trace('Checking Return Type', { input });
20
48
 
21
49
  if (Array.isArray(input)) {
22
- const itemArray = input as Item<S, L1, L2, L3, L4, L5>[];
23
- return itemArray.map((item) => validatePK(item, pkType)) as Item<S, L1, L2, L3, L4, L5>[];
24
- } else {
25
- const item = input as Item<S, L1, L2, L3, L4, L5>;
26
- if( item ) {
27
- if (item.key) {
28
- const keyTypeArray = toKeyTypeArray(item.key as ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>);
29
- const match: boolean = keyTypeArray[0] === pkType;
30
- if (!match) {
31
- logger.error('Key Type Array Mismatch', { keyTypeArray, pkType });
32
- throw new Error('Item does not have the correct primary key type');
33
- } else {
34
- return item;
35
- }
36
- } else {
37
- logger.error('Validating PK, Item does not have a key', { item });
38
- throw new Error('Validating PK, Item does not have a key');
39
- }
40
- } else {
41
- logger.error('Validating PK, Item is undefined', { item });
42
- throw new Error('Validating PK, Item is undefined');
43
- }
50
+ return input.map((item) => validatePKForItem(item, pkType));
44
51
  }
52
+ return validatePKForItem(input, pkType);
45
53
  };
46
54
 
47
55
  export const validateKeys = <
@@ -50,30 +58,30 @@ export const validateKeys = <
50
58
  L2 extends string = never,
51
59
  L3 extends string = never,
52
60
  L4 extends string = never,
53
- L5 extends string = never
54
- >(item: Item<S, L1, L2, L3, L4, L5>, keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>):
55
- Item<S, L1, L2, L3, L4, L5> => {
61
+ L5 extends string = never,
62
+ >(
63
+ item: Item<S, L1, L2, L3, L4, L5>,
64
+ keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>,
65
+ ): Item<S, L1, L2, L3, L4, L5> => {
56
66
  logger.trace('Checking Return Type', { item });
57
- if( item ) {
58
- if (item.key) {
59
- const keyTypeArray = toKeyTypeArray(item.key as ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>);
60
- if (keyTypeArray.length !== keyTypes.length) {
61
- throw new Error('Item does not have the correct number of keys');
62
- } else {
63
- const match: boolean = JSON.stringify(keyTypeArray) === JSON.stringify(keyTypes);
64
- if (!match) {
65
- logger.error('Key Type Array Mismatch', { keyTypeArray, thisKeyTypes: keyTypes });
66
- throw new Error('Item does not have the correct key types');
67
- } else {
68
- return item;
69
- }
70
- }
71
- } else {
72
- throw new Error('validating keys, item does not have a key: ' + JSON.stringify(item));
73
- }
74
- } else {
67
+ if (!item) {
75
68
  throw new Error('validating keys, item is undefined');
76
69
  }
70
+ if (!item.key) {
71
+ throw new Error('validating keys, item does not have a key: ' + JSON.stringify(item));
72
+ }
73
+
74
+ const keyTypeArray = toKeyTypeArray(item.key as ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>);
75
+ if (keyTypeArray.length !== keyTypes.length) {
76
+ throw new Error(`Item does not have the correct number of keys. Expected ${keyTypes.length}, but got ${keyTypeArray.length}`);
77
+ }
78
+
79
+ const match: boolean = JSON.stringify(keyTypeArray) === JSON.stringify(keyTypes);
80
+ if (!match) {
81
+ logger.error('Key Type Array Mismatch', { keyTypeArray, thisKeyTypes: keyTypes });
82
+ throw new Error(`Item does not have the correct key types. Expected [${keyTypes.join(', ')}], but got [${keyTypeArray.join(', ')}]`);
83
+ }
84
+ return item;
77
85
  };
78
86
 
79
87
  export const isPriItem = <
@@ -82,10 +90,12 @@ export const isPriItem = <
82
90
  L2 extends string = never,
83
91
  L3 extends string = never,
84
92
  L4 extends string = never,
85
- L5 extends string = never
86
- >(item: Item<S, L1, L2, L3, L4, L5>): item is Item<S, L1, L2, L3, L4, L5> => {
87
- return (item && item.key) ? isPriKey(item.key as PriKey<S>) : false;
88
- }
93
+ L5 extends string = never,
94
+ >(
95
+ item: Item<S, L1, L2, L3, L4, L5>,
96
+ ): item is Item<S> & { key: PriKey<S> } => {
97
+ return !!(item && item.key && isPriKey(item.key));
98
+ };
89
99
 
90
100
  export const isComItem = <
91
101
  S extends string,
@@ -93,7 +103,9 @@ export const isComItem = <
93
103
  L2 extends string = never,
94
104
  L3 extends string = never,
95
105
  L4 extends string = never,
96
- L5 extends string = never
97
- >(item: Item<S, L1, L2, L3, L4, L5>): item is Item<S, L1, L2, L3, L4, L5> => {
98
- return (item && item.key) ? isComKey(item.key as ComKey<S, L1, L2, L3, L4, L5>) : false;
99
- }
106
+ L5 extends string = never,
107
+ >(
108
+ item: Item<S, L1, L2, L3, L4, L5>,
109
+ ): item is Item<S, L1, L2, L3, L4, L5> & { key: ComKey<S, L1, L2, L3, L4, L5> } => {
110
+ return !!(item && item.key && isComKey(item.key));
111
+ };
package/src/items.ts CHANGED
@@ -16,8 +16,6 @@ export type Identified<S extends string,
16
16
  key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>;
17
17
  };
18
18
 
19
- export type Propertied = { [key: string]: any };
20
-
21
19
  /**
22
20
  * This is a generic item event, and it's designed to make sure we have the ability to define not just
23
21
  * the required fields, but also the optional fields.
@@ -48,29 +46,6 @@ export interface Deletable extends Partial<Evented> {
48
46
 
49
47
  export type ManagedEvents = Timestamped & Deletable;
50
48
 
51
- export type ItemProperties<
52
- S extends string,
53
- L1 extends string = never,
54
- L2 extends string = never,
55
- L3 extends string = never,
56
- L4 extends string = never,
57
- L5 extends string = never> =
58
- Omit<Item<S, L1, L2, L3, L4, L5>, 'events' | 'key'> & {
59
- events?: Evented;
60
- };
61
-
62
- export type TypesProperties<
63
- V extends Item<S, L1, L2, L3, L4, L5>,
64
- S extends string,
65
- L1 extends string = never,
66
- L2 extends string = never,
67
- L3 extends string = never,
68
- L4 extends string = never,
69
- L5 extends string = never> =
70
- Omit<V, 'events' | 'key'> & {
71
- events?: Evented;
72
- };
73
-
74
49
  export type References = Record<
75
50
  string,
76
51
  ComKey<string, string | never, string | never, string | never, string | never, string | never> |
@@ -94,9 +69,43 @@ export interface Item<S extends string = never,
94
69
  L2 extends string = never,
95
70
  L3 extends string = never,
96
71
  L4 extends string = never,
97
- L5 extends string = never> extends Identified<S, L1, L2, L3, L4, L5>, Propertied {
72
+ L5 extends string = never> extends Identified<S, L1, L2, L3, L4, L5> {
98
73
  events: ManagedEvents & Evented;
99
74
  // TODO: This is a bit of a hack to get around the fact that we don't want to pass all these generics
100
75
  aggs?: ReferenceItems;
101
76
  refs?: References;
77
+ [key: string]: any
102
78
  }
79
+
80
+ /**
81
+ * Interface for properties that can be added to items
82
+ */
83
+ export interface Propertied {
84
+ name: string;
85
+ value: number;
86
+ }
87
+
88
+ /**
89
+ * Type for item properties without the key - equivalent to Partial<Item> without the key
90
+ */
91
+ export type ItemProperties<
92
+ S extends string = never,
93
+ L1 extends string = never,
94
+ L2 extends string = never,
95
+ L3 extends string = never,
96
+ L4 extends string = never,
97
+ L5 extends string = never
98
+ > = Partial<Omit<Item<S, L1, L2, L3, L4, L5>, 'key'>>;
99
+
100
+ /**
101
+ * Type for item properties without the key - equivalent to Partial<Item> without the key
102
+ * This is an alias for ItemProperties for backward compatibility
103
+ */
104
+ export type TypesProperties<
105
+ S extends string = never,
106
+ L1 extends string = never,
107
+ L2 extends string = never,
108
+ L3 extends string = never,
109
+ L4 extends string = never,
110
+ L5 extends string = never
111
+ > = Partial<Omit<Item<S, L1, L2, L3, L4, L5>, 'key'>>;
package/src/key/KUtils.ts CHANGED
@@ -23,7 +23,7 @@ export const isItemKeyEqual = <
23
23
  if (isComKey(a) && isComKey(b)) {
24
24
  return isComKeyEqual(a as ComKey<S, L1, L2, L3, L4, L5>, b as ComKey<S, L1, L2, L3, L4, L5>);
25
25
  } else if (isPriKey(a) && isPriKey(b)) {
26
- if(isComKey(a) || isComKey(b)) {
26
+ if (isComKey(a) || isComKey(b)) {
27
27
  return false;
28
28
  } else {
29
29
  return isPriKeyEqual(a as PriKey<S>, b as PriKey<S>);
@@ -163,7 +163,7 @@ export const toKeyTypeArray = <
163
163
  logger.trace('toKeyTypeArray', { ik });
164
164
  if (isComKey(ik)) {
165
165
  const ck = ik as ComKey<S, L1, L2, L3, L4, L5>;
166
- return [ck.kt, ...ck.loc.map((l : LocKey<L1 | L2 | L3 | L4 | L5>) => l.kt)];
166
+ return [ck.kt, ...ck.loc.map((l: LocKey<L1 | L2 | L3 | L4 | L5>) => l.kt)];
167
167
  } else {
168
168
  return [(ik as PriKey<S>).kt];
169
169
  }
@@ -178,10 +178,10 @@ export const abbrevIK = <
178
178
  L5 extends string = never
179
179
  >(ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): string => {
180
180
  logger.trace('abbrevIK', { ik });
181
- if(ik) {
181
+ if (ik) {
182
182
  if (isComKey(ik)) {
183
183
  const ck = ik as ComKey<S, L1, L2, L3, L4, L5>;
184
- return `${ck.kt}:${ck.pk}:${ck.loc.map((l : LocKey<L1 | L2 | L3 | L4 | L5>) => `${l.kt}:${l.lk}`).join(',')}`;
184
+ return `${ck.kt}:${ck.pk}:${ck.loc.map((l: LocKey<L1 | L2 | L3 | L4 | L5>) => `${l.kt}:${l.lk}`).join(',')}`;
185
185
  } else {
186
186
  return `${(ik as PriKey<S>).kt}:${(ik as PriKey<S>).pk}`;
187
187
  }
@@ -228,10 +228,10 @@ export const primaryType = <
228
228
  }
229
229
 
230
230
  /**
231
- *
232
- * @param ik ItemKey to be used as a basis for a location
233
- * @returns
234
- */
231
+ *
232
+ * @param ik ItemKey to be used as a basis for a location
233
+ * @returns
234
+ */
235
235
  export const itemKeyToLocKeyArray =
236
236
  <
237
237
  S extends string,
@@ -257,10 +257,10 @@ export const itemKeyToLocKeyArray =
257
257
  export const ikToLKA = itemKeyToLocKeyArray;
258
258
 
259
259
  /**
260
- * Sometimes you need to take a location key array and convert it to the item key that points to the containing item.
261
- * @param lka A location key array
262
- * @returns An item key corresponding to the containing item this location refers to.
263
- */
260
+ * Sometimes you need to take a location key array and convert it to the item key that points to the containing item.
261
+ * @param lka A location key array
262
+ * @returns An item key corresponding to the containing item this location refers to.
263
+ */
264
264
  export const locKeyArrayToItemKey =
265
265
  <
266
266
  L1 extends string,
@@ -272,7 +272,7 @@ export const locKeyArrayToItemKey =
272
272
  PriKey<L1> | ComKey<L1, L2, L3, L4, L5> => {
273
273
  logger.trace('locKeyArrayToItemKey', { lka: abbrevLKA(lka as Array<LocKey<L1 | L2 | L3 | L4 | L5>>) });
274
274
 
275
- if(lka && lka.length === 1) {
275
+ if (lka && lka.length === 1) {
276
276
  const priKey = cPK(lka[0].lk, lka[0].kt);
277
277
  return priKey as PriKey<L1>;
278
278
  } else if (lka && lka.length > 1 && lka[0] !== undefined) {
package/vitest.config.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineConfig } from 'vitest/config';
2
- import path from 'path';
2
+ import * as path from 'path';
3
3
 
4
4
  export default defineConfig({
5
5
  resolve: {