@agentshouse/mdruntime-adapter 0.1.0-alpha.8 → 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 +257 -194
- 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 +9 -3
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +123 -196
- 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,13 +11,19 @@ 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
|
+
export type OperationHead = {
|
|
16
|
+
readonly operation_id: string;
|
|
17
|
+
readonly app_ref?: string;
|
|
18
|
+
readonly release?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function operationHead(batch: ChangeBatch): OperationHead;
|
|
15
21
|
export declare function batchPaths(changes: readonly HouseOperation[]): readonly string[];
|
|
16
22
|
export declare function deltaBody(changes: readonly HouseOperation[]): string;
|
|
17
23
|
export declare function deltaBytes(delta: string): number;
|
|
18
24
|
export declare function uploadable(bytes: number): boolean;
|
|
19
25
|
export declare function deltaDigest(delta: string): Promise<string>;
|
|
20
|
-
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;
|
|
21
27
|
export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
|
|
22
28
|
kind: 'unmapped';
|
|
23
29
|
}>): {
|
|
@@ -30,7 +36,7 @@ export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
|
|
|
30
36
|
};
|
|
31
37
|
export declare function revisionBody(input: {
|
|
32
38
|
path: string;
|
|
33
|
-
handle: string
|
|
39
|
+
handle: string;
|
|
34
40
|
revision?: string;
|
|
35
41
|
pageToken?: string;
|
|
36
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,164 +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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
103
|
+
return { kind: 'changes', changes };
|
|
104
|
+
}
|
|
105
|
+
export function operationHead(batch) {
|
|
106
|
+
const writer = batch.writtenBy;
|
|
107
|
+
return writer === undefined
|
|
108
|
+
? { operation_id: batch.id }
|
|
109
|
+
: { operation_id: batch.id, app_ref: writer.app, release: writer.release };
|
|
152
110
|
}
|
|
153
111
|
export function batchPaths(changes) {
|
|
154
112
|
return [
|
|
155
|
-
...new Set(changes.flatMap((change)=>change.op === 'rename' ? [
|
|
156
|
-
String(change.path),
|
|
157
|
-
String(change.to)
|
|
158
|
-
] : [
|
|
159
|
-
String(change.path)
|
|
160
|
-
]))
|
|
113
|
+
...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
161
114
|
].sort();
|
|
162
115
|
}
|
|
163
116
|
export function deltaBody(changes) {
|
|
164
|
-
return JSON.stringify({
|
|
165
|
-
changes
|
|
166
|
-
});
|
|
117
|
+
return JSON.stringify({ changes });
|
|
167
118
|
}
|
|
168
119
|
export function deltaBytes(delta) {
|
|
169
120
|
return textBytes(delta);
|
|
@@ -175,97 +126,89 @@ export function deltaDigest(delta) {
|
|
|
175
126
|
return sha256Hex(delta);
|
|
176
127
|
}
|
|
177
128
|
function material(value, handle) {
|
|
178
|
-
if (!Array.isArray(value))
|
|
129
|
+
if (!Array.isArray(value))
|
|
130
|
+
return null;
|
|
179
131
|
const held = [];
|
|
180
|
-
for (const entry of value){
|
|
181
|
-
if (typeof entry !== 'object' || entry === null)
|
|
132
|
+
for (const entry of value) {
|
|
133
|
+
if (typeof entry !== 'object' || entry === null)
|
|
134
|
+
return null;
|
|
182
135
|
const file = entry;
|
|
183
|
-
if (typeof file.path !== 'string')
|
|
184
|
-
|
|
185
|
-
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;
|
|
186
142
|
let path;
|
|
187
143
|
try {
|
|
188
144
|
path = roomLocalPath(file.path, handle);
|
|
189
|
-
}
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
190
147
|
return null;
|
|
191
148
|
}
|
|
192
149
|
held.push({
|
|
193
150
|
path,
|
|
194
151
|
content: file.content,
|
|
195
|
-
revision: typeof file.revision === 'string' ? file.revision : null
|
|
152
|
+
revision: typeof file.revision === 'string' ? file.revision : null,
|
|
196
153
|
});
|
|
197
154
|
}
|
|
198
155
|
return held;
|
|
199
156
|
}
|
|
200
157
|
function affectedOf(held) {
|
|
201
158
|
const affected = {};
|
|
202
|
-
for (const entry of held){
|
|
203
|
-
if (entry.content !== null)
|
|
159
|
+
for (const entry of held) {
|
|
160
|
+
if (entry.content !== null)
|
|
161
|
+
affected[entry.path] = entry.content;
|
|
204
162
|
}
|
|
205
163
|
return affected;
|
|
206
164
|
}
|
|
207
165
|
export function mutationOutcome(status, body, locator, handle) {
|
|
208
166
|
const refusal = doorRefusal(body);
|
|
167
|
+
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
168
|
+
return { kind: 'write-halted' };
|
|
169
|
+
}
|
|
209
170
|
if (refusal !== null && refusal.code === 'rate_limited') {
|
|
210
171
|
const reset = refusal.fields.retry_at;
|
|
211
172
|
return {
|
|
212
173
|
kind: 'retryable-refusal',
|
|
213
174
|
code: refusal.code,
|
|
214
175
|
fields: refusal.fields,
|
|
215
|
-
...typeof reset === 'string' ? {
|
|
216
|
-
reset
|
|
217
|
-
} : {}
|
|
176
|
+
...(typeof reset === 'string' ? { reset } : {}),
|
|
218
177
|
};
|
|
219
178
|
}
|
|
220
|
-
if (refusal !== null && refusal.code === 'operation_expired')
|
|
221
|
-
kind: 'expired'
|
|
222
|
-
};
|
|
179
|
+
if (refusal !== null && refusal.code === 'operation_expired')
|
|
180
|
+
return { kind: 'expired' };
|
|
223
181
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
224
182
|
const { current, ...fields } = refusal.fields;
|
|
225
183
|
const held = material(current, handle) ?? [];
|
|
226
|
-
return {
|
|
227
|
-
kind: 'conflicted',
|
|
228
|
-
affected: affectedOf(held),
|
|
229
|
-
code: refusal.code,
|
|
230
|
-
fields
|
|
231
|
-
};
|
|
184
|
+
return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
|
|
232
185
|
}
|
|
233
186
|
if (refusal !== null && status === 404) {
|
|
234
187
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
235
188
|
}
|
|
236
189
|
const classified = classifyDoor(status, body, locator);
|
|
237
190
|
if (classified !== null && classified.kind !== 'scoped-refusal') {
|
|
238
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
239
|
-
kind: 'expired'
|
|
240
|
-
} : classified;
|
|
191
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;
|
|
241
192
|
}
|
|
242
|
-
if (classified !== null && status === 403)
|
|
193
|
+
if (classified !== null && status === 403)
|
|
194
|
+
return classified;
|
|
243
195
|
if (refusal !== null && status >= 400) {
|
|
244
|
-
return {
|
|
245
|
-
kind: 'rejected',
|
|
246
|
-
affected: {},
|
|
247
|
-
code: refusal.code,
|
|
248
|
-
fields: refusal.fields
|
|
249
|
-
};
|
|
196
|
+
return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
|
|
250
197
|
}
|
|
251
198
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
252
|
-
return {
|
|
253
|
-
kind: 'transport-uncertainty'
|
|
254
|
-
};
|
|
199
|
+
return { kind: 'transport-uncertainty' };
|
|
255
200
|
}
|
|
256
201
|
const held = body;
|
|
257
202
|
const at = readPosition(held);
|
|
258
|
-
if (at === null)
|
|
259
|
-
kind: 'transport-uncertainty'
|
|
260
|
-
};
|
|
203
|
+
if (at === null)
|
|
204
|
+
return { kind: 'transport-uncertainty' };
|
|
261
205
|
const contents = material(held.contents, handle);
|
|
262
|
-
if (contents === null)
|
|
263
|
-
kind: 'transport-uncertainty'
|
|
264
|
-
};
|
|
206
|
+
if (contents === null)
|
|
207
|
+
return { kind: 'transport-uncertainty' };
|
|
265
208
|
const documents = {};
|
|
266
209
|
const revisions = {};
|
|
267
210
|
const removals = [];
|
|
268
|
-
for (const entry of contents){
|
|
211
|
+
for (const entry of contents) {
|
|
269
212
|
if (entry.content === null || entry.revision === null) {
|
|
270
213
|
removals.push(entry.path);
|
|
271
214
|
continue;
|
|
@@ -278,7 +221,7 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
278
221
|
roomVersion: roomVersion(at),
|
|
279
222
|
documents,
|
|
280
223
|
revisions,
|
|
281
|
-
removals: removals.sort()
|
|
224
|
+
removals: removals.sort(),
|
|
282
225
|
};
|
|
283
226
|
}
|
|
284
227
|
export function rejectedMapping(mapping) {
|
|
@@ -286,94 +229,78 @@ export function rejectedMapping(mapping) {
|
|
|
286
229
|
kind: 'rejected',
|
|
287
230
|
affected: {},
|
|
288
231
|
code: mapping.rule,
|
|
289
|
-
fields: {
|
|
290
|
-
path: mapping.path
|
|
291
|
-
}
|
|
232
|
+
fields: { path: mapping.path },
|
|
292
233
|
};
|
|
293
234
|
}
|
|
294
235
|
export function revisionBody(input) {
|
|
295
236
|
return {
|
|
296
237
|
path: nativePath(input.path, input.handle),
|
|
297
|
-
...input.revision === undefined ? {} : {
|
|
298
|
-
|
|
299
|
-
},
|
|
300
|
-
...input.pageToken === undefined ? {} : {
|
|
301
|
-
before: Number(input.pageToken)
|
|
302
|
-
}
|
|
238
|
+
...(input.revision === undefined ? {} : { revision: input.revision }),
|
|
239
|
+
...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),
|
|
303
240
|
};
|
|
304
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
|
+
}
|
|
305
254
|
export function historyOutcome(status, body, locator, request) {
|
|
306
255
|
const classified = classifyDoor(status, body, locator);
|
|
307
256
|
if (classified !== null) {
|
|
308
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
309
|
-
kind: 'transport-uncertainty'
|
|
310
|
-
} : classified;
|
|
257
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;
|
|
311
258
|
}
|
|
312
259
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
313
|
-
return {
|
|
314
|
-
kind: 'transport-uncertainty'
|
|
315
|
-
};
|
|
260
|
+
return { kind: 'transport-uncertainty' };
|
|
316
261
|
}
|
|
317
262
|
const held = body;
|
|
318
|
-
if (!Array.isArray(held.revisions))
|
|
319
|
-
kind: 'transport-uncertainty'
|
|
320
|
-
};
|
|
263
|
+
if (!Array.isArray(held.revisions))
|
|
264
|
+
return { kind: 'transport-uncertainty' };
|
|
321
265
|
const entries = [];
|
|
322
|
-
for (const entry of held.revisions){
|
|
323
|
-
if (typeof entry !== 'object' || entry === null)
|
|
324
|
-
kind: 'transport-uncertainty'
|
|
325
|
-
};
|
|
266
|
+
for (const entry of held.revisions) {
|
|
267
|
+
if (typeof entry !== 'object' || entry === null)
|
|
268
|
+
return { kind: 'transport-uncertainty' };
|
|
326
269
|
entries.push(entry);
|
|
327
270
|
}
|
|
328
271
|
if (request.revision !== undefined) {
|
|
329
272
|
const named = entries[0];
|
|
330
|
-
if (named === undefined)
|
|
331
|
-
kind: 'no-history'
|
|
332
|
-
};
|
|
273
|
+
if (named === undefined)
|
|
274
|
+
return { kind: 'no-history' };
|
|
333
275
|
if (named.unavailable === true) {
|
|
334
276
|
return {
|
|
335
277
|
kind: 'scoped-refusal',
|
|
336
278
|
locator,
|
|
337
279
|
scope: 'content',
|
|
338
280
|
code: 'retained_history_unavailable',
|
|
339
|
-
fields: {
|
|
340
|
-
path: request.path,
|
|
341
|
-
revision: request.revision
|
|
342
|
-
}
|
|
281
|
+
fields: { path: request.path, revision: request.revision },
|
|
343
282
|
};
|
|
344
283
|
}
|
|
345
|
-
if (typeof named.content !== 'string')
|
|
346
|
-
kind: 'transport-uncertainty'
|
|
347
|
-
};
|
|
348
|
-
return {
|
|
349
|
-
kind: 'revision',
|
|
350
|
-
content: named.content
|
|
351
|
-
};
|
|
284
|
+
if (typeof named.content !== 'string')
|
|
285
|
+
return { kind: 'transport-uncertainty' };
|
|
286
|
+
return { kind: 'revision', content: named.content };
|
|
352
287
|
}
|
|
353
|
-
if (entries.length === 0)
|
|
354
|
-
kind: 'no-history'
|
|
355
|
-
};
|
|
288
|
+
if (entries.length === 0)
|
|
289
|
+
return { kind: 'no-history' };
|
|
356
290
|
const revisions = [];
|
|
357
|
-
for (const entry of entries){
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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' };
|
|
362
297
|
}
|
|
363
|
-
revisions.push({
|
|
364
|
-
revision: entry.revision,
|
|
365
|
-
author: entry.author_user,
|
|
366
|
-
time: entry.created_at
|
|
367
|
-
});
|
|
298
|
+
revisions.push({ revision: entry.revision, author, time: entry.created_at });
|
|
368
299
|
}
|
|
369
300
|
const next = held.next_before;
|
|
370
301
|
return {
|
|
371
302
|
kind: 'history',
|
|
372
303
|
revisions,
|
|
373
|
-
...typeof next === 'number' ? {
|
|
374
|
-
pageToken: String(next)
|
|
375
|
-
} : {}
|
|
304
|
+
...(typeof next === 'number' ? { pageToken: String(next) } : {}),
|
|
376
305
|
};
|
|
377
306
|
}
|
|
378
|
-
|
|
379
|
-
//# 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
|
}
|