@aws-amplify/datastore 3.14.5-unstable.2 → 3.14.5
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 +19 -0
- package/build.js +5 -0
- package/dist/aws-amplify-datastore.js +92853 -0
- package/dist/aws-amplify-datastore.js.map +1 -0
- package/dist/aws-amplify-datastore.min.js +65 -0
- package/dist/aws-amplify-datastore.min.js.map +1 -0
- package/index.js +7 -0
- package/lib/authModeStrategies/multiAuthStrategy.js +64 -6
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.js +297 -703
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.js +4 -6
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.js +6 -127
- package/lib/predicates/index.js.map +1 -1
- package/lib/predicates/sort.js +4 -10
- package/lib/predicates/sort.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +381 -138
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js +98 -37
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +67 -16
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js +4 -2
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +420 -272
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js +5 -3
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -2
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/lib/storage/storage.js +143 -72
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.js +55 -6
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.native.js +4 -2
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.js +124 -49
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +74 -8
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +97 -24
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.js +35 -5
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.js +131 -47
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.js +102 -29
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.js +102 -26
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +103 -40
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.js +39 -9
- package/lib/types.js.map +1 -1
- package/lib/util.js +188 -192
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +57 -2
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +8 -59
- package/lib-esm/datastore/datastore.js +234 -642
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/index.d.ts +2 -3
- package/lib-esm/index.js +1 -2
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/predicates/index.d.ts +2 -16
- package/lib-esm/predicates/index.js +7 -128
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/predicates/sort.js +4 -10
- package/lib-esm/predicates/sort.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +1 -2
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +349 -109
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +68 -7
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.d.ts +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +2 -4
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +368 -227
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib-esm/storage/storage.d.ts +6 -7
- package/lib-esm/storage/storage.js +101 -33
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +47 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.js +76 -4
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.js +67 -1
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.js +74 -1
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.js +32 -2
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.js +93 -12
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.js +69 -6
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.js +75 -2
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +1 -1
- package/lib-esm/sync/utils.js +95 -32
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +10 -63
- package/lib-esm/types.js +38 -7
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +6 -39
- package/lib-esm/util.js +171 -171
- package/lib-esm/util.js.map +1 -1
- package/package.json +14 -21
- package/src/authModeStrategies/multiAuthStrategy.ts +2 -2
- package/src/datastore/datastore.ts +206 -699
- package/src/index.ts +0 -4
- package/src/predicates/index.ts +17 -143
- package/src/predicates/sort.ts +2 -8
- package/src/storage/adapter/AsyncStorageAdapter.ts +178 -56
- package/src/storage/adapter/AsyncStorageDatabase.ts +15 -16
- package/src/storage/adapter/InMemoryStore.ts +2 -5
- package/src/storage/adapter/IndexedDBAdapter.ts +191 -166
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -2
- package/src/storage/storage.ts +37 -56
- package/src/sync/datastoreConnectivity.ts +4 -4
- package/src/sync/index.ts +28 -22
- package/src/sync/merger.ts +1 -1
- package/src/sync/outbox.ts +6 -6
- package/src/sync/processors/errorMaps.ts +1 -1
- package/src/sync/processors/mutation.ts +19 -23
- package/src/sync/processors/subscription.ts +16 -20
- package/src/sync/processors/sync.ts +17 -17
- package/src/sync/utils.ts +48 -42
- package/src/types.ts +16 -128
- package/src/util.ts +150 -108
- package/webpack.config.dev.js +6 -0
- package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
- package/lib/authModeStrategies/index.d.ts +0 -2
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -13
- package/lib/datastore/datastore.d.ts +0 -207
- package/lib/index.d.ts +0 -16
- package/lib/predicates/index.d.ts +0 -30
- package/lib/predicates/next.d.ts +0 -301
- package/lib/predicates/next.js +0 -816
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.d.ts +0 -8
- package/lib/ssr/index.d.ts +0 -3
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -42
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -39
- 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 -61
- 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/relationship.d.ts +0 -140
- package/lib/storage/relationship.js +0 -335
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.d.ts +0 -50
- package/lib/sync/datastoreConnectivity.d.ts +0 -16
- 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 -89
- package/lib/sync/merger.d.ts +0 -17
- 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 -58
- package/lib/sync/processors/subscription.d.ts +0 -33
- package/lib/sync/processors/sync.d.ts +0 -28
- package/lib/sync/utils.d.ts +0 -42
- package/lib/types.d.ts +0 -554
- package/lib/util.d.ts +0 -189
- package/lib-esm/predicates/next.d.ts +0 -301
- package/lib-esm/predicates/next.js +0 -812
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/storage/relationship.d.ts +0 -140
- package/lib-esm/storage/relationship.js +0 -333
- package/lib-esm/storage/relationship.js.map +0 -1
- package/src/predicates/next.ts +0 -967
- package/src/storage/relationship.ts +0 -272
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ModelInstanceCreator } from './datastore/datastore';
|
|
2
2
|
import {
|
|
3
|
+
exhaustiveCheck,
|
|
3
4
|
isAWSDate,
|
|
4
5
|
isAWSTime,
|
|
5
6
|
isAWSDateTime,
|
|
@@ -9,27 +10,18 @@ import {
|
|
|
9
10
|
isAWSURL,
|
|
10
11
|
isAWSPhone,
|
|
11
12
|
isAWSIPAddress,
|
|
12
|
-
NAMESPACES,
|
|
13
13
|
extractPrimaryKeyFieldNames,
|
|
14
14
|
} from './util';
|
|
15
15
|
import { PredicateAll } from './predicates';
|
|
16
16
|
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
17
17
|
import { Auth } from '@aws-amplify/auth';
|
|
18
18
|
import { API } from '@aws-amplify/api';
|
|
19
|
-
import
|
|
19
|
+
import Cache from '@aws-amplify/cache';
|
|
20
20
|
import { Adapter } from './storage/adapter';
|
|
21
|
-
import {
|
|
22
|
-
ModelPredicateExtender,
|
|
23
|
-
PredicateInternalsKey,
|
|
24
|
-
ModelPredicate as V5ModelPredicate,
|
|
25
|
-
} from './predicates/next';
|
|
26
|
-
|
|
27
|
-
export type Scalar<T> = T extends Array<infer InnerType> ? InnerType : T;
|
|
28
21
|
|
|
29
22
|
//#region Schema types
|
|
30
23
|
export type Schema = UserSchema & {
|
|
31
24
|
version: string;
|
|
32
|
-
codegenVersion: string;
|
|
33
25
|
};
|
|
34
26
|
export type UserSchema = {
|
|
35
27
|
models: SchemaModels;
|
|
@@ -42,7 +34,6 @@ export type UserSchema = {
|
|
|
42
34
|
export type InternalSchema = {
|
|
43
35
|
namespaces: SchemaNamespaces;
|
|
44
36
|
version: string;
|
|
45
|
-
codegenVersion: string;
|
|
46
37
|
};
|
|
47
38
|
export type SchemaNamespaces = Record<string, SchemaNamespace>;
|
|
48
39
|
export type SchemaNamespace = UserSchema & {
|
|
@@ -77,11 +68,7 @@ type SchemaEnum = {
|
|
|
77
68
|
name: string;
|
|
78
69
|
values: string[];
|
|
79
70
|
};
|
|
80
|
-
|
|
81
|
-
builder: PersistentModelConstructor<T>;
|
|
82
|
-
schema: SchemaModel;
|
|
83
|
-
pkField: string[];
|
|
84
|
-
};
|
|
71
|
+
|
|
85
72
|
export type ModelAssociation = AssociatedWith | TargetNameAssociation;
|
|
86
73
|
type AssociatedWith = {
|
|
87
74
|
connectionType: 'HAS_MANY' | 'HAS_ONE';
|
|
@@ -106,16 +93,6 @@ export function isTargetNameAssociation(
|
|
|
106
93
|
return obj?.targetName || obj?.targetNames;
|
|
107
94
|
}
|
|
108
95
|
|
|
109
|
-
type FieldAssociation = {
|
|
110
|
-
connectionType: 'HAS_ONE' | 'BELONGS_TO' | 'HAS_MANY';
|
|
111
|
-
};
|
|
112
|
-
export function isFieldAssociation(
|
|
113
|
-
obj: any,
|
|
114
|
-
fieldName: string
|
|
115
|
-
): obj is FieldAssociation {
|
|
116
|
-
return obj?.fields[fieldName]?.association?.connectionType;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
96
|
export type ModelAttributes = ModelAttribute[];
|
|
120
97
|
export type ModelAttribute = { type: string; properties?: Record<string, any> };
|
|
121
98
|
|
|
@@ -249,7 +226,7 @@ export namespace GraphQLScalarType {
|
|
|
249
226
|
typeof GraphQLScalarType,
|
|
250
227
|
'getJSType' | 'getValidationFunction'
|
|
251
228
|
>
|
|
252
|
-
) {
|
|
229
|
+
): 'string' | 'number' | 'boolean' | 'object' {
|
|
253
230
|
switch (scalar) {
|
|
254
231
|
case 'Boolean':
|
|
255
232
|
return 'boolean';
|
|
@@ -270,7 +247,7 @@ export namespace GraphQLScalarType {
|
|
|
270
247
|
case 'AWSJSON':
|
|
271
248
|
return 'object';
|
|
272
249
|
default:
|
|
273
|
-
|
|
250
|
+
exhaustiveCheck(scalar as never);
|
|
274
251
|
}
|
|
275
252
|
}
|
|
276
253
|
|
|
@@ -279,7 +256,7 @@ export namespace GraphQLScalarType {
|
|
|
279
256
|
typeof GraphQLScalarType,
|
|
280
257
|
'getJSType' | 'getValidationFunction'
|
|
281
258
|
>
|
|
282
|
-
): ((val: string
|
|
259
|
+
): ((val: string | number) => boolean) | undefined {
|
|
283
260
|
switch (scalar) {
|
|
284
261
|
case 'AWSDate':
|
|
285
262
|
return isAWSDate;
|
|
@@ -324,13 +301,8 @@ export function isGraphQLScalarType(
|
|
|
324
301
|
return obj && GraphQLScalarType[obj] !== undefined;
|
|
325
302
|
}
|
|
326
303
|
|
|
327
|
-
export type ModelFieldType = {
|
|
328
|
-
|
|
329
|
-
modelConstructor?: ModelMeta<PersistentModel>;
|
|
330
|
-
};
|
|
331
|
-
export function isModelFieldType<T extends PersistentModel>(
|
|
332
|
-
obj: any
|
|
333
|
-
): obj is ModelFieldType {
|
|
304
|
+
export type ModelFieldType = { model: string };
|
|
305
|
+
export function isModelFieldType(obj: any): obj is ModelFieldType {
|
|
334
306
|
const modelField: keyof ModelFieldType = 'model';
|
|
335
307
|
if (obj && obj[modelField]) return true;
|
|
336
308
|
|
|
@@ -386,24 +358,6 @@ export type PersistentModelConstructor<T extends PersistentModel> = {
|
|
|
386
358
|
): T;
|
|
387
359
|
};
|
|
388
360
|
|
|
389
|
-
/**
|
|
390
|
-
* @private
|
|
391
|
-
* Internal use of Amplify only.
|
|
392
|
-
*
|
|
393
|
-
* Indicates to use lazy models or eager models.
|
|
394
|
-
*/
|
|
395
|
-
export declare class LazyLoadingDisabled {
|
|
396
|
-
disabled: true;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* @private
|
|
401
|
-
* Internal use of Amplify only.
|
|
402
|
-
*
|
|
403
|
-
* Indicates to use lazy models or eager models.
|
|
404
|
-
*/
|
|
405
|
-
export declare class LazyLoading {}
|
|
406
|
-
|
|
407
361
|
export type TypeConstructorMap = Record<
|
|
408
362
|
string,
|
|
409
363
|
PersistentModelConstructor<any> | NonModelTypeConstructor<unknown>
|
|
@@ -485,53 +439,6 @@ export type PersistentModelMetaData<T> = {
|
|
|
485
439
|
readOnlyFields?: string;
|
|
486
440
|
};
|
|
487
441
|
|
|
488
|
-
export interface AsyncCollection<T> extends AsyncIterable<T> {
|
|
489
|
-
toArray(options?: { max?: number }): Promise<T[]>;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
export type SettableFieldType<T> = T extends Promise<infer InnerPromiseType>
|
|
493
|
-
? undefined extends InnerPromiseType
|
|
494
|
-
? InnerPromiseType | null
|
|
495
|
-
: InnerPromiseType
|
|
496
|
-
: T extends AsyncCollection<infer InnerCollectionType>
|
|
497
|
-
? InnerCollectionType[] | undefined
|
|
498
|
-
: undefined extends T
|
|
499
|
-
? T | null
|
|
500
|
-
: T;
|
|
501
|
-
|
|
502
|
-
export type PredicateFieldType<T> = NonNullable<
|
|
503
|
-
Scalar<
|
|
504
|
-
T extends Promise<infer InnerPromiseType>
|
|
505
|
-
? InnerPromiseType
|
|
506
|
-
: T extends AsyncCollection<infer InnerCollectionType>
|
|
507
|
-
? InnerCollectionType
|
|
508
|
-
: T
|
|
509
|
-
>
|
|
510
|
-
>;
|
|
511
|
-
|
|
512
|
-
type KeysOfType<T, FilterType> = {
|
|
513
|
-
[P in keyof T]: T[P] extends FilterType ? P : never;
|
|
514
|
-
}[keyof T];
|
|
515
|
-
|
|
516
|
-
type KeysOfSuperType<T, FilterType> = {
|
|
517
|
-
[P in keyof T]: FilterType extends T[P] ? P : never;
|
|
518
|
-
}[keyof T];
|
|
519
|
-
|
|
520
|
-
type OptionalRelativesOf<T> =
|
|
521
|
-
| KeysOfType<T, AsyncCollection<any>>
|
|
522
|
-
| KeysOfSuperType<T, Promise<undefined>>;
|
|
523
|
-
|
|
524
|
-
type OmitOptionalRelatives<T> = Omit<T, OptionalRelativesOf<T>>;
|
|
525
|
-
type PickOptionalRelatives<T> = Pick<T, OptionalRelativesOf<T>>;
|
|
526
|
-
type OmitOptionalFields<T> = Omit<
|
|
527
|
-
T,
|
|
528
|
-
KeysOfSuperType<T, undefined> | OptionalRelativesOf<T>
|
|
529
|
-
>;
|
|
530
|
-
type PickOptionalFields<T> = Pick<
|
|
531
|
-
T,
|
|
532
|
-
KeysOfSuperType<T, undefined> | OptionalRelativesOf<T>
|
|
533
|
-
>;
|
|
534
|
-
|
|
535
442
|
export type DefaultPersistentModelMetaData = {
|
|
536
443
|
identifier: ManagedIdentifier<{ id: string }, 'id'>;
|
|
537
444
|
readOnlyFields: never;
|
|
@@ -561,7 +468,7 @@ export type MetadataReadOnlyFields<
|
|
|
561
468
|
// This type omits readOnlyFields in the constructor init object
|
|
562
469
|
// This type requires some identifiers in the constructor init object (e.g. CustomIdentifier)
|
|
563
470
|
// This type makes optional some identifiers in the constructor init object (e.g. OptionallyManagedIdentifier)
|
|
564
|
-
export type
|
|
471
|
+
export type ModelInit<
|
|
565
472
|
T extends PersistentModel,
|
|
566
473
|
M extends PersistentModelMetaData<T> = {}
|
|
567
474
|
> = Omit<
|
|
@@ -575,26 +482,9 @@ export type ModelInitBase<
|
|
|
575
482
|
? Partial<Pick<T, IdentifierFieldsForInit<T, M>>>
|
|
576
483
|
: Required<Pick<T, IdentifierFieldsForInit<T, M>>>);
|
|
577
484
|
|
|
578
|
-
export type ModelInit<
|
|
579
|
-
T extends PersistentModel,
|
|
580
|
-
M extends PersistentModelMetaData<T> = {}
|
|
581
|
-
> = {
|
|
582
|
-
[P in keyof OmitOptionalRelatives<ModelInitBase<T, M>>]: SettableFieldType<
|
|
583
|
-
ModelInitBase<T, M>[P]
|
|
584
|
-
>;
|
|
585
|
-
} & {
|
|
586
|
-
[P in keyof PickOptionalRelatives<ModelInitBase<T, M>>]+?: SettableFieldType<
|
|
587
|
-
ModelInitBase<T, M>[P]
|
|
588
|
-
>;
|
|
589
|
-
};
|
|
590
|
-
|
|
591
485
|
type DeepWritable<T> = {
|
|
592
486
|
-readonly [P in keyof T]: T[P] extends TypeName<T[P]>
|
|
593
487
|
? T[P]
|
|
594
|
-
: T[P] extends Promise<infer InnerPromiseType>
|
|
595
|
-
? InnerPromiseType
|
|
596
|
-
: T[P] extends AsyncCollection<infer InnerCollectionType>
|
|
597
|
-
? InnerCollectionType[] | undefined
|
|
598
488
|
: DeepWritable<T[P]>;
|
|
599
489
|
};
|
|
600
490
|
|
|
@@ -863,10 +753,10 @@ export type SystemComponent = {
|
|
|
863
753
|
namespaceResolver: NamespaceResolver,
|
|
864
754
|
modelInstanceCreator: ModelInstanceCreator,
|
|
865
755
|
getModelConstructorByModelName: (
|
|
866
|
-
namsespaceName:
|
|
756
|
+
namsespaceName: string,
|
|
867
757
|
modelName: string
|
|
868
758
|
) => PersistentModelConstructor<any>,
|
|
869
|
-
appId
|
|
759
|
+
appId: string
|
|
870
760
|
): Promise<void>;
|
|
871
761
|
};
|
|
872
762
|
|
|
@@ -1000,18 +890,16 @@ syncExpressions: [
|
|
|
1000
890
|
}),
|
|
1001
891
|
]
|
|
1002
892
|
*/
|
|
1003
|
-
|
|
1004
893
|
type Option0 = [];
|
|
1005
|
-
type Option1<T extends PersistentModel> = [
|
|
894
|
+
type Option1<T extends PersistentModel> = [ModelPredicate<T> | undefined];
|
|
1006
895
|
type Option<T extends PersistentModel> = Option0 | Option1<T>;
|
|
1007
896
|
|
|
1008
897
|
type Lookup<T extends PersistentModel> = {
|
|
1009
898
|
0:
|
|
1010
|
-
|
|
|
1011
|
-
| Promise<
|
|
1012
|
-
| typeof PredicateAll
|
|
1013
|
-
|
|
1014
|
-
1: PredicateInternalsKey | undefined;
|
|
899
|
+
| ProducerModelPredicate<T>
|
|
900
|
+
| Promise<ProducerModelPredicate<T>>
|
|
901
|
+
| typeof PredicateAll;
|
|
902
|
+
1: ModelPredicate<T> | undefined;
|
|
1015
903
|
};
|
|
1016
904
|
|
|
1017
905
|
type ConditionProducer<T extends PersistentModel, A extends Option<T>> = (
|
package/src/util.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
AllOperators,
|
|
8
8
|
isPredicateGroup,
|
|
9
9
|
isPredicateObj,
|
|
10
|
+
ModelInstanceMetadata,
|
|
10
11
|
PersistentModel,
|
|
11
12
|
PersistentModelConstructor,
|
|
12
13
|
PredicateGroups,
|
|
@@ -23,7 +24,6 @@ import {
|
|
|
23
24
|
isModelAttributePrimaryKey,
|
|
24
25
|
isModelAttributeCompositeKey,
|
|
25
26
|
NonModelTypeConstructor,
|
|
26
|
-
PaginationInput,
|
|
27
27
|
DeferredCallbackResolverOptions,
|
|
28
28
|
LimitTimerRaceResolvedValues,
|
|
29
29
|
SchemaModel,
|
|
@@ -32,7 +32,6 @@ import {
|
|
|
32
32
|
ModelAssociation,
|
|
33
33
|
} from './types';
|
|
34
34
|
import { WordArray } from 'amazon-cognito-identity-js';
|
|
35
|
-
import { ModelSortPredicateCreator } from './predicates';
|
|
36
35
|
|
|
37
36
|
export const ID = 'id';
|
|
38
37
|
|
|
@@ -111,7 +110,7 @@ export const validatePredicate = <T extends PersistentModel>(
|
|
|
111
110
|
filterType = 'some';
|
|
112
111
|
break;
|
|
113
112
|
default:
|
|
114
|
-
|
|
113
|
+
exhaustiveCheck(groupType);
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
const result: boolean = predicatesOrGroups[filterType](predicateOrGroup => {
|
|
@@ -170,6 +169,7 @@ export const validatePredicateField = <T>(
|
|
|
170
169
|
(<string>(<unknown>value)).indexOf(<string>(<unknown>operand)) === -1
|
|
171
170
|
);
|
|
172
171
|
default:
|
|
172
|
+
exhaustiveCheck(operator, false);
|
|
173
173
|
return false;
|
|
174
174
|
}
|
|
175
175
|
};
|
|
@@ -202,22 +202,155 @@ export const traverseModel = <T extends PersistentModel>(
|
|
|
202
202
|
namespace: SchemaNamespace,
|
|
203
203
|
modelInstanceCreator: ModelInstanceCreator,
|
|
204
204
|
getModelConstructorByModelName: (
|
|
205
|
-
namsespaceName:
|
|
205
|
+
namsespaceName: string,
|
|
206
206
|
modelName: string
|
|
207
207
|
) => PersistentModelConstructor<any>
|
|
208
208
|
) => {
|
|
209
|
+
const relationships = namespace.relationships;
|
|
210
|
+
|
|
209
211
|
const modelConstructor = getModelConstructorByModelName(
|
|
210
|
-
namespace.name
|
|
212
|
+
namespace.name,
|
|
211
213
|
srcModelName
|
|
212
214
|
);
|
|
213
215
|
|
|
216
|
+
const relation = relationships[srcModelName];
|
|
217
|
+
|
|
214
218
|
const result: {
|
|
215
219
|
modelName: string;
|
|
216
220
|
item: T;
|
|
217
221
|
instance: T;
|
|
218
222
|
}[] = [];
|
|
219
223
|
|
|
220
|
-
const newInstance = modelConstructor.copyOf(instance,
|
|
224
|
+
const newInstance = modelConstructor.copyOf(instance, draftInstance => {
|
|
225
|
+
relation.relationTypes.forEach((rItem: RelationType) => {
|
|
226
|
+
const modelConstructor = getModelConstructorByModelName(
|
|
227
|
+
namespace.name,
|
|
228
|
+
rItem.modelName
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
switch (rItem.relationType) {
|
|
232
|
+
case 'HAS_ONE':
|
|
233
|
+
if (instance[rItem.fieldName]) {
|
|
234
|
+
let modelInstance: T;
|
|
235
|
+
try {
|
|
236
|
+
modelInstance = modelInstanceCreator(
|
|
237
|
+
modelConstructor,
|
|
238
|
+
instance[rItem.fieldName]
|
|
239
|
+
);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
// Do nothing
|
|
242
|
+
console.log(error);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
result.push({
|
|
246
|
+
modelName: rItem.modelName,
|
|
247
|
+
item: instance[rItem.fieldName],
|
|
248
|
+
instance: modelInstance,
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const targetNames: string[] | undefined =
|
|
252
|
+
extractTargetNamesFromSrc(rItem);
|
|
253
|
+
|
|
254
|
+
// `targetName` will be defined for Has One if feature flag
|
|
255
|
+
// https://docs.amplify.aws/cli/reference/feature-flags/#useAppsyncModelgenPlugin
|
|
256
|
+
// is true (default as of 5/7/21)
|
|
257
|
+
// Making this conditional for backward-compatibility
|
|
258
|
+
if (targetNames) {
|
|
259
|
+
targetNames.forEach((targetName, idx) => {
|
|
260
|
+
// Get the connected record
|
|
261
|
+
const relatedRecordInProxy = <PersistentModel>(
|
|
262
|
+
draftInstance[rItem.fieldName]
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
// Previously, we used the hardcoded 'id' as they key,
|
|
266
|
+
// now we need the value of the key to get the PK (and SK)
|
|
267
|
+
// values from the related record
|
|
268
|
+
|
|
269
|
+
const { primaryKey } = namespace.keys[modelConstructor.name];
|
|
270
|
+
const keyField = primaryKey && primaryKey[idx];
|
|
271
|
+
|
|
272
|
+
// Get the value
|
|
273
|
+
const relatedRecordInProxyPkValue =
|
|
274
|
+
relatedRecordInProxy[keyField];
|
|
275
|
+
|
|
276
|
+
// Set the targetName value
|
|
277
|
+
(<any>draftInstance)[targetName] = relatedRecordInProxyPkValue;
|
|
278
|
+
});
|
|
279
|
+
// Delete the instance from the proxy
|
|
280
|
+
delete (<any>draftInstance)[rItem.fieldName];
|
|
281
|
+
} else {
|
|
282
|
+
(<any>draftInstance)[rItem.fieldName] = (<PersistentModel>(
|
|
283
|
+
draftInstance[rItem.fieldName]
|
|
284
|
+
)).id;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
break;
|
|
289
|
+
case 'BELONGS_TO':
|
|
290
|
+
if (instance[rItem.fieldName]) {
|
|
291
|
+
let modelInstance: T;
|
|
292
|
+
try {
|
|
293
|
+
modelInstance = modelInstanceCreator(
|
|
294
|
+
modelConstructor,
|
|
295
|
+
instance[rItem.fieldName]
|
|
296
|
+
);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
// Do nothing
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const isDeleted = (<ModelInstanceMetadata>(
|
|
302
|
+
draftInstance[rItem.fieldName]
|
|
303
|
+
))._deleted;
|
|
304
|
+
|
|
305
|
+
if (!isDeleted) {
|
|
306
|
+
result.push({
|
|
307
|
+
modelName: rItem.modelName,
|
|
308
|
+
item: instance[rItem.fieldName],
|
|
309
|
+
instance: modelInstance,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (draftInstance[rItem.fieldName]) {
|
|
315
|
+
const targetNames: string[] | undefined =
|
|
316
|
+
extractTargetNamesFromSrc(rItem);
|
|
317
|
+
|
|
318
|
+
if (targetNames) {
|
|
319
|
+
targetNames.forEach((targetName, idx) => {
|
|
320
|
+
// Get the connected record
|
|
321
|
+
const relatedRecordInProxy = <PersistentModel>(
|
|
322
|
+
draftInstance[rItem.fieldName]
|
|
323
|
+
);
|
|
324
|
+
// Previously, we used the hardcoded `id` for the key.
|
|
325
|
+
// Now, we need the value of the key to get the PK (and SK)
|
|
326
|
+
// values from the related record
|
|
327
|
+
const { primaryKey } = namespace.keys[modelConstructor.name];
|
|
328
|
+
|
|
329
|
+
// fall back to ID if
|
|
330
|
+
const keyField = primaryKey && primaryKey[idx];
|
|
331
|
+
|
|
332
|
+
// Get the value
|
|
333
|
+
const relatedRecordInProxyPkValue =
|
|
334
|
+
relatedRecordInProxy[keyField];
|
|
335
|
+
|
|
336
|
+
// Set the targetName value
|
|
337
|
+
(<any>draftInstance)[targetName] = relatedRecordInProxyPkValue;
|
|
338
|
+
});
|
|
339
|
+
// Delete the instance from the proxy
|
|
340
|
+
delete (<any>draftInstance)[rItem.fieldName];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
break;
|
|
345
|
+
case 'HAS_MANY':
|
|
346
|
+
// Intentionally blank
|
|
347
|
+
break;
|
|
348
|
+
default:
|
|
349
|
+
exhaustiveCheck(rItem.relationType);
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
});
|
|
221
354
|
|
|
222
355
|
result.unshift({
|
|
223
356
|
modelName: srcModelName,
|
|
@@ -228,7 +361,7 @@ export const traverseModel = <T extends PersistentModel>(
|
|
|
228
361
|
if (!topologicallySortedModels.has(namespace)) {
|
|
229
362
|
topologicallySortedModels.set(
|
|
230
363
|
namespace,
|
|
231
|
-
Array.from(namespace.modelTopologicalOrdering
|
|
364
|
+
Array.from(namespace.modelTopologicalOrdering.keys())
|
|
232
365
|
);
|
|
233
366
|
}
|
|
234
367
|
|
|
@@ -236,7 +369,7 @@ export const traverseModel = <T extends PersistentModel>(
|
|
|
236
369
|
|
|
237
370
|
result.sort((a, b) => {
|
|
238
371
|
return (
|
|
239
|
-
sortedModels
|
|
372
|
+
sortedModels.indexOf(a.modelName) - sortedModels.indexOf(b.modelName)
|
|
240
373
|
);
|
|
241
374
|
});
|
|
242
375
|
|
|
@@ -485,8 +618,8 @@ export function valuesEqual(
|
|
|
485
618
|
}
|
|
486
619
|
|
|
487
620
|
if (a instanceof Map && b instanceof Map) {
|
|
488
|
-
a =
|
|
489
|
-
b =
|
|
621
|
+
a = Object.fromEntries(a);
|
|
622
|
+
b = Object.fromEntries(b);
|
|
490
623
|
}
|
|
491
624
|
|
|
492
625
|
const aKeys = Object.keys(a);
|
|
@@ -514,97 +647,6 @@ export function valuesEqual(
|
|
|
514
647
|
return true;
|
|
515
648
|
}
|
|
516
649
|
|
|
517
|
-
/**
|
|
518
|
-
* Statelessly extracts the specified page from an array.
|
|
519
|
-
*
|
|
520
|
-
* @param records - The source array to extract a page from.
|
|
521
|
-
* @param pagination - A definition of the page to extract.
|
|
522
|
-
* @returns This items from `records` matching the `pagination` definition.
|
|
523
|
-
*/
|
|
524
|
-
export function inMemoryPagination<T extends PersistentModel>(
|
|
525
|
-
records: T[],
|
|
526
|
-
pagination?: PaginationInput<T>
|
|
527
|
-
): T[] {
|
|
528
|
-
if (pagination && records.length > 1) {
|
|
529
|
-
if (pagination.sort) {
|
|
530
|
-
const sortPredicates = ModelSortPredicateCreator.getPredicates(
|
|
531
|
-
pagination.sort
|
|
532
|
-
);
|
|
533
|
-
|
|
534
|
-
if (sortPredicates.length) {
|
|
535
|
-
const compareFn = sortCompareFunction(sortPredicates);
|
|
536
|
-
records.sort(compareFn);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
const { page = 0, limit = 0 } = pagination;
|
|
540
|
-
const start = Math.max(0, page * limit) || 0;
|
|
541
|
-
|
|
542
|
-
const end = limit > 0 ? start + limit : records.length;
|
|
543
|
-
|
|
544
|
-
return records.slice(start, end);
|
|
545
|
-
}
|
|
546
|
-
return records;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* An `aysnc` implementation of `Array.some()`. Returns as soon as a match is found.
|
|
551
|
-
* @param items The items to check.
|
|
552
|
-
* @param matches The async matcher function, expected to
|
|
553
|
-
* return Promise<boolean>: `true` for a matching item, `false` otherwise.
|
|
554
|
-
* @returns A `Promise<boolean>`, `true` if "some" items match; `false` otherwise.
|
|
555
|
-
*/
|
|
556
|
-
export async function asyncSome(
|
|
557
|
-
items: Record<string, any>[],
|
|
558
|
-
matches: (item: Record<string, any>) => Promise<boolean>
|
|
559
|
-
): Promise<boolean> {
|
|
560
|
-
for (const item of items) {
|
|
561
|
-
if (await matches(item)) {
|
|
562
|
-
return true;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return false;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* An `aysnc` implementation of `Array.every()`. Returns as soon as a non-match is found.
|
|
570
|
-
* @param items The items to check.
|
|
571
|
-
* @param matches The async matcher function, expected to
|
|
572
|
-
* return Promise<boolean>: `true` for a matching item, `false` otherwise.
|
|
573
|
-
* @returns A `Promise<boolean>`, `true` if every item matches; `false` otherwise.
|
|
574
|
-
*/
|
|
575
|
-
export async function asyncEvery(
|
|
576
|
-
items: Record<string, any>[],
|
|
577
|
-
matches: (item: Record<string, any>) => Promise<boolean>
|
|
578
|
-
): Promise<boolean> {
|
|
579
|
-
for (const item of items) {
|
|
580
|
-
if (!(await matches(item))) {
|
|
581
|
-
return false;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
return true;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
/**
|
|
588
|
-
* An `async` implementation of `Array.filter()`. Returns after all items have been filtered.
|
|
589
|
-
* TODO: Return AsyncIterable.
|
|
590
|
-
* @param items The items to filter.
|
|
591
|
-
* @param matches The `async` matcher function, expected to
|
|
592
|
-
* return Promise<boolean>: `true` for a matching item, `false` otherwise.
|
|
593
|
-
* @returns A `Promise<T>` of matching items.
|
|
594
|
-
*/
|
|
595
|
-
export async function asyncFilter<T>(
|
|
596
|
-
items: T[],
|
|
597
|
-
matches: (item: T) => Promise<boolean>
|
|
598
|
-
): Promise<T[]> {
|
|
599
|
-
const results: T[] = [];
|
|
600
|
-
for (const item of items) {
|
|
601
|
-
if (await matches(item)) {
|
|
602
|
-
results.push(item);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
return results;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
650
|
export const isAWSDate = (val: string): boolean => {
|
|
609
651
|
return !!/^\d{4}-\d{2}-\d{2}(Z|[+-]\d{2}:\d{2}($|:\d{2}))?$/.exec(val);
|
|
610
652
|
};
|
|
@@ -719,7 +761,7 @@ export class DeferredCallbackResolver {
|
|
|
719
761
|
this.raceInFlight = false;
|
|
720
762
|
this.limitPromise = new DeferredPromise();
|
|
721
763
|
|
|
722
|
-
return winner
|
|
764
|
+
return winner;
|
|
723
765
|
}
|
|
724
766
|
}
|
|
725
767
|
|
|
@@ -769,7 +811,7 @@ export function mergePatches<T>(
|
|
|
769
811
|
patches = p;
|
|
770
812
|
}
|
|
771
813
|
);
|
|
772
|
-
return patches
|
|
814
|
+
return patches;
|
|
773
815
|
}
|
|
774
816
|
|
|
775
817
|
export const getStorename = (namespace: string, modelName: string) => {
|
|
@@ -945,14 +987,14 @@ export const establishRelationAndKeys = (
|
|
|
945
987
|
typeof fieldAttribute.type === 'object' &&
|
|
946
988
|
'model' in fieldAttribute.type
|
|
947
989
|
) {
|
|
948
|
-
const connectionType = fieldAttribute.association
|
|
990
|
+
const connectionType = fieldAttribute.association.connectionType;
|
|
949
991
|
relationship[mKey].relationTypes.push({
|
|
950
992
|
fieldName: fieldAttribute.name,
|
|
951
993
|
modelName: fieldAttribute.type.model,
|
|
952
994
|
relationType: connectionType,
|
|
953
|
-
targetName: fieldAttribute.association
|
|
954
|
-
targetNames: fieldAttribute.association
|
|
955
|
-
associatedWith: fieldAttribute.association
|
|
995
|
+
targetName: fieldAttribute.association['targetName'],
|
|
996
|
+
targetNames: fieldAttribute.association['targetNames'],
|
|
997
|
+
associatedWith: fieldAttribute.association['associatedWith'],
|
|
956
998
|
});
|
|
957
999
|
|
|
958
1000
|
if (connectionType === 'BELONGS_TO') {
|
|
@@ -1088,7 +1130,7 @@ export const getIndexKeys = (
|
|
|
1088
1130
|
namespace: SchemaNamespace,
|
|
1089
1131
|
modelName: string
|
|
1090
1132
|
): string[] => {
|
|
1091
|
-
const keyPath = namespace?.keys
|
|
1133
|
+
const keyPath = namespace?.keys[modelName]?.primaryKey;
|
|
1092
1134
|
|
|
1093
1135
|
if (keyPath) {
|
|
1094
1136
|
return keyPath;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AuthModeStrategy, AmplifyContext } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Returns an array of auth modes to try based on the schema, model, and
|
|
4
|
-
* authenticated user (or lack thereof). Rules are sourced from `getAuthRules`
|
|
5
|
-
* and returned in the order they ought to be attempted.
|
|
6
|
-
*
|
|
7
|
-
* @see sortAuthRulesWithPriority
|
|
8
|
-
* @see getAuthRules
|
|
9
|
-
*
|
|
10
|
-
* @param param0 The `{schema, modelName}` to inspect.
|
|
11
|
-
* @returns A sorted array of auth modes to attempt.
|
|
12
|
-
*/
|
|
13
|
-
export declare const multiAuthStrategy: (amplifyContext: AmplifyContext) => AuthModeStrategy;
|