@contember/bindx 0.1.0
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/dist/adapter/ContemberAdapter.d.ts +40 -0
- package/dist/adapter/ContemberAdapter.d.ts.map +1 -0
- package/dist/adapter/MockAdapter.d.ts +81 -0
- package/dist/adapter/MockAdapter.d.ts.map +1 -0
- package/dist/adapter/MockQueryEngine.d.ts +43 -0
- package/dist/adapter/MockQueryEngine.d.ts.map +1 -0
- package/dist/adapter/index.d.ts +5 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/types.d.ts +184 -0
- package/dist/adapter/types.d.ts.map +1 -0
- package/dist/brand/ComponentBrand.d.ts +25 -0
- package/dist/brand/ComponentBrand.d.ts.map +1 -0
- package/dist/contember/index.d.ts +10 -0
- package/dist/contember/index.d.ts.map +1 -0
- package/dist/core/ActionDispatcher.d.ts +64 -0
- package/dist/core/ActionDispatcher.d.ts.map +1 -0
- package/dist/core/Disposable.d.ts +57 -0
- package/dist/core/Disposable.d.ts.map +1 -0
- package/dist/core/EntityLoader.d.ts +80 -0
- package/dist/core/EntityLoader.d.ts.map +1 -0
- package/dist/core/PersistenceManager.d.ts +126 -0
- package/dist/core/PersistenceManager.d.ts.map +1 -0
- package/dist/core/SelectionResolver.d.ts +21 -0
- package/dist/core/SelectionResolver.d.ts.map +1 -0
- package/dist/core/actionClassification.d.ts +48 -0
- package/dist/core/actionClassification.d.ts.map +1 -0
- package/dist/core/actions.d.ts +301 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/dataview/filterHandlers.d.ts +18 -0
- package/dist/dataview/filterHandlers.d.ts.map +1 -0
- package/dist/dataview/index.d.ts +3 -0
- package/dist/dataview/index.d.ts.map +1 -0
- package/dist/dataview/types.d.ts +164 -0
- package/dist/dataview/types.d.ts.map +1 -0
- package/dist/errors/UnfetchedFieldError.d.ts +11 -0
- package/dist/errors/UnfetchedFieldError.d.ts.map +1 -0
- package/dist/errors/errorPathResolver.d.ts +52 -0
- package/dist/errors/errorPathResolver.d.ts.map +1 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/pathMapper.d.ts +42 -0
- package/dist/errors/pathMapper.d.ts.map +1 -0
- package/dist/errors/types.d.ts +131 -0
- package/dist/errors/types.d.ts.map +1 -0
- package/dist/events/EventEmitter.d.ts +97 -0
- package/dist/events/EventEmitter.d.ts.map +1 -0
- package/dist/events/eventFactory.d.ts +40 -0
- package/dist/events/eventFactory.d.ts.map +1 -0
- package/dist/events/index.d.ts +15 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/types.d.ts +264 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/handles/BaseHandle.d.ts +64 -0
- package/dist/handles/BaseHandle.d.ts.map +1 -0
- package/dist/handles/EntityHandle.d.ts +208 -0
- package/dist/handles/EntityHandle.d.ts.map +1 -0
- package/dist/handles/FieldHandle.d.ts +111 -0
- package/dist/handles/FieldHandle.d.ts.map +1 -0
- package/dist/handles/HasManyListHandle.d.ts +166 -0
- package/dist/handles/HasManyListHandle.d.ts.map +1 -0
- package/dist/handles/HasOneHandle.d.ts +168 -0
- package/dist/handles/HasOneHandle.d.ts.map +1 -0
- package/dist/handles/PlaceholderHandle.d.ts +117 -0
- package/dist/handles/PlaceholderHandle.d.ts.map +1 -0
- package/dist/handles/index.d.ts +8 -0
- package/dist/handles/index.d.ts.map +1 -0
- package/dist/handles/proxyFactory.d.ts +66 -0
- package/dist/handles/proxyFactory.d.ts.map +1 -0
- package/dist/handles/types.d.ts +430 -0
- package/dist/handles/types.d.ts.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/internal.d.ts +11 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/persistence/BatchPersister.d.ts +142 -0
- package/dist/persistence/BatchPersister.d.ts.map +1 -0
- package/dist/persistence/ChangeRegistry.d.ts +87 -0
- package/dist/persistence/ChangeRegistry.d.ts.map +1 -0
- package/dist/persistence/ContemberSchemaMutationAdapter.d.ts +16 -0
- package/dist/persistence/ContemberSchemaMutationAdapter.d.ts.map +1 -0
- package/dist/persistence/MutationCollector.d.ts +96 -0
- package/dist/persistence/MutationCollector.d.ts.map +1 -0
- package/dist/persistence/MutationSchemaProvider.d.ts +30 -0
- package/dist/persistence/MutationSchemaProvider.d.ts.map +1 -0
- package/dist/persistence/index.d.ts +7 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/types.d.ts +189 -0
- package/dist/persistence/types.d.ts.map +1 -0
- package/dist/roles/RoleSchemaRegistry.d.ts +77 -0
- package/dist/roles/RoleSchemaRegistry.d.ts.map +1 -0
- package/dist/roles/index.d.ts +11 -0
- package/dist/roles/index.d.ts.map +1 -0
- package/dist/roles/types.d.ts +242 -0
- package/dist/roles/types.d.ts.map +1 -0
- package/dist/schema/ContemberSchema.d.ts +98 -0
- package/dist/schema/ContemberSchema.d.ts.map +1 -0
- package/dist/schema/SchemaLoader.d.ts +28 -0
- package/dist/schema/SchemaLoader.d.ts.map +1 -0
- package/dist/schema/SchemaRegistry.d.ts +95 -0
- package/dist/schema/SchemaRegistry.d.ts.map +1 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/roles.d.ts +62 -0
- package/dist/schema/roles.d.ts.map +1 -0
- package/dist/schema/types.d.ts +179 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/selection/SelectionMetaCollector.d.ts +32 -0
- package/dist/selection/SelectionMetaCollector.d.ts.map +1 -0
- package/dist/selection/SelectionScope.d.ts +77 -0
- package/dist/selection/SelectionScope.d.ts.map +1 -0
- package/dist/selection/buildQuery.d.ts +45 -0
- package/dist/selection/buildQuery.d.ts.map +1 -0
- package/dist/selection/createFragment.d.ts +29 -0
- package/dist/selection/createFragment.d.ts.map +1 -0
- package/dist/selection/createSelectionBuilder.d.ts +18 -0
- package/dist/selection/createSelectionBuilder.d.ts.map +1 -0
- package/dist/selection/index.d.ts +8 -0
- package/dist/selection/index.d.ts.map +1 -0
- package/dist/selection/queryTypes.d.ts +84 -0
- package/dist/selection/queryTypes.d.ts.map +1 -0
- package/dist/selection/types.d.ts +238 -0
- package/dist/selection/types.d.ts.map +1 -0
- package/dist/store/DirtyTracker.d.ts +26 -0
- package/dist/store/DirtyTracker.d.ts.map +1 -0
- package/dist/store/EntityMetaStore.d.ts +52 -0
- package/dist/store/EntityMetaStore.d.ts.map +1 -0
- package/dist/store/EntitySnapshotStore.d.ts +63 -0
- package/dist/store/EntitySnapshotStore.d.ts.map +1 -0
- package/dist/store/ErrorStore.d.ts +82 -0
- package/dist/store/ErrorStore.d.ts.map +1 -0
- package/dist/store/RelationStore.d.ts +175 -0
- package/dist/store/RelationStore.d.ts.map +1 -0
- package/dist/store/SnapshotStore.d.ts +143 -0
- package/dist/store/SnapshotStore.d.ts.map +1 -0
- package/dist/store/SubscriptionManager.d.ts +90 -0
- package/dist/store/SubscriptionManager.d.ts.map +1 -0
- package/dist/store/TouchedStore.d.ts +24 -0
- package/dist/store/TouchedStore.d.ts.map +1 -0
- package/dist/store/entityId.d.ts +29 -0
- package/dist/store/entityId.d.ts.map +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/snapshots.d.ts +144 -0
- package/dist/store/snapshots.d.ts.map +1 -0
- package/dist/undo/UndoManager.d.ts +120 -0
- package/dist/undo/UndoManager.d.ts.map +1 -0
- package/dist/undo/index.d.ts +3 -0
- package/dist/undo/index.d.ts.map +1 -0
- package/dist/undo/types.d.ts +74 -0
- package/dist/undo/types.d.ts.map +1 -0
- package/dist/utils/aliasGenerator.d.ts +25 -0
- package/dist/utils/aliasGenerator.d.ts.map +1 -0
- package/dist/utils/deepEqual.d.ts +6 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +29 -0
- package/src/adapter/ContemberAdapter.ts +239 -0
- package/src/adapter/MockAdapter.ts +394 -0
- package/src/adapter/MockQueryEngine.ts +236 -0
- package/src/adapter/index.ts +21 -0
- package/src/adapter/types.ts +199 -0
- package/src/brand/ComponentBrand.ts +28 -0
- package/src/contember/index.ts +17 -0
- package/src/core/ActionDispatcher.ts +450 -0
- package/src/core/Disposable.ts +126 -0
- package/src/core/EntityLoader.ts +169 -0
- package/src/core/SelectionResolver.ts +78 -0
- package/src/core/actionClassification.ts +196 -0
- package/src/core/actions.ts +491 -0
- package/src/core/index.ts +20 -0
- package/src/dataview/filterHandlers.ts +443 -0
- package/src/dataview/index.ts +36 -0
- package/src/dataview/types.ts +220 -0
- package/src/errors/UnfetchedFieldError.ts +18 -0
- package/src/errors/errorPathResolver.ts +239 -0
- package/src/errors/index.ts +40 -0
- package/src/errors/pathMapper.ts +40 -0
- package/src/errors/types.ts +223 -0
- package/src/events/EventEmitter.ts +447 -0
- package/src/events/eventFactory.ts +430 -0
- package/src/events/index.ts +89 -0
- package/src/events/types.ts +374 -0
- package/src/handles/BaseHandle.ts +100 -0
- package/src/handles/EntityHandle.ts +538 -0
- package/src/handles/FieldHandle.ts +268 -0
- package/src/handles/HasManyListHandle.ts +500 -0
- package/src/handles/HasOneHandle.ts +500 -0
- package/src/handles/PlaceholderHandle.ts +321 -0
- package/src/handles/index.ts +37 -0
- package/src/handles/proxyFactory.ts +218 -0
- package/src/handles/types.ts +743 -0
- package/src/index.ts +384 -0
- package/src/internal.ts +19 -0
- package/src/persistence/BatchPersister.ts +911 -0
- package/src/persistence/ChangeRegistry.ts +150 -0
- package/src/persistence/ContemberSchemaMutationAdapter.ts +57 -0
- package/src/persistence/MutationCollector.ts +567 -0
- package/src/persistence/MutationSchemaProvider.ts +33 -0
- package/src/persistence/index.ts +23 -0
- package/src/persistence/types.ts +220 -0
- package/src/schema/ContemberSchema.ts +132 -0
- package/src/schema/SchemaLoader.ts +93 -0
- package/src/schema/SchemaRegistry.ts +286 -0
- package/src/schema/index.ts +51 -0
- package/src/schema/roles.ts +83 -0
- package/src/schema/types.ts +238 -0
- package/src/selection/SelectionMetaCollector.ts +122 -0
- package/src/selection/SelectionScope.ts +208 -0
- package/src/selection/buildQuery.ts +134 -0
- package/src/selection/createFragment.ts +50 -0
- package/src/selection/createSelectionBuilder.ts +283 -0
- package/src/selection/index.ts +31 -0
- package/src/selection/queryTypes.ts +135 -0
- package/src/selection/types.ts +320 -0
- package/src/store/DirtyTracker.ts +117 -0
- package/src/store/EntityMetaStore.ts +143 -0
- package/src/store/EntitySnapshotStore.ts +260 -0
- package/src/store/ErrorStore.ts +251 -0
- package/src/store/RelationStore.ts +696 -0
- package/src/store/SnapshotStore.ts +765 -0
- package/src/store/SubscriptionManager.ts +241 -0
- package/src/store/TouchedStore.ts +42 -0
- package/src/store/entityId.ts +43 -0
- package/src/store/index.ts +2 -0
- package/src/store/snapshots.ts +203 -0
- package/src/undo/UndoManager.ts +418 -0
- package/src/undo/index.ts +9 -0
- package/src/undo/types.ts +84 -0
- package/src/utils/aliasGenerator.ts +56 -0
- package/src/utils/deepEqual.ts +33 -0
- package/src/utils/index.ts +2 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { BackendAdapter } from '../adapter/types.js';
|
|
2
|
+
import type { ActionDispatcher } from '../core/ActionDispatcher.js';
|
|
3
|
+
import type { MutationDataCollector } from './types.js';
|
|
4
|
+
import type { SchemaRegistry } from '../schema/SchemaRegistry.js';
|
|
5
|
+
import type { SnapshotStore } from '../store/SnapshotStore.js';
|
|
6
|
+
import type { UndoManager } from '../undo/UndoManager.js';
|
|
7
|
+
import { ChangeRegistry } from './ChangeRegistry.js';
|
|
8
|
+
import type { BatchPersistOptions, EntityPersistResult, PersistenceResult, PersistScope, UpdateMode } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Options for BatchPersister
|
|
11
|
+
*/
|
|
12
|
+
export interface BatchPersisterOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Custom mutation collector for building complex mutation inputs.
|
|
15
|
+
*/
|
|
16
|
+
mutationCollector?: MutationDataCollector;
|
|
17
|
+
/**
|
|
18
|
+
* UndoManager instance to block during persist operations.
|
|
19
|
+
*/
|
|
20
|
+
undoManager?: UndoManager;
|
|
21
|
+
/**
|
|
22
|
+
* Schema registry for mapping server errors to fields.
|
|
23
|
+
*/
|
|
24
|
+
schema?: SchemaRegistry;
|
|
25
|
+
/**
|
|
26
|
+
* Default update mode for all persist operations.
|
|
27
|
+
* Can be overridden per-operation via BatchPersistOptions.
|
|
28
|
+
* @default 'optimistic'
|
|
29
|
+
*/
|
|
30
|
+
defaultUpdateMode?: UpdateMode;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* BatchPersister orchestrates multi-entity persistence with:
|
|
34
|
+
* - Deduplication (same entity referenced multiple times → single mutation)
|
|
35
|
+
* - Dependency ordering (new entities before entities referencing them)
|
|
36
|
+
* - Transactional execution (all-or-nothing via adapter.persistTransaction)
|
|
37
|
+
* - Field-level granularity (persist only specific fields)
|
|
38
|
+
*/
|
|
39
|
+
export declare class BatchPersister {
|
|
40
|
+
private readonly adapter;
|
|
41
|
+
private readonly store;
|
|
42
|
+
private readonly dispatcher;
|
|
43
|
+
private readonly changeRegistry;
|
|
44
|
+
private readonly mutationCollector?;
|
|
45
|
+
private readonly undoManager?;
|
|
46
|
+
private readonly schema?;
|
|
47
|
+
private readonly defaultUpdateMode;
|
|
48
|
+
constructor(adapter: BackendAdapter, store: SnapshotStore, dispatcher: ActionDispatcher, options?: BatchPersisterOptions);
|
|
49
|
+
/**
|
|
50
|
+
* Gets the default update mode for this persister.
|
|
51
|
+
*/
|
|
52
|
+
getDefaultUpdateMode(): UpdateMode;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the change registry for external access.
|
|
55
|
+
*/
|
|
56
|
+
getChangeRegistry(): ChangeRegistry;
|
|
57
|
+
/**
|
|
58
|
+
* Persists all dirty entities in a single transaction.
|
|
59
|
+
*/
|
|
60
|
+
persistAll(options?: BatchPersistOptions): Promise<PersistenceResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Persists a single entity.
|
|
63
|
+
*/
|
|
64
|
+
persist(entityType: string, entityId: string, options?: BatchPersistOptions): Promise<EntityPersistResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Persists specific fields of an entity.
|
|
67
|
+
*/
|
|
68
|
+
persistFields(entityType: string, entityId: string, fields: readonly string[], options?: BatchPersistOptions): Promise<EntityPersistResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Persists entities matching the given scope.
|
|
71
|
+
*/
|
|
72
|
+
persistScope(scope: PersistScope, options?: BatchPersistOptions): Promise<PersistenceResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Collects entities to persist based on the scope.
|
|
75
|
+
*/
|
|
76
|
+
private collectEntitiesForScope;
|
|
77
|
+
/**
|
|
78
|
+
* Sorts entities by dependencies (creates before updates that reference them).
|
|
79
|
+
*/
|
|
80
|
+
private sortByDependencies;
|
|
81
|
+
/**
|
|
82
|
+
* Builds mutations for the given entities.
|
|
83
|
+
*/
|
|
84
|
+
private buildMutations;
|
|
85
|
+
/**
|
|
86
|
+
* Collects create data, throwing if dirty relations exist without a MutationCollector.
|
|
87
|
+
*/
|
|
88
|
+
private collectCreateDataWithRelationCheck;
|
|
89
|
+
/**
|
|
90
|
+
* Collects update data, throwing if dirty relations exist without a MutationCollector.
|
|
91
|
+
*/
|
|
92
|
+
private collectUpdateDataWithRelationCheck;
|
|
93
|
+
/**
|
|
94
|
+
* Throws if the entity has dirty relations but no MutationCollector is configured.
|
|
95
|
+
*/
|
|
96
|
+
private assertNoRelationChanges;
|
|
97
|
+
/**
|
|
98
|
+
* Collects data for specific fields only.
|
|
99
|
+
*/
|
|
100
|
+
private collectFieldsData;
|
|
101
|
+
/**
|
|
102
|
+
* Simple update data collection (field diff).
|
|
103
|
+
*/
|
|
104
|
+
private collectUpdateData;
|
|
105
|
+
/**
|
|
106
|
+
* Simple create data collection.
|
|
107
|
+
*/
|
|
108
|
+
private collectCreateData;
|
|
109
|
+
/**
|
|
110
|
+
* Executes mutations as a transaction.
|
|
111
|
+
*/
|
|
112
|
+
private executeTransaction;
|
|
113
|
+
/**
|
|
114
|
+
* Processes transaction result and commits/rolls back as needed.
|
|
115
|
+
* For pessimistic mode, restores captured state on success.
|
|
116
|
+
*/
|
|
117
|
+
private processTransactionResult;
|
|
118
|
+
/**
|
|
119
|
+
* Captures the current state of entities for pessimistic mode.
|
|
120
|
+
* This allows us to restore the dirty state after a successful persist.
|
|
121
|
+
*/
|
|
122
|
+
private captureEntityStates;
|
|
123
|
+
/**
|
|
124
|
+
* Restores a captured entity state and commits it.
|
|
125
|
+
* Used in pessimistic mode after successful server confirmation.
|
|
126
|
+
*/
|
|
127
|
+
private restoreAndCommitEntityState;
|
|
128
|
+
/**
|
|
129
|
+
* Rolls back an entity's optimistic changes to server state.
|
|
130
|
+
* Handles all mutation types: create, update, and delete.
|
|
131
|
+
*/
|
|
132
|
+
private rollbackEntity;
|
|
133
|
+
/**
|
|
134
|
+
* Maps server errors to entity fields/relations.
|
|
135
|
+
*/
|
|
136
|
+
private mapServerErrors;
|
|
137
|
+
/**
|
|
138
|
+
* Cancels all in-flight operations.
|
|
139
|
+
*/
|
|
140
|
+
cancelAll(): void;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=BatchPersister.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BatchPersister.d.ts","sourceRoot":"","sources":["../../src/persistence/BatchPersister.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAA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AAC;IAI3E;;OAEG;IACG,OAAO,CACZ,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;IAc/B;;OAEG;IACG,aAAa,CAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;IAc/B;;OAEG;IACG,YAAY,CACjB,KAAK,EAAE,YAAY,EACnB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,iBAAiB,CAAC;IA0G7B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IA6F/B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAQ1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAkDtB;;OAEG;IACH,OAAO,CAAC,kCAAkC;IAK1C;;OAEG;IACH,OAAO,CAAC,kCAAkC;IAK1C;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAU/B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAoBzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAqBzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAsBzB;;OAEG;YACW,kBAAkB;IAiGhC;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAoHhC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAgB3B;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IAyCnC;;;OAGG;IACH,OAAO,CAAC,cAAc;IAsBtB;;OAEG;IACH,OAAO,CAAC,eAAe;IA4DvB;;OAEG;IACH,SAAS,IAAI,IAAI;CAGjB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { SnapshotStore } from '../store/SnapshotStore.js';
|
|
2
|
+
/**
|
|
3
|
+
* Information about a dirty entity
|
|
4
|
+
*/
|
|
5
|
+
export interface DirtyEntity {
|
|
6
|
+
readonly entityType: string;
|
|
7
|
+
readonly entityId: string;
|
|
8
|
+
readonly changeType: 'create' | 'update' | 'delete';
|
|
9
|
+
readonly dirtyFields: readonly string[];
|
|
10
|
+
readonly dirtyRelations: readonly string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* ChangeRegistry tracks all dirty entities and in-flight persistence operations.
|
|
14
|
+
* It wraps SnapshotStore's dirty tracking methods and adds deduplication and
|
|
15
|
+
* in-flight tracking for batch persistence operations.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ChangeRegistry {
|
|
18
|
+
private readonly store;
|
|
19
|
+
/** Set of entity keys currently being persisted (for batch operations) */
|
|
20
|
+
private readonly inFlight;
|
|
21
|
+
/** Subscribers to in-flight state changes */
|
|
22
|
+
private readonly subscribers;
|
|
23
|
+
constructor(store: SnapshotStore);
|
|
24
|
+
/**
|
|
25
|
+
* Gets the entity key for internal tracking.
|
|
26
|
+
*/
|
|
27
|
+
private getKey;
|
|
28
|
+
/**
|
|
29
|
+
* Gets all dirty entities with their change types and dirty fields/relations.
|
|
30
|
+
*/
|
|
31
|
+
getDirtyEntities(): readonly DirtyEntity[];
|
|
32
|
+
/**
|
|
33
|
+
* Gets dirty entities that are not currently in-flight.
|
|
34
|
+
*/
|
|
35
|
+
getDirtyEntitiesNotInFlight(): readonly DirtyEntity[];
|
|
36
|
+
/**
|
|
37
|
+
* Gets dirty fields for a specific entity.
|
|
38
|
+
*/
|
|
39
|
+
getDirtyFields(entityType: string, entityId: string): readonly string[];
|
|
40
|
+
/**
|
|
41
|
+
* Gets dirty relations for a specific entity.
|
|
42
|
+
*/
|
|
43
|
+
getDirtyRelations(entityType: string, entityId: string): readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* Checks if an entity is currently being persisted (in a batch operation).
|
|
46
|
+
*/
|
|
47
|
+
isInFlight(entityType: string, entityId: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Marks entities as in-flight (being persisted).
|
|
50
|
+
*/
|
|
51
|
+
markInFlight(entities: ReadonlyArray<{
|
|
52
|
+
entityType: string;
|
|
53
|
+
entityId: string;
|
|
54
|
+
}>): void;
|
|
55
|
+
/**
|
|
56
|
+
* Clears in-flight status for entities.
|
|
57
|
+
*/
|
|
58
|
+
clearInFlight(entities: ReadonlyArray<{
|
|
59
|
+
entityType: string;
|
|
60
|
+
entityId: string;
|
|
61
|
+
}>): void;
|
|
62
|
+
/**
|
|
63
|
+
* Clears all in-flight status.
|
|
64
|
+
*/
|
|
65
|
+
clearAllInFlight(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Gets the set of all in-flight entity keys.
|
|
68
|
+
*/
|
|
69
|
+
getInFlightEntities(): ReadonlySet<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Checks if any entity is currently in-flight.
|
|
72
|
+
*/
|
|
73
|
+
hasInFlight(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Checks if there are any dirty entities.
|
|
76
|
+
*/
|
|
77
|
+
hasDirtyEntities(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Subscribe to in-flight state changes.
|
|
80
|
+
*/
|
|
81
|
+
subscribe(callback: () => void): () => void;
|
|
82
|
+
/**
|
|
83
|
+
* Notifies all subscribers of in-flight state changes.
|
|
84
|
+
*/
|
|
85
|
+
private notifySubscribers;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=ChangeRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChangeRegistry.d.ts","sourceRoot":"","sources":["../../src/persistence/ChangeRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAE9D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,UAAU,EAAE,QAAQ,GAAG,QAA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AI,OAAO;IAI3B;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAO3C;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAKzB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SchemaNames } from '@contember/client-content';
|
|
2
|
+
import type { MutationSchemaProvider } from './MutationSchemaProvider.js';
|
|
3
|
+
/**
|
|
4
|
+
* Adapter that wraps Contember SchemaNames to implement MutationSchemaProvider.
|
|
5
|
+
* Translates Contember's schema format (column/one/many) to the unified format (scalar/hasOne/hasMany).
|
|
6
|
+
*/
|
|
7
|
+
export declare class ContemberSchemaMutationAdapter implements MutationSchemaProvider {
|
|
8
|
+
private readonly schema;
|
|
9
|
+
constructor(schema: SchemaNames);
|
|
10
|
+
getScalarFields(entityType: string): readonly string[];
|
|
11
|
+
getRelationFields(entityType: string): readonly string[];
|
|
12
|
+
getRelationType(entityType: string, fieldName: string): 'hasOne' | 'hasMany' | undefined;
|
|
13
|
+
getRelationTarget(entityType: string, fieldName: string): string | undefined;
|
|
14
|
+
hasEntity(entityType: string): boolean;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ContemberSchemaMutationAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContemberSchemaMutationAdapter.d.ts","sourceRoot":"","sources":["../../src/persistence/ContemberSchemaMutationAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAEzE;;;GAGG;AACH,qBAAa,8BAA+B,YAAW,sBAAsB;IAChE,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,WAAW;IAEhD,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE;IAStD,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE;IASxD,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS;IAYxF,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAa5E,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;CAGtC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type SnapshotStore } from '../store/SnapshotStore.js';
|
|
2
|
+
import type { MutationSchemaProvider } from './MutationSchemaProvider.js';
|
|
3
|
+
import type { MutationDataCollector } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Result of collecting mutations for an entity
|
|
6
|
+
*/
|
|
7
|
+
export interface EntityMutationResult {
|
|
8
|
+
/** Type of mutation: create, update, or delete */
|
|
9
|
+
type: 'create' | 'update' | 'delete';
|
|
10
|
+
/** Entity type name */
|
|
11
|
+
entityType: string;
|
|
12
|
+
/** Entity ID (may be temp ID for creates) */
|
|
13
|
+
entityId: string;
|
|
14
|
+
/** The mutation data (for create/update) */
|
|
15
|
+
data?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* MutationCollector builds Contember-compatible mutation input
|
|
19
|
+
* by collecting changes from SnapshotStore including:
|
|
20
|
+
* - Scalar field changes
|
|
21
|
+
* - Has-one relation operations (connect, disconnect, delete, create, update)
|
|
22
|
+
* - Has-many relation operations (connect, disconnect, delete, create, update)
|
|
23
|
+
* - Entity creates and deletes
|
|
24
|
+
*
|
|
25
|
+
* This is a unified implementation that works with any schema provider
|
|
26
|
+
* implementing MutationSchemaProvider interface (SchemaRegistry, Contember SchemaNames via adapter).
|
|
27
|
+
*/
|
|
28
|
+
export declare class MutationCollector implements MutationDataCollector {
|
|
29
|
+
private readonly store;
|
|
30
|
+
private readonly schemaProvider;
|
|
31
|
+
private excludedEntityIds;
|
|
32
|
+
constructor(store: SnapshotStore, schemaProvider: MutationSchemaProvider);
|
|
33
|
+
/**
|
|
34
|
+
* Sets entity IDs that should be excluded from nested mutation generation.
|
|
35
|
+
* These entities get their own top-level mutations, so nested updates are skipped
|
|
36
|
+
* to avoid duplicate changes.
|
|
37
|
+
*/
|
|
38
|
+
setExcludedEntities(ids: ReadonlySet<string>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Collects all changes for an entity into appropriate mutation format.
|
|
41
|
+
* Returns the mutation result or null if no changes/entity doesn't exist.
|
|
42
|
+
*/
|
|
43
|
+
collectMutation(entityType: string, entityId: string): EntityMutationResult | null;
|
|
44
|
+
/**
|
|
45
|
+
* Collects all changes for an entity into Contember UpdateDataInput format.
|
|
46
|
+
* Returns the mutation data or null if no changes.
|
|
47
|
+
*/
|
|
48
|
+
collectUpdateData(entityType: string, entityId: string): Record<string, unknown> | null;
|
|
49
|
+
/**
|
|
50
|
+
* Collects data for creating a new entity.
|
|
51
|
+
* Returns the create data or null if empty.
|
|
52
|
+
*/
|
|
53
|
+
collectCreateData(entityType: string, entityId: string): Record<string, unknown> | null;
|
|
54
|
+
/**
|
|
55
|
+
* Collects mutation data for specific fields only.
|
|
56
|
+
* Returns the mutation data containing only the specified fields.
|
|
57
|
+
*/
|
|
58
|
+
collectFieldsData(entityType: string, entityId: string, fieldNames: readonly string[]): Record<string, unknown> | null;
|
|
59
|
+
/**
|
|
60
|
+
* Collects scalar field changes by comparing data to serverData.
|
|
61
|
+
*/
|
|
62
|
+
private collectScalarChanges;
|
|
63
|
+
/**
|
|
64
|
+
* Collects has-one and has-many relation changes.
|
|
65
|
+
*/
|
|
66
|
+
private collectRelationChanges;
|
|
67
|
+
/**
|
|
68
|
+
* Collects has-one relation operation.
|
|
69
|
+
* Returns the operation object or null if no change.
|
|
70
|
+
*/
|
|
71
|
+
private collectHasOneOperation;
|
|
72
|
+
/**
|
|
73
|
+
* Collects has-one relation for create mutation.
|
|
74
|
+
*/
|
|
75
|
+
private collectCreateOneRelation;
|
|
76
|
+
/**
|
|
77
|
+
* Collects has-many relation operations.
|
|
78
|
+
* Uses StoredHasManyState as the single source of truth for all operations.
|
|
79
|
+
* Returns array of operations or null if no changes.
|
|
80
|
+
*/
|
|
81
|
+
private collectHasManyOperations;
|
|
82
|
+
/**
|
|
83
|
+
* Collects has-many relations for create mutation.
|
|
84
|
+
*/
|
|
85
|
+
private collectCreateManyRelation;
|
|
86
|
+
/**
|
|
87
|
+
* Processes nested data to handle relation objects.
|
|
88
|
+
* Converts nested objects with 'id' to connect operations.
|
|
89
|
+
*/
|
|
90
|
+
private processNestedData;
|
|
91
|
+
/**
|
|
92
|
+
* Checks if an entity ID represents an existing entity (persisted, not temp or placeholder).
|
|
93
|
+
*/
|
|
94
|
+
private isExistingEntity;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=MutationCollector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutationCollector.d.ts","sourceRoot":"","sources":["../../src/persistence/MutationCollector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAA2B,MAAM,2BAA2B,CAAA;AAEvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAGvD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,kDAAkD;IAClD,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;IACpC,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAA;IAChB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,iBAAkB,YAAW,qBAAqB;IAI7D,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAJhC,OAAO,CAAC,iBAAiB,CAAiC;gBAGxC,KAAK,EAAE,aAAa,EACpB,cAAc,EAAE,sBAAsB;IAGxD;;;;OAIG;IACH,mBAAmB,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI;IAMnD;;;OAGG;IACH,eAAe,CACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACd,oBAAoB,GAAG,IAAI;IAkD9B;;;OAGG;IACH,iBAAiB,CAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAqBjC;;;OAGG;IACH,iBAAiB,CAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACd,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IA8CjC;;;OAGG;IACH,iBAAiB,CAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,SAAS,MAAM,EAAE,GAC3B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IA6CjC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAqB5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAwB9B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA+D9B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IA8BhC;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IA6EhC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA+BjC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAgDzB;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAGxB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for schema providers used by MutationCollector.
|
|
3
|
+
* Abstracts schema access to allow different schema implementations
|
|
4
|
+
* (SchemaRegistry, Contember SchemaNames) to be used interchangeably.
|
|
5
|
+
*/
|
|
6
|
+
export interface MutationSchemaProvider {
|
|
7
|
+
/**
|
|
8
|
+
* Gets all scalar (non-relation) field names for an entity.
|
|
9
|
+
*/
|
|
10
|
+
getScalarFields(entityType: string): readonly string[];
|
|
11
|
+
/**
|
|
12
|
+
* Gets all relation field names for an entity.
|
|
13
|
+
*/
|
|
14
|
+
getRelationFields(entityType: string): readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* Gets the relation type for a field.
|
|
17
|
+
* Returns undefined if the field is not a relation.
|
|
18
|
+
*/
|
|
19
|
+
getRelationType(entityType: string, fieldName: string): 'hasOne' | 'hasMany' | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the target entity type for a relation field.
|
|
22
|
+
* Returns undefined if the field is not a relation.
|
|
23
|
+
*/
|
|
24
|
+
getRelationTarget(entityType: string, fieldName: string): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if an entity type exists in the schema.
|
|
27
|
+
*/
|
|
28
|
+
hasEntity(entityType: string): boolean;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=MutationSchemaProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutationSchemaProvider.d.ts","sourceRoot":"","sources":["../../src/persistence/MutationSchemaProvider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;IAEtD;;OAEG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;IAExD;;;OAGG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;IAExF;;;OAGG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAE5E;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CACtC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { BatchPersister, type BatchPersisterOptions } from './BatchPersister.js';
|
|
2
|
+
export { ChangeRegistry, type DirtyEntity } from './ChangeRegistry.js';
|
|
3
|
+
export { MutationCollector, type EntityMutationResult } from './MutationCollector.js';
|
|
4
|
+
export type { MutationSchemaProvider } from './MutationSchemaProvider.js';
|
|
5
|
+
export { ContemberSchemaMutationAdapter } from './ContemberSchemaMutationAdapter.js';
|
|
6
|
+
export type { MutationDataCollector, AllScope, EntityScope, FieldsScope, RelationScope, CustomScope, PersistScope, FieldPersistResult, EntityPersistResult, PersistError, PersistenceResult, TransactionMutation, TransactionMutationResult, TransactionResult, BatchPersistOptions, UpdateMode, } from './types.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/persistence/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtE,OAAO,EAAE,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACrF,YAAY,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACzE,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAA;AACpF,YAAY,EACX,qBAAqB,EACrB,QAAQ,EACR,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,GACV,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { ContemberMutationResult } from '../errors/pathMapper.js';
|
|
2
|
+
import type { FieldError } from '../errors/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for custom mutation data collectors.
|
|
5
|
+
* Used to build proper nested mutations for persistence operations.
|
|
6
|
+
*/
|
|
7
|
+
export interface MutationDataCollector {
|
|
8
|
+
/**
|
|
9
|
+
* Collects mutation data for updating an existing entity.
|
|
10
|
+
* Returns the mutation input or null if no changes.
|
|
11
|
+
*/
|
|
12
|
+
collectUpdateData(entityType: string, entityId: string): Record<string, unknown> | null;
|
|
13
|
+
/**
|
|
14
|
+
* Collects mutation data for creating a new entity.
|
|
15
|
+
* Returns the mutation input or null if no data.
|
|
16
|
+
*/
|
|
17
|
+
collectCreateData?(entityType: string, entityId: string): Record<string, unknown> | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Scope that encompasses all dirty entities
|
|
21
|
+
*/
|
|
22
|
+
export interface AllScope {
|
|
23
|
+
readonly type: 'all';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Scope for a single entity
|
|
27
|
+
*/
|
|
28
|
+
export interface EntityScope {
|
|
29
|
+
readonly type: 'entity';
|
|
30
|
+
readonly entityType: string;
|
|
31
|
+
readonly entityId: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Scope for specific fields of an entity
|
|
35
|
+
*/
|
|
36
|
+
export interface FieldsScope {
|
|
37
|
+
readonly type: 'fields';
|
|
38
|
+
readonly entityType: string;
|
|
39
|
+
readonly entityId: string;
|
|
40
|
+
readonly fields: readonly string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Scope for a specific relation of an entity
|
|
44
|
+
*/
|
|
45
|
+
export interface RelationScope {
|
|
46
|
+
readonly type: 'relation';
|
|
47
|
+
readonly entityType: string;
|
|
48
|
+
readonly entityId: string;
|
|
49
|
+
readonly relationName: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Custom scope with explicit entity list
|
|
53
|
+
*/
|
|
54
|
+
export interface CustomScope {
|
|
55
|
+
readonly type: 'custom';
|
|
56
|
+
readonly entities: ReadonlyArray<{
|
|
57
|
+
readonly entityType: string;
|
|
58
|
+
readonly entityId: string;
|
|
59
|
+
readonly fields?: readonly string[];
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Union of all persist scope types
|
|
64
|
+
*/
|
|
65
|
+
export type PersistScope = AllScope | EntityScope | FieldsScope | RelationScope | CustomScope;
|
|
66
|
+
/**
|
|
67
|
+
* Result for a single field persist operation
|
|
68
|
+
*/
|
|
69
|
+
export interface FieldPersistResult {
|
|
70
|
+
readonly entityType: string;
|
|
71
|
+
readonly entityId: string;
|
|
72
|
+
readonly fieldName: string;
|
|
73
|
+
readonly success: boolean;
|
|
74
|
+
readonly error?: FieldError;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Result for a single entity persist operation
|
|
78
|
+
*/
|
|
79
|
+
export interface EntityPersistResult {
|
|
80
|
+
readonly entityType: string;
|
|
81
|
+
readonly entityId: string;
|
|
82
|
+
readonly operation: 'create' | 'update' | 'delete';
|
|
83
|
+
readonly success: boolean;
|
|
84
|
+
readonly error?: PersistError;
|
|
85
|
+
readonly fieldResults?: readonly FieldPersistResult[];
|
|
86
|
+
/** Server-assigned ID for creates (when tempId was used) */
|
|
87
|
+
readonly persistedId?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Error information for failed persist operations
|
|
91
|
+
*/
|
|
92
|
+
export interface PersistError {
|
|
93
|
+
readonly message: string;
|
|
94
|
+
readonly mutationResult?: ContemberMutationResult;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Result of a batch/transaction persist operation
|
|
98
|
+
*/
|
|
99
|
+
export interface PersistenceResult {
|
|
100
|
+
/** Whether the entire operation succeeded */
|
|
101
|
+
readonly success: boolean;
|
|
102
|
+
/** Results for each entity in the operation */
|
|
103
|
+
readonly results: readonly EntityPersistResult[];
|
|
104
|
+
/** Number of successfully persisted entities */
|
|
105
|
+
readonly successCount: number;
|
|
106
|
+
/** Number of failed entities */
|
|
107
|
+
readonly failedCount: number;
|
|
108
|
+
/** Number of entities skipped (e.g., already in-flight) */
|
|
109
|
+
readonly skippedCount: number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A single mutation in a transaction
|
|
113
|
+
*/
|
|
114
|
+
export interface TransactionMutation {
|
|
115
|
+
readonly entityType: string;
|
|
116
|
+
readonly entityId: string;
|
|
117
|
+
readonly operation: 'create' | 'update' | 'delete';
|
|
118
|
+
readonly data?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Result of a single mutation in a transaction
|
|
122
|
+
*/
|
|
123
|
+
export interface TransactionMutationResult {
|
|
124
|
+
readonly entityType: string;
|
|
125
|
+
readonly entityId: string;
|
|
126
|
+
readonly ok: boolean;
|
|
127
|
+
/** Server-assigned ID for creates */
|
|
128
|
+
readonly persistedId?: string;
|
|
129
|
+
readonly errorMessage?: string;
|
|
130
|
+
readonly mutationResult?: ContemberMutationResult;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Result of a transaction persist operation
|
|
134
|
+
*/
|
|
135
|
+
export interface TransactionResult {
|
|
136
|
+
/** Whether all mutations succeeded */
|
|
137
|
+
readonly ok: boolean;
|
|
138
|
+
/** Results per mutation, in same order as input */
|
|
139
|
+
readonly results: readonly TransactionMutationResult[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Update mode for persistence operations.
|
|
143
|
+
* - 'optimistic': Update UI immediately, revert on failure (default)
|
|
144
|
+
* - 'pessimistic': Wait for server confirmation before updating UI
|
|
145
|
+
*/
|
|
146
|
+
export type UpdateMode = 'optimistic' | 'pessimistic';
|
|
147
|
+
/**
|
|
148
|
+
* Options for batch persist operations
|
|
149
|
+
*/
|
|
150
|
+
export interface BatchPersistOptions {
|
|
151
|
+
/**
|
|
152
|
+
* Skip entities that are currently in-flight
|
|
153
|
+
* @default true
|
|
154
|
+
*/
|
|
155
|
+
readonly skipInFlight?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* AbortSignal for cancellation
|
|
158
|
+
*/
|
|
159
|
+
readonly signal?: AbortSignal;
|
|
160
|
+
/**
|
|
161
|
+
* Automatically rollback optimistic changes when persistence fails.
|
|
162
|
+
* When enabled, entity data, relations, and has-many lists are reverted
|
|
163
|
+
* to their server state on failure.
|
|
164
|
+
* @default false
|
|
165
|
+
*/
|
|
166
|
+
readonly rollbackOnError?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Update mode for this operation.
|
|
169
|
+
* - 'optimistic': Changes shown in UI immediately (default)
|
|
170
|
+
* - 'pessimistic': Wait for server confirmation before showing in UI
|
|
171
|
+
*
|
|
172
|
+
* When using pessimistic mode:
|
|
173
|
+
* - Changes are staged but not visible in UI until server confirms
|
|
174
|
+
* - If server fails, staged changes are discarded (no UI change occurs)
|
|
175
|
+
* - Loading state is properly tracked via isPersisting
|
|
176
|
+
*
|
|
177
|
+
* @default Uses provider-level default or 'optimistic'
|
|
178
|
+
*/
|
|
179
|
+
readonly updateMode?: UpdateMode;
|
|
180
|
+
/**
|
|
181
|
+
* Called for each entity before persistence
|
|
182
|
+
*/
|
|
183
|
+
readonly onEntityPersisting?: (entityType: string, entityId: string) => void | Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Called for each entity after persistence (success or failure)
|
|
186
|
+
*/
|
|
187
|
+
readonly onEntityPersisted?: (result: EntityPersistResult) => void;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/persistence/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAy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