@interactive-inc/docs-client 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -1718,14 +1718,20 @@ declare class DocClient {
1718
1718
  declare class DocFileSystemMock extends DocFileSystem {
1719
1719
  private files;
1720
1720
  private readonly _pathSystem;
1721
+ private readonly _basePath;
1721
1722
  constructor(props: {
1722
1723
  basePath: string;
1723
1724
  pathSystem: DocPathSystem;
1725
+ skipDefaultFiles?: boolean;
1724
1726
  });
1725
1727
  /**
1726
1728
  * PathSystem accessor (for testing)
1727
1729
  */
1728
1730
  getPathSystem(): DocPathSystem;
1731
+ /**
1732
+ * Normalize path using basePath
1733
+ */
1734
+ private normalizePath;
1729
1735
  /**
1730
1736
  * Create instance (mock data is automatically loaded)
1731
1737
  */
package/build/index.js CHANGED
@@ -3199,7 +3199,7 @@ schema: {}
3199
3199
  ${yamlStr}
3200
3200
  ---
3201
3201
 
3202
- ${this.body}`;
3202
+ ${this.toMarkdownText()}`;
3203
3203
  }
3204
3204
  /**
3205
3205
  * Output in JSON format
@@ -5293,10 +5293,14 @@ Complete API reference.`
5293
5293
  var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5294
5294
  files = /* @__PURE__ */ new Map();
5295
5295
  _pathSystem;
5296
+ _basePath;
5296
5297
  constructor(props) {
5297
5298
  super(props);
5298
5299
  this._pathSystem = props.pathSystem;
5299
- this.setupTestFiles(mockDirectoryData);
5300
+ this._basePath = props.basePath.endsWith("/") ? props.basePath.slice(0, -1) : props.basePath;
5301
+ if (!props.skipDefaultFiles) {
5302
+ this.setupTestFiles(mockDirectoryData);
5303
+ }
5300
5304
  Object.freeze(this);
5301
5305
  }
5302
5306
  /**
@@ -5305,6 +5309,16 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5305
5309
  getPathSystem() {
5306
5310
  return this._pathSystem;
5307
5311
  }
5312
+ /**
5313
+ * Normalize path using basePath
5314
+ */
5315
+ normalizePath(filePath) {
5316
+ if (filePath.startsWith(this._basePath)) {
5317
+ return filePath;
5318
+ }
5319
+ const cleanPath = filePath.startsWith("/") ? filePath.slice(1) : filePath;
5320
+ return `${this._basePath}/${cleanPath}`;
5321
+ }
5308
5322
  /**
5309
5323
  * Create instance (mock data is automatically loaded)
5310
5324
  */
@@ -5318,11 +5332,17 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5318
5332
  static createWithFiles(props) {
5319
5333
  const pathSystem = new DocPathSystem();
5320
5334
  const basePath = props.basePath ?? "/test";
5321
- const fileSystem = new _DocFileSystemMock({ basePath, pathSystem });
5335
+ const fileSystem = new _DocFileSystemMock({
5336
+ basePath,
5337
+ pathSystem,
5338
+ skipDefaultFiles: true
5339
+ });
5322
5340
  if (props.fileContents) {
5323
5341
  const now = /* @__PURE__ */ new Date();
5324
5342
  for (const [path, content] of Object.entries(props.fileContents)) {
5325
- fileSystem.files.set(path, {
5343
+ const cleanPath = path.startsWith("/") ? path.slice(1) : path;
5344
+ const normalizedPath = path.startsWith(basePath) ? path : `${basePath}/${cleanPath}`;
5345
+ fileSystem.files.set(normalizedPath, {
5326
5346
  content,
5327
5347
  modifiedTime: now,
5328
5348
  createdTime: now,
@@ -5334,7 +5354,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5334
5354
  }
5335
5355
  async readFile(filePath) {
5336
5356
  try {
5337
- const normalizedPath = filePath.startsWith("docs/") ? filePath : `docs/${filePath}`;
5357
+ const normalizedPath = this.normalizePath(filePath);
5338
5358
  const file = this.files.get(normalizedPath);
5339
5359
  return file ? file.content : null;
5340
5360
  } catch (error) {
@@ -5343,7 +5363,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5343
5363
  }
5344
5364
  async writeFile(filePath, content) {
5345
5365
  try {
5346
- const normalizedPath = filePath.startsWith("docs/") ? filePath : `docs/${filePath}`;
5366
+ const normalizedPath = this.normalizePath(filePath);
5347
5367
  const now = /* @__PURE__ */ new Date();
5348
5368
  const existing = this.files.get(normalizedPath);
5349
5369
  this.files.set(normalizedPath, {
@@ -5358,8 +5378,8 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5358
5378
  }
5359
5379
  }
5360
5380
  async deleteFile(filePath) {
5361
- const normalizedPath = filePath.startsWith("docs/") ? filePath : `docs/${filePath}`;
5362
5381
  try {
5382
+ const normalizedPath = this.normalizePath(filePath);
5363
5383
  this.files.delete(normalizedPath);
5364
5384
  return null;
5365
5385
  } catch (error) {
@@ -5367,7 +5387,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5367
5387
  }
5368
5388
  }
5369
5389
  async exists(filePath) {
5370
- const normalizedPath = filePath.startsWith("docs/") ? filePath : `docs/${filePath}`;
5390
+ const normalizedPath = this.normalizePath(filePath);
5371
5391
  if (this.files.has(normalizedPath)) {
5372
5392
  return true;
5373
5393
  }
@@ -5381,8 +5401,8 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5381
5401
  }
5382
5402
  async copyFile(source, destination) {
5383
5403
  try {
5384
- const normalizedSource = source.startsWith("docs/") ? source : `docs/${source}`;
5385
- const normalizedDest = destination.startsWith("docs/") ? destination : `docs/${destination}`;
5404
+ const normalizedSource = this.normalizePath(source);
5405
+ const normalizedDest = this.normalizePath(destination);
5386
5406
  const file = this.files.get(normalizedSource);
5387
5407
  if (!file) {
5388
5408
  return new Error(`Source file not found: ${normalizedSource}`);
@@ -5398,8 +5418,8 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5398
5418
  }
5399
5419
  async moveFile(source, destination) {
5400
5420
  try {
5401
- const normalizedSource = source.startsWith("docs/") ? source : `docs/${source}`;
5402
- const normalizedDest = destination.startsWith("docs/") ? destination : `docs/${destination}`;
5421
+ const normalizedSource = this.normalizePath(source);
5422
+ const normalizedDest = this.normalizePath(destination);
5403
5423
  const file = this.files.get(normalizedSource);
5404
5424
  if (!file) {
5405
5425
  return new Error(`Source file not found: ${normalizedSource}`);
@@ -5437,11 +5457,13 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5437
5457
  }
5438
5458
  async readDirectoryFilePaths(directoryPath) {
5439
5459
  try {
5440
- const dirPath = directoryPath.endsWith("/") ? directoryPath : `${directoryPath}/`;
5460
+ const normalizedDir = this.normalizePath(directoryPath);
5461
+ const dirPath = normalizedDir.endsWith("/") ? normalizedDir : `${normalizedDir}/`;
5441
5462
  const files = [];
5442
5463
  for (const path of this.files.keys()) {
5443
5464
  if (path.startsWith(dirPath) && !path.slice(dirPath.length).includes("/")) {
5444
- files.push(path);
5465
+ const relativePath = path.startsWith(`${this._basePath}/`) ? path.slice(this._basePath.length + 1) : path;
5466
+ files.push(relativePath);
5445
5467
  }
5446
5468
  }
5447
5469
  return files.sort();
@@ -5462,7 +5484,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5462
5484
  }
5463
5485
  async getFileSize(filePath) {
5464
5486
  try {
5465
- const normalizedPath = filePath.startsWith("docs/") ? filePath : `docs/${filePath}`;
5487
+ const normalizedPath = this.normalizePath(filePath);
5466
5488
  const file = this.files.get(normalizedPath);
5467
5489
  if (!file) {
5468
5490
  return new Error(`File not found: ${normalizedPath}`);
@@ -5474,7 +5496,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5474
5496
  }
5475
5497
  async getFileModifiedTime(filePath) {
5476
5498
  try {
5477
- const normalizedPath = filePath.startsWith("docs/") ? filePath : `docs/${filePath}`;
5499
+ const normalizedPath = this.normalizePath(filePath);
5478
5500
  const file = this.files.get(normalizedPath);
5479
5501
  if (!file) {
5480
5502
  return new Error(`File not found: ${normalizedPath}`);
@@ -5486,7 +5508,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5486
5508
  }
5487
5509
  async getFileCreatedTime(filePath) {
5488
5510
  try {
5489
- const normalizedPath = filePath.startsWith("docs/") ? filePath : `docs/${filePath}`;
5511
+ const normalizedPath = this.normalizePath(filePath);
5490
5512
  const file = this.files.get(normalizedPath);
5491
5513
  if (!file) {
5492
5514
  return new Error(`File not found: ${normalizedPath}`);
@@ -5497,7 +5519,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5497
5519
  }
5498
5520
  }
5499
5521
  async isDirectory(relativePath) {
5500
- const normalizedPath = relativePath.startsWith("docs/") ? relativePath : `docs/${relativePath}`;
5522
+ const normalizedPath = this.normalizePath(relativePath);
5501
5523
  const dirPath = normalizedPath.endsWith("/") ? normalizedPath : `${normalizedPath}/`;
5502
5524
  for (const path of this.files.keys()) {
5503
5525
  if (path.startsWith(dirPath)) {
@@ -5507,7 +5529,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5507
5529
  return false;
5508
5530
  }
5509
5531
  async isFile(relativePath) {
5510
- const normalizedPath = relativePath.startsWith("docs/") ? relativePath : `docs/${relativePath}`;
5532
+ const normalizedPath = this.normalizePath(relativePath);
5511
5533
  return this.files.has(normalizedPath);
5512
5534
  }
5513
5535
  /**
@@ -5515,7 +5537,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5515
5537
  */
5516
5538
  async readDirectoryFileNames(directoryPath = "") {
5517
5539
  try {
5518
- const normalizedDir = directoryPath === "" ? "docs" : directoryPath === "docs" ? "docs" : directoryPath.startsWith("docs/") ? directoryPath : `docs/${directoryPath}`;
5540
+ const normalizedDir = directoryPath === "" ? this._basePath : this.normalizePath(directoryPath);
5519
5541
  const dirPath = normalizedDir.endsWith("/") ? normalizedDir : `${normalizedDir}/`;
5520
5542
  const entries = /* @__PURE__ */ new Set();
5521
5543
  for (const path of this.files.keys()) {
@@ -5560,19 +5582,23 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5560
5582
  * Check file existence (for testing)
5561
5583
  */
5562
5584
  hasFile(filePath) {
5563
- return this.files.has(filePath);
5585
+ const normalizedPath = this.normalizePath(filePath);
5586
+ return this.files.has(normalizedPath);
5564
5587
  }
5565
5588
  /**
5566
5589
  * Get file content (sync version, for testing)
5567
5590
  */
5568
5591
  getFileContent(filePath) {
5569
- return this.files.get(filePath)?.content;
5592
+ const normalizedPath = this.normalizePath(filePath);
5593
+ return this.files.get(normalizedPath)?.content;
5570
5594
  }
5571
5595
  /**
5572
5596
  * Get all file paths (for testing)
5573
5597
  */
5574
5598
  getAllFilePaths() {
5575
- return Array.from(this.files.keys()).sort();
5599
+ return Array.from(this.files.keys()).map((path) => {
5600
+ return path.startsWith(`${this._basePath}/`) ? path.slice(this._basePath.length + 1) : path;
5601
+ }).sort();
5576
5602
  }
5577
5603
  /**
5578
5604
  * Get file count (for testing)
@@ -5586,7 +5612,8 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
5586
5612
  setupTestFiles(files) {
5587
5613
  const now = /* @__PURE__ */ new Date();
5588
5614
  for (const [path, content] of Object.entries(files)) {
5589
- this.files.set(path, {
5615
+ const normalizedPath = this.normalizePath(path);
5616
+ this.files.set(normalizedPath, {
5590
5617
  content,
5591
5618
  modifiedTime: now,
5592
5619
  createdTime: now,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interactive-inc/docs-client",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "check": "tsgo --noEmit",