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,21 @@
1
+ import { z } from "zod/v4";
2
+ import { CORE_CAPABILITY_URI } from "./registry.js";
3
+ /**
4
+ * Zod schema for JMAPServerCapabilities.
5
+ *
6
+ * Validates the structural requirement that the Core capability key is present.
7
+ * Content validation of individual capabilities is handled by each capability's
8
+ * own StandardSchema, validated via {@link CapabilityRegistryInterface.validateServerCapabilities}.
9
+ */
10
+ export const JMAPServerCapabilitiesSchema = z.looseObject({
11
+ [CORE_CAPABILITY_URI]: z.looseObject({}),
12
+ });
13
+ /**
14
+ * Zod schema for JMAPAccountCapabilities.
15
+ *
16
+ * Validates the structural shape of account capabilities. Content validation of individual
17
+ * capabilities is handled by each capability's own StandardSchema, validated via
18
+ * {@link CapabilityRegistryInterface.validateAccountCapabilities}.
19
+ */
20
+ export const JMAPAccountCapabilitiesSchema = z.looseObject({});
21
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAqD3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAwGpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,WAAW,CAAC;IACtD,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC;CAC3C,CAAC,CAAC;AAiCH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Id } from "./types.js";
2
+ /**
3
+ * A generator function that produces unique IDs with an optional prefix. The IDs are generated as
4
+ * strings of incrementing BigInt values, starting from a specified initial value (default is 0).
5
+ * This is used for generating unique identifiers for method calls by the
6
+ * by the {@linkcode RequestBuilder}.
7
+ *
8
+ * @param prefix The prefix to prepend to each generated ID.
9
+ * @param start The initial value for the ID counter.
10
+ * @returns A generator that yields unique IDs as strings with the specified prefix.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const gen = idGenerator("c");
15
+ * console.log(gen.next().value); // "c0"
16
+ * console.log(gen.next().value); // "c1"
17
+ * console.log(gen.next().value); // "c2"
18
+ * ```
19
+ */
20
+ export declare function idGenerator(prefix?: string, start?: Parameters<typeof BigInt>[0]): Generator<Id, never, never>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A generator function that produces unique IDs with an optional prefix. The IDs are generated as
3
+ * strings of incrementing BigInt values, starting from a specified initial value (default is 0).
4
+ * This is used for generating unique identifiers for method calls by the
5
+ * by the {@linkcode RequestBuilder}.
6
+ *
7
+ * @param prefix The prefix to prepend to each generated ID.
8
+ * @param start The initial value for the ID counter.
9
+ * @returns A generator that yields unique IDs as strings with the specified prefix.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const gen = idGenerator("c");
14
+ * console.log(gen.next().value); // "c0"
15
+ * console.log(gen.next().value); // "c1"
16
+ * console.log(gen.next().value); // "c2"
17
+ * ```
18
+ */
19
+ export function* idGenerator(prefix = "", start = 0) {
20
+ let id = BigInt(start);
21
+ while (true) {
22
+ yield `${prefix}${id}`;
23
+ id = id + 1n;
24
+ }
25
+ }
26
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/common/utils.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,SAAS,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,EAAE,EAAE,QAAsC,CAAC;IAC7E,IAAI,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAEvB,OAAO,IAAI,EAAE,CAAC;QACV,MAAM,GAAG,MAAM,GAAG,EAAE,EAAE,CAAC;QACvB,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC;AACL,CAAC"}
@@ -0,0 +1,40 @@
1
+ export { ErrorInvocation } from "./invocation/error-invocation.js";
2
+ export { Invocation } from "./invocation/invocation.js";
3
+ export { ResultReference } from "./invocation/result-reference.js";
4
+ export { JMAPClient } from "./jmap-client/jmap-client.js";
5
+ export { RequestBuilder } from "./request-builder/request-builder.js";
6
+ export { isErrorInvocation, isResultReference } from "./invocation/utils.js";
7
+ export { JMAPRequestError } from "./jmap-client/utils/jmap-request-error.js";
8
+ export { BlobCapability } from "./capabilities/blob-capability.js";
9
+ export { CoreCapability } from "./capabilities/core-capability.js";
10
+ export { EmailCapability } from "./capabilities/email-capability.js";
11
+ export { MaskedEmailCapability } from "./capabilities/maskedemail-capability.js";
12
+ export { SubmissionCapability } from "./capabilities/submission-capability.js";
13
+ export { VacationResponseCapability } from "./capabilities/vacationresponse-capability.js";
14
+ export { Blob } from "./capabilities/blob/blob.js";
15
+ export { Core } from "./capabilities/core/core.js";
16
+ export { Email } from "./capabilities/email/email.js";
17
+ export { EmailSubmission } from "./capabilities/emailsubmission/emailsubmission.js";
18
+ export { Identity } from "./capabilities/identity/identity.js";
19
+ export { Mailbox } from "./capabilities/mailbox/mailbox.js";
20
+ export { MaskedEmail } from "./capabilities/maskedemail/maskedemail.js";
21
+ export { SearchSnippet } from "./capabilities/searchsnippet/searchsnippet.js";
22
+ export { Thread } from "./capabilities/thread/thread.js";
23
+ export { VacationResponse } from "./capabilities/vacationresponse/vacationresponse.js";
24
+ export * from "./common/registry.js";
25
+ export type * from "./common/types.js";
26
+ export type { CapabilityRegistrationResult, ClientContext, ConnectionStatus, EventEmitterFn, JMAPAccount, JMAPClientEventName, JMAPClientEvents, JMAPClientInterface, JMAPClientOptions, JMAPSession, JMAPUploadResponse, Logger, LoggerMethod, Transport, TransportRequestOptions, TransportResponseType, TypedEventEmitterFn, } from "./jmap-client/types.js";
27
+ export type { AddedItem, BaseChangesRequestInvocationArgs, BaseChangesResponseInvocationArgs, BaseCopyRequestInvocationArgs, BaseCopyResponseInvocationArgs, BaseFilterCondition, BaseGetRequestInvocationArgs, BaseGetResponseInvocationArgs, BaseInvocationArgs, BaseObject, BaseQueryChangesRequestInvocationArgs, BaseQueryChangesResponseInvocationArgs, BaseQueryRequestInvocationArgs, BaseQueryResponseInvocationArgs, BaseSetRequestInvocationArgs, BaseSetResponseInvocationArgs, Comparator, FilterCondition, FilterOperator, GenericInvocationFactory, InvocationArgs, InvocationFactory, InvocationFactoryCollection, InvocationFactoryMethods, InvocationInterface, PatchObject, ResultReferenceInterface, SetError, SetErrorCategory, SetErrorType, } from "./invocation/types.js";
28
+ export type { AccountCapabilityValidationResult, BasePluginContext, CapabilityDefinition, CapabilityRegistryInterface, InvocationFactoryMap, PluginContext, PluginData, PluginLifecycleHook, PluginTrigger, ServerCapabilityValidationResult, TransformationPlugin, TransformationPluginMap, TransformerExecutionContext, ValidationPlugin, ValidationPluginContext, ValidationPluginLifecycleHook, ValidationPluginMap, ValidationPluginTrigger, ValidationResult, ValidatorExecutionContext, } from "./capability-registry/types.js";
29
+ export type { HandlerFn, InvocationHandlerMap } from "./invocation-factory/types.js";
30
+ export type { CoreEchoRequestInvocationArgs, CoreEchoResponseInvocationArgs, CoreInvocationArgs, } from "./capabilities/core/types.js";
31
+ export type { EmailAddress, EmailAddressGroup, EmailBodyPart, EmailBodyValue, EmailChangesRequestInvocationArgs, EmailChangesResponseInvocationArgs, EmailCopyRequestInvocationArgs, EmailCopyResponseInvocationArgs, EmailFilterCondition, EmailGetRequestInvocationArgs, EmailGetResponseInvocationArgs, EmailHeader, EmailImport, EmailImportRequestInvocationArgs, EmailImportResponseInvocationArgs, EmailObject, EmailObjectServerSet, EmailObjectSettable, EmailParseRequestInvocationArgs, EmailParseResponseInvocationArgs, EmailQueryChangesRequestInvocationArgs, EmailQueryChangesResponseInvocationArgs, EmailQueryRequestInvocationArgs, EmailQueryResponseInvocationArgs, EmailSetRequestInvocationArgs, EmailSetResponseInvocationArgs, JMAPKeywords, } from "./capabilities/email/types.js";
32
+ export type { MailboxChangesRequestInvocationArgs, MailboxChangesResponseInvocationArgs, MailboxFilterCondition, MailboxGetRequestInvocationArgs, MailboxGetResponseInvocationArgs, MailboxObject, MailboxObjectServerSet, MailboxObjectSettable, MailboxQueryChangesRequestInvocationArgs, MailboxQueryChangesResponseInvocationArgs, MailboxQueryRequestInvocationArgs, MailboxQueryResponseInvocationArgs, MailboxRights, MailboxSetRequestInvocationArgs, MailboxSetResponseInvocationArgs, } from "./capabilities/mailbox/types.js";
33
+ export type { ThreadChangesRequestInvocationArgs, ThreadChangesResponseInvocationArgs, ThreadGetRequestInvocationArgs, ThreadGetResponseInvocationArgs, ThreadObject, ThreadObjectServerSet, } from "./capabilities/thread/types.js";
34
+ export type { IdentityChangesRequestInvocationArgs, IdentityChangesResponseInvocationArgs, IdentityGetRequestInvocationArgs, IdentityGetResponseInvocationArgs, IdentityObject, IdentityObjectServerSet, IdentityObjectSettable, IdentitySetRequestInvocationArgs, IdentitySetResponseInvocationArgs, } from "./capabilities/identity/types.js";
35
+ export { HTTPDigestAlgorithmSchema as HTTPDigestAlgorithmValueSchema } from "./capabilities/blob/types.js";
36
+ export type { BlobCopyRequestInvocationArgs, BlobCopyResponseInvocationArgs, BlobDataFormat, BlobGetRequestInvocationArgs, BlobGetResponseInvocationArgs, BlobInfo, BlobLookupRequestInvocationArgs, BlobLookupResponseInvocationArgs, BlobObject, BlobObjectData, BlobObjectDigest, BlobObjectSize, BlobUploadRequestInvocationArgs, BlobUploadResponseInvocationArgs, DataCreatedObject, DataSourceObject, HTTPDigestAlgorithm, UploadObject, } from "./capabilities/blob/types.js";
37
+ export type { DeliveryStatus, EmailSubmissionAddress, EmailSubmissionChangesRequestInvocationArgs, EmailSubmissionChangesResponseInvocationArgs, EmailSubmissionEnvelope, EmailSubmissionFilterCondition, EmailSubmissionGetRequestInvocationArgs, EmailSubmissionGetResponseInvocationArgs, EmailSubmissionObject, EmailSubmissionObjectServerSet, EmailSubmissionObjectSettable, EmailSubmissionQueryChangesRequestInvocationArgs, EmailSubmissionQueryChangesResponseInvocationArgs, EmailSubmissionQueryRequestInvocationArgs, EmailSubmissionQueryResponseInvocationArgs, EmailSubmissionSetRequestInvocationArgs, EmailSubmissionSetResponseInvocationArgs, } from "./capabilities/emailsubmission/types.js";
38
+ export type { VacationResponseGetRequestInvocationArgs, VacationResponseGetResponseInvocationArgs, VacationResponseObject, VacationResponseObjectServerSet, VacationResponseObjectSettable, VacationResponseSetRequestInvocationArgs, VacationResponseSetResponseInvocationArgs, } from "./capabilities/vacationresponse/types.js";
39
+ export type { MaskedEmailGetRequestInvocationArgs, MaskedEmailGetResponseInvocationArgs, MaskedEmailObject, MaskedEmailObjectServerSet, MaskedEmailObjectSettable, MaskedEmailSetRequestInvocationArgs, MaskedEmailSetResponseInvocationArgs, MaskedEmailState, } from "./capabilities/maskedemail/types.js";
40
+ export type { SearchSnippetGetRequestInvocationArgs, SearchSnippetGetResponseInvocationArgs, SearchSnippetObject, } from "./capabilities/searchsnippet/types.js";
@@ -0,0 +1,33 @@
1
+ // Classes
2
+ export { ErrorInvocation } from "./invocation/error-invocation.js";
3
+ export { Invocation } from "./invocation/invocation.js";
4
+ export { ResultReference } from "./invocation/result-reference.js";
5
+ export { JMAPClient } from "./jmap-client/jmap-client.js";
6
+ export { RequestBuilder } from "./request-builder/request-builder.js";
7
+ // Type guards
8
+ export { isErrorInvocation, isResultReference } from "./invocation/utils.js";
9
+ // Error handling
10
+ export { JMAPRequestError } from "./jmap-client/utils/jmap-request-error.js";
11
+ // Capability definitions
12
+ export { BlobCapability } from "./capabilities/blob-capability.js";
13
+ export { CoreCapability } from "./capabilities/core-capability.js";
14
+ export { EmailCapability } from "./capabilities/email-capability.js";
15
+ export { MaskedEmailCapability } from "./capabilities/maskedemail-capability.js";
16
+ export { SubmissionCapability } from "./capabilities/submission-capability.js";
17
+ export { VacationResponseCapability } from "./capabilities/vacationresponse-capability.js";
18
+ // Invocation factories
19
+ export { Blob } from "./capabilities/blob/blob.js";
20
+ export { Core } from "./capabilities/core/core.js";
21
+ export { Email } from "./capabilities/email/email.js";
22
+ export { EmailSubmission } from "./capabilities/emailsubmission/emailsubmission.js";
23
+ export { Identity } from "./capabilities/identity/identity.js";
24
+ export { Mailbox } from "./capabilities/mailbox/mailbox.js";
25
+ export { MaskedEmail } from "./capabilities/maskedemail/maskedemail.js";
26
+ export { SearchSnippet } from "./capabilities/searchsnippet/searchsnippet.js";
27
+ export { Thread } from "./capabilities/thread/thread.js";
28
+ export { VacationResponse } from "./capabilities/vacationresponse/vacationresponse.js";
29
+ // Common types and capability URI constants
30
+ export * from "./common/registry.js";
31
+ // Blob types
32
+ export { HTTPDigestAlgorithmSchema as HTTPDigestAlgorithmValueSchema } from "./capabilities/blob/types.js";
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAEtE,cAAc;AACd,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE7E,iBAAiB;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAE7E,yBAAyB;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAE3F,uBAAuB;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAC;AAEvF,4CAA4C;AAC5C,cAAc,sBAAsB,CAAC;AAqKrC,aAAa;AACb,OAAO,EAAE,yBAAyB,IAAI,8BAA8B,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Invocation } from "./invocation.js";
2
+ import type { BaseInvocationArgs } from "./types.js";
3
+ /**
4
+ * Creates a Proxy over an {@link Invocation} that behaves like a plain object.
5
+ *
6
+ * The returned Proxy supports property access, `in`, `Object.keys()`, spread,
7
+ * and `JSON.stringify()`. If the host implements `setArgument` and `deleteArgument`,
8
+ * property assignment and deletion delegate to those methods (preserving any
9
+ * validation they perform). Otherwise, those operations throw a TypeError.
10
+ *
11
+ * @param host The backing Invocation to proxy
12
+ * @returns A Proxy that presents the host's arguments as an object
13
+ */
14
+ export declare function createArgumentsProxy<TArgs extends BaseInvocationArgs>(host: Invocation<TArgs>): TArgs;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Creates a Proxy over an {@link Invocation} that behaves like a plain object.
3
+ *
4
+ * The returned Proxy supports property access, `in`, `Object.keys()`, spread,
5
+ * and `JSON.stringify()`. If the host implements `setArgument` and `deleteArgument`,
6
+ * property assignment and deletion delegate to those methods (preserving any
7
+ * validation they perform). Otherwise, those operations throw a TypeError.
8
+ *
9
+ * @param host The backing Invocation to proxy
10
+ * @returns A Proxy that presents the host's arguments as an object
11
+ */
12
+ export function createArgumentsProxy(host) {
13
+ return new Proxy(host, {
14
+ get: (target, prop) => target.getArgument(prop),
15
+ has: (target, prop) => target.hasArgument(prop),
16
+ ownKeys: (target) => target.argumentKeys(),
17
+ getOwnPropertyDescriptor: (target, prop) => {
18
+ if (target.hasArgument(prop)) {
19
+ return {
20
+ configurable: true,
21
+ enumerable: true,
22
+ writable: typeof target.setArgument === "function",
23
+ value: target.getArgument(prop),
24
+ };
25
+ }
26
+ return undefined;
27
+ },
28
+ set(target, prop, value) {
29
+ target.setArgument(prop, value);
30
+ return true;
31
+ },
32
+ deleteProperty(target, prop) {
33
+ return target.deleteArgument(prop);
34
+ },
35
+ });
36
+ }
37
+ //# sourceMappingURL=arguments-proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arguments-proxy.js","sourceRoot":"","sources":["../../../src/invocation/arguments-proxy.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAAmC,IAAuB;IAE1F,OAAO,IAAI,KAAK,CAAoB,IAAI,EAAE;QACtC,GAAG,EAAE,CAAC,MAAM,EAAE,IAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;QAC5D,GAAG,EAAE,CAAC,MAAM,EAAE,IAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;QAC5D,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE;QAC1C,wBAAwB,EAAE,CAAC,MAAM,EAAE,IAAiB,EAAE,EAAE;YACpD,IAAI,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3B,OAAO;oBACH,YAAY,EAAE,IAAI;oBAClB,UAAU,EAAE,IAAI;oBAChB,QAAQ,EAAE,OAAO,MAAM,CAAC,WAAW,KAAK,UAAU;oBAClD,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;iBAClC,CAAC;YACN,CAAC;YACD,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,GAAG,CAAC,MAAM,EAAE,IAAiB,EAAE,KAAsD;YACjF,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,cAAc,CAAC,MAAM,EAAE,IAAiB;YACpC,OAAO,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC;KACJ,CAAqB,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { JMAPResponseInvocationErrorArgs, JSONValue } from "../common/types.js";
2
+ /**
3
+ * Represents a JMAP method-level error invocation.
4
+ *
5
+ * This class encapsulates error responses from the JMAP server, providing a similar interface
6
+ * to Invocation, but with no dataType property. The error arguments are stored as a map and
7
+ * can be accessed via the `arguments` getter. The error type is available via the `type` getter.
8
+ */
9
+ export declare class ErrorInvocation {
10
+ #private;
11
+ /**
12
+ * Construct a new ErrorInvocation.
13
+ * @param args The error arguments, including the required `type` property.
14
+ * @param methodCallId The unique symbol for this invocation (optional; a new symbol is generated if omitted).
15
+ */
16
+ constructor(args: JMAPResponseInvocationErrorArgs, methodCallId?: symbol);
17
+ /** The name of this invocation, always "error". */
18
+ get name(): "error";
19
+ /** The error arguments as a plain object. */
20
+ get arguments(): {
21
+ [k: string]: JSONValue;
22
+ };
23
+ /** The unique symbol identifier for this error invocation. */
24
+ get id(): symbol;
25
+ /** The error type string (e.g., "serverFail", "invalidArguments"). */
26
+ get type(): JMAPResponseInvocationErrorArgs["type"];
27
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Represents a JMAP method-level error invocation.
3
+ *
4
+ * This class encapsulates error responses from the JMAP server, providing a similar interface
5
+ * to Invocation, but with no dataType property. The error arguments are stored as a map and
6
+ * can be accessed via the `arguments` getter. The error type is available via the `type` getter.
7
+ */
8
+ export class ErrorInvocation {
9
+ /** Map of error argument keys to their values. */
10
+ #arguments;
11
+ /** The unique symbol identifier for this error invocation. */
12
+ #id;
13
+ /**
14
+ * Construct a new ErrorInvocation.
15
+ * @param args The error arguments, including the required `type` property.
16
+ * @param methodCallId The unique symbol for this invocation (optional; a new symbol is generated if omitted).
17
+ */
18
+ constructor(args, methodCallId) {
19
+ this.#arguments = new Map(Object.entries(args));
20
+ this.#id = methodCallId ?? Symbol();
21
+ }
22
+ /** The name of this invocation, always "error". */
23
+ get name() {
24
+ return "error";
25
+ }
26
+ /** The error arguments as a plain object. */
27
+ get arguments() {
28
+ return Object.fromEntries(this.#arguments);
29
+ }
30
+ /** The unique symbol identifier for this error invocation. */
31
+ get id() {
32
+ return this.#id;
33
+ }
34
+ /** The error type string (e.g., "serverFail", "invalidArguments"). */
35
+ get type() {
36
+ return this.#arguments.get("type");
37
+ }
38
+ }
39
+ //# sourceMappingURL=error-invocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-invocation.js","sourceRoot":"","sources":["../../../src/invocation/error-invocation.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;IACxB,kDAAkD;IACzC,UAAU,CAAiE;IACpF,8DAA8D;IACrD,GAAG,CAAS;IAErB;;;;OAIG;IACH,YAAY,IAAqC,EAAE,YAAqB;QACpE,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,IAAI,CAAC,GAAG,GAAG,YAAY,IAAI,MAAM,EAAE,CAAC;IACxC,CAAC;IACD,mDAAmD;IACnD,IAAI,IAAI;QACJ,OAAO,OAAgB,CAAC;IAC5B,CAAC;IAED,6CAA6C;IAC7C,IAAI,SAAS;QACT,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED,8DAA8D;IAC9D,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAED,sEAAsE;IACtE,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAA4C,CAAC;IAClF,CAAC;CACJ"}
@@ -0,0 +1,111 @@
1
+ import type { JMAPCapability, JMAPDataType, JMAPMethodName, JMAPRequestInvocation } from "../common/types.js";
2
+ import { ResultReference } from "./result-reference.js";
3
+ import type { BaseInvocationArgs, InvocationArgs, InvocationInterface, JMAPInvocationInternal } from "./types.js";
4
+ /**
5
+ * Base class for invocations.
6
+ * @remarks
7
+ * This class is not meant to be constructed directly. Instead, use one of the capabilities subclasses,
8
+ * or extend it to build a new capability.
9
+ * @typeParam TArgs The type of the arguments for the invocation
10
+ */
11
+ export declare abstract class Invocation<TArgs extends BaseInvocationArgs> implements InvocationInterface<TArgs> {
12
+ #private;
13
+ abstract readonly uri: JMAPCapability;
14
+ /**
15
+ * Constructs an Invocation
16
+ *
17
+ * @param dataType The data type of the invocation
18
+ * @param method The name of the method being invoked (e.g., "get", "set", "query")
19
+ * @param args object containing named arguments for that method or response
20
+ * @throws {InvalidResultReferenceError}
21
+ * @throws {UnexpectedResultReferenceError}
22
+ */
23
+ constructor(dataType: JMAPDataType, method: JMAPMethodName, args: InvocationArgs<TArgs>, methodCallId?: symbol);
24
+ /**
25
+ * Get the name of the method
26
+ *
27
+ * The name of the method in the format "{dataType}/{method}"
28
+ */
29
+ get name(): string;
30
+ /**
31
+ * Get the data type of the invocation
32
+ *
33
+ * The data type of the invocation is the name of the object that methods are associated with
34
+ * (e.g., "Email", "Mailbox", "Thread")
35
+ */
36
+ get dataType(): JMAPDataType;
37
+ /**
38
+ * Get the method name of the invocation
39
+ *
40
+ * The method name of the invocation is the name of the method being invoked (e.g., "get", "set", "query")
41
+ */
42
+ get method(): JMAPMethodName;
43
+ /**
44
+ * Get the internal identifier for the invocation
45
+ *
46
+ * The internal identifier is a unique symbol used to identify this invocation instance.
47
+ */
48
+ get id(): symbol;
49
+ /**
50
+ * Get the arguments for the invocation
51
+ *
52
+ * The arguments are the named parameters passed to the method being invoked.
53
+ */
54
+ get arguments(): TArgs;
55
+ /**
56
+ * Get the value of a named argument.
57
+ * @param name The name of the argument
58
+ * @returns The value or result reference for the named argument.
59
+ */
60
+ getArgument<K extends keyof TArgs & string>(name: K): TArgs[K];
61
+ /**
62
+ * Set the value of a named argument.
63
+ * @param name The name of the argument
64
+ * @param value The value or result reference for the named argument.
65
+ */
66
+ setArgument<K extends keyof TArgs & string>(name: K, value: InvocationArgs<TArgs>[K]): void;
67
+ /**
68
+ * Delete a named argument.
69
+ * @param name The name of the argument
70
+ * @returns Whether the argument was deleted
71
+ */
72
+ deleteArgument(name: keyof TArgs & string): boolean;
73
+ /**
74
+ * Check if a named argument exists.
75
+ * @param name The name of the argument
76
+ * @returns Whether the argument exists
77
+ */
78
+ hasArgument(name: keyof TArgs & string): boolean;
79
+ /**
80
+ * Get the keys of all arguments.
81
+ * @returns An array of argument names
82
+ */
83
+ argumentKeys(): (keyof TArgs & string)[];
84
+ /**
85
+ * Create a result reference for a named argument to use in another method.
86
+ * @param path The path to the result to reference
87
+ * @returns The result reference
88
+ */
89
+ createReference(path: string): ResultReference;
90
+ /**
91
+ * Resolve the invocation into a JMAP request invocation tuple.
92
+ *
93
+ * Converts internal {@link ResultReference} arguments into their wire format
94
+ * (`#property` keys with resolved `resultOf` ids) and produces the
95
+ * `[name, arguments, methodCallId]` tuple expected by the JMAP protocol.
96
+ *
97
+ * @param id The method call id to assign to this invocation in the request
98
+ * @param lookupId A function that resolves an invocation's internal symbol id
99
+ * to the string method call id assigned in the request
100
+ * @returns The resolved JMAP request invocation tuple
101
+ * @throws If a result reference refers to an invocation whose id cannot be resolved
102
+ */
103
+ resolve(id: string, lookupId: (id: symbol) => string | undefined): JMAPRequestInvocation;
104
+ /**
105
+ * Convert the invocation to a serialisable representation.
106
+ * @returns A serialisable representation of the invocation
107
+ * @remarks It is expected that the caller will provide a resolver function to resolve the ID
108
+ * and any result references referring to other invocations.
109
+ */
110
+ toJSON(): JMAPInvocationInternal;
111
+ }
@@ -0,0 +1,158 @@
1
+ import { createArgumentsProxy } from "./arguments-proxy.js";
2
+ import { ResultReference } from "./result-reference.js";
3
+ import { isResultReference } from "./utils.js";
4
+ /**
5
+ * Base class for invocations.
6
+ * @remarks
7
+ * This class is not meant to be constructed directly. Instead, use one of the capabilities subclasses,
8
+ * or extend it to build a new capability.
9
+ * @typeParam TArgs The type of the arguments for the invocation
10
+ */
11
+ export class Invocation {
12
+ #dataType;
13
+ #method;
14
+ #arguments;
15
+ #id;
16
+ #argumentsProxy = null;
17
+ /**
18
+ * Constructs an Invocation
19
+ *
20
+ * @param dataType The data type of the invocation
21
+ * @param method The name of the method being invoked (e.g., "get", "set", "query")
22
+ * @param args object containing named arguments for that method or response
23
+ * @throws {InvalidResultReferenceError}
24
+ * @throws {UnexpectedResultReferenceError}
25
+ */
26
+ constructor(dataType, method, args, methodCallId) {
27
+ this.#dataType = dataType;
28
+ this.#method = method;
29
+ this.#arguments = new Map(Object.entries(args));
30
+ this.#id = methodCallId ?? Symbol();
31
+ }
32
+ /**
33
+ * Get the name of the method
34
+ *
35
+ * The name of the method in the format "{dataType}/{method}"
36
+ */
37
+ get name() {
38
+ return `${this.#dataType}/${this.#method}`;
39
+ }
40
+ /**
41
+ * Get the data type of the invocation
42
+ *
43
+ * The data type of the invocation is the name of the object that methods are associated with
44
+ * (e.g., "Email", "Mailbox", "Thread")
45
+ */
46
+ get dataType() {
47
+ return this.#dataType;
48
+ }
49
+ /**
50
+ * Get the method name of the invocation
51
+ *
52
+ * The method name of the invocation is the name of the method being invoked (e.g., "get", "set", "query")
53
+ */
54
+ get method() {
55
+ return this.#method;
56
+ }
57
+ /**
58
+ * Get the internal identifier for the invocation
59
+ *
60
+ * The internal identifier is a unique symbol used to identify this invocation instance.
61
+ */
62
+ get id() {
63
+ return this.#id;
64
+ }
65
+ /**
66
+ * Get the arguments for the invocation
67
+ *
68
+ * The arguments are the named parameters passed to the method being invoked.
69
+ */
70
+ get arguments() {
71
+ this.#argumentsProxy ??= createArgumentsProxy(this);
72
+ return this.#argumentsProxy;
73
+ }
74
+ /**
75
+ * Get the value of a named argument.
76
+ * @param name The name of the argument
77
+ * @returns The value or result reference for the named argument.
78
+ */
79
+ getArgument(name) {
80
+ return this.#arguments.get(name);
81
+ }
82
+ /**
83
+ * Set the value of a named argument.
84
+ * @param name The name of the argument
85
+ * @param value The value or result reference for the named argument.
86
+ */
87
+ setArgument(name, value) {
88
+ if (isResultReference(value) && value.id === this.#id) {
89
+ throw new Error(`Result reference must not reference the invocation itself`);
90
+ }
91
+ this.#arguments.set(name, value);
92
+ }
93
+ /**
94
+ * Delete a named argument.
95
+ * @param name The name of the argument
96
+ * @returns Whether the argument was deleted
97
+ */
98
+ deleteArgument(name) {
99
+ return this.#arguments.delete(name);
100
+ }
101
+ /**
102
+ * Check if a named argument exists.
103
+ * @param name The name of the argument
104
+ * @returns Whether the argument exists
105
+ */
106
+ hasArgument(name) {
107
+ return this.#arguments.has(name);
108
+ }
109
+ /**
110
+ * Get the keys of all arguments.
111
+ * @returns An array of argument names
112
+ */
113
+ argumentKeys() {
114
+ return [...this.#arguments.keys()];
115
+ }
116
+ /**
117
+ * Create a result reference for a named argument to use in another method.
118
+ * @param path The path to the result to reference
119
+ * @returns The result reference
120
+ */
121
+ createReference(path) {
122
+ return new ResultReference(this.#id, this.name, path);
123
+ }
124
+ /**
125
+ * Resolve the invocation into a JMAP request invocation tuple.
126
+ *
127
+ * Converts internal {@link ResultReference} arguments into their wire format
128
+ * (`#property` keys with resolved `resultOf` ids) and produces the
129
+ * `[name, arguments, methodCallId]` tuple expected by the JMAP protocol.
130
+ *
131
+ * @param id The method call id to assign to this invocation in the request
132
+ * @param lookupId A function that resolves an invocation's internal symbol id
133
+ * to the string method call id assigned in the request
134
+ * @returns The resolved JMAP request invocation tuple
135
+ * @throws If a result reference refers to an invocation whose id cannot be resolved
136
+ */
137
+ resolve(id, lookupId) {
138
+ const entries = [...this.#arguments];
139
+ const args = Object.fromEntries(entries.map(([property, value]) => {
140
+ return value instanceof ResultReference ? [`#${property}`, value.resolve(lookupId)] : [property, value];
141
+ }));
142
+ return [this.name, args, id];
143
+ }
144
+ /**
145
+ * Convert the invocation to a serialisable representation.
146
+ * @returns A serialisable representation of the invocation
147
+ * @remarks It is expected that the caller will provide a resolver function to resolve the ID
148
+ * and any result references referring to other invocations.
149
+ */
150
+ toJSON() {
151
+ return [
152
+ this.name,
153
+ Object.fromEntries(Array.from(this.#arguments.entries(), ([k, v]) => v instanceof ResultReference ? [`#${k}`, v] : [k, v])),
154
+ this.#id,
155
+ ];
156
+ }
157
+ }
158
+ //# sourceMappingURL=invocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocation.js","sourceRoot":"","sources":["../../../src/invocation/invocation.ts"],"names":[],"mappings":"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"}