@helia/mfs 5.1.0 → 6.0.0-9c67dbd4

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.
@@ -28,6 +28,7 @@
28
28
  */
29
29
  import { CID } from 'multiformats/cid';
30
30
  import type { AddOptions, CatOptions, ChmodOptions, CpOptions, LsOptions, MkdirOptions as UnixFsMkdirOptions, RmOptions as UnixFsRmOptions, StatOptions, TouchOptions, FileStats, DirectoryStats, RawStats, ExtendedStatOptions, ExtendedFileStats, ExtendedDirectoryStats, ExtendedRawStats } from '@helia/unixfs';
31
+ import type { ComponentLogger } from '@libp2p/interface';
31
32
  import type { Blockstore } from 'interface-blockstore';
32
33
  import type { Datastore } from 'interface-datastore';
33
34
  import type { Mtime } from 'ipfs-unixfs';
@@ -36,6 +37,7 @@ import type { ByteStream } from 'ipfs-unixfs-importer';
36
37
  export interface MFSComponents {
37
38
  blockstore: Blockstore;
38
39
  datastore: Datastore;
40
+ logger: ComponentLogger;
39
41
  }
40
42
  export interface MFSInit {
41
43
  /**
@@ -218,5 +220,6 @@ export interface MFS {
218
220
  export declare function mfs(helia: {
219
221
  blockstore: Blockstore;
220
222
  datastore: Datastore;
223
+ logger: ComponentLogger;
221
224
  }, init?: MFSInit): MFS;
222
225
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAOH,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAEtC,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,IAAI,kBAAkB,EAAE,SAAS,IAAI,eAAe,EAAE,WAAW,EAAE,YAAY,EAAU,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,sBAAsB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,CAAE,KAAK,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,EAAE,IAAI,GAAE,OAAY,GAAG,GAAG,CAE9H"}
package/dist/src/index.js CHANGED
@@ -26,288 +26,12 @@
26
26
  * }
27
27
  * ```
28
28
  */
29
- import { unixfs } from '@helia/unixfs';
30
- import { AlreadyExistsError, DoesNotExistError, InvalidParametersError, NotADirectoryError } from '@helia/unixfs/errors';
31
- import { logger } from '@libp2p/logger';
32
- import { Key } from 'interface-datastore';
33
- import { UnixFS as IPFSUnixFS } from 'ipfs-unixfs';
34
29
  import { CID } from 'multiformats/cid';
35
- import { basename } from './utils/basename.js';
36
- const log = logger('helia:mfs');
37
- class DefaultMFS {
38
- components;
39
- unixfs;
40
- root;
41
- key;
42
- constructor(components, init = {}) {
43
- this.components = components;
44
- // spellchecker:disable-next-line
45
- this.key = new Key(init.key ?? '/locals/filesroot');
46
- this.unixfs = unixfs(components);
47
- }
48
- async #getRootCID() {
49
- if (this.root == null) {
50
- try {
51
- const buf = await this.components.datastore.get(this.key);
52
- this.root = CID.decode(buf);
53
- }
54
- catch (err) {
55
- if (err.name !== 'NotFoundError') {
56
- throw err;
57
- }
58
- this.root = await this.unixfs.addDirectory();
59
- }
60
- }
61
- return this.root;
62
- }
63
- async writeBytes(bytes, path, options) {
64
- const cid = await this.unixfs.addBytes(bytes, options);
65
- await this.cp(cid, path, options);
66
- if (options?.mode != null) {
67
- await this.chmod(path, options.mode, options);
68
- }
69
- if (options?.mtime != null) {
70
- await this.touch(path, options);
71
- }
72
- }
73
- async writeByteStream(bytes, path, options) {
74
- const cid = await this.unixfs.addByteStream(bytes, options);
75
- await this.cp(cid, path, options);
76
- if (options?.mode != null) {
77
- await this.chmod(path, options.mode, options);
78
- }
79
- if (options?.mtime != null) {
80
- await this.touch(path, options);
81
- }
82
- }
83
- async *cat(path, options = {}) {
84
- const root = await this.#getRootCID();
85
- const trail = await this.#walkPath(root, path, {
86
- ...options,
87
- createMissingDirectories: false,
88
- finalSegmentMustBeDirectory: false
89
- });
90
- yield* this.unixfs.cat(trail[trail.length - 1].cid, options);
91
- }
92
- async chmod(path, mode, options = {}) {
93
- const root = await this.#getRootCID();
94
- this.root = await this.unixfs.chmod(root, mode, {
95
- ...options,
96
- path
97
- });
98
- }
99
- async cp(source, destination, options) {
100
- const root = await this.#getRootCID();
101
- const force = options?.force ?? false;
102
- if (typeof source === 'string') {
103
- const stat = await this.stat(source, options);
104
- source = stat.cid;
105
- }
106
- if (!force) {
107
- await this.#ensurePathDoesNotExist(destination, options);
108
- }
109
- const fileName = basename(destination);
110
- const containingDirectory = destination.substring(0, destination.length - `/${fileName}`.length);
111
- let trail = [{
112
- cid: root,
113
- name: ''
114
- }];
115
- if (containingDirectory !== '') {
116
- trail = await this.#walkPath(root, containingDirectory, {
117
- ...options,
118
- createMissingDirectories: options?.force ?? false,
119
- finalSegmentMustBeDirectory: true
120
- });
121
- }
122
- trail.push({
123
- cid: source,
124
- name: fileName
125
- });
126
- this.root = await this.#persistPath(trail, options);
127
- }
128
- async *ls(path, options) {
129
- const root = await this.#getRootCID();
130
- if (options?.path != null) {
131
- path = `${path}/${options.path}`;
132
- }
133
- yield* this.unixfs.ls(root, {
134
- ...options,
135
- path
136
- });
137
- }
138
- async mkdir(path, options) {
139
- const force = options?.force ?? false;
140
- if (!force) {
141
- await this.#ensurePathDoesNotExist(path, options);
142
- }
143
- const dirName = basename(path);
144
- const containingDirectory = path.substring(0, path.length - `/${dirName}`.length);
145
- const root = await this.#getRootCID();
146
- let trail = [{
147
- cid: root,
148
- name: ''
149
- }];
150
- if (containingDirectory !== '') {
151
- trail = await this.#walkPath(root, containingDirectory, {
152
- ...options,
153
- createMissingDirectories: force,
154
- finalSegmentMustBeDirectory: true
155
- });
156
- }
157
- trail.push({
158
- cid: await this.unixfs.addDirectory({
159
- mode: options?.mode,
160
- mtime: options?.mtime
161
- }, options),
162
- name: basename(path)
163
- });
164
- this.root = await this.#persistPath(trail, options);
165
- }
166
- async rm(path, options) {
167
- const force = options?.force ?? false;
168
- if (!force) {
169
- await this.#ensurePathExists(path, options);
170
- }
171
- const root = await this.#getRootCID();
172
- const trail = await this.#walkPath(root, path, {
173
- ...options,
174
- createMissingDirectories: false,
175
- finalSegmentMustBeDirectory: false
176
- });
177
- const lastSegment = trail.pop();
178
- if (lastSegment == null) {
179
- throw new InvalidParametersError('path was too short');
180
- }
181
- // remove directory entry
182
- const containingDir = trail[trail.length - 1];
183
- containingDir.cid = await this.unixfs.rm(containingDir.cid, lastSegment.name, options);
184
- this.root = await this.#persistPath(trail, options);
185
- }
186
- async stat(path, options) {
187
- const root = await this.#getRootCID();
188
- const trail = await this.#walkPath(root, path, {
189
- ...options,
190
- createMissingDirectories: false,
191
- finalSegmentMustBeDirectory: false
192
- });
193
- const finalEntry = trail.pop();
194
- if (finalEntry == null) {
195
- throw new DoesNotExistError();
196
- }
197
- return this.unixfs.stat(finalEntry.cid, options);
198
- }
199
- async touch(path, options) {
200
- const root = await this.#getRootCID();
201
- const trail = await this.#walkPath(root, path, {
202
- ...options,
203
- createMissingDirectories: false,
204
- finalSegmentMustBeDirectory: false
205
- });
206
- const finalEntry = trail[trail.length - 1];
207
- if (finalEntry == null) {
208
- throw new DoesNotExistError();
209
- }
210
- finalEntry.cid = await this.unixfs.touch(finalEntry.cid, options);
211
- this.root = await this.#persistPath(trail, options);
212
- }
213
- async #walkPath(root, path, opts) {
214
- if (!path.startsWith('/')) {
215
- throw new InvalidParametersError('path must be absolute');
216
- }
217
- const stat = await this.unixfs.stat(root, {
218
- ...opts,
219
- offline: true
220
- });
221
- const output = [{
222
- cid: root,
223
- name: '',
224
- unixfs: stat.unixfs
225
- }];
226
- let cid = root;
227
- const parts = path.split('/').filter(Boolean);
228
- for (let i = 0; i < parts.length; i++) {
229
- const segment = parts[i];
230
- try {
231
- const stat = await this.unixfs.stat(cid, {
232
- ...opts,
233
- offline: true,
234
- path: segment
235
- });
236
- output.push({
237
- cid: stat.cid,
238
- name: segment,
239
- unixfs: stat.unixfs
240
- });
241
- cid = stat.cid;
242
- }
243
- catch (err) {
244
- log.error('could not resolve path segment %s of %s under %c', segment, path, root);
245
- if (opts.createMissingDirectories) {
246
- const cid = await this.unixfs.addDirectory();
247
- output.push({
248
- cid,
249
- name: segment,
250
- unixfs: new IPFSUnixFS({ type: 'directory' })
251
- });
252
- }
253
- else {
254
- throw new DoesNotExistError(`${path} does not exist`);
255
- }
256
- }
257
- }
258
- const lastSegment = output[output.length - 1];
259
- if (opts.finalSegmentMustBeDirectory && lastSegment.unixfs?.isDirectory() !== true) {
260
- throw new NotADirectoryError(`${path} was not a directory`);
261
- }
262
- return output;
263
- }
264
- async #persistPath(path, options = {}) {
265
- let child = path.pop();
266
- if (child == null) {
267
- throw new InvalidParametersError('path was too short');
268
- }
269
- let cid = child.cid;
270
- for (let i = path.length - 1; i > -1; i--) {
271
- const segment = path[i];
272
- segment.cid = await this.unixfs.cp(child.cid, segment.cid, child.name, {
273
- ...options,
274
- force: true
275
- });
276
- child = segment;
277
- cid = segment.cid;
278
- }
279
- await this.components.datastore.put(this.key, cid.bytes, options);
280
- return cid;
281
- }
282
- async #ensurePathExists(path, options = {}) {
283
- const exists = await this.#pathExists(path, options);
284
- if (!exists) {
285
- throw new DoesNotExistError();
286
- }
287
- }
288
- async #ensurePathDoesNotExist(path, options = {}) {
289
- const exists = await this.#pathExists(path, options);
290
- if (exists) {
291
- throw new AlreadyExistsError();
292
- }
293
- }
294
- async #pathExists(path, options = {}) {
295
- try {
296
- await this.stat(path, {
297
- ...options,
298
- offline: true
299
- });
300
- return true;
301
- }
302
- catch {
303
- return false;
304
- }
305
- }
306
- }
30
+ import { MFS as MFSClass } from './mfs.js';
307
31
  /**
308
32
  * Create a {@link MFS} instance powered by {@link https://github.com/ipfs/helia Helia}
309
33
  */
310
34
  export function mfs(helia, init = {}) {
311
- return new DefaultMFS(helia, init);
35
+ return new MFSClass(helia, init);
312
36
  }
313
37
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAS9C,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;AA8M/B,MAAM,UAAU;IACG,UAAU,CAAe;IACzB,MAAM,CAAQ;IACvB,IAAI,CAAM;IACD,GAAG,CAAK;IAEzB,YAAa,UAAyB,EAAE,OAAgB,EAAE;QACxD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAE5B,iCAAiC;QACjC,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAA;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;IAClC,CAAC;IAED,KAAK,CAAC,WAAW;QACf,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBACzD,IAAI,CAAC,IAAI,GAAG,GAAG,CAA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CAAC,CAAA;AAClC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { CID } from 'multiformats/cid';
2
+ import type { MFSComponents, MFSInit, MFS as MFSInterface, MkdirOptions, RmOptions, WriteOptions } from './index.js';
3
+ import type { CatOptions, ChmodOptions, CpOptions, LsOptions, StatOptions, TouchOptions, FileStats, DirectoryStats, RawStats, ExtendedStatOptions, ExtendedFileStats, ExtendedDirectoryStats, ExtendedRawStats } from '@helia/unixfs';
4
+ import type { UnixFSEntry } from 'ipfs-unixfs-exporter';
5
+ import type { ByteStream } from 'ipfs-unixfs-importer';
6
+ export declare class MFS implements MFSInterface {
7
+ #private;
8
+ private readonly components;
9
+ private readonly unixfs;
10
+ private root?;
11
+ private readonly key;
12
+ private readonly log;
13
+ constructor(components: MFSComponents, init?: MFSInit);
14
+ writeBytes(bytes: Uint8Array, path: string, options?: Partial<WriteOptions>): Promise<void>;
15
+ writeByteStream(bytes: ByteStream, path: string, options?: Partial<WriteOptions>): Promise<void>;
16
+ cat(path: string, options?: Partial<CatOptions>): AsyncIterable<Uint8Array>;
17
+ chmod(path: string, mode: number, options?: Partial<ChmodOptions>): Promise<void>;
18
+ cp(source: CID | string, destination: string, options?: Partial<CpOptions>): Promise<void>;
19
+ ls(path?: string, options?: Partial<LsOptions>): AsyncIterable<UnixFSEntry>;
20
+ mkdir(path: string, options?: Partial<MkdirOptions>): Promise<void>;
21
+ rm(path: string, options?: Partial<RmOptions>): Promise<void>;
22
+ stat(path: string, options?: StatOptions): Promise<FileStats | DirectoryStats | RawStats>;
23
+ stat(path: string, options?: ExtendedStatOptions): Promise<ExtendedFileStats | ExtendedDirectoryStats | ExtendedRawStats>;
24
+ touch(path: string, options?: Partial<TouchOptions>): Promise<void>;
25
+ }
26
+ //# sourceMappingURL=mfs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mfs.d.ts","sourceRoot":"","sources":["../../src/mfs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,MAA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,OAAO,CAAC,YAAY,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAStF,EAAE,CAAE,MAAM,EAAE,GAAG,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAsCzF,EAAE,CAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC,WAAW,CAAC;IAa9E,KAAK,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCpE,EAAE,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA4B9D,IAAI,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,GAAG,cAAc,GAAG,QAAQ,CAAC;IAC1F,IAAI,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,iBAAiB,GAAG,sBAAsB,GAAG,gBAAgB,CAAC;IAmB1H,KAAK,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAsI3E"}
@@ -0,0 +1,279 @@
1
+ import { unixfs } from '@helia/unixfs';
2
+ import { AlreadyExistsError, DoesNotExistError, InvalidParametersError, NotADirectoryError } from '@helia/unixfs/errors';
3
+ import { Key } from 'interface-datastore';
4
+ import { UnixFS as IPFSUnixFS } from 'ipfs-unixfs';
5
+ import { CID } from 'multiformats/cid';
6
+ import { basename } from './utils/basename.js';
7
+ export class MFS {
8
+ components;
9
+ unixfs;
10
+ root;
11
+ key;
12
+ log;
13
+ constructor(components, init = {}) {
14
+ this.components = components;
15
+ this.log = components.logger.forComponent('helia:mfs');
16
+ // spellchecker:disable-next-line
17
+ this.key = new Key(init.key ?? '/locals/filesroot');
18
+ this.unixfs = unixfs(components);
19
+ }
20
+ async #getRootCID() {
21
+ if (this.root == null) {
22
+ try {
23
+ const buf = await this.components.datastore.get(this.key);
24
+ this.root = CID.decode(buf);
25
+ }
26
+ catch (err) {
27
+ if (err.name !== 'NotFoundError') {
28
+ throw err;
29
+ }
30
+ this.root = await this.unixfs.addDirectory();
31
+ }
32
+ }
33
+ return this.root;
34
+ }
35
+ async writeBytes(bytes, path, options) {
36
+ const cid = await this.unixfs.addBytes(bytes, options);
37
+ await this.cp(cid, path, options);
38
+ if (options?.mode != null) {
39
+ await this.chmod(path, options.mode, options);
40
+ }
41
+ if (options?.mtime != null) {
42
+ await this.touch(path, options);
43
+ }
44
+ }
45
+ async writeByteStream(bytes, path, options) {
46
+ const cid = await this.unixfs.addByteStream(bytes, options);
47
+ await this.cp(cid, path, options);
48
+ if (options?.mode != null) {
49
+ await this.chmod(path, options.mode, options);
50
+ }
51
+ if (options?.mtime != null) {
52
+ await this.touch(path, options);
53
+ }
54
+ }
55
+ async *cat(path, options = {}) {
56
+ const root = await this.#getRootCID();
57
+ const trail = await this.#walkPath(root, path, {
58
+ ...options,
59
+ createMissingDirectories: false,
60
+ finalSegmentMustBeDirectory: false
61
+ });
62
+ yield* this.unixfs.cat(trail[trail.length - 1].cid, options);
63
+ }
64
+ async chmod(path, mode, options = {}) {
65
+ const root = await this.#getRootCID();
66
+ this.root = await this.unixfs.chmod(root, mode, {
67
+ ...options,
68
+ path
69
+ });
70
+ }
71
+ async cp(source, destination, options) {
72
+ const root = await this.#getRootCID();
73
+ const force = options?.force ?? false;
74
+ if (typeof source === 'string') {
75
+ const stat = await this.stat(source, options);
76
+ source = stat.cid;
77
+ }
78
+ if (!force) {
79
+ await this.#ensurePathDoesNotExist(destination, options);
80
+ }
81
+ const fileName = basename(destination);
82
+ const containingDirectory = destination.substring(0, destination.length - `/${fileName}`.length);
83
+ let trail = [{
84
+ cid: root,
85
+ name: ''
86
+ }];
87
+ if (containingDirectory !== '') {
88
+ trail = await this.#walkPath(root, containingDirectory, {
89
+ ...options,
90
+ createMissingDirectories: options?.force ?? false,
91
+ finalSegmentMustBeDirectory: true
92
+ });
93
+ }
94
+ trail.push({
95
+ cid: source,
96
+ name: fileName
97
+ });
98
+ this.root = await this.#persistPath(trail, options);
99
+ }
100
+ async *ls(path, options) {
101
+ const root = await this.#getRootCID();
102
+ if (options?.path != null) {
103
+ path = `${path}/${options.path}`;
104
+ }
105
+ yield* this.unixfs.ls(root, {
106
+ ...options,
107
+ path
108
+ });
109
+ }
110
+ async mkdir(path, options) {
111
+ const force = options?.force ?? false;
112
+ if (!force) {
113
+ await this.#ensurePathDoesNotExist(path, options);
114
+ }
115
+ const dirName = basename(path);
116
+ const containingDirectory = path.substring(0, path.length - `/${dirName}`.length);
117
+ const root = await this.#getRootCID();
118
+ let trail = [{
119
+ cid: root,
120
+ name: ''
121
+ }];
122
+ if (containingDirectory !== '') {
123
+ trail = await this.#walkPath(root, containingDirectory, {
124
+ ...options,
125
+ createMissingDirectories: force,
126
+ finalSegmentMustBeDirectory: true
127
+ });
128
+ }
129
+ trail.push({
130
+ cid: await this.unixfs.addDirectory({
131
+ mode: options?.mode,
132
+ mtime: options?.mtime
133
+ }, options),
134
+ name: basename(path)
135
+ });
136
+ this.root = await this.#persistPath(trail, options);
137
+ }
138
+ async rm(path, options) {
139
+ const force = options?.force ?? false;
140
+ if (!force) {
141
+ await this.#ensurePathExists(path, options);
142
+ }
143
+ const root = await this.#getRootCID();
144
+ const trail = await this.#walkPath(root, path, {
145
+ ...options,
146
+ createMissingDirectories: false,
147
+ finalSegmentMustBeDirectory: false
148
+ });
149
+ const lastSegment = trail.pop();
150
+ if (lastSegment == null) {
151
+ throw new InvalidParametersError('path was too short');
152
+ }
153
+ // remove directory entry
154
+ const containingDir = trail[trail.length - 1];
155
+ containingDir.cid = await this.unixfs.rm(containingDir.cid, lastSegment.name, options);
156
+ this.root = await this.#persistPath(trail, options);
157
+ }
158
+ async stat(path, options) {
159
+ const root = await this.#getRootCID();
160
+ const trail = await this.#walkPath(root, path, {
161
+ ...options,
162
+ createMissingDirectories: false,
163
+ finalSegmentMustBeDirectory: false
164
+ });
165
+ const finalEntry = trail.pop();
166
+ if (finalEntry == null) {
167
+ throw new DoesNotExistError();
168
+ }
169
+ return this.unixfs.stat(finalEntry.cid, options);
170
+ }
171
+ async touch(path, options) {
172
+ const root = await this.#getRootCID();
173
+ const trail = await this.#walkPath(root, path, {
174
+ ...options,
175
+ createMissingDirectories: false,
176
+ finalSegmentMustBeDirectory: false
177
+ });
178
+ const finalEntry = trail[trail.length - 1];
179
+ if (finalEntry == null) {
180
+ throw new DoesNotExistError();
181
+ }
182
+ finalEntry.cid = await this.unixfs.touch(finalEntry.cid, options);
183
+ this.root = await this.#persistPath(trail, options);
184
+ }
185
+ async #walkPath(root, path, opts) {
186
+ if (!path.startsWith('/')) {
187
+ throw new InvalidParametersError('path must be absolute');
188
+ }
189
+ const stat = await this.unixfs.stat(root, {
190
+ ...opts,
191
+ offline: true
192
+ });
193
+ const output = [{
194
+ cid: root,
195
+ name: '',
196
+ unixfs: stat.unixfs
197
+ }];
198
+ let cid = root;
199
+ const parts = path.split('/').filter(Boolean);
200
+ for (let i = 0; i < parts.length; i++) {
201
+ const segment = parts[i];
202
+ try {
203
+ const stat = await this.unixfs.stat(cid, {
204
+ ...opts,
205
+ offline: true,
206
+ path: segment
207
+ });
208
+ output.push({
209
+ cid: stat.cid,
210
+ name: segment,
211
+ unixfs: stat.unixfs
212
+ });
213
+ cid = stat.cid;
214
+ }
215
+ catch (err) {
216
+ this.log.error('could not resolve path segment %s of %s under %c', segment, path, root);
217
+ if (opts.createMissingDirectories) {
218
+ const cid = await this.unixfs.addDirectory();
219
+ output.push({
220
+ cid,
221
+ name: segment,
222
+ unixfs: new IPFSUnixFS({ type: 'directory' })
223
+ });
224
+ }
225
+ else {
226
+ throw new DoesNotExistError(`${path} does not exist`);
227
+ }
228
+ }
229
+ }
230
+ const lastSegment = output[output.length - 1];
231
+ if (opts.finalSegmentMustBeDirectory && lastSegment.unixfs?.isDirectory() !== true) {
232
+ throw new NotADirectoryError(`${path} was not a directory`);
233
+ }
234
+ return output;
235
+ }
236
+ async #persistPath(path, options = {}) {
237
+ let child = path.pop();
238
+ if (child == null) {
239
+ throw new InvalidParametersError('path was too short');
240
+ }
241
+ let cid = child.cid;
242
+ for (let i = path.length - 1; i > -1; i--) {
243
+ const segment = path[i];
244
+ segment.cid = await this.unixfs.cp(child.cid, segment.cid, child.name, {
245
+ ...options,
246
+ force: true
247
+ });
248
+ child = segment;
249
+ cid = segment.cid;
250
+ }
251
+ await this.components.datastore.put(this.key, cid.bytes, options);
252
+ return cid;
253
+ }
254
+ async #ensurePathExists(path, options = {}) {
255
+ const exists = await this.#pathExists(path, options);
256
+ if (!exists) {
257
+ throw new DoesNotExistError();
258
+ }
259
+ }
260
+ async #ensurePathDoesNotExist(path, options = {}) {
261
+ const exists = await this.#pathExists(path, options);
262
+ if (exists) {
263
+ throw new AlreadyExistsError();
264
+ }
265
+ }
266
+ async #pathExists(path, options = {}) {
267
+ try {
268
+ await this.stat(path, {
269
+ ...options,
270
+ offline: true
271
+ });
272
+ return true;
273
+ }
274
+ catch {
275
+ return false;
276
+ }
277
+ }
278
+ }
279
+ //# sourceMappingURL=mfs.js.map