@fatagnus/dink-sdk 2.26.1 → 2.27.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.
@@ -0,0 +1,100 @@
1
+ import { NatsConnection } from 'nats';
2
+ import type { FileStat, DirEntry, TreeNode, SearchResult, EditOp, ActorInfo, WriteMode, ChangeEntry, DiffResult, ChangeEvent, WatchOptions, WatchSubscription, PushConfig } from './types.js';
3
+ /**
4
+ * Options for creating an EdgeFSClient.
5
+ */
6
+ export interface EdgeFSClientOptions {
7
+ /** NATS connection to use. */
8
+ nc: NatsConnection;
9
+ /** Filesystem identifier. */
10
+ fsID: string;
11
+ /** Request timeout in milliseconds (default: 30000). */
12
+ timeout?: number;
13
+ /** App ID for change-event subject (required for watch). */
14
+ appID?: string;
15
+ }
16
+ /**
17
+ * EdgeFSClient provides a typed TypeScript client for the EdgeFS NATS micro service.
18
+ *
19
+ * Each method sends a JSON request to the `edgefs.{Method}` NATS subject and
20
+ * parses the response, throwing on errors.
21
+ */
22
+ export declare class EdgeFSClient {
23
+ private readonly nc;
24
+ private readonly fsID;
25
+ private readonly timeout;
26
+ private readonly appID;
27
+ constructor(opts: EdgeFSClientOptions);
28
+ private rpc;
29
+ /** Get file or directory metadata. */
30
+ stat(path: string): Promise<FileStat>;
31
+ /** List entries in a directory, optionally filtered by a glob pattern. */
32
+ list(path: string, glob?: string): Promise<DirEntry[]>;
33
+ /** Get a recursive tree of the filesystem starting at `path`. */
34
+ tree(path: string, depth?: number): Promise<TreeNode>;
35
+ /** Search file contents by regex pattern. */
36
+ search(pattern: string, path?: string, glob?: string): Promise<SearchResult[]>;
37
+ /** Find files matching a glob pattern. */
38
+ find(glob: string, path?: string): Promise<string[]>;
39
+ /** Read a file's content. Returns `{ content, size }`. */
40
+ read(path: string, offset?: number, limit?: number): Promise<{
41
+ content: string;
42
+ size: number;
43
+ }>;
44
+ /** Read multiple files at once. Returns a map of path to content/error. */
45
+ readMulti(paths: string[]): Promise<Record<string, {
46
+ content?: string;
47
+ size?: number;
48
+ error?: string;
49
+ }>>;
50
+ /** Write content to a file. */
51
+ write(path: string, content: Uint8Array | string, actor: ActorInfo, opts?: {
52
+ mode?: WriteMode;
53
+ message?: string;
54
+ }): Promise<FileStat>;
55
+ /** Apply line-based edits to a file. */
56
+ edit(path: string, edits: EditOp[], actor: ActorInfo, message?: string): Promise<FileStat>;
57
+ /** Delete a file or directory. */
58
+ delete(path: string, actor: ActorInfo, recursive?: boolean): Promise<{
59
+ deleted: boolean;
60
+ }>;
61
+ /** Rename (move) a file or directory. */
62
+ rename(from: string, to: string, actor: ActorInfo): Promise<{
63
+ renamed: boolean;
64
+ }>;
65
+ /** Create a directory. */
66
+ mkdir(path: string, recursive?: boolean): Promise<{
67
+ created: boolean;
68
+ }>;
69
+ /** Get the change log for a path (or the whole filesystem). */
70
+ log(path?: string, limit?: number): Promise<ChangeEntry[]>;
71
+ /** Get a unified diff between two versions of a file. */
72
+ diff(path: string, versionA: number, versionB: number): Promise<DiffResult>;
73
+ /** Create a named snapshot of the filesystem. */
74
+ snapshot(message?: string, actor?: string): Promise<{
75
+ id: string;
76
+ }>;
77
+ /** Restore a file to a previous version. */
78
+ restore(path: string, version: number, actor: ActorInfo): Promise<FileStat>;
79
+ /** Configure Convex push sync for a filesystem. */
80
+ setPushConfig(fsID: string, convexSiteURL: string, pushSecret: string, enabled?: boolean): Promise<{
81
+ success: boolean;
82
+ }>;
83
+ /** Get the current push sync configuration for a filesystem. */
84
+ getPushConfig(fsID: string): Promise<PushConfig>;
85
+ /** Remove push sync configuration for a filesystem. */
86
+ deletePushConfig(fsID: string): Promise<{
87
+ success: boolean;
88
+ }>;
89
+ /**
90
+ * Watch for filesystem change events via NATS subscription.
91
+ *
92
+ * Events are published by the Go service to `edgefs.{appID}.{fsID}.changes`.
93
+ * Client-side filtering is applied based on the provided options.
94
+ *
95
+ * @param handler - Called for each matching change event.
96
+ * @param opts - Optional filters (path prefix, operation types).
97
+ * @returns A subscription handle with an `unsubscribe()` method.
98
+ */
99
+ watch(handler: (event: ChangeEvent) => void, opts?: WatchOptions): WatchSubscription;
100
+ }
@@ -0,0 +1,192 @@
1
+ import { StringCodec } from 'nats';
2
+ const sc = StringCodec();
3
+ /**
4
+ * EdgeFSClient provides a typed TypeScript client for the EdgeFS NATS micro service.
5
+ *
6
+ * Each method sends a JSON request to the `edgefs.{Method}` NATS subject and
7
+ * parses the response, throwing on errors.
8
+ */
9
+ export class EdgeFSClient {
10
+ nc;
11
+ fsID;
12
+ timeout;
13
+ appID;
14
+ constructor(opts) {
15
+ this.nc = opts.nc;
16
+ this.fsID = opts.fsID;
17
+ this.timeout = opts.timeout ?? 30000;
18
+ this.appID = opts.appID ?? '';
19
+ }
20
+ // ------------------------------------------------------------------
21
+ // Internal helper
22
+ // ------------------------------------------------------------------
23
+ async rpc(method, payload) {
24
+ const subject = `edgefs.${method}`;
25
+ const body = { fs: this.fsID, ...payload };
26
+ const msg = await this.nc.request(subject, sc.encode(JSON.stringify(body)), {
27
+ timeout: this.timeout,
28
+ });
29
+ const resp = JSON.parse(sc.decode(msg.data));
30
+ if (!resp.success) {
31
+ const code = resp.error?.code ?? 'unknown';
32
+ const message = resp.error?.message ?? 'Unknown EdgeFS error';
33
+ throw new Error(`EdgeFS ${method} failed [${code}]: ${message}`);
34
+ }
35
+ return resp.data;
36
+ }
37
+ // ------------------------------------------------------------------
38
+ // Mapping
39
+ // ------------------------------------------------------------------
40
+ /** Get file or directory metadata. */
41
+ async stat(path) {
42
+ return this.rpc('Stat', { path });
43
+ }
44
+ /** List entries in a directory, optionally filtered by a glob pattern. */
45
+ async list(path, glob) {
46
+ return this.rpc('List', { path, glob });
47
+ }
48
+ /** Get a recursive tree of the filesystem starting at `path`. */
49
+ async tree(path, depth) {
50
+ return this.rpc('Tree', { path, depth });
51
+ }
52
+ // ------------------------------------------------------------------
53
+ // Discovery
54
+ // ------------------------------------------------------------------
55
+ /** Search file contents by regex pattern. */
56
+ async search(pattern, path, glob) {
57
+ return this.rpc('Search', { pattern, path, glob });
58
+ }
59
+ /** Find files matching a glob pattern. */
60
+ async find(glob, path) {
61
+ return this.rpc('Find', { glob, path });
62
+ }
63
+ // ------------------------------------------------------------------
64
+ // Context (reading)
65
+ // ------------------------------------------------------------------
66
+ /** Read a file's content. Returns `{ content, size }`. */
67
+ async read(path, offset, limit) {
68
+ return this.rpc('Read', { path, offset, limit });
69
+ }
70
+ /** Read multiple files at once. Returns a map of path to content/error. */
71
+ async readMulti(paths) {
72
+ return this.rpc('ReadMulti', { paths });
73
+ }
74
+ // ------------------------------------------------------------------
75
+ // Execution (writing)
76
+ // ------------------------------------------------------------------
77
+ /** Write content to a file. */
78
+ async write(path, content, actor, opts) {
79
+ const raw = typeof content === 'string' ? new TextEncoder().encode(content) : content;
80
+ // Encode as base64 for JSON transport (Go side expects []byte → base64)
81
+ const b64 = btoa(String.fromCharCode(...raw));
82
+ return this.rpc('Write', {
83
+ path,
84
+ content: b64,
85
+ mode: opts?.mode,
86
+ actor,
87
+ message: opts?.message,
88
+ });
89
+ }
90
+ /** Apply line-based edits to a file. */
91
+ async edit(path, edits, actor, message) {
92
+ return this.rpc('Edit', { path, edits, actor, message });
93
+ }
94
+ /** Delete a file or directory. */
95
+ async delete(path, actor, recursive) {
96
+ return this.rpc('Delete', { path, actor, recursive });
97
+ }
98
+ /** Rename (move) a file or directory. */
99
+ async rename(from, to, actor) {
100
+ return this.rpc('Rename', { from, to, actor });
101
+ }
102
+ /** Create a directory. */
103
+ async mkdir(path, recursive) {
104
+ return this.rpc('Mkdir', { path, recursive });
105
+ }
106
+ // ------------------------------------------------------------------
107
+ // History
108
+ // ------------------------------------------------------------------
109
+ /** Get the change log for a path (or the whole filesystem). */
110
+ async log(path, limit) {
111
+ return this.rpc('Log', { path, limit });
112
+ }
113
+ /** Get a unified diff between two versions of a file. */
114
+ async diff(path, versionA, versionB) {
115
+ return this.rpc('Diff', { path, version_a: versionA, version_b: versionB });
116
+ }
117
+ /** Create a named snapshot of the filesystem. */
118
+ async snapshot(message, actor) {
119
+ return this.rpc('Snapshot', { message, actor });
120
+ }
121
+ /** Restore a file to a previous version. */
122
+ async restore(path, version, actor) {
123
+ return this.rpc('Restore', { path, version, actor });
124
+ }
125
+ // ------------------------------------------------------------------
126
+ // Reactivity
127
+ // ------------------------------------------------------------------
128
+ // ------------------------------------------------------------------
129
+ // Push Config
130
+ // ------------------------------------------------------------------
131
+ /** Configure Convex push sync for a filesystem. */
132
+ async setPushConfig(fsID, convexSiteURL, pushSecret, enabled = true) {
133
+ return this.rpc('SetPushConfig', {
134
+ fs_id: fsID,
135
+ convex_site_url: convexSiteURL,
136
+ push_secret: pushSecret,
137
+ enabled,
138
+ });
139
+ }
140
+ /** Get the current push sync configuration for a filesystem. */
141
+ async getPushConfig(fsID) {
142
+ return this.rpc('GetPushConfig', { fs_id: fsID });
143
+ }
144
+ /** Remove push sync configuration for a filesystem. */
145
+ async deletePushConfig(fsID) {
146
+ return this.rpc('DeletePushConfig', { fs_id: fsID });
147
+ }
148
+ /**
149
+ * Watch for filesystem change events via NATS subscription.
150
+ *
151
+ * Events are published by the Go service to `edgefs.{appID}.{fsID}.changes`.
152
+ * Client-side filtering is applied based on the provided options.
153
+ *
154
+ * @param handler - Called for each matching change event.
155
+ * @param opts - Optional filters (path prefix, operation types).
156
+ * @returns A subscription handle with an `unsubscribe()` method.
157
+ */
158
+ watch(handler, opts) {
159
+ if (!this.appID) {
160
+ throw new Error('EdgeFSClient: appID is required for watch()');
161
+ }
162
+ const subject = `edgefs.${this.appID}.${this.fsID}.changes`;
163
+ let sub = null;
164
+ sub = this.nc.subscribe(subject, {
165
+ callback: (_err, msg) => {
166
+ if (_err)
167
+ return;
168
+ try {
169
+ const event = JSON.parse(sc.decode(msg.data));
170
+ // Client-side filtering
171
+ if (opts?.pathPrefix && !event.path.startsWith(opts.pathPrefix)) {
172
+ return;
173
+ }
174
+ if (opts?.operations && opts.operations.length > 0 && !opts.operations.includes(event.operation)) {
175
+ return;
176
+ }
177
+ handler(event);
178
+ }
179
+ catch {
180
+ // Ignore malformed events
181
+ }
182
+ },
183
+ });
184
+ return {
185
+ unsubscribe: () => {
186
+ sub?.unsubscribe();
187
+ sub = null;
188
+ },
189
+ };
190
+ }
191
+ }
192
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/edgefs/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAA2B,MAAM,MAAM,CAAC;AAiB5E,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;AAyBzB;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IACP,EAAE,CAAiB;IACnB,IAAI,CAAS;IACb,OAAO,CAAS;IAChB,KAAK,CAAS;IAE/B,YAAY,IAAyB;QACpC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;IAC/B,CAAC;IAED,qEAAqE;IACrE,kBAAkB;IAClB,qEAAqE;IAE7D,KAAK,CAAC,GAAG,CAAI,MAAc,EAAE,OAAgC;QACpE,MAAM,OAAO,GAAG,UAAU,MAAM,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC;QAC3C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE;YAC3E,OAAO,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,IA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AAE,OAAO;gBACjB,IAAI,CAAC;oBACJ,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAgB,CAAC;oBAE7D,wBAAwB;oBACxB,IAAI,IAAI,EAAE,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;wBACjE,OAAO;oBACR,CAAC;oBACD,IAAI,IAAI,EAAE,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;wBAClG,OAAO;oBACR,CAAC;oBAED,OAAO,CAAC,KAAK,CAAC,CAAC;gBAChB,CAAC;gBAAC,MAAM,CAAC;oBACR,0BAA0B;gBAC3B,CAAC;YACF,CAAC;SACD,CAAC,CAAC;QAEH,OAAO;YACN,WAAW,EAAE,GAAG,EAAE;gBACjB,GAAG,EAAE,WAAW,EAAE,CAAC;gBACnB,GAAG,GAAG,IAAI,CAAC;YACZ,CAAC;SACD,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,3 @@
1
+ export { EdgeFSClient, type EdgeFSClientOptions } from './client.js';
2
+ export { WriteMode } from './types.js';
3
+ export type { FileStat, DirEntry, TreeNode, SearchResult, EditOp, ActorInfo, ChangeEntry, DiffResult, ChangeEvent, WatchOptions, WatchSubscription, PushConfig, } from './types.js';
@@ -0,0 +1,3 @@
1
+ export { EdgeFSClient } from './client.js';
2
+ export { WriteMode } from './types.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/edgefs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA4B,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Write mode for file operations.
3
+ */
4
+ export declare enum WriteMode {
5
+ /** Replace the entire file contents. */
6
+ Overwrite = 0,
7
+ /** Append data to the end of the file. */
8
+ Append = 1
9
+ }
10
+ /**
11
+ * File or directory metadata.
12
+ */
13
+ export interface FileStat {
14
+ path: string;
15
+ size: number;
16
+ is_dir: boolean;
17
+ mode: number;
18
+ mod_time: string;
19
+ ino?: number;
20
+ nlink?: number;
21
+ }
22
+ /**
23
+ * An entry in a directory listing.
24
+ */
25
+ export interface DirEntry {
26
+ name: string;
27
+ size: number;
28
+ is_dir: boolean;
29
+ mode: number;
30
+ }
31
+ /**
32
+ * A node in a filesystem tree.
33
+ */
34
+ export interface TreeNode {
35
+ name: string;
36
+ path: string;
37
+ is_dir: boolean;
38
+ size: number;
39
+ children?: TreeNode[];
40
+ }
41
+ /**
42
+ * A match found by a content search.
43
+ */
44
+ export interface SearchResult {
45
+ path: string;
46
+ line: number;
47
+ content: string;
48
+ }
49
+ /**
50
+ * A single edit operation (line-based replacement).
51
+ */
52
+ export interface EditOp {
53
+ start_line: number;
54
+ end_line: number;
55
+ new_text: string;
56
+ }
57
+ /**
58
+ * Identifies who performed an operation.
59
+ */
60
+ export interface ActorInfo {
61
+ id: string;
62
+ type: string;
63
+ }
64
+ /**
65
+ * A single version change record for a file.
66
+ */
67
+ export interface ChangeEntry {
68
+ id: number;
69
+ path: string;
70
+ version: number;
71
+ operation: string;
72
+ actor: string;
73
+ actor_type: string;
74
+ message?: string;
75
+ data_hash: string;
76
+ metadata?: string;
77
+ created_at: string;
78
+ }
79
+ /**
80
+ * A unified diff between two versions of a file.
81
+ */
82
+ export interface DiffResult {
83
+ path: string;
84
+ version_a: number;
85
+ version_b: number;
86
+ unified: string;
87
+ }
88
+ /**
89
+ * A filesystem change event published via NATS.
90
+ */
91
+ export interface ChangeEvent {
92
+ fs_id: string;
93
+ path: string;
94
+ operation: string;
95
+ actor?: string;
96
+ actor_type?: string;
97
+ timestamp: number;
98
+ content?: string;
99
+ content_hash?: string;
100
+ size?: number;
101
+ }
102
+ /**
103
+ * Options for the watch method.
104
+ */
105
+ export interface WatchOptions {
106
+ /** Only receive events for paths matching this prefix. */
107
+ pathPrefix?: string;
108
+ /** Only receive events for these operations (e.g., "write", "delete"). */
109
+ operations?: string[];
110
+ }
111
+ /**
112
+ * A watch subscription handle.
113
+ */
114
+ export interface WatchSubscription {
115
+ unsubscribe(): void;
116
+ }
117
+ /**
118
+ * Per-filesystem push sync configuration.
119
+ */
120
+ export interface PushConfig {
121
+ fs_id: string;
122
+ convex_site_url: string;
123
+ push_secret: string;
124
+ enabled: boolean;
125
+ created_at: string;
126
+ updated_at: string;
127
+ }
@@ -0,0 +1,13 @@
1
+ // EdgeFS TypeScript SDK types
2
+ // These types mirror the Go types in pkg/edgefs/types.go and pkg/edgefs/history_types.go
3
+ /**
4
+ * Write mode for file operations.
5
+ */
6
+ export var WriteMode;
7
+ (function (WriteMode) {
8
+ /** Replace the entire file contents. */
9
+ WriteMode[WriteMode["Overwrite"] = 0] = "Overwrite";
10
+ /** Append data to the end of the file. */
11
+ WriteMode[WriteMode["Append"] = 1] = "Append";
12
+ })(WriteMode || (WriteMode = {}));
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/edgefs/types.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,yFAAyF;AAEzF;;GAEG;AACH,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACpB,wCAAwC;IACxC,mDAAa,CAAA;IACb,0CAA0C;IAC1C,6CAAU,CAAA;AACX,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ import { NatsConnection } from 'nats';
4
+
3
5
  /**
4
6
  * Service definition metadata
5
7
  */
@@ -1125,5 +1127,230 @@ export declare class ConfigError extends DinkError {
1125
1127
  export declare class WebhookError extends DinkError {
1126
1128
  constructor(message: string, code?: string);
1127
1129
  }
1130
+ /**
1131
+ * Write mode for file operations.
1132
+ */
1133
+ export declare enum WriteMode {
1134
+ /** Replace the entire file contents. */
1135
+ Overwrite = 0,
1136
+ /** Append data to the end of the file. */
1137
+ Append = 1
1138
+ }
1139
+ /**
1140
+ * File or directory metadata.
1141
+ */
1142
+ export interface FileStat {
1143
+ path: string;
1144
+ size: number;
1145
+ is_dir: boolean;
1146
+ mode: number;
1147
+ mod_time: string;
1148
+ ino?: number;
1149
+ nlink?: number;
1150
+ }
1151
+ /**
1152
+ * An entry in a directory listing.
1153
+ */
1154
+ export interface DirEntry {
1155
+ name: string;
1156
+ size: number;
1157
+ is_dir: boolean;
1158
+ mode: number;
1159
+ }
1160
+ /**
1161
+ * A node in a filesystem tree.
1162
+ */
1163
+ export interface TreeNode {
1164
+ name: string;
1165
+ path: string;
1166
+ is_dir: boolean;
1167
+ size: number;
1168
+ children?: TreeNode[];
1169
+ }
1170
+ /**
1171
+ * A match found by a content search.
1172
+ */
1173
+ export interface SearchResult {
1174
+ path: string;
1175
+ line: number;
1176
+ content: string;
1177
+ }
1178
+ /**
1179
+ * A single edit operation (line-based replacement).
1180
+ */
1181
+ export interface EditOp {
1182
+ start_line: number;
1183
+ end_line: number;
1184
+ new_text: string;
1185
+ }
1186
+ /**
1187
+ * Identifies who performed an operation.
1188
+ */
1189
+ export interface ActorInfo {
1190
+ id: string;
1191
+ type: string;
1192
+ }
1193
+ /**
1194
+ * A single version change record for a file.
1195
+ */
1196
+ export interface ChangeEntry {
1197
+ id: number;
1198
+ path: string;
1199
+ version: number;
1200
+ operation: string;
1201
+ actor: string;
1202
+ actor_type: string;
1203
+ message?: string;
1204
+ data_hash: string;
1205
+ metadata?: string;
1206
+ created_at: string;
1207
+ }
1208
+ /**
1209
+ * A unified diff between two versions of a file.
1210
+ */
1211
+ export interface DiffResult {
1212
+ path: string;
1213
+ version_a: number;
1214
+ version_b: number;
1215
+ unified: string;
1216
+ }
1217
+ /**
1218
+ * A filesystem change event published via NATS.
1219
+ */
1220
+ export interface ChangeEvent {
1221
+ fs_id: string;
1222
+ path: string;
1223
+ operation: string;
1224
+ actor?: string;
1225
+ actor_type?: string;
1226
+ timestamp: number;
1227
+ content?: string;
1228
+ content_hash?: string;
1229
+ size?: number;
1230
+ }
1231
+ /**
1232
+ * Options for the watch method.
1233
+ */
1234
+ export interface WatchOptions {
1235
+ /** Only receive events for paths matching this prefix. */
1236
+ pathPrefix?: string;
1237
+ /** Only receive events for these operations (e.g., "write", "delete"). */
1238
+ operations?: string[];
1239
+ }
1240
+ /**
1241
+ * A watch subscription handle.
1242
+ */
1243
+ export interface WatchSubscription {
1244
+ unsubscribe(): void;
1245
+ }
1246
+ /**
1247
+ * Per-filesystem push sync configuration.
1248
+ */
1249
+ export interface PushConfig {
1250
+ fs_id: string;
1251
+ convex_site_url: string;
1252
+ push_secret: string;
1253
+ enabled: boolean;
1254
+ created_at: string;
1255
+ updated_at: string;
1256
+ }
1257
+ /**
1258
+ * Options for creating an EdgeFSClient.
1259
+ */
1260
+ export interface EdgeFSClientOptions {
1261
+ /** NATS connection to use. */
1262
+ nc: NatsConnection;
1263
+ /** Filesystem identifier. */
1264
+ fsID: string;
1265
+ /** Request timeout in milliseconds (default: 30000). */
1266
+ timeout?: number;
1267
+ /** App ID for change-event subject (required for watch). */
1268
+ appID?: string;
1269
+ }
1270
+ /**
1271
+ * EdgeFSClient provides a typed TypeScript client for the EdgeFS NATS micro service.
1272
+ *
1273
+ * Each method sends a JSON request to the `edgefs.{Method}` NATS subject and
1274
+ * parses the response, throwing on errors.
1275
+ */
1276
+ export declare class EdgeFSClient {
1277
+ private readonly nc;
1278
+ private readonly fsID;
1279
+ private readonly timeout;
1280
+ private readonly appID;
1281
+ constructor(opts: EdgeFSClientOptions);
1282
+ private rpc;
1283
+ /** Get file or directory metadata. */
1284
+ stat(path: string): Promise<FileStat>;
1285
+ /** List entries in a directory, optionally filtered by a glob pattern. */
1286
+ list(path: string, glob?: string): Promise<DirEntry[]>;
1287
+ /** Get a recursive tree of the filesystem starting at `path`. */
1288
+ tree(path: string, depth?: number): Promise<TreeNode>;
1289
+ /** Search file contents by regex pattern. */
1290
+ search(pattern: string, path?: string, glob?: string): Promise<SearchResult[]>;
1291
+ /** Find files matching a glob pattern. */
1292
+ find(glob: string, path?: string): Promise<string[]>;
1293
+ /** Read a file's content. Returns `{ content, size }`. */
1294
+ read(path: string, offset?: number, limit?: number): Promise<{
1295
+ content: string;
1296
+ size: number;
1297
+ }>;
1298
+ /** Read multiple files at once. Returns a map of path to content/error. */
1299
+ readMulti(paths: string[]): Promise<Record<string, {
1300
+ content?: string;
1301
+ size?: number;
1302
+ error?: string;
1303
+ }>>;
1304
+ /** Write content to a file. */
1305
+ write(path: string, content: Uint8Array | string, actor: ActorInfo, opts?: {
1306
+ mode?: WriteMode;
1307
+ message?: string;
1308
+ }): Promise<FileStat>;
1309
+ /** Apply line-based edits to a file. */
1310
+ edit(path: string, edits: EditOp[], actor: ActorInfo, message?: string): Promise<FileStat>;
1311
+ /** Delete a file or directory. */
1312
+ delete(path: string, actor: ActorInfo, recursive?: boolean): Promise<{
1313
+ deleted: boolean;
1314
+ }>;
1315
+ /** Rename (move) a file or directory. */
1316
+ rename(from: string, to: string, actor: ActorInfo): Promise<{
1317
+ renamed: boolean;
1318
+ }>;
1319
+ /** Create a directory. */
1320
+ mkdir(path: string, recursive?: boolean): Promise<{
1321
+ created: boolean;
1322
+ }>;
1323
+ /** Get the change log for a path (or the whole filesystem). */
1324
+ log(path?: string, limit?: number): Promise<ChangeEntry[]>;
1325
+ /** Get a unified diff between two versions of a file. */
1326
+ diff(path: string, versionA: number, versionB: number): Promise<DiffResult>;
1327
+ /** Create a named snapshot of the filesystem. */
1328
+ snapshot(message?: string, actor?: string): Promise<{
1329
+ id: string;
1330
+ }>;
1331
+ /** Restore a file to a previous version. */
1332
+ restore(path: string, version: number, actor: ActorInfo): Promise<FileStat>;
1333
+ /** Configure Convex push sync for a filesystem. */
1334
+ setPushConfig(fsID: string, convexSiteURL: string, pushSecret: string, enabled?: boolean): Promise<{
1335
+ success: boolean;
1336
+ }>;
1337
+ /** Get the current push sync configuration for a filesystem. */
1338
+ getPushConfig(fsID: string): Promise<PushConfig>;
1339
+ /** Remove push sync configuration for a filesystem. */
1340
+ deletePushConfig(fsID: string): Promise<{
1341
+ success: boolean;
1342
+ }>;
1343
+ /**
1344
+ * Watch for filesystem change events via NATS subscription.
1345
+ *
1346
+ * Events are published by the Go service to `edgefs.{appID}.{fsID}.changes`.
1347
+ * Client-side filtering is applied based on the provided options.
1348
+ *
1349
+ * @param handler - Called for each matching change event.
1350
+ * @param opts - Optional filters (path prefix, operation types).
1351
+ * @returns A subscription handle with an `unsubscribe()` method.
1352
+ */
1353
+ watch(handler: (event: ChangeEvent) => void, opts?: WatchOptions): WatchSubscription;
1354
+ }
1128
1355
 
1129
1356
  export {};
package/dist/index.js CHANGED
@@ -12,4 +12,6 @@ export { CenterClient } from './center/index.js';
12
12
  export { loadDinkEnv, DinkEnvError } from './env/index.js';
13
13
  // Export error types
14
14
  export { DinkError, ConnectionError, AuthError, ServiceError, TimeoutError, ConfigError, WebhookError } from './errors.js';
15
+ // Export EdgeFS client for filesystem operations on the edge
16
+ export * from './edgefs/index.js';
15
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,2EAA2E;AAuB3E,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1D,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAsB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAsE,MAAM,kBAAkB,CAAC;AAExH,qEAAqE;AACrE,OAAO,EAAE,YAAY,EAAsB,MAAM,mBAAmB,CAAC;AAErE,sDAAsD;AACtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAkC,MAAM,gBAAgB,CAAC;AAE3F,qBAAqB;AACrB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,2EAA2E;AAuB3E,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1D,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAsB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAsE,MAAM,kBAAkB,CAAC;AAExH,qEAAqE;AACrE,OAAO,EAAE,YAAY,EAAsB,MAAM,mBAAmB,CAAC;AAErE,sDAAsD;AACtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAkC,MAAM,gBAAgB,CAAC;AAE3F,qBAAqB;AACrB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1H,6DAA6D;AAC7D,cAAc,mBAAmB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fatagnus/dink-sdk",
3
- "version": "2.26.1",
3
+ "version": "2.27.2",
4
4
  "description": "TypeScript SDK for Dink edge mesh platform",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -25,6 +25,10 @@
25
25
  "./env": {
26
26
  "types": "./dist/env/index.d.ts",
27
27
  "import": "./dist/env/index.js"
28
+ },
29
+ "./edgefs": {
30
+ "types": "./dist/edgefs/index.d.ts",
31
+ "import": "./dist/edgefs/index.js"
28
32
  }
29
33
  },
30
34
  "typesVersions": {
@@ -38,6 +42,9 @@
38
42
  "env": [
39
43
  "dist/env/index.d.ts"
40
44
  ],
45
+ "edgefs": [
46
+ "dist/edgefs/index.d.ts"
47
+ ],
41
48
  "types": [
42
49
  "dist/types.d.ts"
43
50
  ]