@aws-amplify/datastore 3.12.6-next.13 → 3.12.6-next.32
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 +58 -0
- package/lib/authModeStrategies/multiAuthStrategy.js +17 -64
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.js +682 -469
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.js +12 -2
- package/lib/predicates/index.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +393 -298
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js +97 -122
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +16 -67
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js +2 -4
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +497 -404
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js +3 -5
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +2 -4
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/lib/storage/storage.js +129 -151
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.js +13 -17
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.native.js +2 -4
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.js +544 -488
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +21 -80
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +95 -162
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.js +4 -34
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.js +285 -312
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.js +218 -259
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.js +141 -212
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +50 -61
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.js +13 -39
- package/lib/types.js.map +1 -1
- package/lib/util.js +429 -242
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.d.ts +11 -0
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +13 -57
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +107 -17
- package/lib-esm/datastore/datastore.js +649 -433
- 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 +4 -3
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +356 -258
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.d.ts +14 -4
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +67 -92
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js +1 -52
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +26 -4
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +446 -346
- 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 +1 -1
- package/lib-esm/storage/storage.js +94 -113
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -0
- package/lib-esm/sync/datastoreConnectivity.js +10 -11
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.d.ts +31 -5
- package/lib-esm/sync/index.js +525 -466
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.d.ts +9 -3
- package/lib-esm/sync/merger.js +14 -73
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.d.ts +2 -2
- package/lib-esm/sync/outbox.js +79 -146
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.js +1 -31
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.d.ts +2 -0
- package/lib-esm/sync/processors/mutation.js +271 -295
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.d.ts +2 -0
- package/lib-esm/sync/processors/subscription.js +214 -245
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.d.ts +2 -1
- package/lib-esm/sync/processors/sync.js +127 -195
- 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 +45 -57
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +65 -26
- package/lib-esm/types.js +10 -38
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +67 -24
- package/lib-esm/util.js +420 -233
- package/lib-esm/util.js.map +1 -1
- package/package.json +14 -7
- package/src/authModeStrategies/multiAuthStrategy.ts +12 -1
- package/src/datastore/datastore.ts +798 -397
- package/src/predicates/index.ts +32 -10
- package/src/storage/adapter/AsyncStorageAdapter.ts +309 -93
- package/src/storage/adapter/AsyncStorageDatabase.ts +74 -26
- package/src/storage/adapter/IndexedDBAdapter.ts +358 -134
- package/src/storage/adapter/index.ts +1 -1
- package/src/storage/storage.ts +69 -22
- package/src/sync/datastoreConnectivity.ts +6 -0
- package/src/sync/index.ts +521 -412
- package/src/sync/merger.ts +20 -4
- package/src/sync/outbox.ts +22 -9
- package/src/sync/processors/mutation.ts +188 -150
- package/src/sync/processors/subscription.ts +289 -253
- package/src/sync/processors/sync.ts +151 -138
- package/src/sync/utils.ts +67 -12
- package/src/types.ts +182 -30
- package/src/util.ts +505 -176
- package/build.js +0 -5
- package/dist/aws-amplify-datastore.js +0 -98255
- package/dist/aws-amplify-datastore.js.map +0 -1
- package/dist/aws-amplify-datastore.min.js +0 -66
- package/dist/aws-amplify-datastore.min.js.map +0 -1
- package/index.js +0 -7
- package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
- package/lib/authModeStrategies/index.d.ts +0 -2
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -2
- package/lib/datastore/datastore.d.ts +0 -66
- package/lib/index.d.ts +0 -31
- package/lib/predicates/index.d.ts +0 -15
- package/lib/predicates/sort.d.ts +0 -8
- package/lib/ssr/index.d.ts +0 -3
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -40
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -29
- package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
- package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -37
- package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
- package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
- package/lib/storage/adapter/index.d.ts +0 -9
- package/lib/storage/storage.d.ts +0 -49
- package/lib/sync/datastoreConnectivity.d.ts +0 -15
- package/lib/sync/datastoreReachability/index.d.ts +0 -3
- package/lib/sync/datastoreReachability/index.native.d.ts +0 -3
- package/lib/sync/index.d.ts +0 -63
- package/lib/sync/merger.d.ts +0 -11
- package/lib/sync/outbox.d.ts +0 -27
- package/lib/sync/processors/errorMaps.d.ts +0 -17
- package/lib/sync/processors/mutation.d.ts +0 -56
- package/lib/sync/processors/subscription.d.ts +0 -31
- package/lib/sync/processors/sync.d.ts +0 -27
- package/lib/sync/utils.d.ts +0 -41
- package/lib/types.d.ts +0 -462
- package/lib/util.d.ts +0 -113
- package/webpack.config.dev.js +0 -6
package/src/types.ts
CHANGED
|
@@ -10,12 +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';
|
|
16
17
|
import { Auth } from '@aws-amplify/auth';
|
|
17
18
|
import { API } from '@aws-amplify/api';
|
|
18
|
-
import Cache from '@aws-amplify/cache';
|
|
19
|
+
import { BrowserStorageCache as Cache } from '@aws-amplify/cache';
|
|
19
20
|
import { Adapter } from './storage/adapter';
|
|
20
21
|
|
|
21
22
|
//#region Schema types
|
|
@@ -46,9 +47,17 @@ export type SchemaModel = {
|
|
|
46
47
|
fields: ModelFields;
|
|
47
48
|
syncable?: boolean;
|
|
48
49
|
};
|
|
50
|
+
|
|
49
51
|
export function isSchemaModel(obj: any): obj is SchemaModel {
|
|
50
52
|
return obj && (<SchemaModel>obj).pluralName !== undefined;
|
|
51
53
|
}
|
|
54
|
+
|
|
55
|
+
export function isSchemaModelWithAttributes(
|
|
56
|
+
m: SchemaModel | SchemaNonModel
|
|
57
|
+
): m is SchemaModel {
|
|
58
|
+
return isSchemaModel(m) && (m as SchemaModel).attributes !== undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
52
61
|
export type SchemaNonModels = Record<string, SchemaNonModel>;
|
|
53
62
|
export type SchemaNonModel = {
|
|
54
63
|
name: string;
|
|
@@ -63,25 +72,29 @@ type SchemaEnum = {
|
|
|
63
72
|
export type ModelAssociation = AssociatedWith | TargetNameAssociation;
|
|
64
73
|
type AssociatedWith = {
|
|
65
74
|
connectionType: 'HAS_MANY' | 'HAS_ONE';
|
|
66
|
-
associatedWith: string;
|
|
75
|
+
associatedWith: string | string[];
|
|
67
76
|
targetName?: string;
|
|
77
|
+
targetNames?: string[];
|
|
68
78
|
};
|
|
79
|
+
|
|
69
80
|
export function isAssociatedWith(obj: any): obj is AssociatedWith {
|
|
70
81
|
return obj && obj.associatedWith;
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
type TargetNameAssociation = {
|
|
74
85
|
connectionType: 'BELONGS_TO';
|
|
75
|
-
targetName
|
|
86
|
+
targetName?: string;
|
|
87
|
+
targetNames?: string[];
|
|
76
88
|
};
|
|
89
|
+
|
|
77
90
|
export function isTargetNameAssociation(
|
|
78
91
|
obj: any
|
|
79
92
|
): obj is TargetNameAssociation {
|
|
80
|
-
return obj
|
|
93
|
+
return obj?.targetName || obj?.targetNames;
|
|
81
94
|
}
|
|
82
95
|
|
|
83
96
|
export type ModelAttributes = ModelAttribute[];
|
|
84
|
-
type ModelAttribute = { type: string; properties?: Record<string, any> };
|
|
97
|
+
export type ModelAttribute = { type: string; properties?: Record<string, any> };
|
|
85
98
|
|
|
86
99
|
export type ModelAuthRule = {
|
|
87
100
|
allow: string;
|
|
@@ -123,6 +136,7 @@ type ModelAttributeKey = {
|
|
|
123
136
|
type ModelAttributePrimaryKey = {
|
|
124
137
|
type: 'key';
|
|
125
138
|
properties: {
|
|
139
|
+
name: never;
|
|
126
140
|
fields: string[];
|
|
127
141
|
};
|
|
128
142
|
};
|
|
@@ -336,33 +350,138 @@ export type NonModelTypeConstructor<T> = {
|
|
|
336
350
|
};
|
|
337
351
|
|
|
338
352
|
// Class for model
|
|
339
|
-
export type PersistentModelConstructor<
|
|
340
|
-
T
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
new (init: ModelInit<T, K>): T;
|
|
346
|
-
copyOf(src: T, mutator: (draft: MutableModel<T, K>) => void): T;
|
|
353
|
+
export type PersistentModelConstructor<T extends PersistentModel> = {
|
|
354
|
+
new (init: ModelInit<T, PersistentModelMetaData<T>>): T;
|
|
355
|
+
copyOf(
|
|
356
|
+
src: T,
|
|
357
|
+
mutator: (draft: MutableModel<T, PersistentModelMetaData<T>>) => void
|
|
358
|
+
): T;
|
|
347
359
|
};
|
|
348
360
|
|
|
349
361
|
export type TypeConstructorMap = Record<
|
|
350
362
|
string,
|
|
351
|
-
PersistentModelConstructor<any> | NonModelTypeConstructor<
|
|
363
|
+
PersistentModelConstructor<any> | NonModelTypeConstructor<unknown>
|
|
364
|
+
>;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Each identifier type is represented using nominal types, see:
|
|
368
|
+
* https://basarat.gitbook.io/typescript/main-1/nominaltyping
|
|
369
|
+
*/
|
|
370
|
+
export declare const __identifierBrand__: unique symbol;
|
|
371
|
+
export type IdentifierBrand<T, K> = T & { [__identifierBrand__]: K };
|
|
372
|
+
|
|
373
|
+
// datastore generates a uuid for you
|
|
374
|
+
export type ManagedIdentifier<T, F extends keyof T> = IdentifierBrand<
|
|
375
|
+
{ field: F extends string ? F : never; type: T },
|
|
376
|
+
'ManagedIdentifier'
|
|
377
|
+
>;
|
|
378
|
+
|
|
379
|
+
// you can provide a value, if not, datastore generates a uuid for you
|
|
380
|
+
export type OptionallyManagedIdentifier<T, F extends keyof T> = IdentifierBrand<
|
|
381
|
+
{ field: F extends string ? F : never; type: T },
|
|
382
|
+
'OptionallyManagedIdentifier'
|
|
352
383
|
>;
|
|
353
384
|
|
|
385
|
+
// You provide the values
|
|
386
|
+
export type CompositeIdentifier<T, K extends Array<keyof T>> = IdentifierBrand<
|
|
387
|
+
{ fields: K; type: T },
|
|
388
|
+
'CompositeIdentifier'
|
|
389
|
+
>;
|
|
390
|
+
|
|
391
|
+
// You provide the value
|
|
392
|
+
export type CustomIdentifier<T, K extends keyof T> = CompositeIdentifier<
|
|
393
|
+
T,
|
|
394
|
+
[K]
|
|
395
|
+
>;
|
|
396
|
+
|
|
397
|
+
export type Identifier<T> =
|
|
398
|
+
| ManagedIdentifier<T, any>
|
|
399
|
+
| OptionallyManagedIdentifier<T, any>
|
|
400
|
+
| CompositeIdentifier<T, any>
|
|
401
|
+
| CustomIdentifier<T, any>;
|
|
402
|
+
|
|
403
|
+
export type IdentifierFields<
|
|
404
|
+
T extends PersistentModel,
|
|
405
|
+
M extends PersistentModelMetaData<T> = never
|
|
406
|
+
> = (MetadataOrDefault<T, M>['identifier'] extends
|
|
407
|
+
| ManagedIdentifier<any, any>
|
|
408
|
+
| OptionallyManagedIdentifier<any, any>
|
|
409
|
+
? MetadataOrDefault<T, M>['identifier']['field']
|
|
410
|
+
: MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<
|
|
411
|
+
T,
|
|
412
|
+
infer B
|
|
413
|
+
>
|
|
414
|
+
? B[number] // B[number]
|
|
415
|
+
: MetadataOrDefault<T, M>['identifier']['field']) &
|
|
416
|
+
string;
|
|
417
|
+
|
|
418
|
+
export type IdentifierFieldsForInit<
|
|
419
|
+
T extends PersistentModel,
|
|
420
|
+
M extends PersistentModelMetaData<T>
|
|
421
|
+
> = MetadataOrDefault<T, M>['identifier'] extends
|
|
422
|
+
| DefaultPersistentModelMetaData
|
|
423
|
+
| ManagedIdentifier<T, any>
|
|
424
|
+
? never
|
|
425
|
+
: MetadataOrDefault<T, M>['identifier'] extends OptionallyManagedIdentifier<
|
|
426
|
+
T,
|
|
427
|
+
any
|
|
428
|
+
>
|
|
429
|
+
? IdentifierFields<T, M>
|
|
430
|
+
: MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any>
|
|
431
|
+
? IdentifierFields<T, M>
|
|
432
|
+
: never;
|
|
433
|
+
|
|
354
434
|
// Instance of model
|
|
355
|
-
export
|
|
356
|
-
|
|
435
|
+
export declare const __modelMeta__: unique symbol;
|
|
436
|
+
|
|
437
|
+
export type PersistentModelMetaData<T> = {
|
|
438
|
+
identifier?: Identifier<T>;
|
|
439
|
+
readOnlyFields?: string;
|
|
357
440
|
};
|
|
358
441
|
|
|
359
|
-
export type
|
|
442
|
+
export type DefaultPersistentModelMetaData = {
|
|
443
|
+
identifier: ManagedIdentifier<{ id: string }, 'id'>;
|
|
444
|
+
readOnlyFields: never;
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
export type MetadataOrDefault<
|
|
448
|
+
T extends PersistentModel,
|
|
449
|
+
_ extends PersistentModelMetaData<T> = never
|
|
450
|
+
> = T extends {
|
|
451
|
+
[__modelMeta__]: PersistentModelMetaData<T>;
|
|
452
|
+
}
|
|
453
|
+
? T[typeof __modelMeta__]
|
|
454
|
+
: DefaultPersistentModelMetaData;
|
|
455
|
+
|
|
456
|
+
export type PersistentModel = Readonly<Record<string, any>>;
|
|
457
|
+
|
|
458
|
+
export type MetadataReadOnlyFields<
|
|
459
|
+
T extends PersistentModel,
|
|
460
|
+
M extends PersistentModelMetaData<T>
|
|
461
|
+
> = Extract<
|
|
462
|
+
MetadataOrDefault<T, M>['readOnlyFields'] | M['readOnlyFields'],
|
|
463
|
+
keyof T
|
|
464
|
+
>;
|
|
465
|
+
|
|
466
|
+
// This type omits the metadata field in the constructor init object
|
|
467
|
+
// This type omits identifier fields in the constructor init object
|
|
468
|
+
// This type omits readOnlyFields in the constructor init object
|
|
469
|
+
// This type requires some identifiers in the constructor init object (e.g. CustomIdentifier)
|
|
470
|
+
// This type makes optional some identifiers in the constructor init object (e.g. OptionallyManagedIdentifier)
|
|
360
471
|
export type ModelInit<
|
|
472
|
+
T extends PersistentModel,
|
|
473
|
+
M extends PersistentModelMetaData<T> = {}
|
|
474
|
+
> = Omit<
|
|
361
475
|
T,
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
476
|
+
typeof __modelMeta__ | IdentifierFields<T, M> | MetadataReadOnlyFields<T, M>
|
|
477
|
+
> &
|
|
478
|
+
(MetadataOrDefault<T, M>['identifier'] extends OptionallyManagedIdentifier<
|
|
479
|
+
T,
|
|
480
|
+
any
|
|
481
|
+
>
|
|
482
|
+
? Partial<Pick<T, IdentifierFieldsForInit<T, M>>>
|
|
483
|
+
: Required<Pick<T, IdentifierFieldsForInit<T, M>>>);
|
|
484
|
+
|
|
366
485
|
type DeepWritable<T> = {
|
|
367
486
|
-readonly [P in keyof T]: T[P] extends TypeName<T[P]>
|
|
368
487
|
? T[P]
|
|
@@ -370,22 +489,45 @@ type DeepWritable<T> = {
|
|
|
370
489
|
};
|
|
371
490
|
|
|
372
491
|
export type MutableModel<
|
|
373
|
-
T extends
|
|
374
|
-
|
|
375
|
-
readOnlyFields: 'createdAt' | 'updatedAt';
|
|
376
|
-
}
|
|
492
|
+
T extends PersistentModel,
|
|
493
|
+
M extends PersistentModelMetaData<T> = {}
|
|
377
494
|
// This provides Intellisense with ALL of the properties, regardless of read-only
|
|
378
495
|
// but will throw a linting error if trying to overwrite a read-only property
|
|
379
|
-
> = DeepWritable<
|
|
380
|
-
|
|
496
|
+
> = DeepWritable<
|
|
497
|
+
Omit<T, IdentifierFields<T, M> | MetadataReadOnlyFields<T, M>>
|
|
498
|
+
> &
|
|
499
|
+
Readonly<Pick<T, IdentifierFields<T, M> | MetadataReadOnlyFields<T, M>>>;
|
|
381
500
|
|
|
382
501
|
export type ModelInstanceMetadata = {
|
|
383
|
-
id: string;
|
|
384
502
|
_version: number;
|
|
385
503
|
_lastChangedAt: number;
|
|
386
504
|
_deleted: boolean;
|
|
387
505
|
};
|
|
388
506
|
|
|
507
|
+
export type IdentifierFieldValue<
|
|
508
|
+
T extends PersistentModel,
|
|
509
|
+
M extends PersistentModelMetaData<T>
|
|
510
|
+
> = MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any>
|
|
511
|
+
? MetadataOrDefault<T, M>['identifier']['fields'] extends [any]
|
|
512
|
+
? T[MetadataOrDefault<T, M>['identifier']['fields'][0]]
|
|
513
|
+
: never
|
|
514
|
+
: T[MetadataOrDefault<T, M>['identifier']['field']];
|
|
515
|
+
|
|
516
|
+
export type IdentifierFieldOrIdentifierObject<
|
|
517
|
+
T extends PersistentModel,
|
|
518
|
+
M extends PersistentModelMetaData<T>
|
|
519
|
+
> = Pick<T, IdentifierFields<T, M>> | IdentifierFieldValue<T, M>;
|
|
520
|
+
|
|
521
|
+
export function isIdentifierObject<T extends PersistentModel>(
|
|
522
|
+
obj: any,
|
|
523
|
+
modelDefinition: SchemaModel
|
|
524
|
+
): obj is IdentifierFields<T extends PersistentModel ? T : never, any> {
|
|
525
|
+
const keys = extractPrimaryKeyFieldNames(modelDefinition);
|
|
526
|
+
|
|
527
|
+
return (
|
|
528
|
+
typeof obj === 'object' && obj && keys.every(k => obj[k] !== undefined)
|
|
529
|
+
);
|
|
530
|
+
}
|
|
389
531
|
//#endregion
|
|
390
532
|
|
|
391
533
|
//#region Subscription messages
|
|
@@ -635,11 +777,21 @@ export type RelationType = {
|
|
|
635
777
|
modelName: string;
|
|
636
778
|
relationType: 'HAS_ONE' | 'HAS_MANY' | 'BELONGS_TO';
|
|
637
779
|
targetName?: string;
|
|
638
|
-
|
|
780
|
+
targetNames?: string[];
|
|
781
|
+
associatedWith?: string | string[];
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
type IndexOptions = {
|
|
785
|
+
unique?: boolean;
|
|
639
786
|
};
|
|
640
787
|
|
|
788
|
+
export type IndexesType = Array<[string, string[], IndexOptions?]>;
|
|
789
|
+
|
|
641
790
|
export type RelationshipType = {
|
|
642
|
-
[modelName: string]: {
|
|
791
|
+
[modelName: string]: {
|
|
792
|
+
indexes: IndexesType;
|
|
793
|
+
relationTypes: RelationType[];
|
|
794
|
+
};
|
|
643
795
|
};
|
|
644
796
|
|
|
645
797
|
//#endregion
|