@aws-amplify/datastore 3.7.3 → 3.7.4-custom-pk.79
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/CHANGELOG.md +144 -17
- package/README.md +154 -0
- package/dist/aws-amplify-datastore.js +3344 -1405
- package/dist/aws-amplify-datastore.js.map +1 -1
- package/dist/aws-amplify-datastore.min.js +25 -95
- package/dist/aws-amplify-datastore.min.js.map +1 -1
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +2 -2
- package/lib/authModeStrategies/multiAuthStrategy.js +32 -26
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.d.ts +17 -16
- package/lib/datastore/datastore.js +250 -78
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.d.ts +3 -19
- package/lib/predicates/index.d.ts +3 -2
- package/lib/predicates/index.js +12 -2
- package/lib/predicates/index.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +6 -2
- package/lib/storage/adapter/AsyncStorageAdapter.js +140 -66
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +4 -4
- package/lib/storage/adapter/AsyncStorageDatabase.js +57 -27
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +2 -2
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +7 -2
- package/lib/storage/adapter/IndexedDBAdapter.js +460 -253
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/index.d.ts +1 -1
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +106 -28
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/index.d.ts +23 -7
- package/lib/sync/index.js +18 -17
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.d.ts +3 -3
- package/lib/sync/merger.js +8 -6
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.d.ts +2 -2
- package/lib/sync/outbox.js +12 -9
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.d.ts +17 -0
- package/lib/sync/processors/errorMaps.js +125 -0
- package/lib/sync/processors/errorMaps.js.map +1 -0
- package/lib/sync/processors/mutation.d.ts +22 -4
- package/lib/sync/processors/mutation.js +119 -51
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.d.ts +4 -2
- package/lib/sync/processors/subscription.js +76 -41
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.d.ts +4 -2
- package/lib/sync/processors/sync.js +62 -27
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.d.ts +3 -2
- package/lib/sync/utils.js +54 -7
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.d.ts +85 -33
- package/lib/types.js +31 -2
- package/lib/types.js.map +1 -1
- package/lib/util.d.ts +43 -33
- package/lib/util.js +161 -21
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.d.ts +2 -2
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +32 -26
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +17 -16
- package/lib-esm/datastore/datastore.js +252 -80
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/index.d.ts +3 -19
- package/lib-esm/predicates/index.d.ts +3 -2
- package/lib-esm/predicates/index.js +13 -3
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +6 -2
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +140 -66
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.d.ts +4 -4
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +57 -27
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js +2 -2
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +7 -2
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +460 -253
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/index.d.ts +1 -1
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +106 -28
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/index.d.ts +23 -7
- package/lib-esm/sync/index.js +20 -19
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.d.ts +3 -3
- package/lib-esm/sync/merger.js +8 -6
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.d.ts +2 -2
- package/lib-esm/sync/outbox.js +13 -10
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.d.ts +17 -0
- package/lib-esm/sync/processors/errorMaps.js +119 -0
- package/lib-esm/sync/processors/errorMaps.js.map +1 -0
- package/lib-esm/sync/processors/mutation.d.ts +22 -4
- package/lib-esm/sync/processors/mutation.js +122 -54
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.d.ts +4 -2
- package/lib-esm/sync/processors/subscription.js +77 -42
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.d.ts +4 -2
- package/lib-esm/sync/processors/sync.js +62 -27
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +3 -2
- package/lib-esm/sync/utils.js +54 -8
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +85 -33
- package/lib-esm/types.js +29 -3
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +43 -33
- package/lib-esm/util.js +151 -18
- package/lib-esm/util.js.map +1 -1
- package/package.json +10 -9
- package/src/authModeStrategies/multiAuthStrategy.ts +24 -21
- package/src/datastore/datastore.ts +396 -143
- package/src/predicates/index.ts +32 -10
- package/src/storage/adapter/AsyncStorageAdapter.ts +161 -61
- package/src/storage/adapter/AsyncStorageDatabase.ts +62 -25
- package/src/storage/adapter/InMemoryStore.ts +2 -2
- package/src/storage/adapter/IndexedDBAdapter.ts +355 -101
- package/src/storage/adapter/index.ts +1 -1
- package/src/storage/storage.ts +85 -24
- package/src/sync/index.ts +74 -58
- package/src/sync/merger.ts +16 -4
- package/src/sync/outbox.ts +22 -8
- package/src/sync/processors/errorMaps.ts +93 -0
- package/src/sync/processors/mutation.ts +143 -84
- package/src/sync/processors/subscription.ts +67 -36
- package/src/sync/processors/sync.ts +37 -12
- package/src/sync/utils.ts +63 -15
- package/src/types.ts +242 -49
- package/src/util.ts +212 -35
- package/ssr/package.json +1 -1
package/lib-esm/types.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ModelInstanceCreator } from './datastore/datastore';
|
|
2
2
|
import { PredicateAll } from './predicates';
|
|
3
3
|
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
4
|
+
import { Auth } from '@aws-amplify/auth';
|
|
5
|
+
import { API } from '@aws-amplify/api';
|
|
6
|
+
import Cache from '@aws-amplify/cache';
|
|
4
7
|
import { Adapter } from './storage/adapter';
|
|
5
8
|
export declare type Schema = UserSchema & {
|
|
6
9
|
version: string;
|
|
@@ -43,17 +46,19 @@ declare type SchemaEnum = {
|
|
|
43
46
|
export declare type ModelAssociation = AssociatedWith | TargetNameAssociation;
|
|
44
47
|
declare type AssociatedWith = {
|
|
45
48
|
connectionType: 'HAS_MANY' | 'HAS_ONE';
|
|
46
|
-
associatedWith: string;
|
|
49
|
+
associatedWith: string | string[];
|
|
47
50
|
targetName?: string;
|
|
51
|
+
targetNames?: string[];
|
|
48
52
|
};
|
|
49
53
|
export declare function isAssociatedWith(obj: any): obj is AssociatedWith;
|
|
50
54
|
declare type TargetNameAssociation = {
|
|
51
55
|
connectionType: 'BELONGS_TO';
|
|
52
|
-
targetName
|
|
56
|
+
targetName?: string;
|
|
57
|
+
targetNames?: string[];
|
|
53
58
|
};
|
|
54
59
|
export declare function isTargetNameAssociation(obj: any): obj is TargetNameAssociation;
|
|
55
60
|
export declare type ModelAttributes = ModelAttribute[];
|
|
56
|
-
declare type ModelAttribute = {
|
|
61
|
+
export declare type ModelAttribute = {
|
|
57
62
|
type: string;
|
|
58
63
|
properties?: Record<string, any>;
|
|
59
64
|
};
|
|
@@ -84,6 +89,7 @@ declare type ModelAttributeKey = {
|
|
|
84
89
|
declare type ModelAttributePrimaryKey = {
|
|
85
90
|
type: 'key';
|
|
86
91
|
properties: {
|
|
92
|
+
name: never;
|
|
87
93
|
fields: string[];
|
|
88
94
|
};
|
|
89
95
|
};
|
|
@@ -176,44 +182,74 @@ export declare type ModelField = {
|
|
|
176
182
|
export declare type NonModelTypeConstructor<T> = {
|
|
177
183
|
new (init: T): T;
|
|
178
184
|
};
|
|
179
|
-
export declare type PersistentModelConstructor<T extends PersistentModel
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
export declare type
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
export declare type
|
|
193
|
-
|
|
194
|
-
|
|
185
|
+
export declare type PersistentModelConstructor<T extends PersistentModel> = {
|
|
186
|
+
new (init: ModelInit<T, PersistentModelMetaData<T>>): T;
|
|
187
|
+
copyOf(src: T, mutator: (draft: MutableModel<T, PersistentModelMetaData<T>>) => void): T;
|
|
188
|
+
};
|
|
189
|
+
export declare type TypeConstructorMap = Record<string, PersistentModelConstructor<any> | NonModelTypeConstructor<unknown>>;
|
|
190
|
+
export declare const __identifierBrand__: unique symbol;
|
|
191
|
+
export declare type IdentifierBrand<T, K> = T & {
|
|
192
|
+
[__identifierBrand__]: K;
|
|
193
|
+
};
|
|
194
|
+
export declare type ManagedIdentifier<T, F extends keyof T> = IdentifierBrand<{
|
|
195
|
+
field: F extends string ? F : never;
|
|
196
|
+
type: T;
|
|
197
|
+
}, 'ManagedIdentifier'>;
|
|
198
|
+
export declare type OptionallyManagedIdentifier<T, F extends keyof T> = IdentifierBrand<{
|
|
199
|
+
field: F extends string ? F : never;
|
|
200
|
+
type: T;
|
|
201
|
+
}, 'OptionallyManagedIdentifier'>;
|
|
202
|
+
export declare type CompositeIdentifier<T, K extends Array<keyof T>> = IdentifierBrand<{
|
|
203
|
+
fields: K;
|
|
204
|
+
type: T;
|
|
205
|
+
}, 'CompositeIdentifier'>;
|
|
206
|
+
export declare type CustomIdentifier<T, K extends keyof T> = CompositeIdentifier<T, [K]>;
|
|
207
|
+
export declare type Identifier<T> = ManagedIdentifier<T, any> | OptionallyManagedIdentifier<T, any> | CompositeIdentifier<T, any> | CustomIdentifier<T, any>;
|
|
208
|
+
export declare type IdentifierFields<T extends PersistentModel, M extends PersistentModelMetaData<T> = never> = (MetadataOrDefault<T, M>['identifier'] extends ManagedIdentifier<any, any> | OptionallyManagedIdentifier<any, any> ? MetadataOrDefault<T, M>['identifier']['field'] : MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, infer B> ? B[number] : MetadataOrDefault<T, M>['identifier']['field']) & string;
|
|
209
|
+
export declare type IdentifierFieldsForInit<T extends PersistentModel, M extends PersistentModelMetaData<T>> = MetadataOrDefault<T, M>['identifier'] extends DefaultPersistentModelMetaData | ManagedIdentifier<T, any> ? never : MetadataOrDefault<T, M>['identifier'] extends OptionallyManagedIdentifier<T, any> ? IdentifierFields<T, M> : MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any> ? IdentifierFields<T, M> : never;
|
|
210
|
+
export declare const __modelMeta__: unique symbol;
|
|
211
|
+
export declare type PersistentModelMetaData<T> = {
|
|
212
|
+
identifier?: Identifier<T>;
|
|
213
|
+
readOnlyFields?: string;
|
|
214
|
+
};
|
|
215
|
+
export declare type DefaultPersistentModelMetaData = {
|
|
216
|
+
identifier: ManagedIdentifier<{
|
|
217
|
+
id: string;
|
|
218
|
+
}, 'id'>;
|
|
219
|
+
readOnlyFields: never;
|
|
220
|
+
};
|
|
221
|
+
export declare type MetadataOrDefault<T extends PersistentModel, _ extends PersistentModelMetaData<T> = never> = T extends {
|
|
222
|
+
[__modelMeta__]: PersistentModelMetaData<T>;
|
|
223
|
+
} ? T[typeof __modelMeta__] : DefaultPersistentModelMetaData;
|
|
224
|
+
export declare type PersistentModel = Readonly<Record<string, any>>;
|
|
225
|
+
export declare type MetadataReadOnlyFields<T extends PersistentModel, M extends PersistentModelMetaData<T>> = Extract<MetadataOrDefault<T, M>['readOnlyFields'] | M['readOnlyFields'], keyof T>;
|
|
226
|
+
export declare type ModelInit<T extends PersistentModel, M extends PersistentModelMetaData<T> = {}> = Omit<T, typeof __modelMeta__ | IdentifierFields<T, M> | MetadataReadOnlyFields<T, M>> & (MetadataOrDefault<T, M>['identifier'] extends OptionallyManagedIdentifier<T, any> ? Partial<Pick<T, IdentifierFieldsForInit<T, M>>> : Required<Pick<T, IdentifierFieldsForInit<T, M>>>);
|
|
195
227
|
declare type DeepWritable<T> = {
|
|
196
228
|
-readonly [P in keyof T]: T[P] extends TypeName<T[P]> ? T[P] : DeepWritable<T[P]>;
|
|
197
229
|
};
|
|
198
|
-
export declare type MutableModel<T extends
|
|
199
|
-
readOnlyFields: 'createdAt' | 'updatedAt';
|
|
200
|
-
}> = DeepWritable<Omit<T, 'id' | K['readOnlyFields']>> & Readonly<Pick<T, 'id' | K['readOnlyFields']>>;
|
|
230
|
+
export declare type MutableModel<T extends PersistentModel, M extends PersistentModelMetaData<T> = {}> = DeepWritable<Omit<T, IdentifierFields<T, M> | MetadataReadOnlyFields<T, M>>> & Readonly<Pick<T, IdentifierFields<T, M> | MetadataReadOnlyFields<T, M>>>;
|
|
201
231
|
export declare type ModelInstanceMetadata = {
|
|
202
|
-
id: string;
|
|
203
232
|
_version: number;
|
|
204
233
|
_lastChangedAt: number;
|
|
205
234
|
_deleted: boolean;
|
|
206
235
|
};
|
|
236
|
+
export declare type IdentifierFieldValue<T extends PersistentModel, M extends PersistentModelMetaData<T>> = MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any> ? MetadataOrDefault<T, M>['identifier']['fields'] extends [any] ? T[MetadataOrDefault<T, M>['identifier']['fields'][0]] : never : T[MetadataOrDefault<T, M>['identifier']['field']];
|
|
237
|
+
export declare type IdentifierFieldOrIdentifierObject<T extends PersistentModel, M extends PersistentModelMetaData<T>> = Pick<T, IdentifierFields<T, M>> | IdentifierFieldValue<T, M>;
|
|
238
|
+
export declare function isIdentifierFieldValue<T extends PersistentModel>(obj: any, modelDefinition: SchemaModel): obj is IdentifierFieldValue<T extends PersistentModel ? T : never, any>;
|
|
239
|
+
export declare function isIdentifierFieldOrObject<T extends PersistentModel>(obj: any, modelDefinition: SchemaModel): obj is IdentifierFieldOrIdentifierObject<T, any>;
|
|
240
|
+
export declare function isIdentifierObject<T extends PersistentModel>(obj: any, modelDefinition: SchemaModel): obj is IdentifierFields<T extends PersistentModel ? T : never, any>;
|
|
207
241
|
export declare enum OpType {
|
|
208
242
|
INSERT = "INSERT",
|
|
209
243
|
UPDATE = "UPDATE",
|
|
210
244
|
DELETE = "DELETE"
|
|
211
245
|
}
|
|
212
|
-
export declare type SubscriptionMessage<T extends PersistentModel> =
|
|
246
|
+
export declare type SubscriptionMessage<T extends PersistentModel> = Pick<InternalSubscriptionMessage<T>, 'opType' | 'element' | 'model' | 'condition'>;
|
|
247
|
+
export declare type InternalSubscriptionMessage<T extends PersistentModel> = {
|
|
213
248
|
opType: OpType;
|
|
214
249
|
element: T;
|
|
215
250
|
model: PersistentModelConstructor<T>;
|
|
216
251
|
condition: PredicatesGroup<T> | null;
|
|
252
|
+
savedElement?: T;
|
|
217
253
|
};
|
|
218
254
|
export declare type DataStoreSnapshot<T extends PersistentModel> = {
|
|
219
255
|
items: T[];
|
|
@@ -332,7 +368,8 @@ export declare type RelationType = {
|
|
|
332
368
|
modelName: string;
|
|
333
369
|
relationType: 'HAS_ONE' | 'HAS_MANY' | 'BELONGS_TO';
|
|
334
370
|
targetName?: string;
|
|
335
|
-
|
|
371
|
+
targetNames?: string[];
|
|
372
|
+
associatedWith?: string | string[];
|
|
336
373
|
};
|
|
337
374
|
export declare type RelationshipType = {
|
|
338
375
|
[modelName: string]: {
|
|
@@ -351,7 +388,7 @@ export declare type DataStoreConfig = {
|
|
|
351
388
|
DataStore?: {
|
|
352
389
|
authModeStrategyType?: AuthModeStrategyType;
|
|
353
390
|
conflictHandler?: ConflictHandler;
|
|
354
|
-
errorHandler?: (error: SyncError) => void;
|
|
391
|
+
errorHandler?: (error: SyncError<PersistentModel>) => void;
|
|
355
392
|
maxRecordsToSync?: number;
|
|
356
393
|
syncPageSize?: number;
|
|
357
394
|
fullSyncInterval?: number;
|
|
@@ -361,7 +398,7 @@ export declare type DataStoreConfig = {
|
|
|
361
398
|
};
|
|
362
399
|
authModeStrategyType?: AuthModeStrategyType;
|
|
363
400
|
conflictHandler?: ConflictHandler;
|
|
364
|
-
errorHandler?: (error: SyncError) => void;
|
|
401
|
+
errorHandler?: (error: SyncError<PersistentModel>) => void;
|
|
365
402
|
maxRecordsToSync?: number;
|
|
366
403
|
syncPageSize?: number;
|
|
367
404
|
fullSyncInterval?: number;
|
|
@@ -419,17 +456,27 @@ export declare type SyncConflict = {
|
|
|
419
456
|
operation: OpType;
|
|
420
457
|
attempts: number;
|
|
421
458
|
};
|
|
422
|
-
export declare type SyncError = {
|
|
459
|
+
export declare type SyncError<T extends PersistentModel> = {
|
|
423
460
|
message: string;
|
|
424
|
-
errorType:
|
|
425
|
-
errorInfo
|
|
426
|
-
|
|
427
|
-
|
|
461
|
+
errorType: ErrorType;
|
|
462
|
+
errorInfo?: string;
|
|
463
|
+
recoverySuggestion?: string;
|
|
464
|
+
model?: string;
|
|
465
|
+
localModel: T;
|
|
466
|
+
remoteModel: T;
|
|
467
|
+
process: ProcessName;
|
|
428
468
|
operation: string;
|
|
469
|
+
cause?: Error;
|
|
429
470
|
};
|
|
471
|
+
export declare type ErrorType = 'ConfigError' | 'BadModel' | 'BadRecord' | 'Unauthorized' | 'Transient' | 'Unknown';
|
|
472
|
+
export declare enum ProcessName {
|
|
473
|
+
'sync' = "sync",
|
|
474
|
+
'mutate' = "mutate",
|
|
475
|
+
'subscribe' = "subscribe"
|
|
476
|
+
}
|
|
430
477
|
export declare const DISCARD: unique symbol;
|
|
431
478
|
export declare type ConflictHandler = (conflict: SyncConflict) => Promise<PersistentModel | typeof DISCARD> | PersistentModel | typeof DISCARD;
|
|
432
|
-
export declare type ErrorHandler = (error: SyncError) => void;
|
|
479
|
+
export declare type ErrorHandler = (error: SyncError<PersistentModel>) => void;
|
|
433
480
|
export declare type DeferredCallbackResolverOptions = {
|
|
434
481
|
callback: () => void;
|
|
435
482
|
maxInterval?: number;
|
|
@@ -439,4 +486,9 @@ export declare enum LimitTimerRaceResolvedValues {
|
|
|
439
486
|
LIMIT = "LIMIT",
|
|
440
487
|
TIMER = "TIMER"
|
|
441
488
|
}
|
|
489
|
+
export declare type AmplifyContext = {
|
|
490
|
+
Auth: typeof Auth;
|
|
491
|
+
API: typeof API;
|
|
492
|
+
Cache: typeof Cache;
|
|
493
|
+
};
|
|
442
494
|
export {};
|
package/lib-esm/types.js
CHANGED
|
@@ -34,7 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
import { exhaustiveCheck, isAWSDate, isAWSTime, isAWSDateTime, isAWSTimestamp, isAWSEmail, isAWSJSON, isAWSURL, isAWSPhone, isAWSIPAddress, } from './util';
|
|
37
|
+
import { exhaustiveCheck, isAWSDate, isAWSTime, isAWSDateTime, isAWSTimestamp, isAWSEmail, isAWSJSON, isAWSURL, isAWSPhone, isAWSIPAddress, extractPrimaryKeyFieldNames, } from './util';
|
|
38
38
|
export function isSchemaModel(obj) {
|
|
39
39
|
return obj && obj.pluralName !== undefined;
|
|
40
40
|
}
|
|
@@ -42,7 +42,7 @@ export function isAssociatedWith(obj) {
|
|
|
42
42
|
return obj && obj.associatedWith;
|
|
43
43
|
}
|
|
44
44
|
export function isTargetNameAssociation(obj) {
|
|
45
|
-
return obj
|
|
45
|
+
return (obj === null || obj === void 0 ? void 0 : obj.targetName) || (obj === null || obj === void 0 ? void 0 : obj.targetNames);
|
|
46
46
|
}
|
|
47
47
|
export function isModelAttributeAuth(attr) {
|
|
48
48
|
return (attr.type === 'auth' &&
|
|
@@ -170,6 +170,27 @@ export function isEnumFieldType(obj) {
|
|
|
170
170
|
return true;
|
|
171
171
|
return false;
|
|
172
172
|
}
|
|
173
|
+
export function isIdentifierFieldValue(obj, modelDefinition) {
|
|
174
|
+
var _a;
|
|
175
|
+
var keys = extractPrimaryKeyFieldNames(modelDefinition);
|
|
176
|
+
if (keys.length === 1) {
|
|
177
|
+
var type = ((_a = modelDefinition === null || modelDefinition === void 0 ? void 0 : modelDefinition.fields[keys[0]]) !== null && _a !== void 0 ? _a : {}).type;
|
|
178
|
+
if (isGraphQLScalarType(type)) {
|
|
179
|
+
var jsType = GraphQLScalarType.getJSType(type);
|
|
180
|
+
return typeof obj === jsType;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
export function isIdentifierFieldOrObject(obj, modelDefinition) {
|
|
187
|
+
return (isIdentifierFieldValue(obj, modelDefinition) ||
|
|
188
|
+
isIdentifierObject(obj, modelDefinition));
|
|
189
|
+
}
|
|
190
|
+
export function isIdentifierObject(obj, modelDefinition) {
|
|
191
|
+
var keys = extractPrimaryKeyFieldNames(modelDefinition);
|
|
192
|
+
return (typeof obj === 'object' && obj && keys.every(function (k) { return obj[k] !== undefined; }));
|
|
193
|
+
}
|
|
173
194
|
//#endregion
|
|
174
195
|
//#region Subscription messages
|
|
175
196
|
export var OpType;
|
|
@@ -216,11 +237,16 @@ export function syncExpression(modelConstructor, conditionProducer) {
|
|
|
216
237
|
});
|
|
217
238
|
});
|
|
218
239
|
}
|
|
240
|
+
export var ProcessName;
|
|
241
|
+
(function (ProcessName) {
|
|
242
|
+
ProcessName["sync"] = "sync";
|
|
243
|
+
ProcessName["mutate"] = "mutate";
|
|
244
|
+
ProcessName["subscribe"] = "subscribe";
|
|
245
|
+
})(ProcessName || (ProcessName = {}));
|
|
219
246
|
export var DISCARD = Symbol('DISCARD');
|
|
220
247
|
export var LimitTimerRaceResolvedValues;
|
|
221
248
|
(function (LimitTimerRaceResolvedValues) {
|
|
222
249
|
LimitTimerRaceResolvedValues["LIMIT"] = "LIMIT";
|
|
223
250
|
LimitTimerRaceResolvedValues["TIMER"] = "TIMER";
|
|
224
251
|
})(LimitTimerRaceResolvedValues || (LimitTimerRaceResolvedValues = {}));
|
|
225
|
-
//#endregion
|
|
226
252
|
//# sourceMappingURL=types.js.map
|
package/lib-esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EACN,eAAe,EACf,SAAS,EACT,SAAS,EACT,aAAa,EACb,cAAc,EACd,UAAU,EACV,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EACN,eAAe,EACf,SAAS,EACT,SAAS,EACT,aAAa,EACb,cAAc,EACd,UAAU,EACV,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,EACd,2BAA2B,GAC3B,MAAM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}
|
package/lib-esm/util.d.ts
CHANGED
|
@@ -1,37 +1,11 @@
|
|
|
1
1
|
import { ULID } from 'ulid';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare
|
|
9
|
-
export declare const isModelConstructor: <T extends Readonly<{
|
|
10
|
-
id: string;
|
|
11
|
-
} & Record<string, any>>>(obj: any) => obj is PersistentModelConstructor<T, {
|
|
12
|
-
readOnlyFields: "createdAt" | "updatedAt";
|
|
13
|
-
}>;
|
|
14
|
-
export declare function registerNonModelClass(clazz: NonModelTypeConstructor<any>): void;
|
|
15
|
-
export declare const isNonModelConstructor: (obj: any) => obj is NonModelTypeConstructor<any>;
|
|
16
|
-
export declare const processCompositeKeys: (attributes: ModelAttributes) => Set<string>[];
|
|
17
|
-
export declare const establishRelationAndKeys: (namespace: SchemaNamespace) => [RelationshipType, ModelKeys];
|
|
18
|
-
export declare const traverseModel: <T extends Readonly<{
|
|
19
|
-
id: string;
|
|
20
|
-
} & Record<string, any>>>(srcModelName: string, instance: T, namespace: SchemaNamespace, modelInstanceCreator: <T_1 extends Readonly<{
|
|
21
|
-
id: string;
|
|
22
|
-
} & Record<string, any>> = Readonly<{
|
|
23
|
-
id: string;
|
|
24
|
-
} & Record<string, any>>>(modelConstructor: PersistentModelConstructor<T_1, {
|
|
25
|
-
readOnlyFields: "createdAt" | "updatedAt";
|
|
26
|
-
}>, init: Pick<T_1, Exclude<keyof T_1, "id" | "createdAt" | "updatedAt">> & Partial<ModelInstanceMetadata>) => T_1, getModelConstructorByModelName: (namsespaceName: string, modelName: string) => PersistentModelConstructor<any, {
|
|
27
|
-
readOnlyFields: "createdAt" | "updatedAt";
|
|
28
|
-
}>) => {
|
|
29
|
-
modelName: string;
|
|
30
|
-
item: T;
|
|
31
|
-
instance: T;
|
|
32
|
-
}[];
|
|
33
|
-
export declare const getIndex: (rel: RelationType[], src: string) => string;
|
|
34
|
-
export declare const getIndexFromAssociation: (indexes: string[], src: string) => string;
|
|
2
|
+
import { Patch } from 'immer';
|
|
3
|
+
import { PersistentModel, PersistentModelConstructor, PredicateObject, PredicatesGroup, RelationshipType, RelationType, ModelKeys, ModelAttributes, SchemaNamespace, SortPredicatesGroup, NonModelTypeConstructor, DeferredCallbackResolverOptions, SchemaModel, ModelAttribute } from './types';
|
|
4
|
+
export declare function extractKeyIfExists(modelDefinition: SchemaModel): ModelAttribute | undefined;
|
|
5
|
+
export declare function extractPrimaryKeyFieldNames(modelDefinition: SchemaModel): string[];
|
|
6
|
+
export declare function extractPrimaryKeyValues<T extends PersistentModel>(model: T, keyFields: string[]): string[];
|
|
7
|
+
export declare function isIdManaged(modelDefinition: SchemaModel): boolean;
|
|
8
|
+
export declare function isIdOptionallyManaged(modelDefinition: SchemaModel): boolean;
|
|
35
9
|
export declare enum NAMESPACES {
|
|
36
10
|
DATASTORE = "datastore",
|
|
37
11
|
USER = "user",
|
|
@@ -43,6 +17,23 @@ declare const USER = NAMESPACES.USER;
|
|
|
43
17
|
declare const SYNC = NAMESPACES.SYNC;
|
|
44
18
|
declare const STORAGE = NAMESPACES.STORAGE;
|
|
45
19
|
export { USER, SYNC, STORAGE, DATASTORE };
|
|
20
|
+
export declare const USER_AGENT_SUFFIX_DATASTORE = "/DataStore";
|
|
21
|
+
export declare const exhaustiveCheck: (obj: never, throwOnError?: boolean) => void;
|
|
22
|
+
export declare const isNullOrUndefined: (val: any) => boolean;
|
|
23
|
+
export declare const validatePredicate: <T extends Readonly<Record<string, any>>>(model: T, groupType: "and" | "or" | "not", predicatesOrGroups: (PredicateObject<T> | PredicatesGroup<T>)[]) => any;
|
|
24
|
+
export declare const validatePredicateField: <T>(value: T, operator: "ne" | "eq" | "le" | "lt" | "ge" | "gt" | "between" | "beginsWith" | "contains" | "notContains", operand: T | [T, T]) => boolean;
|
|
25
|
+
export declare const isModelConstructor: <T extends Readonly<Record<string, any>>>(obj: any) => obj is PersistentModelConstructor<T>;
|
|
26
|
+
export declare function registerNonModelClass(clazz: NonModelTypeConstructor<any>): void;
|
|
27
|
+
export declare const isNonModelConstructor: (obj: any) => obj is NonModelTypeConstructor<any>;
|
|
28
|
+
export declare const processCompositeKeys: (attributes: ModelAttributes) => Set<string>[];
|
|
29
|
+
export declare const establishRelationAndKeys: (namespace: SchemaNamespace) => [RelationshipType, ModelKeys];
|
|
30
|
+
export declare const traverseModel: <T extends Readonly<Record<string, any>>>(srcModelName: string, instance: T, namespace: SchemaNamespace, modelInstanceCreator: <T_1 extends Readonly<Record<string, any>>>(modelConstructor: PersistentModelConstructor<T_1>, init: Partial<T_1>) => T_1, getModelConstructorByModelName: (namsespaceName: string, modelName: string) => PersistentModelConstructor<any>) => {
|
|
31
|
+
modelName: string;
|
|
32
|
+
item: T;
|
|
33
|
+
instance: T;
|
|
34
|
+
}[];
|
|
35
|
+
export declare const getIndex: (rel: RelationType[], src: any) => string;
|
|
36
|
+
export declare const getIndexFromAssociation: (indexes: string[], src: any) => any;
|
|
46
37
|
export declare const isPrivateMode: () => Promise<unknown>;
|
|
47
38
|
export declare function monotonicUlidFactory(seed?: number): ULID;
|
|
48
39
|
/**
|
|
@@ -91,3 +82,22 @@ export declare class DeferredCallbackResolver {
|
|
|
91
82
|
clear(): void;
|
|
92
83
|
resolve(): void;
|
|
93
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* merge two sets of patches created by immer produce.
|
|
87
|
+
* newPatches take precedent over oldPatches for patches modifying the same path.
|
|
88
|
+
* In the case many consecutive pathces are merged the original model should
|
|
89
|
+
* always be the root model.
|
|
90
|
+
*
|
|
91
|
+
* Example:
|
|
92
|
+
* A -> B, patches1
|
|
93
|
+
* B -> C, patches2
|
|
94
|
+
*
|
|
95
|
+
* mergePatches(A, patches1, patches2) to get patches for A -> C
|
|
96
|
+
*
|
|
97
|
+
* @param originalSource the original Model the patches should be applied to
|
|
98
|
+
* @param oldPatches immer produce patch list
|
|
99
|
+
* @param newPatches immer produce patch list (will take precedence)
|
|
100
|
+
* @return merged patches
|
|
101
|
+
*/
|
|
102
|
+
export declare function mergePatches<T>(originalSource: T, oldPatches: Patch[], newPatches: Patch[]): Patch[];
|
|
103
|
+
export declare function extractTargetNamesFromSrc(src: any): string[] | undefined;
|
package/lib-esm/util.js
CHANGED
|
@@ -68,8 +68,60 @@ var __values = (this && this.__values) || function(o) {
|
|
|
68
68
|
import { Buffer } from 'buffer';
|
|
69
69
|
import { monotonicFactory } from 'ulid';
|
|
70
70
|
import { v4 as uuid } from 'uuid';
|
|
71
|
+
import { produce, applyPatches } from 'immer';
|
|
71
72
|
import { isPredicateGroup, isPredicateObj, SortDirection, isModelAttributeKey, isModelAttributePrimaryKey, isModelAttributeCompositeKey, LimitTimerRaceResolvedValues, } from './types';
|
|
72
73
|
import { WordArray } from 'amazon-cognito-identity-js';
|
|
74
|
+
var ID = 'id';
|
|
75
|
+
export function extractKeyIfExists(modelDefinition) {
|
|
76
|
+
var _c;
|
|
77
|
+
var keyAttribute = (_c = modelDefinition === null || modelDefinition === void 0 ? void 0 : modelDefinition.attributes) === null || _c === void 0 ? void 0 : _c.find(isModelAttributeKey);
|
|
78
|
+
return keyAttribute;
|
|
79
|
+
}
|
|
80
|
+
export function extractPrimaryKeyFieldNames(modelDefinition) {
|
|
81
|
+
var keyAttribute = extractKeyIfExists(modelDefinition);
|
|
82
|
+
if (keyAttribute && isModelAttributePrimaryKey(keyAttribute)) {
|
|
83
|
+
return keyAttribute.properties.fields;
|
|
84
|
+
}
|
|
85
|
+
return [ID];
|
|
86
|
+
}
|
|
87
|
+
export function extractPrimaryKeyValues(model, keyFields) {
|
|
88
|
+
return keyFields.map(function (key) { return model[key]; });
|
|
89
|
+
}
|
|
90
|
+
// IdentifierFields<ManagedIdentifier>
|
|
91
|
+
// Default behavior without explicit @primaryKey defined
|
|
92
|
+
export function isIdManaged(modelDefinition) {
|
|
93
|
+
var keyAttribute = extractKeyIfExists(modelDefinition);
|
|
94
|
+
if (keyAttribute && isModelAttributePrimaryKey(keyAttribute)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
// IdentifierFields<OptionallyManagedIdentifier>
|
|
100
|
+
// @primaryKey with explicit `id` in the PK. Single key or composite
|
|
101
|
+
export function isIdOptionallyManaged(modelDefinition) {
|
|
102
|
+
var keyAttribute = extractKeyIfExists(modelDefinition);
|
|
103
|
+
if (keyAttribute && isModelAttributePrimaryKey(keyAttribute)) {
|
|
104
|
+
// const idInKey = !!keyAttribute.properties.fields.find(
|
|
105
|
+
// field => field === ID
|
|
106
|
+
// );
|
|
107
|
+
// return idInKey && keyAttribute.properties.fields.length === 1;
|
|
108
|
+
return keyAttribute.properties.fields[0] === ID;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
export var NAMESPACES;
|
|
113
|
+
(function (NAMESPACES) {
|
|
114
|
+
NAMESPACES["DATASTORE"] = "datastore";
|
|
115
|
+
NAMESPACES["USER"] = "user";
|
|
116
|
+
NAMESPACES["SYNC"] = "sync";
|
|
117
|
+
NAMESPACES["STORAGE"] = "storage";
|
|
118
|
+
})(NAMESPACES || (NAMESPACES = {}));
|
|
119
|
+
var DATASTORE = NAMESPACES.DATASTORE;
|
|
120
|
+
var USER = NAMESPACES.USER;
|
|
121
|
+
var SYNC = NAMESPACES.SYNC;
|
|
122
|
+
var STORAGE = NAMESPACES.STORAGE;
|
|
123
|
+
export { USER, SYNC, STORAGE, DATASTORE };
|
|
124
|
+
export var USER_AGENT_SUFFIX_DATASTORE = '/DataStore';
|
|
73
125
|
export var exhaustiveCheck = function (obj, throwOnError) {
|
|
74
126
|
if (throwOnError === void 0) { throwOnError = true; }
|
|
75
127
|
if (throwOnError) {
|
|
@@ -247,10 +299,26 @@ export var establishRelationAndKeys = function (namespace) {
|
|
|
247
299
|
modelName: fieldAttribute.type.model,
|
|
248
300
|
relationType: connectionType,
|
|
249
301
|
targetName: fieldAttribute.association['targetName'],
|
|
302
|
+
targetNames: fieldAttribute.association['targetNames'],
|
|
250
303
|
associatedWith: fieldAttribute.association['associatedWith'],
|
|
251
304
|
});
|
|
252
305
|
if (connectionType === 'BELONGS_TO') {
|
|
253
|
-
|
|
306
|
+
// const targetNames: string[] = extractTargetNamesFromSrc(
|
|
307
|
+
// fieldAttribute.association
|
|
308
|
+
// );
|
|
309
|
+
// targetNames.forEach((targetName: string) => {
|
|
310
|
+
// relationship[mKey].indexes.push(targetName);
|
|
311
|
+
// });
|
|
312
|
+
if (fieldAttribute.association.targetName) {
|
|
313
|
+
// backwards-compatability for schema generated prior to custom primary key support
|
|
314
|
+
relationship[mKey].indexes.push(fieldAttribute.association['targetName']);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
// iterate through fieldAttribute.association.targetNames, and push to relationship[mKey].indexes
|
|
318
|
+
fieldAttribute.association.targetNames.forEach(function (targetName) {
|
|
319
|
+
relationship[mKey].indexes.push(targetName);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
254
322
|
}
|
|
255
323
|
}
|
|
256
324
|
});
|
|
@@ -292,6 +360,9 @@ export var establishRelationAndKeys = function (namespace) {
|
|
|
292
360
|
}
|
|
293
361
|
finally { if (e_1) throw e_1.error; }
|
|
294
362
|
}
|
|
363
|
+
if (!keys[mKey].primaryKey) {
|
|
364
|
+
keys[mKey].primaryKey = [ID];
|
|
365
|
+
}
|
|
295
366
|
}
|
|
296
367
|
});
|
|
297
368
|
return [relationship, keys];
|
|
@@ -321,12 +392,26 @@ export var traverseModel = function (srcModelName, instance, namespace, modelIns
|
|
|
321
392
|
item: instance[rItem.fieldName],
|
|
322
393
|
instance: modelInstance,
|
|
323
394
|
});
|
|
324
|
-
|
|
395
|
+
var targetNames = extractTargetNamesFromSrc(rItem);
|
|
396
|
+
// `targetName` will be defined for Has One if feature flag
|
|
325
397
|
// https://docs.amplify.aws/cli/reference/feature-flags/#useAppsyncModelgenPlugin
|
|
326
398
|
// is true (default as of 5/7/21)
|
|
327
399
|
// Making this conditional for backward-compatibility
|
|
328
|
-
if (
|
|
329
|
-
|
|
400
|
+
if (targetNames) {
|
|
401
|
+
targetNames.forEach(function (targetName, idx) {
|
|
402
|
+
// Get the connected record
|
|
403
|
+
var relatedRecordInProxy = (draftInstance[rItem.fieldName]);
|
|
404
|
+
// Previously, we used the hardcoded 'id' as they key,
|
|
405
|
+
// now we need the value of the key to get the PK (and SK)
|
|
406
|
+
// values from the related record
|
|
407
|
+
var primaryKey = namespace.keys[modelConstructor.name].primaryKey;
|
|
408
|
+
var keyField = primaryKey && primaryKey[idx];
|
|
409
|
+
// Get the value
|
|
410
|
+
var relatedRecordInProxyPkValue = relatedRecordInProxy[keyField];
|
|
411
|
+
// Set the targetName value
|
|
412
|
+
draftInstance[targetName] = relatedRecordInProxyPkValue;
|
|
413
|
+
});
|
|
414
|
+
// Delete the instance from the proxy
|
|
330
415
|
delete draftInstance[rItem.fieldName];
|
|
331
416
|
}
|
|
332
417
|
else {
|
|
@@ -353,8 +438,25 @@ export var traverseModel = function (srcModelName, instance, namespace, modelIns
|
|
|
353
438
|
}
|
|
354
439
|
}
|
|
355
440
|
if (draftInstance[rItem.fieldName]) {
|
|
356
|
-
|
|
357
|
-
|
|
441
|
+
var targetNames = extractTargetNamesFromSrc(rItem);
|
|
442
|
+
if (targetNames) {
|
|
443
|
+
targetNames.forEach(function (targetName, idx) {
|
|
444
|
+
// Get the connected record
|
|
445
|
+
var relatedRecordInProxy = (draftInstance[rItem.fieldName]);
|
|
446
|
+
// Previously, we used the hardcoded `id` for the key.
|
|
447
|
+
// Now, we need the value of the key to get the PK (and SK)
|
|
448
|
+
// values from the related record
|
|
449
|
+
var primaryKey = namespace.keys[modelConstructor.name].primaryKey;
|
|
450
|
+
// fall back to ID if
|
|
451
|
+
var keyField = primaryKey && primaryKey[idx];
|
|
452
|
+
// Get the value
|
|
453
|
+
var relatedRecordInProxyPkValue = relatedRecordInProxy[keyField];
|
|
454
|
+
// Set the targetName value
|
|
455
|
+
draftInstance[targetName] = relatedRecordInProxyPkValue;
|
|
456
|
+
});
|
|
457
|
+
// Delete the instance from the proxy
|
|
458
|
+
delete draftInstance[rItem.fieldName];
|
|
459
|
+
}
|
|
358
460
|
}
|
|
359
461
|
break;
|
|
360
462
|
case 'HAS_MANY':
|
|
@@ -393,18 +495,6 @@ export var getIndexFromAssociation = function (indexes, src) {
|
|
|
393
495
|
var index = indexes.find(function (idx) { return idx === src; });
|
|
394
496
|
return index;
|
|
395
497
|
};
|
|
396
|
-
export var NAMESPACES;
|
|
397
|
-
(function (NAMESPACES) {
|
|
398
|
-
NAMESPACES["DATASTORE"] = "datastore";
|
|
399
|
-
NAMESPACES["USER"] = "user";
|
|
400
|
-
NAMESPACES["SYNC"] = "sync";
|
|
401
|
-
NAMESPACES["STORAGE"] = "storage";
|
|
402
|
-
})(NAMESPACES || (NAMESPACES = {}));
|
|
403
|
-
var DATASTORE = NAMESPACES.DATASTORE;
|
|
404
|
-
var USER = NAMESPACES.USER;
|
|
405
|
-
var SYNC = NAMESPACES.SYNC;
|
|
406
|
-
var STORAGE = NAMESPACES.STORAGE;
|
|
407
|
-
export { USER, SYNC, STORAGE, DATASTORE };
|
|
408
498
|
var privateModeCheckResult;
|
|
409
499
|
export var isPrivateMode = function () {
|
|
410
500
|
return new Promise(function (resolve) {
|
|
@@ -687,4 +777,47 @@ var DeferredCallbackResolver = /** @class */ (function () {
|
|
|
687
777
|
return DeferredCallbackResolver;
|
|
688
778
|
}());
|
|
689
779
|
export { DeferredCallbackResolver };
|
|
780
|
+
/**
|
|
781
|
+
* merge two sets of patches created by immer produce.
|
|
782
|
+
* newPatches take precedent over oldPatches for patches modifying the same path.
|
|
783
|
+
* In the case many consecutive pathces are merged the original model should
|
|
784
|
+
* always be the root model.
|
|
785
|
+
*
|
|
786
|
+
* Example:
|
|
787
|
+
* A -> B, patches1
|
|
788
|
+
* B -> C, patches2
|
|
789
|
+
*
|
|
790
|
+
* mergePatches(A, patches1, patches2) to get patches for A -> C
|
|
791
|
+
*
|
|
792
|
+
* @param originalSource the original Model the patches should be applied to
|
|
793
|
+
* @param oldPatches immer produce patch list
|
|
794
|
+
* @param newPatches immer produce patch list (will take precedence)
|
|
795
|
+
* @return merged patches
|
|
796
|
+
*/
|
|
797
|
+
export function mergePatches(originalSource, oldPatches, newPatches) {
|
|
798
|
+
var patchesToMerge = oldPatches.concat(newPatches);
|
|
799
|
+
var patches;
|
|
800
|
+
produce(originalSource, function (draft) {
|
|
801
|
+
applyPatches(draft, patchesToMerge);
|
|
802
|
+
}, function (p) {
|
|
803
|
+
patches = p;
|
|
804
|
+
});
|
|
805
|
+
return patches;
|
|
806
|
+
}
|
|
807
|
+
/* Backwards-compatability for schema generated prior to custom primary key support:
|
|
808
|
+
the single field `targetName` has been replaced with an array of `targetNames`
|
|
809
|
+
*/
|
|
810
|
+
export function extractTargetNamesFromSrc(src) {
|
|
811
|
+
var targetName = src === null || src === void 0 ? void 0 : src.targetName;
|
|
812
|
+
var targetNames = src === null || src === void 0 ? void 0 : src.targetNames;
|
|
813
|
+
if (Array.isArray(targetNames) && (targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) {
|
|
814
|
+
return targetNames;
|
|
815
|
+
}
|
|
816
|
+
else if (typeof targetName === 'string') {
|
|
817
|
+
return [targetName];
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
return undefined;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
690
823
|
//# sourceMappingURL=util.js.map
|