@aigne/afs-json 1.1.0 → 1.11.0-beta

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.
@@ -0,0 +1,122 @@
1
+ import { z } from "zod";
2
+ import { AFSAccessMode, AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSReadOptions, AFSReadResult, AFSRenameOptions, AFSRenameResult, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteOptions, AFSWriteResult } from "@aigne/afs";
3
+
4
+ //#region src/index.d.ts
5
+ interface AFSJSONOptions {
6
+ name?: string;
7
+ jsonPath: string;
8
+ description?: string;
9
+ /**
10
+ * Access mode for this module.
11
+ * - "readonly": Only read operations are allowed
12
+ * - "readwrite": All operations are allowed (default, unless agentSkills is enabled)
13
+ * @default "readwrite" (or "readonly" when agentSkills is true)
14
+ */
15
+ accessMode?: AFSAccessMode;
16
+ /**
17
+ * Enable automatic agent skill scanning for this module.
18
+ * When enabled, defaults accessMode to "readonly" if not explicitly set.
19
+ * @default false
20
+ */
21
+ agentSkills?: boolean;
22
+ }
23
+ /**
24
+ * AFS module for mounting JSON/YAML files as virtual file systems.
25
+ *
26
+ * JSON/YAML objects are treated as directories, and properties/array items as files.
27
+ * Supports nested structures and path-based access to data values.
28
+ */
29
+ declare class AFSJSON implements AFSModule {
30
+ options: AFSJSONOptions & {
31
+ cwd?: string;
32
+ };
33
+ static schema(): z.ZodEffects<z.ZodObject<{
34
+ name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
35
+ jsonPath: z.ZodString;
36
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
37
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
38
+ agentSkills: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ jsonPath: string;
41
+ name?: string | undefined;
42
+ description?: string | undefined;
43
+ accessMode?: "readonly" | "readwrite" | undefined;
44
+ agentSkills?: boolean | undefined;
45
+ }, {
46
+ jsonPath: string;
47
+ name?: string | undefined;
48
+ description?: string | undefined;
49
+ accessMode?: "readonly" | "readwrite" | undefined;
50
+ agentSkills?: boolean | undefined;
51
+ }>, {
52
+ jsonPath: string;
53
+ name?: string | undefined;
54
+ description?: string | undefined;
55
+ accessMode?: "readonly" | "readwrite" | undefined;
56
+ agentSkills?: boolean | undefined;
57
+ }, any>;
58
+ static load({
59
+ filepath,
60
+ parsed
61
+ }: AFSModuleLoadParams): Promise<AFSJSON>;
62
+ private jsonData;
63
+ private fileStats;
64
+ private fileFormat;
65
+ constructor(options: AFSJSONOptions & {
66
+ cwd?: string;
67
+ });
68
+ name: string;
69
+ description?: string;
70
+ accessMode: AFSAccessMode;
71
+ agentSkills?: boolean;
72
+ /**
73
+ * Load JSON/YAML data from file. Called lazily on first access.
74
+ * Uses YAML parser which can handle both JSON and YAML formats.
75
+ */
76
+ private ensureLoaded;
77
+ /**
78
+ * Save JSON/YAML data back to file. Only called in readwrite mode.
79
+ */
80
+ private saveToFile;
81
+ /**
82
+ * Normalize path to ensure consistent format
83
+ */
84
+ private normalizePath;
85
+ /**
86
+ * Get path segments from normalized path
87
+ */
88
+ private getPathSegments;
89
+ /**
90
+ * Navigate to a value in the JSON structure using path segments
91
+ */
92
+ private getValueAtPath;
93
+ /**
94
+ * Set a value in the JSON structure at the given path
95
+ */
96
+ private setValueAtPath;
97
+ /**
98
+ * Delete a value from the JSON structure at the given path
99
+ */
100
+ private deleteValueAtPath;
101
+ /**
102
+ * Check if a value is a "directory" (object or array with children)
103
+ */
104
+ private isDirectory;
105
+ /**
106
+ * Get children of a directory value
107
+ */
108
+ private getChildren;
109
+ /**
110
+ * Convert a JSON value to an AFSEntry
111
+ */
112
+ private valueToAFSEntry;
113
+ list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
114
+ read(path: string, _options?: AFSReadOptions): Promise<AFSReadResult>;
115
+ write(path: string, entry: AFSWriteEntryPayload, _options?: AFSWriteOptions): Promise<AFSWriteResult>;
116
+ delete(path: string, options?: AFSDeleteOptions): Promise<AFSDeleteResult>;
117
+ rename(oldPath: string, newPath: string, options?: AFSRenameOptions): Promise<AFSRenameResult>;
118
+ search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult>;
119
+ }
120
+ //#endregion
121
+ export { AFSJSON, AFSJSONOptions };
122
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;UA4BiB,cAAA;EAAA,IAAA;EAAA,QAAA;EAAA,WAAA;EAAA;AAuCjB;;;;;EAvCiB,UAAA,GAUF,aAAA;EAAA;AA6Bf;;;;EA7Be,WAAA;AAAA;AAAA;AA6Bf;;;;;AA7Be,cA6BF,OAAA,YAAmB,SAAA;EAAA,OAAA,EAiBF,cAAA;IAAA,GAAA;EAAA;EAAA,OAAA,OAAA,GAhBf,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA;IAAA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;KAI2B,mBAAA,GAAmB,OAAA,CAAA,OAAA;EAAA,QAAA,QAAA;EAAA,QAAA,SAAA;EAAA,QAAA,UAAA;EAAA,YAAA,OAAA,EAY/B,cAAA;IAAA,GAAA;EAAA;EAAA,IAAA;EAAA,WAAA;EAAA,UAAA,EAwChB,aAAA;EAAA,WAAA;EAAA;;;;EAAA,QAAA,YAAA;EAAA;;;EAAA,QAAA,UAAA;EAAA;;;EAAA,QAAA,aAAA;EAAA;;;EAAA,QAAA,eAAA;EAAA;;;EAAA,QAAA,cAAA;EAAA;;;EAAA,QAAA,cAAA;EAAA;;;EAAA,QAAA,iBAAA;EAAA;;;EAAA,QAAA,WAAA;EAAA;;;EAAA,QAAA,WAAA;EAAA;;;EAAA,QAAA,eAAA;EAAA,KAAA,IAAA,UAAA,OAAA,GAkPuB,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAAA,KAAA,IAAA,UAAA,QAAA,GAmExB,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAAA,MAAA,IAAA,UAAA,KAAA,EAmBpD,oBAAA,EAAA,QAAA,GACI,eAAA,GACV,OAAA,CAAQ,cAAA;EAAA,OAAA,IAAA,UAAA,OAAA,GAqC0B,gBAAA,GAAmB,OAAA,CAAQ,eAAA;EAAA,OAAA,OAAA,UAAA,OAAA,UAAA,OAAA,GA2BpD,gBAAA,GACT,OAAA,CAAQ,eAAA;EAAA,OAAA,IAAA,UAAA,KAAA,UAAA,OAAA,GA+ByC,gBAAA,GAAmB,OAAA,CAAQ,eAAA;AAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,367 @@
1
+ import { readFile, stat, writeFile } from "node:fs/promises";
2
+ import { basename, dirname, extname, isAbsolute, join } from "node:path";
3
+ import { camelize, optionalize, zodParse } from "@aigne/afs/utils/zod";
4
+ import { parse, stringify } from "yaml";
5
+ import { z } from "zod";
6
+
7
+ //#region src/index.ts
8
+ const LIST_MAX_LIMIT = 1e3;
9
+ const afsJSONOptionsSchema = camelize(z.object({
10
+ name: optionalize(z.string()),
11
+ jsonPath: z.string().describe("The path to the JSON/YAML file to mount"),
12
+ description: optionalize(z.string().describe("A description of the JSON module")),
13
+ accessMode: optionalize(z.enum(["readonly", "readwrite"]).describe("Access mode for this module")),
14
+ agentSkills: optionalize(z.boolean().describe("Enable automatic agent skill scanning for this module"))
15
+ }));
16
+ /**
17
+ * AFS module for mounting JSON/YAML files as virtual file systems.
18
+ *
19
+ * JSON/YAML objects are treated as directories, and properties/array items as files.
20
+ * Supports nested structures and path-based access to data values.
21
+ */
22
+ var AFSJSON = class AFSJSON {
23
+ static schema() {
24
+ return afsJSONOptionsSchema;
25
+ }
26
+ static async load({ filepath, parsed }) {
27
+ return new AFSJSON({
28
+ ...await AFSJSON.schema().parseAsync(parsed),
29
+ cwd: dirname(filepath)
30
+ });
31
+ }
32
+ jsonData = null;
33
+ fileStats = {};
34
+ fileFormat = "json";
35
+ constructor(options) {
36
+ this.options = options;
37
+ zodParse(afsJSONOptionsSchema, options);
38
+ let jsonPath;
39
+ jsonPath = options.jsonPath.replaceAll("${CWD}", process.cwd());
40
+ if (jsonPath.startsWith("~/")) jsonPath = join(process.env.HOME || "", jsonPath.slice(2));
41
+ if (!isAbsolute(jsonPath)) jsonPath = join(options.cwd || process.cwd(), jsonPath);
42
+ const ext = extname(jsonPath).toLowerCase();
43
+ this.fileFormat = ext === ".yaml" || ext === ".yml" ? "yaml" : "json";
44
+ const extensions = [
45
+ ".json",
46
+ ".yaml",
47
+ ".yml"
48
+ ];
49
+ let name = basename(jsonPath);
50
+ for (const e of extensions) if (name.endsWith(e)) {
51
+ name = name.slice(0, -e.length);
52
+ break;
53
+ }
54
+ this.name = options.name || name || "json";
55
+ this.description = options.description;
56
+ this.agentSkills = options.agentSkills;
57
+ this.accessMode = options.accessMode ?? (options.agentSkills ? "readonly" : "readwrite");
58
+ this.options.jsonPath = jsonPath;
59
+ }
60
+ name;
61
+ description;
62
+ accessMode;
63
+ agentSkills;
64
+ /**
65
+ * Load JSON/YAML data from file. Called lazily on first access.
66
+ * Uses YAML parser which can handle both JSON and YAML formats.
67
+ */
68
+ async ensureLoaded() {
69
+ if (this.jsonData !== null) return;
70
+ try {
71
+ const stats = await stat(this.options.jsonPath);
72
+ this.fileStats = {
73
+ birthtime: stats.birthtime,
74
+ mtime: stats.mtime
75
+ };
76
+ this.jsonData = parse(await readFile(this.options.jsonPath, "utf8"));
77
+ } catch (error) {
78
+ if (error.code === "ENOENT") this.jsonData = {};
79
+ else throw error;
80
+ }
81
+ }
82
+ /**
83
+ * Save JSON/YAML data back to file. Only called in readwrite mode.
84
+ */
85
+ async saveToFile() {
86
+ let content;
87
+ if (this.fileFormat === "yaml") content = stringify(this.jsonData);
88
+ else content = JSON.stringify(this.jsonData, null, 2);
89
+ await writeFile(this.options.jsonPath, content, "utf8");
90
+ const stats = await stat(this.options.jsonPath);
91
+ this.fileStats = {
92
+ birthtime: this.fileStats.birthtime || stats.birthtime,
93
+ mtime: stats.mtime
94
+ };
95
+ }
96
+ /**
97
+ * Normalize path to ensure consistent format
98
+ */
99
+ normalizePath(path) {
100
+ let normalized = path.startsWith("/") ? path : `/${path}`;
101
+ if (normalized.length > 1 && normalized.endsWith("/")) normalized = normalized.slice(0, -1);
102
+ return normalized;
103
+ }
104
+ /**
105
+ * Get path segments from normalized path
106
+ */
107
+ getPathSegments(path) {
108
+ const normalized = this.normalizePath(path);
109
+ if (normalized === "/") return [];
110
+ return normalized.slice(1).split("/");
111
+ }
112
+ /**
113
+ * Navigate to a value in the JSON structure using path segments
114
+ */
115
+ getValueAtPath(data, segments) {
116
+ let current = data;
117
+ for (const segment of segments) {
118
+ if (current == null) return void 0;
119
+ if (Array.isArray(current)) {
120
+ const index = Number.parseInt(segment, 10);
121
+ if (Number.isNaN(index) || index < 0 || index >= current.length) return;
122
+ current = current[index];
123
+ } else if (typeof current === "object") current = current[segment];
124
+ else return;
125
+ }
126
+ return current;
127
+ }
128
+ /**
129
+ * Set a value in the JSON structure at the given path
130
+ */
131
+ setValueAtPath(data, segments, value) {
132
+ if (segments.length === 0) throw new Error("Cannot set value at root path");
133
+ let current = data;
134
+ for (let i = 0; i < segments.length - 1; i++) {
135
+ const segment = segments[i];
136
+ const nextSegment = segments[i + 1];
137
+ if (Array.isArray(current)) {
138
+ const index = Number.parseInt(segment, 10);
139
+ if (Number.isNaN(index) || index < 0) throw new Error(`Invalid array index: ${segment}`);
140
+ while (current.length <= index) current.push(null);
141
+ if (current[index] == null) current[index] = !Number.isNaN(Number.parseInt(nextSegment, 10)) ? [] : {};
142
+ current = current[index];
143
+ } else if (typeof current === "object") {
144
+ if (current[segment] == null) current[segment] = !Number.isNaN(Number.parseInt(nextSegment, 10)) ? [] : {};
145
+ current = current[segment];
146
+ } else throw new Error(`Cannot set property on non-object at ${segments.slice(0, i + 1).join("/")}`);
147
+ }
148
+ const lastSegment = segments[segments.length - 1];
149
+ if (Array.isArray(current)) {
150
+ const index = Number.parseInt(lastSegment, 10);
151
+ if (Number.isNaN(index) || index < 0) throw new Error(`Invalid array index: ${lastSegment}`);
152
+ current[index] = value;
153
+ } else if (typeof current === "object") current[lastSegment] = value;
154
+ else throw new Error("Cannot set property on non-object");
155
+ }
156
+ /**
157
+ * Delete a value from the JSON structure at the given path
158
+ */
159
+ deleteValueAtPath(data, segments) {
160
+ if (segments.length === 0) throw new Error("Cannot delete root path");
161
+ let current = data;
162
+ for (let i = 0; i < segments.length - 1; i++) {
163
+ const segment = segments[i];
164
+ if (Array.isArray(current)) {
165
+ const index = Number.parseInt(segment, 10);
166
+ if (Number.isNaN(index) || index < 0 || index >= current.length) return false;
167
+ current = current[index];
168
+ } else if (typeof current === "object") {
169
+ if (!(segment in current)) return false;
170
+ current = current[segment];
171
+ } else return false;
172
+ }
173
+ const lastSegment = segments[segments.length - 1];
174
+ if (Array.isArray(current)) {
175
+ const index = Number.parseInt(lastSegment, 10);
176
+ if (Number.isNaN(index) || index < 0 || index >= current.length) return false;
177
+ current.splice(index, 1);
178
+ return true;
179
+ }
180
+ if (typeof current === "object") {
181
+ if (!(lastSegment in current)) return false;
182
+ delete current[lastSegment];
183
+ return true;
184
+ }
185
+ return false;
186
+ }
187
+ /**
188
+ * Check if a value is a "directory" (object or array with children)
189
+ */
190
+ isDirectory(value) {
191
+ if (Array.isArray(value)) return true;
192
+ if (typeof value === "object" && value !== null) return true;
193
+ return false;
194
+ }
195
+ /**
196
+ * Get children of a directory value
197
+ */
198
+ getChildren(value) {
199
+ if (Array.isArray(value)) return value.map((item, index) => ({
200
+ key: String(index),
201
+ value: item
202
+ }));
203
+ if (typeof value === "object" && value !== null) return Object.entries(value).map(([key, val]) => ({
204
+ key,
205
+ value: val
206
+ }));
207
+ return [];
208
+ }
209
+ /**
210
+ * Convert a JSON value to an AFSEntry
211
+ */
212
+ valueToAFSEntry(path, value) {
213
+ const isDir = this.isDirectory(value);
214
+ const children = isDir ? this.getChildren(value) : [];
215
+ return {
216
+ id: path,
217
+ path,
218
+ content: isDir ? void 0 : value,
219
+ createdAt: this.fileStats.birthtime,
220
+ updatedAt: this.fileStats.mtime,
221
+ metadata: {
222
+ type: isDir ? "directory" : "file",
223
+ childrenCount: isDir ? children.length : void 0
224
+ }
225
+ };
226
+ }
227
+ async list(path, options) {
228
+ await this.ensureLoaded();
229
+ const normalizedPath = this.normalizePath(path);
230
+ const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);
231
+ const maxChildren = typeof options?.maxChildren === "number" ? options.maxChildren : Number.MAX_SAFE_INTEGER;
232
+ const maxDepth = options?.maxDepth ?? 1;
233
+ const segments = this.getPathSegments(normalizedPath);
234
+ const value = this.getValueAtPath(this.jsonData, segments);
235
+ if (value === void 0) throw new Error(`Path not found: ${normalizedPath}`);
236
+ const entries = [];
237
+ const queue = [{
238
+ path: normalizedPath,
239
+ value,
240
+ depth: 0
241
+ }];
242
+ while (queue.length > 0) {
243
+ const item = queue.shift();
244
+ if (!item) break;
245
+ const { path: itemPath, value: itemValue, depth } = item;
246
+ const entry = this.valueToAFSEntry(itemPath, itemValue);
247
+ entries.push(entry);
248
+ if (entries.length >= limit) {
249
+ if (entry.metadata) entry.metadata.childrenTruncated = true;
250
+ break;
251
+ }
252
+ if (this.isDirectory(itemValue) && depth < maxDepth) {
253
+ const children = this.getChildren(itemValue);
254
+ const childrenToProcess = children.length > maxChildren ? children.slice(0, maxChildren) : children;
255
+ if (childrenToProcess.length < children.length && entry.metadata) entry.metadata.childrenTruncated = true;
256
+ for (const child of childrenToProcess) {
257
+ const childPath = itemPath === "/" ? `/${child.key}` : `${itemPath}/${child.key}`;
258
+ queue.push({
259
+ path: childPath,
260
+ value: child.value,
261
+ depth: depth + 1
262
+ });
263
+ }
264
+ }
265
+ }
266
+ return { data: entries };
267
+ }
268
+ async read(path, _options) {
269
+ await this.ensureLoaded();
270
+ const normalizedPath = this.normalizePath(path);
271
+ const segments = this.getPathSegments(normalizedPath);
272
+ const value = this.getValueAtPath(this.jsonData, segments);
273
+ if (value === void 0) return {
274
+ data: void 0,
275
+ message: `Path not found: ${normalizedPath}`
276
+ };
277
+ return { data: this.valueToAFSEntry(normalizedPath, value) };
278
+ }
279
+ async write(path, entry, _options) {
280
+ await this.ensureLoaded();
281
+ const normalizedPath = this.normalizePath(path);
282
+ const segments = this.getPathSegments(normalizedPath);
283
+ this.setValueAtPath(this.jsonData, segments, entry.content);
284
+ await this.saveToFile();
285
+ const newValue = this.getValueAtPath(this.jsonData, segments);
286
+ const isDir = this.isDirectory(newValue);
287
+ const children = isDir ? this.getChildren(newValue) : [];
288
+ return { data: {
289
+ id: normalizedPath,
290
+ path: normalizedPath,
291
+ content: entry.content,
292
+ summary: entry.summary,
293
+ description: entry.description,
294
+ createdAt: this.fileStats.birthtime,
295
+ updatedAt: this.fileStats.mtime,
296
+ metadata: {
297
+ ...entry.metadata,
298
+ type: isDir ? "directory" : "file",
299
+ childrenCount: isDir ? children.length : void 0
300
+ },
301
+ userId: entry.userId,
302
+ sessionId: entry.sessionId,
303
+ linkTo: entry.linkTo
304
+ } };
305
+ }
306
+ async delete(path, options) {
307
+ await this.ensureLoaded();
308
+ const normalizedPath = this.normalizePath(path);
309
+ const segments = this.getPathSegments(normalizedPath);
310
+ const value = this.getValueAtPath(this.jsonData, segments);
311
+ if (value === void 0) throw new Error(`Path not found: ${normalizedPath}`);
312
+ if (this.isDirectory(value) && this.getChildren(value).length > 0 && !options?.recursive) throw new Error(`Cannot delete directory '${normalizedPath}' without recursive option. Set recursive: true to delete directories.`);
313
+ this.deleteValueAtPath(this.jsonData, segments);
314
+ await this.saveToFile();
315
+ return { message: `Successfully deleted: ${normalizedPath}` };
316
+ }
317
+ async rename(oldPath, newPath, options) {
318
+ await this.ensureLoaded();
319
+ const normalizedOldPath = this.normalizePath(oldPath);
320
+ const normalizedNewPath = this.normalizePath(newPath);
321
+ const oldSegments = this.getPathSegments(normalizedOldPath);
322
+ const newSegments = this.getPathSegments(normalizedNewPath);
323
+ const oldValue = this.getValueAtPath(this.jsonData, oldSegments);
324
+ if (oldValue === void 0) throw new Error(`Source path not found: ${normalizedOldPath}`);
325
+ if (this.getValueAtPath(this.jsonData, newSegments) !== void 0 && !options?.overwrite) throw new Error(`Destination '${normalizedNewPath}' already exists. Set overwrite: true to replace it.`);
326
+ this.setValueAtPath(this.jsonData, newSegments, oldValue);
327
+ this.deleteValueAtPath(this.jsonData, oldSegments);
328
+ await this.saveToFile();
329
+ return { message: `Successfully renamed '${normalizedOldPath}' to '${normalizedNewPath}'` };
330
+ }
331
+ async search(path, query, options) {
332
+ await this.ensureLoaded();
333
+ const normalizedPath = this.normalizePath(path);
334
+ const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);
335
+ const caseSensitive = options?.caseSensitive ?? false;
336
+ const segments = this.getPathSegments(normalizedPath);
337
+ const rootValue = this.getValueAtPath(this.jsonData, segments);
338
+ if (rootValue === void 0) throw new Error(`Path not found: ${normalizedPath}`);
339
+ const entries = [];
340
+ const searchQuery = caseSensitive ? query : query.toLowerCase();
341
+ const searchInValue = (valuePath, value) => {
342
+ if (entries.length >= limit) return;
343
+ let matched = false;
344
+ if (!this.isDirectory(value)) {
345
+ const valueStr = typeof value === "string" ? value : JSON.stringify(value);
346
+ if ((caseSensitive ? valueStr : valueStr.toLowerCase()).includes(searchQuery)) matched = true;
347
+ }
348
+ if (matched) entries.push(this.valueToAFSEntry(valuePath, value));
349
+ if (this.isDirectory(value)) {
350
+ const children = this.getChildren(value);
351
+ for (const child of children) {
352
+ if (entries.length >= limit) break;
353
+ searchInValue(valuePath === "/" ? `/${child.key}` : `${valuePath}/${child.key}`, child.value);
354
+ }
355
+ }
356
+ };
357
+ searchInValue(normalizedPath, rootValue);
358
+ return {
359
+ data: entries,
360
+ message: entries.length >= limit ? `Results truncated to limit ${limit}` : void 0
361
+ };
362
+ }
363
+ };
364
+
365
+ //#endregion
366
+ export { AFSJSON };
367
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["parseYAML","stringifyYAML"],"sources":["../src/index.ts"],"sourcesContent":["import { readFile, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, extname, isAbsolute, join } from \"node:path\";\nimport type {\n AFSAccessMode,\n AFSDeleteOptions,\n AFSDeleteResult,\n AFSEntry,\n AFSListOptions,\n AFSListResult,\n AFSModule,\n AFSModuleClass,\n AFSModuleLoadParams,\n AFSReadOptions,\n AFSReadResult,\n AFSRenameOptions,\n AFSRenameResult,\n AFSSearchOptions,\n AFSSearchResult,\n AFSWriteEntryPayload,\n AFSWriteOptions,\n AFSWriteResult,\n} from \"@aigne/afs\";\nimport { camelize, optionalize, zodParse } from \"@aigne/afs/utils/zod\";\nimport { parse as parseYAML, stringify as stringifyYAML } from \"yaml\";\nimport { z } from \"zod\";\n\nconst LIST_MAX_LIMIT = 1000;\n\nexport interface AFSJSONOptions {\n name?: string;\n jsonPath: string;\n description?: string;\n /**\n * Access mode for this module.\n * - \"readonly\": Only read operations are allowed\n * - \"readwrite\": All operations are allowed (default, unless agentSkills is enabled)\n * @default \"readwrite\" (or \"readonly\" when agentSkills is true)\n */\n accessMode?: AFSAccessMode;\n /**\n * Enable automatic agent skill scanning for this module.\n * When enabled, defaults accessMode to \"readonly\" if not explicitly set.\n * @default false\n */\n agentSkills?: boolean;\n}\n\nconst afsJSONOptionsSchema = camelize(\n z.object({\n name: optionalize(z.string()),\n jsonPath: z.string().describe(\"The path to the JSON/YAML file to mount\"),\n description: optionalize(z.string().describe(\"A description of the JSON module\")),\n accessMode: optionalize(\n z.enum([\"readonly\", \"readwrite\"]).describe(\"Access mode for this module\"),\n ),\n agentSkills: optionalize(\n z.boolean().describe(\"Enable automatic agent skill scanning for this module\"),\n ),\n }),\n);\n\n/**\n * AFS module for mounting JSON/YAML files as virtual file systems.\n *\n * JSON/YAML objects are treated as directories, and properties/array items as files.\n * Supports nested structures and path-based access to data values.\n */\nexport class AFSJSON implements AFSModule {\n static schema() {\n return afsJSONOptionsSchema;\n }\n\n static async load({ filepath, parsed }: AFSModuleLoadParams) {\n const valid = await AFSJSON.schema().parseAsync(parsed);\n return new AFSJSON({ ...valid, cwd: dirname(filepath) });\n }\n\n private jsonData: any = null;\n private fileStats: {\n birthtime?: Date;\n mtime?: Date;\n } = {};\n private fileFormat: \"json\" | \"yaml\" = \"json\";\n\n constructor(public options: AFSJSONOptions & { cwd?: string }) {\n zodParse(afsJSONOptionsSchema, options);\n\n let jsonPath: string;\n\n // biome-ignore lint/suspicious/noTemplateCurlyInString: explicitly replace ${CWD}\n jsonPath = options.jsonPath.replaceAll(\"${CWD}\", process.cwd());\n if (jsonPath.startsWith(\"~/\")) {\n jsonPath = join(process.env.HOME || \"\", jsonPath.slice(2));\n }\n if (!isAbsolute(jsonPath)) {\n jsonPath = join(options.cwd || process.cwd(), jsonPath);\n }\n\n // Detect file format based on extension for writing\n const ext = extname(jsonPath).toLowerCase();\n this.fileFormat = ext === \".yaml\" || ext === \".yml\" ? \"yaml\" : \"json\";\n\n // Extract name without extension\n const extensions = [\".json\", \".yaml\", \".yml\"];\n let name = basename(jsonPath);\n for (const e of extensions) {\n if (name.endsWith(e)) {\n name = name.slice(0, -e.length);\n break;\n }\n }\n\n this.name = options.name || name || \"json\";\n this.description = options.description;\n this.agentSkills = options.agentSkills;\n // Default to \"readwrite\", but \"readonly\" if agentSkills is enabled\n this.accessMode = options.accessMode ?? (options.agentSkills ? \"readonly\" : \"readwrite\");\n this.options.jsonPath = jsonPath;\n }\n\n name: string;\n\n description?: string;\n\n accessMode: AFSAccessMode;\n\n agentSkills?: boolean;\n\n /**\n * Load JSON/YAML data from file. Called lazily on first access.\n * Uses YAML parser which can handle both JSON and YAML formats.\n */\n private async ensureLoaded(): Promise<void> {\n if (this.jsonData !== null) return;\n\n try {\n const stats = await stat(this.options.jsonPath);\n this.fileStats = {\n birthtime: stats.birthtime,\n mtime: stats.mtime,\n };\n\n const content = await readFile(this.options.jsonPath, \"utf8\");\n\n // YAML parser can handle both JSON and YAML formats\n this.jsonData = parseYAML(content);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n // File doesn't exist yet, start with empty object\n this.jsonData = {};\n } else {\n throw error;\n }\n }\n }\n\n /**\n * Save JSON/YAML data back to file. Only called in readwrite mode.\n */\n private async saveToFile(): Promise<void> {\n let content: string;\n\n // Serialize based on file format\n if (this.fileFormat === \"yaml\") {\n content = stringifyYAML(this.jsonData);\n } else {\n content = JSON.stringify(this.jsonData, null, 2);\n }\n\n await writeFile(this.options.jsonPath, content, \"utf8\");\n\n // Update file stats\n const stats = await stat(this.options.jsonPath);\n this.fileStats = {\n birthtime: this.fileStats.birthtime || stats.birthtime,\n mtime: stats.mtime,\n };\n }\n\n /**\n * Normalize path to ensure consistent format\n */\n private normalizePath(path: string): string {\n let normalized = path.startsWith(\"/\") ? path : `/${path}`;\n if (normalized.length > 1 && normalized.endsWith(\"/\")) {\n normalized = normalized.slice(0, -1);\n }\n return normalized;\n }\n\n /**\n * Get path segments from normalized path\n */\n private getPathSegments(path: string): string[] {\n const normalized = this.normalizePath(path);\n if (normalized === \"/\") return [];\n return normalized.slice(1).split(\"/\");\n }\n\n /**\n * Navigate to a value in the JSON structure using path segments\n */\n private getValueAtPath(data: any, segments: string[]): any {\n let current = data;\n for (const segment of segments) {\n if (current == null) return undefined;\n\n // Handle array indices\n if (Array.isArray(current)) {\n const index = Number.parseInt(segment, 10);\n if (Number.isNaN(index) || index < 0 || index >= current.length) {\n return undefined;\n }\n current = current[index];\n } else if (typeof current === \"object\") {\n current = current[segment as keyof typeof current];\n } else {\n return undefined;\n }\n }\n return current;\n }\n\n /**\n * Set a value in the JSON structure at the given path\n */\n private setValueAtPath(data: any, segments: string[], value: any): void {\n if (segments.length === 0) {\n throw new Error(\"Cannot set value at root path\");\n }\n\n let current = data;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n const nextSegment = segments[i + 1]!;\n\n if (Array.isArray(current)) {\n const index = Number.parseInt(segment, 10);\n if (Number.isNaN(index) || index < 0) {\n throw new Error(`Invalid array index: ${segment}`);\n }\n\n // Extend array if necessary\n while (current.length <= index) {\n current.push(null);\n }\n\n if (current[index] == null) {\n // Determine if next level should be array or object\n const isNextArray = !Number.isNaN(Number.parseInt(nextSegment, 10));\n current[index] = isNextArray ? [] : {};\n }\n current = current[index];\n } else if (typeof current === \"object\") {\n if (current[segment] == null) {\n // Determine if next level should be array or object\n const isNextArray = !Number.isNaN(Number.parseInt(nextSegment, 10));\n current[segment] = isNextArray ? [] : {};\n }\n current = current[segment];\n } else {\n throw new Error(\n `Cannot set property on non-object at ${segments.slice(0, i + 1).join(\"/\")}`,\n );\n }\n }\n\n const lastSegment = segments[segments.length - 1]!;\n if (Array.isArray(current)) {\n const index = Number.parseInt(lastSegment, 10);\n if (Number.isNaN(index) || index < 0) {\n throw new Error(`Invalid array index: ${lastSegment}`);\n }\n current[index] = value;\n } else if (typeof current === \"object\") {\n current[lastSegment] = value;\n } else {\n throw new Error(\"Cannot set property on non-object\");\n }\n }\n\n /**\n * Delete a value from the JSON structure at the given path\n */\n private deleteValueAtPath(data: any, segments: string[]): boolean {\n if (segments.length === 0) {\n throw new Error(\"Cannot delete root path\");\n }\n\n let current = data;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n\n if (Array.isArray(current)) {\n const index = Number.parseInt(segment, 10);\n if (Number.isNaN(index) || index < 0 || index >= current.length) {\n return false;\n }\n current = current[index];\n } else if (typeof current === \"object\") {\n if (!(segment in current)) return false;\n current = current[segment];\n } else {\n return false;\n }\n }\n\n const lastSegment = segments[segments.length - 1]!;\n if (Array.isArray(current)) {\n const index = Number.parseInt(lastSegment, 10);\n if (Number.isNaN(index) || index < 0 || index >= current.length) {\n return false;\n }\n current.splice(index, 1);\n return true;\n }\n if (typeof current === \"object\") {\n if (!(lastSegment in current)) return false;\n delete current[lastSegment];\n return true;\n }\n return false;\n }\n\n /**\n * Check if a value is a \"directory\" (object or array with children)\n */\n private isDirectory(value: any): boolean {\n if (Array.isArray(value)) return true;\n if (typeof value === \"object\" && value !== null) return true;\n return false;\n }\n\n /**\n * Get children of a directory value\n */\n private getChildren(value: any): Array<{ key: string; value: any }> {\n if (Array.isArray(value)) {\n return value.map((item, index) => ({ key: String(index), value: item }));\n }\n if (typeof value === \"object\" && value !== null) {\n return Object.entries(value).map(([key, val]) => ({ key, value: val }));\n }\n return [];\n }\n\n /**\n * Convert a JSON value to an AFSEntry\n */\n private valueToAFSEntry(path: string, value: any): AFSEntry {\n const isDir = this.isDirectory(value);\n const children = isDir ? this.getChildren(value) : [];\n\n return {\n id: path,\n path: path,\n content: isDir ? undefined : value,\n createdAt: this.fileStats.birthtime,\n updatedAt: this.fileStats.mtime,\n metadata: {\n type: isDir ? \"directory\" : \"file\",\n childrenCount: isDir ? children.length : undefined,\n },\n };\n }\n\n async list(path: string, options?: AFSListOptions): Promise<AFSListResult> {\n await this.ensureLoaded();\n\n const normalizedPath = this.normalizePath(path);\n const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);\n const maxChildren =\n typeof options?.maxChildren === \"number\" ? options.maxChildren : Number.MAX_SAFE_INTEGER;\n const maxDepth = options?.maxDepth ?? 1;\n\n const segments = this.getPathSegments(normalizedPath);\n const value = this.getValueAtPath(this.jsonData, segments);\n\n if (value === undefined) {\n throw new Error(`Path not found: ${normalizedPath}`);\n }\n\n const entries: AFSEntry[] = [];\n\n interface QueueItem {\n path: string;\n value: any;\n depth: number;\n }\n\n const queue: QueueItem[] = [{ path: normalizedPath, value, depth: 0 }];\n\n while (queue.length > 0) {\n const item = queue.shift();\n if (!item) break;\n\n const { path: itemPath, value: itemValue, depth } = item;\n\n const entry = this.valueToAFSEntry(itemPath, itemValue);\n entries.push(entry);\n\n if (entries.length >= limit) {\n if (entry.metadata) {\n entry.metadata.childrenTruncated = true;\n }\n break;\n }\n\n // Process children if within depth limit\n if (this.isDirectory(itemValue) && depth < maxDepth) {\n const children = this.getChildren(itemValue);\n const childrenToProcess =\n children.length > maxChildren ? children.slice(0, maxChildren) : children;\n const isTruncated = childrenToProcess.length < children.length;\n\n if (isTruncated && entry.metadata) {\n entry.metadata.childrenTruncated = true;\n }\n\n for (const child of childrenToProcess) {\n const childPath = itemPath === \"/\" ? `/${child.key}` : `${itemPath}/${child.key}`;\n queue.push({\n path: childPath,\n value: child.value,\n depth: depth + 1,\n });\n }\n }\n }\n\n return { data: entries };\n }\n\n async read(path: string, _options?: AFSReadOptions): Promise<AFSReadResult> {\n await this.ensureLoaded();\n\n const normalizedPath = this.normalizePath(path);\n const segments = this.getPathSegments(normalizedPath);\n const value = this.getValueAtPath(this.jsonData, segments);\n\n if (value === undefined) {\n return {\n data: undefined,\n message: `Path not found: ${normalizedPath}`,\n };\n }\n\n return { data: this.valueToAFSEntry(normalizedPath, value) };\n }\n\n async write(\n path: string,\n entry: AFSWriteEntryPayload,\n _options?: AFSWriteOptions,\n ): Promise<AFSWriteResult> {\n await this.ensureLoaded();\n\n const normalizedPath = this.normalizePath(path);\n const segments = this.getPathSegments(normalizedPath);\n\n // Set the value in the JSON structure\n this.setValueAtPath(this.jsonData, segments, entry.content);\n\n // Save back to file\n await this.saveToFile();\n\n const newValue = this.getValueAtPath(this.jsonData, segments);\n const isDir = this.isDirectory(newValue);\n const children = isDir ? this.getChildren(newValue) : [];\n\n const writtenEntry: AFSEntry = {\n id: normalizedPath,\n path: normalizedPath,\n content: entry.content,\n summary: entry.summary,\n description: entry.description,\n createdAt: this.fileStats.birthtime,\n updatedAt: this.fileStats.mtime,\n metadata: {\n ...entry.metadata,\n type: isDir ? \"directory\" : \"file\",\n childrenCount: isDir ? children.length : undefined,\n },\n userId: entry.userId,\n sessionId: entry.sessionId,\n linkTo: entry.linkTo,\n };\n\n return { data: writtenEntry };\n }\n\n async delete(path: string, options?: AFSDeleteOptions): Promise<AFSDeleteResult> {\n await this.ensureLoaded();\n\n const normalizedPath = this.normalizePath(path);\n const segments = this.getPathSegments(normalizedPath);\n const value = this.getValueAtPath(this.jsonData, segments);\n\n if (value === undefined) {\n throw new Error(`Path not found: ${normalizedPath}`);\n }\n\n const hasChildren = this.isDirectory(value) && this.getChildren(value).length > 0;\n if (hasChildren && !options?.recursive) {\n throw new Error(\n `Cannot delete directory '${normalizedPath}' without recursive option. Set recursive: true to delete directories.`,\n );\n }\n\n this.deleteValueAtPath(this.jsonData, segments);\n await this.saveToFile();\n\n return { message: `Successfully deleted: ${normalizedPath}` };\n }\n\n async rename(\n oldPath: string,\n newPath: string,\n options?: AFSRenameOptions,\n ): Promise<AFSRenameResult> {\n await this.ensureLoaded();\n\n const normalizedOldPath = this.normalizePath(oldPath);\n const normalizedNewPath = this.normalizePath(newPath);\n\n const oldSegments = this.getPathSegments(normalizedOldPath);\n const newSegments = this.getPathSegments(normalizedNewPath);\n\n const oldValue = this.getValueAtPath(this.jsonData, oldSegments);\n if (oldValue === undefined) {\n throw new Error(`Source path not found: ${normalizedOldPath}`);\n }\n\n const existingNewValue = this.getValueAtPath(this.jsonData, newSegments);\n if (existingNewValue !== undefined && !options?.overwrite) {\n throw new Error(\n `Destination '${normalizedNewPath}' already exists. Set overwrite: true to replace it.`,\n );\n }\n\n // Copy to new location and delete old\n this.setValueAtPath(this.jsonData, newSegments, oldValue);\n this.deleteValueAtPath(this.jsonData, oldSegments);\n await this.saveToFile();\n\n return {\n message: `Successfully renamed '${normalizedOldPath}' to '${normalizedNewPath}'`,\n };\n }\n\n async search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult> {\n await this.ensureLoaded();\n\n const normalizedPath = this.normalizePath(path);\n const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);\n const caseSensitive = options?.caseSensitive ?? false;\n\n const segments = this.getPathSegments(normalizedPath);\n const rootValue = this.getValueAtPath(this.jsonData, segments);\n\n if (rootValue === undefined) {\n throw new Error(`Path not found: ${normalizedPath}`);\n }\n\n const entries: AFSEntry[] = [];\n const searchQuery = caseSensitive ? query : query.toLowerCase();\n\n const searchInValue = (valuePath: string, value: any): void => {\n if (entries.length >= limit) return;\n\n let matched = false;\n\n // Search in the value itself\n if (!this.isDirectory(value)) {\n const valueStr = typeof value === \"string\" ? value : JSON.stringify(value);\n const searchValue = caseSensitive ? valueStr : valueStr.toLowerCase();\n if (searchValue.includes(searchQuery)) {\n matched = true;\n }\n }\n\n if (matched) {\n entries.push(this.valueToAFSEntry(valuePath, value));\n }\n\n // Recursively search children\n if (this.isDirectory(value)) {\n const children = this.getChildren(value);\n for (const child of children) {\n if (entries.length >= limit) break;\n const childPath = valuePath === \"/\" ? `/${child.key}` : `${valuePath}/${child.key}`;\n searchInValue(childPath, child.value);\n }\n }\n };\n\n searchInValue(normalizedPath, rootValue);\n\n return {\n data: entries,\n message: entries.length >= limit ? `Results truncated to limit ${limit}` : undefined,\n };\n }\n}\n\nconst _typeCheck: AFSModuleClass<AFSJSON, AFSJSONOptions> = AFSJSON;\n"],"mappings":";;;;;;;AA0BA,MAAM,iBAAiB;AAqBvB,MAAM,uBAAuB,SAC3B,EAAE,OAAO;CACP,MAAM,YAAY,EAAE,QAAQ,CAAC;CAC7B,UAAU,EAAE,QAAQ,CAAC,SAAS,0CAA0C;CACxE,aAAa,YAAY,EAAE,QAAQ,CAAC,SAAS,mCAAmC,CAAC;CACjF,YAAY,YACV,EAAE,KAAK,CAAC,YAAY,YAAY,CAAC,CAAC,SAAS,8BAA8B,CAC1E;CACD,aAAa,YACX,EAAE,SAAS,CAAC,SAAS,wDAAwD,CAC9E;CACF,CAAC,CACH;;;;;;;AAQD,IAAa,UAAb,MAAa,QAA6B;CACxC,OAAO,SAAS;AACd,SAAO;;CAGT,aAAa,KAAK,EAAE,UAAU,UAA+B;AAE3D,SAAO,IAAI,QAAQ;GAAE,GADP,MAA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I,MAAM,mBAAmB,iBAAiB;EAGtD,MAAM,UAAsB,EAAE;EAC9B,MAAM,cAAc,gBAAgB,QAAQ,MAAM,aAAa;EAE/D,MAAM,iBAAiB,WAAmB,UAAqB;AAC7D,OAAI,QAAQ,UAAU,MAAO;GAE7B,IAAI,UAAU;AAGd,OAAI,CAAC,KAAK,YAAY,MAAM,EAAE;IAC5B,MAAM,WAAW,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,MAAM;AAE1E,SADoB,gBAAgB,WAAW,SAAS,aAAa,EACrD,SAAS,YAAY,CACnC,WAAU;;AAId,OAAI,QACF,SAAQ,KAAK,KAAK,gBAAgB,WAAW,MAAM,CAAC;AAItD,OAAI,KAAK,YAAY,MAAM,EAAE;IAC3B,MAAM,WAAW,KAAK,YAAY,MAAM;AACxC,SAAK,MAAM,SAAS,UAAU;AAC5B,SAAI,QAAQ,UAAU,MAAO;AAE7B,mBADkB,cAAc,MAAM,IAAI,MAAM,QAAQ,GAAG,UAAU,GAAG,MAAM,OACrD,MAAM,MAAM;;;;AAK3C,gBAAc,gBAAgB,UAAU;AAExC,SAAO;GACL,MAAM;GACN,SAAS,QAAQ,UAAU,QAAQ,8BAA8B,UAAU;GAC5E"}
package/package.json CHANGED
@@ -1,70 +1,56 @@
1
1
  {
2
2
  "name": "@aigne/afs-json",
3
- "version": "1.1.0",
3
+ "version": "1.11.0-beta",
4
4
  "description": "AIGNE AFS module for JSON and YAML file storage",
5
+ "license": "Elastic-2.0",
5
6
  "publishConfig": {
6
7
  "access": "public"
7
8
  },
8
- "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
9
- "homepage": "https://www.aigne.io/framework",
10
- "license": "Elastic-2.0",
9
+ "author": "Arcblock <blocklet@arcblock.io> https://github.com/arcblock",
10
+ "homepage": "https://github.com/arcblock/afs",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/AIGNE-io/aigne-framework"
13
+ "url": "git+https://github.com/arcblock/afs"
14
14
  },
15
15
  "bugs": {
16
- "url": "https://github.com/AIGNE-io/aigne-framework/issues"
16
+ "url": "https://github.com/arcblock/afs/issues"
17
17
  },
18
- "files": [
19
- "lib/cjs",
20
- "lib/dts",
21
- "lib/esm",
22
- "LICENSE",
23
- "README.md",
24
- "CHANGELOG.md"
25
- ],
26
18
  "type": "module",
27
- "main": "./lib/cjs/index.js",
28
- "module": "./lib/esm/index.js",
29
- "types": "./lib/dts/index.d.ts",
19
+ "main": "./dist/index.cjs",
20
+ "module": "./dist/index.mjs",
21
+ "types": "./dist/index.d.cts",
30
22
  "exports": {
31
23
  ".": {
32
- "import": "./lib/esm/index.js",
33
- "require": "./lib/cjs/index.js",
34
- "types": "./lib/dts/index.d.ts"
24
+ "require": "./dist/index.cjs",
25
+ "import": "./dist/index.mjs"
35
26
  },
36
- "./*": {
37
- "import": "./lib/esm/*",
38
- "require": "./lib/cjs/*",
39
- "types": "./lib/dts/*"
40
- }
41
- },
42
- "typesVersions": {
43
- "*": {
44
- ".": [
45
- "./lib/dts/index.d.ts"
46
- ]
47
- }
27
+ "./*": "./*"
48
28
  },
29
+ "files": [
30
+ "dist",
31
+ "LICENSE",
32
+ "README.md",
33
+ "CHANGELOG.md"
34
+ ],
49
35
  "dependencies": {
50
36
  "yaml": "^2.8.1",
51
37
  "zod": "^3.25.67",
52
- "@aigne/afs": "^1.4.0",
53
- "@aigne/core": "^1.72.0"
38
+ "@aigne/afs": "^1.11.0-beta"
54
39
  },
55
40
  "devDependencies": {
56
- "@types/bun": "^1.2.22",
41
+ "@types/bun": "^1.3.6",
57
42
  "npm-run-all": "^4.1.5",
58
- "rimraf": "^6.0.1",
59
- "typescript": "^5.9.2",
60
- "@aigne/test-utils": "^0.5.69"
43
+ "rimraf": "^6.1.2",
44
+ "tsdown": "0.20.0-beta.3",
45
+ "typescript": "5.9.2",
46
+ "@aigne/scripts": "0.0.0",
47
+ "@aigne/typescript-config": "0.0.0"
61
48
  },
62
49
  "scripts": {
63
- "lint": "tsc --noEmit",
64
- "build": "tsc --build scripts/tsconfig.build.json",
65
- "clean": "rimraf lib test/coverage",
50
+ "build": "tsdown",
51
+ "check-types": "tsc --noEmit",
52
+ "clean": "rimraf dist coverage",
66
53
  "test": "bun test",
67
- "test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text",
68
- "postbuild": "node ../../scripts/post-build-lib.mjs"
54
+ "test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text"
69
55
  }
70
56
  }