superbee 0.1.4 → 0.1.5-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -14
- package/dist/publication-bridge.mjs +148 -40
- package/dist/publication.mjs +182 -45
- package/dist/superbee.mjs +27640 -25020
- package/package.json +6 -4
package/dist/publication.mjs
CHANGED
|
@@ -1157,7 +1157,7 @@ var require_omap = __commonJS({
|
|
|
1157
1157
|
var _toString = Object.prototype.toString;
|
|
1158
1158
|
function resolveYamlOmap(data) {
|
|
1159
1159
|
if (data === null) return true;
|
|
1160
|
-
var objectKeys =
|
|
1160
|
+
var objectKeys = {}, index2, length, pair, pairKey, pairHasKey, object = data;
|
|
1161
1161
|
for (index2 = 0, length = object.length; index2 < length; index2 += 1) {
|
|
1162
1162
|
pair = object[index2];
|
|
1163
1163
|
pairHasKey = false;
|
|
@@ -1169,8 +1169,8 @@ var require_omap = __commonJS({
|
|
|
1169
1169
|
}
|
|
1170
1170
|
}
|
|
1171
1171
|
if (!pairHasKey) return false;
|
|
1172
|
-
if (
|
|
1173
|
-
|
|
1172
|
+
if (_hasOwnProperty.call(objectKeys, pairKey)) return false;
|
|
1173
|
+
Object.defineProperty(objectKeys, pairKey, { value: true });
|
|
1174
1174
|
}
|
|
1175
1175
|
return true;
|
|
1176
1176
|
}
|
|
@@ -1607,17 +1607,22 @@ var require_loader = __commonJS({
|
|
|
1607
1607
|
state.result += _result;
|
|
1608
1608
|
}
|
|
1609
1609
|
}
|
|
1610
|
+
function chargeMergeWork(state) {
|
|
1611
|
+
state.totalMergeKeys += 1;
|
|
1612
|
+
if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys) {
|
|
1613
|
+
throwError(state, "merge keys exceeded maxTotalMergeKeys (" + state.maxTotalMergeKeys + ")");
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1610
1616
|
function mergeMappings(state, destination, source, overridableKeys) {
|
|
1611
1617
|
var sourceKeys, key, index2, quantity;
|
|
1612
1618
|
if (!common.isObject(source)) {
|
|
1613
1619
|
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1614
1620
|
}
|
|
1621
|
+
chargeMergeWork(state);
|
|
1615
1622
|
sourceKeys = Object.keys(source);
|
|
1616
1623
|
for (index2 = 0, quantity = sourceKeys.length; index2 < quantity; index2 += 1) {
|
|
1617
1624
|
key = sourceKeys[index2];
|
|
1618
|
-
|
|
1619
|
-
throwError(state, "merge keys exceeded maxTotalMergeKeys (" + state.maxTotalMergeKeys + ")");
|
|
1620
|
-
}
|
|
1625
|
+
chargeMergeWork(state);
|
|
1621
1626
|
if (!_hasOwnProperty.call(destination, key)) {
|
|
1622
1627
|
setProperty(destination, key, source[key]);
|
|
1623
1628
|
overridableKeys[key] = true;
|
|
@@ -1646,6 +1651,9 @@ var require_loader = __commonJS({
|
|
|
1646
1651
|
}
|
|
1647
1652
|
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1648
1653
|
if (Array.isArray(valueNode)) {
|
|
1654
|
+
if (valueNode.length > 100) {
|
|
1655
|
+
throwError(state, "abnormal merge sequence size");
|
|
1656
|
+
}
|
|
1649
1657
|
for (index2 = 0, quantity = valueNode.length; index2 < quantity; index2 += 1) {
|
|
1650
1658
|
mergeMappings(state, _result, valueNode[index2], overridableKeys);
|
|
1651
1659
|
}
|
|
@@ -31536,6 +31544,13 @@ var MalformedDocumentError = class extends Error {
|
|
|
31536
31544
|
}
|
|
31537
31545
|
};
|
|
31538
31546
|
function parseMarkdown(raw, context) {
|
|
31547
|
+
if (/^---(?:\r?\n|$)/.test(raw)) {
|
|
31548
|
+
const firstLineEnd = raw.indexOf("\n");
|
|
31549
|
+
const afterOpening = firstLineEnd === -1 ? "" : raw.slice(firstLineEnd + 1);
|
|
31550
|
+
if (!/^---\r?$/m.test(afterOpening)) {
|
|
31551
|
+
throw new MalformedDocumentError(context, new Error("unterminated YAML frontmatter delimiter"));
|
|
31552
|
+
}
|
|
31553
|
+
}
|
|
31539
31554
|
let parsed;
|
|
31540
31555
|
try {
|
|
31541
31556
|
parsed = (0, import_gray_matter.default)(raw, { engines: { yaml: yamlEngine } });
|
|
@@ -31545,16 +31560,20 @@ function parseMarkdown(raw, context) {
|
|
|
31545
31560
|
const frontmatter2 = normalizeFrontmatter(parsed.data ?? {});
|
|
31546
31561
|
return { frontmatter: frontmatter2, body: parsed.content };
|
|
31547
31562
|
}
|
|
31563
|
+
function normalizeDocumentBodyForStorage(body) {
|
|
31564
|
+
return body.endsWith("\n") ? body : `${body}
|
|
31565
|
+
`;
|
|
31566
|
+
}
|
|
31548
31567
|
function stringifyWithData(data, body) {
|
|
31549
31568
|
const engines2 = import_gray_matter.default.engines;
|
|
31550
31569
|
const yaml3 = engines2.yaml.stringify(data).trim();
|
|
31551
31570
|
const content3 = body ?? "";
|
|
31552
31571
|
const newline = (value) => value.endsWith("\n") ? value : `${value}
|
|
31553
31572
|
`;
|
|
31554
|
-
if (yaml3 === "{}") return
|
|
31573
|
+
if (yaml3 === "{}") return normalizeDocumentBodyForStorage(content3);
|
|
31555
31574
|
return `---
|
|
31556
31575
|
${newline(yaml3)}---
|
|
31557
|
-
${
|
|
31576
|
+
${normalizeDocumentBodyForStorage(content3)}`;
|
|
31558
31577
|
}
|
|
31559
31578
|
function stringifyDoc(frontmatter2, body) {
|
|
31560
31579
|
return stringifyWithData(frontmatter2, body);
|
|
@@ -31839,6 +31858,33 @@ function processExists(pid) {
|
|
|
31839
31858
|
return err.code !== "ESRCH";
|
|
31840
31859
|
}
|
|
31841
31860
|
}
|
|
31861
|
+
function staleLockQuarantinePath(lockPath, owner) {
|
|
31862
|
+
const tokenHash = createHash("sha256").update(owner.token).digest("hex");
|
|
31863
|
+
return `${lockPath}.stale-${tokenHash}`;
|
|
31864
|
+
}
|
|
31865
|
+
async function pathExists(candidate) {
|
|
31866
|
+
try {
|
|
31867
|
+
await fs.lstat(candidate);
|
|
31868
|
+
return true;
|
|
31869
|
+
} catch (err) {
|
|
31870
|
+
if (err.code === "ENOENT") return false;
|
|
31871
|
+
throw err;
|
|
31872
|
+
}
|
|
31873
|
+
}
|
|
31874
|
+
async function quarantineStaleLock(lockPath, owner) {
|
|
31875
|
+
if (owner.hostname !== hostname() || processExists(owner.pid)) return false;
|
|
31876
|
+
const quarantinePath = staleLockQuarantinePath(lockPath, owner);
|
|
31877
|
+
try {
|
|
31878
|
+
await fs.rename(lockPath, quarantinePath);
|
|
31879
|
+
return true;
|
|
31880
|
+
} catch (err) {
|
|
31881
|
+
const code2 = err.code;
|
|
31882
|
+
if (code2 === "ENOENT") return false;
|
|
31883
|
+
if (await pathExists(quarantinePath)) return false;
|
|
31884
|
+
if (process.platform === "win32" && WINDOWS_DIRECTORY_CONTENTION_CODES.has(code2 ?? "")) return false;
|
|
31885
|
+
throw err;
|
|
31886
|
+
}
|
|
31887
|
+
}
|
|
31842
31888
|
function delay(ms) {
|
|
31843
31889
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
31844
31890
|
}
|
|
@@ -31901,46 +31947,74 @@ async function selectLockRoot(options2) {
|
|
|
31901
31947
|
await ensurePrivateLockRoot(lockRoot);
|
|
31902
31948
|
return lockRoot;
|
|
31903
31949
|
}
|
|
31950
|
+
var WINDOWS_DIRECTORY_CONTENTION_CODES = /* @__PURE__ */ new Set(["EACCES", "EBUSY", "EPERM"]);
|
|
31951
|
+
async function classifyLockClaimFailure(error, lockPath) {
|
|
31952
|
+
const code2 = error.code;
|
|
31953
|
+
if (code2 === "EEXIST") return "contention";
|
|
31954
|
+
if (process.platform !== "win32" || !WINDOWS_DIRECTORY_CONTENTION_CODES.has(code2 ?? "")) return "terminal";
|
|
31955
|
+
try {
|
|
31956
|
+
await fs.lstat(lockPath);
|
|
31957
|
+
return "contention";
|
|
31958
|
+
} catch (probeError) {
|
|
31959
|
+
const probeCode = probeError.code;
|
|
31960
|
+
return probeCode === "ENOENT" || probeCode === "ENOTDIR" ? "unwitnessed-windows-sharing-error" : "terminal";
|
|
31961
|
+
}
|
|
31962
|
+
}
|
|
31904
31963
|
async function claimLockPath(lockPath, owner, waitMs, pollMs) {
|
|
31905
31964
|
const started = owner.created_at_ms;
|
|
31965
|
+
let unwitnessedWindowsRetryUsed = false;
|
|
31906
31966
|
while (true) {
|
|
31907
31967
|
try {
|
|
31908
31968
|
await fs.mkdir(lockPath, { mode: 448 });
|
|
31909
|
-
|
|
31910
|
-
|
|
31969
|
+
} catch (err) {
|
|
31970
|
+
const failure = await classifyLockClaimFailure(err, lockPath);
|
|
31971
|
+
if (failure === "terminal") throw err;
|
|
31972
|
+
if (failure === "unwitnessed-windows-sharing-error") {
|
|
31973
|
+
if (unwitnessedWindowsRetryUsed) throw err;
|
|
31974
|
+
unwitnessedWindowsRetryUsed = true;
|
|
31975
|
+
continue;
|
|
31976
|
+
} else {
|
|
31977
|
+
unwitnessedWindowsRetryUsed = false;
|
|
31978
|
+
}
|
|
31979
|
+
let existingOwner = await readOwner(lockPath);
|
|
31980
|
+
if (existingOwner !== null) {
|
|
31981
|
+
if (await quarantineStaleLock(lockPath, existingOwner)) continue;
|
|
31982
|
+
existingOwner = await readOwner(lockPath);
|
|
31983
|
+
}
|
|
31984
|
+
if (Date.now() - started >= waitMs) throw timeoutError(lockPath, existingOwner, owner.target);
|
|
31985
|
+
await delay(pollMs);
|
|
31986
|
+
continue;
|
|
31987
|
+
}
|
|
31988
|
+
try {
|
|
31989
|
+
await fs.writeFile(path.join(lockPath, OWNER_FILE), `${JSON.stringify(owner)}
|
|
31911
31990
|
`, {
|
|
31912
|
-
|
|
31913
|
-
|
|
31914
|
-
|
|
31915
|
-
|
|
31916
|
-
} catch (err) {
|
|
31917
|
-
await fs.rm(lockPath, { recursive: true, force: true }).catch(() => {
|
|
31918
|
-
});
|
|
31919
|
-
throw err;
|
|
31920
|
-
}
|
|
31921
|
-
return async () => {
|
|
31922
|
-
const current = await readOwner(lockPath);
|
|
31923
|
-
if (current?.token !== owner.token) {
|
|
31924
|
-
throw new FilesystemMutationLockError(
|
|
31925
|
-
`refusing to release filesystem mutation lock '${lockPath}' because its owner token changed; the mutation may have completed, inspect the lock before retrying.`,
|
|
31926
|
-
{ lockPath, owner: current, stale: false, malformed: current === null }
|
|
31927
|
-
);
|
|
31928
|
-
}
|
|
31929
|
-
try {
|
|
31930
|
-
await fs.rm(lockPath, { recursive: true, force: false });
|
|
31931
|
-
} catch (err) {
|
|
31932
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
31933
|
-
throw new FilesystemMutationLockError(
|
|
31934
|
-
`mutation completed but filesystem lock '${lockPath}' could not be removed (${message}); inspect the lock before retrying.`,
|
|
31935
|
-
{ lockPath, owner: current, stale: false, malformed: false }
|
|
31936
|
-
);
|
|
31937
|
-
}
|
|
31938
|
-
};
|
|
31991
|
+
encoding: "utf8",
|
|
31992
|
+
flag: "wx",
|
|
31993
|
+
mode: 384
|
|
31994
|
+
});
|
|
31939
31995
|
} catch (err) {
|
|
31940
|
-
|
|
31996
|
+
await fs.rm(lockPath, { recursive: true, force: true }).catch(() => {
|
|
31997
|
+
});
|
|
31998
|
+
throw err;
|
|
31941
31999
|
}
|
|
31942
|
-
|
|
31943
|
-
|
|
32000
|
+
return async () => {
|
|
32001
|
+
const current = await readOwner(lockPath);
|
|
32002
|
+
if (current?.token !== owner.token) {
|
|
32003
|
+
throw new FilesystemMutationLockError(
|
|
32004
|
+
`refusing to release filesystem mutation lock '${lockPath}' because its owner token changed; the mutation may have completed, inspect the lock before retrying.`,
|
|
32005
|
+
{ lockPath, owner: current, stale: false, malformed: current === null }
|
|
32006
|
+
);
|
|
32007
|
+
}
|
|
32008
|
+
try {
|
|
32009
|
+
await fs.rm(lockPath, { recursive: true, force: false });
|
|
32010
|
+
} catch (err) {
|
|
32011
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
32012
|
+
throw new FilesystemMutationLockError(
|
|
32013
|
+
`mutation completed but filesystem lock '${lockPath}' could not be removed (${message}); inspect the lock before retrying.`,
|
|
32014
|
+
{ lockPath, owner: current, stale: false, malformed: false }
|
|
32015
|
+
);
|
|
32016
|
+
}
|
|
32017
|
+
};
|
|
31944
32018
|
}
|
|
31945
32019
|
}
|
|
31946
32020
|
function newOwner(target) {
|
|
@@ -33027,6 +33101,10 @@ var VALID_FIELDS_KEYS = /* @__PURE__ */ new Set([
|
|
|
33027
33101
|
"descriptions"
|
|
33028
33102
|
]);
|
|
33029
33103
|
var MISPLACED_TOP_LEVEL_KEYS = /* @__PURE__ */ new Set(["enum", "enums", "values", "constraints"]);
|
|
33104
|
+
var CLAIM_COORDINATE_KEYS = [
|
|
33105
|
+
["owner_field", "ownerField"],
|
|
33106
|
+
["state_field", "stateField"]
|
|
33107
|
+
];
|
|
33030
33108
|
function parseConventionDoc(doc) {
|
|
33031
33109
|
const fm = doc.frontmatter;
|
|
33032
33110
|
const governs = typeof fm.governs === "string" ? fm.governs.trim() : "";
|
|
@@ -33335,6 +33413,35 @@ function parseConventionDoc(doc) {
|
|
|
33335
33413
|
if (Object.keys(parsed).length > 0) expectsInbound = parsed;
|
|
33336
33414
|
}
|
|
33337
33415
|
}
|
|
33416
|
+
const claimSource = fm.claim;
|
|
33417
|
+
let claim;
|
|
33418
|
+
if (claimSource !== void 0) {
|
|
33419
|
+
if (!isPlainObject(claimSource)) {
|
|
33420
|
+
warnings.push({
|
|
33421
|
+
code: "KIND_CONVENTION_BAD_SHAPE",
|
|
33422
|
+
message: `kind convention '${doc.id}' has a non-map 'claim' key (${describeShape(claimSource)}; expected a map declaring 'owner_field' and/or 'state_field'); ignoring it.`,
|
|
33423
|
+
field: "claim",
|
|
33424
|
+
severity: "warning"
|
|
33425
|
+
});
|
|
33426
|
+
} else {
|
|
33427
|
+
const parsed = {};
|
|
33428
|
+
for (const [key, target] of CLAIM_COORDINATE_KEYS) {
|
|
33429
|
+
const declared = claimSource[key];
|
|
33430
|
+
if (declared === void 0) continue;
|
|
33431
|
+
if (!isScalar(declared) || String(declared).trim() === "") {
|
|
33432
|
+
warnings.push({
|
|
33433
|
+
code: "KIND_CONVENTION_BAD_MEMBER",
|
|
33434
|
+
message: `kind convention '${doc.id}' has a malformed 'claim.${key}' (${describeShape(declared)}; expected a declared field name); skipping it.`,
|
|
33435
|
+
field: `claim.${key}`,
|
|
33436
|
+
severity: "warning"
|
|
33437
|
+
});
|
|
33438
|
+
continue;
|
|
33439
|
+
}
|
|
33440
|
+
parsed[target] = String(declared).trim();
|
|
33441
|
+
}
|
|
33442
|
+
if (parsed.ownerField !== void 0 || parsed.stateField !== void 0) claim = parsed;
|
|
33443
|
+
}
|
|
33444
|
+
}
|
|
33338
33445
|
const sections = Array.isArray(fm.sections) ? fm.sections.filter((s) => typeof s === "string" && s.trim() !== "") : void 0;
|
|
33339
33446
|
const title = typeof fm.title === "string" && fm.title.trim() !== "" ? fm.title.trim() : governs;
|
|
33340
33447
|
let description;
|
|
@@ -33367,6 +33474,7 @@ function parseConventionDoc(doc) {
|
|
|
33367
33474
|
if (sections && sections.length > 0) kind.sections = sections;
|
|
33368
33475
|
if (freshnessHorizon !== void 0) kind.freshnessHorizon = freshnessHorizon;
|
|
33369
33476
|
if (browseCollapsed !== void 0) kind.browseCollapsed = browseCollapsed;
|
|
33477
|
+
if (claim !== void 0) kind.claim = claim;
|
|
33370
33478
|
return {
|
|
33371
33479
|
ok: true,
|
|
33372
33480
|
kind,
|
|
@@ -43191,18 +43299,37 @@ async function authorizePublicationRoot(requested) {
|
|
|
43191
43299
|
}
|
|
43192
43300
|
async function assertPublicationRoot(identity) {
|
|
43193
43301
|
let entry;
|
|
43302
|
+
try {
|
|
43303
|
+
entry = await lstat(identity.requested);
|
|
43304
|
+
} catch (error) {
|
|
43305
|
+
const code2 = error.code;
|
|
43306
|
+
if (code2 === "ENOENT" || code2 === "ENOTDIR") {
|
|
43307
|
+
throw new PublicationError("SOURCE_CHANGED", "the publication source identity became unavailable during capture", { retryable: true, cause: error });
|
|
43308
|
+
}
|
|
43309
|
+
throw new PublicationError("IO_ERROR", "the publication source identity could not be read during capture", { cause: error });
|
|
43310
|
+
}
|
|
43311
|
+
if (entry.isSymbolicLink() || !entry.isDirectory()) {
|
|
43312
|
+
throw new PublicationError("SOURCE_CHANGED", "the publication source root changed during capture", {
|
|
43313
|
+
retryable: true,
|
|
43314
|
+
expected: { canonical: identity.canonical, dev: identity.dev, ino: identity.ino },
|
|
43315
|
+
actual: { symlink: entry.isSymbolicLink(), directory: entry.isDirectory() }
|
|
43316
|
+
});
|
|
43317
|
+
}
|
|
43194
43318
|
let canonical2;
|
|
43195
43319
|
let current;
|
|
43196
43320
|
try {
|
|
43197
|
-
[
|
|
43198
|
-
lstat(identity.requested),
|
|
43321
|
+
[canonical2, current] = await Promise.all([
|
|
43199
43322
|
realpath(identity.requested),
|
|
43200
43323
|
stat(identity.requested)
|
|
43201
43324
|
]);
|
|
43202
43325
|
} catch (error) {
|
|
43203
|
-
|
|
43326
|
+
const code2 = error.code;
|
|
43327
|
+
if (code2 === "ENOENT" || code2 === "ENOTDIR") {
|
|
43328
|
+
throw new PublicationError("SOURCE_CHANGED", "the publication source identity became unavailable during capture", { retryable: true, cause: error });
|
|
43329
|
+
}
|
|
43330
|
+
throw new PublicationError("IO_ERROR", "the publication source identity could not be read during capture", { cause: error });
|
|
43204
43331
|
}
|
|
43205
|
-
if (
|
|
43332
|
+
if (!current.isDirectory() || canonical2 !== identity.canonical || current.dev !== identity.dev || current.ino !== identity.ino) {
|
|
43206
43333
|
throw new PublicationError("SOURCE_CHANGED", "the publication source root changed during capture", {
|
|
43207
43334
|
retryable: true,
|
|
43208
43335
|
expected: { canonical: identity.canonical, dev: identity.dev, ino: identity.ino },
|
|
@@ -43378,6 +43505,16 @@ function mapCaptureError(error) {
|
|
|
43378
43505
|
}
|
|
43379
43506
|
return new PublicationError("INVALID_BUNDLE", error instanceof Error ? error.message : "the bundle is invalid", { cause: error });
|
|
43380
43507
|
}
|
|
43508
|
+
async function classifyCaptureError(error, rootIdentity) {
|
|
43509
|
+
const mapped = mapCaptureError(error);
|
|
43510
|
+
if (mapped.code !== "IO_ERROR") return mapped;
|
|
43511
|
+
try {
|
|
43512
|
+
await assertPublicationRoot(rootIdentity);
|
|
43513
|
+
} catch (rootError) {
|
|
43514
|
+
if (rootError instanceof PublicationError && rootError.code === "SOURCE_CHANGED") return rootError;
|
|
43515
|
+
}
|
|
43516
|
+
return mapped;
|
|
43517
|
+
}
|
|
43381
43518
|
function addObject(objects, bytes, mediaType, representation) {
|
|
43382
43519
|
const digest2 = sha256(bytes);
|
|
43383
43520
|
if (!objects.has(digest2)) objects.set(digest2, bytes.slice());
|
|
@@ -43577,7 +43714,7 @@ async function capturePublicationSnapshot(options2) {
|
|
|
43577
43714
|
}
|
|
43578
43715
|
return handle;
|
|
43579
43716
|
} catch (error) {
|
|
43580
|
-
lastError =
|
|
43717
|
+
lastError = await classifyCaptureError(error, rootIdentity);
|
|
43581
43718
|
if (!lastError.retryable || attempt === maxAttempts) throw lastError;
|
|
43582
43719
|
}
|
|
43583
43720
|
}
|