@aws-amplify/datastore 3.14.1-unstable.3 → 3.14.1

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.
Files changed (111) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/aws-amplify-datastore.js +2798 -1458
  3. package/dist/aws-amplify-datastore.js.map +1 -1
  4. package/dist/aws-amplify-datastore.min.js +10 -10
  5. package/dist/aws-amplify-datastore.min.js.map +1 -1
  6. package/lib/authModeStrategies/multiAuthStrategy.js +11 -0
  7. package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
  8. package/lib/datastore/datastore.js +524 -323
  9. package/lib/datastore/datastore.js.map +1 -1
  10. package/lib/storage/adapter/IndexedDBAdapter.js +76 -25
  11. package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
  12. package/lib/storage/storage.js +2 -2
  13. package/lib/storage/storage.js.map +1 -1
  14. package/lib/sync/datastoreConnectivity.js +45 -0
  15. package/lib/sync/datastoreConnectivity.js.map +1 -1
  16. package/lib/sync/index.js +518 -395
  17. package/lib/sync/index.js.map +1 -1
  18. package/lib/sync/merger.js +6 -0
  19. package/lib/sync/merger.js.map +1 -1
  20. package/lib/sync/outbox.js +66 -62
  21. package/lib/sync/outbox.js.map +1 -1
  22. package/lib/sync/processors/mutation.js +207 -165
  23. package/lib/sync/processors/mutation.js.map +1 -1
  24. package/lib/sync/processors/subscription.js +210 -175
  25. package/lib/sync/processors/subscription.js.map +1 -1
  26. package/lib/sync/processors/sync.js +95 -72
  27. package/lib/sync/processors/sync.js.map +1 -1
  28. package/lib/sync/utils.js +1 -3
  29. package/lib/sync/utils.js.map +1 -1
  30. package/lib/util.js +89 -0
  31. package/lib/util.js.map +1 -1
  32. package/lib-esm/authModeStrategies/multiAuthStrategy.d.ts +11 -0
  33. package/lib-esm/authModeStrategies/multiAuthStrategy.js +11 -0
  34. package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
  35. package/lib-esm/datastore/datastore.d.ts +95 -2
  36. package/lib-esm/datastore/datastore.js +524 -323
  37. package/lib-esm/datastore/datastore.js.map +1 -1
  38. package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +21 -0
  39. package/lib-esm/storage/adapter/IndexedDBAdapter.js +77 -26
  40. package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
  41. package/lib-esm/storage/storage.js +2 -2
  42. package/lib-esm/storage/storage.js.map +1 -1
  43. package/lib-esm/sync/datastoreConnectivity.d.ts +1 -0
  44. package/lib-esm/sync/datastoreConnectivity.js +45 -0
  45. package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
  46. package/lib-esm/sync/index.d.ts +9 -1
  47. package/lib-esm/sync/index.js +519 -396
  48. package/lib-esm/sync/index.js.map +1 -1
  49. package/lib-esm/sync/merger.d.ts +6 -0
  50. package/lib-esm/sync/merger.js +6 -0
  51. package/lib-esm/sync/merger.js.map +1 -1
  52. package/lib-esm/sync/outbox.js +66 -62
  53. package/lib-esm/sync/outbox.js.map +1 -1
  54. package/lib-esm/sync/processors/mutation.d.ts +2 -0
  55. package/lib-esm/sync/processors/mutation.js +208 -166
  56. package/lib-esm/sync/processors/mutation.js.map +1 -1
  57. package/lib-esm/sync/processors/subscription.d.ts +2 -0
  58. package/lib-esm/sync/processors/subscription.js +211 -176
  59. package/lib-esm/sync/processors/subscription.js.map +1 -1
  60. package/lib-esm/sync/processors/sync.d.ts +2 -0
  61. package/lib-esm/sync/processors/sync.js +96 -73
  62. package/lib-esm/sync/processors/sync.js.map +1 -1
  63. package/lib-esm/sync/utils.js +1 -3
  64. package/lib-esm/sync/utils.js.map +1 -1
  65. package/lib-esm/util.d.ts +11 -0
  66. package/lib-esm/util.js +89 -0
  67. package/lib-esm/util.js.map +1 -1
  68. package/package.json +7 -7
  69. package/src/authModeStrategies/multiAuthStrategy.ts +11 -0
  70. package/src/datastore/datastore.ts +572 -366
  71. package/src/storage/adapter/IndexedDBAdapter.ts +50 -9
  72. package/src/storage/storage.ts +2 -2
  73. package/src/sync/datastoreConnectivity.ts +6 -0
  74. package/src/sync/index.ts +492 -400
  75. package/src/sync/merger.ts +6 -0
  76. package/src/sync/outbox.ts +1 -1
  77. package/src/sync/processors/mutation.ts +139 -104
  78. package/src/sync/processors/subscription.ts +287 -250
  79. package/src/sync/processors/sync.ts +88 -60
  80. package/src/sync/utils.ts +1 -3
  81. package/src/util.ts +92 -2
  82. package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
  83. package/lib/authModeStrategies/index.d.ts +0 -2
  84. package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -2
  85. package/lib/datastore/datastore.d.ts +0 -63
  86. package/lib/index.d.ts +0 -15
  87. package/lib/predicates/index.d.ts +0 -16
  88. package/lib/predicates/sort.d.ts +0 -8
  89. package/lib/ssr/index.d.ts +0 -3
  90. package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -41
  91. package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -39
  92. package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
  93. package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
  94. package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -38
  95. package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
  96. package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
  97. package/lib/storage/adapter/index.d.ts +0 -9
  98. package/lib/storage/storage.d.ts +0 -49
  99. package/lib/sync/datastoreConnectivity.d.ts +0 -15
  100. package/lib/sync/datastoreReachability/index.d.ts +0 -3
  101. package/lib/sync/datastoreReachability/index.native.d.ts +0 -3
  102. package/lib/sync/index.d.ts +0 -81
  103. package/lib/sync/merger.d.ts +0 -11
  104. package/lib/sync/outbox.d.ts +0 -27
  105. package/lib/sync/processors/errorMaps.d.ts +0 -17
  106. package/lib/sync/processors/mutation.d.ts +0 -56
  107. package/lib/sync/processors/subscription.d.ts +0 -31
  108. package/lib/sync/processors/sync.d.ts +0 -26
  109. package/lib/sync/utils.d.ts +0 -42
  110. package/lib/types.d.ts +0 -501
  111. package/lib/util.d.ts +0 -145
package/lib/types.d.ts DELETED
@@ -1,501 +0,0 @@
1
- import { ModelInstanceCreator } from './datastore/datastore';
2
- import { PredicateAll } from './predicates';
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';
7
- import { Adapter } from './storage/adapter';
8
- export declare type Schema = UserSchema & {
9
- version: string;
10
- };
11
- export declare type UserSchema = {
12
- models: SchemaModels;
13
- nonModels?: SchemaNonModels;
14
- relationships?: RelationshipType;
15
- keys?: ModelKeys;
16
- enums: SchemaEnums;
17
- modelTopologicalOrdering?: Map<string, string[]>;
18
- };
19
- export declare type InternalSchema = {
20
- namespaces: SchemaNamespaces;
21
- version: string;
22
- };
23
- export declare type SchemaNamespaces = Record<string, SchemaNamespace>;
24
- export declare type SchemaNamespace = UserSchema & {
25
- name: string;
26
- };
27
- export declare type SchemaModels = Record<string, SchemaModel>;
28
- export declare type SchemaModel = {
29
- name: string;
30
- pluralName: string;
31
- attributes?: ModelAttributes;
32
- fields: ModelFields;
33
- syncable?: boolean;
34
- };
35
- export declare function isSchemaModel(obj: any): obj is SchemaModel;
36
- export declare function isSchemaModelWithAttributes(m: SchemaModel | SchemaNonModel): m is SchemaModel;
37
- export declare type SchemaNonModels = Record<string, SchemaNonModel>;
38
- export declare type SchemaNonModel = {
39
- name: string;
40
- fields: ModelFields;
41
- };
42
- declare type SchemaEnums = Record<string, SchemaEnum>;
43
- declare type SchemaEnum = {
44
- name: string;
45
- values: string[];
46
- };
47
- export declare type ModelAssociation = AssociatedWith | TargetNameAssociation;
48
- declare type AssociatedWith = {
49
- connectionType: 'HAS_MANY' | 'HAS_ONE';
50
- associatedWith: string | string[];
51
- targetName?: string;
52
- targetNames?: string[];
53
- };
54
- export declare function isAssociatedWith(obj: any): obj is AssociatedWith;
55
- declare type TargetNameAssociation = {
56
- connectionType: 'BELONGS_TO';
57
- targetName?: string;
58
- targetNames?: string[];
59
- };
60
- export declare function isTargetNameAssociation(obj: any): obj is TargetNameAssociation;
61
- export declare type ModelAttributes = ModelAttribute[];
62
- export declare type ModelAttribute = {
63
- type: string;
64
- properties?: Record<string, any>;
65
- };
66
- export declare type ModelAuthRule = {
67
- allow: string;
68
- provider?: string;
69
- operations?: string[];
70
- ownerField?: string;
71
- identityClaim?: string;
72
- groups?: string[];
73
- groupClaim?: string;
74
- groupsField?: string;
75
- };
76
- export declare type ModelAttributeAuth = {
77
- type: 'auth';
78
- properties: {
79
- rules: ModelAuthRule[];
80
- };
81
- };
82
- export declare function isModelAttributeAuth(attr: ModelAttribute): attr is ModelAttributeAuth;
83
- declare type ModelAttributeKey = {
84
- type: 'key';
85
- properties: {
86
- name?: string;
87
- fields: string[];
88
- };
89
- };
90
- declare type ModelAttributePrimaryKey = {
91
- type: 'key';
92
- properties: {
93
- name: never;
94
- fields: string[];
95
- };
96
- };
97
- declare type ModelAttributeCompositeKey = {
98
- type: 'key';
99
- properties: {
100
- name: string;
101
- fields: [string, string, string, string?, string?];
102
- };
103
- };
104
- export declare function isModelAttributeKey(attr: ModelAttribute): attr is ModelAttributeKey;
105
- export declare function isModelAttributePrimaryKey(attr: ModelAttribute): attr is ModelAttributePrimaryKey;
106
- export declare function isModelAttributeCompositeKey(attr: ModelAttribute): attr is ModelAttributeCompositeKey;
107
- export declare type ModelAttributeAuthProperty = {
108
- allow: ModelAttributeAuthAllow;
109
- identityClaim?: string;
110
- groupClaim?: string;
111
- groups?: string[];
112
- operations?: string[];
113
- ownerField?: string;
114
- provider?: ModelAttributeAuthProvider;
115
- };
116
- export declare enum ModelAttributeAuthAllow {
117
- CUSTOM = "custom",
118
- OWNER = "owner",
119
- GROUPS = "groups",
120
- PRIVATE = "private",
121
- PUBLIC = "public"
122
- }
123
- export declare enum ModelAttributeAuthProvider {
124
- FUNCTION = "function",
125
- USER_POOLS = "userPools",
126
- OIDC = "oidc",
127
- IAM = "iam",
128
- API_KEY = "apiKey"
129
- }
130
- export declare type ModelFields = Record<string, ModelField>;
131
- export declare enum GraphQLScalarType {
132
- ID = 0,
133
- String = 1,
134
- Int = 2,
135
- Float = 3,
136
- Boolean = 4,
137
- AWSDate = 5,
138
- AWSTime = 6,
139
- AWSDateTime = 7,
140
- AWSTimestamp = 8,
141
- AWSEmail = 9,
142
- AWSJSON = 10,
143
- AWSURL = 11,
144
- AWSPhone = 12,
145
- AWSIPAddress = 13
146
- }
147
- export declare namespace GraphQLScalarType {
148
- function getJSType(scalar: keyof Omit<typeof GraphQLScalarType, 'getJSType' | 'getValidationFunction'>): 'string' | 'number' | 'boolean' | 'object';
149
- function getValidationFunction(scalar: keyof Omit<typeof GraphQLScalarType, 'getJSType' | 'getValidationFunction'>): ((val: string | number) => boolean) | undefined;
150
- }
151
- export declare type AuthorizationRule = {
152
- identityClaim: string;
153
- ownerField: string;
154
- provider: 'userPools' | 'oidc' | 'iam' | 'apiKey';
155
- groupClaim: string;
156
- groups: [string];
157
- authStrategy: 'owner' | 'groups' | 'private' | 'public';
158
- areSubscriptionsPublic: boolean;
159
- };
160
- export declare function isGraphQLScalarType(obj: any): obj is keyof Omit<typeof GraphQLScalarType, 'getJSType' | 'getValidationFunction'>;
161
- export declare type ModelFieldType = {
162
- model: string;
163
- };
164
- export declare function isModelFieldType(obj: any): obj is ModelFieldType;
165
- export declare type NonModelFieldType = {
166
- nonModel: string;
167
- };
168
- export declare function isNonModelFieldType(obj: any): obj is NonModelFieldType;
169
- declare type EnumFieldType = {
170
- enum: string;
171
- };
172
- export declare function isEnumFieldType(obj: any): obj is EnumFieldType;
173
- export declare type ModelField = {
174
- name: string;
175
- type: keyof Omit<typeof GraphQLScalarType, 'getJSType' | 'getValidationFunction'> | ModelFieldType | NonModelFieldType | EnumFieldType;
176
- isArray: boolean;
177
- isRequired?: boolean;
178
- isReadOnly?: boolean;
179
- isArrayNullable?: boolean;
180
- association?: ModelAssociation;
181
- attributes?: ModelAttributes[];
182
- };
183
- export declare type NonModelTypeConstructor<T> = {
184
- new (init: T): T;
185
- };
186
- export declare type PersistentModelConstructor<T extends PersistentModel> = {
187
- new (init: ModelInit<T, PersistentModelMetaData<T>>): T;
188
- copyOf(src: T, mutator: (draft: MutableModel<T, PersistentModelMetaData<T>>) => void): T;
189
- };
190
- export declare type TypeConstructorMap = Record<string, PersistentModelConstructor<any> | NonModelTypeConstructor<unknown>>;
191
- /**
192
- * Each identifier type is represented using nominal types, see:
193
- * https://basarat.gitbook.io/typescript/main-1/nominaltyping
194
- */
195
- export declare const __identifierBrand__: unique symbol;
196
- export declare type IdentifierBrand<T, K> = T & {
197
- [__identifierBrand__]: K;
198
- };
199
- export declare type ManagedIdentifier<T, F extends keyof T> = IdentifierBrand<{
200
- field: F extends string ? F : never;
201
- type: T;
202
- }, 'ManagedIdentifier'>;
203
- export declare type OptionallyManagedIdentifier<T, F extends keyof T> = IdentifierBrand<{
204
- field: F extends string ? F : never;
205
- type: T;
206
- }, 'OptionallyManagedIdentifier'>;
207
- export declare type CompositeIdentifier<T, K extends Array<keyof T>> = IdentifierBrand<{
208
- fields: K;
209
- type: T;
210
- }, 'CompositeIdentifier'>;
211
- export declare type CustomIdentifier<T, K extends keyof T> = CompositeIdentifier<T, [K]>;
212
- export declare type Identifier<T> = ManagedIdentifier<T, any> | OptionallyManagedIdentifier<T, any> | CompositeIdentifier<T, any> | CustomIdentifier<T, any>;
213
- 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;
214
- 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;
215
- export declare const __modelMeta__: unique symbol;
216
- export declare type PersistentModelMetaData<T> = {
217
- identifier?: Identifier<T>;
218
- readOnlyFields?: string;
219
- };
220
- export declare type DefaultPersistentModelMetaData = {
221
- identifier: ManagedIdentifier<{
222
- id: string;
223
- }, 'id'>;
224
- readOnlyFields: never;
225
- };
226
- export declare type MetadataOrDefault<T extends PersistentModel, _ extends PersistentModelMetaData<T> = never> = T extends {
227
- [__modelMeta__]: PersistentModelMetaData<T>;
228
- } ? T[typeof __modelMeta__] : DefaultPersistentModelMetaData;
229
- export declare type PersistentModel = Readonly<Record<string, any>>;
230
- export declare type MetadataReadOnlyFields<T extends PersistentModel, M extends PersistentModelMetaData<T>> = Extract<MetadataOrDefault<T, M>['readOnlyFields'] | M['readOnlyFields'], keyof T>;
231
- 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>>>);
232
- declare type DeepWritable<T> = {
233
- -readonly [P in keyof T]: T[P] extends TypeName<T[P]> ? T[P] : DeepWritable<T[P]>;
234
- };
235
- 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>>>;
236
- export declare type ModelInstanceMetadata = {
237
- _version: number;
238
- _lastChangedAt: number;
239
- _deleted: boolean;
240
- };
241
- 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']];
242
- export declare type IdentifierFieldOrIdentifierObject<T extends PersistentModel, M extends PersistentModelMetaData<T>> = Pick<T, IdentifierFields<T, M>> | IdentifierFieldValue<T, M>;
243
- export declare function isIdentifierObject<T extends PersistentModel>(obj: any, modelDefinition: SchemaModel): obj is IdentifierFields<T extends PersistentModel ? T : never, any>;
244
- export declare enum OpType {
245
- INSERT = "INSERT",
246
- UPDATE = "UPDATE",
247
- DELETE = "DELETE"
248
- }
249
- export declare type SubscriptionMessage<T extends PersistentModel> = Pick<InternalSubscriptionMessage<T>, 'opType' | 'element' | 'model' | 'condition'>;
250
- export declare type InternalSubscriptionMessage<T extends PersistentModel> = {
251
- opType: OpType;
252
- element: T;
253
- model: PersistentModelConstructor<T>;
254
- condition: PredicatesGroup<T> | null;
255
- savedElement?: T;
256
- };
257
- export declare type DataStoreSnapshot<T extends PersistentModel> = {
258
- items: T[];
259
- isSynced: boolean;
260
- };
261
- export declare type PredicateExpression<M extends PersistentModel, FT> = TypeName<FT> extends keyof MapTypeToOperands<FT> ? (operator: keyof MapTypeToOperands<FT>[TypeName<FT>], operand: MapTypeToOperands<FT>[TypeName<FT>][keyof MapTypeToOperands<FT>[TypeName<FT>]]) => ModelPredicate<M> : never;
262
- declare type EqualityOperators<T> = {
263
- ne: T;
264
- eq: T;
265
- };
266
- declare type ScalarNumberOperators<T> = EqualityOperators<T> & {
267
- le: T;
268
- lt: T;
269
- ge: T;
270
- gt: T;
271
- };
272
- declare type NumberOperators<T> = ScalarNumberOperators<T> & {
273
- between: [T, T];
274
- };
275
- declare type StringOperators<T> = ScalarNumberOperators<T> & {
276
- beginsWith: T;
277
- contains: T;
278
- notContains: T;
279
- };
280
- declare type BooleanOperators<T> = EqualityOperators<T>;
281
- declare type ArrayOperators<T> = {
282
- contains: T;
283
- notContains: T;
284
- };
285
- export declare type AllOperators = NumberOperators<any> & StringOperators<any> & ArrayOperators<any>;
286
- declare type MapTypeToOperands<T> = {
287
- number: NumberOperators<NonNullable<T>>;
288
- string: StringOperators<NonNullable<T>>;
289
- boolean: BooleanOperators<NonNullable<T>>;
290
- 'number[]': ArrayOperators<number>;
291
- 'string[]': ArrayOperators<string>;
292
- 'boolean[]': ArrayOperators<boolean>;
293
- };
294
- declare type TypeName<T> = T extends string ? 'string' : T extends number ? 'number' : T extends boolean ? 'boolean' : T extends string[] ? 'string[]' : T extends number[] ? 'number[]' : T extends boolean[] ? 'boolean[]' : never;
295
- export declare type PredicateGroups<T extends PersistentModel> = {
296
- and: (predicate: (predicate: ModelPredicate<T>) => ModelPredicate<T>) => ModelPredicate<T>;
297
- or: (predicate: (predicate: ModelPredicate<T>) => ModelPredicate<T>) => ModelPredicate<T>;
298
- not: (predicate: (predicate: ModelPredicate<T>) => ModelPredicate<T>) => ModelPredicate<T>;
299
- };
300
- export declare type ModelPredicate<M extends PersistentModel> = {
301
- [K in keyof M]-?: PredicateExpression<M, NonNullable<M[K]>>;
302
- } & PredicateGroups<M>;
303
- export declare type ProducerModelPredicate<M extends PersistentModel> = (condition: ModelPredicate<M>) => ModelPredicate<M>;
304
- export declare type PredicatesGroup<T extends PersistentModel> = {
305
- type: keyof PredicateGroups<T>;
306
- predicates: (PredicateObject<T> | PredicatesGroup<T>)[];
307
- };
308
- export declare function isPredicateObj<T extends PersistentModel>(obj: any): obj is PredicateObject<T>;
309
- export declare function isPredicateGroup<T extends PersistentModel>(obj: any): obj is PredicatesGroup<T>;
310
- export declare type PredicateObject<T extends PersistentModel> = {
311
- field: keyof T;
312
- operator: keyof AllOperators;
313
- operand: any;
314
- };
315
- export declare enum QueryOne {
316
- FIRST = 0,
317
- LAST = 1
318
- }
319
- export declare type GraphQLField = {
320
- [field: string]: {
321
- [operator: string]: string | number | [number, number];
322
- };
323
- };
324
- export declare type GraphQLCondition = Partial<GraphQLField | {
325
- and: [GraphQLCondition];
326
- or: [GraphQLCondition];
327
- not: GraphQLCondition;
328
- }>;
329
- export declare type GraphQLFilter = Partial<GraphQLField | {
330
- and: GraphQLFilter[];
331
- } | {
332
- or: GraphQLFilter[];
333
- } | {
334
- not: GraphQLFilter;
335
- }>;
336
- export declare type ProducerPaginationInput<T extends PersistentModel> = {
337
- sort?: ProducerSortPredicate<T>;
338
- limit?: number;
339
- page?: number;
340
- };
341
- export declare type ObserveQueryOptions<T extends PersistentModel> = Pick<ProducerPaginationInput<T>, 'sort'>;
342
- export declare type PaginationInput<T extends PersistentModel> = {
343
- sort?: SortPredicate<T>;
344
- limit?: number;
345
- page?: number;
346
- };
347
- export declare type ProducerSortPredicate<M extends PersistentModel> = (condition: SortPredicate<M>) => SortPredicate<M>;
348
- export declare type SortPredicate<T extends PersistentModel> = {
349
- [K in keyof T]-?: SortPredicateExpression<T, NonNullable<T[K]>>;
350
- };
351
- export declare type SortPredicateExpression<M extends PersistentModel, FT> = TypeName<FT> extends keyof MapTypeToOperands<FT> ? (sortDirection: keyof typeof SortDirection) => SortPredicate<M> : never;
352
- export declare enum SortDirection {
353
- ASCENDING = "ASCENDING",
354
- DESCENDING = "DESCENDING"
355
- }
356
- export declare type SortPredicatesGroup<T extends PersistentModel> = SortPredicateObject<T>[];
357
- export declare type SortPredicateObject<T extends PersistentModel> = {
358
- field: keyof T;
359
- sortDirection: keyof typeof SortDirection;
360
- };
361
- export declare type SystemComponent = {
362
- setUp(schema: InternalSchema, namespaceResolver: NamespaceResolver, modelInstanceCreator: ModelInstanceCreator, getModelConstructorByModelName: (namsespaceName: string, modelName: string) => PersistentModelConstructor<any>, appId: string): Promise<void>;
363
- };
364
- export declare type NamespaceResolver = (modelConstructor: PersistentModelConstructor<any>) => string;
365
- export declare type ControlMessageType<T> = {
366
- type: T;
367
- data?: any;
368
- };
369
- export declare type RelationType = {
370
- fieldName: string;
371
- modelName: string;
372
- relationType: 'HAS_ONE' | 'HAS_MANY' | 'BELONGS_TO';
373
- targetName?: string;
374
- targetNames?: string[];
375
- associatedWith?: string | string[];
376
- };
377
- declare type IndexOptions = {
378
- unique?: boolean;
379
- };
380
- export declare type IndexesType = Array<[string, string[], IndexOptions?]>;
381
- export declare type RelationshipType = {
382
- [modelName: string]: {
383
- indexes: IndexesType;
384
- relationTypes: RelationType[];
385
- };
386
- };
387
- export declare type KeyType = {
388
- primaryKey?: string[];
389
- compositeKeys?: Set<string>[];
390
- };
391
- export declare type ModelKeys = {
392
- [modelName: string]: KeyType;
393
- };
394
- export declare type DataStoreConfig = {
395
- DataStore?: {
396
- authModeStrategyType?: AuthModeStrategyType;
397
- conflictHandler?: ConflictHandler;
398
- errorHandler?: (error: SyncError<PersistentModel>) => void;
399
- maxRecordsToSync?: number;
400
- syncPageSize?: number;
401
- fullSyncInterval?: number;
402
- syncExpressions?: SyncExpression[];
403
- authProviders?: AuthProviders;
404
- storageAdapter?: Adapter;
405
- };
406
- authModeStrategyType?: AuthModeStrategyType;
407
- conflictHandler?: ConflictHandler;
408
- errorHandler?: (error: SyncError<PersistentModel>) => void;
409
- maxRecordsToSync?: number;
410
- syncPageSize?: number;
411
- fullSyncInterval?: number;
412
- syncExpressions?: SyncExpression[];
413
- authProviders?: AuthProviders;
414
- storageAdapter?: Adapter;
415
- };
416
- export declare type AuthProviders = {
417
- functionAuthProvider: () => {
418
- token: string;
419
- } | Promise<{
420
- token: string;
421
- }>;
422
- };
423
- export declare enum AuthModeStrategyType {
424
- DEFAULT = "DEFAULT",
425
- MULTI_AUTH = "MULTI_AUTH"
426
- }
427
- export declare type AuthModeStrategyReturn = GRAPHQL_AUTH_MODE | GRAPHQL_AUTH_MODE[] | undefined | null;
428
- export declare type AuthModeStrategyParams = {
429
- schema: InternalSchema;
430
- modelName: string;
431
- operation: ModelOperation;
432
- };
433
- export declare type AuthModeStrategy = (authModeStrategyParams: AuthModeStrategyParams) => AuthModeStrategyReturn | Promise<AuthModeStrategyReturn>;
434
- export declare enum ModelOperation {
435
- CREATE = "CREATE",
436
- READ = "READ",
437
- UPDATE = "UPDATE",
438
- DELETE = "DELETE"
439
- }
440
- export declare type ModelAuthModes = Record<string, {
441
- [Property in ModelOperation]: GRAPHQL_AUTH_MODE[];
442
- }>;
443
- export declare type SyncExpression = Promise<{
444
- modelConstructor: any;
445
- conditionProducer: (c?: any) => any;
446
- }>;
447
- declare type Option0 = [];
448
- declare type Option1<T extends PersistentModel> = [ModelPredicate<T> | undefined];
449
- declare type Option<T extends PersistentModel> = Option0 | Option1<T>;
450
- declare type Lookup<T extends PersistentModel> = {
451
- 0: ProducerModelPredicate<T> | Promise<ProducerModelPredicate<T>> | typeof PredicateAll;
452
- 1: ModelPredicate<T> | undefined;
453
- };
454
- declare type ConditionProducer<T extends PersistentModel, A extends Option<T>> = (...args: A) => A['length'] extends keyof Lookup<T> ? Lookup<T>[A['length']] : never;
455
- export declare function syncExpression<T extends PersistentModel, A extends Option<T>>(modelConstructor: PersistentModelConstructor<T>, conditionProducer: ConditionProducer<T, A>): Promise<{
456
- modelConstructor: PersistentModelConstructor<T>;
457
- conditionProducer: ConditionProducer<T, A>;
458
- }>;
459
- export declare type SyncConflict = {
460
- modelConstructor: PersistentModelConstructor<any>;
461
- localModel: PersistentModel;
462
- remoteModel: PersistentModel;
463
- operation: OpType;
464
- attempts: number;
465
- };
466
- export declare type SyncError<T extends PersistentModel> = {
467
- message: string;
468
- errorType: ErrorType;
469
- errorInfo?: string;
470
- recoverySuggestion?: string;
471
- model?: string;
472
- localModel: T;
473
- remoteModel: T;
474
- process: ProcessName;
475
- operation: string;
476
- cause?: Error;
477
- };
478
- export declare type ErrorType = 'ConfigError' | 'BadModel' | 'BadRecord' | 'Unauthorized' | 'Transient' | 'Unknown';
479
- export declare enum ProcessName {
480
- 'sync' = "sync",
481
- 'mutate' = "mutate",
482
- 'subscribe' = "subscribe"
483
- }
484
- export declare const DISCARD: unique symbol;
485
- export declare type ConflictHandler = (conflict: SyncConflict) => Promise<PersistentModel | typeof DISCARD> | PersistentModel | typeof DISCARD;
486
- export declare type ErrorHandler = (error: SyncError<PersistentModel>) => void;
487
- export declare type DeferredCallbackResolverOptions = {
488
- callback: () => void;
489
- maxInterval?: number;
490
- errorHandler?: (error: string) => void;
491
- };
492
- export declare enum LimitTimerRaceResolvedValues {
493
- LIMIT = "LIMIT",
494
- TIMER = "TIMER"
495
- }
496
- export declare type AmplifyContext = {
497
- Auth: typeof Auth;
498
- API: typeof API;
499
- Cache: typeof Cache;
500
- };
501
- export {};
package/lib/util.d.ts DELETED
@@ -1,145 +0,0 @@
1
- import { ULID } from 'ulid';
2
- import { Patch } from 'immer';
3
- import { PersistentModel, PersistentModelConstructor, PredicateObject, PredicatesGroup, RelationshipType, RelationType, ModelKeys, ModelAttributes, SchemaNamespace, SortPredicatesGroup, NonModelTypeConstructor, DeferredCallbackResolverOptions, SchemaModel, ModelAttribute, IndexesType } from './types';
4
- export declare const ID = "id";
5
- /**
6
- * Used by the Async Storage Adapter to concatenate key values
7
- * for a record. For instance, if a model has the following keys:
8
- * `customId: ID! @primaryKey(sortKeyFields: ["createdAt"])`,
9
- * we concatenate the `customId` and `createdAt` as:
10
- * `12-234-5#2022-09-28T00:00:00.000Z`
11
- */
12
- export declare const DEFAULT_PRIMARY_KEY_VALUE_SEPARATOR = "#";
13
- /**
14
- * Used for generating spinal-cased index name from an array of
15
- * key field names.
16
- * E.g. for keys `[id, title]` => 'id-title'
17
- */
18
- export declare const IDENTIFIER_KEY_SEPARATOR = "-";
19
- export declare const errorMessages: {
20
- idEmptyString: string;
21
- queryByPkWithCompositeKeyPresent: string;
22
- deleteByPkWithCompositeKeyPresent: string;
23
- observeWithObjectLiteral: string;
24
- };
25
- export declare enum NAMESPACES {
26
- DATASTORE = "datastore",
27
- USER = "user",
28
- SYNC = "sync",
29
- STORAGE = "storage"
30
- }
31
- declare const DATASTORE = NAMESPACES.DATASTORE;
32
- declare const USER = NAMESPACES.USER;
33
- declare const SYNC = NAMESPACES.SYNC;
34
- declare const STORAGE = NAMESPACES.STORAGE;
35
- export { USER, SYNC, STORAGE, DATASTORE };
36
- export declare const USER_AGENT_SUFFIX_DATASTORE = "/DataStore";
37
- export declare const exhaustiveCheck: (obj: never, throwOnError?: boolean) => void;
38
- export declare const isNullOrUndefined: (val: any) => boolean;
39
- export declare const validatePredicate: <T extends Readonly<Record<string, any>>>(model: T, groupType: "and" | "or" | "not", predicatesOrGroups: (PredicateObject<T> | PredicatesGroup<T>)[]) => any;
40
- export declare const validatePredicateField: <T>(value: T, operator: "ne" | "eq" | "le" | "lt" | "ge" | "gt" | "between" | "beginsWith" | "contains" | "notContains", operand: T | [T, T]) => boolean;
41
- export declare const isModelConstructor: <T extends Readonly<Record<string, any>>>(obj: any) => obj is PersistentModelConstructor<T>;
42
- export declare function registerNonModelClass(clazz: NonModelTypeConstructor<any>): void;
43
- export declare const isNonModelConstructor: (obj: any) => obj is NonModelTypeConstructor<any>;
44
- 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>) => {
45
- modelName: string;
46
- item: T;
47
- instance: T;
48
- }[];
49
- export declare const isPrivateMode: () => Promise<unknown>;
50
- export declare function monotonicUlidFactory(seed?: number): ULID;
51
- /**
52
- * Uses performance.now() if available, otherwise, uses Date.now() (e.g. react native without a polyfill)
53
- *
54
- * The values returned by performance.now() always increase at a constant rate,
55
- * independent of the system clock (which might be adjusted manually or skewed
56
- * by software like NTP).
57
- *
58
- * Otherwise, performance.timing.navigationStart + performance.now() will be
59
- * approximately equal to Date.now()
60
- *
61
- * See: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#Example
62
- */
63
- export declare function getNow(): number;
64
- export declare function sortCompareFunction<T extends PersistentModel>(sortPredicates: SortPredicatesGroup<T>): (a: any, b: any) => number;
65
- export declare function valuesEqual(valA: any, valB: any, nullish?: boolean): boolean;
66
- export declare const isAWSDate: (val: string) => boolean;
67
- export declare const isAWSTime: (val: string) => boolean;
68
- export declare const isAWSDateTime: (val: string) => boolean;
69
- export declare const isAWSTimestamp: (val: number) => boolean;
70
- export declare const isAWSEmail: (val: string) => boolean;
71
- export declare const isAWSJSON: (val: string) => boolean;
72
- export declare const isAWSURL: (val: string) => boolean;
73
- export declare const isAWSPhone: (val: string) => boolean;
74
- export declare const isAWSIPAddress: (val: string) => boolean;
75
- export declare class DeferredPromise {
76
- promise: Promise<string>;
77
- resolve: (value: string | PromiseLike<string>) => void;
78
- reject: () => void;
79
- constructor();
80
- }
81
- export declare class DeferredCallbackResolver {
82
- private limitPromise;
83
- private timerPromise;
84
- private maxInterval;
85
- private timer;
86
- private raceInFlight;
87
- private callback;
88
- private errorHandler;
89
- private defaultErrorHandler;
90
- constructor(options: DeferredCallbackResolverOptions);
91
- private startTimer;
92
- private racePromises;
93
- start(): void;
94
- clear(): void;
95
- resolve(): void;
96
- }
97
- /**
98
- * merge two sets of patches created by immer produce.
99
- * newPatches take precedent over oldPatches for patches modifying the same path.
100
- * In the case many consecutive pathces are merged the original model should
101
- * always be the root model.
102
- *
103
- * Example:
104
- * A -> B, patches1
105
- * B -> C, patches2
106
- *
107
- * mergePatches(A, patches1, patches2) to get patches for A -> C
108
- *
109
- * @param originalSource the original Model the patches should be applied to
110
- * @param oldPatches immer produce patch list
111
- * @param newPatches immer produce patch list (will take precedence)
112
- * @return merged patches
113
- */
114
- export declare function mergePatches<T>(originalSource: T, oldPatches: Patch[], newPatches: Patch[]): Patch[];
115
- export declare const getStorename: (namespace: string, modelName: string) => string;
116
- export declare const processCompositeKeys: (attributes: ModelAttributes) => Set<string>[];
117
- export declare const extractKeyIfExists: (modelDefinition: SchemaModel) => ModelAttribute;
118
- export declare const extractPrimaryKeyFieldNames: (modelDefinition: SchemaModel) => string[];
119
- export declare const extractPrimaryKeyValues: <T extends Readonly<Record<string, any>>>(model: T, keyFields: string[]) => string[];
120
- export declare const extractPrimaryKeysAndValues: <T extends Readonly<Record<string, any>>>(model: T, keyFields: string[]) => any;
121
- export declare const isIdManaged: (modelDefinition: SchemaModel) => boolean;
122
- export declare const isIdOptionallyManaged: (modelDefinition: SchemaModel) => boolean;
123
- export declare const establishRelationAndKeys: (namespace: SchemaNamespace) => [RelationshipType, ModelKeys];
124
- export declare const getIndex: (rel: RelationType[], src: string) => string;
125
- export declare const getIndexFromAssociation: (indexes: IndexesType, src: string | string[]) => string;
126
- /**
127
- * Backwards-compatability for schema generated prior to custom primary key support:
128
- the single field `targetName` has been replaced with an array of `targetNames`.
129
- `targetName` and `targetNames` are exclusive (will never exist on the same schema)
130
- * @param src {RelationType | ModelAssociation | undefined}
131
- * @returns array of targetNames, or `undefined`
132
- */
133
- export declare const extractTargetNamesFromSrc: (src: RelationType | {
134
- connectionType: "HAS_ONE" | "HAS_MANY";
135
- associatedWith: string | string[];
136
- targetName?: string;
137
- targetNames?: string[];
138
- } | {
139
- connectionType: "BELONGS_TO";
140
- targetName?: string;
141
- targetNames?: string[];
142
- }) => string[];
143
- export declare const indexNameFromKeys: (keys: string[]) => string;
144
- export declare const keysEqual: (keysA: any, keysB: any) => boolean;
145
- export declare const getIndexKeys: (namespace: SchemaNamespace, modelName: string) => string[];