@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c0074032f9909
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 +32 -0
- package/dist/actions.d.ts +8 -16
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +43 -436
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +352 -231
- package/dist/authored-path.d.ts +9 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +34 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +0 -1
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +49 -42
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +317 -232
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/map.d.ts +2 -3
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +6 -7
- package/dist/model.d.ts +8 -19
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +43 -57
- package/dist/read.d.ts +65 -54
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +217 -295
- package/dist/refusal.d.ts +7 -11
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +53 -69
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/bounds.d.ts +7 -0
- package/dist/session-content/check.d.ts +18 -0
- package/dist/session-content/index.d.ts +7 -0
- package/dist/session-content/parts.d.ts +103 -0
- package/dist/session-content/state.d.ts +61 -0
- package/dist/session-content/turn.d.ts +328 -0
- package/dist/site.d.ts +1 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +142 -172
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +20 -9
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +394 -236
- package/dist/transport.d.ts +172 -47
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +58 -12
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +13 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +65 -0
- package/dist/version.d.ts +3 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +32 -18
- package/dist/write.d.ts +24 -11
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +263 -241
- package/package.json +10 -14
- package/AGENTS.md +0 -79
- package/dist/actions.js.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/digest.js.map +0 -1
- package/dist/discovery.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/map.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/read.js.map +0 -1
- package/dist/refusal.js.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/stream.js.map +0 -1
- package/dist/transport.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/write.js.map +0 -1
package/dist/write.js
CHANGED
|
@@ -1,389 +1,411 @@
|
|
|
1
|
+
import { departure, partsChanges, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
|
|
1
3
|
import { sha256Hex, textBytes } from './digest.js';
|
|
2
4
|
import { nativePath, roomLocalPath } from './map.js';
|
|
3
|
-
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
5
|
+
import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
|
|
4
6
|
import { readPosition, roomVersion } from './version.js';
|
|
5
|
-
|
|
6
|
-
export const UPLOAD_LINE_BYTES = 37;
|
|
7
|
-
export const UPLOAD_BYTES_MAX = 32 * 1024 * 1024 - UPLOAD_LINE_BYTES;
|
|
7
|
+
import { unusable } from './uncertain.js';
|
|
8
8
|
function priorField(batch, path, name) {
|
|
9
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'field' && precondition.path === path && precondition.name === name);
|
|
9
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'field' && precondition.path === path && precondition.name === name);
|
|
10
10
|
}
|
|
11
11
|
function priorSection(batch, path, name) {
|
|
12
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'section' && precondition.path === path && precondition.name === name);
|
|
12
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'section' && precondition.path === path && precondition.name === name);
|
|
13
13
|
}
|
|
14
14
|
function priorPreamble(batch, path) {
|
|
15
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'preamble' && precondition.path === path);
|
|
15
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'preamble' && precondition.path === path);
|
|
16
16
|
}
|
|
17
17
|
function priorAbsence(batch, path) {
|
|
18
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'absent' && precondition.path === path);
|
|
18
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'absent' && precondition.path === path);
|
|
19
19
|
}
|
|
20
20
|
function priorExistence(batch, path) {
|
|
21
|
-
const precondition = batch.preconditions.find((held)=>held.path === path && (held.kind === 'revision' || held.kind === 'present'));
|
|
22
|
-
if (precondition === undefined)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} : {
|
|
26
|
-
kind: 'presence'
|
|
27
|
-
};
|
|
21
|
+
const precondition = batch.preconditions.find((held) => held.path === path && (held.kind === 'revision' || held.kind === 'present'));
|
|
22
|
+
if (precondition === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };
|
|
28
25
|
}
|
|
29
|
-
function
|
|
26
|
+
function created(change, path) {
|
|
27
|
+
if ('content' in change)
|
|
28
|
+
return { op: 'create', path, content: change.content };
|
|
30
29
|
const { type, ...fields } = change.fields;
|
|
31
|
-
if (typeof type !== 'string' || type.length === 0)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
path,
|
|
35
|
-
type,
|
|
36
|
-
fields,
|
|
37
|
-
sections: change.sections
|
|
38
|
-
};
|
|
30
|
+
if (typeof type !== 'string' || type.length === 0)
|
|
31
|
+
return null;
|
|
32
|
+
return { op: 'create_typed', path, type, fields };
|
|
39
33
|
}
|
|
40
34
|
function operationOf(batch, change, handle) {
|
|
41
35
|
const path = nativePath(change.path, handle);
|
|
42
36
|
if (change.kind === 'field') {
|
|
43
37
|
const prior = priorField(batch, change.path, change.name);
|
|
44
|
-
if (prior === undefined)
|
|
45
|
-
rule: 'precondition-missing'
|
|
46
|
-
};
|
|
38
|
+
if (prior === undefined)
|
|
39
|
+
return { rule: 'precondition-missing' };
|
|
47
40
|
return {
|
|
48
41
|
operation: {
|
|
49
42
|
op: 'set_field',
|
|
50
43
|
path,
|
|
51
44
|
field: change.name,
|
|
52
45
|
value: change.value,
|
|
53
|
-
...prior.value === undefined ? {} : {
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
46
|
+
...(prior.value === undefined ? {} : { base: prior.value }),
|
|
47
|
+
},
|
|
57
48
|
};
|
|
58
49
|
}
|
|
59
50
|
if (change.kind === 'section') {
|
|
60
51
|
const prior = priorSection(batch, change.path, change.name);
|
|
61
|
-
if (prior === undefined)
|
|
62
|
-
rule: 'precondition-missing'
|
|
63
|
-
};
|
|
52
|
+
if (prior === undefined)
|
|
53
|
+
return { rule: 'precondition-missing' };
|
|
64
54
|
return {
|
|
65
55
|
operation: {
|
|
66
56
|
op: 'replace_section',
|
|
67
57
|
path,
|
|
68
58
|
section: change.name,
|
|
69
59
|
base: prior.value,
|
|
70
|
-
content: change.value
|
|
71
|
-
}
|
|
60
|
+
content: change.value,
|
|
61
|
+
},
|
|
72
62
|
};
|
|
73
63
|
}
|
|
74
64
|
if (change.kind === 'preamble') {
|
|
75
65
|
const prior = priorPreamble(batch, change.path);
|
|
76
|
-
if (prior === undefined)
|
|
77
|
-
rule: 'precondition-missing'
|
|
78
|
-
};
|
|
66
|
+
if (prior === undefined)
|
|
67
|
+
return { rule: 'precondition-missing' };
|
|
79
68
|
return {
|
|
80
|
-
operation: {
|
|
81
|
-
op: 'replace_preamble',
|
|
82
|
-
path,
|
|
83
|
-
base: prior.value,
|
|
84
|
-
content: change.value
|
|
85
|
-
}
|
|
69
|
+
operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },
|
|
86
70
|
};
|
|
87
71
|
}
|
|
88
72
|
if (change.kind === 'create') {
|
|
89
|
-
if (priorAbsence(batch, change.path) === undefined)
|
|
90
|
-
rule: 'precondition-missing'
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
73
|
+
if (priorAbsence(batch, change.path) === undefined)
|
|
74
|
+
return { rule: 'precondition-missing' };
|
|
75
|
+
const operation = created(change, path);
|
|
76
|
+
return operation === null ? { rule: 'type-missing' } : { operation };
|
|
77
|
+
}
|
|
78
|
+
if (change.kind === 'binary') {
|
|
79
|
+
const written = {
|
|
80
|
+
op: 'upload',
|
|
81
|
+
path,
|
|
82
|
+
local_id: change.localId,
|
|
83
|
+
bytes: change.byteLength,
|
|
84
|
+
sha256: change.sha256,
|
|
85
|
+
media_type: change.mediaType,
|
|
97
86
|
};
|
|
87
|
+
const from = departure(batch.changes, batch.changes.indexOf(change));
|
|
88
|
+
if (from === change.path && priorAbsence(batch, change.path) !== undefined)
|
|
89
|
+
return { operation: written };
|
|
90
|
+
const replaced = priorExistence(batch, from);
|
|
91
|
+
if (replaced === undefined)
|
|
92
|
+
return { rule: 'precondition-missing' };
|
|
93
|
+
if (!('base' in replaced))
|
|
94
|
+
return { rule: 'presence-base-unrepresentable' };
|
|
95
|
+
return { operation: { ...written, base: replaced.base } };
|
|
98
96
|
}
|
|
99
97
|
const existence = priorExistence(batch, change.path);
|
|
100
|
-
if (existence === undefined)
|
|
101
|
-
rule: 'precondition-missing'
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
rule: 'presence-base-unrepresentable'
|
|
105
|
-
};
|
|
98
|
+
if (existence === undefined)
|
|
99
|
+
return { rule: 'precondition-missing' };
|
|
100
|
+
if (!('base' in existence))
|
|
101
|
+
return { rule: 'presence-base-unrepresentable' };
|
|
106
102
|
if (change.kind === 'replace') {
|
|
107
|
-
return {
|
|
108
|
-
operation: {
|
|
109
|
-
op: 'replace',
|
|
110
|
-
path,
|
|
111
|
-
base: existence.base,
|
|
112
|
-
content: change.content
|
|
113
|
-
}
|
|
114
|
-
};
|
|
103
|
+
return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
|
|
115
104
|
}
|
|
116
105
|
if (change.kind === 'move') {
|
|
117
|
-
if (priorAbsence(batch, change.to) === undefined)
|
|
118
|
-
rule: 'precondition-missing'
|
|
119
|
-
};
|
|
106
|
+
if (priorAbsence(batch, change.to) === undefined)
|
|
107
|
+
return { rule: 'precondition-missing' };
|
|
120
108
|
return {
|
|
121
|
-
operation: {
|
|
122
|
-
op: 'rename',
|
|
123
|
-
path,
|
|
124
|
-
to: nativePath(change.to, handle),
|
|
125
|
-
base: existence.base
|
|
126
|
-
}
|
|
109
|
+
operation: { op: 'rename', path, to: nativePath(change.to, handle), base: existence.base },
|
|
127
110
|
};
|
|
128
111
|
}
|
|
129
|
-
return {
|
|
130
|
-
operation: {
|
|
131
|
-
op: 'remove',
|
|
132
|
-
path,
|
|
133
|
-
base: existence.base
|
|
134
|
-
}
|
|
135
|
-
};
|
|
112
|
+
return { operation: { op: 'remove', path, base: existence.base } };
|
|
136
113
|
}
|
|
137
114
|
export function houseChanges(batch, handle) {
|
|
138
115
|
const changes = [];
|
|
139
|
-
for (const change of batch.changes){
|
|
116
|
+
for (const change of batch.changes) {
|
|
140
117
|
const mapped = operationOf(batch, change, handle);
|
|
141
|
-
if ('rule' in mapped)
|
|
142
|
-
kind: 'unmapped',
|
|
143
|
-
path: change.path,
|
|
144
|
-
rule: mapped.rule
|
|
145
|
-
};
|
|
118
|
+
if ('rule' in mapped)
|
|
119
|
+
return { kind: 'unmapped', path: change.path, rule: mapped.rule };
|
|
146
120
|
changes.push(mapped.operation);
|
|
147
121
|
}
|
|
148
|
-
return {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
};
|
|
122
|
+
return { kind: 'changes', changes };
|
|
123
|
+
}
|
|
124
|
+
export function houseParts(saved, handle) {
|
|
125
|
+
return houseChanges({ id: '', baseRoomVersion: '', ...partsChanges(saved) }, handle);
|
|
126
|
+
}
|
|
127
|
+
export function houseMove(batch, source, destination) {
|
|
128
|
+
const changes = [];
|
|
129
|
+
for (const { path, to } of batch.between?.moves ?? []) {
|
|
130
|
+
const existence = priorExistence(batch, path);
|
|
131
|
+
if (existence === undefined)
|
|
132
|
+
return { kind: 'unmapped', path, rule: 'precondition-missing' };
|
|
133
|
+
if (!('base' in existence)) {
|
|
134
|
+
return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
|
|
135
|
+
}
|
|
136
|
+
changes.push({
|
|
137
|
+
op: 'rename',
|
|
138
|
+
path: nativePath(path, source),
|
|
139
|
+
to: nativePath(to, destination),
|
|
140
|
+
base: existence.base,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return { kind: 'changes', changes };
|
|
152
144
|
}
|
|
153
|
-
export function operationHead(batch) {
|
|
145
|
+
export function operationHead(batch, room) {
|
|
154
146
|
const writer = batch.writtenBy;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
} : {
|
|
158
|
-
operation_id: batch.id,
|
|
159
|
-
app_ref: writer.app,
|
|
160
|
-
release: writer.release
|
|
161
|
-
};
|
|
147
|
+
const head = { operation_id: batch.id, room_ref: room };
|
|
148
|
+
return writer === undefined ? head : { ...head, app_ref: writer.app, release: writer.release };
|
|
162
149
|
}
|
|
163
150
|
export function batchPaths(changes) {
|
|
164
151
|
return [
|
|
165
|
-
...new Set(changes.flatMap((change)=>change.op === 'rename' ? [
|
|
166
|
-
|
|
167
|
-
String(change.to)
|
|
168
|
-
] : [
|
|
169
|
-
String(change.path)
|
|
170
|
-
]))
|
|
171
|
-
].sort();
|
|
152
|
+
...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
153
|
+
];
|
|
172
154
|
}
|
|
173
155
|
export function deltaBody(changes) {
|
|
174
|
-
return JSON.stringify({
|
|
175
|
-
changes
|
|
176
|
-
});
|
|
156
|
+
return JSON.stringify({ changes });
|
|
177
157
|
}
|
|
178
158
|
export function deltaBytes(delta) {
|
|
179
159
|
return textBytes(delta);
|
|
180
160
|
}
|
|
181
|
-
export function uploadable(bytes) {
|
|
182
|
-
return
|
|
161
|
+
export function uploadable(inline, bytes, bounds) {
|
|
162
|
+
return (textBytes(JSON.stringify(inline)) > bounds.max_inline_body_bytes &&
|
|
163
|
+
bytes <= bounds.max_upload_bytes);
|
|
183
164
|
}
|
|
184
165
|
export function deltaDigest(delta) {
|
|
185
166
|
return sha256Hex(delta);
|
|
186
167
|
}
|
|
187
|
-
function material(value, handle) {
|
|
188
|
-
if (!Array.isArray(value))
|
|
168
|
+
function* material(value, handle, within = () => true) {
|
|
169
|
+
if (!Array.isArray(value))
|
|
170
|
+
return null;
|
|
189
171
|
const held = [];
|
|
190
|
-
for (const entry of value){
|
|
191
|
-
|
|
172
|
+
for (const entry of value) {
|
|
173
|
+
yield ROW_WEIGHT;
|
|
174
|
+
if (typeof entry !== 'object' || entry === null)
|
|
175
|
+
return null;
|
|
192
176
|
const file = entry;
|
|
193
|
-
if (typeof file.path !== 'string')
|
|
194
|
-
|
|
195
|
-
if (file.
|
|
177
|
+
if (typeof file.path !== 'string')
|
|
178
|
+
return null;
|
|
179
|
+
if (!within(file.path))
|
|
180
|
+
continue;
|
|
181
|
+
if (file.content !== null && typeof file.content !== 'string')
|
|
182
|
+
return null;
|
|
183
|
+
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
184
|
+
return null;
|
|
185
|
+
const binary = binaryFileOf(file);
|
|
186
|
+
if (binary === null)
|
|
187
|
+
return null;
|
|
188
|
+
const head = headChange(file);
|
|
189
|
+
if (head === null)
|
|
190
|
+
return null;
|
|
196
191
|
let path;
|
|
197
192
|
try {
|
|
198
193
|
path = roomLocalPath(file.path, handle);
|
|
199
|
-
}
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
200
196
|
return null;
|
|
201
197
|
}
|
|
202
198
|
held.push({
|
|
203
199
|
path,
|
|
204
200
|
content: file.content,
|
|
205
|
-
revision: typeof file.revision === 'string' ? file.revision : null
|
|
201
|
+
revision: typeof file.revision === 'string' ? file.revision : null,
|
|
202
|
+
...(binary === undefined ? {} : { binary }),
|
|
203
|
+
...(head === undefined ? {} : { head }),
|
|
206
204
|
});
|
|
207
205
|
}
|
|
208
206
|
return held;
|
|
209
207
|
}
|
|
210
|
-
function affectedOf(held) {
|
|
208
|
+
function* affectedOf(held) {
|
|
211
209
|
const affected = {};
|
|
212
|
-
for (const entry of held){
|
|
213
|
-
if (entry.content !== null)
|
|
210
|
+
for (const entry of held) {
|
|
211
|
+
if (entry.content !== null)
|
|
212
|
+
affected[entry.path] = entry.content;
|
|
213
|
+
yield ROW_WEIGHT;
|
|
214
214
|
}
|
|
215
215
|
return affected;
|
|
216
216
|
}
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
217
|
+
function* acceptedOf(at, contents) {
|
|
218
|
+
const answer = answering();
|
|
219
|
+
for (const entry of contents) {
|
|
220
|
+
yield ROW_WEIGHT + (entry.content?.length ?? 0);
|
|
221
|
+
if (entry.revision === null) {
|
|
222
|
+
answer.removals.add(entry.path);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (entry.content !== null)
|
|
226
|
+
answer.documents.set(entry.path, entry.content);
|
|
227
|
+
if (entry.binary !== undefined)
|
|
228
|
+
answer.binaryFiles.set(entry.path, entry.binary);
|
|
229
|
+
revised(answer, entry.path, entry.revision);
|
|
230
|
+
if (entry.head !== undefined)
|
|
231
|
+
answer.changes.set(entry.path, entry.head);
|
|
229
232
|
}
|
|
230
|
-
|
|
231
|
-
|
|
233
|
+
const unbinaried = answer.binaryFiles.size === 0;
|
|
234
|
+
const { binaryFiles, facts: _facts, ...room } = yield* answered(answer);
|
|
235
|
+
return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
|
|
236
|
+
}
|
|
237
|
+
function* movedOutcome(held, move) {
|
|
238
|
+
const authorities = Array.isArray(held.authorities) ? held.authorities : [];
|
|
239
|
+
const at = (authority) => {
|
|
240
|
+
const entry = authorities.find((one) => typeof one === 'object' &&
|
|
241
|
+
one !== null &&
|
|
242
|
+
one.authority === authority);
|
|
243
|
+
return entry === undefined ? null : readPosition(entry);
|
|
244
|
+
};
|
|
245
|
+
const left = at(move.source.authority);
|
|
246
|
+
const arrived = at(move.destination.authority);
|
|
247
|
+
if (left === null || arrived === null)
|
|
248
|
+
return unusable();
|
|
249
|
+
const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
|
|
250
|
+
const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
|
|
251
|
+
const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
|
|
252
|
+
if (leaving === null || arriving === null)
|
|
253
|
+
return unusable();
|
|
254
|
+
return {
|
|
255
|
+
kind: 'accepted',
|
|
256
|
+
...(yield* acceptedOf(left, leaving)),
|
|
257
|
+
destination: yield* acceptedOf(arrived, arriving),
|
|
232
258
|
};
|
|
259
|
+
}
|
|
260
|
+
export function* mutationOutcome(status, body, locator, handle, move) {
|
|
261
|
+
const refusal = doorRefusal(body);
|
|
262
|
+
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
263
|
+
return { kind: 'write-halted' };
|
|
264
|
+
}
|
|
233
265
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
234
266
|
const { current, ...fields } = refusal.fields;
|
|
235
|
-
const held = material(current, handle) ?? [];
|
|
267
|
+
const held = (yield* material(current, handle)) ?? [];
|
|
236
268
|
return {
|
|
237
269
|
kind: 'conflicted',
|
|
238
|
-
affected: affectedOf(held),
|
|
270
|
+
affected: yield* affectedOf(held),
|
|
239
271
|
code: refusal.code,
|
|
240
|
-
fields
|
|
272
|
+
fields,
|
|
273
|
+
retryable: refusal.retryable,
|
|
241
274
|
};
|
|
242
275
|
}
|
|
243
276
|
if (refusal !== null && status === 404) {
|
|
244
277
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
245
278
|
}
|
|
246
279
|
const classified = classifyDoor(status, body, locator);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
280
|
+
const reset = resetOf(refusal);
|
|
281
|
+
if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
|
|
282
|
+
return {
|
|
283
|
+
kind: 'retryable-refusal',
|
|
284
|
+
code: refusal.code,
|
|
285
|
+
fields: refusal.fields,
|
|
286
|
+
retryable: true,
|
|
287
|
+
reset,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
if (classified !== null && classified.kind !== 'scoped-refusal')
|
|
291
|
+
return classified;
|
|
292
|
+
if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
|
|
293
|
+
return classified;
|
|
251
294
|
}
|
|
252
|
-
if (classified !== null && status === 403) return classified;
|
|
253
295
|
if (refusal !== null && status >= 400) {
|
|
254
296
|
return {
|
|
255
297
|
kind: 'rejected',
|
|
256
298
|
affected: {},
|
|
257
299
|
code: refusal.code,
|
|
258
|
-
fields: refusal.fields
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
262
|
-
return {
|
|
263
|
-
kind: 'transport-uncertainty'
|
|
300
|
+
fields: refusal.fields,
|
|
301
|
+
retryable: refusal.retryable,
|
|
264
302
|
};
|
|
265
303
|
}
|
|
304
|
+
if (status !== 200)
|
|
305
|
+
return answeredFailure(status, body);
|
|
306
|
+
if (typeof body !== 'object' || body === null)
|
|
307
|
+
return unusable();
|
|
266
308
|
const held = body;
|
|
309
|
+
if (move !== undefined)
|
|
310
|
+
return yield* movedOutcome(held, move);
|
|
267
311
|
const at = readPosition(held);
|
|
268
|
-
if (at === null)
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
};
|
|
275
|
-
const documents = {};
|
|
276
|
-
const revisions = {};
|
|
277
|
-
const removals = [];
|
|
278
|
-
for (const entry of contents){
|
|
279
|
-
if (entry.content === null || entry.revision === null) {
|
|
280
|
-
removals.push(entry.path);
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
documents[entry.path] = entry.content;
|
|
284
|
-
revisions[entry.path] = entry.revision;
|
|
285
|
-
}
|
|
286
|
-
return {
|
|
287
|
-
kind: 'accepted',
|
|
288
|
-
roomVersion: roomVersion(at),
|
|
289
|
-
documents,
|
|
290
|
-
revisions,
|
|
291
|
-
removals: removals.sort()
|
|
292
|
-
};
|
|
312
|
+
if (at === null)
|
|
313
|
+
return unusable();
|
|
314
|
+
const contents = yield* material(held.contents, handle);
|
|
315
|
+
if (contents === null)
|
|
316
|
+
return unusable();
|
|
317
|
+
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
293
318
|
}
|
|
294
319
|
export function rejectedMapping(mapping) {
|
|
295
320
|
return {
|
|
296
321
|
kind: 'rejected',
|
|
297
322
|
affected: {},
|
|
298
323
|
code: mapping.rule,
|
|
299
|
-
fields: {
|
|
300
|
-
|
|
301
|
-
}
|
|
324
|
+
fields: { path: mapping.path },
|
|
325
|
+
retryable: false,
|
|
302
326
|
};
|
|
303
327
|
}
|
|
304
328
|
export function revisionBody(input) {
|
|
305
329
|
return {
|
|
306
330
|
path: nativePath(input.path, input.handle),
|
|
307
|
-
...input.revision === undefined ? {} : {
|
|
308
|
-
|
|
309
|
-
},
|
|
310
|
-
...input.pageToken === undefined ? {} : {
|
|
311
|
-
before: Number(input.pageToken)
|
|
312
|
-
}
|
|
331
|
+
...(input.revision === undefined ? {} : { revision: input.revision }),
|
|
332
|
+
...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),
|
|
313
333
|
};
|
|
314
334
|
}
|
|
335
|
+
function revisionAuthor(entry) {
|
|
336
|
+
const user = entry.author_user;
|
|
337
|
+
const userName = entry.author_user_name;
|
|
338
|
+
const site = entry.author_site;
|
|
339
|
+
const siteName = entry.author_site_name;
|
|
340
|
+
const inbox = entry.author_inbox;
|
|
341
|
+
const inboxName = entry.author_inbox_name;
|
|
342
|
+
const app = entry.author_app;
|
|
343
|
+
const appName = entry.author_app_name;
|
|
344
|
+
const named = [site, siteName, inbox, inboxName, app, appName].filter((held) => held !== undefined);
|
|
345
|
+
if (typeof user === 'string' && typeof userName === 'string' && named.length === 0)
|
|
346
|
+
return { kind: 'user', id: user, name: userName };
|
|
347
|
+
if (user !== null || userName !== undefined || named.length !== 2)
|
|
348
|
+
return null;
|
|
349
|
+
if (typeof site === 'string' && typeof siteName === 'string') {
|
|
350
|
+
return { kind: 'site', id: site, name: siteName };
|
|
351
|
+
}
|
|
352
|
+
if (typeof inbox === 'string' && typeof inboxName === 'string') {
|
|
353
|
+
return { kind: 'inbox', id: inbox, name: inboxName };
|
|
354
|
+
}
|
|
355
|
+
if (typeof app === 'string' && typeof appName === 'string') {
|
|
356
|
+
return { kind: 'app', id: app, name: appName };
|
|
357
|
+
}
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
315
360
|
export function historyOutcome(status, body, locator, request) {
|
|
316
361
|
const classified = classifyDoor(status, body, locator);
|
|
317
|
-
if (classified !== null)
|
|
318
|
-
return classified
|
|
319
|
-
kind: 'transport-uncertainty'
|
|
320
|
-
} : classified;
|
|
321
|
-
}
|
|
362
|
+
if (classified !== null)
|
|
363
|
+
return classified;
|
|
322
364
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
323
|
-
return
|
|
324
|
-
kind: 'transport-uncertainty'
|
|
325
|
-
};
|
|
365
|
+
return unusable();
|
|
326
366
|
}
|
|
327
367
|
const held = body;
|
|
328
|
-
if (!Array.isArray(held.revisions))
|
|
329
|
-
|
|
330
|
-
};
|
|
368
|
+
if (!Array.isArray(held.revisions))
|
|
369
|
+
return unusable();
|
|
331
370
|
const entries = [];
|
|
332
|
-
for (const entry of held.revisions){
|
|
333
|
-
if (typeof entry !== 'object' || entry === null)
|
|
334
|
-
|
|
335
|
-
};
|
|
371
|
+
for (const entry of held.revisions) {
|
|
372
|
+
if (typeof entry !== 'object' || entry === null)
|
|
373
|
+
return unusable();
|
|
336
374
|
entries.push(entry);
|
|
337
375
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if (named === undefined)
|
|
341
|
-
kind: 'no-history'
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
kind: 'scoped-refusal',
|
|
346
|
-
locator,
|
|
347
|
-
scope: 'content',
|
|
348
|
-
code: 'retained_history_unavailable',
|
|
349
|
-
fields: {
|
|
350
|
-
path: request.path,
|
|
351
|
-
revision: request.revision
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
if (typeof named.content !== 'string') return {
|
|
356
|
-
kind: 'transport-uncertainty'
|
|
357
|
-
};
|
|
358
|
-
return {
|
|
359
|
-
kind: 'revision',
|
|
360
|
-
content: named.content
|
|
361
|
-
};
|
|
376
|
+
const named = entries[0];
|
|
377
|
+
if (request.revision !== undefined && typeof named?.media_type !== 'string') {
|
|
378
|
+
if (named === undefined)
|
|
379
|
+
return { kind: 'no-history' };
|
|
380
|
+
if (typeof named.content !== 'string')
|
|
381
|
+
return unusable();
|
|
382
|
+
return { kind: 'revision', content: named.content };
|
|
362
383
|
}
|
|
363
|
-
if (entries.length === 0)
|
|
364
|
-
kind: 'no-history'
|
|
365
|
-
};
|
|
384
|
+
if (entries.length === 0)
|
|
385
|
+
return { kind: 'no-history' };
|
|
366
386
|
const revisions = [];
|
|
367
|
-
for (const entry of entries){
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
387
|
+
for (const entry of entries) {
|
|
388
|
+
const author = revisionAuthor(entry);
|
|
389
|
+
if (typeof entry.revision !== 'string' ||
|
|
390
|
+
author === null ||
|
|
391
|
+
typeof entry.created_at !== 'string') {
|
|
392
|
+
return unusable();
|
|
372
393
|
}
|
|
394
|
+
const binaryFile = binaryFileOf(entry);
|
|
395
|
+
if (binaryFile === null)
|
|
396
|
+
return unusable();
|
|
373
397
|
revisions.push({
|
|
374
398
|
revision: entry.revision,
|
|
375
|
-
author
|
|
376
|
-
time: entry.created_at
|
|
399
|
+
author,
|
|
400
|
+
time: entry.created_at,
|
|
401
|
+
...(binaryFile === undefined ? {} : { binaryFile }),
|
|
377
402
|
});
|
|
378
403
|
}
|
|
379
404
|
const next = held.next_before;
|
|
380
405
|
return {
|
|
381
406
|
kind: 'history',
|
|
382
407
|
revisions,
|
|
383
|
-
...typeof next === 'number' ? {
|
|
384
|
-
|
|
385
|
-
} : {}
|
|
408
|
+
...(typeof next === 'number' ? { pageToken: String(next) } : {}),
|
|
409
|
+
...(held.deleted === true ? { deleted: true } : {}),
|
|
386
410
|
};
|
|
387
411
|
}
|
|
388
|
-
|
|
389
|
-
//# sourceMappingURL=write.js.map
|