@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c6ddfd288ac81
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/AGENTS.md +157 -26
- package/README.md +32 -0
- package/dist/actions.d.ts +4 -12
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +239 -332
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +256 -193
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +20 -18
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +182 -210
- package/dist/gather.d.ts +3 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +40 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/links.d.ts +11 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +51 -0
- package/dist/map.d.ts +2 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +6 -7
- package/dist/model.d.ts +2 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +21 -39
- package/dist/read.d.ts +29 -23
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +222 -195
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +30 -51
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +108 -124
- package/dist/stream.d.ts +9 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +186 -203
- package/dist/transport.d.ts +45 -28
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -3
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +23 -18
- package/dist/write.d.ts +3 -3
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +120 -203
- package/package.json +4 -12
- 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/version.js
CHANGED
|
@@ -3,27 +3,32 @@ export function roomVersion(at) {
|
|
|
3
3
|
}
|
|
4
4
|
export function logPosition(version) {
|
|
5
5
|
const split = version.lastIndexOf(':');
|
|
6
|
-
if (split < 1 || split === version.length - 1)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
position: version.slice(split + 1)
|
|
10
|
-
};
|
|
6
|
+
if (split < 1 || split === version.length - 1)
|
|
7
|
+
return null;
|
|
8
|
+
return { logEpoch: version.slice(0, split), position: version.slice(split + 1) };
|
|
11
9
|
}
|
|
12
10
|
export function readPosition(held) {
|
|
13
11
|
const { position, log_epoch: logEpoch } = held;
|
|
14
|
-
if (typeof position !== 'string' || position.length === 0)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
12
|
+
if (typeof position !== 'string' || position.length === 0)
|
|
13
|
+
return null;
|
|
14
|
+
if (typeof logEpoch !== 'string' || logEpoch.length === 0)
|
|
15
|
+
return null;
|
|
16
|
+
return { position, logEpoch };
|
|
20
17
|
}
|
|
21
18
|
export function presented(authority, at) {
|
|
22
|
-
return {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
return { authority, position: at.position, log_epoch: at.logEpoch };
|
|
20
|
+
}
|
|
21
|
+
const DECIMAL = /^(?:0|[1-9][0-9]*)$/;
|
|
22
|
+
export function reachedVersion(roomVersion, target, currentEpoch) {
|
|
23
|
+
if (roomVersion === target)
|
|
24
|
+
return true;
|
|
25
|
+
const held = logPosition(roomVersion);
|
|
26
|
+
const wanted = logPosition(target);
|
|
27
|
+
if (held === null || wanted === null)
|
|
28
|
+
return false;
|
|
29
|
+
if (!DECIMAL.test(held.position) || !DECIMAL.test(wanted.position))
|
|
30
|
+
return false;
|
|
31
|
+
if (held.logEpoch === wanted.logEpoch)
|
|
32
|
+
return BigInt(held.position) >= BigInt(wanted.position);
|
|
33
|
+
return held.logEpoch === currentEpoch;
|
|
27
34
|
}
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=version.js.map
|
package/dist/write.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type ChangeMapping = {
|
|
|
11
11
|
path: string;
|
|
12
12
|
rule: string;
|
|
13
13
|
};
|
|
14
|
-
export declare function houseChanges(batch: ChangeBatch, handle: string
|
|
14
|
+
export declare function houseChanges(batch: ChangeBatch, handle: string): ChangeMapping;
|
|
15
15
|
export type OperationHead = {
|
|
16
16
|
readonly operation_id: string;
|
|
17
17
|
readonly app_ref?: string;
|
|
@@ -23,7 +23,7 @@ export declare function deltaBody(changes: readonly HouseOperation[]): string;
|
|
|
23
23
|
export declare function deltaBytes(delta: string): number;
|
|
24
24
|
export declare function uploadable(bytes: number): boolean;
|
|
25
25
|
export declare function deltaDigest(delta: string): Promise<string>;
|
|
26
|
-
export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string
|
|
26
|
+
export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string): MutationResult;
|
|
27
27
|
export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
|
|
28
28
|
kind: 'unmapped';
|
|
29
29
|
}>): {
|
|
@@ -36,7 +36,7 @@ export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
|
|
|
36
36
|
};
|
|
37
37
|
export declare function revisionBody(input: {
|
|
38
38
|
path: string;
|
|
39
|
-
handle: string
|
|
39
|
+
handle: string;
|
|
40
40
|
revision?: string;
|
|
41
41
|
pageToken?: string;
|
|
42
42
|
}): Record<string, unknown>;
|
package/dist/write.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,EAEb,cAAc,EAEf,MAAM,wBAAwB,CAAC;AAMhC,eAAO,MAAM,uBAAuB,QAAkB,CAAC;AAEvD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,gBAAgB,QAAuC,CAAC;AAErE,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/D,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAuGrD,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAQ9E;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,CAK/D;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,SAAS,MAAM,EAAE,CAQhF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAEpE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE1D;AAqCD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,cAAc,CAyDhB;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;IAEjF,IAAI,EAAE,UAAU;IAChB,QAAQ;IACR,IAAI;IACJ,MAAM;QAAI,IAAI;;EAEjB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM1B;AAeD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,aAAa,CAiDf"}
|
package/dist/write.js
CHANGED
|
@@ -6,174 +6,115 @@ export const INLINE_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
|
6
6
|
export const UPLOAD_LINE_BYTES = 37;
|
|
7
7
|
export const UPLOAD_BYTES_MAX = 32 * 1024 * 1024 - UPLOAD_LINE_BYTES;
|
|
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, sections: change.sections };
|
|
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
|
-
return created === null ? {
|
|
94
|
-
rule: 'type-missing'
|
|
95
|
-
} : {
|
|
96
|
-
operation: created
|
|
97
|
-
};
|
|
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 };
|
|
98
77
|
}
|
|
99
78
|
const existence = priorExistence(batch, change.path);
|
|
100
|
-
if (existence === undefined)
|
|
101
|
-
rule: 'precondition-missing'
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
rule: 'presence-base-unrepresentable'
|
|
105
|
-
};
|
|
79
|
+
if (existence === undefined)
|
|
80
|
+
return { rule: 'precondition-missing' };
|
|
81
|
+
if (!('base' in existence))
|
|
82
|
+
return { rule: 'presence-base-unrepresentable' };
|
|
106
83
|
if (change.kind === 'replace') {
|
|
107
|
-
return {
|
|
108
|
-
operation: {
|
|
109
|
-
op: 'replace',
|
|
110
|
-
path,
|
|
111
|
-
base: existence.base,
|
|
112
|
-
content: change.content
|
|
113
|
-
}
|
|
114
|
-
};
|
|
84
|
+
return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
|
|
115
85
|
}
|
|
116
86
|
if (change.kind === 'move') {
|
|
117
|
-
if (priorAbsence(batch, change.to) === undefined)
|
|
118
|
-
rule: 'precondition-missing'
|
|
119
|
-
};
|
|
87
|
+
if (priorAbsence(batch, change.to) === undefined)
|
|
88
|
+
return { rule: 'precondition-missing' };
|
|
120
89
|
return {
|
|
121
|
-
operation: {
|
|
122
|
-
op: 'rename',
|
|
123
|
-
path,
|
|
124
|
-
to: nativePath(change.to, handle),
|
|
125
|
-
base: existence.base
|
|
126
|
-
}
|
|
90
|
+
operation: { op: 'rename', path, to: nativePath(change.to, handle), base: existence.base },
|
|
127
91
|
};
|
|
128
92
|
}
|
|
129
|
-
return {
|
|
130
|
-
operation: {
|
|
131
|
-
op: 'remove',
|
|
132
|
-
path,
|
|
133
|
-
base: existence.base
|
|
134
|
-
}
|
|
135
|
-
};
|
|
93
|
+
return { operation: { op: 'remove', path, base: existence.base } };
|
|
136
94
|
}
|
|
137
95
|
export function houseChanges(batch, handle) {
|
|
138
96
|
const changes = [];
|
|
139
|
-
for (const change of batch.changes){
|
|
97
|
+
for (const change of batch.changes) {
|
|
140
98
|
const mapped = operationOf(batch, change, handle);
|
|
141
|
-
if ('rule' in mapped)
|
|
142
|
-
kind: 'unmapped',
|
|
143
|
-
path: change.path,
|
|
144
|
-
rule: mapped.rule
|
|
145
|
-
};
|
|
99
|
+
if ('rule' in mapped)
|
|
100
|
+
return { kind: 'unmapped', path: change.path, rule: mapped.rule };
|
|
146
101
|
changes.push(mapped.operation);
|
|
147
102
|
}
|
|
148
|
-
return {
|
|
149
|
-
kind: 'changes',
|
|
150
|
-
changes
|
|
151
|
-
};
|
|
103
|
+
return { kind: 'changes', changes };
|
|
152
104
|
}
|
|
153
105
|
export function operationHead(batch) {
|
|
154
106
|
const writer = batch.writtenBy;
|
|
155
|
-
return writer === undefined
|
|
156
|
-
operation_id: batch.id
|
|
157
|
-
|
|
158
|
-
operation_id: batch.id,
|
|
159
|
-
app_ref: writer.app,
|
|
160
|
-
release: writer.release
|
|
161
|
-
};
|
|
107
|
+
return writer === undefined
|
|
108
|
+
? { operation_id: batch.id }
|
|
109
|
+
: { operation_id: batch.id, app_ref: writer.app, release: writer.release };
|
|
162
110
|
}
|
|
163
111
|
export function batchPaths(changes) {
|
|
164
112
|
return [
|
|
165
|
-
...new Set(changes.flatMap((change)=>change.op === 'rename' ? [
|
|
166
|
-
String(change.path),
|
|
167
|
-
String(change.to)
|
|
168
|
-
] : [
|
|
169
|
-
String(change.path)
|
|
170
|
-
]))
|
|
113
|
+
...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
171
114
|
].sort();
|
|
172
115
|
}
|
|
173
116
|
export function deltaBody(changes) {
|
|
174
|
-
return JSON.stringify({
|
|
175
|
-
changes
|
|
176
|
-
});
|
|
117
|
+
return JSON.stringify({ changes });
|
|
177
118
|
}
|
|
178
119
|
export function deltaBytes(delta) {
|
|
179
120
|
return textBytes(delta);
|
|
@@ -185,97 +126,89 @@ export function deltaDigest(delta) {
|
|
|
185
126
|
return sha256Hex(delta);
|
|
186
127
|
}
|
|
187
128
|
function material(value, handle) {
|
|
188
|
-
if (!Array.isArray(value))
|
|
129
|
+
if (!Array.isArray(value))
|
|
130
|
+
return null;
|
|
189
131
|
const held = [];
|
|
190
|
-
for (const entry of value){
|
|
191
|
-
if (typeof entry !== 'object' || entry === null)
|
|
132
|
+
for (const entry of value) {
|
|
133
|
+
if (typeof entry !== 'object' || entry === null)
|
|
134
|
+
return null;
|
|
192
135
|
const file = entry;
|
|
193
|
-
if (typeof file.path !== 'string')
|
|
194
|
-
|
|
195
|
-
if (file.
|
|
136
|
+
if (typeof file.path !== 'string')
|
|
137
|
+
return null;
|
|
138
|
+
if (file.content !== null && typeof file.content !== 'string')
|
|
139
|
+
return null;
|
|
140
|
+
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
141
|
+
return null;
|
|
196
142
|
let path;
|
|
197
143
|
try {
|
|
198
144
|
path = roomLocalPath(file.path, handle);
|
|
199
|
-
}
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
200
147
|
return null;
|
|
201
148
|
}
|
|
202
149
|
held.push({
|
|
203
150
|
path,
|
|
204
151
|
content: file.content,
|
|
205
|
-
revision: typeof file.revision === 'string' ? file.revision : null
|
|
152
|
+
revision: typeof file.revision === 'string' ? file.revision : null,
|
|
206
153
|
});
|
|
207
154
|
}
|
|
208
155
|
return held;
|
|
209
156
|
}
|
|
210
157
|
function affectedOf(held) {
|
|
211
158
|
const affected = {};
|
|
212
|
-
for (const entry of held){
|
|
213
|
-
if (entry.content !== null)
|
|
159
|
+
for (const entry of held) {
|
|
160
|
+
if (entry.content !== null)
|
|
161
|
+
affected[entry.path] = entry.content;
|
|
214
162
|
}
|
|
215
163
|
return affected;
|
|
216
164
|
}
|
|
217
165
|
export function mutationOutcome(status, body, locator, handle) {
|
|
218
166
|
const refusal = doorRefusal(body);
|
|
167
|
+
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
168
|
+
return { kind: 'write-halted' };
|
|
169
|
+
}
|
|
219
170
|
if (refusal !== null && refusal.code === 'rate_limited') {
|
|
220
171
|
const reset = refusal.fields.retry_at;
|
|
221
172
|
return {
|
|
222
173
|
kind: 'retryable-refusal',
|
|
223
174
|
code: refusal.code,
|
|
224
175
|
fields: refusal.fields,
|
|
225
|
-
...typeof reset === 'string' ? {
|
|
226
|
-
reset
|
|
227
|
-
} : {}
|
|
176
|
+
...(typeof reset === 'string' ? { reset } : {}),
|
|
228
177
|
};
|
|
229
178
|
}
|
|
230
|
-
if (refusal !== null && refusal.code === 'operation_expired')
|
|
231
|
-
kind: 'expired'
|
|
232
|
-
};
|
|
179
|
+
if (refusal !== null && refusal.code === 'operation_expired')
|
|
180
|
+
return { kind: 'expired' };
|
|
233
181
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
234
182
|
const { current, ...fields } = refusal.fields;
|
|
235
183
|
const held = material(current, handle) ?? [];
|
|
236
|
-
return {
|
|
237
|
-
kind: 'conflicted',
|
|
238
|
-
affected: affectedOf(held),
|
|
239
|
-
code: refusal.code,
|
|
240
|
-
fields
|
|
241
|
-
};
|
|
184
|
+
return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
|
|
242
185
|
}
|
|
243
186
|
if (refusal !== null && status === 404) {
|
|
244
187
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
245
188
|
}
|
|
246
189
|
const classified = classifyDoor(status, body, locator);
|
|
247
190
|
if (classified !== null && classified.kind !== 'scoped-refusal') {
|
|
248
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
249
|
-
kind: 'expired'
|
|
250
|
-
} : classified;
|
|
191
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;
|
|
251
192
|
}
|
|
252
|
-
if (classified !== null && status === 403)
|
|
193
|
+
if (classified !== null && status === 403)
|
|
194
|
+
return classified;
|
|
253
195
|
if (refusal !== null && status >= 400) {
|
|
254
|
-
return {
|
|
255
|
-
kind: 'rejected',
|
|
256
|
-
affected: {},
|
|
257
|
-
code: refusal.code,
|
|
258
|
-
fields: refusal.fields
|
|
259
|
-
};
|
|
196
|
+
return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
|
|
260
197
|
}
|
|
261
198
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
262
|
-
return {
|
|
263
|
-
kind: 'transport-uncertainty'
|
|
264
|
-
};
|
|
199
|
+
return { kind: 'transport-uncertainty' };
|
|
265
200
|
}
|
|
266
201
|
const held = body;
|
|
267
202
|
const at = readPosition(held);
|
|
268
|
-
if (at === null)
|
|
269
|
-
kind: 'transport-uncertainty'
|
|
270
|
-
};
|
|
203
|
+
if (at === null)
|
|
204
|
+
return { kind: 'transport-uncertainty' };
|
|
271
205
|
const contents = material(held.contents, handle);
|
|
272
|
-
if (contents === null)
|
|
273
|
-
kind: 'transport-uncertainty'
|
|
274
|
-
};
|
|
206
|
+
if (contents === null)
|
|
207
|
+
return { kind: 'transport-uncertainty' };
|
|
275
208
|
const documents = {};
|
|
276
209
|
const revisions = {};
|
|
277
210
|
const removals = [];
|
|
278
|
-
for (const entry of contents){
|
|
211
|
+
for (const entry of contents) {
|
|
279
212
|
if (entry.content === null || entry.revision === null) {
|
|
280
213
|
removals.push(entry.path);
|
|
281
214
|
continue;
|
|
@@ -288,7 +221,7 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
288
221
|
roomVersion: roomVersion(at),
|
|
289
222
|
documents,
|
|
290
223
|
revisions,
|
|
291
|
-
removals: removals.sort()
|
|
224
|
+
removals: removals.sort(),
|
|
292
225
|
};
|
|
293
226
|
}
|
|
294
227
|
export function rejectedMapping(mapping) {
|
|
@@ -296,94 +229,78 @@ export function rejectedMapping(mapping) {
|
|
|
296
229
|
kind: 'rejected',
|
|
297
230
|
affected: {},
|
|
298
231
|
code: mapping.rule,
|
|
299
|
-
fields: {
|
|
300
|
-
path: mapping.path
|
|
301
|
-
}
|
|
232
|
+
fields: { path: mapping.path },
|
|
302
233
|
};
|
|
303
234
|
}
|
|
304
235
|
export function revisionBody(input) {
|
|
305
236
|
return {
|
|
306
237
|
path: nativePath(input.path, input.handle),
|
|
307
|
-
...input.revision === undefined ? {} : {
|
|
308
|
-
|
|
309
|
-
},
|
|
310
|
-
...input.pageToken === undefined ? {} : {
|
|
311
|
-
before: Number(input.pageToken)
|
|
312
|
-
}
|
|
238
|
+
...(input.revision === undefined ? {} : { revision: input.revision }),
|
|
239
|
+
...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),
|
|
313
240
|
};
|
|
314
241
|
}
|
|
242
|
+
function revisionAuthor(entry) {
|
|
243
|
+
const user = entry.author_user;
|
|
244
|
+
const site = entry.author_site;
|
|
245
|
+
const name = entry.author_site_name;
|
|
246
|
+
if (typeof user === 'string' && site === undefined && name === undefined) {
|
|
247
|
+
return { kind: 'user', id: user };
|
|
248
|
+
}
|
|
249
|
+
if (user === null && typeof site === 'string' && typeof name === 'string') {
|
|
250
|
+
return { kind: 'site', id: site, name };
|
|
251
|
+
}
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
315
254
|
export function historyOutcome(status, body, locator, request) {
|
|
316
255
|
const classified = classifyDoor(status, body, locator);
|
|
317
256
|
if (classified !== null) {
|
|
318
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
319
|
-
kind: 'transport-uncertainty'
|
|
320
|
-
} : classified;
|
|
257
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;
|
|
321
258
|
}
|
|
322
259
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
323
|
-
return {
|
|
324
|
-
kind: 'transport-uncertainty'
|
|
325
|
-
};
|
|
260
|
+
return { kind: 'transport-uncertainty' };
|
|
326
261
|
}
|
|
327
262
|
const held = body;
|
|
328
|
-
if (!Array.isArray(held.revisions))
|
|
329
|
-
kind: 'transport-uncertainty'
|
|
330
|
-
};
|
|
263
|
+
if (!Array.isArray(held.revisions))
|
|
264
|
+
return { kind: 'transport-uncertainty' };
|
|
331
265
|
const entries = [];
|
|
332
|
-
for (const entry of held.revisions){
|
|
333
|
-
if (typeof entry !== 'object' || entry === null)
|
|
334
|
-
kind: 'transport-uncertainty'
|
|
335
|
-
};
|
|
266
|
+
for (const entry of held.revisions) {
|
|
267
|
+
if (typeof entry !== 'object' || entry === null)
|
|
268
|
+
return { kind: 'transport-uncertainty' };
|
|
336
269
|
entries.push(entry);
|
|
337
270
|
}
|
|
338
271
|
if (request.revision !== undefined) {
|
|
339
272
|
const named = entries[0];
|
|
340
|
-
if (named === undefined)
|
|
341
|
-
kind: 'no-history'
|
|
342
|
-
};
|
|
273
|
+
if (named === undefined)
|
|
274
|
+
return { kind: 'no-history' };
|
|
343
275
|
if (named.unavailable === true) {
|
|
344
276
|
return {
|
|
345
277
|
kind: 'scoped-refusal',
|
|
346
278
|
locator,
|
|
347
279
|
scope: 'content',
|
|
348
280
|
code: 'retained_history_unavailable',
|
|
349
|
-
fields: {
|
|
350
|
-
path: request.path,
|
|
351
|
-
revision: request.revision
|
|
352
|
-
}
|
|
281
|
+
fields: { path: request.path, revision: request.revision },
|
|
353
282
|
};
|
|
354
283
|
}
|
|
355
|
-
if (typeof named.content !== 'string')
|
|
356
|
-
kind: 'transport-uncertainty'
|
|
357
|
-
};
|
|
358
|
-
return {
|
|
359
|
-
kind: 'revision',
|
|
360
|
-
content: named.content
|
|
361
|
-
};
|
|
284
|
+
if (typeof named.content !== 'string')
|
|
285
|
+
return { kind: 'transport-uncertainty' };
|
|
286
|
+
return { kind: 'revision', content: named.content };
|
|
362
287
|
}
|
|
363
|
-
if (entries.length === 0)
|
|
364
|
-
kind: 'no-history'
|
|
365
|
-
};
|
|
288
|
+
if (entries.length === 0)
|
|
289
|
+
return { kind: 'no-history' };
|
|
366
290
|
const revisions = [];
|
|
367
|
-
for (const entry of entries){
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
291
|
+
for (const entry of entries) {
|
|
292
|
+
const author = revisionAuthor(entry);
|
|
293
|
+
if (typeof entry.revision !== 'string' ||
|
|
294
|
+
author === null ||
|
|
295
|
+
typeof entry.created_at !== 'string') {
|
|
296
|
+
return { kind: 'transport-uncertainty' };
|
|
372
297
|
}
|
|
373
|
-
revisions.push({
|
|
374
|
-
revision: entry.revision,
|
|
375
|
-
author: entry.author_user,
|
|
376
|
-
time: entry.created_at
|
|
377
|
-
});
|
|
298
|
+
revisions.push({ revision: entry.revision, author, time: entry.created_at });
|
|
378
299
|
}
|
|
379
300
|
const next = held.next_before;
|
|
380
301
|
return {
|
|
381
302
|
kind: 'history',
|
|
382
303
|
revisions,
|
|
383
|
-
...typeof next === 'number' ? {
|
|
384
|
-
pageToken: String(next)
|
|
385
|
-
} : {}
|
|
304
|
+
...(typeof next === 'number' ? { pageToken: String(next) } : {}),
|
|
386
305
|
};
|
|
387
306
|
}
|
|
388
|
-
|
|
389
|
-
//# sourceMappingURL=write.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-c6ddfd288ac81",
|
|
4
4
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,19 +21,11 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
|
23
23
|
"AGENTS.md",
|
|
24
|
+
"README.md",
|
|
24
25
|
"LICENSE"
|
|
25
26
|
],
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/agentshouse/mdruntime.git",
|
|
29
|
-
"directory": "packages/mdruntime-adapter"
|
|
30
|
-
},
|
|
31
|
-
"homepage": "https://github.com/agentshouse/mdruntime#readme",
|
|
32
|
-
"bugs": {
|
|
33
|
-
"url": "https://github.com/agentshouse/mdruntime/issues"
|
|
34
|
-
},
|
|
35
27
|
"dependencies": {
|
|
36
|
-
"@agentshouse/mdmodel": "0.1.0-
|
|
37
|
-
"@agentshouse/mdruntime": "0.1.0-
|
|
28
|
+
"@agentshouse/mdmodel": "0.1.0-c83456e1cebfb",
|
|
29
|
+
"@agentshouse/mdruntime": "0.1.0-c436a939f2119"
|
|
38
30
|
}
|
|
39
31
|
}
|