@fjell/core 4.4.48 → 4.4.50

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 (94) hide show
  1. package/README.md +92 -0
  2. package/dist/Coordinate.d.ts +7 -0
  3. package/dist/errors/ActionError.d.ts +51 -0
  4. package/dist/errors/BusinessLogicError.d.ts +4 -0
  5. package/dist/errors/DuplicateError.d.ts +4 -0
  6. package/dist/errors/NotFoundError.d.ts +4 -0
  7. package/dist/errors/PermissionError.d.ts +4 -0
  8. package/dist/errors/ValidationError.d.ts +4 -0
  9. package/dist/errors/index.d.ts +6 -0
  10. package/dist/event/emitter.d.ts +140 -0
  11. package/dist/event/events.d.ts +81 -0
  12. package/dist/event/index.d.ts +38 -0
  13. package/dist/event/matching.d.ts +54 -0
  14. package/dist/event/subscription.d.ts +74 -0
  15. package/dist/event/types.d.ts +186 -0
  16. package/dist/index.d.ts +13 -0
  17. package/dist/index.js +1584 -47
  18. package/dist/item/IUtils.d.ts +6 -3
  19. package/dist/operations/OperationContext.d.ts +10 -0
  20. package/dist/operations/Operations.d.ts +259 -0
  21. package/dist/operations/contained.d.ts +65 -0
  22. package/dist/operations/errorEnhancer.d.ts +79 -0
  23. package/dist/operations/index.d.ts +2 -0
  24. package/dist/operations/methods.d.ts +134 -0
  25. package/dist/operations/primary.d.ts +57 -0
  26. package/dist/operations/specialized.d.ts +41 -0
  27. package/dist/operations/wrappers/createActionWrapper.d.ts +28 -0
  28. package/dist/operations/wrappers/createAllActionWrapper.d.ts +28 -0
  29. package/dist/operations/wrappers/createAllFacetWrapper.d.ts +27 -0
  30. package/dist/operations/wrappers/createAllWrapper.d.ts +28 -0
  31. package/dist/operations/wrappers/createCreateWrapper.d.ts +28 -0
  32. package/dist/operations/wrappers/createFacetWrapper.d.ts +27 -0
  33. package/dist/operations/wrappers/createFindOneWrapper.d.ts +28 -0
  34. package/dist/operations/wrappers/createFindWrapper.d.ts +28 -0
  35. package/dist/operations/wrappers/createGetWrapper.d.ts +28 -0
  36. package/dist/operations/wrappers/createOneWrapper.d.ts +38 -0
  37. package/dist/operations/wrappers/createRemoveWrapper.d.ts +28 -0
  38. package/dist/operations/wrappers/createUpdateWrapper.d.ts +28 -0
  39. package/dist/operations/wrappers/createUpsertWrapper.d.ts +28 -0
  40. package/dist/operations/wrappers/index.d.ts +34 -0
  41. package/dist/operations/wrappers/types.d.ts +48 -0
  42. package/dist/validation/ItemValidator.d.ts +43 -0
  43. package/dist/validation/KeyValidator.d.ts +56 -0
  44. package/dist/validation/LocationValidator.d.ts +39 -0
  45. package/dist/validation/QueryValidator.d.ts +57 -0
  46. package/dist/validation/index.d.ts +15 -0
  47. package/dist/validation/index.js +501 -0
  48. package/dist/validation/types.d.ts +38 -0
  49. package/package.json +7 -2
  50. package/src/Coordinate.ts +35 -0
  51. package/src/errors/ActionError.ts +69 -0
  52. package/src/errors/BusinessLogicError.ts +24 -0
  53. package/src/errors/DuplicateError.ts +57 -0
  54. package/src/errors/NotFoundError.ts +24 -0
  55. package/src/errors/PermissionError.ts +31 -0
  56. package/src/errors/ValidationError.ts +27 -0
  57. package/src/errors/index.ts +7 -0
  58. package/src/event/emitter.ts +247 -0
  59. package/src/event/events.ts +178 -0
  60. package/src/event/index.ts +130 -0
  61. package/src/event/matching.ts +264 -0
  62. package/src/event/subscription.ts +181 -0
  63. package/src/event/types.ts +282 -0
  64. package/src/index.ts +57 -0
  65. package/src/item/IUtils.ts +9 -80
  66. package/src/operations/OperationContext.ts +12 -0
  67. package/src/operations/Operations.ts +357 -0
  68. package/src/operations/contained.ts +134 -0
  69. package/src/operations/errorEnhancer.ts +204 -0
  70. package/src/operations/index.ts +2 -0
  71. package/src/operations/methods.ts +363 -0
  72. package/src/operations/primary.ts +101 -0
  73. package/src/operations/specialized.ts +71 -0
  74. package/src/operations/wrappers/createActionWrapper.ts +108 -0
  75. package/src/operations/wrappers/createAllActionWrapper.ts +109 -0
  76. package/src/operations/wrappers/createAllFacetWrapper.ts +98 -0
  77. package/src/operations/wrappers/createAllWrapper.ts +103 -0
  78. package/src/operations/wrappers/createCreateWrapper.ts +117 -0
  79. package/src/operations/wrappers/createFacetWrapper.ts +97 -0
  80. package/src/operations/wrappers/createFindOneWrapper.ts +105 -0
  81. package/src/operations/wrappers/createFindWrapper.ts +105 -0
  82. package/src/operations/wrappers/createGetWrapper.ts +96 -0
  83. package/src/operations/wrappers/createOneWrapper.ts +128 -0
  84. package/src/operations/wrappers/createRemoveWrapper.ts +91 -0
  85. package/src/operations/wrappers/createUpdateWrapper.ts +106 -0
  86. package/src/operations/wrappers/createUpsertWrapper.ts +108 -0
  87. package/src/operations/wrappers/index.ts +39 -0
  88. package/src/operations/wrappers/types.ts +63 -0
  89. package/src/validation/ItemValidator.ts +131 -0
  90. package/src/validation/KeyValidator.ts +365 -0
  91. package/src/validation/LocationValidator.ts +136 -0
  92. package/src/validation/QueryValidator.ts +250 -0
  93. package/src/validation/index.ts +32 -0
  94. package/src/validation/types.ts +45 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for action() operation
3
+ *
4
+ * Provides automatic validation for action() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { ActionOperationMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped action() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional configuration
16
+ * @returns A fully validated action() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const action = createActionWrapper(
21
+ * coordinate,
22
+ * async (key, action, params) => {
23
+ * return await database.executeAction(key, action, params);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createActionWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: ActionOperationMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): ActionOperationMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for allAction() operation
3
+ *
4
+ * Provides automatic validation for allAction() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { AllActionOperationMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped allAction() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional configuration
16
+ * @returns A fully validated allAction() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const allAction = createAllActionWrapper(
21
+ * coordinate,
22
+ * async (action, params, locations) => {
23
+ * return await database.executeAllAction(action, params, locations);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createAllActionWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: AllActionOperationMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): AllActionOperationMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Wrapper for allFacet() operation
3
+ *
4
+ * Provides automatic validation for allFacet() operation parameters.
5
+ */
6
+ import type { Coordinate } from "../../Coordinate";
7
+ import type { AllFacetOperationMethod } from "../methods";
8
+ import type { WrapperOptions } from "./types";
9
+ /**
10
+ * Creates a wrapped allFacet() method with automatic parameter validation.
11
+ *
12
+ * @param coordinate - The coordinate defining the item hierarchy
13
+ * @param implementation - The core logic for the operation
14
+ * @param options - Optional configuration
15
+ * @returns A fully validated allFacet() method
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const allFacet = createAllFacetWrapper(
20
+ * coordinate,
21
+ * async (facet, params, locations) => {
22
+ * return await database.executeAllFacet(facet, params, locations);
23
+ * }
24
+ * );
25
+ * ```
26
+ */
27
+ export declare function createAllFacetWrapper<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: AllFacetOperationMethod<L1, L2, L3, L4, L5>, options?: WrapperOptions): AllFacetOperationMethod<L1, L2, L3, L4, L5>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for all() operation
3
+ *
4
+ * Provides automatic validation for all() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { AllMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped all() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional configuration
16
+ * @returns A fully validated all() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const all = createAllWrapper(
21
+ * coordinate,
22
+ * async (query, locations) => {
23
+ * return await database.findAll(query, locations);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createAllWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: AllMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): AllMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for create() operation
3
+ *
4
+ * Provides automatic validation for create() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { CreateMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped create() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional wrapper configuration
16
+ * @returns A fully validated create() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const create = createCreateWrapper(
21
+ * coordinate,
22
+ * async (item, options) => {
23
+ * return await database.create(item, options);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createCreateWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: CreateMethod<V, S, L1, L2, L3, L4, L5>, wrapperOptions?: WrapperOptions): CreateMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Wrapper for facet() operation
3
+ *
4
+ * Provides automatic validation for facet() operation parameters.
5
+ */
6
+ import type { Coordinate } from "../../Coordinate";
7
+ import type { FacetOperationMethod } from "../methods";
8
+ import type { WrapperOptions } from "./types";
9
+ /**
10
+ * Creates a wrapped facet() method with automatic parameter validation.
11
+ *
12
+ * @param coordinate - The coordinate defining the item hierarchy
13
+ * @param implementation - The core logic for the operation
14
+ * @param options - Optional configuration
15
+ * @returns A fully validated facet() method
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const facet = createFacetWrapper(
20
+ * coordinate,
21
+ * async (key, facet, params) => {
22
+ * return await database.executeFacet(key, facet, params);
23
+ * }
24
+ * );
25
+ * ```
26
+ */
27
+ export declare function createFacetWrapper<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: FacetOperationMethod<S, L1, L2, L3, L4, L5>, options?: WrapperOptions): FacetOperationMethod<S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for findOne() operation
3
+ *
4
+ * Provides automatic validation for findOne() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { FindOneMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped findOne() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional configuration
16
+ * @returns A fully validated findOne() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const findOne = createFindOneWrapper(
21
+ * coordinate,
22
+ * async (finder, params, locations) => {
23
+ * return await database.executeFinderOne(finder, params, locations);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createFindOneWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: FindOneMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): FindOneMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for find() operation
3
+ *
4
+ * Provides automatic validation for find() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { FindMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped find() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional configuration
16
+ * @returns A fully validated find() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const find = createFindWrapper(
21
+ * coordinate,
22
+ * async (finder, params, locations) => {
23
+ * return await database.executeFinder(finder, params, locations);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createFindWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: FindMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): FindMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for get() operation
3
+ *
4
+ * Provides automatic validation for get() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { GetMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped get() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional configuration
16
+ * @returns A fully validated get() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const get = createGetWrapper(
21
+ * coordinate,
22
+ * async (key) => {
23
+ * return await database.findByKey(key);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createGetWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: GetMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): GetMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Wrapper for one() operation
3
+ *
4
+ * Provides automatic validation for one() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { OneMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped one() method with automatic parameter validation.
12
+ *
13
+ * The wrapper handles:
14
+ * - Query validation
15
+ * - Location array validation against coordinate
16
+ * - Parameter normalization (undefined → defaults)
17
+ * - Consistent error handling
18
+ *
19
+ * @param coordinate - The coordinate defining the item hierarchy
20
+ * @param implementation - The core logic for the operation (no validation needed)
21
+ * @param options - Optional configuration
22
+ * @returns A fully validated one() method
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const one = createOneWrapper(
27
+ * coordinate,
28
+ * async (query, locations) => {
29
+ * // Just implement the logic - validation is automatic
30
+ * return await database.findOne(query, locations);
31
+ * }
32
+ * );
33
+ *
34
+ * // Usage
35
+ * const item = await one({ status: 'active' }, [{ kt: 'org', lk: '123' }]);
36
+ * ```
37
+ */
38
+ export declare function createOneWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: OneMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): OneMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for remove() operation
3
+ *
4
+ * Provides automatic validation for remove() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { RemoveMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped remove() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional configuration
16
+ * @returns A fully validated remove() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const remove = createRemoveWrapper(
21
+ * coordinate,
22
+ * async (key) => {
23
+ * return await database.delete(key);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createRemoveWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: RemoveMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): RemoveMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for update() operation
3
+ *
4
+ * Provides automatic validation for update() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { UpdateMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped update() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional configuration
16
+ * @returns A fully validated update() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const update = createUpdateWrapper(
21
+ * coordinate,
22
+ * async (key, item) => {
23
+ * return await database.update(key, item);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createUpdateWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: UpdateMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): UpdateMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Wrapper for upsert() operation
3
+ *
4
+ * Provides automatic validation for upsert() operation parameters.
5
+ */
6
+ import type { Item } from "../../items";
7
+ import type { Coordinate } from "../../Coordinate";
8
+ import type { UpsertMethod } from "../methods";
9
+ import type { WrapperOptions } from "./types";
10
+ /**
11
+ * Creates a wrapped upsert() method with automatic parameter validation.
12
+ *
13
+ * @param coordinate - The coordinate defining the item hierarchy
14
+ * @param implementation - The core logic for the operation
15
+ * @param options - Optional configuration
16
+ * @returns A fully validated upsert() method
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const upsert = createUpsertWrapper(
21
+ * coordinate,
22
+ * async (key, item, locations) => {
23
+ * return await database.upsert(key, item, locations);
24
+ * }
25
+ * );
26
+ * ```
27
+ */
28
+ export declare function createUpsertWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: UpsertMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): UpsertMethod<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Operation wrapper functions that provide automatic parameter validation.
3
+ *
4
+ * These wrappers eliminate boilerplate validation code in Operations implementations.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { createOneWrapper } from '@fjell/core';
9
+ *
10
+ * const one = createOneWrapper(
11
+ * coordinate,
12
+ * async (query, locations) => {
13
+ * // Validation happens automatically
14
+ * return await database.findOne(query, locations);
15
+ * }
16
+ * );
17
+ * ```
18
+ *
19
+ * @module wrappers
20
+ */
21
+ export type { WrapperOptions, ErrorContext, WrapperContext } from './types';
22
+ export { createOneWrapper } from './createOneWrapper';
23
+ export { createAllWrapper } from './createAllWrapper';
24
+ export { createGetWrapper } from './createGetWrapper';
25
+ export { createCreateWrapper } from './createCreateWrapper';
26
+ export { createUpdateWrapper } from './createUpdateWrapper';
27
+ export { createUpsertWrapper } from './createUpsertWrapper';
28
+ export { createRemoveWrapper } from './createRemoveWrapper';
29
+ export { createFindWrapper } from './createFindWrapper';
30
+ export { createFindOneWrapper } from './createFindOneWrapper';
31
+ export { createActionWrapper } from './createActionWrapper';
32
+ export { createAllActionWrapper } from './createAllActionWrapper';
33
+ export { createFacetWrapper } from './createFacetWrapper';
34
+ export { createAllFacetWrapper } from './createAllFacetWrapper';
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Types for operation wrappers
3
+ *
4
+ * These wrappers provide automatic parameter validation for all Operations methods.
5
+ */
6
+ import type { Coordinate } from "../../Coordinate";
7
+ /**
8
+ * Options for configuring wrapper behavior
9
+ */
10
+ export interface WrapperOptions {
11
+ /**
12
+ * Skip automatic parameter validation.
13
+ * Use this if you're handling validation elsewhere.
14
+ * @default false
15
+ */
16
+ skipValidation?: boolean;
17
+ /**
18
+ * Custom operation name for error messages.
19
+ * If not provided, uses the wrapper's default name.
20
+ */
21
+ operationName?: string;
22
+ /**
23
+ * Enable debug logging for wrapper calls.
24
+ * @default false
25
+ */
26
+ debug?: boolean;
27
+ /**
28
+ * Custom error handler.
29
+ * If provided, catches and transforms errors from the implementation.
30
+ */
31
+ onError?: (error: Error, context: ErrorContext) => Error | never;
32
+ }
33
+ /**
34
+ * Context provided to error handlers
35
+ */
36
+ export interface ErrorContext {
37
+ operationName: string;
38
+ params: any[];
39
+ coordinate: Coordinate<any, any, any, any, any, any>;
40
+ }
41
+ /**
42
+ * Internal context passed through wrapper execution
43
+ */
44
+ export interface WrapperContext<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
45
+ coordinate: Coordinate<S, L1, L2, L3, L4, L5>;
46
+ operationName: string;
47
+ options: WrapperOptions;
48
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Item validation
3
+ *
4
+ * Validates that Item objects have correct key types and structures.
5
+ */
6
+ import type { Item } from "../items";
7
+ import type { AllItemTypeArrays } from "../keys";
8
+ /**
9
+ * Validates that an item or array of items have the correct primary key type
10
+ *
11
+ * @param input - The item or array of items to validate
12
+ * @param pkType - The expected primary key type
13
+ * @returns The validated item(s)
14
+ * @throws Error if any item is invalid or has wrong key type
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // Validate single item
19
+ * const item = validatePK(fetchedItem, 'product');
20
+ *
21
+ * // Validate array of items
22
+ * const items = validatePK(fetchedItems, 'product');
23
+ * ```
24
+ */
25
+ export declare const validatePK: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(input: Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[], pkType: S) => Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[];
26
+ /**
27
+ * Validates that an item's key matches the expected key type array
28
+ *
29
+ * This is used to validate composite items where the key structure must match
30
+ * the complete hierarchy (e.g., [product, store, region])
31
+ *
32
+ * @param item - The item to validate
33
+ * @param keyTypes - The expected key type array
34
+ * @returns The validated item
35
+ * @throws Error if item is invalid or key types don't match
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * // Validate item has correct key structure
40
+ * const item = validateKeys(fetchedItem, ['product', 'store']);
41
+ * ```
42
+ */
43
+ export declare const validateKeys: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(item: Item<S, L1, L2, L3, L4, L5>, keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>) => Item<S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Key validation (PriKey, ComKey)
3
+ *
4
+ * Validates key structures and ensures keys match the expected library type.
5
+ */
6
+ import type { ComKey, PriKey } from "../keys";
7
+ import type { Coordinate } from "../Coordinate";
8
+ /**
9
+ * Validates that a key is valid and matches the expected library type.
10
+ *
11
+ * This function performs comprehensive validation:
12
+ * 1. Validates key type (PriKey vs ComKey) matches library type (primary vs composite)
13
+ * 2. For composite keys, validates location key array order matches hierarchy
14
+ * 3. Validates key structure is correct
15
+ *
16
+ * @param key - The key to validate
17
+ * @param coordinate - The coordinate defining the library's key type hierarchy
18
+ * @param operation - The operation name (for error messages)
19
+ * @throws Error if key type doesn't match library type or location key array order is incorrect
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Validate a PriKey for a primary library
24
+ * validateKey(
25
+ * { kt: 'product', pk: '123' },
26
+ * coordinate,
27
+ * 'get'
28
+ * );
29
+ *
30
+ * // Validate a ComKey for a composite library
31
+ * validateKey(
32
+ * { kt: 'product', pk: '123', loc: [{ kt: 'store', lk: '456' }] },
33
+ * coordinate,
34
+ * 'get'
35
+ * );
36
+ * ```
37
+ */
38
+ export declare const validateKey: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(key: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, operation: string) => void;
39
+ /**
40
+ * Validates a PriKey structure
41
+ *
42
+ * @param key - The primary key to validate
43
+ * @param expectedType - The expected key type
44
+ * @param operation - The operation name (for error messages)
45
+ * @throws Error if key is invalid
46
+ */
47
+ export declare const validatePriKey: <S extends string>(key: PriKey<S>, expectedType: S, operation: string) => void;
48
+ /**
49
+ * Validates a ComKey structure
50
+ *
51
+ * @param key - The composite key to validate
52
+ * @param coordinate - The coordinate defining the expected hierarchy
53
+ * @param operation - The operation name (for error messages)
54
+ * @throws Error if key is invalid
55
+ */
56
+ export declare const validateComKey: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(key: ComKey<S, L1, L2, L3, L4, L5>, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, operation: string) => void;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Location array validation
3
+ *
4
+ * Validates that LocKeyArray parameters match the expected Coordinate hierarchy.
5
+ */
6
+ import type { LocKeyArray } from "../keys";
7
+ import type { Coordinate } from "../Coordinate";
8
+ import type { ValidationResult } from "./types";
9
+ /**
10
+ * Validates that a standalone LocKeyArray parameter matches the expected hierarchy
11
+ * defined by the coordinate's key type array (kta).
12
+ *
13
+ * This is used to validate the `locations` parameter passed to operations like
14
+ * all(), find(), create(), etc.
15
+ *
16
+ * @param locations - The location key array to validate
17
+ * @param coordinate - The coordinate defining the library's key type hierarchy
18
+ * @param operation - The operation name (for error messages)
19
+ * @throws Error if location key array order is incorrect
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * validateLocations(
24
+ * [{kt: 'store', lk: '123'}],
25
+ * coordinate,
26
+ * 'find'
27
+ * );
28
+ * ```
29
+ */
30
+ export declare const validateLocations: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(locations: LocKeyArray<L1, L2, L3, L4, L5> | [] | undefined, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, operation: string) => void;
31
+ /**
32
+ * Non-throwing version of validateLocations that returns a ValidationResult
33
+ *
34
+ * @param locations - The location key array to validate
35
+ * @param coordinate - The coordinate defining the library's key type hierarchy
36
+ * @param operation - The operation name (for error messages)
37
+ * @returns ValidationResult with valid flag and optional error message
38
+ */
39
+ export declare const isValidLocations: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(locations: LocKeyArray<L1, L2, L3, L4, L5> | [] | undefined, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, operation: string) => ValidationResult;