@aws-amplify/datastore 5.0.1-unstable.cfbde4c.0 → 5.0.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 (209) hide show
  1. package/{lib → dist/cjs}/authModeStrategies/defaultAuthStrategy.js +3 -1
  2. package/dist/cjs/authModeStrategies/defaultAuthStrategy.js.map +1 -0
  3. package/{lib → dist/cjs}/authModeStrategies/index.js +3 -1
  4. package/dist/cjs/authModeStrategies/index.js.map +1 -0
  5. package/{lib → dist/cjs}/authModeStrategies/multiAuthStrategy.js +3 -3
  6. package/dist/cjs/authModeStrategies/multiAuthStrategy.js.map +1 -0
  7. package/{lib → dist/cjs}/datastore/datastore.js +5 -3
  8. package/dist/cjs/datastore/datastore.js.map +1 -0
  9. package/{lib → dist/cjs}/index.js +5 -16
  10. package/dist/cjs/index.js.map +1 -0
  11. package/{lib → dist/cjs}/predicates/index.js +3 -1
  12. package/dist/cjs/predicates/index.js.map +1 -0
  13. package/{lib → dist/cjs}/predicates/next.js +3 -1
  14. package/dist/cjs/predicates/next.js.map +1 -0
  15. package/{lib → dist/cjs}/predicates/sort.js +4 -3
  16. package/dist/cjs/predicates/sort.js.map +1 -0
  17. package/{lib → dist/cjs}/storage/adapter/AsyncStorageAdapter.js +5 -5
  18. package/dist/cjs/storage/adapter/AsyncStorageAdapter.js.map +1 -0
  19. package/{lib → dist/cjs}/storage/adapter/AsyncStorageDatabase.js +3 -1
  20. package/dist/cjs/storage/adapter/AsyncStorageDatabase.js.map +1 -0
  21. package/{lib → dist/cjs}/storage/adapter/InMemoryStore.js +3 -1
  22. package/dist/cjs/storage/adapter/InMemoryStore.js.map +1 -0
  23. package/{lib → dist/cjs}/storage/adapter/InMemoryStore.native.js +5 -5
  24. package/dist/cjs/storage/adapter/InMemoryStore.native.js.map +1 -0
  25. package/{lib → dist/cjs}/storage/adapter/IndexedDBAdapter.js +5 -25
  26. package/dist/cjs/storage/adapter/IndexedDBAdapter.js.map +1 -0
  27. package/{lib → dist/cjs}/storage/adapter/StorageAdapterBase.js +3 -1
  28. package/dist/cjs/storage/adapter/StorageAdapterBase.js.map +1 -0
  29. package/{lib → dist/cjs}/storage/adapter/getDefaultAdapter/index.js +6 -6
  30. package/dist/cjs/storage/adapter/getDefaultAdapter/index.js.map +1 -0
  31. package/dist/cjs/storage/adapter/getDefaultAdapter/index.native.js +10 -0
  32. package/dist/cjs/storage/adapter/getDefaultAdapter/index.native.js.map +1 -0
  33. package/{lib → dist/cjs}/storage/adapter/index.js +3 -1
  34. package/dist/cjs/storage/adapter/index.js.map +1 -0
  35. package/{lib → dist/cjs}/storage/relationship.js +3 -1
  36. package/dist/cjs/storage/relationship.js.map +1 -0
  37. package/{lib → dist/cjs}/storage/storage.js +5 -5
  38. package/dist/cjs/storage/storage.js.map +1 -0
  39. package/{lib → dist/cjs}/sync/datastoreConnectivity.js +4 -2
  40. package/dist/cjs/sync/datastoreConnectivity.js.map +1 -0
  41. package/{lib → dist/cjs}/sync/datastoreReachability/index.js +3 -1
  42. package/dist/cjs/sync/datastoreReachability/index.js.map +1 -0
  43. package/{lib → dist/cjs}/sync/datastoreReachability/index.native.js +3 -1
  44. package/dist/cjs/sync/datastoreReachability/index.native.js.map +1 -0
  45. package/{lib → dist/cjs}/sync/index.js +6 -7
  46. package/dist/cjs/sync/index.js.map +1 -0
  47. package/{lib → dist/cjs}/sync/merger.js +3 -1
  48. package/dist/cjs/sync/merger.js.map +1 -0
  49. package/{lib → dist/cjs}/sync/outbox.js +3 -1
  50. package/dist/cjs/sync/outbox.js.map +1 -0
  51. package/{lib → dist/cjs}/sync/processors/errorMaps.js +4 -4
  52. package/dist/cjs/sync/processors/errorMaps.js.map +1 -0
  53. package/{lib → dist/cjs}/sync/processors/mutation.js +3 -1
  54. package/dist/cjs/sync/processors/mutation.js.map +1 -0
  55. package/{lib → dist/cjs}/sync/processors/subscription.js +4 -4
  56. package/dist/cjs/sync/processors/subscription.js.map +1 -0
  57. package/{lib → dist/cjs}/sync/processors/sync.js +3 -1
  58. package/dist/cjs/sync/processors/sync.js.map +1 -0
  59. package/{lib → dist/cjs}/sync/utils.js +3 -1
  60. package/dist/cjs/sync/utils.js.map +1 -0
  61. package/{lib → dist/cjs}/types.js +12 -21
  62. package/dist/cjs/types.js.map +1 -0
  63. package/{lib → dist/cjs}/util.js +3 -1
  64. package/dist/cjs/util.js.map +1 -0
  65. package/{lib-esm/authModeStrategies/defaultAuthStrategy.js → dist/esm/authModeStrategies/defaultAuthStrategy.mjs} +4 -1
  66. package/dist/esm/authModeStrategies/defaultAuthStrategy.mjs.map +1 -0
  67. package/dist/esm/authModeStrategies/index.mjs +3 -0
  68. package/dist/esm/authModeStrategies/index.mjs.map +1 -0
  69. package/{lib-esm/authModeStrategies/multiAuthStrategy.js → dist/esm/authModeStrategies/multiAuthStrategy.mjs} +7 -5
  70. package/dist/esm/authModeStrategies/multiAuthStrategy.mjs.map +1 -0
  71. package/{lib-esm/datastore/datastore.js → dist/esm/datastore/datastore.mjs} +30 -26
  72. package/dist/esm/datastore/datastore.mjs.map +1 -0
  73. package/dist/esm/index.mjs +19 -0
  74. package/dist/esm/index.mjs.map +1 -0
  75. package/{lib-esm/predicates/index.js → dist/esm/predicates/index.mjs} +10 -7
  76. package/dist/esm/predicates/index.mjs.map +1 -0
  77. package/{lib-esm/predicates/next.js → dist/esm/predicates/next.mjs} +15 -11
  78. package/dist/esm/predicates/next.mjs.map +1 -0
  79. package/{lib-esm/predicates/sort.js → dist/esm/predicates/sort.mjs} +3 -2
  80. package/dist/esm/predicates/sort.mjs.map +1 -0
  81. package/{lib-esm/storage/adapter/AsyncStorageAdapter.js → dist/esm/storage/adapter/AsyncStorageAdapter.mjs} +10 -6
  82. package/dist/esm/storage/adapter/AsyncStorageAdapter.mjs.map +1 -0
  83. package/{lib-esm/storage/adapter/AsyncStorageDatabase.js → dist/esm/storage/adapter/AsyncStorageDatabase.mjs} +7 -4
  84. package/dist/esm/storage/adapter/AsyncStorageDatabase.mjs.map +1 -0
  85. package/{lib-esm/storage/adapter/InMemoryStore.js → dist/esm/storage/adapter/InMemoryStore.mjs} +5 -2
  86. package/dist/esm/storage/adapter/InMemoryStore.mjs.map +1 -0
  87. package/{lib-esm/storage/adapter/InMemoryStore.native.js → dist/esm/storage/adapter/InMemoryStore.native.mjs} +6 -2
  88. package/dist/esm/storage/adapter/InMemoryStore.native.mjs.map +1 -0
  89. package/{lib-esm/storage/adapter/IndexedDBAdapter.js → dist/esm/storage/adapter/IndexedDBAdapter.mjs} +10 -6
  90. package/dist/esm/storage/adapter/IndexedDBAdapter.mjs.map +1 -0
  91. package/{lib-esm/storage/adapter/StorageAdapterBase.js → dist/esm/storage/adapter/StorageAdapterBase.mjs} +9 -5
  92. package/dist/esm/storage/adapter/StorageAdapterBase.mjs.map +1 -0
  93. package/dist/esm/storage/adapter/getDefaultAdapter/index.mjs +13 -0
  94. package/dist/esm/storage/adapter/getDefaultAdapter/index.mjs.map +1 -0
  95. package/dist/esm/storage/adapter/getDefaultAdapter/index.native.mjs +8 -0
  96. package/dist/esm/storage/adapter/getDefaultAdapter/index.native.mjs.map +1 -0
  97. package/dist/esm/storage/adapter/index.mjs +2 -0
  98. package/dist/esm/storage/adapter/index.mjs.map +1 -0
  99. package/{lib-esm/storage/relationship.js → dist/esm/storage/relationship.mjs} +6 -2
  100. package/dist/esm/storage/relationship.mjs.map +1 -0
  101. package/{lib-esm/storage/storage.js → dist/esm/storage/storage.mjs} +11 -8
  102. package/dist/esm/storage/storage.mjs.map +1 -0
  103. package/{lib-esm/sync/datastoreConnectivity.js → dist/esm/sync/datastoreConnectivity.mjs} +9 -5
  104. package/dist/esm/sync/datastoreConnectivity.mjs.map +1 -0
  105. package/dist/esm/sync/datastoreReachability/index.d.ts +1 -0
  106. package/{lib-esm/sync/datastoreReachability/index.js → dist/esm/sync/datastoreReachability/index.mjs} +6 -2
  107. package/dist/esm/sync/datastoreReachability/index.mjs.map +1 -0
  108. package/dist/esm/sync/datastoreReachability/index.native.d.ts +1 -0
  109. package/{lib-esm/sync/datastoreReachability/index.native.js → dist/esm/sync/datastoreReachability/index.native.mjs} +7 -3
  110. package/dist/esm/sync/datastoreReachability/index.native.mjs.map +1 -0
  111. package/{lib-esm/sync/index.js → dist/esm/sync/index.mjs} +24 -21
  112. package/dist/esm/sync/index.mjs.map +1 -0
  113. package/{lib-esm/sync/merger.js → dist/esm/sync/merger.mjs} +5 -2
  114. package/dist/esm/sync/merger.mjs.map +1 -0
  115. package/{lib-esm/sync/outbox.js → dist/esm/sync/outbox.mjs} +7 -4
  116. package/dist/esm/sync/outbox.mjs.map +1 -0
  117. package/{lib-esm/sync/processors/errorMaps.js → dist/esm/sync/processors/errorMaps.mjs} +13 -11
  118. package/dist/esm/sync/processors/errorMaps.mjs.map +1 -0
  119. package/{lib → dist/esm}/sync/processors/mutation.d.ts +1 -1
  120. package/{lib-esm/sync/processors/mutation.js → dist/esm/sync/processors/mutation.mjs} +10 -7
  121. package/dist/esm/sync/processors/mutation.mjs.map +1 -0
  122. package/{lib-esm/sync/processors/subscription.js → dist/esm/sync/processors/subscription.mjs} +18 -17
  123. package/dist/esm/sync/processors/subscription.mjs.map +1 -0
  124. package/{lib-esm/sync/processors/sync.js → dist/esm/sync/processors/sync.mjs} +8 -5
  125. package/dist/esm/sync/processors/sync.mjs.map +1 -0
  126. package/{lib-esm/sync/utils.js → dist/esm/sync/utils.mjs} +30 -26
  127. package/dist/esm/sync/utils.mjs.map +1 -0
  128. package/{lib-esm/types.js → dist/esm/types.mjs} +34 -30
  129. package/dist/esm/types.mjs.map +1 -0
  130. package/{lib-esm/util.js → dist/esm/util.mjs} +61 -57
  131. package/dist/esm/util.mjs.map +1 -0
  132. package/package.json +133 -137
  133. package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
  134. package/lib/authModeStrategies/index.d.ts +0 -2
  135. package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -13
  136. package/lib/datastore/datastore.d.ts +0 -231
  137. package/lib/index.d.ts +0 -16
  138. package/lib/predicates/index.d.ts +0 -100
  139. package/lib/predicates/next.d.ts +0 -317
  140. package/lib/predicates/sort.d.ts +0 -8
  141. package/lib/ssr/index.d.ts +0 -3
  142. package/lib/ssr/index.js +0 -18
  143. package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -40
  144. package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -39
  145. package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
  146. package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
  147. package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -70
  148. package/lib/storage/adapter/StorageAdapterBase.d.ts +0 -134
  149. package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
  150. package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
  151. package/lib/storage/adapter/getDefaultAdapter/index.native.js +0 -10
  152. package/lib/storage/adapter/index.d.ts +0 -9
  153. package/lib/storage/relationship.d.ts +0 -149
  154. package/lib/storage/storage.d.ts +0 -50
  155. package/lib/sync/datastoreConnectivity.d.ts +0 -16
  156. package/lib/sync/datastoreReachability/index.d.ts +0 -1
  157. package/lib/sync/datastoreReachability/index.native.d.ts +0 -1
  158. package/lib/sync/index.d.ts +0 -103
  159. package/lib/sync/merger.d.ts +0 -17
  160. package/lib/sync/outbox.d.ts +0 -27
  161. package/lib/sync/processors/errorMaps.d.ts +0 -17
  162. package/lib/sync/processors/subscription.d.ts +0 -42
  163. package/lib/sync/processors/sync.d.ts +0 -28
  164. package/lib/sync/utils.d.ts +0 -107
  165. package/lib/tsconfig.tsbuildinfo +0 -1
  166. package/lib/types.d.ts +0 -641
  167. package/lib/util.d.ts +0 -196
  168. package/lib-esm/authModeStrategies/index.js +0 -4
  169. package/lib-esm/index.js +0 -14
  170. package/lib-esm/ssr/index.d.ts +0 -3
  171. package/lib-esm/ssr/index.js +0 -13
  172. package/lib-esm/storage/adapter/getDefaultAdapter/index.js +0 -10
  173. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -5
  174. package/lib-esm/storage/adapter/index.js +0 -1
  175. package/lib-esm/sync/datastoreReachability/index.d.ts +0 -1
  176. package/lib-esm/sync/datastoreReachability/index.native.d.ts +0 -1
  177. package/lib-esm/sync/processors/mutation.d.ts +0 -67
  178. package/lib-esm/tsconfig.tsbuildinfo +0 -1
  179. package/src/ssr/index.ts +0 -27
  180. package/ssr/package.json +0 -8
  181. /package/{lib-esm → dist/esm}/authModeStrategies/defaultAuthStrategy.d.ts +0 -0
  182. /package/{lib-esm → dist/esm}/authModeStrategies/index.d.ts +0 -0
  183. /package/{lib-esm → dist/esm}/authModeStrategies/multiAuthStrategy.d.ts +0 -0
  184. /package/{lib-esm → dist/esm}/datastore/datastore.d.ts +0 -0
  185. /package/{lib-esm → dist/esm}/index.d.ts +0 -0
  186. /package/{lib-esm → dist/esm}/predicates/index.d.ts +0 -0
  187. /package/{lib-esm → dist/esm}/predicates/next.d.ts +0 -0
  188. /package/{lib-esm → dist/esm}/predicates/sort.d.ts +0 -0
  189. /package/{lib-esm → dist/esm}/storage/adapter/AsyncStorageAdapter.d.ts +0 -0
  190. /package/{lib-esm → dist/esm}/storage/adapter/AsyncStorageDatabase.d.ts +0 -0
  191. /package/{lib-esm → dist/esm}/storage/adapter/InMemoryStore.d.ts +0 -0
  192. /package/{lib-esm → dist/esm}/storage/adapter/InMemoryStore.native.d.ts +0 -0
  193. /package/{lib-esm → dist/esm}/storage/adapter/IndexedDBAdapter.d.ts +0 -0
  194. /package/{lib-esm → dist/esm}/storage/adapter/StorageAdapterBase.d.ts +0 -0
  195. /package/{lib-esm → dist/esm}/storage/adapter/getDefaultAdapter/index.d.ts +0 -0
  196. /package/{lib-esm → dist/esm}/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -0
  197. /package/{lib-esm → dist/esm}/storage/adapter/index.d.ts +0 -0
  198. /package/{lib-esm → dist/esm}/storage/relationship.d.ts +0 -0
  199. /package/{lib-esm → dist/esm}/storage/storage.d.ts +0 -0
  200. /package/{lib-esm → dist/esm}/sync/datastoreConnectivity.d.ts +0 -0
  201. /package/{lib-esm → dist/esm}/sync/index.d.ts +0 -0
  202. /package/{lib-esm → dist/esm}/sync/merger.d.ts +0 -0
  203. /package/{lib-esm → dist/esm}/sync/outbox.d.ts +0 -0
  204. /package/{lib-esm → dist/esm}/sync/processors/errorMaps.d.ts +0 -0
  205. /package/{lib-esm → dist/esm}/sync/processors/subscription.d.ts +0 -0
  206. /package/{lib-esm → dist/esm}/sync/processors/sync.d.ts +0 -0
  207. /package/{lib-esm → dist/esm}/sync/utils.d.ts +0 -0
  208. /package/{lib-esm → dist/esm}/types.d.ts +0 -0
  209. /package/{lib-esm → dist/esm}/util.d.ts +0 -0
@@ -1,317 +0,0 @@
1
- import { PersistentModel, ModelMeta, ModelPredicate as StoragePredicate, PredicateInternalsKey, V5ModelPredicate as ModelPredicate, RecursiveModelPredicate } from '../types';
2
- import { ExclusiveStorage as StorageAdapter } from '../storage/storage';
3
- type GroupOperator = 'and' | 'or' | 'not';
4
- type UntypedCondition = {
5
- fetch: (storage: StorageAdapter) => Promise<Record<string, any>[]>;
6
- matches: (item: Record<string, any>) => Promise<boolean>;
7
- copy(extract?: GroupCondition): [UntypedCondition, GroupCondition | undefined];
8
- toAST(): any;
9
- };
10
- /**
11
- * Takes a key object from `registerPredicateInternals()` to fetch an internal
12
- * `GroupCondition` object, which can then be used to query storage or
13
- * test/match objects.
14
- *
15
- * This indirection exists to hide `GroupCondition` from public interfaces, since
16
- * `GroupCondition` contains extra methods and properties that public callers
17
- * should not use.
18
- *
19
- * @param key A key object previously returned by `registerPredicateInternals()`
20
- */
21
- export declare const internals: (key: any) => GroupCondition;
22
- /**
23
- * A condition that can operate against a single "primitive" field of a model or item.
24
- * @member field The field of *some record* to test against.
25
- * @member operator The equality or comparison operator to use.
26
- * @member operands The operands for the equality/comparison check.
27
- */
28
- export declare class FieldCondition {
29
- field: string;
30
- operator: string;
31
- operands: string[];
32
- constructor(field: string, operator: string, operands: string[]);
33
- /**
34
- * Creates a copy of self.
35
- * @param extract Not used. Present only to fulfill the `UntypedCondition` interface.
36
- * @returns A new, identitical `FieldCondition`.
37
- */
38
- copy(extract?: GroupCondition): [FieldCondition, GroupCondition | undefined];
39
- /**
40
- * Produces a tree structure similar to a graphql condition. The returned
41
- * structure is "dumb" and is intended for another query/condition
42
- * generation mechanism to interpret, such as the cloud or storage query
43
- * builders.
44
- *
45
- * E.g.,
46
- *
47
- * ```json
48
- * {
49
- * "name": {
50
- * "eq": "robert"
51
- * }
52
- * }
53
- * ```
54
- */
55
- toAST(): {
56
- [x: string]: {
57
- [x: string]: string | string[];
58
- };
59
- };
60
- /**
61
- * Produces a new condition (`FieldCondition` or `GroupCondition`) that
62
- * matches the opposite of this condition.
63
- *
64
- * Intended to be used when applying De Morgan's Law, which can be done to
65
- * produce more efficient queries against the storage layer if a negation
66
- * appears in the query tree.
67
- *
68
- * For example:
69
- *
70
- * 1. `name.eq('robert')` becomes `name.ne('robert')`
71
- * 2. `price.between(100, 200)` becomes `m => m.or(m => [m.price.lt(100), m.price.gt(200)])`
72
- *
73
- * @param model The model meta to use when construction a new `GroupCondition`
74
- * for cases where the negation requires multiple `FieldCondition`'s.
75
- */
76
- negated(model: ModelMeta<any>): GroupCondition | FieldCondition;
77
- /**
78
- * Not implemented. Not needed. GroupCondition instead consumes FieldConditions and
79
- * transforms them into legacy predicates. (*For now.*)
80
- * @param storage N/A. If ever implemented, the storage adapter to query.
81
- * @returns N/A. If ever implemented, return items from `storage` that match.
82
- */
83
- fetch(storage: StorageAdapter): Promise<Record<string, any>[]>;
84
- /**
85
- * Determins whether a given item matches the expressed condition.
86
- * @param item The item to test.
87
- * @returns `Promise<boolean>`, `true` if matches; `false` otherwise.
88
- */
89
- matches(item: Record<string, any>): Promise<boolean>;
90
- /**
91
- * Checks `this.operands` for compatibility with `this.operator`.
92
- */
93
- validate(): void;
94
- }
95
- /**
96
- * A set of sub-conditions to operate against a model, optionally scoped to
97
- * a specific field, combined with the given operator (one of `and`, `or`, or `not`).
98
- * @member groupId Used to distinguish between GroupCondition instances for
99
- * debugging and troublehsooting.
100
- * @member model A metadata object that tells GroupCondition what to query and how.
101
- * @member field The field on the model that the sub-conditions apply to.
102
- * @member operator How to group child conditions together.
103
- * @member operands The child conditions.
104
- */
105
- export declare class GroupCondition {
106
- /**
107
- * The `ModelMeta` of the model to query and/or filter against.
108
- * Expected to contain:
109
- *
110
- * ```js
111
- * {
112
- * builder: ModelConstructor,
113
- * schema: SchemaModel,
114
- * pkField: string[]
115
- * }
116
- * ```
117
- */
118
- model: ModelMeta<any>;
119
- /**
120
- * If populated, this group specifices a condition on a relationship.
121
- *
122
- * If `field` does *not* point to a related model, that's an error. It
123
- * could indicate that the `GroupCondition` was instantiated with bad
124
- * data, or that the model metadata is incorrect.
125
- */
126
- field: string | undefined;
127
- /**
128
- * If a `field` is given, whether the relationship is a `HAS_ONE`,
129
- * 'HAS_MANY`, or `BELONGS_TO`.
130
- *
131
- * TODO: Remove this and replace with derivation using
132
- * `ModelRelationship.from(this.model, this.field).relationship`;
133
- */
134
- relationshipType: string | undefined;
135
- /**
136
- *
137
- */
138
- operator: GroupOperator;
139
- /**
140
- *
141
- */
142
- operands: UntypedCondition[];
143
- /**
144
- * Whether this GroupCondition is the result of an optimize call.
145
- *
146
- * This is used to guard against infinitely fetch -> optimize -> fetch
147
- * recursion.
148
- */
149
- isOptimized: boolean;
150
- groupId: string;
151
- constructor(
152
- /**
153
- * The `ModelMeta` of the model to query and/or filter against.
154
- * Expected to contain:
155
- *
156
- * ```js
157
- * {
158
- * builder: ModelConstructor,
159
- * schema: SchemaModel,
160
- * pkField: string[]
161
- * }
162
- * ```
163
- */
164
- model: ModelMeta<any>,
165
- /**
166
- * If populated, this group specifices a condition on a relationship.
167
- *
168
- * If `field` does *not* point to a related model, that's an error. It
169
- * could indicate that the `GroupCondition` was instantiated with bad
170
- * data, or that the model metadata is incorrect.
171
- */
172
- field: string | undefined,
173
- /**
174
- * If a `field` is given, whether the relationship is a `HAS_ONE`,
175
- * 'HAS_MANY`, or `BELONGS_TO`.
176
- *
177
- * TODO: Remove this and replace with derivation using
178
- * `ModelRelationship.from(this.model, this.field).relationship`;
179
- */
180
- relationshipType: string | undefined,
181
- /**
182
- *
183
- */
184
- operator: GroupOperator,
185
- /**
186
- *
187
- */
188
- operands: UntypedCondition[],
189
- /**
190
- * Whether this GroupCondition is the result of an optimize call.
191
- *
192
- * This is used to guard against infinitely fetch -> optimize -> fetch
193
- * recursion.
194
- */
195
- isOptimized?: boolean);
196
- /**
197
- * Returns a copy of a GroupCondition, which also returns the copy of a
198
- * given reference node to "extract".
199
- * @param extract A node of interest. Its copy will *also* be returned if the node exists.
200
- * @returns [The full copy, the copy of `extract` | undefined]
201
- */
202
- copy(extract?: GroupCondition): [GroupCondition, GroupCondition | undefined];
203
- /**
204
- * Creates a new `GroupCondition` that contains only the local field conditions,
205
- * omitting related model conditions. That resulting `GroupCondition` can be
206
- * used to produce predicates that are compatible with the storage adapters and
207
- * Cloud storage.
208
- *
209
- * @param negate Whether the condition tree should be negated according
210
- * to De Morgan's law.
211
- */
212
- withFieldConditionsOnly(negate: boolean): GroupCondition;
213
- /**
214
- * Returns a version of the predicate tree with unnecessary logical groups
215
- * condensed and merged together. This is intended to create a dense tree
216
- * with leaf nodes (`FieldCondition`'s) aggregated under as few group conditions
217
- * as possible for the most efficient fetching possible -- it allows `fetch()`.
218
- *
219
- * E.g. a grouping like this:
220
- *
221
- * ```yaml
222
- * and:
223
- * and:
224
- * id:
225
- * eq: "abc"
226
- * and:
227
- * name:
228
- * eq: "xyz"
229
- * ```
230
- *
231
- * Will become this:
232
- *
233
- * ```yaml
234
- * and:
235
- * id:
236
- * eq: "abc"
237
- * name:
238
- * eq: "xyz"
239
- * ```
240
- *
241
- * This allows `fetch()` to pass both the `id` and `name` conditions to the adapter
242
- * together, which can then decide what index to use based on both fields together.
243
- *
244
- * @param preserveNode Whether to preserve the current node and to explicitly not eliminate
245
- * it during optimization. Used internally to preserve the root node and children of
246
- * `not` groups. `not` groups will always have a single child, so there's nothing to
247
- * optimize below a `not` (for now), and it makes the query logic simpler later.
248
- */
249
- optimized(preserveNode?: boolean): UntypedCondition;
250
- /**
251
- * Fetches matching records from a given storage adapter using legacy predicates (for now).
252
- * @param storage The storage adapter this predicate will query against.
253
- * @param breadcrumb For debugging/troubleshooting. A list of the `groupId`'s this
254
- * GroupdCondition.fetch is nested within.
255
- * @param negate Whether to match on the `NOT` of `this`.
256
- * @returns An `Promise` of `any[]` from `storage` matching the child conditions.
257
- */
258
- fetch(storage: StorageAdapter, breadcrumb?: string[], negate?: boolean): Promise<Record<string, any>[]>;
259
- /**
260
- * Determines whether a single item matches the conditions of `this`.
261
- * When checking the target `item`'s properties, each property will be `await`'d
262
- * to ensure lazy-loading is respected where applicable.
263
- * @param item The item to match against.
264
- * @param ignoreFieldName Tells `match()` that the field name has already been dereferenced.
265
- * (Used for iterating over children on HAS_MANY checks.)
266
- * @returns A boolean (promise): `true` if matched, `false` otherwise.
267
- */
268
- matches(item: Record<string, any>, ignoreFieldName?: boolean): Promise<boolean>;
269
- /**
270
- * Tranfsorm to a AppSync GraphQL compatible AST.
271
- * (Does not support filtering in nested types.)
272
- */
273
- toAST(): {
274
- [x: string]: any[];
275
- };
276
- /**
277
- * Turn this predicate group into something a storage adapter
278
- * understands how to use.
279
- */
280
- toStoragePredicate<T>(): StoragePredicate<T>;
281
- /**
282
- * A JSON representation that's good for debugging.
283
- */
284
- toJSON(): this & {
285
- model: string;
286
- };
287
- }
288
- /**
289
- * Creates a "seed" predicate that can be used to build an executable condition.
290
- * This is used in `query()`, for example, to seed customer- E.g.,
291
- *
292
- * ```
293
- * const p = predicateFor({builder: modelConstructor, schema: modelSchema, pkField: string[]});
294
- * p.and(child => [
295
- * child.field.eq('whatever'),
296
- * child.childModel.childField.eq('whatever else'),
297
- * child.childModel.or(child => [
298
- * child.otherField.contains('x'),
299
- * child.otherField.contains('y'),
300
- * child.otherField.contains('z'),
301
- * ])
302
- * ])
303
- * ```
304
- *
305
- * `predicateFor()` returns objecst with recursive getters. To facilitate this,
306
- * a `query` and `tail` can be provided to "accumulate" nested conditions.
307
- *
308
- * @param ModelType The ModelMeta used to build child properties.
309
- * @param field Scopes the query branch to a field.
310
- * @param query A base query to build on. Omit to start a new query.
311
- * @param tail The point in an existing `query` to attach new conditions to.
312
- * @returns A ModelPredicate (builder) that customers can create queries with.
313
- * (As shown in function description.)
314
- */
315
- export declare function recursivePredicateFor<T extends PersistentModel>(ModelType: ModelMeta<T>, allowRecursion?: boolean, field?: string, query?: GroupCondition, tail?: GroupCondition): RecursiveModelPredicate<T> & PredicateInternalsKey;
316
- export declare function predicateFor<T extends PersistentModel>(ModelType: ModelMeta<T>): ModelPredicate<T> & PredicateInternalsKey;
317
- export {};
@@ -1,8 +0,0 @@
1
- import { PersistentModel, SchemaModel, SortPredicate, ProducerSortPredicate, SortPredicatesGroup } from '../types';
2
- export declare class ModelSortPredicateCreator {
3
- private static sortPredicateGroupsMap;
4
- private static createPredicateBuilder;
5
- static isValidPredicate<T extends PersistentModel>(predicate: any): predicate is SortPredicate<T>;
6
- static getPredicates<T extends PersistentModel>(predicate: SortPredicate<T>, throwOnInvalid?: boolean): SortPredicatesGroup<T>;
7
- static createFromExisting<T extends PersistentModel>(modelDefinition: SchemaModel, existing: ProducerSortPredicate<T>): SortPredicate<T>;
8
- }
@@ -1,3 +0,0 @@
1
- import { PersistentModel, PersistentModelConstructor } from '@aws-amplify/datastore';
2
- export declare function deserializeModel<T extends PersistentModel>(Model: PersistentModelConstructor<T>, init: T | T[]): any;
3
- export declare function serializeModel<T extends PersistentModel>(model: T | T[]): JSON;
package/lib/ssr/index.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeModel = exports.deserializeModel = void 0;
4
- // Helper for converting JSON back into DataStore models (while respecting IDs)
5
- function deserializeModel(Model, init) {
6
- if (Array.isArray(init)) {
7
- return init.map(init => deserializeModel(Model, init));
8
- }
9
- // `fromJSON` is intentionally hidden from types as a "private" method (though it exists on the instance)
10
- // @ts-ignore Property 'fromJSON' does not exist on type 'PersistentModelConstructor<T>'.ts(2339)
11
- return Model.fromJSON(init);
12
- }
13
- exports.deserializeModel = deserializeModel;
14
- // Helper for converting DataStore models to JSON
15
- function serializeModel(model) {
16
- return JSON.parse(JSON.stringify(model));
17
- }
18
- exports.serializeModel = serializeModel;
@@ -1,40 +0,0 @@
1
- import AsyncStorageDatabase from './AsyncStorageDatabase';
2
- import { ModelInstanceMetadata, ModelPredicate, OpType, PaginationInput, PersistentModel, PersistentModelConstructor, QueryOne } from '../../types';
3
- import { StorageAdapterBase } from './StorageAdapterBase';
4
- export declare class AsyncStorageAdapter extends StorageAdapterBase {
5
- protected db: AsyncStorageDatabase;
6
- protected preSetUpChecks(): Promise<void>;
7
- protected preOpCheck(): Promise<void>;
8
- /**
9
- * Open AsyncStorage database
10
- * Create new DB if one doesn't exist
11
- *
12
- * Called by `StorageAdapterBase.setUp()`
13
- *
14
- * @returns AsyncStorageDatabase instance
15
- */
16
- protected initDb(): Promise<AsyncStorageDatabase>;
17
- clear(): Promise<void>;
18
- batchSave<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<any>, items: ModelInstanceMetadata[]): Promise<[T, OpType][]>;
19
- protected _get<T>(storeName: string, keyArr: string[]): Promise<T>;
20
- save<T extends PersistentModel>(model: T, condition?: ModelPredicate<T>): Promise<[T, OpType.INSERT | OpType.UPDATE][]>;
21
- query<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, predicate?: ModelPredicate<T>, pagination?: PaginationInput<T>): Promise<T[]>;
22
- private getByKey;
23
- private getAll;
24
- private filterOnPredicate;
25
- private inMemoryPagination;
26
- queryOne<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, firstOrLast?: QueryOne): Promise<T | undefined>;
27
- protected deleteItem<T extends PersistentModel>(deleteQueue?: {
28
- storeName: string;
29
- items: T[] | IDBValidKey[];
30
- }[]): Promise<void>;
31
- /**
32
- * Retrieves concatenated primary key values from a model
33
- *
34
- * @param model
35
- * @returns
36
- */
37
- private getIndexKeyValuesPath;
38
- }
39
- declare const _default: AsyncStorageAdapter;
40
- export default _default;
@@ -1,39 +0,0 @@
1
- import { ModelInstanceMetadata, OpType, PaginationInput, PersistentModel, QueryOne } from '../../types';
2
- declare class AsyncStorageDatabase {
3
- /**
4
- * Maps storeNames to a map of ulid->id
5
- */
6
- private _collectionInMemoryIndex;
7
- private storage;
8
- /**
9
- * Collection index is map of stores (i.e. sync, metadata, mutation event, and data)
10
- * @param storeName {string} - Name of the store
11
- * @returns Map of ulid->id
12
- */
13
- private getCollectionIndex;
14
- /**
15
- * Return ULID for store if it exists, otherwise create a new one
16
- * @param storeName {string} - Name of the store
17
- * @returns ulid
18
- */
19
- private getMonotonicFactory;
20
- init(): Promise<void>;
21
- save<T extends PersistentModel>(item: T, storeName: string, keys: string[], keyValuesPath: string): Promise<void>;
22
- batchSave<T extends PersistentModel>(storeName: string, items: ModelInstanceMetadata[], keys: string[]): Promise<[T, OpType][]>;
23
- get<T extends PersistentModel>(keyValuePath: string, storeName: string): Promise<T>;
24
- getOne(firstOrLast: QueryOne, storeName: string): Promise<any>;
25
- /**
26
- * This function gets all the records stored in async storage for a particular storeName
27
- * It then loads all the records for that filtered set of keys using multiGet()
28
- */
29
- getAll<T extends PersistentModel>(storeName: string, pagination?: PaginationInput<T>): Promise<T[]>;
30
- delete(key: string, storeName: string): Promise<void>;
31
- /**
32
- * Clear the AsyncStorage of all DataStore entries
33
- */
34
- clear(): Promise<void>;
35
- private getKeyForItem;
36
- private getLegacyKeyForItem;
37
- private getKeyPrefixForStoreItems;
38
- }
39
- export default AsyncStorageDatabase;
@@ -1,11 +0,0 @@
1
- export declare class InMemoryStore {
2
- db: Map<string, string>;
3
- getAllKeys: () => Promise<string[]>;
4
- multiGet: (keys: string[]) => Promise<[string, string][]>;
5
- multiRemove: (keys: string[], callback?: any) => Promise<void>;
6
- multiSet: (entries: string[][], callback?: any) => Promise<void>;
7
- setItem: (key: string, value: string) => Promise<Map<string, string>>;
8
- removeItem: (key: string) => Promise<boolean>;
9
- getItem: (key: string) => Promise<string>;
10
- }
11
- export declare function createInMemoryStore(): InMemoryStore;
@@ -1 +0,0 @@
1
- export declare function createInMemoryStore(): import("@react-native-async-storage/async-storage").AsyncStorageStatic;
@@ -1,70 +0,0 @@
1
- import * as idb from 'idb';
2
- import { ModelInstanceMetadata, ModelPredicate, OpType, PaginationInput, PersistentModel, PersistentModelConstructor, QueryOne } from '../../types';
3
- import { StorageAdapterBase } from './StorageAdapterBase';
4
- declare class IndexedDBAdapter extends StorageAdapterBase {
5
- protected db: idb.IDBPDatabase;
6
- private safariCompatabilityMode;
7
- protected preSetUpChecks(): Promise<void>;
8
- protected preOpCheck(): Promise<void>;
9
- /**
10
- * Initialize IndexedDB database
11
- * Create new DB if one doesn't exist
12
- * Upgrade outdated DB
13
- *
14
- * Called by `StorageAdapterBase.setUp()`
15
- *
16
- * @returns IDB Database instance
17
- */
18
- protected initDb(): Promise<idb.IDBPDatabase>;
19
- protected _get<T>(storeOrStoreName: idb.IDBPObjectStore | string, keyArr: string[]): Promise<T>;
20
- clear(): Promise<void>;
21
- save<T extends PersistentModel>(model: T, condition?: ModelPredicate<T>): Promise<[T, OpType.INSERT | OpType.UPDATE][]>;
22
- query<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, predicate?: ModelPredicate<T>, pagination?: PaginationInput<T>): Promise<T[]>;
23
- queryOne<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, firstOrLast?: QueryOne): Promise<T | undefined>;
24
- batchSave<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<any>, items: ModelInstanceMetadata[]): Promise<[T, OpType][]>;
25
- protected deleteItem<T extends PersistentModel>(deleteQueue: {
26
- storeName: string;
27
- items: T[] | IDBValidKey[];
28
- }[]): Promise<void>;
29
- private checkPrivate;
30
- /**
31
- * Whether the browser's implementation of IndexedDB is coercing single-field
32
- * indexes to a scalar key.
33
- *
34
- * If this returns `true`, we need to treat indexes containing a single field
35
- * as scalars.
36
- *
37
- * See PR description for reference:
38
- * https://github.com/aws-amplify/amplify-js/pull/10527
39
- */
40
- private setSafariCompatabilityMode;
41
- private getNamespaceAndModelFromStorename;
42
- private createObjectStoreForModel;
43
- private getByKey;
44
- private getAll;
45
- /**
46
- * Tries to generate an index fetcher for the given predicates. Assumes
47
- * that the given predicate conditions are contained by an AND group and
48
- * should therefore all match a single record.
49
- *
50
- * @param storeName The table to query.
51
- * @param predicates The predicates to try to AND together.
52
- * @param transaction
53
- */
54
- private matchingIndexQueries;
55
- private baseQueryIndex;
56
- private filterOnPredicate;
57
- private inMemoryPagination;
58
- private enginePagination;
59
- /**
60
- * Checks the given path against the browser's IndexedDB implementation for
61
- * necessary compatibility transformations, applying those transforms if needed.
62
- *
63
- * @param `keyArr` strings to compatibilize for browser-indexeddb index operations
64
- * @returns An array or string, depending on and given key,
65
- * that is ensured to be compatible with the IndexedDB implementation's nuances.
66
- */
67
- private canonicalKeyPath;
68
- }
69
- declare const _default: IndexedDBAdapter;
70
- export default _default;
@@ -1,134 +0,0 @@
1
- import { Adapter } from './index';
2
- import { ModelInstanceCreator } from '../../datastore/datastore';
3
- import { InternalSchema, ModelInstanceMetadata, ModelPredicate, NamespaceResolver, OpType, PaginationInput, PersistentModel, PersistentModelConstructor, PredicatesGroup, QueryOne } from '../../types';
4
- import { NAMESPACES } from '../../util';
5
- import type { IDBPDatabase, IDBPObjectStore } from 'idb';
6
- import type AsyncStorageDatabase from './AsyncStorageDatabase';
7
- export declare abstract class StorageAdapterBase implements Adapter {
8
- protected schema: InternalSchema;
9
- protected namespaceResolver: NamespaceResolver;
10
- protected modelInstanceCreator: ModelInstanceCreator;
11
- protected getModelConstructorByModelName: (namsespaceName: NAMESPACES, modelName: string) => PersistentModelConstructor<any>;
12
- protected initPromise: Promise<void>;
13
- protected resolve: (value?: any) => void;
14
- protected reject: (value?: any) => void;
15
- protected dbName: string;
16
- protected abstract db: IDBPDatabase | AsyncStorageDatabase;
17
- protected abstract preSetUpChecks(): Promise<void>;
18
- protected abstract preOpCheck(): Promise<void>;
19
- protected abstract initDb(): Promise<IDBPDatabase | AsyncStorageDatabase>;
20
- /**
21
- * Initializes local DB
22
- *
23
- * @param theSchema
24
- * @param namespaceResolver
25
- * @param modelInstanceCreator
26
- * @param getModelConstructorByModelName
27
- * @param sessionId
28
- */
29
- setUp(theSchema: InternalSchema, namespaceResolver: NamespaceResolver, modelInstanceCreator: ModelInstanceCreator, getModelConstructorByModelName: (namsespaceName: NAMESPACES, modelName: string) => PersistentModelConstructor<any>, sessionId?: string): Promise<void>;
30
- abstract clear(): Promise<void>;
31
- abstract save<T extends PersistentModel>(model: T, condition?: ModelPredicate<T>): any;
32
- abstract query<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, predicate?: ModelPredicate<T>, pagination?: PaginationInput<T>): Promise<T[]>;
33
- abstract queryOne<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, firstOrLast: QueryOne): Promise<T | undefined>;
34
- abstract batchSave<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<any>, items: ModelInstanceMetadata[]): Promise<[T, OpType][]>;
35
- /**
36
- * @param modelConstructor
37
- * @returns local DB table name
38
- */
39
- protected getStorenameForModel(modelConstructor: PersistentModelConstructor<any>): string;
40
- /**
41
- *
42
- * @param model - instantiated model record
43
- * @returns the record's primary key values
44
- */
45
- protected getIndexKeyValuesFromModel<T extends PersistentModel>(model: T): string[];
46
- /**
47
- * Common metadata for `save` operation
48
- * used by individual storage adapters
49
- *
50
- * @param model
51
- */
52
- protected saveMetadata<T extends PersistentModel>(model: T): {
53
- storeName: string;
54
- set: Set<string>;
55
- connectionStoreNames: any;
56
- modelKeyValues: string[];
57
- };
58
- /**
59
- * Enforces conditional save. Throws if condition is not met.
60
- * used by individual storage adapters
61
- *
62
- * @param model
63
- */
64
- protected validateSaveCondition<T extends PersistentModel>(condition?: ModelPredicate<T>, fromDB?: unknown): void;
65
- protected abstract _get<T>(storeOrStoreName: IDBPObjectStore | string, keyArr: string[]): Promise<T>;
66
- /**
67
- * Instantiate models from POJO records returned from the database
68
- *
69
- * @param namespaceName - string model namespace
70
- * @param srcModelName - string model name
71
- * @param records - array of uninstantiated records
72
- * @returns
73
- */
74
- protected load<T>(namespaceName: NAMESPACES, srcModelName: string, records: T[]): Promise<T[]>;
75
- /**
76
- * Extracts operands from a predicate group into an array of key values
77
- * Used in the query method
78
- *
79
- * @param predicates - predicate group
80
- * @param keyPath - string array of key names ['id', 'sortKey']
81
- * @returns string[] of key values
82
- *
83
- * @example
84
- * ```js
85
- * { and:[{ id: { eq: 'abc' }}, { sortKey: { eq: 'def' }}] }
86
- * ```
87
- * Becomes
88
- * ```
89
- * ['abc', 'def']
90
- * ```
91
- */
92
- private keyValueFromPredicate;
93
- /**
94
- * Common metadata for `query` operation
95
- * used by individual storage adapters
96
- *
97
- * @param modelConstructor
98
- * @param predicate
99
- * @param pagination
100
- */
101
- protected queryMetadata<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, predicate?: ModelPredicate<T>, pagination?: PaginationInput<T>): {
102
- storeName: string;
103
- namespaceName: NAMESPACES;
104
- queryByKey: string[];
105
- predicates: PredicatesGroup<any>;
106
- hasSort: import("../../types").SortPredicate<T>;
107
- hasPagination: number;
108
- };
109
- /**
110
- * Delete record
111
- * Cascades to related records (for Has One and Has Many relationships)
112
- *
113
- * @param modelOrModelConstructor
114
- * @param condition
115
- * @returns
116
- */
117
- delete<T extends PersistentModel>(modelOrModelConstructor: T | PersistentModelConstructor<T>, condition?: ModelPredicate<T>): Promise<[T[], T[]]>;
118
- protected abstract deleteItem<T extends PersistentModel>(deleteQueue?: {
119
- storeName: string;
120
- items: T[] | IDBValidKey[];
121
- }[]): any;
122
- /**
123
- * Recursively traverse relationship graph and add
124
- * all Has One and Has Many relations to `deleteQueue` param
125
- *
126
- * Actual deletion of records added to `deleteQueue` occurs in the `delete` method
127
- *
128
- * @param models
129
- * @param modelConstructor
130
- * @param namespace
131
- * @param deleteQueue
132
- */
133
- private deleteTraverse;
134
- }
@@ -1,3 +0,0 @@
1
- import { Adapter } from '..';
2
- declare const getDefaultAdapter: () => Adapter;
3
- export default getDefaultAdapter;
@@ -1,3 +0,0 @@
1
- import { Adapter } from '..';
2
- declare const getDefaultAdapter: () => Adapter;
3
- export default getDefaultAdapter;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const AsyncStorageAdapter_1 = __importDefault(require("../AsyncStorageAdapter"));
7
- const getDefaultAdapter = () => {
8
- return AsyncStorageAdapter_1.default;
9
- };
10
- exports.default = getDefaultAdapter;