@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4432977.0

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 (182) hide show
  1. package/README.md +4 -0
  2. package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
  3. package/lib/authModeStrategies/index.js +3 -3
  4. package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
  5. package/lib/datastore/datastore.d.ts +3 -4
  6. package/lib/datastore/datastore.js +361 -227
  7. package/lib/index.d.ts +1 -1
  8. package/lib/index.js +25 -12
  9. package/lib/predicates/index.js +46 -12
  10. package/lib/predicates/next.d.ts +2 -2
  11. package/lib/predicates/next.js +172 -74
  12. package/lib/predicates/sort.js +3 -4
  13. package/lib/ssr/index.js +1 -1
  14. package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
  15. package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
  16. package/lib/storage/adapter/InMemoryStore.js +68 -17
  17. package/lib/storage/adapter/InMemoryStore.native.js +5 -3
  18. package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
  19. package/lib/storage/adapter/StorageAdapterBase.js +154 -85
  20. package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
  21. package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
  22. package/lib/storage/adapter/index.js +0 -1
  23. package/lib/storage/relationship.js +31 -21
  24. package/lib/storage/storage.d.ts +3 -3
  25. package/lib/storage/storage.js +143 -61
  26. package/lib/sync/datastoreConnectivity.d.ts +1 -1
  27. package/lib/sync/datastoreConnectivity.js +57 -9
  28. package/lib/sync/datastoreReachability/index.js +3 -3
  29. package/lib/sync/datastoreReachability/index.native.js +7 -5
  30. package/lib/sync/index.d.ts +1 -1
  31. package/lib/sync/index.js +193 -125
  32. package/lib/sync/merger.js +81 -10
  33. package/lib/sync/outbox.js +101 -30
  34. package/lib/sync/processors/errorMaps.d.ts +1 -1
  35. package/lib/sync/processors/errorMaps.js +41 -6
  36. package/lib/sync/processors/mutation.d.ts +1 -1
  37. package/lib/sync/processors/mutation.js +192 -101
  38. package/lib/sync/processors/subscription.d.ts +4 -1
  39. package/lib/sync/processors/subscription.js +190 -178
  40. package/lib/sync/processors/sync.d.ts +1 -1
  41. package/lib/sync/processors/sync.js +113 -47
  42. package/lib/sync/utils.d.ts +4 -4
  43. package/lib/sync/utils.js +162 -81
  44. package/lib/tsconfig.tsbuildinfo +1 -0
  45. package/lib/types.d.ts +138 -140
  46. package/lib/types.js +40 -5
  47. package/lib/util.d.ts +9 -17
  48. package/lib/util.js +216 -100
  49. package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
  50. package/lib-esm/authModeStrategies/index.js +0 -1
  51. package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
  52. package/lib-esm/datastore/datastore.d.ts +3 -4
  53. package/lib-esm/datastore/datastore.js +206 -77
  54. package/lib-esm/index.d.ts +1 -1
  55. package/lib-esm/index.js +0 -1
  56. package/lib-esm/predicates/index.js +40 -7
  57. package/lib-esm/predicates/next.d.ts +2 -2
  58. package/lib-esm/predicates/next.js +148 -52
  59. package/lib-esm/predicates/sort.js +2 -4
  60. package/lib-esm/ssr/index.js +0 -1
  61. package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
  62. package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
  63. package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
  64. package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
  65. package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
  66. package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
  67. package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
  68. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
  69. package/lib-esm/storage/adapter/index.js +1 -1
  70. package/lib-esm/storage/relationship.js +27 -18
  71. package/lib-esm/storage/storage.d.ts +3 -3
  72. package/lib-esm/storage/storage.js +87 -9
  73. package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
  74. package/lib-esm/sync/datastoreConnectivity.js +48 -3
  75. package/lib-esm/sync/datastoreReachability/index.js +1 -2
  76. package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
  77. package/lib-esm/sync/index.d.ts +1 -1
  78. package/lib-esm/sync/index.js +136 -72
  79. package/lib-esm/sync/merger.js +73 -3
  80. package/lib-esm/sync/outbox.js +75 -5
  81. package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
  82. package/lib-esm/sync/processors/errorMaps.js +39 -5
  83. package/lib-esm/sync/processors/mutation.d.ts +1 -1
  84. package/lib-esm/sync/processors/mutation.js +130 -44
  85. package/lib-esm/sync/processors/subscription.d.ts +4 -1
  86. package/lib-esm/sync/processors/subscription.js +134 -126
  87. package/lib-esm/sync/processors/sync.d.ts +1 -1
  88. package/lib-esm/sync/processors/sync.js +74 -12
  89. package/lib-esm/sync/utils.d.ts +4 -4
  90. package/lib-esm/sync/utils.js +135 -55
  91. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  92. package/lib-esm/types.d.ts +138 -140
  93. package/lib-esm/types.js +36 -2
  94. package/lib-esm/util.d.ts +9 -17
  95. package/lib-esm/util.js +96 -16
  96. package/package.json +139 -132
  97. package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
  98. package/src/datastore/datastore.ts +32 -25
  99. package/src/predicates/sort.ts +3 -1
  100. package/src/storage/adapter/InMemoryStore.ts +1 -1
  101. package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
  102. package/src/storage/adapter/StorageAdapterBase.ts +1 -1
  103. package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
  104. package/src/storage/storage.ts +1 -1
  105. package/src/sync/datastoreConnectivity.ts +2 -2
  106. package/src/sync/datastoreReachability/index.native.ts +1 -1
  107. package/src/sync/datastoreReachability/index.ts +1 -1
  108. package/src/sync/index.ts +69 -78
  109. package/src/sync/processors/mutation.ts +16 -10
  110. package/src/sync/processors/subscription.ts +55 -127
  111. package/src/sync/processors/sync.ts +8 -4
  112. package/src/sync/utils.ts +7 -8
  113. package/src/types.ts +4 -8
  114. package/src/util.ts +5 -6
  115. package/lib/.tsbuildinfo +0 -3
  116. package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
  117. package/lib/authModeStrategies/index.js.map +0 -1
  118. package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
  119. package/lib/datastore/datastore.js.map +0 -1
  120. package/lib/index.js.map +0 -1
  121. package/lib/predicates/index.js.map +0 -1
  122. package/lib/predicates/next.js.map +0 -1
  123. package/lib/predicates/sort.js.map +0 -1
  124. package/lib/ssr/index.js.map +0 -1
  125. package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
  126. package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
  127. package/lib/storage/adapter/InMemoryStore.js.map +0 -1
  128. package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
  129. package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
  130. package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
  131. package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
  132. package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
  133. package/lib/storage/adapter/index.js.map +0 -1
  134. package/lib/storage/relationship.js.map +0 -1
  135. package/lib/storage/storage.js.map +0 -1
  136. package/lib/sync/datastoreConnectivity.js.map +0 -1
  137. package/lib/sync/datastoreReachability/index.js.map +0 -1
  138. package/lib/sync/datastoreReachability/index.native.js.map +0 -1
  139. package/lib/sync/index.js.map +0 -1
  140. package/lib/sync/merger.js.map +0 -1
  141. package/lib/sync/outbox.js.map +0 -1
  142. package/lib/sync/processors/errorMaps.js.map +0 -1
  143. package/lib/sync/processors/mutation.js.map +0 -1
  144. package/lib/sync/processors/subscription.js.map +0 -1
  145. package/lib/sync/processors/sync.js.map +0 -1
  146. package/lib/sync/utils.js.map +0 -1
  147. package/lib/types.js.map +0 -1
  148. package/lib/util.js.map +0 -1
  149. package/lib-esm/.tsbuildinfo +0 -3
  150. package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
  151. package/lib-esm/authModeStrategies/index.js.map +0 -1
  152. package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
  153. package/lib-esm/datastore/datastore.js.map +0 -1
  154. package/lib-esm/index.js.map +0 -1
  155. package/lib-esm/predicates/index.js.map +0 -1
  156. package/lib-esm/predicates/next.js.map +0 -1
  157. package/lib-esm/predicates/sort.js.map +0 -1
  158. package/lib-esm/ssr/index.js.map +0 -1
  159. package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
  160. package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
  161. package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
  162. package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
  163. package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
  164. package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
  165. package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
  166. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
  167. package/lib-esm/storage/adapter/index.js.map +0 -1
  168. package/lib-esm/storage/relationship.js.map +0 -1
  169. package/lib-esm/storage/storage.js.map +0 -1
  170. package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
  171. package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
  172. package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
  173. package/lib-esm/sync/index.js.map +0 -1
  174. package/lib-esm/sync/merger.js.map +0 -1
  175. package/lib-esm/sync/outbox.js.map +0 -1
  176. package/lib-esm/sync/processors/errorMaps.js.map +0 -1
  177. package/lib-esm/sync/processors/mutation.js.map +0 -1
  178. package/lib-esm/sync/processors/subscription.js.map +0 -1
  179. package/lib-esm/sync/processors/sync.js.map +0 -1
  180. package/lib-esm/sync/utils.js.map +0 -1
  181. package/lib-esm/types.js.map +0 -1
  182. package/lib-esm/util.js.map +0 -1
package/lib-esm/types.js CHANGED
@@ -1,4 +1,39 @@
1
- import { __awaiter, __generator } from "tslib";
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
2
37
  import { isAWSDate, isAWSTime, isAWSDateTime, isAWSTimestamp, isAWSEmail, isAWSJSON, isAWSURL, isAWSPhone, isAWSIPAddress, extractPrimaryKeyFieldNames, } from './util';
3
38
  export function isSchemaModel(obj) {
4
39
  return obj && obj.pluralName !== undefined;
@@ -216,4 +251,3 @@ var PredicateInternalsKey = /** @class */ (function () {
216
251
  }());
217
252
  export { PredicateInternalsKey };
218
253
  // #endregion
219
- //# sourceMappingURL=types.js.map
package/lib-esm/util.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ULID } from 'ulid';
2
2
  import { Patch } from 'immer';
3
- import { PersistentModel, PersistentModelConstructor, PredicateObject, PredicatesGroup, RelationshipType, RelationType, ModelKeys, ModelAttributes, SchemaNamespace, SortPredicatesGroup, NonModelTypeConstructor, PaginationInput, DeferredCallbackResolverOptions, SchemaModel, ModelAttribute, IndexesType } from './types';
3
+ import { ModelInstanceCreator } from './datastore/datastore';
4
+ import { AllOperators, PersistentModel, PersistentModelConstructor, PredicateGroups, PredicateObject, PredicatesGroup, RelationshipType, RelationType, ModelKeys, ModelAttributes, SchemaNamespace, SortPredicatesGroup, NonModelTypeConstructor, PaginationInput, DeferredCallbackResolverOptions, SchemaModel, ModelAttribute, IndexesType, ModelAssociation } from './types';
4
5
  export declare const ID = "id";
5
6
  /**
6
7
  * Used by the Async Storage Adapter to concatenate key values
@@ -35,12 +36,12 @@ declare const STORAGE = NAMESPACES.STORAGE;
35
36
  export { USER, SYNC, STORAGE, DATASTORE };
36
37
  export declare const exhaustiveCheck: (obj: never, throwOnError?: boolean) => void;
37
38
  export declare const isNullOrUndefined: (val: any) => boolean;
38
- export declare const validatePredicate: <T extends Readonly<Record<string, any>>>(model: T, groupType: "and" | "or" | "not", predicatesOrGroups: (PredicateObject<T> | PredicatesGroup<T>)[]) => any;
39
- export declare const validatePredicateField: <T>(value: T, operator: "eq" | "ne" | "gt" | "lt" | "ge" | "le" | "contains" | "notContains" | "beginsWith" | "between", operand: T | [T, T]) => boolean;
39
+ export declare const validatePredicate: <T extends Readonly<Record<string, any>>>(model: T, groupType: keyof PredicateGroups<T>, predicatesOrGroups: (PredicateObject<T> | PredicatesGroup<T>)[]) => any;
40
+ export declare const validatePredicateField: <T>(value: T, operator: keyof AllOperators, operand: T | [T, T]) => boolean;
40
41
  export declare const isModelConstructor: <T extends Readonly<Record<string, any>>>(obj: any) => obj is PersistentModelConstructor<T>;
41
42
  export declare function registerNonModelClass(clazz: NonModelTypeConstructor<any>): void;
42
43
  export declare const isNonModelConstructor: (obj: any) => obj is NonModelTypeConstructor<any>;
43
- 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: NAMESPACES, modelName: string) => PersistentModelConstructor<any>) => {
44
+ export declare const traverseModel: <T extends Readonly<Record<string, any>>>(srcModelName: string, instance: T, namespace: SchemaNamespace, modelInstanceCreator: ModelInstanceCreator, getModelConstructorByModelName: (namsespaceName: NAMESPACES, modelName: string) => PersistentModelConstructor<any>) => {
44
45
  modelName: string;
45
46
  item: T;
46
47
  instance: T;
@@ -157,15 +158,15 @@ export declare class DeferredCallbackResolver {
157
158
  export declare function mergePatches<T>(originalSource: T, oldPatches: Patch[], newPatches: Patch[]): Patch[];
158
159
  export declare const getStorename: (namespace: string, modelName: string) => string;
159
160
  export declare const processCompositeKeys: (attributes: ModelAttributes) => Set<string>[];
160
- export declare const extractKeyIfExists: (modelDefinition: SchemaModel) => ModelAttribute;
161
+ export declare const extractKeyIfExists: (modelDefinition: SchemaModel) => ModelAttribute | undefined;
161
162
  export declare const extractPrimaryKeyFieldNames: (modelDefinition: SchemaModel) => string[];
162
163
  export declare const extractPrimaryKeyValues: <T extends Readonly<Record<string, any>>>(model: T, keyFields: string[]) => string[];
163
164
  export declare const extractPrimaryKeysAndValues: <T extends Readonly<Record<string, any>>>(model: T, keyFields: string[]) => any;
164
165
  export declare const isIdManaged: (modelDefinition: SchemaModel) => boolean;
165
166
  export declare const isIdOptionallyManaged: (modelDefinition: SchemaModel) => boolean;
166
167
  export declare const establishRelationAndKeys: (namespace: SchemaNamespace) => [RelationshipType, ModelKeys];
167
- export declare const getIndex: (rel: RelationType[], src: string) => string;
168
- export declare const getIndexFromAssociation: (indexes: IndexesType, src: string | string[]) => string;
168
+ export declare const getIndex: (rel: RelationType[], src: string) => string | undefined;
169
+ export declare const getIndexFromAssociation: (indexes: IndexesType, src: string | string[]) => string | undefined;
169
170
  /**
170
171
  * Backwards-compatability for schema generated prior to custom primary key support:
171
172
  the single field `targetName` has been replaced with an array of `targetNames`.
@@ -173,16 +174,7 @@ the single field `targetName` has been replaced with an array of `targetNames`.
173
174
  * @param src {RelationType | ModelAssociation | undefined}
174
175
  * @returns array of targetNames, or `undefined`
175
176
  */
176
- export declare const extractTargetNamesFromSrc: (src: {
177
- connectionType: "HAS_MANY" | "HAS_ONE";
178
- associatedWith: string | string[];
179
- targetName?: string;
180
- targetNames?: string[];
181
- } | {
182
- connectionType: "BELONGS_TO";
183
- targetName?: string;
184
- targetNames?: string[];
185
- } | RelationType) => string[];
177
+ export declare const extractTargetNamesFromSrc: (src: RelationType | ModelAssociation | undefined) => string[] | undefined;
186
178
  export declare const indexNameFromKeys: (keys: string[]) => string;
187
179
  export declare const keysEqual: (keysA: any, keysB: any) => boolean;
188
180
  export declare const getIndexKeys: (namespace: SchemaNamespace, modelName: string) => string[];
package/lib-esm/util.js CHANGED
@@ -1,12 +1,92 @@
1
- import { __assign, __awaiter, __generator, __read, __spread, __values } from "tslib";
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __read = (this && this.__read) || function (o, n) {
49
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
50
+ if (!m) return o;
51
+ var i = m.call(o), r, ar = [], e;
52
+ try {
53
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
54
+ }
55
+ catch (error) { e = { error: error }; }
56
+ finally {
57
+ try {
58
+ if (r && !r.done && (m = i["return"])) m.call(i);
59
+ }
60
+ finally { if (e) throw e.error; }
61
+ }
62
+ return ar;
63
+ };
64
+ var __values = (this && this.__values) || function(o) {
65
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
66
+ if (m) return m.call(o);
67
+ if (o && typeof o.length === "number") return {
68
+ next: function () {
69
+ if (o && i >= o.length) o = void 0;
70
+ return { value: o && o[i++], done: !o };
71
+ }
72
+ };
73
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
74
+ };
75
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
76
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
77
+ if (ar || !(i in from)) {
78
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
79
+ ar[i] = from[i];
80
+ }
81
+ }
82
+ return to.concat(ar || Array.prototype.slice.call(from));
83
+ };
2
84
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
85
  // SPDX-License-Identifier: Apache-2.0
4
- import { Buffer } from 'buffer';
5
86
  import { monotonicFactory } from 'ulid';
6
87
  import { v4 as uuid } from 'uuid';
7
88
  import { produce, applyPatches } from 'immer';
8
89
  import { isPredicateGroup, isPredicateObj, SortDirection, isModelAttributeKey, isModelAttributePrimaryKey, isModelAttributeCompositeKey, LimitTimerRaceResolvedValues, } from './types';
9
- import { WordArray } from 'amazon-cognito-identity-js';
10
90
  import { ModelSortPredicateCreator } from './predicates';
11
91
  export var ID = 'id';
12
92
  /**
@@ -44,7 +124,7 @@ export { USER, SYNC, STORAGE, DATASTORE };
44
124
  export var exhaustiveCheck = function (obj, throwOnError) {
45
125
  if (throwOnError === void 0) { throwOnError = true; }
46
126
  if (throwOnError) {
47
- throw new Error("Invalid " + obj);
127
+ throw new Error("Invalid ".concat(obj));
48
128
  }
49
129
  };
50
130
  export var isNullOrUndefined = function (val) {
@@ -68,7 +148,7 @@ export var validatePredicate = function (model, groupType, predicatesOrGroups) {
68
148
  filterType = 'some';
69
149
  break;
70
150
  default:
71
- throw new Error("Invalid " + groupType);
151
+ throw new Error("Invalid ".concat(groupType));
72
152
  }
73
153
  var result = predicatesOrGroups[filterType](function (predicateOrGroup) {
74
154
  if (isPredicateObj(predicateOrGroup)) {
@@ -271,10 +351,11 @@ export var isSafariCompatabilityMode = function () { return __awaiter(void 0, vo
271
351
  }
272
352
  });
273
353
  }); };
274
- var randomBytes = function (nBytes) {
275
- return Buffer.from(new WordArray().random(nBytes).toString(), 'hex');
276
- };
277
- var prng = function () { return randomBytes(1).readUInt8(0) / 0xff; };
354
+ // TODO(v6): refactor this random number logic auth -> core
355
+ // const randomBytes = (nBytes: number): Buffer => {
356
+ // return Buffer.from(new WordArray().random(nBytes).toString(), 'hex');
357
+ // };
358
+ var prng = function () { return 10 / 0xff; };
278
359
  export function monotonicUlidFactory(seed) {
279
360
  var ulid = monotonicFactory(prng);
280
361
  return function () {
@@ -363,8 +444,8 @@ export function valuesEqual(valA, valB, nullish) {
363
444
  return false;
364
445
  }
365
446
  if (a instanceof Set && b instanceof Set) {
366
- a = __spread(a);
367
- b = __spread(b);
447
+ a = __spreadArray([], __read(a), false);
448
+ b = __spreadArray([], __read(b), false);
368
449
  }
369
450
  if (a instanceof Map && b instanceof Map) {
370
451
  a = Object.fromEntries(a);
@@ -704,7 +785,7 @@ export function mergePatches(originalSource, oldPatches, newPatches) {
704
785
  return patches;
705
786
  }
706
787
  export var getStorename = function (namespace, modelName) {
707
- var storeName = namespace + "_" + modelName;
788
+ var storeName = "".concat(namespace, "_").concat(modelName);
708
789
  return storeName;
709
790
  };
710
791
  //#region Key Utils
@@ -763,10 +844,10 @@ export var processCompositeKeys = function (attributes) {
763
844
  }
764
845
  // does the current set share values with another set we've already added to `combined`?
765
846
  var intersectingSetIdx = combined.findIndex(function (existingSet) {
766
- return __spread(existingSet).some(function (f) { return sortKeyFieldsSet.has(f); });
847
+ return __spreadArray([], __read(existingSet), false).some(function (f) { return sortKeyFieldsSet.has(f); });
767
848
  });
768
849
  if (intersectingSetIdx > -1) {
769
- var union = new Set(__spread(combined[intersectingSetIdx], sortKeyFieldsSet));
850
+ var union = new Set(__spreadArray(__spreadArray([], __read(combined[intersectingSetIdx]), false), __read(sortKeyFieldsSet), false));
770
851
  // combine the current set with the intersecting set we found above
771
852
  combined[intersectingSetIdx] = union;
772
853
  }
@@ -957,7 +1038,7 @@ export var indexNameFromKeys = function (keys) {
957
1038
  if (idx === 0) {
958
1039
  return cur;
959
1040
  }
960
- return "" + prev + IDENTIFIER_KEY_SEPARATOR + cur;
1041
+ return "".concat(prev).concat(IDENTIFIER_KEY_SEPARATOR).concat(cur);
961
1042
  }, '');
962
1043
  };
963
1044
  export var keysEqual = function (keysA, keysB) {
@@ -999,4 +1080,3 @@ export var getTimestampFields = function (definition) {
999
1080
  var customFields = timestampFieldsMap || {};
1000
1081
  return __assign(__assign({}, defaultFields), customFields);
1001
1082
  };
1002
- //# sourceMappingURL=util.js.map
package/package.json CHANGED
@@ -1,134 +1,141 @@
1
1
  {
2
- "name": "@aws-amplify/datastore",
3
- "version": "4.7.5",
4
- "description": "AppSyncLocal support for aws-amplify",
5
- "main": "./lib/index.js",
6
- "module": "./lib-esm/index.js",
7
- "typings": "./lib-esm/index.d.ts",
8
- "react-native": {
9
- "./lib/index": "./lib-esm/index.js"
10
- },
11
- "publishConfig": {
12
- "access": "public"
13
- },
14
- "sideEffects": [
15
- "./lib/datastore/datastore.js",
16
- "./lib-esm/datastore/datastore.js"
17
- ],
18
- "scripts": {
19
- "test": "npm run lint && jest -w 1 --coverage",
20
- "test:size": "size-limit",
21
- "build-with-test": "npm test && npm run build",
22
- "build:cjs": "node ./build es5 && webpack && webpack --config ./webpack.config.dev.js",
23
- "build:esm": "node ./build es6",
24
- "build:cjs:watch": "node ./build es5 --watch",
25
- "build:esm:watch": "rimraf lib-esm && node ./build es6 --watch",
26
- "build": "yarn clean && yarn build:esm && npm run build:cjs",
27
- "clean": "npm run clean:size && rimraf lib-esm lib dist",
28
- "clean:size": "rimraf dual-publish-tmp tmp*",
29
- "format": "echo \"Not implemented\" && npm run ts-coverage",
30
- "lint": "tslint '{__tests__,src}/**/*.ts' && npm run ts-coverage",
31
- "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 92.05"
32
- },
33
- "repository": {
34
- "type": "git",
35
- "url": "https://github.com/aws-amplify/amplify-js.git"
36
- },
37
- "author": "Amazon Web Services",
38
- "license": "Apache-2.0",
39
- "bugs": {
40
- "url": "https://github.com/aws/aws-amplify/issues"
41
- },
42
- "homepage": "https://aws-amplify.github.io/",
43
- "devDependencies": {
44
- "@react-native-community/netinfo": "4.7.0",
45
- "@types/uuid": "3.4.6",
46
- "@types/uuid-validate": "^0.0.1",
47
- "dexie": "3.2.2",
48
- "dexie-export-import": "1.0.3",
49
- "fake-indexeddb": "3.0.0"
50
- },
51
- "files": [
52
- "lib",
53
- "lib-esm",
54
- "src",
55
- "ssr"
56
- ],
57
- "dependencies": {
58
- "@aws-amplify/api": "5.4.5",
59
- "@aws-amplify/auth": "5.6.5",
60
- "@aws-amplify/core": "5.8.5",
61
- "@aws-amplify/pubsub": "5.5.5",
62
- "amazon-cognito-identity-js": "6.3.6",
63
- "buffer": "4.9.2",
64
- "idb": "5.0.6",
65
- "immer": "9.0.6",
66
- "ulid": "2.3.0",
67
- "uuid": "3.4.0",
68
- "zen-observable-ts": "0.8.19",
69
- "zen-push": "0.2.1"
70
- },
71
- "size-limit": [
72
- {
73
- "name": "DataStore (top-level class)",
74
- "path": "./lib-esm/index.js",
75
- "import": "{ Amplify, DataStore }",
76
- "limit": "137 kB"
77
- }
78
- ],
79
- "jest": {
80
- "globals": {
81
- "ts-jest": {
82
- "diagnostics": true,
83
- "tsConfig": {
84
- "lib": [
85
- "es5",
86
- "es2015",
87
- "dom",
88
- "esnext.asynciterable",
89
- "es2019"
90
- ],
91
- "target": "es5",
92
- "allowJs": true,
93
- "esModuleInterop": true,
94
- "downlevelIteration": true,
95
- "strictNullChecks": true
96
- }
97
- }
98
- },
99
- "transform": {
100
- "^.+\\.(js|jsx|ts|tsx)$": "ts-jest"
101
- },
102
- "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
103
- "testPathIgnorePatterns": [
104
- "__tests__/model.ts",
105
- "__tests__/schema.ts",
106
- "__tests__/helpers/",
107
- "__tests__/commonAdapterTests.ts"
108
- ],
109
- "moduleFileExtensions": [
110
- "ts",
111
- "tsx",
112
- "js",
113
- "json",
114
- "jsx"
115
- ],
116
- "testEnvironment": "jsdom",
117
- "testURL": "http://localhost/",
118
- "coverageThreshold": {
119
- "global": {
120
- "branches": 0,
121
- "functions": 0,
122
- "lines": 0,
123
- "statements": 0
124
- }
125
- },
126
- "coveragePathIgnorePatterns": [
127
- "/node_modules/",
128
- "dist",
129
- "lib",
130
- "lib-esm"
131
- ]
132
- },
133
- "gitHead": "c3a06153e3ffe05dd65485a22b1f99aabe9b3d83"
2
+ "name": "@aws-amplify/datastore",
3
+ "version": "5.0.1-console-preview.4432977.0+4432977",
4
+ "description": "AppSyncLocal support for aws-amplify",
5
+ "main": "./lib/index.js",
6
+ "module": "./lib-esm/index.js",
7
+ "typings": "./lib-esm/index.d.ts",
8
+ "react-native": {
9
+ "./lib/index": "./lib-esm/index.js"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "sideEffects": [
15
+ "./lib/datastore/datastore.js",
16
+ "./lib-esm/datastore/datastore.js"
17
+ ],
18
+ "scripts": {
19
+ "test": "npm run lint && jest -w 1 --coverage",
20
+ "test:size": "size-limit",
21
+ "build-with-test": "npm test && npm run build",
22
+ "build:cjs": "rimraf lib && tsc -m commonjs --outDir lib && webpack && webpack --config ./webpack.config.dev.js",
23
+ "build:esm": "rimraf lib-esm && tsc -m esnext --outDir lib-esm",
24
+ "build:cjs:watch": "rimraf lib && tsc -m commonjs --outDir lib --watch",
25
+ "build:esm:watch": "rimraf lib-esm && tsc -m esnext --outDir lib-esm --watch",
26
+ "build": "yarn clean && yarn build:esm && npm run build:cjs",
27
+ "clean": "npm run clean:size && rimraf lib-esm lib dist",
28
+ "clean:size": "rimraf dual-publish-tmp tmp*",
29
+ "format": "echo \"Not implemented\" && npm run ts-coverage",
30
+ "lint": "tslint '{__tests__,src}/**/*.ts' && npm run ts-coverage",
31
+ "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 92.05"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/aws-amplify/amplify-js.git"
36
+ },
37
+ "author": "Amazon Web Services",
38
+ "license": "Apache-2.0",
39
+ "bugs": {
40
+ "url": "https://github.com/aws/aws-amplify/issues"
41
+ },
42
+ "homepage": "https://aws-amplify.github.io/",
43
+ "files": [
44
+ "lib",
45
+ "lib-esm",
46
+ "src",
47
+ "ssr"
48
+ ],
49
+ "dependencies": {
50
+ "@aws-amplify/api": "6.0.1-console-preview.4432977.0+4432977",
51
+ "@aws-amplify/auth": "6.0.1-console-preview.4432977.0+4432977",
52
+ "buffer": "4.9.2",
53
+ "idb": "5.0.6",
54
+ "immer": "9.0.6",
55
+ "ulid": "^2.3.0",
56
+ "uuid": "^9.0.0",
57
+ "zen-observable-ts": "0.8.19",
58
+ "zen-push": "0.2.1"
59
+ },
60
+ "peerDependencies": {
61
+ "@aws-amplify/core": "6.0.1-console-preview.4432977.0+4432977"
62
+ },
63
+ "devDependencies": {
64
+ "@aws-amplify/core": "6.0.1-console-preview.4432977.0+4432977",
65
+ "@react-native-community/netinfo": "4.7.0",
66
+ "@types/uuid": "^9.0.0",
67
+ "@types/uuid-validate": "^0.0.1",
68
+ "dexie": "3.2.2",
69
+ "dexie-export-import": "1.0.3",
70
+ "fake-indexeddb": "3.0.0",
71
+ "typescript": "5.0.2"
72
+ },
73
+ "size-limit": [
74
+ {
75
+ "name": "DataStore (top-level class)",
76
+ "path": "./lib-esm/index.js",
77
+ "import": "{ Amplify, DataStore }",
78
+ "limit": "137 kB"
79
+ }
80
+ ],
81
+ "jest": {
82
+ "globals": {
83
+ "ts-jest": {
84
+ "diagnostics": true,
85
+ "tsConfig": {
86
+ "lib": [
87
+ "es5",
88
+ "es2015",
89
+ "dom",
90
+ "esnext.asynciterable",
91
+ "es2019"
92
+ ],
93
+ "target": "es5",
94
+ "allowJs": true,
95
+ "esModuleInterop": true,
96
+ "strictNullChecks": false,
97
+ "types": [
98
+ "@types/jest"
99
+ ]
100
+ }
101
+ }
102
+ },
103
+ "transform": {
104
+ "^.+\\.(js|jsx|ts|tsx)$": "ts-jest"
105
+ },
106
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
107
+ "testPathIgnorePatterns": [
108
+ "__tests__/model.ts",
109
+ "__tests__/schema.ts",
110
+ "__tests__/helpers/",
111
+ "__tests__/commonAdapterTests.ts",
112
+ "__tests__/DataStore.ts",
113
+ "__tests__/connectivityHandling.test.ts",
114
+ "__tests__/mutation.test.ts"
115
+ ],
116
+ "moduleFileExtensions": [
117
+ "ts",
118
+ "tsx",
119
+ "js",
120
+ "json",
121
+ "jsx"
122
+ ],
123
+ "testEnvironment": "jsdom",
124
+ "testURL": "http://localhost/",
125
+ "coverageThreshold": {
126
+ "global": {
127
+ "branches": 0,
128
+ "functions": 0,
129
+ "lines": 0,
130
+ "statements": 0
131
+ }
132
+ },
133
+ "coveragePathIgnorePatterns": [
134
+ "/node_modules/",
135
+ "dist",
136
+ "lib",
137
+ "lib-esm"
138
+ ]
139
+ },
140
+ "gitHead": "4432977940335c2e9fe48cc9415350c4c44ef0eb"
134
141
  }
@@ -1,7 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { Auth } from '@aws-amplify/auth';
4
- import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
3
+ import { fetchAuthSession } from '@aws-amplify/core';
5
4
  import {
6
5
  AuthModeStrategy,
7
6
  ModelAttributeAuthProperty,
@@ -9,6 +8,7 @@ import {
9
8
  ModelAttributeAuthAllow,
10
9
  AmplifyContext,
11
10
  } from '../types';
11
+ import { GraphQLAuthModeKeys } from '@aws-amplify/core/internals/utils';
12
12
 
13
13
  function getProviderFromRule(
14
14
  rule: ModelAttributeAuthProperty
@@ -63,7 +63,7 @@ function getAuthRules({
63
63
  currentUser: unknown;
64
64
  }) {
65
65
  // Using Set to ensure uniqueness
66
- const authModes = new Set<GRAPHQL_AUTH_MODE>();
66
+ const authModes = new Set<GraphQLAuthModeKeys>();
67
67
 
68
68
  rules.forEach(rule => {
69
69
  switch (rule.allow) {
@@ -73,7 +73,7 @@ function getAuthRules({
73
73
  !rule.provider ||
74
74
  rule.provider === ModelAttributeAuthProvider.FUNCTION
75
75
  ) {
76
- authModes.add(GRAPHQL_AUTH_MODE.AWS_LAMBDA);
76
+ authModes.add('lambda');
77
77
  }
78
78
  break;
79
79
  case ModelAttributeAuthAllow.GROUPS:
@@ -81,9 +81,9 @@ function getAuthRules({
81
81
  // We shouldn't attempt User Pool or OIDC if there isn't an authenticated user
82
82
  if (currentUser) {
83
83
  if (rule.provider === ModelAttributeAuthProvider.USER_POOLS) {
84
- authModes.add(GRAPHQL_AUTH_MODE.AMAZON_COGNITO_USER_POOLS);
84
+ authModes.add('jwt');
85
85
  } else if (rule.provider === ModelAttributeAuthProvider.OIDC) {
86
- authModes.add(GRAPHQL_AUTH_MODE.OPENID_CONNECT);
86
+ authModes.add('jwt');
87
87
  }
88
88
  }
89
89
  break;
@@ -96,9 +96,9 @@ function getAuthRules({
96
96
  !rule.provider ||
97
97
  rule.provider === ModelAttributeAuthProvider.USER_POOLS
98
98
  ) {
99
- authModes.add(GRAPHQL_AUTH_MODE.AMAZON_COGNITO_USER_POOLS);
99
+ authModes.add('jwt');
100
100
  } else if (rule.provider === ModelAttributeAuthProvider.IAM) {
101
- authModes.add(GRAPHQL_AUTH_MODE.AWS_IAM);
101
+ authModes.add('iam');
102
102
  }
103
103
  }
104
104
 
@@ -106,13 +106,13 @@ function getAuthRules({
106
106
  }
107
107
  case ModelAttributeAuthAllow.PUBLIC: {
108
108
  if (rule.provider === ModelAttributeAuthProvider.IAM) {
109
- authModes.add(GRAPHQL_AUTH_MODE.AWS_IAM);
109
+ authModes.add('iam');
110
110
  } else if (
111
111
  !rule.provider ||
112
112
  rule.provider === ModelAttributeAuthProvider.API_KEY
113
113
  ) {
114
114
  // public with no provider means apiKey
115
- authModes.add(GRAPHQL_AUTH_MODE.API_KEY);
115
+ authModes.add('apiKey');
116
116
  }
117
117
  break;
118
118
  }
@@ -140,10 +140,9 @@ export const multiAuthStrategy: (
140
140
  ) => AuthModeStrategy =
141
141
  (amplifyContext: AmplifyContext) =>
142
142
  async ({ schema, modelName }) => {
143
- amplifyContext.Auth = amplifyContext.Auth || Auth;
144
143
  let currentUser;
145
144
  try {
146
- currentUser = await amplifyContext.Auth.currentAuthenticatedUser();
145
+ currentUser = await fetchAuthSession();
147
146
  } catch (e) {
148
147
  // No current user
149
148
  }