@mdbase-dev/connect 0.1.0-beta.32 → 0.1.0-beta.33
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.
- package/README.md +37 -15
- package/dist/advanced.d.ts +2 -0
- package/dist/advanced.js +2 -0
- package/dist/application-session.d.ts +31 -11
- package/dist/application-session.js +188 -73
- package/dist/browser/integrity.json +1 -1
- package/dist/browser/mdbase-connect.min.js +3 -3
- package/dist/browser/mdbase-connect.min.js.sha384 +1 -1
- package/dist/collection-client.d.ts +9 -6
- package/dist/collection-client.js +522 -77
- package/dist/connect-authorization-helpers.d.ts +3 -0
- package/dist/connect-authorization-helpers.js +13 -0
- package/dist/connect.js +4 -6
- package/dist/connection.d.ts +7 -6
- package/dist/connection.js +103 -89
- package/dist/crypto-entry.d.ts +6 -3
- package/dist/crypto-entry.js +3 -3
- package/dist/file-transfer-internals.d.ts +2 -1
- package/dist/file-transfer-internals.js +38 -0
- package/dist/files.d.ts +20 -2
- package/dist/files.js +43 -19
- package/dist/index.d.ts +24 -16
- package/dist/index.js +10 -14
- package/dist/internal-types.d.ts +1 -0
- package/dist/operation-helpers.js +5 -5
- package/dist/operation-types.d.ts +404 -39
- package/dist/session.d.ts +1 -1
- package/dist/session.js +2 -1
- package/dist/watch-policy.d.ts +8 -0
- package/dist/watch-policy.js +12 -0
- package/package.json +3 -3
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { abortableDelay } from "./async.js";
|
|
2
|
-
import { connectError, connectProblem, operationProblem } from "./errors.js";
|
|
2
|
+
import { MdbaseConnectError, connectError, connectProblem, operationProblem } from "./errors.js";
|
|
3
3
|
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";
|
|
4
|
+
import { createRequestBudget, DEFAULT_REQUEST_TIMEOUT_MS, requestAbortReason } from "./request-budget.js";
|
|
5
|
+
import { watchRetryPolicy } from "./watch-policy.js";
|
|
4
6
|
/**
|
|
5
7
|
* Typed collection operations independent of OAuth, HTTP, or storage.
|
|
6
8
|
*
|
|
@@ -9,23 +11,38 @@ import { COLLECTION_CHANGES_PROBLEM_CODES, COLLECTION_DESCRIPTION_PROBLEM_CODES,
|
|
|
9
11
|
*/
|
|
10
12
|
export class MdbaseCollectionClient {
|
|
11
13
|
transport;
|
|
12
|
-
|
|
14
|
+
requestTimeoutMs;
|
|
15
|
+
constructor(transport, requestTimeoutMs = DEFAULT_REQUEST_TIMEOUT_MS) {
|
|
13
16
|
this.transport = transport;
|
|
17
|
+
this.requestTimeoutMs = requestTimeoutMs;
|
|
14
18
|
}
|
|
15
19
|
operation(operation, input, options) {
|
|
16
20
|
return captureConnectOutcome(() => this.transport.operation(operation, input, options), ALL_CONNECT_PROBLEM_CODES);
|
|
17
21
|
}
|
|
18
|
-
describe(options) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
22
|
+
async describe(options) {
|
|
23
|
+
const outcome = await this.rawOperation("describe", {}, COLLECTION_DESCRIPTION_PROBLEM_CODES, options);
|
|
24
|
+
return mapOutcome(outcome, wireCollectionDescription);
|
|
25
|
+
}
|
|
26
|
+
async changes(input = {}, options) {
|
|
27
|
+
const outcome = await this.rawOperation("changes", input, COLLECTION_CHANGES_PROBLEM_CODES, options);
|
|
28
|
+
return mapOutcome(outcome, wireChangesPage);
|
|
29
|
+
}
|
|
30
|
+
async read(input, options) {
|
|
31
|
+
const outcome = await this.envelopeOperation("read", wireReadInput(input), COLLECTION_READ_PROBLEM_CODES, options);
|
|
32
|
+
return mapOutcome(outcome, wireRecordDocument);
|
|
33
|
+
}
|
|
34
|
+
async query(input = {}, options) {
|
|
35
|
+
const outcome = await this.envelopeOperation("query", wireQueryInput(input), COLLECTION_QUERY_PROBLEM_CODES, options);
|
|
36
|
+
return mapOutcome(outcome, ({ results, meta }) => ({
|
|
37
|
+
results: results.map(wireQueryRecord),
|
|
38
|
+
...(meta ? {
|
|
39
|
+
meta: {
|
|
40
|
+
totalCount: meta.total_count,
|
|
41
|
+
hasMore: meta.has_more,
|
|
42
|
+
...(meta.snapshot ? { snapshot: meta.snapshot } : {})
|
|
43
|
+
}
|
|
44
|
+
} : {})
|
|
45
|
+
}));
|
|
29
46
|
}
|
|
30
47
|
async *queryPages(input = {}, options = {}) {
|
|
31
48
|
const { offset: requestedOffset, limit: requestedLimit, snapshot: requestedSnapshot, ...criteria } = input;
|
|
@@ -41,7 +58,7 @@ export class MdbaseCollectionClient {
|
|
|
41
58
|
offset,
|
|
42
59
|
limit: pageNumber === 0 ? firstPageSize : pageSize,
|
|
43
60
|
...(snapshot ? { snapshot } : {})
|
|
44
|
-
}, { signal: options.signal, timeoutMs: options.
|
|
61
|
+
}, { signal: options.signal, timeoutMs: options.pageTimeoutMs });
|
|
45
62
|
if (!queried.ok) {
|
|
46
63
|
yield queried;
|
|
47
64
|
return;
|
|
@@ -55,7 +72,7 @@ export class MdbaseCollectionClient {
|
|
|
55
72
|
if (!snapshot && returnedSnapshot)
|
|
56
73
|
snapshot = returnedSnapshot;
|
|
57
74
|
loaded += result.results.length;
|
|
58
|
-
const complete = !result.meta?.
|
|
75
|
+
const complete = !result.meta?.hasMore || result.results.length === 0;
|
|
59
76
|
const page = {
|
|
60
77
|
results: result.results,
|
|
61
78
|
...(result.meta ? { meta: result.meta } : {}),
|
|
@@ -74,32 +91,54 @@ export class MdbaseCollectionClient {
|
|
|
74
91
|
}
|
|
75
92
|
}
|
|
76
93
|
async queryAll(input = {}, options = {}) {
|
|
94
|
+
const budget = createRequestBudget(options, this.requestTimeoutMs);
|
|
77
95
|
const results = [];
|
|
78
96
|
let finalPage;
|
|
79
97
|
const diagnostics = [];
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
98
|
+
try {
|
|
99
|
+
for await (const outcome of this.queryPages(input, {
|
|
100
|
+
firstPageSize: options.firstPageSize,
|
|
101
|
+
pageSize: options.pageSize,
|
|
102
|
+
signal: budget.signal,
|
|
103
|
+
pageTimeoutMs: null,
|
|
104
|
+
onProgress: options.onProgress
|
|
105
|
+
})) {
|
|
106
|
+
if (!outcome.ok)
|
|
107
|
+
return outcome;
|
|
108
|
+
const page = outcome.value;
|
|
109
|
+
results.push(...page.results);
|
|
110
|
+
finalPage = page;
|
|
111
|
+
diagnostics.push(...outcome.diagnostics);
|
|
112
|
+
}
|
|
113
|
+
if (budget.signal.aborted)
|
|
114
|
+
throw requestAbortReason(budget.signal);
|
|
115
|
+
return connectSuccess({
|
|
116
|
+
results,
|
|
117
|
+
meta: {
|
|
118
|
+
...(finalPage?.meta ?? {}),
|
|
119
|
+
totalCount: finalPage?.meta?.totalCount ?? results.length,
|
|
120
|
+
hasMore: finalPage ? !finalPage.complete : false,
|
|
121
|
+
...(finalPage?.snapshot ? { snapshot: finalPage.snapshot } : {})
|
|
122
|
+
}
|
|
123
|
+
}, diagnostics);
|
|
87
124
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
...(finalPage?.meta ?? {}),
|
|
92
|
-
total_count: finalPage?.meta?.total_count ?? results.length,
|
|
93
|
-
has_more: finalPage ? !finalPage.complete : false,
|
|
94
|
-
...(finalPage?.snapshot ? { snapshot: finalPage.snapshot } : {})
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (error instanceof MdbaseConnectError) {
|
|
127
|
+
return connectFailure(error.problem);
|
|
95
128
|
}
|
|
96
|
-
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
budget.dispose();
|
|
133
|
+
}
|
|
97
134
|
}
|
|
98
|
-
listViews(options) {
|
|
99
|
-
|
|
135
|
+
async listViews(options) {
|
|
136
|
+
const outcome = await this.envelopeOperation("list_views", {}, COLLECTION_READ_PROBLEM_CODES, options);
|
|
137
|
+
return mapOutcome(outcome, (value) => ({ views: value.views, meta: { totalCount: value.meta.total_count } }));
|
|
100
138
|
}
|
|
101
|
-
executeView(input, options) {
|
|
102
|
-
|
|
139
|
+
async executeView(input, options) {
|
|
140
|
+
const outcome = await this.envelopeOperation("execute_view", input, COLLECTION_READ_PROBLEM_CODES, options);
|
|
141
|
+
return mapOutcome(outcome, wireSavedViewExecution);
|
|
103
142
|
}
|
|
104
143
|
readViewSource(input, options) {
|
|
105
144
|
return this.envelopeOperation("read_view_source", input, COLLECTION_READ_PROBLEM_CODES, options);
|
|
@@ -108,28 +147,41 @@ export class MdbaseCollectionClient {
|
|
|
108
147
|
return this.envelopeOperation("create_view_source", input, COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
109
148
|
}
|
|
110
149
|
updateViewSource(input, options) {
|
|
111
|
-
return this.envelopeOperation("update_view_source", input, COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
150
|
+
return this.envelopeOperation("update_view_source", wireRevisionInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
112
151
|
}
|
|
113
152
|
deleteViewSource(input, options) {
|
|
114
|
-
return this.envelopeOperation("delete_view_source", input, COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
115
|
-
}
|
|
116
|
-
create(input, options) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
153
|
+
return this.envelopeOperation("delete_view_source", wireRevisionInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
154
|
+
}
|
|
155
|
+
async create(input, options) {
|
|
156
|
+
const outcome = await this.envelopeOperation("create", wireCreateInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
157
|
+
return mapOutcome(outcome, wireRecordDocument);
|
|
158
|
+
}
|
|
159
|
+
async update(input, options) {
|
|
160
|
+
const outcome = await this.envelopeOperation("update", wireUpdateInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
161
|
+
return mapOutcome(outcome, wireRecordDocument);
|
|
162
|
+
}
|
|
163
|
+
async delete(input, options) {
|
|
164
|
+
const outcome = await this.envelopeOperation("delete", wireDeleteInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
165
|
+
return mapOutcome(outcome, wireDeleteResult);
|
|
166
|
+
}
|
|
167
|
+
async preflightDelete(input, options) {
|
|
168
|
+
const outcome = await this.envelopeOperation("delete", {
|
|
169
|
+
...wireDeleteInput(input),
|
|
170
|
+
check_backlinks: true,
|
|
171
|
+
dry_run: true
|
|
172
|
+
}, COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
173
|
+
return mapOutcome(outcome, wireDeletePreflightResult);
|
|
174
|
+
}
|
|
175
|
+
async rename(input, options) {
|
|
176
|
+
const outcome = await this.envelopeOperation("rename", wireRenameInput(input), COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
177
|
+
return mapOutcome(outcome, wireRenameResult);
|
|
178
|
+
}
|
|
179
|
+
async preflightRename(input, options) {
|
|
180
|
+
const outcome = await this.envelopeOperation("rename", {
|
|
181
|
+
...wireRenameInput(input),
|
|
182
|
+
dry_run: true
|
|
183
|
+
}, COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
184
|
+
return mapOutcome(outcome, wireRenamePreflightResult);
|
|
133
185
|
}
|
|
134
186
|
validate(input = {}, options) {
|
|
135
187
|
return this.envelopeOperation("validate", input, COLLECTION_READ_PROBLEM_CODES, options);
|
|
@@ -141,25 +193,56 @@ export class MdbaseCollectionClient {
|
|
|
141
193
|
return this.envelopeOperation("create_type", input, COLLECTION_TYPE_PROBLEM_CODES, options);
|
|
142
194
|
}
|
|
143
195
|
updateType(input, options) {
|
|
144
|
-
return this.envelopeOperation("update_type", input, COLLECTION_TYPE_PROBLEM_CODES, options);
|
|
145
|
-
}
|
|
146
|
-
assessTypePack(input, options) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return
|
|
196
|
+
return this.envelopeOperation("update_type", wireRevisionInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
|
|
197
|
+
}
|
|
198
|
+
async assessTypePack(input, options) {
|
|
199
|
+
const outcome = await this.envelopeOperation("assess_type_pack", wireAssessTypePackInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
|
|
200
|
+
return mapOutcome(outcome, wireTypePackAssessment);
|
|
201
|
+
}
|
|
202
|
+
async applyTypePack(input, options) {
|
|
203
|
+
const outcome = await this.envelopeOperation("apply_type_pack", wireApplyTypePackInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
|
|
204
|
+
return mapOutcome(outcome, wireTypePackApplyResult);
|
|
205
|
+
}
|
|
206
|
+
async assessCollectionSetup(input, options) {
|
|
207
|
+
const outcome = await this.envelopeOperation("assess_collection_setup", wireAssessCollectionSetupInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
|
|
208
|
+
return mapOutcome(outcome, wireCollectionSetupAssessment);
|
|
209
|
+
}
|
|
210
|
+
async applyCollectionSetup(input, options) {
|
|
211
|
+
const outcome = await this.envelopeOperation("apply_collection_setup", wireApplyCollectionSetupInput(input), COLLECTION_TYPE_PROBLEM_CODES, options);
|
|
212
|
+
return mapOutcome(outcome, (value) => ({
|
|
213
|
+
assessment: wireCollectionSetupAssessment(value.assessment),
|
|
214
|
+
receipt: wireCollectionSetupReceipt(value.receipt)
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
async listTimers(namespace, options) {
|
|
218
|
+
const outcome = await this.rawOperation("list_timers", { namespace }, COLLECTION_READ_PROBLEM_CODES, options);
|
|
219
|
+
return mapOutcome(outcome, (value) => ({
|
|
220
|
+
namespace: value.namespace,
|
|
221
|
+
timers: value.timers.map(wireTimer)
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
async putTimer(input, options) {
|
|
225
|
+
const outcome = await this.rawOperation("put_timer", {
|
|
226
|
+
namespace: input.namespace,
|
|
227
|
+
criterion_id: input.criterionId,
|
|
228
|
+
timer: wireDesiredTimer(input.timer)
|
|
229
|
+
}, COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
230
|
+
return mapOutcome(outcome, wireTimer);
|
|
157
231
|
}
|
|
158
232
|
cancelTimer(input, options) {
|
|
159
233
|
return this.rawOperation("cancel_timer", input, COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
160
234
|
}
|
|
161
|
-
reconcileTimers(input, options) {
|
|
162
|
-
|
|
235
|
+
async reconcileTimers(input, options) {
|
|
236
|
+
const outcome = await this.rawOperation("reconcile_timers", {
|
|
237
|
+
namespace: input.namespace,
|
|
238
|
+
criterion_id: input.criterionId,
|
|
239
|
+
timers: input.timers.map(wireDesiredTimer)
|
|
240
|
+
}, COLLECTION_MUTATION_PROBLEM_CODES, options);
|
|
241
|
+
return mapOutcome(outcome, (value) => ({
|
|
242
|
+
namespace: value.namespace,
|
|
243
|
+
timers: value.timers.map(wireTimer),
|
|
244
|
+
cancelledIds: value.cancelled_ids
|
|
245
|
+
}));
|
|
163
246
|
}
|
|
164
247
|
async *watch(options = {}) {
|
|
165
248
|
let cursor = options.cursor;
|
|
@@ -220,7 +303,7 @@ export class MdbaseCollectionClient {
|
|
|
220
303
|
for (const event of page.events)
|
|
221
304
|
yield connectSuccess(event);
|
|
222
305
|
cursor = page.cursor;
|
|
223
|
-
if (!page.
|
|
306
|
+
if (!page.hasMore) {
|
|
224
307
|
try {
|
|
225
308
|
await abortableDelay(pollInterval, options.signal);
|
|
226
309
|
}
|
|
@@ -245,14 +328,376 @@ export class MdbaseCollectionClient {
|
|
|
245
328
|
return connectSuccess(envelope.result, envelope.diagnostics);
|
|
246
329
|
}
|
|
247
330
|
}
|
|
248
|
-
function
|
|
249
|
-
|
|
250
|
-
|
|
331
|
+
function mapOutcome(outcome, map) {
|
|
332
|
+
return outcome.ok ? connectSuccess(map(outcome.value), outcome.diagnostics) : outcome;
|
|
333
|
+
}
|
|
334
|
+
function wireReadInput(input) {
|
|
335
|
+
return {
|
|
336
|
+
path: input.path,
|
|
337
|
+
...(input.contract ? { contract: input.contract } : {}),
|
|
338
|
+
...(input.includeDocument === undefined ? {} : { include_document: input.includeDocument })
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function wireQueryInput(input) {
|
|
342
|
+
return {
|
|
343
|
+
...(input.types ? { types: input.types } : {}),
|
|
344
|
+
...(input.context ? { context: input.context } : {}),
|
|
345
|
+
...(input.projections ? {
|
|
346
|
+
projections: Object.fromEntries(Object.entries(input.projections).map(([name, projection]) => [
|
|
347
|
+
name,
|
|
348
|
+
{ expr: projection.expression, ...(projection.description ? { description: projection.description } : {}) }
|
|
349
|
+
]))
|
|
350
|
+
} : {}),
|
|
351
|
+
...(input.where ? { where: input.where } : {}),
|
|
352
|
+
...(input.select ? {
|
|
353
|
+
select: input.select.map((selection) => typeof selection === "string"
|
|
354
|
+
? selection
|
|
355
|
+
: {
|
|
356
|
+
name: selection.name,
|
|
357
|
+
expr: selection.expression,
|
|
358
|
+
...(selection.label ? { label: selection.label } : {}),
|
|
359
|
+
...(selection.description ? { description: selection.description } : {})
|
|
360
|
+
})
|
|
361
|
+
} : {}),
|
|
362
|
+
...(input.orderBy ? { order_by: input.orderBy } : {}),
|
|
363
|
+
...(input.groupBy ? { group_by: input.groupBy } : {}),
|
|
364
|
+
...(input.summaryFunctions ? {
|
|
365
|
+
summary_functions: Object.fromEntries(Object.entries(input.summaryFunctions).map(([name, projection]) => [
|
|
366
|
+
name,
|
|
367
|
+
{ expr: projection.expression, ...(projection.description ? { description: projection.description } : {}) }
|
|
368
|
+
]))
|
|
369
|
+
} : {}),
|
|
370
|
+
...(input.summaries ? { summaries: input.summaries } : {}),
|
|
371
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
372
|
+
...(input.offset === undefined ? {} : { offset: input.offset }),
|
|
373
|
+
...(input.snapshot ? { snapshot: input.snapshot } : {}),
|
|
374
|
+
...(input.includeBody === undefined ? {} : { include_body: input.includeBody }),
|
|
375
|
+
...(input.frontmatterMode ? { frontmatter_mode: input.frontmatterMode } : {}),
|
|
376
|
+
...(input.contract ? { contract: input.contract } : {})
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function wireCreateInput(input) {
|
|
380
|
+
return {
|
|
381
|
+
...(input.path ? { path: input.path } : {}),
|
|
382
|
+
...(input.type ? { type: input.type } : {}),
|
|
383
|
+
...(input.contract ? { contract: input.contract } : {}),
|
|
384
|
+
...(input.frontmatter ? { frontmatter: input.frontmatter } : {}),
|
|
385
|
+
...(input.body === undefined ? {} : { body: input.body }),
|
|
386
|
+
...(input.ifRevision ? { if_revision: input.ifRevision } : {}),
|
|
387
|
+
...(input.includeDocument === undefined ? {} : { include_document: input.includeDocument })
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function wireUpdateInput(input) {
|
|
391
|
+
return {
|
|
392
|
+
path: input.path,
|
|
393
|
+
...(input.contract ? { contract: input.contract } : {}),
|
|
394
|
+
...(input.ifRevision ? { if_revision: input.ifRevision } : {}),
|
|
395
|
+
...(input.includeDocument === undefined ? {} : { include_document: input.includeDocument }),
|
|
396
|
+
...(input.document === undefined
|
|
397
|
+
? { patch: input.patch, ...(input.body === undefined ? {} : { body: input.body }) }
|
|
398
|
+
: { document: input.document })
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function wireDeleteInput(input) {
|
|
402
|
+
return {
|
|
403
|
+
path: input.path,
|
|
404
|
+
...(input.contract ? { contract: input.contract } : {}),
|
|
405
|
+
...(input.checkBacklinks === undefined ? {} : { check_backlinks: input.checkBacklinks }),
|
|
406
|
+
...(input.ifRevision ? { if_revision: input.ifRevision } : {})
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function wireRenameInput(input) {
|
|
410
|
+
return {
|
|
411
|
+
from: input.from,
|
|
412
|
+
to: input.to,
|
|
413
|
+
...(input.contract ? { contract: input.contract } : {}),
|
|
414
|
+
...(input.updateRefs === undefined ? {} : { update_refs: input.updateRefs }),
|
|
415
|
+
...(input.ifRevision ? { if_revision: input.ifRevision } : {}),
|
|
416
|
+
...(input.includeDocument === undefined ? {} : { include_document: input.includeDocument })
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function wireRevisionInput(input) {
|
|
420
|
+
const { ifRevision, ...rest } = input;
|
|
421
|
+
return { ...rest, ...(ifRevision ? { if_revision: ifRevision } : {}) };
|
|
422
|
+
}
|
|
423
|
+
function wireAssessTypePackInput(input) {
|
|
424
|
+
return {
|
|
425
|
+
provision: input.provision,
|
|
426
|
+
installed_by: input.installedBy,
|
|
427
|
+
...(input.adoptResources ? { adopt_resources: input.adoptResources } : {}),
|
|
428
|
+
...(input.preserveSeedTargets ? { preserve_seed_targets: input.preserveSeedTargets } : {}),
|
|
429
|
+
...(input.targetOverrides ? { target_overrides: input.targetOverrides } : {}),
|
|
430
|
+
...(input.contractSetups ? { contract_setups: input.contractSetups.map(wireContractSetupChoice) } : {})
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function wireApplyTypePackInput(input) {
|
|
434
|
+
return {
|
|
435
|
+
...wireAssessTypePackInput(input),
|
|
436
|
+
expected_assessment_digest: input.expectedAssessmentDigest,
|
|
437
|
+
...(input.allowDowngrade === undefined ? {} : { allow_downgrade: input.allowDowngrade })
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function wireAssessCollectionSetupInput(input) {
|
|
441
|
+
return {
|
|
442
|
+
application_id: input.applicationId,
|
|
443
|
+
declaration_digest: input.declarationDigest,
|
|
444
|
+
requirements: input.requirements,
|
|
445
|
+
provisions: {
|
|
446
|
+
configuration: input.provisions.configuration,
|
|
447
|
+
type_packs: input.provisions.typePacks
|
|
448
|
+
},
|
|
449
|
+
...(input.contractSetups ? { contract_setups: input.contractSetups.map(wireContractSetupChoice) } : {})
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
function wireApplyCollectionSetupInput(input) {
|
|
453
|
+
return {
|
|
454
|
+
...wireAssessCollectionSetupInput(input),
|
|
455
|
+
expected_assessment_digest: input.expectedAssessmentDigest,
|
|
456
|
+
expected_collection_revision: input.expectedCollectionRevision,
|
|
457
|
+
expected_provision_digest: input.expectedProvisionDigest,
|
|
458
|
+
...(input.allowTypePackDowngrades
|
|
459
|
+
? { allow_type_pack_downgrades: input.allowTypePackDowngrades }
|
|
460
|
+
: {})
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function wireDeleteResult(value) {
|
|
464
|
+
return {
|
|
465
|
+
path: value.path,
|
|
466
|
+
deleted: value.deleted,
|
|
467
|
+
...(value.broken_links ? { brokenLinks: value.broken_links } : {})
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function wireDeletePreflightResult(value) {
|
|
471
|
+
return {
|
|
472
|
+
...wireDeleteResult(value),
|
|
473
|
+
deleted: false,
|
|
474
|
+
dryRun: true,
|
|
475
|
+
wouldDelete: true
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function wireRenameResult(value) {
|
|
479
|
+
const { references_updated, ...record } = value;
|
|
480
|
+
return {
|
|
481
|
+
...wireRecordDocument(record),
|
|
482
|
+
from: value.from,
|
|
483
|
+
to: value.to,
|
|
484
|
+
...(references_updated ? { referencesUpdated: references_updated } : {})
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function wireRenamePreflightResult(value) {
|
|
488
|
+
return {
|
|
489
|
+
from: value.from,
|
|
490
|
+
to: value.to,
|
|
491
|
+
dryRun: true,
|
|
492
|
+
wouldRename: true,
|
|
493
|
+
...(value.references_affected ? { referencesAffected: value.references_affected } : {}),
|
|
494
|
+
...(value.warnings ? { warnings: value.warnings } : {})
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function wireDesiredTimer(timer) {
|
|
498
|
+
return { id: timer.id, fire_at: timer.fireAt, ...(timer.data === undefined ? {} : { data: timer.data }) };
|
|
499
|
+
}
|
|
500
|
+
function wireTimer(timer) {
|
|
501
|
+
return {
|
|
502
|
+
id: timer.id,
|
|
503
|
+
fireAt: timer.fire_at,
|
|
504
|
+
...(timer.data === undefined ? {} : { data: timer.data }),
|
|
505
|
+
criterionId: timer.criterion_id,
|
|
506
|
+
generation: timer.generation,
|
|
507
|
+
status: timer.status,
|
|
508
|
+
createdAt: timer.created_at,
|
|
509
|
+
updatedAt: timer.updated_at,
|
|
510
|
+
firedAt: timer.fired_at
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
function wireContractSetupChoice(choice) {
|
|
514
|
+
return choice.mode === "starter"
|
|
515
|
+
? choice
|
|
516
|
+
: {
|
|
517
|
+
contract: choice.contract,
|
|
518
|
+
mode: "existing",
|
|
519
|
+
type_name: choice.typeName,
|
|
520
|
+
type_revision: choice.typeRevision,
|
|
521
|
+
fields: choice.fields,
|
|
522
|
+
...(choice.binding ? { binding: choice.binding } : {})
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
function wireDataContractIdentity(value) {
|
|
526
|
+
return {
|
|
527
|
+
id: value.id,
|
|
528
|
+
version: value.version,
|
|
529
|
+
digest: value.digest,
|
|
530
|
+
type: value.type,
|
|
531
|
+
implementationDigest: value.implementation_digest
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
function wireQueryRecord(value) {
|
|
535
|
+
const { effective_frontmatter, contract, ...record } = value;
|
|
536
|
+
return {
|
|
537
|
+
...record,
|
|
538
|
+
...(effective_frontmatter === undefined ? {} : { effectiveFrontmatter: effective_frontmatter }),
|
|
539
|
+
...(contract ? { contract: wireDataContractIdentity(contract) } : {})
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
function wireRecordDocument(value) {
|
|
543
|
+
const { effective_frontmatter, contract, ...record } = value;
|
|
544
|
+
return {
|
|
545
|
+
...record,
|
|
546
|
+
effectiveFrontmatter: effective_frontmatter,
|
|
547
|
+
...(contract ? { contract: wireDataContractIdentity(contract) } : {})
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
function wireSavedViewExecution(value) {
|
|
551
|
+
return {
|
|
552
|
+
results: value.results.map((record) => {
|
|
553
|
+
const mapped = wireQueryRecord(record);
|
|
554
|
+
if (!mapped.effectiveFrontmatter) {
|
|
555
|
+
throw new Error("Saved view result omitted canonical effective frontmatter.");
|
|
556
|
+
}
|
|
557
|
+
return { ...mapped, effectiveFrontmatter: mapped.effectiveFrontmatter };
|
|
558
|
+
}),
|
|
559
|
+
meta: {
|
|
560
|
+
totalCount: value.meta.total_count,
|
|
561
|
+
hasMore: value.meta.has_more,
|
|
562
|
+
view: value.meta.view,
|
|
563
|
+
...(value.meta.context ? { context: value.meta.context } : {}),
|
|
564
|
+
...(value.meta.groups ? { groups: value.meta.groups } : {})
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
function wireTypePackResource(value) {
|
|
569
|
+
return {
|
|
570
|
+
source: value.source,
|
|
571
|
+
target: value.target,
|
|
572
|
+
kind: value.kind,
|
|
573
|
+
mode: value.mode,
|
|
574
|
+
action: value.action,
|
|
575
|
+
digest: value.digest,
|
|
576
|
+
...(value.current_digest ? { currentDigest: value.current_digest } : {}),
|
|
577
|
+
...(value.installed_digest ? { installedDigest: value.installed_digest } : {}),
|
|
578
|
+
...(value.adopted_from_digest ? { adoptedFromDigest: value.adopted_from_digest } : {}),
|
|
579
|
+
...(value.reason ? { reason: value.reason } : {})
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
function wireTypePackReceipt(value) {
|
|
583
|
+
return {
|
|
584
|
+
id: value.id,
|
|
585
|
+
version: value.version,
|
|
586
|
+
digest: value.digest,
|
|
587
|
+
installedBy: value.installed_by,
|
|
588
|
+
resources: value.resources.map((resource) => ({
|
|
589
|
+
source: resource.source,
|
|
590
|
+
target: resource.target,
|
|
591
|
+
kind: resource.kind,
|
|
592
|
+
mode: resource.mode,
|
|
593
|
+
digest: resource.digest,
|
|
594
|
+
...(resource.adopted_from_digest ? { adoptedFromDigest: resource.adopted_from_digest } : {})
|
|
595
|
+
}))
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function clientContractSetupChoice(choice) {
|
|
599
|
+
return choice.mode === "starter"
|
|
600
|
+
? choice
|
|
601
|
+
: {
|
|
602
|
+
contract: choice.contract,
|
|
603
|
+
mode: "existing",
|
|
604
|
+
typeName: choice.type_name,
|
|
605
|
+
typeRevision: choice.type_revision,
|
|
606
|
+
fields: choice.fields,
|
|
607
|
+
...(choice.binding ? { binding: choice.binding } : {})
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function wireTypePackAssessment(value) {
|
|
611
|
+
return {
|
|
612
|
+
status: value.status,
|
|
613
|
+
applicable: value.applicable,
|
|
614
|
+
assessmentDigest: value.assessment_digest,
|
|
615
|
+
...(value.current ? { current: wireTypePackReceipt(value.current) } : {}),
|
|
616
|
+
desired: wireTypePackReceipt(value.desired),
|
|
617
|
+
resources: value.resources.map(wireTypePackResource),
|
|
618
|
+
lock: value.lock,
|
|
619
|
+
contractSetups: {
|
|
620
|
+
choices: value.contract_setups.choices.map(clientContractSetupChoice),
|
|
621
|
+
resources: value.contract_setups.resources.map(wireTypePackResource)
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
function wireTypePackApplyResult(value) {
|
|
626
|
+
return {
|
|
627
|
+
...wireTypePackAssessment(value),
|
|
628
|
+
receipt: wireTypePackReceipt(value.receipt),
|
|
629
|
+
cleanupDeferred: value.cleanup_deferred
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
function wireCollectionSetupAssessment(value) {
|
|
633
|
+
return {
|
|
634
|
+
status: value.status,
|
|
635
|
+
applicable: value.applicable,
|
|
636
|
+
applicationId: value.application_id,
|
|
637
|
+
declarationDigest: value.declaration_digest,
|
|
638
|
+
provisionDigest: value.provision_digest,
|
|
639
|
+
collectionRevision: value.collection_revision,
|
|
640
|
+
finalCollectionRevision: value.final_collection_revision,
|
|
641
|
+
configuration: value.configuration,
|
|
642
|
+
typePacks: value.type_packs.map(wireTypePackAssessment),
|
|
643
|
+
finalResourceRevisions: value.final_resource_revisions,
|
|
644
|
+
assessmentDigest: value.assessment_digest
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
function wireCollectionSetupReceipt(value) {
|
|
648
|
+
return {
|
|
649
|
+
applicationId: value.application_id,
|
|
650
|
+
declarationDigest: value.declaration_digest,
|
|
651
|
+
provisionDigest: value.provision_digest,
|
|
652
|
+
assessmentDigest: value.assessment_digest,
|
|
653
|
+
collectionRevision: value.collection_revision,
|
|
654
|
+
configuration: value.configuration,
|
|
655
|
+
typePacks: value.type_packs.map(wireTypePackReceipt),
|
|
656
|
+
cleanupDeferred: value.cleanup_deferred
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
function wireChange(value) {
|
|
660
|
+
return {
|
|
661
|
+
cursor: value.cursor,
|
|
662
|
+
type: value.type,
|
|
663
|
+
occurredAt: value.occurred_at,
|
|
664
|
+
payload: value.payload
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
function wireChangesPage(value) {
|
|
668
|
+
return {
|
|
669
|
+
events: value.events.map(wireChange),
|
|
670
|
+
cursor: value.cursor,
|
|
671
|
+
hasMore: value.has_more,
|
|
672
|
+
reset: value.reset
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
function wireCollectionDescription(value) {
|
|
251
676
|
return {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
677
|
+
protocolVersion: value.protocol_version,
|
|
678
|
+
collectionId: value.collection_id,
|
|
679
|
+
displayName: value.display_name,
|
|
680
|
+
specVersion: value.spec_version,
|
|
681
|
+
operations: value.operations,
|
|
682
|
+
changeCursor: value.change_cursor,
|
|
683
|
+
types: value.types,
|
|
684
|
+
contracts: value.contracts.map((contract) => ({
|
|
685
|
+
contractType: contract.contract_type,
|
|
686
|
+
id: contract.id,
|
|
687
|
+
version: contract.version,
|
|
688
|
+
digest: contract.digest,
|
|
689
|
+
schema: contract.schema,
|
|
690
|
+
...(contract.binding_schema ? { bindingSchema: contract.binding_schema } : {}),
|
|
691
|
+
implementations: contract.implementations.map((implementation) => ({
|
|
692
|
+
typeName: implementation.type_name,
|
|
693
|
+
typeVersion: implementation.type_version,
|
|
694
|
+
...(implementation.type_path ? { typePath: implementation.type_path } : {}),
|
|
695
|
+
digest: implementation.digest,
|
|
696
|
+
fields: implementation.fields,
|
|
697
|
+
...(implementation.binding ? { binding: implementation.binding } : {})
|
|
698
|
+
}))
|
|
699
|
+
})),
|
|
700
|
+
...(value.configuration ? { configuration: value.configuration } : {})
|
|
256
701
|
};
|
|
257
702
|
}
|
|
258
703
|
function nonNegativeInteger(value, fallback) {
|