@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/src/types.ts
CHANGED
|
@@ -10,9 +10,13 @@ import {
|
|
|
10
10
|
isAWSURL,
|
|
11
11
|
isAWSPhone,
|
|
12
12
|
isAWSIPAddress,
|
|
13
|
+
extractPrimaryKeyFieldNames,
|
|
13
14
|
} from './util';
|
|
14
15
|
import { PredicateAll } from './predicates';
|
|
15
16
|
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
17
|
+
import { Auth } from '@aws-amplify/auth';
|
|
18
|
+
import { API } from '@aws-amplify/api';
|
|
19
|
+
import Cache from '@aws-amplify/cache';
|
|
16
20
|
import { Adapter } from './storage/adapter';
|
|
17
21
|
|
|
18
22
|
//#region Schema types
|
|
@@ -60,25 +64,29 @@ type SchemaEnum = {
|
|
|
60
64
|
export type ModelAssociation = AssociatedWith | TargetNameAssociation;
|
|
61
65
|
type AssociatedWith = {
|
|
62
66
|
connectionType: 'HAS_MANY' | 'HAS_ONE';
|
|
63
|
-
associatedWith: string;
|
|
67
|
+
associatedWith: string | string[];
|
|
64
68
|
targetName?: string;
|
|
69
|
+
targetNames?: string[];
|
|
65
70
|
};
|
|
71
|
+
|
|
66
72
|
export function isAssociatedWith(obj: any): obj is AssociatedWith {
|
|
67
73
|
return obj && obj.associatedWith;
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
type TargetNameAssociation = {
|
|
71
77
|
connectionType: 'BELONGS_TO';
|
|
72
|
-
targetName
|
|
78
|
+
targetName?: string;
|
|
79
|
+
targetNames?: string[];
|
|
73
80
|
};
|
|
81
|
+
|
|
74
82
|
export function isTargetNameAssociation(
|
|
75
83
|
obj: any
|
|
76
84
|
): obj is TargetNameAssociation {
|
|
77
|
-
return obj
|
|
85
|
+
return obj?.targetName || obj?.targetNames;
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
export type ModelAttributes = ModelAttribute[];
|
|
81
|
-
type ModelAttribute = { type: string; properties?: Record<string, any> };
|
|
89
|
+
export type ModelAttribute = { type: string; properties?: Record<string, any> };
|
|
82
90
|
|
|
83
91
|
export type ModelAuthRule = {
|
|
84
92
|
allow: string;
|
|
@@ -120,6 +128,7 @@ type ModelAttributeKey = {
|
|
|
120
128
|
type ModelAttributePrimaryKey = {
|
|
121
129
|
type: 'key';
|
|
122
130
|
properties: {
|
|
131
|
+
name: never;
|
|
123
132
|
fields: string[];
|
|
124
133
|
};
|
|
125
134
|
};
|
|
@@ -333,33 +342,134 @@ export type NonModelTypeConstructor<T> = {
|
|
|
333
342
|
};
|
|
334
343
|
|
|
335
344
|
// Class for model
|
|
336
|
-
export type PersistentModelConstructor<
|
|
337
|
-
T
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
new (init: ModelInit<T, K>): T;
|
|
343
|
-
copyOf(src: T, mutator: (draft: MutableModel<T, K>) => void): T;
|
|
345
|
+
export type PersistentModelConstructor<T extends PersistentModel> = {
|
|
346
|
+
new (init: ModelInit<T, PersistentModelMetaData<T>>): T;
|
|
347
|
+
copyOf(
|
|
348
|
+
src: T,
|
|
349
|
+
mutator: (draft: MutableModel<T, PersistentModelMetaData<T>>) => void
|
|
350
|
+
): T;
|
|
344
351
|
};
|
|
345
352
|
|
|
346
353
|
export type TypeConstructorMap = Record<
|
|
347
354
|
string,
|
|
348
|
-
PersistentModelConstructor<any> | NonModelTypeConstructor<
|
|
355
|
+
PersistentModelConstructor<any> | NonModelTypeConstructor<unknown>
|
|
349
356
|
>;
|
|
350
357
|
|
|
358
|
+
export declare const __identifierBrand__: unique symbol;
|
|
359
|
+
export type IdentifierBrand<T, K> = T & { [__identifierBrand__]: K };
|
|
360
|
+
|
|
361
|
+
// datastore generates a uuid for you
|
|
362
|
+
export type ManagedIdentifier<T, F extends keyof T> = IdentifierBrand<
|
|
363
|
+
{ field: F extends string ? F : never; type: T },
|
|
364
|
+
'ManagedIdentifier'
|
|
365
|
+
>;
|
|
366
|
+
|
|
367
|
+
// you can provide a value, if not, datastore generates a uuid for you
|
|
368
|
+
export type OptionallyManagedIdentifier<T, F extends keyof T> = IdentifierBrand<
|
|
369
|
+
{ field: F extends string ? F : never; type: T },
|
|
370
|
+
'OptionallyManagedIdentifier'
|
|
371
|
+
>;
|
|
372
|
+
|
|
373
|
+
// You provide the values
|
|
374
|
+
export type CompositeIdentifier<T, K extends Array<keyof T>> = IdentifierBrand<
|
|
375
|
+
{ fields: K; type: T },
|
|
376
|
+
'CompositeIdentifier'
|
|
377
|
+
>;
|
|
378
|
+
|
|
379
|
+
// You provide the value
|
|
380
|
+
export type CustomIdentifier<T, K extends keyof T> = CompositeIdentifier<
|
|
381
|
+
T,
|
|
382
|
+
[K]
|
|
383
|
+
>;
|
|
384
|
+
|
|
385
|
+
export type Identifier<T> =
|
|
386
|
+
| ManagedIdentifier<T, any>
|
|
387
|
+
| OptionallyManagedIdentifier<T, any>
|
|
388
|
+
| CompositeIdentifier<T, any>
|
|
389
|
+
| CustomIdentifier<T, any>;
|
|
390
|
+
|
|
391
|
+
export type IdentifierFields<
|
|
392
|
+
T extends PersistentModel,
|
|
393
|
+
M extends PersistentModelMetaData<T> = never
|
|
394
|
+
> = (MetadataOrDefault<T, M>['identifier'] extends
|
|
395
|
+
| ManagedIdentifier<any, any>
|
|
396
|
+
| OptionallyManagedIdentifier<any, any>
|
|
397
|
+
? MetadataOrDefault<T, M>['identifier']['field']
|
|
398
|
+
: MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<
|
|
399
|
+
T,
|
|
400
|
+
infer B
|
|
401
|
+
>
|
|
402
|
+
? B[number] // B[number]
|
|
403
|
+
: MetadataOrDefault<T, M>['identifier']['field']) &
|
|
404
|
+
string;
|
|
405
|
+
|
|
406
|
+
export type IdentifierFieldsForInit<
|
|
407
|
+
T extends PersistentModel,
|
|
408
|
+
M extends PersistentModelMetaData<T>
|
|
409
|
+
> = MetadataOrDefault<T, M>['identifier'] extends
|
|
410
|
+
| DefaultPersistentModelMetaData
|
|
411
|
+
| ManagedIdentifier<T, any>
|
|
412
|
+
? never
|
|
413
|
+
: MetadataOrDefault<T, M>['identifier'] extends OptionallyManagedIdentifier<
|
|
414
|
+
T,
|
|
415
|
+
any
|
|
416
|
+
>
|
|
417
|
+
? IdentifierFields<T, M>
|
|
418
|
+
: MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any>
|
|
419
|
+
? IdentifierFields<T, M>
|
|
420
|
+
: never;
|
|
421
|
+
|
|
351
422
|
// Instance of model
|
|
352
|
-
export
|
|
353
|
-
|
|
423
|
+
export declare const __modelMeta__: unique symbol;
|
|
424
|
+
|
|
425
|
+
export type PersistentModelMetaData<T> = {
|
|
426
|
+
identifier?: Identifier<T>;
|
|
427
|
+
readOnlyFields?: string;
|
|
354
428
|
};
|
|
355
429
|
|
|
356
|
-
export type
|
|
430
|
+
export type DefaultPersistentModelMetaData = {
|
|
431
|
+
identifier: ManagedIdentifier<{ id: string }, 'id'>;
|
|
432
|
+
readOnlyFields: never;
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
export type MetadataOrDefault<
|
|
436
|
+
T extends PersistentModel,
|
|
437
|
+
_ extends PersistentModelMetaData<T> = never
|
|
438
|
+
> = T extends {
|
|
439
|
+
[__modelMeta__]: PersistentModelMetaData<T>;
|
|
440
|
+
}
|
|
441
|
+
? T[typeof __modelMeta__]
|
|
442
|
+
: DefaultPersistentModelMetaData;
|
|
443
|
+
|
|
444
|
+
export type PersistentModel = Readonly<Record<string, any>>;
|
|
445
|
+
|
|
446
|
+
export type MetadataReadOnlyFields<
|
|
447
|
+
T extends PersistentModel,
|
|
448
|
+
M extends PersistentModelMetaData<T>
|
|
449
|
+
> = Extract<
|
|
450
|
+
MetadataOrDefault<T, M>['readOnlyFields'] | M['readOnlyFields'],
|
|
451
|
+
keyof T
|
|
452
|
+
>;
|
|
453
|
+
|
|
454
|
+
// This type omits the metadata field in the constructor init object
|
|
455
|
+
// This type omits identifier fields in the constructor init object
|
|
456
|
+
// This type omits readOnlyFields in the constructor init object
|
|
457
|
+
// This type requires some identifiers in the constructor init object (e.g. CustomIdentifier)
|
|
458
|
+
// This type makes optional some identifiers in the constructor init object (e.g. OptionallyManagedIdentifier)
|
|
357
459
|
export type ModelInit<
|
|
460
|
+
T extends PersistentModel,
|
|
461
|
+
M extends PersistentModelMetaData<T> = {}
|
|
462
|
+
> = Omit<
|
|
358
463
|
T,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
464
|
+
typeof __modelMeta__ | IdentifierFields<T, M> | MetadataReadOnlyFields<T, M>
|
|
465
|
+
> &
|
|
466
|
+
(MetadataOrDefault<T, M>['identifier'] extends OptionallyManagedIdentifier<
|
|
467
|
+
T,
|
|
468
|
+
any
|
|
469
|
+
>
|
|
470
|
+
? Partial<Pick<T, IdentifierFieldsForInit<T, M>>>
|
|
471
|
+
: Required<Pick<T, IdentifierFieldsForInit<T, M>>>);
|
|
472
|
+
|
|
363
473
|
type DeepWritable<T> = {
|
|
364
474
|
-readonly [P in keyof T]: T[P] extends TypeName<T[P]>
|
|
365
475
|
? T[P]
|
|
@@ -367,22 +477,76 @@ type DeepWritable<T> = {
|
|
|
367
477
|
};
|
|
368
478
|
|
|
369
479
|
export type MutableModel<
|
|
370
|
-
T extends
|
|
371
|
-
|
|
372
|
-
readOnlyFields: 'createdAt' | 'updatedAt';
|
|
373
|
-
}
|
|
480
|
+
T extends PersistentModel,
|
|
481
|
+
M extends PersistentModelMetaData<T> = {}
|
|
374
482
|
// This provides Intellisense with ALL of the properties, regardless of read-only
|
|
375
483
|
// but will throw a linting error if trying to overwrite a read-only property
|
|
376
|
-
> = DeepWritable<
|
|
377
|
-
|
|
484
|
+
> = DeepWritable<
|
|
485
|
+
Omit<T, IdentifierFields<T, M> | MetadataReadOnlyFields<T, M>>
|
|
486
|
+
> &
|
|
487
|
+
Readonly<Pick<T, IdentifierFields<T, M> | MetadataReadOnlyFields<T, M>>>;
|
|
378
488
|
|
|
379
489
|
export type ModelInstanceMetadata = {
|
|
380
|
-
id: string;
|
|
381
490
|
_version: number;
|
|
382
491
|
_lastChangedAt: number;
|
|
383
492
|
_deleted: boolean;
|
|
384
493
|
};
|
|
385
494
|
|
|
495
|
+
export type IdentifierFieldValue<
|
|
496
|
+
T extends PersistentModel,
|
|
497
|
+
M extends PersistentModelMetaData<T>
|
|
498
|
+
> = MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any>
|
|
499
|
+
? MetadataOrDefault<T, M>['identifier']['fields'] extends [any]
|
|
500
|
+
? T[MetadataOrDefault<T, M>['identifier']['fields'][0]]
|
|
501
|
+
: never
|
|
502
|
+
: T[MetadataOrDefault<T, M>['identifier']['field']];
|
|
503
|
+
|
|
504
|
+
export type IdentifierFieldOrIdentifierObject<
|
|
505
|
+
T extends PersistentModel,
|
|
506
|
+
M extends PersistentModelMetaData<T>
|
|
507
|
+
> = Pick<T, IdentifierFields<T, M>> | IdentifierFieldValue<T, M>;
|
|
508
|
+
|
|
509
|
+
export function isIdentifierFieldValue<T extends PersistentModel>(
|
|
510
|
+
obj: any,
|
|
511
|
+
modelDefinition: SchemaModel
|
|
512
|
+
): obj is IdentifierFieldValue<T extends PersistentModel ? T : never, any> {
|
|
513
|
+
const keys = extractPrimaryKeyFieldNames(modelDefinition);
|
|
514
|
+
|
|
515
|
+
if (keys.length === 1) {
|
|
516
|
+
const { type } = modelDefinition?.fields[keys[0]] ?? {};
|
|
517
|
+
|
|
518
|
+
if (isGraphQLScalarType(type)) {
|
|
519
|
+
const jsType = GraphQLScalarType.getJSType(type);
|
|
520
|
+
|
|
521
|
+
return typeof obj === jsType;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function isIdentifierFieldOrObject<T extends PersistentModel>(
|
|
531
|
+
obj: any,
|
|
532
|
+
modelDefinition: SchemaModel
|
|
533
|
+
): obj is IdentifierFieldOrIdentifierObject<T, any> {
|
|
534
|
+
return (
|
|
535
|
+
isIdentifierFieldValue<T>(obj, modelDefinition) ||
|
|
536
|
+
isIdentifierObject<T>(obj, modelDefinition)
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export function isIdentifierObject<T extends PersistentModel>(
|
|
541
|
+
obj: any,
|
|
542
|
+
modelDefinition: SchemaModel
|
|
543
|
+
): obj is IdentifierFields<T extends PersistentModel ? T : never, any> {
|
|
544
|
+
const keys = extractPrimaryKeyFieldNames(modelDefinition);
|
|
545
|
+
|
|
546
|
+
return (
|
|
547
|
+
typeof obj === 'object' && obj && keys.every(k => obj[k] !== undefined)
|
|
548
|
+
);
|
|
549
|
+
}
|
|
386
550
|
//#endregion
|
|
387
551
|
|
|
388
552
|
//#region Subscription messages
|
|
@@ -392,11 +556,17 @@ export enum OpType {
|
|
|
392
556
|
DELETE = 'DELETE',
|
|
393
557
|
}
|
|
394
558
|
|
|
395
|
-
export type SubscriptionMessage<T extends PersistentModel> =
|
|
559
|
+
export type SubscriptionMessage<T extends PersistentModel> = Pick<
|
|
560
|
+
InternalSubscriptionMessage<T>,
|
|
561
|
+
'opType' | 'element' | 'model' | 'condition'
|
|
562
|
+
>;
|
|
563
|
+
|
|
564
|
+
export type InternalSubscriptionMessage<T extends PersistentModel> = {
|
|
396
565
|
opType: OpType;
|
|
397
566
|
element: T;
|
|
398
567
|
model: PersistentModelConstructor<T>;
|
|
399
568
|
condition: PredicatesGroup<T> | null;
|
|
569
|
+
savedElement?: T;
|
|
400
570
|
};
|
|
401
571
|
|
|
402
572
|
export type DataStoreSnapshot<T extends PersistentModel> = {
|
|
@@ -407,15 +577,14 @@ export type DataStoreSnapshot<T extends PersistentModel> = {
|
|
|
407
577
|
|
|
408
578
|
//#region Predicates
|
|
409
579
|
|
|
410
|
-
export type PredicateExpression<
|
|
580
|
+
export type PredicateExpression<
|
|
581
|
+
M extends PersistentModel,
|
|
411
582
|
FT
|
|
412
|
-
> extends keyof MapTypeToOperands<FT>
|
|
583
|
+
> = TypeName<FT> extends keyof MapTypeToOperands<FT>
|
|
413
584
|
? (
|
|
414
585
|
operator: keyof MapTypeToOperands<FT>[TypeName<FT>],
|
|
415
586
|
// make the operand type match the type they're trying to filter on
|
|
416
|
-
operand: MapTypeToOperands<FT>[TypeName<FT>][keyof MapTypeToOperands<
|
|
417
|
-
FT
|
|
418
|
-
>[TypeName<FT>]]
|
|
587
|
+
operand: MapTypeToOperands<FT>[TypeName<FT>][keyof MapTypeToOperands<FT>[TypeName<FT>]]
|
|
419
588
|
) => ModelPredicate<M>
|
|
420
589
|
: never;
|
|
421
590
|
|
|
@@ -483,8 +652,7 @@ export type PredicateGroups<T extends PersistentModel> = {
|
|
|
483
652
|
|
|
484
653
|
export type ModelPredicate<M extends PersistentModel> = {
|
|
485
654
|
[K in keyof M]-?: PredicateExpression<M, NonNullable<M[K]>>;
|
|
486
|
-
} &
|
|
487
|
-
PredicateGroups<M>;
|
|
655
|
+
} & PredicateGroups<M>;
|
|
488
656
|
|
|
489
657
|
export type ProducerModelPredicate<M extends PersistentModel> = (
|
|
490
658
|
condition: ModelPredicate<M>
|
|
@@ -574,9 +742,10 @@ export type SortPredicate<T extends PersistentModel> = {
|
|
|
574
742
|
[K in keyof T]-?: SortPredicateExpression<T, NonNullable<T[K]>>;
|
|
575
743
|
};
|
|
576
744
|
|
|
577
|
-
export type SortPredicateExpression<
|
|
745
|
+
export type SortPredicateExpression<
|
|
746
|
+
M extends PersistentModel,
|
|
578
747
|
FT
|
|
579
|
-
> extends keyof MapTypeToOperands<FT>
|
|
748
|
+
> = TypeName<FT> extends keyof MapTypeToOperands<FT>
|
|
580
749
|
? (sortDirection: keyof typeof SortDirection) => SortPredicate<M>
|
|
581
750
|
: never;
|
|
582
751
|
|
|
@@ -585,9 +754,8 @@ export enum SortDirection {
|
|
|
585
754
|
DESCENDING = 'DESCENDING',
|
|
586
755
|
}
|
|
587
756
|
|
|
588
|
-
export type SortPredicatesGroup<
|
|
589
|
-
T
|
|
590
|
-
> = SortPredicateObject<T>[];
|
|
757
|
+
export type SortPredicatesGroup<T extends PersistentModel> =
|
|
758
|
+
SortPredicateObject<T>[];
|
|
591
759
|
|
|
592
760
|
export type SortPredicateObject<T extends PersistentModel> = {
|
|
593
761
|
field: keyof T;
|
|
@@ -628,7 +796,8 @@ export type RelationType = {
|
|
|
628
796
|
modelName: string;
|
|
629
797
|
relationType: 'HAS_ONE' | 'HAS_MANY' | 'BELONGS_TO';
|
|
630
798
|
targetName?: string;
|
|
631
|
-
|
|
799
|
+
targetNames?: string[];
|
|
800
|
+
associatedWith?: string | string[];
|
|
632
801
|
};
|
|
633
802
|
|
|
634
803
|
export type RelationshipType = {
|
|
@@ -654,7 +823,7 @@ export type DataStoreConfig = {
|
|
|
654
823
|
DataStore?: {
|
|
655
824
|
authModeStrategyType?: AuthModeStrategyType;
|
|
656
825
|
conflictHandler?: ConflictHandler; // default : retry until client wins up to x times
|
|
657
|
-
errorHandler?: (error: SyncError) => void; // default : logger.warn
|
|
826
|
+
errorHandler?: (error: SyncError<PersistentModel>) => void; // default : logger.warn
|
|
658
827
|
maxRecordsToSync?: number; // merge
|
|
659
828
|
syncPageSize?: number;
|
|
660
829
|
fullSyncInterval?: number;
|
|
@@ -664,7 +833,7 @@ export type DataStoreConfig = {
|
|
|
664
833
|
};
|
|
665
834
|
authModeStrategyType?: AuthModeStrategyType;
|
|
666
835
|
conflictHandler?: ConflictHandler; // default : retry until client wins up to x times
|
|
667
|
-
errorHandler?: (error: SyncError) => void; // default : logger.warn
|
|
836
|
+
errorHandler?: (error: SyncError<PersistentModel>) => void; // default : logger.warn
|
|
668
837
|
maxRecordsToSync?: number; // merge
|
|
669
838
|
syncPageSize?: number;
|
|
670
839
|
fullSyncInterval?: number;
|
|
@@ -771,15 +940,33 @@ export type SyncConflict = {
|
|
|
771
940
|
attempts: number;
|
|
772
941
|
};
|
|
773
942
|
|
|
774
|
-
export type SyncError = {
|
|
943
|
+
export type SyncError<T extends PersistentModel> = {
|
|
775
944
|
message: string;
|
|
776
|
-
errorType:
|
|
777
|
-
errorInfo
|
|
778
|
-
|
|
779
|
-
|
|
945
|
+
errorType: ErrorType;
|
|
946
|
+
errorInfo?: string;
|
|
947
|
+
recoverySuggestion?: string;
|
|
948
|
+
model?: string;
|
|
949
|
+
localModel: T;
|
|
950
|
+
remoteModel: T;
|
|
951
|
+
process: ProcessName;
|
|
780
952
|
operation: string;
|
|
953
|
+
cause?: Error;
|
|
781
954
|
};
|
|
782
955
|
|
|
956
|
+
export type ErrorType =
|
|
957
|
+
| 'ConfigError'
|
|
958
|
+
| 'BadModel'
|
|
959
|
+
| 'BadRecord'
|
|
960
|
+
| 'Unauthorized'
|
|
961
|
+
| 'Transient'
|
|
962
|
+
| 'Unknown';
|
|
963
|
+
|
|
964
|
+
export enum ProcessName {
|
|
965
|
+
'sync' = 'sync',
|
|
966
|
+
'mutate' = 'mutate',
|
|
967
|
+
'subscribe' = 'subscribe',
|
|
968
|
+
}
|
|
969
|
+
|
|
783
970
|
export const DISCARD = Symbol('DISCARD');
|
|
784
971
|
|
|
785
972
|
export type ConflictHandler = (
|
|
@@ -788,7 +975,7 @@ export type ConflictHandler = (
|
|
|
788
975
|
| Promise<PersistentModel | typeof DISCARD>
|
|
789
976
|
| PersistentModel
|
|
790
977
|
| typeof DISCARD;
|
|
791
|
-
export type ErrorHandler = (error: SyncError) => void;
|
|
978
|
+
export type ErrorHandler = (error: SyncError<PersistentModel>) => void;
|
|
792
979
|
|
|
793
980
|
export type DeferredCallbackResolverOptions = {
|
|
794
981
|
callback: () => void;
|
|
@@ -801,3 +988,9 @@ export enum LimitTimerRaceResolvedValues {
|
|
|
801
988
|
TIMER = 'TIMER',
|
|
802
989
|
}
|
|
803
990
|
//#endregion
|
|
991
|
+
|
|
992
|
+
export type AmplifyContext = {
|
|
993
|
+
Auth: typeof Auth;
|
|
994
|
+
API: typeof API;
|
|
995
|
+
Cache: typeof Cache;
|
|
996
|
+
};
|