@fjell/core 4.4.50 → 4.4.52

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 (56) hide show
  1. package/package.json +3 -3
  2. package/src/AItemService.ts +0 -38
  3. package/src/Coordinate.ts +0 -35
  4. package/src/dictionary.ts +0 -84
  5. package/src/errors/ActionError.ts +0 -69
  6. package/src/errors/BusinessLogicError.ts +0 -24
  7. package/src/errors/DuplicateError.ts +0 -57
  8. package/src/errors/NotFoundError.ts +0 -24
  9. package/src/errors/PermissionError.ts +0 -31
  10. package/src/errors/ValidationError.ts +0 -27
  11. package/src/errors/index.ts +0 -7
  12. package/src/event/emitter.ts +0 -247
  13. package/src/event/events.ts +0 -178
  14. package/src/event/index.ts +0 -130
  15. package/src/event/matching.ts +0 -264
  16. package/src/event/subscription.ts +0 -181
  17. package/src/event/types.ts +0 -282
  18. package/src/index.ts +0 -70
  19. package/src/item/IFactory.ts +0 -122
  20. package/src/item/IQFactory.ts +0 -163
  21. package/src/item/IQUtils.ts +0 -392
  22. package/src/item/IUtils.ts +0 -40
  23. package/src/item/ItemQuery.ts +0 -88
  24. package/src/items.ts +0 -120
  25. package/src/key/KUtils.ts +0 -484
  26. package/src/keys.ts +0 -95
  27. package/src/logger.ts +0 -5
  28. package/src/operations/OperationContext.ts +0 -12
  29. package/src/operations/Operations.ts +0 -357
  30. package/src/operations/contained.ts +0 -134
  31. package/src/operations/errorEnhancer.ts +0 -204
  32. package/src/operations/index.ts +0 -2
  33. package/src/operations/methods.ts +0 -363
  34. package/src/operations/primary.ts +0 -101
  35. package/src/operations/specialized.ts +0 -71
  36. package/src/operations/wrappers/createActionWrapper.ts +0 -108
  37. package/src/operations/wrappers/createAllActionWrapper.ts +0 -109
  38. package/src/operations/wrappers/createAllFacetWrapper.ts +0 -98
  39. package/src/operations/wrappers/createAllWrapper.ts +0 -103
  40. package/src/operations/wrappers/createCreateWrapper.ts +0 -117
  41. package/src/operations/wrappers/createFacetWrapper.ts +0 -97
  42. package/src/operations/wrappers/createFindOneWrapper.ts +0 -105
  43. package/src/operations/wrappers/createFindWrapper.ts +0 -105
  44. package/src/operations/wrappers/createGetWrapper.ts +0 -96
  45. package/src/operations/wrappers/createOneWrapper.ts +0 -128
  46. package/src/operations/wrappers/createRemoveWrapper.ts +0 -91
  47. package/src/operations/wrappers/createUpdateWrapper.ts +0 -106
  48. package/src/operations/wrappers/createUpsertWrapper.ts +0 -108
  49. package/src/operations/wrappers/index.ts +0 -39
  50. package/src/operations/wrappers/types.ts +0 -63
  51. package/src/validation/ItemValidator.ts +0 -131
  52. package/src/validation/KeyValidator.ts +0 -365
  53. package/src/validation/LocationValidator.ts +0 -136
  54. package/src/validation/QueryValidator.ts +0 -250
  55. package/src/validation/index.ts +0 -32
  56. package/src/validation/types.ts +0 -45
package/src/items.ts DELETED
@@ -1,120 +0,0 @@
1
- import { ComKey, PriKey } from './keys';
2
-
3
- export type RecursivePartial<T> = {
4
- [P in keyof T]?:
5
- T[P] extends (infer U)[] ? RecursivePartial<U>[] :
6
- T[P] extends object | undefined ? RecursivePartial<T[P]> :
7
- T[P];
8
- };
9
-
10
- export type Identified<S extends string,
11
- L1 extends string = never,
12
- L2 extends string = never,
13
- L3 extends string = never,
14
- L4 extends string = never,
15
- L5 extends string = never> = {
16
- key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>;
17
- };
18
-
19
- /**
20
- * This is a generic item event, and it's designed to make sure we have the ability to define not just
21
- * the required fields, but also the optional fields.
22
- */
23
- export interface ItemEvent {
24
- at: Date | null;
25
- by?: ComKey<any, any | never, any | never, any | never, any | never, any | never> | PriKey<any>;
26
- agg?: Item<any, any, any, any, any, any>;
27
- }
28
-
29
- /**
30
- * This is a required item event, and it's here mainly to define that there are events that must be present.
31
- */
32
- export interface RequiredItemEvent extends ItemEvent {
33
- at: Date;
34
- }
35
-
36
- export type Evented = Record<string, ItemEvent>;
37
-
38
- export interface Timestamped extends Evented {
39
- created: RequiredItemEvent;
40
- updated: RequiredItemEvent;
41
- };
42
-
43
- export interface Deletable extends Partial<Evented> {
44
- deleted: ItemEvent;
45
- };
46
-
47
- export type ManagedEvents = Timestamped & Deletable;
48
-
49
- export type Reference<S extends string,
50
- L1 extends string = never,
51
- L2 extends string = never,
52
- L3 extends string = never,
53
- L4 extends string = never,
54
- L5 extends string = never
55
- > = { key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, item?: Item<S, L1, L2, L3, L4, L5> };
56
-
57
- export type ReferenceItem<S extends string,
58
- L1 extends string = never,
59
- L2 extends string = never,
60
- L3 extends string = never,
61
- L4 extends string = never,
62
- L5 extends string = never
63
- > = Reference<S, L1, L2, L3, L4, L5>;
64
-
65
- export type References = Record<string, Reference<any, any, any, any, any, any>>;
66
-
67
- export type Aggregation<
68
- S extends string,
69
- L1 extends string = never,
70
- L2 extends string = never,
71
- L3 extends string = never,
72
- L4 extends string = never,
73
- L5 extends string = never
74
- > = { key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, item?: Item<S, L1, L2, L3, L4, L5> };
75
-
76
- export interface Item<S extends string = never,
77
- L1 extends string = never,
78
- L2 extends string = never,
79
- L3 extends string = never,
80
- L4 extends string = never,
81
- L5 extends string = never> extends Identified<S, L1, L2, L3, L4, L5> {
82
- events: ManagedEvents & Evented;
83
- // TODO: This is a bit of a hack to get around the fact that we don't want to pass all these generics
84
- aggs?: Record<string, Aggregation<any, any, any, any, any, any>[]>;
85
- refs?: Record<string, Reference<any, any, any, any, any, any>>;
86
- [key: string]: any
87
- }
88
-
89
- /**
90
- * Interface for properties that can be added to items
91
- */
92
- export interface Propertied {
93
- name: string;
94
- value: number;
95
- }
96
-
97
- /**
98
- * Type for item properties without the key - equivalent to Partial<Item> without the key
99
- */
100
- export type ItemProperties<
101
- S extends string = never,
102
- L1 extends string = never,
103
- L2 extends string = never,
104
- L3 extends string = never,
105
- L4 extends string = never,
106
- L5 extends string = never
107
- > = Partial<Omit<Item<S, L1, L2, L3, L4, L5>, 'key'>>;
108
-
109
- /**
110
- * Type for item properties without the key - equivalent to Partial<Item> without the key
111
- * This is an alias for ItemProperties for backward compatibility
112
- */
113
- export type TypesProperties<
114
- S extends string = never,
115
- L1 extends string = never,
116
- L2 extends string = never,
117
- L3 extends string = never,
118
- L4 extends string = never,
119
- L5 extends string = never
120
- > = Partial<Omit<Item<S, L1, L2, L3, L4, L5>, 'key'>>;
package/src/key/KUtils.ts DELETED
@@ -1,484 +0,0 @@
1
- /* eslint-disable no-undefined */
2
- import {
3
- ComKey,
4
- LocKey,
5
- LocKeyArray,
6
- PriKey
7
- } from "../keys";
8
-
9
- import LibLogger from "../logger";
10
-
11
- const logger = LibLogger.get('KUtils');
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)
122
- export const isItemKeyEqual = <
123
- S extends string,
124
- L1 extends string = never,
125
- L2 extends string = never,
126
- L3 extends string = never,
127
- L4 extends string = never,
128
- L5 extends string = never
129
- >(a: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, b: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): boolean => {
130
- logger.trace('isKeyEqual', { a, b });
131
- if (isComKey(a) && isComKey(b)) {
132
- return isComKeyEqual(a as ComKey<S, L1, L2, L3, L4, L5>, b as ComKey<S, L1, L2, L3, L4, L5>);
133
- } else if (isPriKey(a) && isPriKey(b)) {
134
- if (isComKey(a) || isComKey(b)) {
135
- return false;
136
- } else {
137
- return isPriKeyEqual(a as PriKey<S>, b as PriKey<S>);
138
- }
139
- } else {
140
- return false;
141
- }
142
- };
143
-
144
- export const isPriKeyEqual = <
145
- S extends string,
146
- >(a: PriKey<S>, b: PriKey<S>): boolean => {
147
- logger.trace('isPriKeyEqual', { a, b });
148
- return a && b && a.pk === b.pk && a.kt === b.kt;
149
- }
150
-
151
- export const isLocKeyEqual = <
152
- L1 extends string,
153
- L2 extends string = never,
154
- L3 extends string = never,
155
- L4 extends string = never,
156
- L5 extends string = never
157
- >(a: LocKey<L1 | L2 | L3 | L4 | L5>, b: LocKey<L1 | L2 | L3 | L4 | L5>): boolean => {
158
- logger.trace('isLocKeyEqual', { a, b });
159
- return a && b && a.lk === b.lk && a.kt === b.kt;
160
- }
161
-
162
- export const isComKeyEqual = <
163
- S extends string,
164
- L1 extends string = never,
165
- L2 extends string = never,
166
- L3 extends string = never,
167
- L4 extends string = never,
168
- L5 extends string = never
169
- >(a: ComKey<S, L1, L2, L3, L4, L5>, b: ComKey<S, L1, L2, L3, L4, L5>): boolean => {
170
- logger.trace('isComKeyEqual', { a, b });
171
- if (a && b && isPriKeyEqual({ kt: a.kt, pk: a.pk } as PriKey<S>, { kt: b.kt, pk: b.pk } as PriKey<S>)) {
172
- if (a.loc.length === b.loc.length) {
173
- for (let i = 0; i < a.loc.length; i++) {
174
- if (!isLocKeyEqual<L1, L2, L3, L4, L5>(a.loc[i], b.loc[i])) {
175
- return false;
176
- }
177
- }
178
- return true;
179
- } else {
180
- return false;
181
- }
182
- } else {
183
- return false;
184
- }
185
- }
186
-
187
- export const isItemKey = (key: any): boolean => {
188
- logger.trace('isItemKey', { key });
189
- return key !== undefined && (isComKey(key) || isPriKey(key));
190
- }
191
-
192
- export const isComKey = (key: any): boolean => {
193
- logger.trace('isComKey', { key });
194
- return key !== undefined &&
195
- (key.pk !== undefined && key.kt !== undefined) && (key.loc !== undefined && Array.isArray(key.loc));
196
- }
197
-
198
- export const isPriKey = (key: any): boolean => {
199
- logger.trace('isPriKey', { key });
200
- return key !== undefined &&
201
- (key.pk !== undefined && key.kt !== undefined) && (key.loc === undefined);
202
- }
203
-
204
- export const isLocKey = (key: any): boolean => {
205
- logger.trace('isLocKey', { key });
206
- return key !== undefined && (key.lk !== undefined && key.kt !== undefined);
207
- }
208
-
209
- export const generateKeyArray = <
210
- S extends string,
211
- L1 extends string = never,
212
- L2 extends string = never,
213
- L3 extends string = never,
214
- L4 extends string = never,
215
- L5 extends string = never,
216
- >(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S> | LocKeyArray<L1, L2, L3, L4, L5> | []):
217
- Array<PriKey<S> | LocKey<L1 | L2 | L3 | L4 | L5>> => {
218
- logger.trace('generateKeyArray', { key });
219
- const keys: Array<PriKey<S> | LocKey<L1 | L2 | L3 | L4 | L5>> = [];
220
-
221
- if (isComKey(key) || isPriKey(key)) {
222
- // console.log('it is an item key');
223
- if (isComKey(key)) {
224
- // console.log('it is a composite key');
225
- const comKey = key as ComKey<S, L1, L2, L3, L4, L5>;
226
- keys.push({ pk: comKey.pk, kt: comKey.kt });
227
- for (let i = 0; i < comKey.loc.length; i++) {
228
- keys.push(comKey.loc[i]);
229
- }
230
- } else {
231
- keys.push(key as PriKey<S>);
232
- }
233
- } else {
234
- // console.log('is is an array, length: ' + key.length);
235
- const locKeys = key as LocKey<L1 | L2 | L3 | L4 | L5>[];
236
- for (let i = 0; i < locKeys.length; i++) {
237
- // console.log('Pushing a key');
238
- keys.push(locKeys[i]);
239
- }
240
- }
241
- return keys;
242
- }
243
-
244
- // TODO: Exactly the same as in ContainedItemLib
245
- export const constructPriKey = <S extends string>(
246
- pk: string | number | PriKey<S>,
247
- kt: S,
248
- ) => {
249
- logger.trace('constructPriKey', { pk, kt });
250
- let pri: PriKey<S>;
251
- if (typeof pk === 'string' || typeof pk === 'number') {
252
- pri = { kt: kt as S, pk: pk };
253
- } else {
254
- pri = pk;
255
- }
256
- return pri;
257
- }
258
-
259
- // TODO: Exactly the same as in ContainedItemLib
260
- export const cPK = constructPriKey;
261
-
262
- export const toKeyTypeArray = <
263
- S extends string,
264
- L1 extends string = never,
265
- L2 extends string = never,
266
- L3 extends string = never,
267
- L4 extends string = never,
268
- L5 extends string = never
269
- >(ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>):
270
- string[] => {
271
- logger.trace('toKeyTypeArray', { ik });
272
- if (isComKey(ik)) {
273
- const ck = ik as ComKey<S, L1, L2, L3, L4, L5>;
274
- return [ck.kt, ...ck.loc.map((l: LocKey<L1 | L2 | L3 | L4 | L5>) => l.kt)];
275
- } else {
276
- return [(ik as PriKey<S>).kt];
277
- }
278
- }
279
-
280
- /**
281
- * Extracts key type arrays from any key type (PriKey, ComKey, or LocKeyArray)
282
- * This is useful for cache invalidation and registry lookups
283
- */
284
- export const extractKeyTypeArray = <
285
- S extends string,
286
- L1 extends string = never,
287
- L2 extends string = never,
288
- L3 extends string = never,
289
- L4 extends string = never,
290
- L5 extends string = never
291
- >(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S> | LocKeyArray<L1, L2, L3, L4, L5>):
292
- string[] => {
293
- logger.trace('extractKeyTypeArray', { key });
294
-
295
- if (isComKey(key)) {
296
- const ck = key as ComKey<S, L1, L2, L3, L4, L5>;
297
- return [ck.kt, ...ck.loc.map((l: LocKey<L1 | L2 | L3 | L4 | L5>) => l.kt)];
298
- } else if (isPriKey(key)) {
299
- return [(key as PriKey<S>).kt];
300
- } else if (Array.isArray(key)) {
301
- // This is a LocKeyArray
302
- return key.map(locKey => locKey.kt);
303
- } else {
304
- logger.warning('extractKeyTypeArray: Unknown key type', { key });
305
- return [];
306
- }
307
- }
308
-
309
- export const abbrevIK = <
310
- S extends string,
311
- L1 extends string = never,
312
- L2 extends string = never,
313
- L3 extends string = never,
314
- L4 extends string = never,
315
- L5 extends string = never
316
- >(ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): string => {
317
- logger.trace('abbrevIK', { ik });
318
- if (ik) {
319
- if (isComKey(ik)) {
320
- const ck = ik as ComKey<S, L1, L2, L3, L4, L5>;
321
- return `${ck.kt}:${ck.pk}:${ck.loc.map((l: LocKey<L1 | L2 | L3 | L4 | L5>) => `${l.kt}:${l.lk}`).join(',')}`;
322
- } else {
323
- return `${(ik as PriKey<S>).kt}:${(ik as PriKey<S>).pk}`;
324
- }
325
- } else {
326
- return 'null IK';
327
- }
328
- }
329
-
330
- export const abbrevLKA = <
331
- L1 extends string,
332
- L2 extends string = never,
333
- L3 extends string = never,
334
- L4 extends string = never,
335
- L5 extends string = never
336
- >(keyArray: Array<LocKey<L1 | L2 | L3 | L4 | L5>> | null): string => {
337
- logger.trace('abbrevLKA', { keyArray });
338
- if (keyArray === undefined || keyArray === null) {
339
- return 'null LKA';
340
- } else {
341
- return keyArray.map(key => {
342
- if (key) {
343
- return `${key.kt}:${key.lk}`;
344
- } else {
345
- return key;
346
- }
347
- }).join(',');
348
- }
349
- }
350
-
351
- export const primaryType = <
352
- S extends string,
353
- L1 extends string = never,
354
- L2 extends string = never,
355
- L3 extends string = never,
356
- L4 extends string = never,
357
- L5 extends string = never
358
- >(ik: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): string => {
359
- logger.trace('primaryType', { ik });
360
- if (isComKey(ik)) {
361
- return (ik as ComKey<S, L1, L2, L3, L4, L5>).kt;
362
- } else {
363
- return (ik as PriKey<S>).kt;
364
- }
365
- }
366
-
367
- /**
368
- *
369
- * @param ik ItemKey to be used as a basis for a location
370
- * @returns
371
- */
372
- export const itemKeyToLocKeyArray =
373
- <
374
- S extends string,
375
- L1 extends string = never,
376
- L2 extends string = never,
377
- L3 extends string = never,
378
- L4 extends string = never,
379
- L5 extends string = never
380
- >(ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>): LocKeyArray<S, L1, L2, L3, L4> => {
381
- logger.trace('itemKeyToLocKeyArray', { ik: abbrevIK(ik) });
382
- let lka: Array<LocKey<L1 | L2 | L3 | L4 | L5>> = [];
383
- if (isComKey(ik)) {
384
- const ck = ik as ComKey<S, L1, L2, L3, L4, L5>;
385
- // For composite keys, return only the parent location keys (ck.loc)
386
- // Location arrays are ordered child-to-parent per KTA hierarchy: ['child', 'parent', 'grandparent']
387
- // This is used for aggregation queries where we want to find sibling items at the same location
388
- lka = [...ck.loc];
389
- } else {
390
- const pk = ik as PriKey<S>;
391
- lka = [{ kt: pk.kt, lk: pk.pk } as unknown as LocKey<L1 | L2 | L3 | L4 | L5>];
392
- }
393
- logger.trace('itemKeyToLocKeyArray Results', { ik: abbrevIK(ik), lka: abbrevLKA(lka) });
394
- return lka as LocKeyArray<S, L1, L2, L3, L4>;
395
- }
396
-
397
- export const ikToLKA = itemKeyToLocKeyArray;
398
-
399
- /**
400
- * Sometimes you need to take a location key array and convert it to the item key that points to the containing item.
401
- * @param lka A location key array
402
- * @returns An item key corresponding to the containing item this location refers to.
403
- */
404
- export const locKeyArrayToItemKey =
405
- <
406
- L1 extends string,
407
- L2 extends string = never,
408
- L3 extends string = never,
409
- L4 extends string = never,
410
- L5 extends string = never
411
- >(lka: LocKeyArray<L1, L2, L3, L4, L5>):
412
- PriKey<L1> | ComKey<L1, L2, L3, L4, L5> => {
413
- logger.trace('locKeyArrayToItemKey', { lka: abbrevLKA(lka as Array<LocKey<L1 | L2 | L3 | L4 | L5>>) });
414
-
415
- if (lka && lka.length === 1) {
416
- const priKey = cPK(lka[0].lk, lka[0].kt);
417
- return priKey as PriKey<L1>;
418
- } else if (lka && lka.length > 1 && lka[0] !== undefined) {
419
- const locs = lka.slice(1);
420
- const priKey = cPK(lka[0].lk, lka[0].kt);
421
- const comKey = { kt: priKey.kt, pk: priKey.pk, loc: locs as unknown as LocKeyArray<L2, L3, L4, L5> };
422
- return comKey as ComKey<L1, L2, L3, L4, L5>;
423
- } else {
424
- throw new Error('locKeyArrayToItemKey: lka is undefined or empty');
425
- }
426
- }
427
-
428
- // TODO: This is annoying that we have to check for '' and 'null'
429
- export const isValidPriKey = <S extends string>(key: PriKey<S>): boolean => {
430
- const valid = (key !== undefined && key !== null)
431
- && (key.pk !== undefined && key.pk !== null && key.pk !== '' && key.pk !== 'null')
432
- && (key.kt !== undefined && key.kt !== null && key.kt !== '' && key.kt !== 'null');
433
- return valid;
434
- }
435
-
436
- // TODO: This is annoying that we have to check for '' and 'null'
437
- export const isValidLocKey = <
438
- L1 extends string,
439
- L2 extends string = never,
440
- L3 extends string = never,
441
- L4 extends string = never,
442
- L5 extends string = never
443
- >(key: LocKey<L1 | L2 | L3 | L4 | L5>): boolean => {
444
- const valid = (key !== undefined && key !== null)
445
- && (key.lk !== undefined && key.lk !== null && key.lk !== '' && key.lk !== 'null')
446
- && (key.kt !== undefined && key.kt !== null && key.kt !== '' && key.kt !== 'null');
447
- return valid;
448
- }
449
-
450
- export const isValidLocKeyArray = <
451
- L1 extends string,
452
- L2 extends string = never,
453
- L3 extends string = never,
454
- L4 extends string = never,
455
- L5 extends string = never
456
- >(keyArray: Array<LocKey<L1 | L2 | L3 | L4 | L5>>): boolean => {
457
- return (keyArray !== undefined && keyArray !== null) && keyArray.every(isValidLocKey);
458
- }
459
-
460
- export const isValidComKey = <
461
- S extends string,
462
- L1 extends string = never,
463
- L2 extends string = never,
464
- L3 extends string = never,
465
- L4 extends string = never,
466
- L5 extends string = never
467
- >(key: ComKey<S, L1, L2, L3, L4, L5>): boolean => {
468
- return (key !== undefined
469
- && key !== null) && isValidPriKey(key) && isValidLocKeyArray(key.loc as Array<LocKey<L1 | L2 | L3 | L4 | L5>>);
470
- }
471
-
472
- export const isValidItemKey = <
473
- S extends string,
474
- L1 extends string = never,
475
- L2 extends string = never,
476
- L3 extends string = never,
477
- L4 extends string = never,
478
- L5 extends string = never
479
- >(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): boolean => {
480
- return (isComKey(key) &&
481
- isValidComKey(key as ComKey<S, L1, L2, L3, L4, L5>)) || (isPriKey(key) && isValidPriKey(key as PriKey<S>));
482
- }
483
-
484
- export const lkaToIK = locKeyArrayToItemKey;
package/src/keys.ts DELETED
@@ -1,95 +0,0 @@
1
-
2
- export type UUID = `${string}-${string}-${string}-${string}-${string}`;
3
-
4
- export interface ComKey<
5
- S extends string,
6
- L1 extends string = never,
7
- L2 extends string = never,
8
- L3 extends string = never,
9
- L4 extends string = never,
10
- L5 extends string = never
11
- > {
12
- readonly kt: S,
13
- readonly pk: UUID | string | number,
14
- readonly loc: LocKeyArray<L1, L2, L3, L4, L5>
15
- };
16
-
17
- export interface PriKey<
18
- S extends string,
19
- > {
20
- readonly kt: S,
21
- readonly pk: UUID | string | number,
22
- };
23
-
24
- export interface LocKey<
25
- L extends string
26
- > {
27
- readonly kt: L,
28
- readonly lk: UUID | string | number
29
- };
30
- export type LocKeyArray<
31
- L1 extends string = never,
32
- L2 extends string = never,
33
- L3 extends string = never,
34
- L4 extends string = never,
35
- L5 extends string = never
36
- > =
37
- ([L5] extends [never] ?
38
- ([L4] extends [never] ?
39
- ([L3] extends [never] ?
40
- ([L2] extends [never] ?
41
- ([L1] extends [never] ?
42
- [] | never :
43
- [LocKey<L1>]) :
44
- [LocKey<L1>, LocKey<L2>]) :
45
- [LocKey<L1>, LocKey<L2>, LocKey<L3>]) :
46
- [LocKey<L1>, LocKey<L2>, LocKey<L3>, LocKey<L4>]) :
47
- [LocKey<L1>, LocKey<L2>, LocKey<L3>, LocKey<L4>, LocKey<L5>]);
48
-
49
- export type ItemTypeArray<
50
- S extends string,
51
- L1 extends string = never,
52
- L2 extends string = never,
53
- L3 extends string = never,
54
- L4 extends string = never,
55
- L5 extends string = never,
56
- > =
57
- ([L5] extends [never] ?
58
- ([L4] extends [never] ?
59
- ([L3] extends [never] ?
60
- ([L2] extends [never] ?
61
- ([L1] extends [never] ?
62
- [S] :
63
- [S, L1]) :
64
- [S, L1, L2]) :
65
- [S, L1, L2, L3]) :
66
- [S, L1, L2, L3, L4]) :
67
- [S, L1, L2, L3, L4, L5]);
68
-
69
- export type AllItemTypeArrays<
70
- S extends string,
71
- L1 extends string = never,
72
- L2 extends string = never,
73
- L3 extends string = never,
74
- L4 extends string = never,
75
- L5 extends string = never,
76
- > = readonly [S] |
77
- readonly [S, L1] |
78
- readonly [S, L1, L2] |
79
- readonly [S, L1, L2, L3] |
80
- readonly [S, L1, L2, L3, L4] |
81
- readonly [S, L1, L2, L3, L4, L5];
82
-
83
- export type AllLocTypeArrays<
84
- L1 extends string = never,
85
- L2 extends string = never,
86
- L3 extends string = never,
87
- L4 extends string = never,
88
- L5 extends string = never,
89
- > = readonly [] |
90
- readonly [L1] |
91
- readonly [L1, L2] |
92
- readonly [L1, L2, L3] |
93
- readonly [L1, L2, L3, L4] |
94
- readonly [L1, L2, L3, L4, L5];
95
-
package/src/logger.ts DELETED
@@ -1,5 +0,0 @@
1
- import Logging from '@fjell/logging';
2
-
3
- const LibLogger = Logging.getLogger('@fjell/core');
4
-
5
- export default LibLogger;