@tinycloud/operations 0.4.0-beta.12 → 0.4.0-beta.14
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/coverage.json +6 -0
- package/dist/artifacts.cjs +19 -4
- package/dist/artifacts.cjs.map +1 -1
- package/dist/artifacts.js +19 -4
- package/dist/artifacts.js.map +1 -1
- package/dist/cli-runtime.cjs +20 -4
- package/dist/cli-runtime.cjs.map +1 -1
- package/dist/cli-runtime.js +20 -4
- package/dist/cli-runtime.js.map +1 -1
- package/dist/delegation-binding.cjs +19 -4
- package/dist/delegation-binding.cjs.map +1 -1
- package/dist/delegation-binding.js +19 -4
- package/dist/delegation-binding.js.map +1 -1
- package/dist/index.cjs +20 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/profile.cjs.map +1 -1
- package/dist/profile.js.map +1 -1
- package/dist/state.cjs +9 -3
- package/dist/state.cjs.map +1 -1
- package/dist/state.d.cts +7 -0
- package/dist/state.d.ts +7 -0
- package/dist/state.js +9 -3
- package/dist/state.js.map +1 -1
- package/package.json +4 -4
|
@@ -278,8 +278,17 @@ function canonicalizeRecapCaveats(caveats) {
|
|
|
278
278
|
}
|
|
279
279
|
return `[${branches.join(",")}]`;
|
|
280
280
|
}
|
|
281
|
+
var EXPLICIT_ONLY_ACTIONS = {
|
|
282
|
+
"tinycloud.kv/sync": true,
|
|
283
|
+
"tinycloud.kv/retain": true
|
|
284
|
+
};
|
|
285
|
+
function isExplicitOnlyAction(action) {
|
|
286
|
+
return Object.prototype.hasOwnProperty.call(EXPLICIT_ONLY_ACTIONS, action);
|
|
287
|
+
}
|
|
281
288
|
function actionContains(grantedAction, requestedAction) {
|
|
282
|
-
if (grantedAction ===
|
|
289
|
+
if (grantedAction === requestedAction) return true;
|
|
290
|
+
if (isExplicitOnlyAction(requestedAction)) return false;
|
|
291
|
+
if (grantedAction === "*") return true;
|
|
283
292
|
if (!grantedAction.endsWith("/*")) return false;
|
|
284
293
|
const service = grantedAction.slice(0, -2);
|
|
285
294
|
return requestedAction === service || requestedAction.startsWith(`${service}/`);
|
|
@@ -581,7 +590,8 @@ async function acquireProfileLock(profile, options) {
|
|
|
581
590
|
const lockPath = profileLockPath(profile);
|
|
582
591
|
const turnDirectory = profileTurnLockPath(profile);
|
|
583
592
|
const directory = profilePath(profile);
|
|
584
|
-
|
|
593
|
+
if (options.requireProfile && !await exists(profileConfigPath(profile))) throw new ProfileDeletedError(profile);
|
|
594
|
+
if (!options.requireProfile) await (0, import_promises.mkdir)(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
|
|
585
595
|
await (0, import_promises.mkdir)((0, import_node_path.dirname)(turnDirectory), { recursive: true, mode: PRIVATE_DIR_MODE });
|
|
586
596
|
for (const path of [tinycloudHomePath(), profilesPath(), directory]) {
|
|
587
597
|
await (0, import_promises.chmod)(path, PRIVATE_DIR_MODE).catch((error) => {
|
|
@@ -590,11 +600,15 @@ async function acquireProfileLock(profile, options) {
|
|
|
590
600
|
}
|
|
591
601
|
const { turn, firstWaitedTurn } = await acquireTurn(profile, turnDirectory, deadline);
|
|
592
602
|
try {
|
|
603
|
+
if (options.requireProfile && !await exists(profileConfigPath(profile))) {
|
|
604
|
+
await (0, import_promises.rmdir)(directory).catch(() => void 0);
|
|
605
|
+
throw new ProfileDeletedError(profile);
|
|
606
|
+
}
|
|
593
607
|
const deletion = await readJson((0, import_node_path.join)(turnDirectory, "deleted.json")).catch(() => null);
|
|
594
608
|
const deletedWhileWaiting = typeof deletion?.slot === "number" && deletion.slot >= firstWaitedTurn;
|
|
595
609
|
while (true) {
|
|
596
610
|
const token = (0, import_node_crypto.randomUUID)();
|
|
597
|
-
if (await publishProfileLock(profile, lockPath, token)) {
|
|
611
|
+
if (await publishProfileLock(profile, lockPath, token, options.requireProfile === true)) {
|
|
598
612
|
return {
|
|
599
613
|
deletedWhileWaiting,
|
|
600
614
|
turnSlot: turn.slot,
|
|
@@ -845,12 +859,13 @@ async function collectTurns(profile, turn) {
|
|
|
845
859
|
}
|
|
846
860
|
}
|
|
847
861
|
}
|
|
848
|
-
async function publishProfileLock(profile, lockPath, token) {
|
|
862
|
+
async function publishProfileLock(profile, lockPath, token, requireProfile) {
|
|
849
863
|
try {
|
|
850
864
|
await (0, import_promises.mkdir)(lockPath, { mode: PRIVATE_DIR_MODE });
|
|
851
865
|
} catch (error) {
|
|
852
866
|
if (isErrno(error, "EEXIST")) return false;
|
|
853
867
|
if (!isErrno(error, "ENOENT")) throw error;
|
|
868
|
+
if (requireProfile) throw new ProfileDeletedError(profile);
|
|
854
869
|
await (0, import_promises.mkdir)(profilePath(profile), { recursive: true, mode: PRIVATE_DIR_MODE });
|
|
855
870
|
return false;
|
|
856
871
|
}
|