@tinycloud/operations 0.2.1 → 0.3.0

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.
@@ -1,4 +1,4 @@
1
- import { I as InvocationTarget, a as OperationResult } from './contract-OnWT3OXa.cjs';
1
+ import { I as InvocationTarget, a as OperationResult } from './contract-xMIIMtpF.cjs';
2
2
 
3
3
  /**
4
4
  * The only published CLI acquisition helper. Its fixed operation identity is
@@ -1,4 +1,4 @@
1
- import { I as InvocationTarget, a as OperationResult } from './contract-OnWT3OXa.js';
1
+ import { I as InvocationTarget, a as OperationResult } from './contract-xMIIMtpF.js';
2
2
 
3
3
  /**
4
4
  * The only published CLI acquisition helper. Its fixed operation identity is
@@ -6752,6 +6752,7 @@ var init_authority = __esm({
6752
6752
 
6753
6753
  // src/state.ts
6754
6754
  import { randomUUID } from "crypto";
6755
+ import { AsyncLocalStorage } from "async_hooks";
6755
6756
  import {
6756
6757
  mkdir,
6757
6758
  readFile,
@@ -6761,11 +6762,18 @@ import {
6761
6762
  writeFile
6762
6763
  } from "fs/promises";
6763
6764
  import { homedir } from "os";
6764
- import { basename, dirname, join, relative, resolve } from "path";
6765
+ import { basename, dirname, isAbsolute, join, relative, resolve } from "path";
6765
6766
  function tinycloudHomePath() {
6766
- const home = process.env.TC_HOME ?? process.env.HOME ?? process.env.USERPROFILE ?? homedir();
6767
+ const home = invocationStateRoot.getStore() ?? process.env.TC_HOME ?? process.env.HOME ?? process.env.USERPROFILE ?? homedir();
6767
6768
  return join(home, ".tinycloud");
6768
6769
  }
6770
+ function withTinyCloudStateRoot(stateRoot, action) {
6771
+ if (stateRoot === void 0) return action();
6772
+ if (!isAbsolute(stateRoot) || stateRoot.includes("\0")) {
6773
+ throw new TypeError("The TinyCloud state root must be an absolute path.");
6774
+ }
6775
+ return invocationStateRoot.run(resolve(stateRoot), action);
6776
+ }
6769
6777
  function tinycloudConfigPath() {
6770
6778
  return join(tinycloudHomePath(), "config.json");
6771
6779
  }
@@ -7017,7 +7025,7 @@ function isErrno(error, code) {
7017
7025
  function sleep(milliseconds) {
7018
7026
  return new Promise((resolve2) => setTimeout(resolve2, milliseconds));
7019
7027
  }
7020
- var DEFAULT_PROFILE, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_LOCK_RETRY_MS, DEFAULT_STALE_LOCK_MS, TEST_LOCK_CONTENTION_SIGNAL_PATH, TEST_LOCK_RECOVERY_BARRIER_DIR, ProfileLockTimeoutError;
7028
+ var DEFAULT_PROFILE, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_LOCK_RETRY_MS, DEFAULT_STALE_LOCK_MS, TEST_LOCK_CONTENTION_SIGNAL_PATH, TEST_LOCK_RECOVERY_BARRIER_DIR, invocationStateRoot, ProfileLockTimeoutError;
7021
7029
  var init_state = __esm({
7022
7030
  "src/state.ts"() {
7023
7031
  "use strict";
@@ -7027,6 +7035,7 @@ var init_state = __esm({
7027
7035
  DEFAULT_STALE_LOCK_MS = 3e4;
7028
7036
  TEST_LOCK_CONTENTION_SIGNAL_PATH = "TC_TEST_PROFILE_LOCK_CONTENTION_SIGNAL_PATH";
7029
7037
  TEST_LOCK_RECOVERY_BARRIER_DIR = "TC_TEST_PROFILE_LOCK_RECOVERY_BARRIER_DIR";
7038
+ invocationStateRoot = new AsyncLocalStorage();
7030
7039
  ProfileLockTimeoutError = class extends Error {
7031
7040
  constructor(profile, timeoutMs) {
7032
7041
  super(`Timed out waiting for the profile lock for "${profile}" after ${timeoutMs}ms.`);
@@ -9910,6 +9919,7 @@ var init_runtime = __esm({
9910
9919
 
9911
9920
  // src/invoke.ts
9912
9921
  import { createHash } from "crypto";
9922
+ import { isAbsolute as isAbsolute2 } from "path";
9913
9923
  import {
9914
9924
  makePkhSpaceId as makePkhSpaceId3,
9915
9925
  parsePkhDid as parsePkhDid3,
@@ -10253,6 +10263,7 @@ function isRecord(value) {
10253
10263
  }
10254
10264
 
10255
10265
  // src/invoke.ts
10266
+ init_state();
10256
10267
  init_secrets();
10257
10268
  async function invokeOperationWithLocalAuthorityRetry(operationId, operationVersion, invocationTarget, unknownInput) {
10258
10269
  const target = normalizeInvocationTarget(invocationTarget);
@@ -10273,6 +10284,17 @@ async function invokeOperationWithLocalAuthorityRetry(operationId, operationVers
10273
10284
  )
10274
10285
  );
10275
10286
  }
10287
+ return withTinyCloudStateRoot(
10288
+ target.stateRoot,
10289
+ () => invokeLocalAuthorityRetry(
10290
+ operationId,
10291
+ operationVersion,
10292
+ target,
10293
+ unknownInput
10294
+ )
10295
+ );
10296
+ }
10297
+ async function invokeLocalAuthorityRetry(operationId, operationVersion, target, unknownInput) {
10276
10298
  const prepared = await prepareInvocation(
10277
10299
  operationId,
10278
10300
  operationVersion,
@@ -10719,14 +10741,16 @@ function normalizeInvocationTarget(target) {
10719
10741
  const candidate = target;
10720
10742
  const profile = candidate.profile;
10721
10743
  const host = candidate.host;
10744
+ const stateRoot = candidate.stateRoot;
10722
10745
  const allowOwnerProfile = candidate.allowOwnerProfile;
10723
10746
  const privateKey = candidate.privateKey;
10724
- if (profile !== void 0 && typeof profile !== "string" || host !== void 0 && typeof host !== "string" || allowOwnerProfile !== void 0 && typeof allowOwnerProfile !== "boolean" || privateKey !== void 0 && typeof privateKey !== "string") {
10747
+ if (profile !== void 0 && typeof profile !== "string" || host !== void 0 && typeof host !== "string" || stateRoot !== void 0 && (typeof stateRoot !== "string" || !isAbsolute2(stateRoot)) || allowOwnerProfile !== void 0 && typeof allowOwnerProfile !== "boolean" || privateKey !== void 0 && typeof privateKey !== "string") {
10725
10748
  return void 0;
10726
10749
  }
10727
10750
  return {
10728
10751
  ...profile === void 0 ? {} : { profile },
10729
10752
  ...host === void 0 ? {} : { host },
10753
+ ...stateRoot === void 0 ? {} : { stateRoot },
10730
10754
  ...allowOwnerProfile === true ? { allowOwnerProfile: true } : {},
10731
10755
  ...privateKey === void 0 ? {} : { privateKey }
10732
10756
  };