@fjell/core 4.4.49 → 4.4.51

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 (58) hide show
  1. package/dist/event/emitter.d.ts +140 -0
  2. package/dist/event/events.d.ts +81 -0
  3. package/dist/event/index.d.ts +38 -0
  4. package/dist/event/matching.d.ts +54 -0
  5. package/dist/event/subscription.d.ts +74 -0
  6. package/dist/event/types.d.ts +186 -0
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.js +272 -0
  9. package/package.json +3 -3
  10. package/src/AItemService.ts +0 -38
  11. package/src/Coordinate.ts +0 -35
  12. package/src/dictionary.ts +0 -84
  13. package/src/errors/ActionError.ts +0 -69
  14. package/src/errors/BusinessLogicError.ts +0 -24
  15. package/src/errors/DuplicateError.ts +0 -57
  16. package/src/errors/NotFoundError.ts +0 -24
  17. package/src/errors/PermissionError.ts +0 -31
  18. package/src/errors/ValidationError.ts +0 -27
  19. package/src/errors/index.ts +0 -7
  20. package/src/index.ts +0 -66
  21. package/src/item/IFactory.ts +0 -122
  22. package/src/item/IQFactory.ts +0 -163
  23. package/src/item/IQUtils.ts +0 -392
  24. package/src/item/IUtils.ts +0 -40
  25. package/src/item/ItemQuery.ts +0 -88
  26. package/src/items.ts +0 -120
  27. package/src/key/KUtils.ts +0 -484
  28. package/src/keys.ts +0 -95
  29. package/src/logger.ts +0 -5
  30. package/src/operations/OperationContext.ts +0 -12
  31. package/src/operations/Operations.ts +0 -357
  32. package/src/operations/contained.ts +0 -134
  33. package/src/operations/errorEnhancer.ts +0 -204
  34. package/src/operations/index.ts +0 -2
  35. package/src/operations/methods.ts +0 -363
  36. package/src/operations/primary.ts +0 -101
  37. package/src/operations/specialized.ts +0 -71
  38. package/src/operations/wrappers/createActionWrapper.ts +0 -108
  39. package/src/operations/wrappers/createAllActionWrapper.ts +0 -109
  40. package/src/operations/wrappers/createAllFacetWrapper.ts +0 -98
  41. package/src/operations/wrappers/createAllWrapper.ts +0 -103
  42. package/src/operations/wrappers/createCreateWrapper.ts +0 -117
  43. package/src/operations/wrappers/createFacetWrapper.ts +0 -97
  44. package/src/operations/wrappers/createFindOneWrapper.ts +0 -105
  45. package/src/operations/wrappers/createFindWrapper.ts +0 -105
  46. package/src/operations/wrappers/createGetWrapper.ts +0 -96
  47. package/src/operations/wrappers/createOneWrapper.ts +0 -128
  48. package/src/operations/wrappers/createRemoveWrapper.ts +0 -91
  49. package/src/operations/wrappers/createUpdateWrapper.ts +0 -106
  50. package/src/operations/wrappers/createUpsertWrapper.ts +0 -108
  51. package/src/operations/wrappers/index.ts +0 -39
  52. package/src/operations/wrappers/types.ts +0 -63
  53. package/src/validation/ItemValidator.ts +0 -131
  54. package/src/validation/KeyValidator.ts +0 -365
  55. package/src/validation/LocationValidator.ts +0 -136
  56. package/src/validation/QueryValidator.ts +0 -250
  57. package/src/validation/index.ts +0 -32
  58. package/src/validation/types.ts +0 -45
@@ -1,31 +0,0 @@
1
- import { ActionError } from './ActionError';
2
-
3
- export class PermissionError extends ActionError {
4
- constructor(
5
- message: string,
6
- requiredPermission?: string,
7
- currentPermissions?: string[]
8
- ) {
9
- super({
10
- code: 'PERMISSION_DENIED',
11
- message,
12
- operation: { type: 'action', name: '', params: {} },
13
- context: {
14
- itemType: '',
15
- ...(requiredPermission && { requiredPermission })
16
- },
17
- details: {
18
- ...(requiredPermission && {
19
- suggestedAction: `Required permission: ${requiredPermission}`,
20
- expectedValue: requiredPermission
21
- }),
22
- ...(currentPermissions && { conflictingValue: currentPermissions }),
23
- retryable: false
24
- },
25
- technical: {
26
- timestamp: new Date().toISOString()
27
- }
28
- });
29
- }
30
- }
31
-
@@ -1,27 +0,0 @@
1
- import { ActionError } from './ActionError';
2
-
3
- export class ValidationError extends ActionError {
4
- constructor(
5
- message: string,
6
- validOptions?: string[],
7
- suggestedAction?: string,
8
- conflictingValue?: any
9
- ) {
10
- super({
11
- code: 'VALIDATION_ERROR',
12
- message,
13
- operation: { type: 'create', name: '', params: {} }, // Will be filled by wrapper
14
- context: { itemType: '' }, // Will be filled by wrapper
15
- details: {
16
- validOptions,
17
- suggestedAction,
18
- retryable: true,
19
- conflictingValue
20
- },
21
- technical: {
22
- timestamp: new Date().toISOString()
23
- }
24
- });
25
- }
26
- }
27
-
@@ -1,7 +0,0 @@
1
- export * from './ActionError';
2
- export * from './ValidationError';
3
- export * from './NotFoundError';
4
- export * from './BusinessLogicError';
5
- export * from './PermissionError';
6
- export * from './DuplicateError';
7
-
package/src/index.ts DELETED
@@ -1,66 +0,0 @@
1
- export * from "./dictionary";
2
- export * from "./keys";
3
- export * from "./items";
4
- export * from "./Coordinate";
5
- export { IFactory } from "./item/IFactory";
6
- export { AItemService } from "./AItemService";
7
-
8
- export * from './key/KUtils';
9
-
10
- export * from './item/IFactory';
11
- export * from './item/IQFactory';
12
- export * from './item/IQUtils';
13
- export * from './item/IUtils';
14
- export * from './item/ItemQuery';
15
-
16
- // Validation module
17
- export * from './validation';
18
-
19
- // Error types and handling
20
- export * from './errors';
21
- export * from './operations';
22
-
23
- // Operations interfaces
24
- export type {
25
- Operations,
26
- OperationParams,
27
- AffectedKeys,
28
- CreateOptions
29
- } from './operations/Operations';
30
- export {
31
- isPriKey as isOperationPriKey,
32
- isComKey as isOperationComKey
33
- } from './operations/Operations';
34
- export type {
35
- GetMethod,
36
- CreateMethod,
37
- UpdateMethod,
38
- RemoveMethod,
39
- UpsertMethod,
40
- AllMethod,
41
- OneMethod,
42
- FindMethod,
43
- FindOneMethod,
44
- FinderMethod,
45
- ActionMethod,
46
- ActionOperationMethod,
47
- AllActionMethod,
48
- AllActionOperationMethod,
49
- FacetMethod,
50
- FacetOperationMethod,
51
- AllFacetMethod,
52
- AllFacetOperationMethod,
53
- OperationsExtensions
54
- } from './operations/methods';
55
-
56
- // Operation wrappers - automatic validation for all operations
57
- export * from './operations/wrappers';
58
- // Core architectural patterns
59
- export type { PrimaryOperations } from './operations/primary';
60
- export type { ContainedOperations } from './operations/contained';
61
-
62
- // UI usage patterns (React providers, etc.)
63
- export type {
64
- CollectionOperations,
65
- InstanceOperations
66
- } from './operations/specialized';
@@ -1,122 +0,0 @@
1
- import deepmerge from 'deepmerge';
2
- import { Item } from '../items';
3
- import { primaryType } from '../key/KUtils';
4
- import { ComKey, PriKey } from '../keys';
5
-
6
- export class IFactory<
7
- V extends Item<S, L1, L2, L3, L4, L5>,
8
- S extends string,
9
- L1 extends string = never,
10
- L2 extends string = never,
11
- L3 extends string = never,
12
- L4 extends string = never,
13
- L5 extends string = never> {
14
- private item: any = {
15
- };
16
-
17
- public constructor(props: Record<string, any> = {}) {
18
- this.item = deepmerge(this.item, props);
19
- }
20
-
21
- public addRef(i: Item<any, any|never, any|never, any|never, any|never, any|never>, name?: string) {
22
- const ik: ComKey<any, any|never, any|never, any|never, any|never, any|never> | PriKey<any> = i.key;
23
-
24
- const refName = name || primaryType(ik);
25
- if (!this.item.refs) {
26
- this.item.refs = {};
27
- }
28
- this.item.refs[refName] = ik;
29
- return this;
30
- }
31
-
32
- public static addRef<
33
- V extends Item<S, L1, L2, L3, L4, L5>,
34
- S extends string,
35
- L1 extends string = never,
36
- L2 extends string = never,
37
- L3 extends string = never,
38
- L4 extends string = never,
39
- L5 extends string = never
40
- >(i: V, name?: string) {
41
- return new IFactory<V, S, L1, L2, L3, L4, L5>().addRef(i, name);
42
- }
43
-
44
- public addDefaultEvents() {
45
- if (!this.item.events) {
46
- this.item.events = {};
47
- }
48
- const now = new Date();
49
- if (!this.item.events.created) {
50
- this.item.events.created = { at: now };
51
- }
52
- if (!this.item.events.updated) {
53
- this.item.events.updated = { at: now };
54
- }
55
- if (!this.item.events.deleted) {
56
- this.item.events.deleted = { at: null };
57
- }
58
- return this;
59
- }
60
-
61
- public addEvent(
62
- name: string,
63
- at: Date | null,
64
- by?: ComKey<any, any|never, any|never, any|never, any|never, any|never> | PriKey<any>
65
- ) {
66
- if (!this.item.events) {
67
- this.item.events = {};
68
- }
69
- this.item.events[name] = { at, by };
70
- return this;
71
- }
72
-
73
- public static addEvent<
74
- V extends Item<S, L1, L2, L3, L4, L5>,
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
- >(name: string, at: Date | null, by?: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>) {
82
- return new IFactory<V, S, L1, L2, L3, L4, L5>().addEvent(name, at, by);
83
- }
84
-
85
- public addProp(name: string, value: string | number | boolean | Date) {
86
- this.item[name] = value;
87
- return this;
88
- }
89
-
90
- public static addProp<
91
- V extends Item<S, L1, L2, L3, L4, L5>,
92
- S extends string,
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
- >(name: string, value: string | number | boolean | Date) {
99
- return new IFactory<V, S, L1, L2, L3, L4, L5>().addProp(name, value);
100
- }
101
-
102
- public addProps(props: Record<string, any>) {
103
- this.item = deepmerge(this.item, props);
104
- return this;
105
- }
106
-
107
- public static addProps<
108
- V extends Item<S, L1, L2, L3, L4, L5>,
109
- S extends string,
110
- L1 extends string = never,
111
- L2 extends string = never,
112
- L3 extends string = never,
113
- L4 extends string = never,
114
- L5 extends string = never
115
- >(props: Record<string, any>) {
116
- return new IFactory<V, S, L1, L2, L3, L4, L5>().addProps(props);
117
- }
118
-
119
- toItem(): V {
120
- return this.item as V;
121
- }
122
- }
@@ -1,163 +0,0 @@
1
- import { cPK } from '../key/KUtils';
2
- import {
3
- CompoundType,
4
- Condition,
5
- ConditionOperator,
6
- EventQuery,
7
- isCondition,
8
- ItemQuery,
9
- OrderDirection
10
- } from "./ItemQuery";
11
-
12
- export class IQFactory {
13
-
14
- private query: ItemQuery = {};
15
-
16
- public constructor(query: ItemQuery = {}) {
17
- this.query = query;
18
- }
19
-
20
- public orderBy(field: string, direction: OrderDirection = 'asc') {
21
- if (!this.query.orderBy) {
22
- this.query.orderBy = [];
23
- }
24
- this.query.orderBy.push({ field, direction });
25
- return this;
26
- }
27
-
28
- public agg(name: string, query: ItemQuery) {
29
- if (!this.query.aggs) {
30
- this.query.aggs = {};
31
- }
32
- this.query.aggs[name] = query;
33
- return this;
34
- }
35
-
36
- public event(name: string, query: EventQuery) {
37
- if (!this.query.events) {
38
- this.query.events = {};
39
- }
40
- this.query.events[name] = query;
41
- return this;
42
- }
43
-
44
- public conditions(conditions: Condition[], compoundType: CompoundType = 'AND') {
45
- for (const condition of conditions) {
46
- if (!isCondition(condition)) {
47
- throw new Error(`Invalid condition: ${JSON.stringify(condition)}`);
48
- }
49
- }
50
- if (!this.query.compoundCondition) {
51
- // If there is no top-level compound condition, create one
52
- // with the given compound type. This will mostly likely be the most common case.
53
- this.query.compoundCondition = {
54
- compoundType,
55
- conditions: conditions,
56
- };
57
- } else {
58
- // If there is already a top-level compound condition, create a new compound condition
59
- // and add it to the conditions array of the top-level compound condition.
60
- const compoundCondition = {
61
- compoundType,
62
- conditions,
63
- };
64
- this.query.compoundCondition.conditions.push(compoundCondition);
65
- }
66
- return this;
67
- }
68
-
69
- public limit(limit: number) {
70
- this.query.limit = limit;
71
- return this;
72
- }
73
-
74
- public offset(offset: number) {
75
- this.query.offset = offset;
76
- return this;
77
- }
78
-
79
- // TODO: right now, we're only supporting PK refs for queries. Should add support for CKs
80
- public pk(kt: string, pk: string, name?: string) {
81
- if (!this.query.refs) {
82
- this.query.refs = {};
83
- }
84
- const refName = name || kt;
85
- this.query.refs[refName] = { key: cPK<string>(pk, kt) };
86
- return this;
87
- }
88
-
89
- public condition(
90
- column: string,
91
- value: string[] | string | number[] | number | boolean | Date | null,
92
- operator: ConditionOperator = '==',
93
- ) {
94
- const condition: Condition = { column, value, operator };
95
- if (isCondition(condition)) {
96
- if (!this.query.compoundCondition) {
97
- // If there is no top-level compound condition, create one
98
- // with the default compound type of 'AND'.
99
- this.query.compoundCondition = {
100
- compoundType: 'AND',
101
- conditions: [],
102
- };
103
- }
104
- this.query.compoundCondition.conditions.push(condition);
105
- return this;
106
- } else {
107
- throw new Error(`Invalid condition: ${JSON.stringify(condition)}`);
108
- }
109
- }
110
-
111
- public static all() {
112
- const iqFactory = new IQFactory();
113
- return iqFactory;
114
- }
115
-
116
- public static orderBy(field: string, direction: OrderDirection = 'asc') {
117
- const iqFactory = new IQFactory();
118
- return iqFactory.orderBy(field, direction);
119
- }
120
-
121
- public static agg(name: string, query: ItemQuery) {
122
- const iqFactory = new IQFactory();
123
- return iqFactory.agg(name, query);
124
- }
125
-
126
- public static event(name: string, query: EventQuery) {
127
- const iqFactory = new IQFactory();
128
- return iqFactory.event(name, query);
129
- }
130
-
131
- public static limit(limit: number) {
132
- const iqFactory = new IQFactory();
133
- return iqFactory.limit(limit);
134
- }
135
-
136
- public static offset(offset: number) {
137
- const iqFactory = new IQFactory();
138
- return iqFactory.offset(offset);
139
- }
140
-
141
- public static pk(kt: string, pk: string, name?: string) {
142
- const iqFactory = new IQFactory();
143
- return iqFactory.pk(kt, pk, name);
144
- }
145
-
146
- public static condition(
147
- column: string,
148
- value: string[] | string | number[] | number | boolean | Date | null,
149
- operator: ConditionOperator = '=='
150
- ) {
151
- const iqFactory = new IQFactory();
152
- return iqFactory.condition(column, value, operator);
153
- }
154
-
155
- public static conditions(conditions: Condition[], compoundType: CompoundType = 'AND') {
156
- const iqFactory = new IQFactory();
157
- return iqFactory.conditions(conditions, compoundType);
158
- }
159
-
160
- toQuery() {
161
- return this.query;
162
- }
163
- }