jmap-kit 0.0.0 → 1.0.2

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 (198) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +138 -3
  3. package/dist/src/capabilities/blob/blob.d.ts +83 -0
  4. package/dist/src/capabilities/blob/blob.js +98 -0
  5. package/dist/src/capabilities/blob/blob.js.map +1 -0
  6. package/dist/src/capabilities/blob/types.d.ts +212 -0
  7. package/dist/src/capabilities/blob/types.js +16 -0
  8. package/dist/src/capabilities/blob/types.js.map +1 -0
  9. package/dist/src/capabilities/blob-capability.d.ts +195 -0
  10. package/dist/src/capabilities/blob-capability.js +277 -0
  11. package/dist/src/capabilities/blob-capability.js.map +1 -0
  12. package/dist/src/capabilities/core/core.d.ts +47 -0
  13. package/dist/src/capabilities/core/core.js +59 -0
  14. package/dist/src/capabilities/core/core.js.map +1 -0
  15. package/dist/src/capabilities/core/types.d.ts +13 -0
  16. package/dist/src/capabilities/core/types.js +2 -0
  17. package/dist/src/capabilities/core/types.js.map +1 -0
  18. package/dist/src/capabilities/core-capability.d.ts +307 -0
  19. package/dist/src/capabilities/core-capability.js +344 -0
  20. package/dist/src/capabilities/core-capability.js.map +1 -0
  21. package/dist/src/capabilities/email/email.d.ts +124 -0
  22. package/dist/src/capabilities/email/email.js +136 -0
  23. package/dist/src/capabilities/email/email.js.map +1 -0
  24. package/dist/src/capabilities/email/types.d.ts +776 -0
  25. package/dist/src/capabilities/email/types.js +2 -0
  26. package/dist/src/capabilities/email/types.js.map +1 -0
  27. package/dist/src/capabilities/email-capability.d.ts +266 -0
  28. package/dist/src/capabilities/email-capability.js +241 -0
  29. package/dist/src/capabilities/email-capability.js.map +1 -0
  30. package/dist/src/capabilities/emailsubmission/emailsubmission.d.ts +95 -0
  31. package/dist/src/capabilities/emailsubmission/emailsubmission.js +107 -0
  32. package/dist/src/capabilities/emailsubmission/emailsubmission.js.map +1 -0
  33. package/dist/src/capabilities/emailsubmission/types.d.ts +256 -0
  34. package/dist/src/capabilities/emailsubmission/types.js +2 -0
  35. package/dist/src/capabilities/emailsubmission/types.js.map +1 -0
  36. package/dist/src/capabilities/example/example.d.ts +80 -0
  37. package/dist/src/capabilities/example/example.js +91 -0
  38. package/dist/src/capabilities/example/example.js.map +1 -0
  39. package/dist/src/capabilities/example/types.d.ts +33 -0
  40. package/dist/src/capabilities/example/types.js +2 -0
  41. package/dist/src/capabilities/example/types.js.map +1 -0
  42. package/dist/src/capabilities/identity/identity.d.ts +71 -0
  43. package/dist/src/capabilities/identity/identity.js +83 -0
  44. package/dist/src/capabilities/identity/identity.js.map +1 -0
  45. package/dist/src/capabilities/identity/types.d.ts +110 -0
  46. package/dist/src/capabilities/identity/types.js +2 -0
  47. package/dist/src/capabilities/identity/types.js.map +1 -0
  48. package/dist/src/capabilities/mailbox/mailbox.d.ts +91 -0
  49. package/dist/src/capabilities/mailbox/mailbox.js +103 -0
  50. package/dist/src/capabilities/mailbox/mailbox.js.map +1 -0
  51. package/dist/src/capabilities/mailbox/types.d.ts +248 -0
  52. package/dist/src/capabilities/mailbox/types.js +2 -0
  53. package/dist/src/capabilities/mailbox/types.js.map +1 -0
  54. package/dist/src/capabilities/maskedemail/maskedemail.d.ts +60 -0
  55. package/dist/src/capabilities/maskedemail/maskedemail.js +72 -0
  56. package/dist/src/capabilities/maskedemail/maskedemail.js.map +1 -0
  57. package/dist/src/capabilities/maskedemail/types.d.ts +67 -0
  58. package/dist/src/capabilities/maskedemail/types.js +4 -0
  59. package/dist/src/capabilities/maskedemail/types.js.map +1 -0
  60. package/dist/src/capabilities/maskedemail-capability.d.ts +112 -0
  61. package/dist/src/capabilities/maskedemail-capability.js +166 -0
  62. package/dist/src/capabilities/maskedemail-capability.js.map +1 -0
  63. package/dist/src/capabilities/searchsnippet/searchsnippet.d.ts +51 -0
  64. package/dist/src/capabilities/searchsnippet/searchsnippet.js +63 -0
  65. package/dist/src/capabilities/searchsnippet/searchsnippet.js.map +1 -0
  66. package/dist/src/capabilities/searchsnippet/types.d.ts +88 -0
  67. package/dist/src/capabilities/searchsnippet/types.js +2 -0
  68. package/dist/src/capabilities/searchsnippet/types.js.map +1 -0
  69. package/dist/src/capabilities/submission-capability.d.ts +89 -0
  70. package/dist/src/capabilities/submission-capability.js +75 -0
  71. package/dist/src/capabilities/submission-capability.js.map +1 -0
  72. package/dist/src/capabilities/thread/thread.d.ts +58 -0
  73. package/dist/src/capabilities/thread/thread.js +70 -0
  74. package/dist/src/capabilities/thread/thread.js.map +1 -0
  75. package/dist/src/capabilities/thread/types.d.ts +43 -0
  76. package/dist/src/capabilities/thread/types.js +2 -0
  77. package/dist/src/capabilities/thread/types.js.map +1 -0
  78. package/dist/src/capabilities/utils/assert-invocation-datatype.d.ts +7 -0
  79. package/dist/src/capabilities/utils/assert-invocation-datatype.js +13 -0
  80. package/dist/src/capabilities/utils/assert-invocation-datatype.js.map +1 -0
  81. package/dist/src/capabilities/utils/assert-invocation-method.d.ts +7 -0
  82. package/dist/src/capabilities/utils/assert-invocation-method.js +13 -0
  83. package/dist/src/capabilities/utils/assert-invocation-method.js.map +1 -0
  84. package/dist/src/capabilities/utils/assert-invocation.d.ts +7 -0
  85. package/dist/src/capabilities/utils/assert-invocation.js +22 -0
  86. package/dist/src/capabilities/utils/assert-invocation.js.map +1 -0
  87. package/dist/src/capabilities/utils/assert-non-nullish.d.ts +1 -0
  88. package/dist/src/capabilities/utils/assert-non-nullish.js +6 -0
  89. package/dist/src/capabilities/utils/assert-non-nullish.js.map +1 -0
  90. package/dist/src/capabilities/utils/create-readonly-account-validator.d.ts +49 -0
  91. package/dist/src/capabilities/utils/create-readonly-account-validator.js +80 -0
  92. package/dist/src/capabilities/utils/create-readonly-account-validator.js.map +1 -0
  93. package/dist/src/capabilities/vacationresponse/types.d.ts +100 -0
  94. package/dist/src/capabilities/vacationresponse/types.js +2 -0
  95. package/dist/src/capabilities/vacationresponse/types.js.map +1 -0
  96. package/dist/src/capabilities/vacationresponse/vacationresponse.d.ts +61 -0
  97. package/dist/src/capabilities/vacationresponse/vacationresponse.js +73 -0
  98. package/dist/src/capabilities/vacationresponse/vacationresponse.js.map +1 -0
  99. package/dist/src/capabilities/vacationresponse-capability.d.ts +65 -0
  100. package/dist/src/capabilities/vacationresponse-capability.js +68 -0
  101. package/dist/src/capabilities/vacationresponse-capability.js.map +1 -0
  102. package/dist/src/capability-registry/capability-registry.d.ts +148 -0
  103. package/dist/src/capability-registry/capability-registry.js +360 -0
  104. package/dist/src/capability-registry/capability-registry.js.map +1 -0
  105. package/dist/src/capability-registry/types.d.ts +385 -0
  106. package/dist/src/capability-registry/types.js +2 -0
  107. package/dist/src/capability-registry/types.js.map +1 -0
  108. package/dist/src/capability-registry/utils.d.ts +71 -0
  109. package/dist/src/capability-registry/utils.js +163 -0
  110. package/dist/src/capability-registry/utils.js.map +1 -0
  111. package/dist/src/common/registry.d.ts +366 -0
  112. package/dist/src/common/registry.js +321 -0
  113. package/dist/src/common/registry.js.map +1 -0
  114. package/dist/src/common/types.d.ts +338 -0
  115. package/dist/src/common/types.js +21 -0
  116. package/dist/src/common/types.js.map +1 -0
  117. package/dist/src/common/utils.d.ts +20 -0
  118. package/dist/src/common/utils.js +26 -0
  119. package/dist/src/common/utils.js.map +1 -0
  120. package/dist/src/index.d.ts +40 -0
  121. package/dist/src/index.js +33 -0
  122. package/dist/src/index.js.map +1 -0
  123. package/dist/src/invocation/arguments-proxy.d.ts +14 -0
  124. package/dist/src/invocation/arguments-proxy.js +37 -0
  125. package/dist/src/invocation/arguments-proxy.js.map +1 -0
  126. package/dist/src/invocation/error-invocation.d.ts +27 -0
  127. package/dist/src/invocation/error-invocation.js +39 -0
  128. package/dist/src/invocation/error-invocation.js.map +1 -0
  129. package/dist/src/invocation/invocation.d.ts +111 -0
  130. package/dist/src/invocation/invocation.js +158 -0
  131. package/dist/src/invocation/invocation.js.map +1 -0
  132. package/dist/src/invocation/result-reference.d.ts +86 -0
  133. package/dist/src/invocation/result-reference.js +118 -0
  134. package/dist/src/invocation/result-reference.js.map +1 -0
  135. package/dist/src/invocation/types.d.ts +637 -0
  136. package/dist/src/invocation/types.js +2 -0
  137. package/dist/src/invocation/types.js.map +1 -0
  138. package/dist/src/invocation/utils.d.ts +21 -0
  139. package/dist/src/invocation/utils.js +30 -0
  140. package/dist/src/invocation/utils.js.map +1 -0
  141. package/dist/src/invocation-factory/invocation-factory-manager.d.ts +20 -0
  142. package/dist/src/invocation-factory/invocation-factory-manager.js +50 -0
  143. package/dist/src/invocation-factory/invocation-factory-manager.js.map +1 -0
  144. package/dist/src/invocation-factory/invocation-list.d.ts +32 -0
  145. package/dist/src/invocation-factory/invocation-list.js +77 -0
  146. package/dist/src/invocation-factory/invocation-list.js.map +1 -0
  147. package/dist/src/invocation-factory/types.d.ts +11 -0
  148. package/dist/src/invocation-factory/types.js +2 -0
  149. package/dist/src/invocation-factory/types.js.map +1 -0
  150. package/dist/src/jmap-client/jmap-client.d.ts +252 -0
  151. package/dist/src/jmap-client/jmap-client.js +777 -0
  152. package/dist/src/jmap-client/jmap-client.js.map +1 -0
  153. package/dist/src/jmap-client/types.d.ts +427 -0
  154. package/dist/src/jmap-client/types.js +21 -0
  155. package/dist/src/jmap-client/types.js.map +1 -0
  156. package/dist/src/jmap-client/utils/abort-controller.d.ts +8 -0
  157. package/dist/src/jmap-client/utils/abort-controller.js +24 -0
  158. package/dist/src/jmap-client/utils/abort-controller.js.map +1 -0
  159. package/dist/src/jmap-client/utils/assert-connected.d.ts +7 -0
  160. package/dist/src/jmap-client/utils/assert-connected.js +11 -0
  161. package/dist/src/jmap-client/utils/assert-connected.js.map +1 -0
  162. package/dist/src/jmap-client/utils/deep-freeze.d.ts +7 -0
  163. package/dist/src/jmap-client/utils/deep-freeze.js +17 -0
  164. package/dist/src/jmap-client/utils/deep-freeze.js.map +1 -0
  165. package/dist/src/jmap-client/utils/emitter.d.ts +9 -0
  166. package/dist/src/jmap-client/utils/emitter.js +18 -0
  167. package/dist/src/jmap-client/utils/emitter.js.map +1 -0
  168. package/dist/src/jmap-client/utils/filter-session-capabilities.d.ts +22 -0
  169. package/dist/src/jmap-client/utils/filter-session-capabilities.js +40 -0
  170. package/dist/src/jmap-client/utils/filter-session-capabilities.js.map +1 -0
  171. package/dist/src/jmap-client/utils/jmap-request-error.d.ts +28 -0
  172. package/dist/src/jmap-client/utils/jmap-request-error.js +48 -0
  173. package/dist/src/jmap-client/utils/jmap-request-error.js.map +1 -0
  174. package/dist/src/jmap-client/utils/logger.d.ts +6 -0
  175. package/dist/src/jmap-client/utils/logger.js +22 -0
  176. package/dist/src/jmap-client/utils/logger.js.map +1 -0
  177. package/dist/src/jmap-client/utils/merge-headers.d.ts +11 -0
  178. package/dist/src/jmap-client/utils/merge-headers.js +40 -0
  179. package/dist/src/jmap-client/utils/merge-headers.js.map +1 -0
  180. package/dist/src/jmap-client/utils/template-utils.d.ts +27 -0
  181. package/dist/src/jmap-client/utils/template-utils.js +61 -0
  182. package/dist/src/jmap-client/utils/template-utils.js.map +1 -0
  183. package/dist/src/jmap-client/utils/track-utils.d.ts +19 -0
  184. package/dist/src/jmap-client/utils/track-utils.js +35 -0
  185. package/dist/src/jmap-client/utils/track-utils.js.map +1 -0
  186. package/dist/src/jmap-client/utils/transport.d.ts +12 -0
  187. package/dist/src/jmap-client/utils/transport.js +38 -0
  188. package/dist/src/jmap-client/utils/transport.js.map +1 -0
  189. package/dist/src/jmap-client/utils/validate-session.d.ts +19 -0
  190. package/dist/src/jmap-client/utils/validate-session.js +29 -0
  191. package/dist/src/jmap-client/utils/validate-session.js.map +1 -0
  192. package/dist/src/request-builder/request-builder.d.ts +95 -0
  193. package/dist/src/request-builder/request-builder.js +343 -0
  194. package/dist/src/request-builder/request-builder.js.map +1 -0
  195. package/dist/src/request-builder/types.d.ts +32 -0
  196. package/dist/src/request-builder/types.js +2 -0
  197. package/dist/src/request-builder/types.js.map +1 -0
  198. package/package.json +69 -3
@@ -0,0 +1,637 @@
1
+ import type { Id, Int, JMAPCapability, JMAPMethodName, JMAPRequestInvocation, JMAPRequestInvocationArgs, JMAPResultReference, JSONValue, RequireSome, UnsignedInt } from "../common/types.js";
2
+ import type { Invocation } from "./invocation.js";
3
+ import type { ResultReference } from "./result-reference.js";
4
+ /**
5
+ * The interface for Invocation instances.
6
+ *
7
+ * @typeParam T - The invocation arguments interface for the `{Object}/{method}` invocation being created
8
+ */
9
+ export interface InvocationInterface<TArgs extends BaseInvocationArgs> {
10
+ readonly name: string;
11
+ readonly uri: JMAPCapability;
12
+ getArgument(name: keyof TArgs & string): JSONValue | ResultReference | undefined;
13
+ setArgument<K extends keyof TArgs & string>(name: K, value: InvocationArgs<TArgs>[K]): void;
14
+ deleteArgument(name: keyof TArgs & string): boolean;
15
+ hasArgument(name: keyof TArgs & string): boolean;
16
+ resolve(id: string, lookupId: (id: symbol) => string | undefined): JMAPRequestInvocation;
17
+ createReference(path: string): ResultReference;
18
+ toJSON(): JMAPInvocationInternal;
19
+ }
20
+ export type InvocationFactory<TArgs extends BaseInvocationArgs, TInvocation extends Invocation<TArgs>> = (args: InvocationArgs<TArgs>, methodCallId?: symbol) => TInvocation;
21
+ /** A generic invocation factory type that can be used for any `{Object}/{method}` invocation. */
22
+ export type GenericInvocationFactory = (args: any, methodCallId?: symbol) => Invocation<BaseInvocationArgs>;
23
+ /** A mapping of method names to their corresponding invocation factory functions. */
24
+ export type InvocationFactoryMethods = Partial<Record<JMAPMethodName, GenericInvocationFactory>>;
25
+ /** A collection of invocation factory functions for both request and response invocations.*/
26
+ export type InvocationFactoryCollection = {
27
+ request: InvocationFactoryMethods;
28
+ response: InvocationFactoryMethods;
29
+ };
30
+ /** The interface for Result Reference objects created by Invocations */
31
+ export interface ResultReferenceInterface {
32
+ readonly name: string;
33
+ readonly path: string;
34
+ toJSON(): JMAPResultReferenceInternal;
35
+ }
36
+ /**
37
+ * An unordered set of patches. The keys are a path in JSON Pointer Format
38
+ * {@link https://www.rfc-editor.org/rfc/rfc6901.html RFC 6901}, with an implicit leading “`/`”
39
+ * (i.e., prefix each key with “`/`” before applying the JSON Pointer evaluation algorithm).
40
+ */
41
+ export type PatchObject = Record<string, JSONValue>;
42
+ /**
43
+ * An object whose allowed properties and semantics depend on the data type
44
+ * and is defined in the `/query` method specification for that type.
45
+ * It MUST NOT have an operator property.
46
+ *
47
+ * @typeParam T - The filter condition object for the `{Object}/query` or `/queryChanges` invocation
48
+ */
49
+ export type FilterCondition<T extends BaseFilterCondition> = T;
50
+ /**
51
+ * An object used to combine multiple conditions with boolean operators.
52
+ *
53
+ * @typeParam T - The filter condition object for the `{Object}/query` or `/queryChanges` invocation
54
+ */
55
+ export type FilterOperator<T extends BaseFilterCondition> = {
56
+ /**
57
+ * This MUST be one of the following strings:
58
+ * - AND: All of the conditions must match for the filter to match.
59
+ * - OR: At least one of the conditions must match for the filter to match.
60
+ * - NOT: None of the conditions must match for the filter to match.
61
+ */
62
+ operator: "AND" | "OR" | "NOT";
63
+ /**
64
+ *The conditions to evaluate against each record.
65
+ */
66
+ conditions: (FilterOperator<T> | FilterCondition<T>)[];
67
+ };
68
+ /**
69
+ * An object used to specify the sorting order for `/query` and `/queryChanges` calls.
70
+ *
71
+ * @typeParam T - The interface of the object whose properties are being compared for sorting
72
+ */
73
+ export type Comparator<TObj extends BaseObject> = {
74
+ /**
75
+ * The name of the property on the Foo objects to compare.
76
+ */
77
+ property: keyof TObj;
78
+ /**
79
+ * (default: true) If true, sort in ascending order. If false, reverse the comparator’s results
80
+ * to sort in descending order.
81
+ */
82
+ isAscending?: boolean;
83
+ /**
84
+ * (default is server dependent) The identifier, as registered in the collation registry
85
+ * defined in {@link https://www.rfc-editor.org/rfc/rfc4790.html RFC 4790}, for the algorithm
86
+ * to use when comparing the order of strings. The algorithms the server supports are
87
+ * advertised in the capabilities object returned with the Session object.
88
+ */
89
+ collation?: string;
90
+ };
91
+ /**
92
+ * Allows ResultReference values on all properties and disallow explicit property names starting with `#`
93
+ *
94
+ * @typeParam T - The invocation arguments interface for the given `{Object}/{method}` invocation
95
+ * being created.
96
+ * */
97
+ export type InvocationArgs<TArgs extends BaseInvocationArgs> = {
98
+ [K in keyof TArgs]: TArgs[K] | ResultReference;
99
+ } & Record<`#${string}`, never>;
100
+ /**
101
+ * Internal interface allowing Symbol values on `resultOf` properties.
102
+ * Used for `ResultReference.prototype.toJSON`.
103
+ *
104
+ * @remarks
105
+ * Any symbol values should be replaced by a `JSON.stringify` `replacer` function.
106
+ */
107
+ export interface JMAPResultReferenceInternal extends Omit<JMAPResultReference, "resultOf"> {
108
+ resultOf: symbol;
109
+ }
110
+ /**
111
+ * Internal interface allowing ResultReference values on all properties,
112
+ * and JMAPResultReference values on property names starting with `#`.
113
+ * Used for `Invocation.prototype.toJSON` (via JMAPInvocationInternal)
114
+ *
115
+ * @remarks
116
+ * Any properties with ResultReference values should be have their name prefixed
117
+ * with `#` and be replaced with a JMAPResultReference object by a `JSON.stringify`
118
+ * `replacer` function.
119
+ */
120
+ export interface JMAPInvocationArgsInternal extends Omit<InvocationArgs<JMAPRequestInvocationArgs>, "ref"> {
121
+ [ref: `#${string}`]: Omit<JSONValue & JMAPResultReference, "member"> | ResultReference;
122
+ }
123
+ /**
124
+ * Internal interface for Invocation.prototype.toJSON
125
+ *
126
+ * @remarks
127
+ * Any symbol values should be replaced by a `JSON.stringify` `replacer` function.
128
+ */
129
+ export type JMAPInvocationInternal = [name: string, arguments: JMAPInvocationArgsInternal, methodCallId: symbol];
130
+ /**
131
+ * Generic JMAP object
132
+ */
133
+ export type BaseObject = Record<string, JSONValue>;
134
+ /**
135
+ * Generic Filter Conditon
136
+ */
137
+ export type BaseFilterCondition = Record<string, JSONValue>;
138
+ /**
139
+ * Generic Invocation arguments
140
+ */
141
+ export type BaseInvocationArgs = Record<string, JSONValue>;
142
+ /**
143
+ * The standard arguments for fetching objects via a `/get` call
144
+ *
145
+ * @typeParam T - The interface of the object whose properties are being fetched
146
+ */
147
+ export type BaseGetRequestInvocationArgs<TObj extends BaseObject> = {
148
+ /**
149
+ * The id of the account to use. The value must be an `Id`
150
+ */
151
+ accountId: Id;
152
+ /**
153
+ * The ids of the objects to return. If null, then all records of the data type are
154
+ * returned, if this is supported for that data type and the number of records does
155
+ * not exceed the maxObjectsInGet limit.
156
+ *
157
+ * The value must be `Id[] | null`
158
+ *
159
+ */
160
+ ids?: Id[] | null;
161
+ /**
162
+ * If supplied, only the properties listed in the array are returned for each object.
163
+ * If null, all properties of the object are returned. The id property of the object
164
+ * is always returned, even if not explicitly requested. If an invalid property is
165
+ * requested, the call MUST be rejected with an invalidArguments error.
166
+ */
167
+ properties?: (keyof TObj)[] | null;
168
+ };
169
+ export type BaseGetResponseInvocationArgs<TObj extends BaseObject> = {
170
+ /**
171
+ * The id of the account used for the call.
172
+ */
173
+ accountId: Id;
174
+ /**
175
+ * A (preferably short) string representing the state on the server for all the data of this
176
+ * type in the account (not just the objects returned in this call). If the data changes, this
177
+ * string MUST change. If the Foo data is unchanged, servers SHOULD return the same state string
178
+ * on subsequent requests for this data type.
179
+ *
180
+ * When a client receives a response with a different state string to a previous call, it MUST
181
+ * either throw away all currently cached objects for the type or call Foo/changes to get the
182
+ * exact changes.
183
+ */
184
+ state: string;
185
+ /**
186
+ * An array of the Foo objects requested. This is the empty array if no objects were found or if
187
+ * the ids argument passed in was also an empty array. The results MAY be in a different order
188
+ * to the ids in the request arguments. If an identical id is included more than once in the
189
+ * request, the server MUST only include it once in either the list or the notFound argument of
190
+ * the response.
191
+ */
192
+ list: TObj[];
193
+ /**
194
+ * This array contains the ids passed to the method for records that do not exist. The array is
195
+ * empty if all requested ids were found or if the ids argument passed in was either null or an
196
+ * empty array.
197
+ */
198
+ notFound: Id[];
199
+ };
200
+ /**
201
+ * The standard arguments for fetching changes via a `/changes` call
202
+ */
203
+ export type BaseChangesRequestInvocationArgs = {
204
+ /**
205
+ * The id of the account to use. The value must be an `Id`
206
+ */
207
+ accountId: Id;
208
+ /**
209
+ * The current state of the client. This is the string that was returned as
210
+ * the state argument in a `/get` response.
211
+ */
212
+ sinceState: string;
213
+ /**
214
+ * The maximum number of ids to return in the response.
215
+ *
216
+ * The value must be `UnsignedInt | null`
217
+ */
218
+ maxChanges?: UnsignedInt | null;
219
+ };
220
+ export type BaseChangesResponseInvocationArgs = {
221
+ /**
222
+ * The id of the account used for the call.
223
+ */
224
+ accountId: Id;
225
+ /**
226
+ * This is the sinceState argument echoed back; it’s the state from which the server is
227
+ * returning changes.
228
+ */
229
+ oldState: string;
230
+ /**
231
+ * This is the state the client will be in after applying the set of changes to the old state.
232
+ */
233
+ newState: string;
234
+ /**
235
+ * If true, the client may call Foo/changes again with the newState returned to get further
236
+ * updates. If false, newState is the current server state.
237
+ */
238
+ hasMoreChanges: boolean;
239
+ /**
240
+ * An array of ids for records that have been created since the old state.
241
+ */
242
+ created: Id[];
243
+ /**
244
+ * An array of ids for records that have been updated since the old state.
245
+ */
246
+ updated: Id[];
247
+ /**
248
+ * An array of ids for records that have been destroyed since the old state.
249
+ */
250
+ destroyed: Id[];
251
+ };
252
+ /**
253
+ * The standard arguments for querying objects via a `/query` call
254
+ */
255
+ export type BaseQueryRequestInvocationArgs<TObj extends BaseObject, F extends BaseFilterCondition> = {
256
+ /**
257
+ * The id of the account to use.
258
+ */
259
+ accountId: Id;
260
+ /**
261
+ * Determines the set of Foos returned in the results. If null, all objects
262
+ * in the account of this type are included in the results.
263
+ */
264
+ filter?: FilterOperator<F> | FilterCondition<F> | null;
265
+ /**
266
+ * Lists the names of properties to compare between two records,
267
+ * and how to compare them, to determine which comes first in the sort.
268
+ * If two Foo records have an identical value for the first comparator,
269
+ * the next comparator will be considered, and so on. If all comparators
270
+ * are the same (this includes the case where an empty array or `null` is
271
+ * given as the sort argument), the sort order is server dependent, but
272
+ * it MUST be stable between calls to `/query`.
273
+ */
274
+ sort?: Comparator<TObj>[] | null;
275
+ /**
276
+ * (default: 0) The zero-based index of the first id in
277
+ * the full list of results to return.
278
+ */
279
+ position?: Int;
280
+ /**
281
+ * An object id. If supplied, the position argument is ignored.
282
+ * The index of this id in the results will be used in combination with
283
+ * the anchorOffset argument to determine the index of the first result
284
+ * to return.
285
+ */
286
+ anchor?: Id | null;
287
+ /**
288
+ * (default: 0) The index of the first result to return relative to the
289
+ * index of the anchor, if an anchor is given. This MAY be negative.
290
+ */
291
+ anchorOffset?: Int;
292
+ /**
293
+ * The maximum number of results to return. If null, no limit presumed.
294
+ */
295
+ limit?: UnsignedInt | null;
296
+ /**
297
+ * (default: false) Does the client wish to know the total number of results
298
+ * in the query? This may be slow and expensive for servers to calculate,
299
+ * particularly with complex filters, so clients should take care to only
300
+ * request the total when needed.
301
+ */
302
+ calculateTotal?: boolean;
303
+ };
304
+ export type BaseQueryResponseInvocationArgs = {
305
+ /**
306
+ * The id of the account used for the call.
307
+ */
308
+ accountId: Id;
309
+ /**
310
+ * A string encoding the current state of the query on the server. This string MUST change if
311
+ * the results of the query (i.e., the matching ids and their sort order) have changed. The
312
+ * queryState string MAY change if something has changed on the server, which means the results
313
+ * may have changed but the server doesn’t know for sure.
314
+ *
315
+ * The queryState string only represents the ordered list of ids that match the particular
316
+ * query (including its sort/filter). There is no requirement for it to change if a property on
317
+ * an object matching the query changes but the query results are unaffected (indeed, it is more
318
+ * efficient if the queryState string does not change in this case). The queryState string only
319
+ * has meaning when compared to future responses to a query with the same type/sort/filter or
320
+ * when used with /queryChanges to fetch changes.
321
+ *
322
+ * Should a client receive back a response with a different queryState string to a previous
323
+ * call, it MUST either throw away the currently cached query and fetch it again (note, this
324
+ * does not require fetching the records again, just the list of ids) or call Foo/queryChanges
325
+ * to get the difference.
326
+ */
327
+ queryState: string;
328
+ /**
329
+ * This is true if the server supports calling Foo/queryChanges with these filter/sort
330
+ * parameters. Note, this does not guarantee that the Foo/queryChanges call will succeed, as it
331
+ * may only be possible for a limited time afterwards due to server internal implementation
332
+ * details.
333
+ */
334
+ canCalculateChanges: boolean;
335
+ /**
336
+ * The zero-based index of the first result in the `ids` array within the complete list of
337
+ * query results. If the `ids` array is empty, the value is undefined and MUST NOT be used
338
+ * by the client.
339
+ */
340
+ position: UnsignedInt;
341
+ /**
342
+ * The list of ids for each Foo in the query results, starting at the index given by the
343
+ * position argument of this response and continuing until it hits the end of the results or
344
+ * reaches the limit number of ids. If position is >= total, this MUST be the empty list.
345
+ */
346
+ ids: Id[];
347
+ /**
348
+ * (only if requested) The total number of Foos in the results (given the filter). This
349
+ * argument MUST be omitted if the calculateTotal request argument is not true.
350
+ */
351
+ total: UnsignedInt;
352
+ /**
353
+ * (if set by the server) The limit enforced by the server on the maximum number of results to
354
+ * return. This is only returned if the server set a limit or used a different limit than that
355
+ * given in the request.
356
+ */
357
+ limit: UnsignedInt;
358
+ };
359
+ /**
360
+ * The standard arguments for querying changes to objects via a `/queryChanges` call
361
+ */
362
+ export type BaseQueryChangesRequestInvocationArgs<TObj extends BaseObject, F extends BaseFilterCondition> = {
363
+ /**
364
+ * The id of the account to use.
365
+ */
366
+ accountId: Id;
367
+ /**
368
+ * The filter argument that was used with Foo/query.
369
+ */
370
+ filter?: FilterOperator<F> | FilterCondition<F> | null;
371
+ /**
372
+ * The sort argument that was used with Foo/query.
373
+ */
374
+ sort?: Comparator<TObj>[] | null;
375
+ /**
376
+ * The current state of the query in the client. This is the string that was
377
+ * returned as the queryState argument in the Foo/query response with the same
378
+ * sort/filter. The server will return the changes made to the query since this state.
379
+ */
380
+ sinceQueryState: string;
381
+ /**
382
+ * The maximum number of changes to return in the response.
383
+ */
384
+ maxChanges?: UnsignedInt | null;
385
+ /**
386
+ * The last (highest-index) id the client currently has cached from the query results.
387
+ * When there are a large number of results, in a common case, the client may have only
388
+ * downloaded and cached a small subset from the beginning of the results. The server may
389
+ * be able to omit added or removed items that are after the client's last cached id, which
390
+ * can significantly increase efficiency.
391
+ */
392
+ upToId?: Id | null;
393
+ /**
394
+ * (default: false) Does the client wish to know the total number of results now in the query?
395
+ * This may be slow and expensive for servers to calculate, particularly with complex filters,
396
+ * so clients should take care to only request the total when needed.
397
+ */
398
+ calculateTotal?: boolean;
399
+ };
400
+ export type BaseQueryChangesResponseInvocationArgs = {
401
+ /**
402
+ * The id of the account used for the call.
403
+ */
404
+ accountId: Id;
405
+ /**
406
+ * This is the sinceQueryState argument echoed back; that is, the state from which the server is
407
+ * returning changes.
408
+ */
409
+ oldQueryState: string;
410
+ /**
411
+ * This is the state the query will be in after applying the set of changes to the old state.
412
+ */
413
+ newQueryState: string;
414
+ /**
415
+ * (only if requested) The total number of Foos in the results (given the filter). This argument
416
+ * MUST be omitted if the calculateTotal request argument is not true.
417
+ */
418
+ total: UnsignedInt;
419
+ /**
420
+ * The `id` for every Foo that was in the query results in the old state and that is not in the
421
+ * results in the new state.
422
+ *
423
+ * If the server cannot calculate this exactly, the server MAY return the ids of extra Foos in
424
+ * addition that may have been in the old results but are not in the new results.
425
+ *
426
+ * If an `upToId` is supplied and existed in the old results, any ids that were removed but had
427
+ * a higher index than `upToId` in those results SHOULD be omitted. If the server cannot
428
+ * calculate this, the `upToId` MUST be ignored.
429
+ *
430
+ * If the `filter` or `sort` includes a mutable property, the server MUST include all Foos in the
431
+ * current results for which this property may have changed. The position of these may have moved
432
+ * in the results, so they must be reinserted by the client to ensure its query cache is correct.
433
+ */
434
+ removed: Id[];
435
+ /**
436
+ * The id and index in the query results (in the new state) for every Foo that has been added to
437
+ * the results since the old state AND every Foo in the current results that was included in the
438
+ * `removed` array (due to a filter or sort based upon a mutable property).
439
+ *
440
+ * If an `upToId` is supplied and exists in the new results, any ids that were added but have a
441
+ * higher index than `upToId` SHOULD be omitted.
442
+ *
443
+ * The array MUST be sorted in order of index, with the lowest index first.
444
+ */
445
+ added: AddedItem[];
446
+ };
447
+ /**
448
+ * An item Id and its index used for the added items array in a `/queryChanges` response.
449
+ */
450
+ export type AddedItem = {
451
+ id: Id;
452
+ index: UnsignedInt;
453
+ };
454
+ /**
455
+ * The standard arguments to copy or move objects between two different accounts via a `/copy` call
456
+ *
457
+ * @typeParam T - The interface of the object specifying invocation arguments for the `create` object.
458
+ * @typeParam RequiredKeys - A union of keys (keyof T) that are required for the `create` object. `id` is always required, even if not specified.
459
+ */
460
+ export type BaseCopyRequestInvocationArgs<TObj extends BaseObject, RequiredKeys extends keyof TObj = "id"> = {
461
+ /**
462
+ * The id of the account to copy records from.
463
+ */
464
+ fromAccountId: Id;
465
+ /**
466
+ * This is a state string as returned by the `/get` method.
467
+ */
468
+ ifFromInState?: string | null;
469
+ /**
470
+ * The id of the account to copy records to.
471
+ */
472
+ accountId: Id;
473
+ /**
474
+ * This is a state string as returned by the `/get` method.
475
+ */
476
+ ifInState?: string | null;
477
+ /**
478
+ * A map of the creation id to an object.
479
+ */
480
+ create: Record<Id, RequireSome<TObj, "id" | RequiredKeys>>;
481
+ /**
482
+ * (default: false) If true, an attempt will be made to destroy the original
483
+ * records that were successfully copied.
484
+ */
485
+ onSuccessDestroyOriginal?: boolean;
486
+ /**
487
+ * This argument is passed on as the ifInState argument to the implicit Foo/set call, if made at the end of this request to destroy the originals that were successfully copied.
488
+ */
489
+ destroyFromIfInState?: string | null;
490
+ };
491
+ /** */
492
+ export type BaseCopyResponseInvocationArgs<TObj extends BaseObject> = {
493
+ /**
494
+ * The id of the account records were copied from.
495
+ */
496
+ fromAccountId: Id;
497
+ /**
498
+ * The id of the account records were copied to.
499
+ */
500
+ accountId: Id;
501
+ /**
502
+ * The state string that would have been returned by Foo/get on the account records that were
503
+ * copied to before making the requested changes, or null if the server doesn’t know what the
504
+ * previous state string was.
505
+ */
506
+ oldState?: string | null;
507
+ /**
508
+ * The state string that will now be returned by Foo/get on the account records were copied to.
509
+ */
510
+ newState: string;
511
+ /**
512
+ * A map of the creation id to an object containing any properties of the copied Foo object that
513
+ * are set by the server (such as the id in most object types; note, the id is likely to be
514
+ * different to the id of the object in the account it was copied from).
515
+ *
516
+ * This argument is null if no Foo objects were successfully copied.
517
+ */
518
+ created?: Record<Id, TObj> | null;
519
+ /**
520
+ * A map of the creation id to a SetError object for each record that failed to be copied, or
521
+ * null if none.
522
+ */
523
+ notCreated?: Record<Id, SetError<"create" | "update", never, {
524
+ type: "alreadyExists";
525
+ existingId: Id;
526
+ }>> | null;
527
+ };
528
+ /**
529
+ * The categories of SetError types
530
+ */
531
+ export type SetErrorCategory = "create" | "update" | "destroy";
532
+ /**
533
+ * The allowed SetError type values as per JMAP spec.
534
+ *
535
+ * Note: This type is for documentation and code completion only. Use `string` for the SetError.type property to avoid TypeScript override errors.
536
+ */
537
+ export type SetErrorType<TCategory extends SetErrorCategory = SetErrorCategory> = "forbidden" | (TCategory extends "destroy" ? never : "overQuota" | "tooLarge") | (TCategory extends "create" ? "rateLimit" : "notFound") | (TCategory extends "update" ? "invalidPatch" | "willDestroy" : "singleton");
538
+ export type SetError<TCategory extends SetErrorCategory = SetErrorCategory, TAdditionalType extends string = never, TAdditionalObj extends Record<string, JSONValue> = never> = {
539
+ /**
540
+ * A description of the error to help with debugging that includes an explanation of what the problem was. This is a non-localised string and is not intended to be shown directly to end users.
541
+ */
542
+ description?: string | null;
543
+ } & ({
544
+ /**
545
+ * The type of error. See JMAP spec for allowed values (e.g. forbidden, overQuota, tooLarge, rateLimit, notFound, invalidPatch, willDestroy, invalidProperties, singleton, etc.)
546
+ */
547
+ type: SetErrorType<TCategory> | TAdditionalType;
548
+ } | (TCategory extends "destroy" ? never : {
549
+ type: "invalidProperties";
550
+ /**
551
+ * (invalidProperties only) The properties that were invalid, if applicable.
552
+ */
553
+ properties?: string[];
554
+ }) | TAdditionalObj);
555
+ /**
556
+ * The standard arguments for creating, updating, and destroying objects via a `/set` call
557
+ *
558
+ * @typeParam T - The interface of the object specifying invocation arguments for the `create`
559
+ * object.
560
+ */
561
+ export type BaseSetRequestInvocationArgs<TObj extends BaseObject> = {
562
+ /**
563
+ * The id of the account to use. The value must be an `Id`
564
+ */
565
+ accountId: Id;
566
+ /**
567
+ * This is a state string as returned by the `/get` method
568
+ * (representing the state of all objects of this type in the account).
569
+ */
570
+ ifInState?: string | null;
571
+ /**
572
+ * A map of a creation id (a temporary id set by the client) to Foo objects,
573
+ * or `null` if no objects are to be created.
574
+ */
575
+ create?: Record<Id, TObj> | null;
576
+ /**
577
+ * A map of an id to a Patch object to apply to the current object with that id,
578
+ * or `null` if no objects are to be updated.
579
+ */
580
+ update?: Record<Id, PatchObject> | null;
581
+ /**
582
+ * A list of ids for objects to permanently delete, or null if no objects
583
+ * are to be destroyed.
584
+ */
585
+ destroy?: Id[] | null;
586
+ };
587
+ export type BaseSetResponseInvocationArgs<TObj extends BaseObject> = {
588
+ /** The id of the account used for the call. */
589
+ accountId: Id;
590
+ /**
591
+ * The state string that would have been returned by Foo/get before making the requested
592
+ * changes, or null if the server doesn’t know what the previous state string was.
593
+ */
594
+ oldState?: string | null;
595
+ /**
596
+ * The state string that will now be returned by Foo/get.
597
+ */
598
+ newState: string;
599
+ /**
600
+ * A map of the creation id to an object containing any properties of the created Foo object
601
+ * that were not sent by the client. This includes all server-set properties (such as the id in
602
+ * most object types) and any properties that were omitted by the client and thus set to a
603
+ * default by the server.
604
+ *
605
+ * This argument is null if no Foo objects were successfully created.
606
+ */
607
+ created?: Record<Id, TObj> | null;
608
+ /**
609
+ * The keys in this map are the ids of all Foos that were successfully updated.
610
+ *
611
+ * The value for each id is a Foo object containing any property that changed in a way not
612
+ * explicitly requested by the PatchObject sent to the server, or null if none. This lets the
613
+ * client know of any changes to server-set or computed properties.
614
+ *
615
+ * This argument is null if no Foo objects were successfully updated.
616
+ */
617
+ updated?: Record<Id, TObj | null> | null;
618
+ /**
619
+ * A list of Foo ids for records that were successfully destroyed, or null if none.
620
+ */
621
+ destroyed?: Id[] | null;
622
+ /**
623
+ * A map of the creation id to a SetError object for each record that failed to be created, or
624
+ * null if all successful.
625
+ */
626
+ notCreated?: Record<Id, SetError<"create">> | null;
627
+ /**
628
+ * A map of the Foo id to a SetError object for each record that failed to be updated, or null
629
+ * if all successful.
630
+ */
631
+ notUpdated?: Record<Id, SetError<"update">> | null;
632
+ /**
633
+ * A map of the Foo id to a SetError object for each record that failed to be destroyed, or null
634
+ * if all successful.
635
+ */
636
+ notDestroyed?: Record<Id, SetError<"destroy">> | null;
637
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/invocation/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { JMAPResponseInvocationErrorArgs } from "../common/types.js";
2
+ import { ErrorInvocation } from "./error-invocation.js";
3
+ import { ResultReference } from "./result-reference.js";
4
+ /**
5
+ * Type guard to check if a value is an instance of ResultReference.
6
+ * @param value The value to check.
7
+ * @returns True if the value is a ResultReference, false otherwise.
8
+ */
9
+ export declare function isResultReference(value: unknown): value is ResultReference;
10
+ /**
11
+ * Type guard to check if an object is an ErrorInvocation instance.
12
+ * @param obj The object to check.
13
+ * @returns True if the object is an ErrorInvocation, false otherwise.
14
+ */
15
+ export declare function isErrorInvocation(obj: unknown): obj is ErrorInvocation;
16
+ /**
17
+ * Type guard to check if an object is a valid JMAPResponseInvocationErrorArgs.
18
+ * @param args The object to check.
19
+ * @returns True if the object has a string `type` property, false otherwise.
20
+ */
21
+ export declare function isJMAPResponseInvocationErrorArgs(args: unknown): args is JMAPResponseInvocationErrorArgs;