@mdbase-dev/connect 0.1.0-beta.100

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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +696 -0
  3. package/dist/advanced.d.ts +9 -0
  4. package/dist/advanced.js +6 -0
  5. package/dist/application-contract.d.ts +22 -0
  6. package/dist/application-contract.js +75 -0
  7. package/dist/application-identity.d.ts +34 -0
  8. package/dist/application-identity.js +148 -0
  9. package/dist/application-session.d.ts +167 -0
  10. package/dist/application-session.js +722 -0
  11. package/dist/async.d.ts +1 -0
  12. package/dist/async.js +19 -0
  13. package/dist/authority-proof.d.ts +3 -0
  14. package/dist/authority-proof.js +24 -0
  15. package/dist/authority-sync-request.d.ts +3 -0
  16. package/dist/authority-sync-request.js +20 -0
  17. package/dist/authorization-refresh.d.ts +14 -0
  18. package/dist/authorization-refresh.js +41 -0
  19. package/dist/authorization-types.d.ts +7 -0
  20. package/dist/authorization-types.js +1 -0
  21. package/dist/authorization-url.d.ts +5 -0
  22. package/dist/authorization-url.js +34 -0
  23. package/dist/base64.d.ts +3 -0
  24. package/dist/base64.js +21 -0
  25. package/dist/browser/integrity.json +4 -0
  26. package/dist/browser/mdbase-connect.min.js +3 -0
  27. package/dist/browser/mdbase-connect.min.js.sha384 +1 -0
  28. package/dist/browser.d.ts +3 -0
  29. package/dist/browser.js +5 -0
  30. package/dist/capabilities.d.ts +24 -0
  31. package/dist/capabilities.js +91 -0
  32. package/dist/collection-client.d.ts +66 -0
  33. package/dist/collection-client.js +686 -0
  34. package/dist/connect-authorization-helpers.d.ts +4 -0
  35. package/dist/connect-authorization-helpers.js +25 -0
  36. package/dist/connect-options.d.ts +35 -0
  37. package/dist/connect-options.js +1 -0
  38. package/dist/connect.d.ts +66 -0
  39. package/dist/connect.js +711 -0
  40. package/dist/connection-file-transport.d.ts +34 -0
  41. package/dist/connection-file-transport.js +85 -0
  42. package/dist/connection-index.d.ts +3 -0
  43. package/dist/connection-index.js +20 -0
  44. package/dist/connection-notifications.d.ts +31 -0
  45. package/dist/connection-notifications.js +197 -0
  46. package/dist/connection-transport-internals.d.ts +24 -0
  47. package/dist/connection-transport-internals.js +1 -0
  48. package/dist/connection-transport.d.ts +64 -0
  49. package/dist/connection-transport.js +725 -0
  50. package/dist/connection-types.d.ts +38 -0
  51. package/dist/connection-types.js +1 -0
  52. package/dist/connection.d.ts +175 -0
  53. package/dist/connection.js +606 -0
  54. package/dist/crypto-entry.d.ts +7 -0
  55. package/dist/crypto-entry.js +4 -0
  56. package/dist/crypto.d.ts +63 -0
  57. package/dist/crypto.js +409 -0
  58. package/dist/direct-access.d.ts +3 -0
  59. package/dist/direct-access.js +29 -0
  60. package/dist/errors.d.ts +45 -0
  61. package/dist/errors.js +142 -0
  62. package/dist/external-store.d.ts +10 -0
  63. package/dist/external-store.js +10 -0
  64. package/dist/file-crypto.d.ts +25 -0
  65. package/dist/file-crypto.js +132 -0
  66. package/dist/file-sha256.d.ts +12 -0
  67. package/dist/file-sha256.js +143 -0
  68. package/dist/file-stream-source.d.ts +17 -0
  69. package/dist/file-stream-source.js +157 -0
  70. package/dist/file-transfer-internals.d.ts +23 -0
  71. package/dist/file-transfer-internals.js +228 -0
  72. package/dist/files.d.ts +115 -0
  73. package/dist/files.js +563 -0
  74. package/dist/fresh-encrypted-request.d.ts +4 -0
  75. package/dist/fresh-encrypted-request.js +28 -0
  76. package/dist/grant-key-leases.d.ts +24 -0
  77. package/dist/grant-key-leases.js +144 -0
  78. package/dist/hosted-file-request.d.ts +6 -0
  79. package/dist/hosted-file-request.js +63 -0
  80. package/dist/hosted-operation-response.d.ts +5 -0
  81. package/dist/hosted-operation-response.js +26 -0
  82. package/dist/index.d.ts +27 -0
  83. package/dist/index.js +10 -0
  84. package/dist/internal-types.d.ts +100 -0
  85. package/dist/internal-types.js +1 -0
  86. package/dist/local-file-transport.d.ts +37 -0
  87. package/dist/local-file-transport.js +457 -0
  88. package/dist/mdbase-connect.d.ts +28 -0
  89. package/dist/mdbase-connect.js +53 -0
  90. package/dist/notifications.d.ts +48 -0
  91. package/dist/notifications.js +52 -0
  92. package/dist/operation-helpers.d.ts +27 -0
  93. package/dist/operation-helpers.js +144 -0
  94. package/dist/operation-types.d.ts +707 -0
  95. package/dist/operation-types.js +1 -0
  96. package/dist/outcomes.d.ts +51 -0
  97. package/dist/outcomes.js +194 -0
  98. package/dist/pending-mutation-store.d.ts +13 -0
  99. package/dist/pending-mutation-store.js +64 -0
  100. package/dist/pending-recovery-transports.d.ts +5 -0
  101. package/dist/pending-recovery-transports.js +52 -0
  102. package/dist/popup-authorization.d.ts +31 -0
  103. package/dist/popup-authorization.js +100 -0
  104. package/dist/query-pagination.d.ts +6 -0
  105. package/dist/query-pagination.js +119 -0
  106. package/dist/request-budget.d.ts +34 -0
  107. package/dist/request-budget.js +104 -0
  108. package/dist/request-coordinator.d.ts +29 -0
  109. package/dist/request-coordinator.js +213 -0
  110. package/dist/retired-grant-keys.d.ts +9 -0
  111. package/dist/retired-grant-keys.js +56 -0
  112. package/dist/runtime-utils.d.ts +52 -0
  113. package/dist/runtime-utils.js +368 -0
  114. package/dist/saved-view-pagination.d.ts +6 -0
  115. package/dist/saved-view-pagination.js +76 -0
  116. package/dist/selection.d.ts +48 -0
  117. package/dist/selection.js +112 -0
  118. package/dist/session.d.ts +114 -0
  119. package/dist/session.js +569 -0
  120. package/dist/shared-operation.d.ts +7 -0
  121. package/dist/shared-operation.js +41 -0
  122. package/dist/stored-token.d.ts +10 -0
  123. package/dist/stored-token.js +64 -0
  124. package/dist/structured-readiness.d.ts +77 -0
  125. package/dist/structured-readiness.js +126 -0
  126. package/dist/token-response.d.ts +12 -0
  127. package/dist/token-response.js +81 -0
  128. package/dist/transient-retry.d.ts +22 -0
  129. package/dist/transient-retry.js +59 -0
  130. package/dist/watch-policy.d.ts +8 -0
  131. package/dist/watch-policy.js +12 -0
  132. package/package.json +51 -0
@@ -0,0 +1,686 @@
1
+ import { abortableDelay } from "./async.js";
2
+ import { coordinatedQueryPages } from "./query-pagination.js";
3
+ import { coordinatedSavedViewPages } from "./saved-view-pagination.js";
4
+ import { MdbaseConnectError, connectError, connectProblem, operationProblem } from "./errors.js";
5
+ import { COLLECTION_CHANGES_PROBLEM_CODES, COLLECTION_DESCRIPTION_PROBLEM_CODES, COLLECTION_MUTATION_PROBLEM_CODES, COLLECTION_QUERY_PROBLEM_CODES, COLLECTION_READ_PROBLEM_CODES, COLLECTION_TYPE_PROBLEM_CODES, ALL_CONNECT_PROBLEM_CODES, captureConnectOutcome, connectFailure, connectSuccess } from "./outcomes.js";
6
+ import { createRequestBudget, DEFAULT_REQUEST_TIMEOUT_MS, requestAbortReason } from "./request-budget.js";
7
+ import { watchRetryPolicy } from "./watch-policy.js";
8
+ /**
9
+ * Typed collection operations independent of OAuth, HTTP, or storage.
10
+ *
11
+ * Application code can use this surface against Connect, the developer
12
+ * sandbox, or another provider without changing its record logic.
13
+ */
14
+ export class MdbaseCollectionClient {
15
+ transport;
16
+ requestTimeoutMs;
17
+ constructor(transport, requestTimeoutMs = DEFAULT_REQUEST_TIMEOUT_MS) {
18
+ this.transport = transport;
19
+ this.requestTimeoutMs = requestTimeoutMs;
20
+ }
21
+ operation(operation, input, options) {
22
+ return captureConnectOutcome(() => this.transport.operation(operation, input, options), ALL_CONNECT_PROBLEM_CODES);
23
+ }
24
+ async describe(options) {
25
+ const outcome = await this.rawOperation("describe", {}, COLLECTION_DESCRIPTION_PROBLEM_CODES, options);
26
+ return mapOutcome(outcome, wireCollectionDescription);
27
+ }
28
+ async changes(input = {}, options) {
29
+ const outcome = await this.rawOperation("changes", input, COLLECTION_CHANGES_PROBLEM_CODES, options);
30
+ return mapOutcome(outcome, wireChangesPage);
31
+ }
32
+ async read(input, options) {
33
+ const outcome = await this.envelopeOperation("read", wireReadInput(input), COLLECTION_READ_PROBLEM_CODES, options);
34
+ return mapOutcome(outcome, wireRecordDocument);
35
+ }
36
+ async query(input = {}, options) {
37
+ const outcome = await this.envelopeOperation("query", wireQueryInput(input), COLLECTION_QUERY_PROBLEM_CODES, options);
38
+ return mapOutcome(outcome, ({ results, meta }) => ({
39
+ results: results.map(wireQueryRecord),
40
+ ...(meta ? {
41
+ meta: {
42
+ ...(typeof meta.total_count === "number" ? { totalCount: meta.total_count } : {}),
43
+ ...(meta.total_count_outcome === undefined
44
+ ? {}
45
+ : { totalCountOutcome: meta.total_count_outcome }),
46
+ hasMore: meta.has_more,
47
+ ...(meta.cursor ? { cursor: meta.cursor } : {}),
48
+ ...(meta.snapshot ? { snapshot: meta.snapshot } : {})
49
+ }
50
+ } : {})
51
+ }));
52
+ }
53
+ async *queryPages(input = {}, options = {}) {
54
+ yield* coordinatedQueryPages((pageInput, pageOptions) => this.query(pageInput, pageOptions), (cursor) => this.releaseQueryCursor(cursor), input, options);
55
+ }
56
+ async queryAll(input = {}, options = {}) {
57
+ const budget = createRequestBudget(options, this.requestTimeoutMs);
58
+ const results = [];
59
+ let finalPage;
60
+ const diagnostics = [];
61
+ try {
62
+ for await (const outcome of this.queryPages(input, {
63
+ firstPageSize: options.firstPageSize,
64
+ pageSize: options.pageSize,
65
+ signal: budget.signal,
66
+ pageTimeoutMs: null,
67
+ coordination: options.coordination,
68
+ onProgress: options.onProgress
69
+ })) {
70
+ if (!outcome.ok)
71
+ return outcome;
72
+ const page = outcome.value;
73
+ results.push(...page.results);
74
+ finalPage = page;
75
+ diagnostics.push(...outcome.diagnostics);
76
+ }
77
+ if (budget.signal.aborted)
78
+ throw requestAbortReason(budget.signal);
79
+ return connectSuccess({
80
+ results,
81
+ meta: {
82
+ totalCount: finalPage?.meta?.totalCount ?? results.length,
83
+ hasMore: finalPage ? !finalPage.complete : false,
84
+ ...(finalPage?.snapshot ? { snapshot: finalPage.snapshot } : {})
85
+ }
86
+ }, diagnostics);
87
+ }
88
+ catch (error) {
89
+ if (error instanceof MdbaseConnectError) {
90
+ return connectFailure(error.problem);
91
+ }
92
+ throw error;
93
+ }
94
+ finally {
95
+ budget.dispose();
96
+ }
97
+ }
98
+ async listViews(options) {
99
+ const outcome = await this.envelopeOperation("list_views", {}, COLLECTION_READ_PROBLEM_CODES, options);
100
+ return mapOutcome(outcome, (value) => ({ views: value.views, meta: { totalCount: value.meta.total_count } }));
101
+ }
102
+ async executeView(input, options) {
103
+ const outcome = await this.envelopeOperation("execute_view", input, COLLECTION_READ_PROBLEM_CODES, options);
104
+ return mapOutcome(outcome, wireSavedViewExecution);
105
+ }
106
+ async *executeViewPages(input, options = {}) {
107
+ yield* coordinatedSavedViewPages((pageInput, pageOptions) => this.executeView(pageInput, pageOptions), (cursor) => this.releaseQueryCursor(cursor), input, options);
108
+ }
109
+ readViewSource(input, options) {
110
+ return this.envelopeOperation("read_view_source", input, COLLECTION_READ_PROBLEM_CODES, options);
111
+ }
112
+ createViewSource(input, options) {
113
+ return this.envelopeOperation("create_view_source", input, COLLECTION_MUTATION_PROBLEM_CODES, options);
114
+ }
115
+ updateViewSource(input, options) {
116
+ return this.envelopeOperation("update_view_source", wireRevisionInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
117
+ }
118
+ deleteViewSource(input, options) {
119
+ return this.envelopeOperation("delete_view_source", wireRevisionInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
120
+ }
121
+ async create(input, options) {
122
+ const outcome = await this.envelopeOperation("create", wireCreateInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
123
+ return mapOutcome(outcome, wireRecordDocument);
124
+ }
125
+ async update(input, options) {
126
+ const outcome = await this.envelopeOperation("update", wireUpdateInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
127
+ return mapOutcome(outcome, wireRecordDocument);
128
+ }
129
+ async delete(input, options) {
130
+ const outcome = await this.envelopeOperation("delete", wireDeleteInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
131
+ return mapOutcome(outcome, wireDeleteResult);
132
+ }
133
+ async preflightDelete(input, options) {
134
+ const outcome = await this.envelopeOperation("delete", {
135
+ ...wireDeleteInput(input),
136
+ check_backlinks: true,
137
+ dry_run: true
138
+ }, COLLECTION_MUTATION_PROBLEM_CODES, options);
139
+ return mapOutcome(outcome, wireDeletePreflightResult);
140
+ }
141
+ async rename(input, options) {
142
+ const outcome = await this.envelopeOperation("rename", wireRenameInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
143
+ return mapOutcome(outcome, wireRenameResult);
144
+ }
145
+ async preflightRename(input, options) {
146
+ const outcome = await this.envelopeOperation("rename", {
147
+ ...wireRenameInput(input),
148
+ dry_run: true
149
+ }, COLLECTION_MUTATION_PROBLEM_CODES, options);
150
+ return mapOutcome(outcome, wireRenamePreflightResult);
151
+ }
152
+ validate(input = {}, options) {
153
+ return this.envelopeOperation("validate", input, COLLECTION_READ_PROBLEM_CODES, options);
154
+ }
155
+ readType(input, options) {
156
+ return this.envelopeOperation("read_type", input, COLLECTION_TYPE_PROBLEM_CODES, options);
157
+ }
158
+ createType(input, options) {
159
+ return this.envelopeOperation("create_type", input, COLLECTION_TYPE_PROBLEM_CODES, options);
160
+ }
161
+ updateType(input, options) {
162
+ return this.envelopeOperation("update_type", wireRevisionInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
163
+ }
164
+ async assessTypePack(input, options) {
165
+ const outcome = await this.envelopeOperation("assess_type_pack", wireAssessTypePackInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
166
+ return mapOutcome(outcome, wireTypePackAssessment);
167
+ }
168
+ async applyTypePack(input, options) {
169
+ const outcome = await this.envelopeOperation("apply_type_pack", wireApplyTypePackInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
170
+ return mapOutcome(outcome, wireTypePackApplyResult);
171
+ }
172
+ async assessCollectionSetup(input, options) {
173
+ const outcome = await this.envelopeOperation("assess_collection_setup", wireAssessCollectionSetupInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
174
+ return mapOutcome(outcome, wireCollectionSetupAssessment);
175
+ }
176
+ async applyCollectionSetup(input, options) {
177
+ const outcome = await this.envelopeOperation("apply_collection_setup", wireApplyCollectionSetupInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
178
+ return mapOutcome(outcome, (value) => ({
179
+ assessment: wireCollectionSetupAssessment(value.assessment),
180
+ receipt: wireCollectionSetupReceipt(value.receipt)
181
+ }));
182
+ }
183
+ async listTimers(namespace, options) {
184
+ const outcome = await this.rawOperation("list_timers", { namespace }, COLLECTION_READ_PROBLEM_CODES, options);
185
+ return mapOutcome(outcome, (value) => ({
186
+ namespace: value.namespace,
187
+ timers: value.timers.map(wireTimer)
188
+ }));
189
+ }
190
+ async putTimer(input, options) {
191
+ const outcome = await this.rawOperation("put_timer", {
192
+ namespace: input.namespace,
193
+ criterion_id: input.criterionId,
194
+ timer: wireDesiredTimer(input.timer)
195
+ }, COLLECTION_MUTATION_PROBLEM_CODES, options);
196
+ return mapOutcome(outcome, wireTimer);
197
+ }
198
+ cancelTimer(input, options) {
199
+ return this.rawOperation("cancel_timer", input, COLLECTION_MUTATION_PROBLEM_CODES, options);
200
+ }
201
+ async reconcileTimers(input, options) {
202
+ const outcome = await this.rawOperation("reconcile_timers", {
203
+ namespace: input.namespace,
204
+ criterion_id: input.criterionId,
205
+ timers: input.timers.map(wireDesiredTimer)
206
+ }, COLLECTION_MUTATION_PROBLEM_CODES, options);
207
+ return mapOutcome(outcome, (value) => ({
208
+ namespace: value.namespace,
209
+ timers: value.timers.map(wireTimer),
210
+ cancelledIds: value.cancelled_ids
211
+ }));
212
+ }
213
+ async *watch(options = {}) {
214
+ let cursor = options.cursor;
215
+ const pollInterval = Math.max(100, options.pollIntervalMs ?? 1_000);
216
+ const retry = watchRetryPolicy(options.retry);
217
+ let failures = 0;
218
+ let connected = false;
219
+ options.onStatus?.({ state: "connecting", ...(cursor === undefined ? {} : { cursor }) });
220
+ while (!options.signal?.aborted) {
221
+ const changed = await this.changes(cursor === undefined ? {} : { after: cursor, limit: 200 }, { signal: options.signal, timeoutMs: options.timeoutMs });
222
+ if (!changed.ok) {
223
+ const problem = changed.problem;
224
+ if (options.signal?.aborted)
225
+ return;
226
+ if (!retry || problem.recovery !== "retry") {
227
+ yield changed;
228
+ return;
229
+ }
230
+ connected = false;
231
+ failures += 1;
232
+ if (retry.maxAttempts !== undefined && failures > retry.maxAttempts) {
233
+ yield changed;
234
+ return;
235
+ }
236
+ const retryInMs = Math.min(retry.maxDelayMs, Math.round(retry.initialDelayMs * retry.multiplier ** (failures - 1)));
237
+ options.onStatus?.({
238
+ state: "reconnecting",
239
+ ...(cursor === undefined ? {} : { cursor }),
240
+ attempt: failures,
241
+ retryInMs,
242
+ problem
243
+ });
244
+ try {
245
+ await abortableDelay(retryInMs, options.signal);
246
+ }
247
+ catch {
248
+ if (!options.signal?.aborted)
249
+ throw connectError("operation_failed", "Watch retry delay failed unexpectedly.");
250
+ }
251
+ continue;
252
+ }
253
+ const page = changed.value;
254
+ if (cursor === undefined) {
255
+ cursor = page.cursor;
256
+ continue;
257
+ }
258
+ if (page.reset) {
259
+ const problem = connectProblem("change_cursor_reset", "The collection change cursor expired. Refresh collection state before subscribing again.");
260
+ options.onStatus?.({ state: "reset_required", cursor, problem });
261
+ yield connectFailure(problem);
262
+ return;
263
+ }
264
+ const recovered = failures > 0;
265
+ failures = 0;
266
+ if (!connected || recovered)
267
+ options.onStatus?.({ state: "connected", cursor, recovered });
268
+ connected = true;
269
+ for (const event of page.events)
270
+ yield connectSuccess(event);
271
+ cursor = page.cursor;
272
+ if (!page.hasMore) {
273
+ try {
274
+ await abortableDelay(pollInterval, options.signal);
275
+ }
276
+ catch {
277
+ if (!options.signal?.aborted)
278
+ throw connectError("operation_failed", "Watch polling delay failed unexpectedly.");
279
+ }
280
+ }
281
+ }
282
+ }
283
+ rawOperation(operation, input, allowedCodes, options) {
284
+ return captureConnectOutcome(() => this.transport.operation(operation, input, options), allowedCodes);
285
+ }
286
+ async releaseQueryCursor(cursor) {
287
+ try {
288
+ await this.envelopeOperation("query", { release_cursor: cursor }, COLLECTION_QUERY_PROBLEM_CODES, { timeoutMs: 2_000, coordination: { coalesce: false } });
289
+ }
290
+ catch {
291
+ // Lease expiry is bounded by the authority; cleanup never masks query results.
292
+ }
293
+ }
294
+ async envelopeOperation(operation, input, allowedCodes, options) {
295
+ const transported = await captureConnectOutcome(() => this.transport.operation(operation, input, options), allowedCodes);
296
+ if (!transported.ok)
297
+ return transported;
298
+ const envelope = transported.value;
299
+ if (!envelope.valid) {
300
+ return connectFailure(operationProblem(envelope));
301
+ }
302
+ return connectSuccess(envelope.result, envelope.diagnostics);
303
+ }
304
+ }
305
+ function mapOutcome(outcome, map) {
306
+ return outcome.ok ? connectSuccess(map(outcome.value), outcome.diagnostics) : outcome;
307
+ }
308
+ function wireReadInput(input) {
309
+ return {
310
+ path: input.path,
311
+ ...(input.contract ? { contract: input.contract } : {}),
312
+ ...(input.includeDocument === undefined ? {} : { include_document: input.includeDocument })
313
+ };
314
+ }
315
+ function wireQueryInput(input) {
316
+ return {
317
+ ...(input.types ? { types: input.types } : {}),
318
+ ...(input.timezone ? { timezone: input.timezone } : {}),
319
+ ...(input.context ? { context: input.context } : {}),
320
+ ...(input.projections ? {
321
+ projections: Object.fromEntries(Object.entries(input.projections).map(([name, projection]) => [
322
+ name,
323
+ { expr: projection.expression, ...(projection.description ? { description: projection.description } : {}) }
324
+ ]))
325
+ } : {}),
326
+ ...(input.where ? { where: input.where } : {}),
327
+ ...(input.select ? {
328
+ select: input.select.map((selection) => typeof selection === "string"
329
+ ? selection
330
+ : {
331
+ name: selection.name,
332
+ expr: selection.expression,
333
+ ...(selection.label ? { label: selection.label } : {}),
334
+ ...(selection.description ? { description: selection.description } : {})
335
+ })
336
+ } : {}),
337
+ ...(input.orderBy ? { order_by: input.orderBy } : {}),
338
+ ...(input.groupBy ? { group_by: input.groupBy } : {}),
339
+ ...(input.summaryFunctions ? {
340
+ summary_functions: Object.fromEntries(Object.entries(input.summaryFunctions).map(([name, projection]) => [
341
+ name,
342
+ { expr: projection.expression, ...(projection.description ? { description: projection.description } : {}) }
343
+ ]))
344
+ } : {}),
345
+ ...(input.summaries ? { summaries: input.summaries } : {}),
346
+ ...(input.limit === undefined ? {} : { limit: input.limit }),
347
+ ...(input.offset === undefined ? {} : { offset: input.offset }),
348
+ ...(input.pagination ? { pagination: input.pagination } : {}),
349
+ ...(input.cursor ? { cursor: input.cursor } : {}),
350
+ ...(input.snapshot ? { snapshot: input.snapshot } : {}),
351
+ ...(input.includeBody === undefined ? {} : { include_body: input.includeBody }),
352
+ ...(input.frontmatterMode ? { frontmatter_mode: input.frontmatterMode } : {}),
353
+ ...(input.contract ? { contract: input.contract } : {})
354
+ };
355
+ }
356
+ function wireCreateInput(input) {
357
+ return {
358
+ ...(input.path ? { path: input.path } : {}),
359
+ ...(input.type ? { type: input.type } : {}),
360
+ ...(input.contract ? { contract: input.contract } : {}),
361
+ ...(input.frontmatter ? { frontmatter: input.frontmatter } : {}),
362
+ ...(input.body === undefined ? {} : { body: input.body }),
363
+ ...(input.ifRevision ? { if_revision: input.ifRevision } : {}),
364
+ ...(input.includeDocument === undefined ? {} : { include_document: input.includeDocument })
365
+ };
366
+ }
367
+ function wireUpdateInput(input) {
368
+ return {
369
+ path: input.path,
370
+ ...(input.contract ? { contract: input.contract } : {}),
371
+ ...(input.ifRevision ? { if_revision: input.ifRevision } : {}),
372
+ ...(input.includeDocument === undefined ? {} : { include_document: input.includeDocument }),
373
+ ...(input.document === undefined
374
+ ? { patch: input.patch, ...(input.body === undefined ? {} : { body: input.body }) }
375
+ : { document: input.document })
376
+ };
377
+ }
378
+ function wireDeleteInput(input) {
379
+ return {
380
+ path: input.path,
381
+ ...(input.contract ? { contract: input.contract } : {}),
382
+ ...(input.checkBacklinks === undefined ? {} : { check_backlinks: input.checkBacklinks }),
383
+ ...(input.ifRevision ? { if_revision: input.ifRevision } : {})
384
+ };
385
+ }
386
+ function wireRenameInput(input) {
387
+ return {
388
+ from: input.from,
389
+ to: input.to,
390
+ ...(input.contract ? { contract: input.contract } : {}),
391
+ ...(input.updateRefs === undefined ? {} : { update_refs: input.updateRefs }),
392
+ ...(input.ifRevision ? { if_revision: input.ifRevision } : {}),
393
+ ...(input.includeDocument === undefined ? {} : { include_document: input.includeDocument })
394
+ };
395
+ }
396
+ function wireRevisionInput(input) {
397
+ const { ifRevision, ...rest } = input;
398
+ return { ...rest, ...(ifRevision ? { if_revision: ifRevision } : {}) };
399
+ }
400
+ function wireAssessTypePackInput(input) {
401
+ return {
402
+ provision: input.provision,
403
+ installed_by: input.installedBy,
404
+ ...(input.adoptResources ? { adopt_resources: input.adoptResources } : {}),
405
+ ...(input.preserveSeedTargets ? { preserve_seed_targets: input.preserveSeedTargets } : {}),
406
+ ...(input.targetOverrides ? { target_overrides: input.targetOverrides } : {}),
407
+ ...(input.contractSetups ? { contract_setups: input.contractSetups.map(wireContractSetupChoice) } : {})
408
+ };
409
+ }
410
+ function wireApplyTypePackInput(input) {
411
+ return {
412
+ ...wireAssessTypePackInput(input),
413
+ expected_assessment_digest: input.expectedAssessmentDigest,
414
+ ...(input.allowDowngrade === undefined ? {} : { allow_downgrade: input.allowDowngrade })
415
+ };
416
+ }
417
+ function wireAssessCollectionSetupInput(input) {
418
+ return {
419
+ application_id: input.applicationId,
420
+ declaration_digest: input.declarationDigest,
421
+ requirements: input.requirements,
422
+ provisions: {
423
+ configuration: input.provisions.configuration,
424
+ type_packs: input.provisions.typePacks
425
+ },
426
+ ...(input.contractSetups ? { contract_setups: input.contractSetups.map(wireContractSetupChoice) } : {}),
427
+ ...(input.typePackAdoptions ? { type_pack_adoptions: input.typePackAdoptions } : {})
428
+ };
429
+ }
430
+ function wireApplyCollectionSetupInput(input) {
431
+ return {
432
+ ...wireAssessCollectionSetupInput(input),
433
+ expected_assessment_digest: input.expectedAssessmentDigest,
434
+ expected_collection_revision: input.expectedCollectionRevision,
435
+ expected_provision_digest: input.expectedProvisionDigest,
436
+ ...(input.allowTypePackDowngrades
437
+ ? { allow_type_pack_downgrades: input.allowTypePackDowngrades }
438
+ : {})
439
+ };
440
+ }
441
+ function wireDeleteResult(value) {
442
+ return {
443
+ path: value.path,
444
+ deleted: value.deleted,
445
+ ...(value.broken_links ? { brokenLinks: value.broken_links } : {})
446
+ };
447
+ }
448
+ function wireDeletePreflightResult(value) {
449
+ return {
450
+ ...wireDeleteResult(value),
451
+ deleted: false,
452
+ dryRun: true,
453
+ wouldDelete: true
454
+ };
455
+ }
456
+ function wireRenameResult(value) {
457
+ const { references_updated, ...record } = value;
458
+ return {
459
+ ...wireRecordDocument(record),
460
+ from: value.from,
461
+ to: value.to,
462
+ ...(references_updated ? { referencesUpdated: references_updated } : {})
463
+ };
464
+ }
465
+ function wireRenamePreflightResult(value) {
466
+ return {
467
+ from: value.from,
468
+ to: value.to,
469
+ dryRun: true,
470
+ wouldRename: true,
471
+ ...(value.references_affected ? { referencesAffected: value.references_affected } : {}),
472
+ ...(value.warnings ? { warnings: value.warnings } : {})
473
+ };
474
+ }
475
+ function wireDesiredTimer(timer) {
476
+ return { id: timer.id, fire_at: timer.fireAt, ...(timer.data === undefined ? {} : { data: timer.data }) };
477
+ }
478
+ function wireTimer(timer) {
479
+ return {
480
+ id: timer.id,
481
+ fireAt: timer.fire_at,
482
+ ...(timer.data === undefined ? {} : { data: timer.data }),
483
+ criterionId: timer.criterion_id,
484
+ generation: timer.generation,
485
+ status: timer.status,
486
+ createdAt: timer.created_at,
487
+ updatedAt: timer.updated_at,
488
+ firedAt: timer.fired_at
489
+ };
490
+ }
491
+ function wireContractSetupChoice(choice) {
492
+ return choice.mode === "starter"
493
+ ? choice
494
+ : {
495
+ contract: choice.contract,
496
+ mode: "existing",
497
+ type_name: choice.typeName,
498
+ type_revision: choice.typeRevision,
499
+ fields: choice.fields,
500
+ ...(choice.binding ? { binding: choice.binding } : {})
501
+ };
502
+ }
503
+ function wireDataContractIdentity(value) {
504
+ return {
505
+ id: value.id,
506
+ version: value.version,
507
+ digest: value.digest,
508
+ type: value.type,
509
+ implementationDigest: value.implementation_digest
510
+ };
511
+ }
512
+ function wireQueryRecord(value) {
513
+ const { effective_frontmatter, contract, ...record } = value;
514
+ return {
515
+ ...record,
516
+ ...(effective_frontmatter === undefined ? {} : { effectiveFrontmatter: effective_frontmatter }),
517
+ ...(contract ? { contract: wireDataContractIdentity(contract) } : {})
518
+ };
519
+ }
520
+ function wireRecordDocument(value) {
521
+ const { effective_frontmatter, contract, ...record } = value;
522
+ return {
523
+ ...record,
524
+ effectiveFrontmatter: effective_frontmatter,
525
+ ...(contract ? { contract: wireDataContractIdentity(contract) } : {})
526
+ };
527
+ }
528
+ function wireSavedViewExecution(value) {
529
+ return {
530
+ results: value.results.map((record) => {
531
+ const mapped = wireQueryRecord(record);
532
+ if (!mapped.effectiveFrontmatter) {
533
+ throw new Error("Saved view result omitted canonical effective frontmatter.");
534
+ }
535
+ return { ...mapped, effectiveFrontmatter: mapped.effectiveFrontmatter };
536
+ }),
537
+ meta: {
538
+ totalCount: value.meta.total_count,
539
+ hasMore: value.meta.has_more,
540
+ ...(value.meta.cursor ? { cursor: value.meta.cursor } : {}),
541
+ view: value.meta.view,
542
+ ...(value.meta.context ? { context: value.meta.context } : {}),
543
+ ...(value.meta.groups ? { groups: value.meta.groups } : {})
544
+ }
545
+ };
546
+ }
547
+ function wireTypePackResource(value) {
548
+ return {
549
+ source: value.source,
550
+ target: value.target,
551
+ kind: value.kind,
552
+ mode: value.mode,
553
+ action: value.action,
554
+ digest: value.digest,
555
+ ...(value.current_digest ? { currentDigest: value.current_digest } : {}),
556
+ ...(value.installed_digest ? { installedDigest: value.installed_digest } : {}),
557
+ ...(value.adopted_from_digest ? { adoptedFromDigest: value.adopted_from_digest } : {}),
558
+ ...(value.reason ? { reason: value.reason } : {})
559
+ };
560
+ }
561
+ function wireTypePackReceipt(value) {
562
+ return {
563
+ id: value.id,
564
+ version: value.version,
565
+ digest: value.digest,
566
+ installedBy: value.installed_by,
567
+ resources: value.resources.map((resource) => ({
568
+ source: resource.source,
569
+ target: resource.target,
570
+ kind: resource.kind,
571
+ mode: resource.mode,
572
+ digest: resource.digest,
573
+ ...(resource.adopted_from_digest ? { adoptedFromDigest: resource.adopted_from_digest } : {})
574
+ }))
575
+ };
576
+ }
577
+ function clientContractSetupChoice(choice) {
578
+ return choice.mode === "starter"
579
+ ? choice
580
+ : {
581
+ contract: choice.contract,
582
+ mode: "existing",
583
+ typeName: choice.type_name,
584
+ typeRevision: choice.type_revision,
585
+ fields: choice.fields,
586
+ ...(choice.binding ? { binding: choice.binding } : {})
587
+ };
588
+ }
589
+ function wireTypePackAssessment(value) {
590
+ return {
591
+ status: value.status,
592
+ applicable: value.applicable,
593
+ assessmentDigest: value.assessment_digest,
594
+ ...(value.current ? { current: wireTypePackReceipt(value.current) } : {}),
595
+ desired: wireTypePackReceipt(value.desired),
596
+ resources: value.resources.map(wireTypePackResource),
597
+ lock: value.lock,
598
+ contractSetups: {
599
+ choices: value.contract_setups.choices.map(clientContractSetupChoice),
600
+ resources: value.contract_setups.resources.map(wireTypePackResource)
601
+ }
602
+ };
603
+ }
604
+ function wireTypePackApplyResult(value) {
605
+ return {
606
+ ...wireTypePackAssessment(value),
607
+ receipt: wireTypePackReceipt(value.receipt),
608
+ cleanupDeferred: value.cleanup_deferred
609
+ };
610
+ }
611
+ function wireCollectionSetupAssessment(value) {
612
+ return {
613
+ status: value.status,
614
+ applicable: value.applicable,
615
+ applicationId: value.application_id,
616
+ declarationDigest: value.declaration_digest,
617
+ provisionDigest: value.provision_digest,
618
+ collectionRevision: value.collection_revision,
619
+ finalCollectionRevision: value.final_collection_revision,
620
+ baselineDiagnosticCount: value.baseline_diagnostic_count,
621
+ finalDiagnosticCount: value.final_diagnostic_count,
622
+ resolvedDiagnosticCount: value.resolved_diagnostic_count,
623
+ introducedDiagnosticCount: value.introduced_diagnostic_count,
624
+ baselineDiagnosticDigest: value.baseline_diagnostic_digest,
625
+ configuration: value.configuration,
626
+ typePacks: value.type_packs.map(wireTypePackAssessment),
627
+ finalResourceRevisions: value.final_resource_revisions,
628
+ assessmentDigest: value.assessment_digest
629
+ };
630
+ }
631
+ function wireCollectionSetupReceipt(value) {
632
+ return {
633
+ applicationId: value.application_id,
634
+ declarationDigest: value.declaration_digest,
635
+ provisionDigest: value.provision_digest,
636
+ assessmentDigest: value.assessment_digest,
637
+ collectionRevision: value.collection_revision,
638
+ configuration: value.configuration,
639
+ typePacks: value.type_packs.map(wireTypePackReceipt),
640
+ cleanupDeferred: value.cleanup_deferred
641
+ };
642
+ }
643
+ function wireChange(value) {
644
+ return {
645
+ cursor: value.cursor,
646
+ type: value.type,
647
+ occurredAt: value.occurred_at,
648
+ payload: value.payload
649
+ };
650
+ }
651
+ function wireChangesPage(value) {
652
+ return {
653
+ events: value.events.map(wireChange),
654
+ cursor: value.cursor,
655
+ hasMore: value.has_more,
656
+ reset: value.reset
657
+ };
658
+ }
659
+ function wireCollectionDescription(value) {
660
+ return {
661
+ protocolVersion: value.protocol_version,
662
+ collectionId: value.collection_id,
663
+ displayName: value.display_name,
664
+ specVersion: value.spec_version,
665
+ operations: value.operations,
666
+ changeCursor: value.change_cursor,
667
+ types: value.types,
668
+ contracts: value.contracts.map((contract) => ({
669
+ contractType: contract.contract_type,
670
+ id: contract.id,
671
+ version: contract.version,
672
+ digest: contract.digest,
673
+ schema: contract.schema,
674
+ ...(contract.binding_schema ? { bindingSchema: contract.binding_schema } : {}),
675
+ implementations: contract.implementations.map((implementation) => ({
676
+ typeName: implementation.type_name,
677
+ typeVersion: implementation.type_version,
678
+ ...(implementation.type_path ? { typePath: implementation.type_path } : {}),
679
+ digest: implementation.digest,
680
+ fields: implementation.fields,
681
+ ...(implementation.binding ? { binding: implementation.binding } : {})
682
+ }))
683
+ })),
684
+ ...(value.configuration ? { configuration: value.configuration } : {})
685
+ };
686
+ }
@@ -0,0 +1,4 @@
1
+ import { MdbaseConnectError } from "./errors.js";
2
+ export declare function assertFreshV2AuthorizationSupport(serverUrl: string, signal?: AbortSignal): Promise<void>;
3
+ export declare function declarationIdFromFamilyIdentity(familyIdentity: string): string;
4
+ export declare function authorizationAbort(signal: AbortSignal, message: string, cause?: unknown): MdbaseConnectError;