@agentshouse/mdruntime 0.1.0-alpha.31 → 0.1.0-alpha.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/dist/collection.d.ts +8 -5
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +35 -11
- package/dist/collection.js.map +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +112 -51
- package/dist/connection.js.map +1 -1
- package/dist/replica.d.ts +3 -2
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +85 -11
- package/dist/replica.js.map +1 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +9 -0
- package/dist/save.js.map +1 -1
- package/package.json +1 -1
package/dist/collection.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Document, type Validation } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { ModelState } from './model.js';
|
|
3
3
|
import type { MdModelIdentity } from './adapter.js';
|
|
4
|
+
import { type Refused, type Unconfirmed } from './transfer.js';
|
|
4
5
|
export declare const MD_MODEL: MdModelIdentity;
|
|
5
6
|
export type Collection = {
|
|
6
7
|
documents: Readonly<Record<string, Document>>;
|
|
@@ -15,14 +16,16 @@ export type Composition = {
|
|
|
15
16
|
} | null;
|
|
16
17
|
};
|
|
17
18
|
export declare function governing(composition: Composition, path: string): ModelState;
|
|
18
|
-
|
|
19
|
+
type Previous = {
|
|
19
20
|
text: Readonly<Record<string, string>>;
|
|
20
21
|
collection: Collection;
|
|
21
|
-
}
|
|
22
|
-
export declare function
|
|
23
|
-
|
|
22
|
+
};
|
|
23
|
+
export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): Collection;
|
|
24
|
+
export declare function readCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): {
|
|
25
|
+
kind: 'read';
|
|
24
26
|
collection: Collection;
|
|
25
|
-
}
|
|
27
|
+
} | Refused | Unconfirmed;
|
|
26
28
|
export declare function validRoot(root: unknown): root is string;
|
|
27
29
|
export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
|
|
30
|
+
export {};
|
|
28
31
|
//# sourceMappingURL=collection.d.ts.map
|
package/dist/collection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EAEb,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAe,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5E,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAIhG,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9C,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI,CAAC;CACnE,CAAC;AASF,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAI5E;AAED,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC;AAanF,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,QAAQ,GAClB,UAAU,CAOZ;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,QAAQ,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GAAG,OAAO,GAAG,WAAW,CAoBlE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEvD;AA0CD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,WAAW,EAAE,WAAW,GACvB,UAAU,CA0CZ"}
|
package/dist/collection.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parse, validate, VERSION } from '@agentshouse/mdmodel';
|
|
2
2
|
import { beneath, normalize } from './paths.js';
|
|
3
|
+
import { unconfirmed } from './transfer.js';
|
|
3
4
|
export const MD_MODEL = {
|
|
4
5
|
identity: '@agentshouse/mdmodel',
|
|
5
6
|
version: VERSION
|
|
@@ -13,15 +14,17 @@ function selected(composition, path) {
|
|
|
13
14
|
export function governing(composition, path) {
|
|
14
15
|
return composition.selection !== null && selected(composition, path) ? composition.selection.model : composition.model;
|
|
15
16
|
}
|
|
17
|
+
function parsedAt(text, path, previous) {
|
|
18
|
+
const retained = previous?.collection.documents[path];
|
|
19
|
+
return retained !== undefined && previous?.text[path] === text[path] ? {
|
|
20
|
+
ok: true,
|
|
21
|
+
document: retained
|
|
22
|
+
} : parse(text[path], path);
|
|
23
|
+
}
|
|
16
24
|
export function parseCollection(text, composition, previous) {
|
|
17
25
|
const documents = {};
|
|
18
26
|
for (const path of Object.keys(text).sort()){
|
|
19
|
-
const
|
|
20
|
-
if (retained !== undefined && previous?.text[path] === text[path]) {
|
|
21
|
-
documents[path] = retained;
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
const parsed = parse(text[path], path);
|
|
27
|
+
const parsed = parsedAt(text, path, previous);
|
|
25
28
|
if (parsed.ok) documents[path] = parsed.document;
|
|
26
29
|
}
|
|
27
30
|
return {
|
|
@@ -30,11 +33,32 @@ export function parseCollection(text, composition, previous) {
|
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
35
|
export function readCollection(text, composition, previous) {
|
|
33
|
-
if (!validRoot(composition.collectionRoot)) return
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if (!validRoot(composition.collectionRoot)) return unconfirmed;
|
|
37
|
+
const documents = {};
|
|
38
|
+
for (const path of Object.keys(text).sort()){
|
|
39
|
+
const parsed = parsedAt(text, path, previous);
|
|
40
|
+
if (!parsed.ok) return {
|
|
41
|
+
kind: 'refused',
|
|
42
|
+
refusal: parsed.refusal
|
|
43
|
+
};
|
|
44
|
+
const { type } = parsed.document;
|
|
45
|
+
if (!member(path, composition.collectionRoot) && !selected(composition, path) && type !== undefined && type !== 'any') return {
|
|
46
|
+
kind: 'refused',
|
|
47
|
+
refusal: {
|
|
48
|
+
rule: 'outside-collection-type',
|
|
49
|
+
file: path,
|
|
50
|
+
version: VERSION
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
documents[path] = parsed.document;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
kind: 'read',
|
|
57
|
+
collection: {
|
|
58
|
+
documents,
|
|
59
|
+
composition
|
|
60
|
+
}
|
|
61
|
+
};
|
|
38
62
|
}
|
|
39
63
|
export function validRoot(root) {
|
|
40
64
|
return typeof root === 'string' && normalize(root) === root;
|
package/dist/collection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime/src/collection.ts"],"sourcesContent":["import {\n parse,\n validate,\n VERSION,\n type Document,\n type Validation,\n type VerifiedModel,\n} from '@agentshouse/mdmodel';\nimport { beneath, normalize } from './paths.js';\nimport type { ModelState } from './model.js';\nimport type { MdModelIdentity } from './adapter.js';\n\nexport const MD_MODEL: MdModelIdentity = { identity: '@agentshouse/mdmodel', version: VERSION };\n\nconst NO_TYPES: VerifiedModel = { types: {} };\n\nexport type Collection = {\n documents: Readonly<Record<string, Document>>;\n composition: Composition;\n};\n\nexport type Composition = {\n collectionRoot: string;\n model: ModelState;\n selection: { roots: readonly string[]; model: ModelState } | null;\n};\n\nfunction selected(composition: Composition, path: string): boolean {\n return (\n composition.selection !== null &&\n composition.selection.roots.some((root) => beneath(root, path))\n );\n}\n\nexport function governing(composition: Composition, path: string): ModelState {\n return composition.selection !== null && selected(composition, path)\n ? composition.selection.model\n : composition.model;\n}\n\nexport function parseCollection(\n text: Readonly<Record<string, string>>,\n composition: Composition,\n previous?: { text: Readonly<Record<string, string>>; collection: Collection },\n): Collection {\n const documents: Record<string, Document> = {};\n for (const path of Object.keys(text).sort()) {\n const retained = previous?.collection.documents[path];\n if (retained !== undefined && previous?.text[path] === text[path]) {\n documents[path] = retained;\n continue;\n }\n const parsed = parse(text[path], path);\n if (parsed.ok) documents[path] = parsed.document;\n }\n return { documents, composition };\n}\n\nexport function readCollection(\n text: Readonly<Record<string, string>>,\n composition: Composition,\n previous?: { text: Readonly<Record<string, string>>; collection: Collection },\n): Collection | null {\n if (!validRoot(composition.collectionRoot)) return null;\n const collection = parseCollection(text, composition, previous);\n if (Object.keys(collection.documents).length !== Object.keys(text).length) return null;\n if (\n Object.entries(collection.documents).some(\n ([path, document]) =>\n !member(path, composition.collectionRoot) &&\n !selected(composition, path) &&\n document.type !== undefined &&\n document.type !== 'any',\n )\n )\n return null;\n return collection;\n}\n\nexport function validRoot(root: unknown): root is string {\n return typeof root === 'string' && normalize(root) === root;\n}\n\nfunction member(path: string, root: string): boolean {\n return root === '' || path.startsWith(`${root}/`);\n}\n\ntype Refusal = Extract<Validation, { verdict: 'refuse' }>;\n\nfunction validateAgainst(\n documents: Readonly<Record<string, string>>,\n binaryTargets: readonly string[],\n prefix: string,\n model: ModelState,\n): Validation {\n if (model.status === 'unavailable') {\n const typed = Object.entries(documents).find(([, content]) => {\n const parsed = parse(content);\n return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';\n });\n if (typed !== undefined)\n return {\n verdict: 'refuse',\n rule: 'model-unavailable',\n file: `${prefix}${typed[0]}`,\n version: VERSION,\n };\n }\n const verdict = validate(\n documents,\n { binaryTargets },\n model.status === 'unavailable' ? NO_TYPES : { types: model.types },\n );\n if (verdict.verdict === 'accept') return verdict;\n return {\n ...verdict,\n file: `${prefix}${verdict.file}`,\n ...(verdict.referrers === undefined\n ? {}\n : { referrers: verdict.referrers.map((path) => `${prefix}${path}`) }),\n };\n}\n\nexport function validateCollection(\n text: Readonly<Record<string, string>>,\n binaryTargets: readonly string[],\n composition: Composition,\n): Validation {\n const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;\n const collection: Record<string, string> = {};\n const selection: Record<string, string> = {};\n for (const [path, content] of Object.entries(text)) {\n if (member(path, composition.collectionRoot)) {\n collection[path.slice(prefix.length)] = content;\n continue;\n }\n if (selected(composition, path)) {\n selection[path] = content;\n continue;\n }\n const parsed = parse(content, path);\n if (!parsed.ok) return { verdict: 'refuse', ...parsed.refusal };\n if (Object.hasOwn(parsed.document.fields, 'type') && parsed.document.fields.type !== 'any') {\n return { verdict: 'refuse', rule: 'outside-collection-type', file: path, version: VERSION };\n }\n }\n const verdicts = [\n validateAgainst(\n collection,\n binaryTargets\n .filter((path) => member(path, composition.collectionRoot))\n .map((path) => path.slice(prefix.length)),\n prefix,\n composition.model,\n ),\n ];\n if (composition.selection !== null) {\n verdicts.push(\n validateAgainst(\n selection,\n binaryTargets.filter((path) => selected(composition, path)),\n '',\n composition.selection.model,\n ),\n );\n }\n const refusals = verdicts.filter((verdict): verdict is Refusal => verdict.verdict === 'refuse');\n if (refusals.length === 0) return verdicts[0];\n return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];\n}\n"],"names":["parse","validate","VERSION","beneath","normalize","MD_MODEL","identity","version","NO_TYPES","types","selected","composition","path","selection","roots","some","root","governing","model","parseCollection","text","previous","documents","Object","keys","sort","retained","collection","undefined","parsed","ok","document","readCollection","validRoot","collectionRoot","length","entries","member","type","startsWith","validateAgainst","binaryTargets","prefix","status","typed","find","content","verdict","rule","file","referrers","map","validateCollection","slice","refusal","hasOwn","fields","verdicts","filter","push","refusals"],"mappings":"AAAA,SACEA,KAAK,EACLC,QAAQ,EACRC,OAAO,QAIF,uBAAuB;AAC9B,SAASC,OAAO,EAAEC,SAAS,QAAQ,aAAa;AAIhD,OAAO,MAAMC,WAA4B;IAAEC,UAAU;IAAwBC,SAASL;AAAQ,EAAE;AAEhG,MAAMM,WAA0B;IAAEC,OAAO,CAAC;AAAE;AAa5C,SAASC,SAASC,WAAwB,EAAEC,IAAY;IACtD,OACED,YAAYE,SAAS,KAAK,QAC1BF,YAAYE,SAAS,CAACC,KAAK,CAACC,IAAI,CAAC,CAACC,OAASb,QAAQa,MAAMJ;AAE7D;AAEA,OAAO,SAASK,UAAUN,WAAwB,EAAEC,IAAY;IAC9D,OAAOD,YAAYE,SAAS,KAAK,QAAQH,SAASC,aAAaC,QAC3DD,YAAYE,SAAS,CAACK,KAAK,GAC3BP,YAAYO,KAAK;AACvB;AAEA,OAAO,SAASC,gBACdC,IAAsC,EACtCT,WAAwB,EACxBU,QAA6E;IAE7E,MAAMC,YAAsC,CAAC;IAC7C,KAAK,MAAMV,QAAQW,OAAOC,IAAI,CAACJ,MAAMK,IAAI,GA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ACA,MAAMjB,SAAS7B,MAAM8C,SAASlC;QAC9B,IAAI,CAACiB,OAAOC,EAAE,EAAE,OAAO;YAAEiB,SAAS;YAAU,GAAGlB,OAAOyB,OAAO;QAAC;QAC9D,IAAI/B,OAAOgC,MAAM,CAAC1B,OAAOE,QAAQ,CAACyB,MAAM,EAAE,WAAW3B,OAAOE,QAAQ,CAACyB,MAAM,CAAClB,IAAI,KAAK,OAAO;YAC1F,OAAO;gBAAES,SAAS;gBAAUC,MAAM;gBAA2BC,MAAMrC;gBAAML,SAASL;YAAQ;QAC5F;IACF;IACA,MAAMuD,WAAW;QACfjB,gBACEb,YACAc,cACGiB,MAAM,CAAC,CAAC9C,OAASyB,OAAOzB,MAAMD,YAAYuB,cAAc,GACxDiB,GAAG,CAAC,CAACvC,OAASA,KAAKyC,KAAK,CAACX,OAAOP,MAAM,IACzCO,QACA/B,YAAYO,KAAK;KAEpB;IACD,IAAIP,YAAYE,SAAS,KAAK,MAAM;QAClC4C,SAASE,IAAI,CACXnB,gBACE3B,WACA4B,cAAciB,MAAM,CAAC,CAAC9C,OAASF,SAASC,aAAaC,QACrD,IACAD,YAAYE,SAAS,CAACK,KAAK;IAGjC;IACA,MAAM0C,WAAWH,SAASC,MAAM,CAAC,CAACX,UAAgCA,QAAQA,OAAO,KAAK;IACtF,IAAIa,SAASzB,MAAM,KAAK,GAAG,OAAOsB,QAAQ,CAAC,EAAE;IAC7C,OAAOG,SAASf,IAAI,CAAC,CAACS,UAAYA,QAAQN,IAAI,KAAK,wBAAwBY,QAAQ,CAAC,EAAE;AACxF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime/src/collection.ts"],"sourcesContent":["import {\n parse,\n validate,\n VERSION,\n type Document,\n type ParseResult,\n type Validation,\n type VerifiedModel,\n} from '@agentshouse/mdmodel';\nimport { beneath, normalize } from './paths.js';\nimport type { ModelState } from './model.js';\nimport type { MdModelIdentity } from './adapter.js';\nimport { unconfirmed, type Refused, type Unconfirmed } from './transfer.js';\n\nexport const MD_MODEL: MdModelIdentity = { identity: '@agentshouse/mdmodel', version: VERSION };\n\nconst NO_TYPES: VerifiedModel = { types: {} };\n\nexport type Collection = {\n documents: Readonly<Record<string, Document>>;\n composition: Composition;\n};\n\nexport type Composition = {\n collectionRoot: string;\n model: ModelState;\n selection: { roots: readonly string[]; model: ModelState } | null;\n};\n\nfunction selected(composition: Composition, path: string): boolean {\n return (\n composition.selection !== null &&\n composition.selection.roots.some((root) => beneath(root, path))\n );\n}\n\nexport function governing(composition: Composition, path: string): ModelState {\n return composition.selection !== null && selected(composition, path)\n ? composition.selection.model\n : composition.model;\n}\n\ntype Previous = { text: Readonly<Record<string, string>>; collection: Collection };\n\nfunction parsedAt(\n text: Readonly<Record<string, string>>,\n path: string,\n previous: Previous | undefined,\n): ParseResult {\n const retained = previous?.collection.documents[path];\n return retained !== undefined && previous?.text[path] === text[path]\n ? { ok: true, document: retained }\n : parse(text[path], path);\n}\n\nexport function parseCollection(\n text: Readonly<Record<string, string>>,\n composition: Composition,\n previous?: Previous,\n): Collection {\n const documents: Record<string, Document> = {};\n for (const path of Object.keys(text).sort()) {\n const parsed = parsedAt(text, path, previous);\n if (parsed.ok) documents[path] = parsed.document;\n }\n return { documents, composition };\n}\n\nexport function readCollection(\n text: Readonly<Record<string, string>>,\n composition: Composition,\n previous?: Previous,\n): { kind: 'read'; collection: Collection } | Refused | Unconfirmed {\n if (!validRoot(composition.collectionRoot)) return unconfirmed;\n const documents: Record<string, Document> = {};\n for (const path of Object.keys(text).sort()) {\n const parsed = parsedAt(text, path, previous);\n if (!parsed.ok) return { kind: 'refused', refusal: parsed.refusal };\n const { type } = parsed.document;\n if (\n !member(path, composition.collectionRoot) &&\n !selected(composition, path) &&\n type !== undefined &&\n type !== 'any'\n )\n return {\n kind: 'refused',\n refusal: { rule: 'outside-collection-type', file: path, version: VERSION },\n };\n documents[path] = parsed.document;\n }\n return { kind: 'read', collection: { documents, composition } };\n}\n\nexport function validRoot(root: unknown): root is string {\n return typeof root === 'string' && normalize(root) === root;\n}\n\nfunction member(path: string, root: string): boolean {\n return root === '' || path.startsWith(`${root}/`);\n}\n\ntype Refusal = Extract<Validation, { verdict: 'refuse' }>;\n\nfunction validateAgainst(\n documents: Readonly<Record<string, string>>,\n binaryTargets: readonly string[],\n prefix: string,\n model: ModelState,\n): Validation {\n if (model.status === 'unavailable') {\n const typed = Object.entries(documents).find(([, content]) => {\n const parsed = parse(content);\n return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';\n });\n if (typed !== undefined)\n return {\n verdict: 'refuse',\n rule: 'model-unavailable',\n file: `${prefix}${typed[0]}`,\n version: VERSION,\n };\n }\n const verdict = validate(\n documents,\n { binaryTargets },\n model.status === 'unavailable' ? NO_TYPES : { types: model.types },\n );\n if (verdict.verdict === 'accept') return verdict;\n return {\n ...verdict,\n file: `${prefix}${verdict.file}`,\n ...(verdict.referrers === undefined\n ? {}\n : { referrers: verdict.referrers.map((path) => `${prefix}${path}`) }),\n };\n}\n\nexport function validateCollection(\n text: Readonly<Record<string, string>>,\n binaryTargets: readonly string[],\n composition: Composition,\n): Validation {\n const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;\n const collection: Record<string, string> = {};\n const selection: Record<string, string> = {};\n for (const [path, content] of Object.entries(text)) {\n if (member(path, composition.collectionRoot)) {\n collection[path.slice(prefix.length)] = content;\n continue;\n }\n if (selected(composition, path)) {\n selection[path] = content;\n continue;\n }\n const parsed = parse(content, path);\n if (!parsed.ok) return { verdict: 'refuse', ...parsed.refusal };\n if (Object.hasOwn(parsed.document.fields, 'type') && parsed.document.fields.type !== 'any') {\n return { verdict: 'refuse', rule: 'outside-collection-type', file: path, version: VERSION };\n }\n }\n const verdicts = [\n validateAgainst(\n collection,\n binaryTargets\n .filter((path) => member(path, composition.collectionRoot))\n .map((path) => path.slice(prefix.length)),\n prefix,\n composition.model,\n ),\n ];\n if (composition.selection !== null) {\n verdicts.push(\n validateAgainst(\n selection,\n binaryTargets.filter((path) => selected(composition, path)),\n '',\n composition.selection.model,\n ),\n );\n }\n const refusals = verdicts.filter((verdict): verdict is Refusal => verdict.verdict === 'refuse');\n if (refusals.length === 0) return verdicts[0];\n return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];\n}\n"],"names":["parse","validate","VERSION","beneath","normalize","unconfirmed","MD_MODEL","identity","version","NO_TYPES","types","selected","composition","path","selection","roots","some","root","governing","model","parsedAt","text","previous","retained","collection","documents","undefined","ok","document","parseCollection","Object","keys","sort","parsed","readCollection","validRoot","collectionRoot","kind","refusal","type","member","rule","file","startsWith","validateAgainst","binaryTargets","prefix","status","typed","entries","find","content","verdict","referrers","map","validateCollection","slice","length","hasOwn","fields","verdicts","filter","push","refusals"],"mappings":"AAAA,SACEA,KAAK,EACLC,QAAQ,EACRC,OAAO,QAKF,uBAAuB;AAC9B,SAASC,OAAO,EAAEC,SAAS,QAAQ,aAAa;AAGhD,SAASC,WAAW,QAAwC,gBAAgB;AAE5E,OAAO,MAAMC,WAA4B;IAAEC,UAAU;IAAwBC,SAASN;AAAQ,EAAE;AAEhG,MAAMO,WAA0B;IAAEC,OAAO,CAAC;AAAE;AAa5C,SAASC,SAASC,WAAwB,EAAEC,IAAY;IACtD,OACED,YAAYE,SAAS,KAAK,QAC1BF,YAAYE,SAAS,CAACC,KAAK,CAACC,IAAI,CAAC,CAACC,OAASd,QAAQc,MAAMJ;AAE7D;AAEA,OAAO,SAASK,UAAUN,WAAwB,EAAEC,IAAY;IAC9D,OAAOD,YAAYE,SAAS,KAAK,QAAQH,SAASC,aAAaC,QAC3DD,YAAYE,SAAS,CAACK,KAAK,GAC3BP,YAAYO,KAAK;AACvB;AAIA,SAASC,SACPC,IAAsC,EACtCR,IAAY,EACZS,QAA8B;IAE9B,MAAMC,WAAWD,UAAUE,WAAWC,SAAS,CAACZ,KAAK;IACrD,OAAOU,aAAaG,aAAaJ,UAAUD,IAAI,CAACR,KAAK,KAAKQ,IAAI,CAACR,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}
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,KAAK,OAAO,EAEZ,KAAK,aAAa,EAIlB,KAAK,aAAa,EAKlB,KAAK,eAAe,EAErB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAExB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAe,SAAS,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAc,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE1F,OAAO,EAA8B,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,KAAK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CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC;QACvE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC,CAAC;QAC/E,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC,CAAC;QACnE,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;QACpE,CACE,KAAK,EAAE,cAAc,EACrB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAC;KAC3C,CAAC;IACF,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,oBAAoB,GACpB,cAAc,GACd,aAAa,GACb,OAAO,GACP,OAAO,GACP,aAAa,GACb,cAAc,GACd,cAAc,CAAC;AAEnB,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,SAAS,CAAC;IACd,KAAK,CACH,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAClC,MAAM,IAAI,CAAC;CACf,CAAC;AAsBF,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAEpE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAmmEzE"}
|
package/dist/connection.js
CHANGED
|
@@ -12,7 +12,7 @@ import { MD_MODEL, validRoot } from './collection.js';
|
|
|
12
12
|
import { createLog } from './log.js';
|
|
13
13
|
import { refreshRoom } from './refresh.js';
|
|
14
14
|
import { buildBatch } from './save.js';
|
|
15
|
-
import { applyReturned, compositionOf, readConfirmed, replicaOf, withdrawals } from './replica.js';
|
|
15
|
+
import { applyReturned, compositionOf, landed, readConfirmed, replicaOf, withdrawals } from './replica.js';
|
|
16
16
|
import { changedParts, changesOf, held, readParts, returnedInto, underneath } from './room-draft.js';
|
|
17
17
|
import { settled, same, saving, STARTING, transferring } from './status.js';
|
|
18
18
|
import { detectStorageLoss, nextGeneration } from './durability.js';
|
|
@@ -67,6 +67,7 @@ export function composeRuntime(options) {
|
|
|
67
67
|
let roomsListed = false;
|
|
68
68
|
const scopedRefusals = new Map();
|
|
69
69
|
const sourceRefusals = new Map();
|
|
70
|
+
const declarationRefusals = new Set();
|
|
70
71
|
function modelKey(locator, attached) {
|
|
71
72
|
return `${attached} ${locator}`;
|
|
72
73
|
}
|
|
@@ -377,9 +378,14 @@ export function composeRuntime(options) {
|
|
|
377
378
|
model: revoked,
|
|
378
379
|
selectionModel: revoked
|
|
379
380
|
};
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
381
|
+
const read = readConfirmed(record, before.confirmed);
|
|
382
|
+
replicas.set(locator, read.kind === 'staged' ? replicaOf(read.confirmed, before.queue, rewriting(), before) : {
|
|
383
|
+
...before,
|
|
384
|
+
confirmed: {
|
|
385
|
+
...before.confirmed,
|
|
386
|
+
record
|
|
387
|
+
}
|
|
388
|
+
});
|
|
383
389
|
}
|
|
384
390
|
rooms.set(locator, {
|
|
385
391
|
...room,
|
|
@@ -477,6 +483,7 @@ export function composeRuntime(options) {
|
|
|
477
483
|
unreadable.delete(locator);
|
|
478
484
|
scopedRefusals.delete(locator);
|
|
479
485
|
sourceRefusals.delete(locator);
|
|
486
|
+
declarationRefusals.delete(locator);
|
|
480
487
|
for (const attached of [
|
|
481
488
|
'collection',
|
|
482
489
|
'typed-selection'
|
|
@@ -552,13 +559,13 @@ export function composeRuntime(options) {
|
|
|
552
559
|
const model = restored(modelKey(record.locator, 'collection'), record.model);
|
|
553
560
|
const selectionModel = restored(modelKey(record.locator, 'typed-selection'), record.selectionModel);
|
|
554
561
|
const prior = previousReplicas.get(record.locator);
|
|
555
|
-
const
|
|
562
|
+
const read = readConfirmed({
|
|
556
563
|
...record,
|
|
557
564
|
model,
|
|
558
565
|
selectionModel
|
|
559
566
|
}, prior?.confirmed);
|
|
560
|
-
if (
|
|
561
|
-
replicas.set(record.locator, replicaOf(confirmed, queuedBatches.get(record.locator) ?? [], rewriting(), prior));
|
|
567
|
+
if (read.kind !== 'staged') continue;
|
|
568
|
+
replicas.set(record.locator, replicaOf(read.confirmed, queuedBatches.get(record.locator) ?? [], rewriting(), prior));
|
|
562
569
|
const existing = rooms.get(record.locator);
|
|
563
570
|
if (existing === undefined) list(record, false);
|
|
564
571
|
else {
|
|
@@ -658,6 +665,7 @@ export function composeRuntime(options) {
|
|
|
658
665
|
];
|
|
659
666
|
const written = new Map();
|
|
660
667
|
for (const { batch, returned } of returning){
|
|
668
|
+
if (returned === null) continue;
|
|
661
669
|
for (const saved of pendings.get(batch.id)?.drafts ?? []){
|
|
662
670
|
const existing = written.get(saved.path) ?? roomDrafts.get(locator)?.get(saved.path);
|
|
663
671
|
written.set(saved.path, {
|
|
@@ -720,18 +728,16 @@ export function composeRuntime(options) {
|
|
|
720
728
|
model: modelOf(room.locator),
|
|
721
729
|
selectionModel: modelOf(room.locator, 'typed-selection')
|
|
722
730
|
}, prior?.confirmed);
|
|
723
|
-
if (retained
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
}));
|
|
728
|
-
return;
|
|
729
|
-
}
|
|
730
|
-
const set = await settle(local, room.locator, prior, retained, prior?.queue ?? [], {
|
|
731
|
+
if (retained.kind !== 'staged') throw new Error(`Cannot retype staged Room ${room.locator}`);
|
|
732
|
+
const queue = prior?.queue ?? [];
|
|
733
|
+
const accepted = queue.filter((batch)=>outcomes.get(batch.id)?.kind === 'accepted');
|
|
734
|
+
const set = await settle(local, room.locator, prior, retained.confirmed, queue.filter((batch)=>!accepted.includes(batch)), {
|
|
731
735
|
room: true
|
|
732
736
|
});
|
|
737
|
+
for (const batch of accepted)pendings.delete(batch.id);
|
|
733
738
|
unreadable.delete(room.locator);
|
|
734
739
|
sourceRefusals.delete(room.locator);
|
|
740
|
+
declarationRefusals.delete(room.locator);
|
|
735
741
|
list(room, true);
|
|
736
742
|
publishChangeSet(set);
|
|
737
743
|
moveTo({
|
|
@@ -987,7 +993,7 @@ export function composeRuntime(options) {
|
|
|
987
993
|
if (held !== undefined) {
|
|
988
994
|
const refreshed = await pullRefresh(authorized, held.confirmed);
|
|
989
995
|
if (refreshed.kind === 'still-current') {
|
|
990
|
-
sourceRefusals.
|
|
996
|
+
if (sourceRefusals.has(room.locator)) return unconfirmed;
|
|
991
997
|
if (unreadable.delete(room.locator)) {
|
|
992
998
|
list(room, true);
|
|
993
999
|
emitRooms();
|
|
@@ -1039,6 +1045,7 @@ export function composeRuntime(options) {
|
|
|
1039
1045
|
}
|
|
1040
1046
|
}
|
|
1041
1047
|
});
|
|
1048
|
+
declarationRefusals.delete(room.locator);
|
|
1042
1049
|
unreadable.add(room.locator);
|
|
1043
1050
|
list(room, false);
|
|
1044
1051
|
emitRooms();
|
|
@@ -1090,10 +1097,50 @@ export function composeRuntime(options) {
|
|
|
1090
1097
|
}
|
|
1091
1098
|
};
|
|
1092
1099
|
}
|
|
1100
|
+
function acceptedOf(accepted) {
|
|
1101
|
+
return {
|
|
1102
|
+
kind: 'accepted',
|
|
1103
|
+
roomVersion: accepted.roomVersion,
|
|
1104
|
+
...accepted.author === undefined ? {} : {
|
|
1105
|
+
author: accepted.author
|
|
1106
|
+
},
|
|
1107
|
+
...accepted.time === undefined ? {} : {
|
|
1108
|
+
time: accepted.time
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
function logAccepted(locator, submitted, accepted) {
|
|
1113
|
+
journal.record(`outcome ${locator} ${submitted.id} accepted ${accepted.roomVersion}` + (accepted.author === undefined ? '' : ` author ${accepted.author}`) + (accepted.time === undefined ? '' : ` time ${accepted.time}`));
|
|
1114
|
+
}
|
|
1115
|
+
async function holdAccepted(room, local, submitted, accepted, refused) {
|
|
1116
|
+
await exclusive(async ()=>{
|
|
1117
|
+
const current = replicas.get(room.locator);
|
|
1118
|
+
if (current === undefined || !current.queue.some((batch)=>batch.id === submitted.id)) {
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
const outcome = acceptedOf(accepted);
|
|
1122
|
+
await local.write({
|
|
1123
|
+
next: current.confirmed.record,
|
|
1124
|
+
previous: current.confirmed.record,
|
|
1125
|
+
queue: current.queue,
|
|
1126
|
+
previousQueue: current.queue,
|
|
1127
|
+
outcomes: [
|
|
1128
|
+
{
|
|
1129
|
+
id: submitted.id,
|
|
1130
|
+
outcome
|
|
1131
|
+
}
|
|
1132
|
+
]
|
|
1133
|
+
});
|
|
1134
|
+
outcomes.set(submitted.id, outcome);
|
|
1135
|
+
outcomeRooms.set(submitted.id, room.locator);
|
|
1136
|
+
logAccepted(room.locator, submitted, accepted);
|
|
1137
|
+
});
|
|
1138
|
+
if (refused !== null) refusedSource(room, refused);
|
|
1139
|
+
}
|
|
1093
1140
|
async function commitAccept(room, local, submitted, accepted, base, overlay) {
|
|
1094
1141
|
const current = replicas.get(room.locator);
|
|
1095
1142
|
if (current === undefined || !current.queue.some((batch)=>batch.id === submitted.id)) {
|
|
1096
|
-
return
|
|
1143
|
+
return null;
|
|
1097
1144
|
}
|
|
1098
1145
|
const remaining = current.queue.filter((batch)=>batch.id !== submitted.id);
|
|
1099
1146
|
const retainedBase = readConfirmed({
|
|
@@ -1101,47 +1148,42 @@ export function composeRuntime(options) {
|
|
|
1101
1148
|
model: modelOf(room.locator),
|
|
1102
1149
|
selectionModel: modelOf(room.locator, 'typed-selection')
|
|
1103
1150
|
}, base);
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
const returned = applyReturned(retainedBase, accepted.documents, accepted.revisions, accepted.removals, accepted.roomVersion);
|
|
1108
|
-
if (returned.kind === 'refused') refusedSource(room, returned);
|
|
1109
|
-
if (returned.kind !== 'staged') return false;
|
|
1110
|
-
applied = returned.confirmed;
|
|
1111
|
-
}
|
|
1112
|
-
const acceptedOutcome = {
|
|
1113
|
-
kind: 'accepted',
|
|
1114
|
-
roomVersion: accepted.roomVersion,
|
|
1115
|
-
...accepted.author === undefined ? {} : {
|
|
1116
|
-
author: accepted.author
|
|
1117
|
-
},
|
|
1118
|
-
...accepted.time === undefined ? {} : {
|
|
1119
|
-
time: accepted.time
|
|
1120
|
-
}
|
|
1121
|
-
};
|
|
1122
|
-
const set = await settle(local, room.locator, current, applied, remaining, {
|
|
1151
|
+
const applied = overlay && retainedBase.kind === 'staged' ? applyReturned(retainedBase.confirmed, accepted.documents, accepted.revisions, accepted.removals, accepted.roomVersion) : retainedBase;
|
|
1152
|
+
if (applied.kind !== 'staged') return applied;
|
|
1153
|
+
const set = await settle(local, room.locator, current, applied.confirmed, remaining, {
|
|
1123
1154
|
accepted: {
|
|
1124
1155
|
id: submitted.id,
|
|
1125
|
-
outcome:
|
|
1156
|
+
outcome: acceptedOf(accepted)
|
|
1126
1157
|
},
|
|
1127
1158
|
room: true
|
|
1128
1159
|
});
|
|
1129
1160
|
unreadable.delete(room.locator);
|
|
1130
1161
|
sourceRefusals.delete(room.locator);
|
|
1162
|
+
declarationRefusals.delete(room.locator);
|
|
1131
1163
|
list(room, true);
|
|
1132
1164
|
publishChangeSet(set);
|
|
1133
1165
|
moveTo({
|
|
1134
1166
|
...status,
|
|
1135
1167
|
...attention()
|
|
1136
1168
|
});
|
|
1137
|
-
|
|
1138
|
-
return
|
|
1169
|
+
logAccepted(room.locator, submitted, accepted);
|
|
1170
|
+
return null;
|
|
1171
|
+
}
|
|
1172
|
+
async function committed(room, local, submitted, accepted, base, overlay) {
|
|
1173
|
+
const failed = await exclusive(()=>commitAccept(room, local, submitted, accepted, base, overlay));
|
|
1174
|
+
if (failed === null) return true;
|
|
1175
|
+
await holdAccepted(room, local, submitted, accepted, failed.kind === 'refused' ? failed : null);
|
|
1176
|
+
return false;
|
|
1139
1177
|
}
|
|
1140
1178
|
async function submitRoom(room, local, authorized, progress) {
|
|
1141
1179
|
while(!closed && authorization !== undefined){
|
|
1142
1180
|
const replica = replicas.get(room.locator);
|
|
1143
1181
|
const head = replica?.queue[0];
|
|
1144
1182
|
if (replica === undefined || head === undefined) return null;
|
|
1183
|
+
if (outcomes.get(head.id)?.kind === 'accepted') {
|
|
1184
|
+
progress.complete = false;
|
|
1185
|
+
return null;
|
|
1186
|
+
}
|
|
1145
1187
|
const { submission, lost: earlier } = pendings.get(head.id) ?? {
|
|
1146
1188
|
submission: {
|
|
1147
1189
|
state: 'waiting'
|
|
@@ -1191,6 +1233,10 @@ export function composeRuntime(options) {
|
|
|
1191
1233
|
return null;
|
|
1192
1234
|
}
|
|
1193
1235
|
if (result.kind === 'conflicted' || result.kind === 'rejected' || result.kind === 'expired' || result.kind === 'retryable-refusal') {
|
|
1236
|
+
if (result.kind === 'expired') {
|
|
1237
|
+
const withheld = await advance(room, local, authorized);
|
|
1238
|
+
if (withheld !== null) return withhold(withheld, room, local, progress);
|
|
1239
|
+
}
|
|
1194
1240
|
journal.record(`outcome ${room.locator} ${head.id} ${result.kind}` + (result.kind === 'conflicted' && result.roomVersion !== undefined ? ` ${result.roomVersion}` : ''));
|
|
1195
1241
|
if (result.kind !== 'expired') journal.record(`refusal ${result.kind} ${result.code}`);
|
|
1196
1242
|
}
|
|
@@ -1213,7 +1259,10 @@ export function composeRuntime(options) {
|
|
|
1213
1259
|
return;
|
|
1214
1260
|
}
|
|
1215
1261
|
const set = await settle(local, room.locator, current, current.confirmed, current.queue.filter((batch)=>batch.id !== head.id), {
|
|
1216
|
-
leaving:
|
|
1262
|
+
leaving: result.kind === 'expired' && landed(head, current.confirmed) ? {
|
|
1263
|
+
...left,
|
|
1264
|
+
returned: null
|
|
1265
|
+
} : left
|
|
1217
1266
|
});
|
|
1218
1267
|
publishChangeSet(set);
|
|
1219
1268
|
moveTo({
|
|
@@ -1221,6 +1270,7 @@ export function composeRuntime(options) {
|
|
|
1221
1270
|
...attention()
|
|
1222
1271
|
});
|
|
1223
1272
|
});
|
|
1273
|
+
if (result.kind === 'expired') continue;
|
|
1224
1274
|
const withheld = await advance(room, local, authorized);
|
|
1225
1275
|
if (withheld !== null) return withhold(withheld, room, local, progress);
|
|
1226
1276
|
continue;
|
|
@@ -1238,8 +1288,7 @@ export function composeRuntime(options) {
|
|
|
1238
1288
|
return null;
|
|
1239
1289
|
}
|
|
1240
1290
|
if (pulled.kind === 'still-current') {
|
|
1241
|
-
|
|
1242
|
-
if (!committed) {
|
|
1291
|
+
if (!await committed(room, local, head, result, from, true)) {
|
|
1243
1292
|
progress.complete = false;
|
|
1244
1293
|
return null;
|
|
1245
1294
|
}
|
|
@@ -1247,8 +1296,7 @@ export function composeRuntime(options) {
|
|
|
1247
1296
|
}
|
|
1248
1297
|
if (pulled.kind === 'advanced') {
|
|
1249
1298
|
const overlay = pulled.confirmed.record.roomVersion === result.roomVersion;
|
|
1250
|
-
|
|
1251
|
-
if (!committed) {
|
|
1299
|
+
if (!await committed(room, local, head, result, pulled.confirmed, overlay)) {
|
|
1252
1300
|
progress.complete = false;
|
|
1253
1301
|
return null;
|
|
1254
1302
|
}
|
|
@@ -1267,8 +1315,7 @@ export function composeRuntime(options) {
|
|
|
1267
1315
|
}
|
|
1268
1316
|
if (bootstrapped.kind === 'staged') {
|
|
1269
1317
|
const overlay = bootstrapped.confirmed.record.roomVersion === result.roomVersion;
|
|
1270
|
-
|
|
1271
|
-
if (!committed) {
|
|
1318
|
+
if (!await committed(room, local, head, result, bootstrapped.confirmed, overlay)) {
|
|
1272
1319
|
progress.complete = false;
|
|
1273
1320
|
return null;
|
|
1274
1321
|
}
|
|
@@ -1282,7 +1329,7 @@ export function composeRuntime(options) {
|
|
|
1282
1329
|
list(room, false);
|
|
1283
1330
|
emitRooms();
|
|
1284
1331
|
} else if (bootstrapped.kind === 'refused') {
|
|
1285
|
-
|
|
1332
|
+
await holdAccepted(room, local, head, result, bootstrapped);
|
|
1286
1333
|
}
|
|
1287
1334
|
return null;
|
|
1288
1335
|
}
|
|
@@ -1294,7 +1341,7 @@ export function composeRuntime(options) {
|
|
|
1294
1341
|
list(room, false);
|
|
1295
1342
|
emitRooms();
|
|
1296
1343
|
} else if (pulled.kind === 'refused') {
|
|
1297
|
-
|
|
1344
|
+
await holdAccepted(room, local, head, result, pulled);
|
|
1298
1345
|
}
|
|
1299
1346
|
return null;
|
|
1300
1347
|
}
|
|
@@ -1332,9 +1379,23 @@ export function composeRuntime(options) {
|
|
|
1332
1379
|
previous: held.confirmed.record,
|
|
1333
1380
|
queue: held.queue
|
|
1334
1381
|
});
|
|
1335
|
-
const
|
|
1336
|
-
if (
|
|
1337
|
-
replicas.set(room.locator, replicaOf(confirmed, held.queue, rewriting(), held));
|
|
1382
|
+
const read = readConfirmed(record, held.confirmed);
|
|
1383
|
+
if (read.kind === 'staged') {
|
|
1384
|
+
replicas.set(room.locator, replicaOf(read.confirmed, held.queue, rewriting(), held));
|
|
1385
|
+
if (declarationRefusals.delete(room.locator)) {
|
|
1386
|
+
sourceRefusals.delete(room.locator);
|
|
1387
|
+
unreadable.delete(room.locator);
|
|
1388
|
+
}
|
|
1389
|
+
} else if (read.kind === 'refused') {
|
|
1390
|
+
replicas.set(room.locator, {
|
|
1391
|
+
...held,
|
|
1392
|
+
confirmed: {
|
|
1393
|
+
...held.confirmed,
|
|
1394
|
+
record
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
refusedSource(room, read);
|
|
1398
|
+
declarationRefusals.add(room.locator);
|
|
1338
1399
|
}
|
|
1339
1400
|
}
|
|
1340
1401
|
models.set(key, next);
|