@aigne/afs-workspace 1.11.0-beta.7

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/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ # Proprietary License
2
+
3
+ Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
4
+
5
+ This software and associated documentation files (the "Software") are proprietary
6
+ and confidential. Unauthorized copying, modification, distribution, or use of
7
+ this Software, via any medium, is strictly prohibited.
8
+
9
+ The Software is provided for internal use only within ArcBlock, Inc. and its
10
+ authorized affiliates.
11
+
12
+ ## No License Granted
13
+
14
+ No license, express or implied, is granted to any party for any purpose.
15
+ All rights are reserved by ArcBlock, Inc.
16
+
17
+ ## Public Artifact Distribution
18
+
19
+ Portions of this Software may be released publicly under separate open-source
20
+ licenses (such as MIT License) through designated public repositories. Such
21
+ public releases are governed by their respective licenses and do not affect
22
+ the proprietary nature of this repository.
23
+
24
+ ## Contact
25
+
26
+ For licensing inquiries, contact: legal@arcblock.io
@@ -0,0 +1,11 @@
1
+
2
+ //#region \0@oxc-project+runtime@0.108.0/helpers/decorate.js
3
+ function __decorate(decorators, target, key, desc) {
4
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
7
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
8
+ }
9
+
10
+ //#endregion
11
+ exports.__decorate = __decorate;
@@ -0,0 +1,10 @@
1
+ //#region \0@oxc-project+runtime@0.108.0/helpers/decorate.js
2
+ function __decorate(decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ }
8
+
9
+ //#endregion
10
+ export { __decorate };
@@ -0,0 +1,70 @@
1
+ let node_path = require("node:path");
2
+ let node_fs = require("node:fs");
3
+ let node_fs_promises = require("node:fs/promises");
4
+ let smol_toml = require("smol-toml");
5
+
6
+ //#region src/config.ts
7
+ const CONFIG_FILENAME = ".afs-workspace.toml";
8
+ /**
9
+ * Get the config file path for a workspace directory
10
+ */
11
+ function getConfigPath(workspacePath) {
12
+ return (0, node_path.join)(workspacePath, CONFIG_FILENAME);
13
+ }
14
+ /**
15
+ * Load workspace config from .afs-workspace.toml.
16
+ * Creates the directory and empty config file if they don't exist.
17
+ */
18
+ async function loadConfig(workspacePath) {
19
+ const absPath = (0, node_path.resolve)(workspacePath);
20
+ if (!(0, node_fs.existsSync)(absPath)) await (0, node_fs_promises.mkdir)(absPath, { recursive: true });
21
+ const configPath = getConfigPath(absPath);
22
+ if (!(0, node_fs.existsSync)(configPath)) {
23
+ await (0, node_fs_promises.writeFile)(configPath, "", "utf8");
24
+ return { mounts: [] };
25
+ }
26
+ const content = await (0, node_fs_promises.readFile)(configPath, "utf8");
27
+ if (!content.trim()) return { mounts: [] };
28
+ return { mounts: (0, smol_toml.parse)(content).mounts ?? [] };
29
+ }
30
+ /**
31
+ * Save workspace config to .afs-workspace.toml using atomic write.
32
+ * Writes to a temp file first, then renames for atomicity.
33
+ */
34
+ async function saveConfig(workspacePath, config) {
35
+ const configPath = getConfigPath((0, node_path.resolve)(workspacePath));
36
+ const tmpPath = `${configPath}.tmp`;
37
+ await (0, node_fs_promises.writeFile)(tmpPath, config.mounts.length > 0 ? (0, smol_toml.stringify)({ mounts: config.mounts }) : "", "utf8");
38
+ await (0, node_fs_promises.rename)(tmpPath, configPath);
39
+ }
40
+ /**
41
+ * Add a mount entry to the config and save.
42
+ */
43
+ async function addMountToConfig(workspacePath, mount) {
44
+ const config = await loadConfig(workspacePath);
45
+ if (config.mounts.find((m) => m.path === mount.path)) throw new Error(`Mount path conflict: '${mount.path}' already exists in workspace config`);
46
+ config.mounts.push(mount);
47
+ await saveConfig(workspacePath, config);
48
+ return config;
49
+ }
50
+ /**
51
+ * Remove a mount entry from the config by path and save.
52
+ * Returns the removed mount config, or undefined if not found.
53
+ */
54
+ async function removeMountFromConfig(workspacePath, mountPath) {
55
+ const config = await loadConfig(workspacePath);
56
+ const index = config.mounts.findIndex((m) => m.path === mountPath);
57
+ if (index === -1) return { config };
58
+ const [removed] = config.mounts.splice(index, 1);
59
+ await saveConfig(workspacePath, config);
60
+ return {
61
+ config,
62
+ removed
63
+ };
64
+ }
65
+
66
+ //#endregion
67
+ exports.addMountToConfig = addMountToConfig;
68
+ exports.getConfigPath = getConfigPath;
69
+ exports.loadConfig = loadConfig;
70
+ exports.removeMountFromConfig = removeMountFromConfig;
@@ -0,0 +1,9 @@
1
+ import { MountConfig } from "@aigne/afs-provider-registry";
2
+
3
+ //#region src/config.d.ts
4
+ interface WorkspaceConfig {
5
+ mounts: MountConfig[];
6
+ }
7
+ //#endregion
8
+ export { WorkspaceConfig };
9
+ //# sourceMappingURL=config.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.cts","names":[],"sources":["../src/config.ts"],"mappings":";;;UAQiB,eAAA;EACf,MAAA,EAAQ,WAAA;AAAA"}
@@ -0,0 +1,9 @@
1
+ import { MountConfig } from "@aigne/afs-provider-registry";
2
+
3
+ //#region src/config.d.ts
4
+ interface WorkspaceConfig {
5
+ mounts: MountConfig[];
6
+ }
7
+ //#endregion
8
+ export { WorkspaceConfig };
9
+ //# sourceMappingURL=config.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.mts","names":[],"sources":["../src/config.ts"],"mappings":";;;UAQiB,eAAA;EACf,MAAA,EAAQ,WAAA;AAAA"}
@@ -0,0 +1,68 @@
1
+ import { join, resolve } from "node:path";
2
+ import { existsSync } from "node:fs";
3
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
4
+ import { parse, stringify } from "smol-toml";
5
+
6
+ //#region src/config.ts
7
+ const CONFIG_FILENAME = ".afs-workspace.toml";
8
+ /**
9
+ * Get the config file path for a workspace directory
10
+ */
11
+ function getConfigPath(workspacePath) {
12
+ return join(workspacePath, CONFIG_FILENAME);
13
+ }
14
+ /**
15
+ * Load workspace config from .afs-workspace.toml.
16
+ * Creates the directory and empty config file if they don't exist.
17
+ */
18
+ async function loadConfig(workspacePath) {
19
+ const absPath = resolve(workspacePath);
20
+ if (!existsSync(absPath)) await mkdir(absPath, { recursive: true });
21
+ const configPath = getConfigPath(absPath);
22
+ if (!existsSync(configPath)) {
23
+ await writeFile(configPath, "", "utf8");
24
+ return { mounts: [] };
25
+ }
26
+ const content = await readFile(configPath, "utf8");
27
+ if (!content.trim()) return { mounts: [] };
28
+ return { mounts: parse(content).mounts ?? [] };
29
+ }
30
+ /**
31
+ * Save workspace config to .afs-workspace.toml using atomic write.
32
+ * Writes to a temp file first, then renames for atomicity.
33
+ */
34
+ async function saveConfig(workspacePath, config) {
35
+ const configPath = getConfigPath(resolve(workspacePath));
36
+ const tmpPath = `${configPath}.tmp`;
37
+ await writeFile(tmpPath, config.mounts.length > 0 ? stringify({ mounts: config.mounts }) : "", "utf8");
38
+ await rename(tmpPath, configPath);
39
+ }
40
+ /**
41
+ * Add a mount entry to the config and save.
42
+ */
43
+ async function addMountToConfig(workspacePath, mount) {
44
+ const config = await loadConfig(workspacePath);
45
+ if (config.mounts.find((m) => m.path === mount.path)) throw new Error(`Mount path conflict: '${mount.path}' already exists in workspace config`);
46
+ config.mounts.push(mount);
47
+ await saveConfig(workspacePath, config);
48
+ return config;
49
+ }
50
+ /**
51
+ * Remove a mount entry from the config by path and save.
52
+ * Returns the removed mount config, or undefined if not found.
53
+ */
54
+ async function removeMountFromConfig(workspacePath, mountPath) {
55
+ const config = await loadConfig(workspacePath);
56
+ const index = config.mounts.findIndex((m) => m.path === mountPath);
57
+ if (index === -1) return { config };
58
+ const [removed] = config.mounts.splice(index, 1);
59
+ await saveConfig(workspacePath, config);
60
+ return {
61
+ config,
62
+ removed
63
+ };
64
+ }
65
+
66
+ //#endregion
67
+ export { addMountToConfig, getConfigPath, loadConfig, removeMountFromConfig };
68
+ //# sourceMappingURL=config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.mjs","names":["parseTOML","stringifyTOML"],"sources":["../src/config.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, rename, writeFile } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport type { MountConfig } from \"@aigne/afs-provider-registry\";\nimport { parse as parseTOML, stringify as stringifyTOML } from \"smol-toml\";\n\nconst CONFIG_FILENAME = \".afs-workspace.toml\";\n\nexport interface WorkspaceConfig {\n mounts: MountConfig[];\n}\n\n/**\n * Get the config file path for a workspace directory\n */\nexport function getConfigPath(workspacePath: string): string {\n return join(workspacePath, CONFIG_FILENAME);\n}\n\n/**\n * Load workspace config from .afs-workspace.toml.\n * Creates the directory and empty config file if they don't exist.\n */\nexport async function loadConfig(workspacePath: string): Promise<WorkspaceConfig> {\n const absPath = resolve(workspacePath);\n\n // Create directory if it doesn't exist\n if (!existsSync(absPath)) {\n await mkdir(absPath, { recursive: true });\n }\n\n const configPath = getConfigPath(absPath);\n\n // Create empty config file if it doesn't exist\n if (!existsSync(configPath)) {\n await writeFile(configPath, \"\", \"utf8\");\n return { mounts: [] };\n }\n\n const content = await readFile(configPath, \"utf8\");\n if (!content.trim()) {\n return { mounts: [] };\n }\n\n const parsed = parseTOML(content);\n const mounts = (parsed.mounts ?? []) as unknown as MountConfig[];\n\n return { mounts };\n}\n\n/**\n * Save workspace config to .afs-workspace.toml using atomic write.\n * Writes to a temp file first, then renames for atomicity.\n */\nexport async function saveConfig(workspacePath: string, config: WorkspaceConfig): Promise<void> {\n const absPath = resolve(workspacePath);\n const configPath = getConfigPath(absPath);\n const tmpPath = `${configPath}.tmp`;\n\n // Build TOML content\n const tomlContent = config.mounts.length > 0 ? stringifyTOML({ mounts: config.mounts }) : \"\";\n\n // Atomic write: write to temp file, then rename\n await writeFile(tmpPath, tomlContent, \"utf8\");\n await rename(tmpPath, configPath);\n}\n\n/**\n * Add a mount entry to the config and save.\n */\nexport async function addMountToConfig(\n workspacePath: string,\n mount: MountConfig,\n): Promise<WorkspaceConfig> {\n const config = await loadConfig(workspacePath);\n\n // Check for path conflict\n const existing = config.mounts.find((m) => m.path === mount.path);\n if (existing) {\n throw new Error(`Mount path conflict: '${mount.path}' already exists in workspace config`);\n }\n\n config.mounts.push(mount);\n await saveConfig(workspacePath, config);\n return config;\n}\n\n/**\n * Remove a mount entry from the config by path and save.\n * Returns the removed mount config, or undefined if not found.\n */\nexport async function removeMountFromConfig(\n workspacePath: string,\n mountPath: string,\n): Promise<{ config: WorkspaceConfig; removed?: MountConfig }> {\n const config = await loadConfig(workspacePath);\n\n const index = config.mounts.findIndex((m) => m.path === mountPath);\n if (index === -1) {\n return { config };\n }\n\n const [removed] = config.mounts.splice(index, 1);\n await saveConfig(workspacePath, config);\n return { config, removed };\n}\n"],"mappings":";;;;;;AAMA,MAAM,kBAAkB;;;;AASxB,SAAgB,cAAc,eAA+B;AAC3D,QAAO,KAAK,eAAe,gBAAgB;;;;;;AAO7C,eAAsB,WAAW,eAAiD;CAChF,MAAM,UAAU,QAAQ,cAAc;AAGtC,KAAI,CAAC,WAAW,QAAQ,CACtB,OAAM,MAAM,SAAS,EAAE,WAAW,MAAM,CAAC;CAG3C,MAAM,aAAa,cAAc,QAAQ;AAGzC,KAAI,CAAC,WAAW,WAAW,EAAE;AAC3B,QAAM,UAAU,YAAY,IAAI,OAAO;AACvC,SAAO,EAAE,QAAQ,EAAE,EAAE;;CAGvB,MA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