@fjell/core 4.4.48 → 4.4.49
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/README.md +92 -0
- package/dist/Coordinate.d.ts +7 -0
- package/dist/errors/ActionError.d.ts +51 -0
- package/dist/errors/BusinessLogicError.d.ts +4 -0
- package/dist/errors/DuplicateError.d.ts +4 -0
- package/dist/errors/NotFoundError.d.ts +4 -0
- package/dist/errors/PermissionError.d.ts +4 -0
- package/dist/errors/ValidationError.d.ts +4 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1312 -47
- package/dist/item/IUtils.d.ts +6 -3
- package/dist/operations/OperationContext.d.ts +10 -0
- package/dist/operations/Operations.d.ts +259 -0
- package/dist/operations/contained.d.ts +65 -0
- package/dist/operations/errorEnhancer.d.ts +79 -0
- package/dist/operations/index.d.ts +2 -0
- package/dist/operations/methods.d.ts +134 -0
- package/dist/operations/primary.d.ts +57 -0
- package/dist/operations/specialized.d.ts +41 -0
- package/dist/operations/wrappers/createActionWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createAllActionWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createAllFacetWrapper.d.ts +27 -0
- package/dist/operations/wrappers/createAllWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createCreateWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createFacetWrapper.d.ts +27 -0
- package/dist/operations/wrappers/createFindOneWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createFindWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createGetWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createOneWrapper.d.ts +38 -0
- package/dist/operations/wrappers/createRemoveWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createUpdateWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createUpsertWrapper.d.ts +28 -0
- package/dist/operations/wrappers/index.d.ts +34 -0
- package/dist/operations/wrappers/types.d.ts +48 -0
- package/dist/validation/ItemValidator.d.ts +43 -0
- package/dist/validation/KeyValidator.d.ts +56 -0
- package/dist/validation/LocationValidator.d.ts +39 -0
- package/dist/validation/QueryValidator.d.ts +57 -0
- package/dist/validation/index.d.ts +15 -0
- package/dist/validation/index.js +501 -0
- package/dist/validation/types.d.ts +38 -0
- package/package.json +7 -2
- package/src/Coordinate.ts +35 -0
- package/src/errors/ActionError.ts +69 -0
- package/src/errors/BusinessLogicError.ts +24 -0
- package/src/errors/DuplicateError.ts +57 -0
- package/src/errors/NotFoundError.ts +24 -0
- package/src/errors/PermissionError.ts +31 -0
- package/src/errors/ValidationError.ts +27 -0
- package/src/errors/index.ts +7 -0
- package/src/index.ts +53 -0
- package/src/item/IUtils.ts +9 -80
- package/src/operations/OperationContext.ts +12 -0
- package/src/operations/Operations.ts +357 -0
- package/src/operations/contained.ts +134 -0
- package/src/operations/errorEnhancer.ts +204 -0
- package/src/operations/index.ts +2 -0
- package/src/operations/methods.ts +363 -0
- package/src/operations/primary.ts +101 -0
- package/src/operations/specialized.ts +71 -0
- package/src/operations/wrappers/createActionWrapper.ts +108 -0
- package/src/operations/wrappers/createAllActionWrapper.ts +109 -0
- package/src/operations/wrappers/createAllFacetWrapper.ts +98 -0
- package/src/operations/wrappers/createAllWrapper.ts +103 -0
- package/src/operations/wrappers/createCreateWrapper.ts +117 -0
- package/src/operations/wrappers/createFacetWrapper.ts +97 -0
- package/src/operations/wrappers/createFindOneWrapper.ts +105 -0
- package/src/operations/wrappers/createFindWrapper.ts +105 -0
- package/src/operations/wrappers/createGetWrapper.ts +96 -0
- package/src/operations/wrappers/createOneWrapper.ts +128 -0
- package/src/operations/wrappers/createRemoveWrapper.ts +91 -0
- package/src/operations/wrappers/createUpdateWrapper.ts +106 -0
- package/src/operations/wrappers/createUpsertWrapper.ts +108 -0
- package/src/operations/wrappers/index.ts +39 -0
- package/src/operations/wrappers/types.ts +63 -0
- package/src/validation/ItemValidator.ts +131 -0
- package/src/validation/KeyValidator.ts +365 -0
- package/src/validation/LocationValidator.ts +136 -0
- package/src/validation/QueryValidator.ts +250 -0
- package/src/validation/index.ts +32 -0
- package/src/validation/types.ts +45 -0
package/README.md
CHANGED
|
@@ -109,6 +109,98 @@ const query = IQFactory.create('user')
|
|
|
109
109
|
const results = await IQUtils.execute(query)
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
+
### Operations Interface
|
|
113
|
+
|
|
114
|
+
@fjell/core provides the standard Operations interface used across all fjell libraries. This interface defines the contract for working with Items:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { Operations, PrimaryOperations, ContainedOperations } from '@fjell/core';
|
|
118
|
+
|
|
119
|
+
// For primary items
|
|
120
|
+
const userOps: PrimaryOperations<User, 'user'> = ...;
|
|
121
|
+
|
|
122
|
+
// For contained items
|
|
123
|
+
const commentOps: ContainedOperations<Comment, 'comment', 'post'> = ...;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
See [Operations README](src/operations/README.md) for detailed documentation.
|
|
127
|
+
|
|
128
|
+
### Validation Module
|
|
129
|
+
|
|
130
|
+
@fjell/core provides centralized validation functions for ensuring data integrity across the Fjell ecosystem:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import {
|
|
134
|
+
validateLocations,
|
|
135
|
+
validateKey,
|
|
136
|
+
validatePK,
|
|
137
|
+
validateKeys
|
|
138
|
+
} from '@fjell/core/validation';
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### Location Validation
|
|
142
|
+
|
|
143
|
+
Validates that location key arrays match the expected coordinate hierarchy:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { validateLocations } from '@fjell/core/validation';
|
|
147
|
+
|
|
148
|
+
// Validate location array order
|
|
149
|
+
validateLocations(
|
|
150
|
+
[{ kt: 'store', lk: 'store-1' }],
|
|
151
|
+
coordinate,
|
|
152
|
+
'create' // operation name for error context
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
// Non-throwing validation
|
|
156
|
+
import { isValidLocations } from '@fjell/core/validation';
|
|
157
|
+
const result = isValidLocations(
|
|
158
|
+
[{ kt: 'store', lk: 'store-1' }],
|
|
159
|
+
coordinate,
|
|
160
|
+
'create'
|
|
161
|
+
);
|
|
162
|
+
if (!result.valid) {
|
|
163
|
+
console.log(result.error); // Validation error message
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### Key Validation
|
|
168
|
+
|
|
169
|
+
Validates PriKey and ComKey structures match library type:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { validateKey, validatePriKey, validateComKey } from '@fjell/core/validation';
|
|
173
|
+
|
|
174
|
+
// Validate any key type
|
|
175
|
+
validateKey(key, coordinate, 'get');
|
|
176
|
+
|
|
177
|
+
// Validate specific key types
|
|
178
|
+
validatePriKey(priKey, coordinate, 'update');
|
|
179
|
+
validateComKey(comKey, coordinate, 'remove');
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### Item Validation
|
|
183
|
+
|
|
184
|
+
Validates Item keys match expected types:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { validatePK, validateKeys } from '@fjell/core/validation';
|
|
188
|
+
|
|
189
|
+
// Validate item has correct primary key type
|
|
190
|
+
const validatedItem = validatePK(item, 'product');
|
|
191
|
+
|
|
192
|
+
// Validate item key types match key type array
|
|
193
|
+
const validatedItem = validateKeys(item, ['product', 'store']);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Features:**
|
|
197
|
+
- **Comprehensive Error Messages**: Detailed context including operation name, expected vs actual values
|
|
198
|
+
- **Type Safety**: Full TypeScript support with proper type inference
|
|
199
|
+
- **Performance**: Optimized O(n) validation with minimal overhead
|
|
200
|
+
- **Flexible**: Both throwing and non-throwing variants available
|
|
201
|
+
|
|
202
|
+
See [Validation Examples](examples/validation-example.ts) for detailed usage patterns.
|
|
203
|
+
|
|
112
204
|
## Architecture Philosophy
|
|
113
205
|
|
|
114
206
|
Fjell Core is designed around **progressive enhancement**:
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ItemTypeArray } from "./keys";
|
|
2
|
+
export interface Coordinate<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
|
|
3
|
+
kta: ItemTypeArray<S, L1, L2, L3, L4, L5>;
|
|
4
|
+
scopes: string[];
|
|
5
|
+
toString: () => string;
|
|
6
|
+
}
|
|
7
|
+
export declare const createCoordinate: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(kta: ItemTypeArray<S, L1, L2, L3, L4, L5> | S, scopes?: string[]) => Coordinate<S, L1, L2, L3, L4, L5>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface ErrorInfo {
|
|
2
|
+
code: string;
|
|
3
|
+
message: string;
|
|
4
|
+
operation: {
|
|
5
|
+
type: 'get' | 'create' | 'update' | 'remove' | 'upsert' | 'all' | 'one' | 'find' | 'findOne' | 'action' | 'allAction' | 'facet' | 'allFacet';
|
|
6
|
+
name: string;
|
|
7
|
+
params: Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
context: {
|
|
10
|
+
itemType: string;
|
|
11
|
+
key?: {
|
|
12
|
+
primary?: string | number;
|
|
13
|
+
composite?: {
|
|
14
|
+
sk: string | number;
|
|
15
|
+
kta: string[];
|
|
16
|
+
locations?: Array<{
|
|
17
|
+
lk: string | number;
|
|
18
|
+
kt: string;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
affectedItems?: Array<{
|
|
23
|
+
id: string | number;
|
|
24
|
+
type: string;
|
|
25
|
+
displayName?: string;
|
|
26
|
+
}>;
|
|
27
|
+
parentLocation?: {
|
|
28
|
+
id: string | number;
|
|
29
|
+
type: string;
|
|
30
|
+
};
|
|
31
|
+
requiredPermission?: string;
|
|
32
|
+
};
|
|
33
|
+
details?: {
|
|
34
|
+
validOptions?: string[];
|
|
35
|
+
suggestedAction?: string;
|
|
36
|
+
retryable?: boolean;
|
|
37
|
+
conflictingValue?: any;
|
|
38
|
+
expectedValue?: any;
|
|
39
|
+
};
|
|
40
|
+
technical?: {
|
|
41
|
+
timestamp: string;
|
|
42
|
+
requestId?: string;
|
|
43
|
+
stackTrace?: string;
|
|
44
|
+
cause?: any;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export declare class ActionError extends Error {
|
|
48
|
+
readonly errorInfo: ErrorInfo;
|
|
49
|
+
constructor(errorInfo: ErrorInfo, cause?: Error);
|
|
50
|
+
toJSON(): ErrorInfo;
|
|
51
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./dictionary";
|
|
2
2
|
export * from "./keys";
|
|
3
3
|
export * from "./items";
|
|
4
|
+
export * from "./Coordinate";
|
|
4
5
|
export { IFactory } from "./item/IFactory";
|
|
5
6
|
export { AItemService } from "./AItemService";
|
|
6
7
|
export * from './key/KUtils';
|
|
@@ -9,3 +10,13 @@ export * from './item/IQFactory';
|
|
|
9
10
|
export * from './item/IQUtils';
|
|
10
11
|
export * from './item/IUtils';
|
|
11
12
|
export * from './item/ItemQuery';
|
|
13
|
+
export * from './validation';
|
|
14
|
+
export * from './errors';
|
|
15
|
+
export * from './operations';
|
|
16
|
+
export type { Operations, OperationParams, AffectedKeys, CreateOptions } from './operations/Operations';
|
|
17
|
+
export { isPriKey as isOperationPriKey, isComKey as isOperationComKey } from './operations/Operations';
|
|
18
|
+
export type { GetMethod, CreateMethod, UpdateMethod, RemoveMethod, UpsertMethod, AllMethod, OneMethod, FindMethod, FindOneMethod, FinderMethod, ActionMethod, ActionOperationMethod, AllActionMethod, AllActionOperationMethod, FacetMethod, FacetOperationMethod, AllFacetMethod, AllFacetOperationMethod, OperationsExtensions } from './operations/methods';
|
|
19
|
+
export * from './operations/wrappers';
|
|
20
|
+
export type { PrimaryOperations } from './operations/primary';
|
|
21
|
+
export type { ContainedOperations } from './operations/contained';
|
|
22
|
+
export type { CollectionOperations, InstanceOperations } from './operations/specialized';
|