Documentation

Class: DocumentStore

Description: The DocumentStore class manages adding, retrieving, and updating documentation files stored within a .komment folder. It utilizes a chunked storage approach to handle large volumes of files efficiently.

Implements: IDocumentStore

Methods


Method: constructor

Description: Initializes a new DocumentStore instance with the provided parameters.

Parameters:

  • provider (any): An object providing methods for interacting with the storage provider (e.g., GitHub API).
  • repoId (string): The ID of the repository where documentation is stored.
  • ref (string): The reference (branch/commit) of the repository.

Returns: void

Example:

const docStore = new DocumentStore(githubApi, "my-repo-id", "main");

Method: setUpdatedAt

Description: Updates the updated_at timestamp within the meta object.

Parameters:

  • updated_at (Date): The new updated timestamp.

Returns: void

Example:

docStore.setUpdatedAt(new Date());

Method: loadSummary

Description: Loads the summary data for the documentation from the remote storage.

Parameters: None

Returns: void

Throws:

  • Error: Thrown if repoId or ref are missing.

Example:

await docStore.loadSummary();

Method: load

Description: Loads all files from the remote storage.

Parameters: None

Returns: void

Example:

await docStore.load();

Method: chunkIndexToChunkKey

Description: Converts a chunk index to a chunk key (string).

Parameters:

  • k (number): The chunk index.

Returns:

  • string: The corresponding chunk key, padded with zeros.

Example:

const chunkKey = docStore.chunkIndexToChunkKey(2); // "00002"

Method: chunkKeyToChunkPath

Description: Converts a chunk key to a chunk path (string).

Parameters:

  • k (string): The chunk key.

Returns:

  • string: The corresponding chunk path.

Example:

const chunkPath = docStore.chunkKeyToChunkPath("00002"); // "00002"

Method: getChunkSummaryPath

Description: Retrieves the path to the summary file.

Parameters: None

Returns:

  • string: The path to the summary file (index).

Example:

const summaryPath = docStore.getChunkSummaryPath(); // "index"

Method: fileIndexToChunkId

Description: Calculates the chunk ID for a given file index.

Parameters:

  • fileIndex (number): The index of the file.

Returns: void

Example:

const chunkId = docStore.fileIndexToChunkId(50); // 1 (assuming CHUNK_SIZE = 40)

Method: isChunkLoaded

Description: Checks if a specific chunk is loaded.

Parameters:

  • chunkIndex (number): The index of the chunk to check.

Returns:

  • boolean: true if the chunk is loaded, false otherwise.

Example:

const isChunkLoaded = docStore.isChunkLoaded(1);

Method: loadChunk

Description: Loads a specific chunk from the remote storage.

Parameters:

  • chunkIndex (number): The index of the chunk to load.

Returns:

  • boolean: true if the chunk was loaded successfully, false otherwise.

Example:

const success = await docStore.loadChunk(1);

Method: getFile

Description: Retrieves a specific file from the stored chunks.

Parameters:

  • path (string): The path to the file.

Returns:

  • StructuredFile: The requested file, or null if not found.

Throws:

  • Error: Thrown if the summary has not been loaded yet.

Example:

const file = await docStore.getFile("path/to/file.js");

Method: getFileHash

Description: Calculates the hash of a file path (for potential obfuscation).

Parameters:

  • path (string): The path to the file.

Returns:

  • string: The hash of the file path.

Example:

const fileHash = docStore.getFileHash("path/to/file.js");

Method: getChunkFileIsIn

Description: Finds the chunk index where a file is located.

Parameters:

  • path (string): The path to the file.

Returns:

  • number: The chunk index where the file is found, or -1 if not found.

Example:

const chunkIndex = docStore.getChunkFileIsIn("path/to/file.js");

Method: getFileIndexInChunk

Description: Determines the index of a file within a specific chunk.

Parameters:

  • chunk (number): The index of the chunk.
  • path (string): The path to the file.

Returns:

  • number: The index of the file within the chunk, or -1 if not found.

Example:

const fileIndexInChunk = docStore.getFileIndexInChunk(1, "path/to/file.js");

Method: getFileIndex

Description: Finds the overall index of a file within the lookup table.

Parameters:

  • path (string): The path to the file.

Returns:

  • number: The overall index of the file, or -1 if not found.

Example:

const fileIndex = docStore.getFileIndex("path/to/file.js");

Method: fileExists

Description: Checks if a file with the given path exists in the lookup table.

Parameters:

  • path (string): The path to the file.

Returns:

  • boolean: true if the file exists, false otherwise.

Example:

const exists = docStore.fileExists("path/to/file.js");

Method: addToEndOfLookup

Description: Adds a file path to the end of the lookup table, creating a new subtable if necessary.

Parameters:

  • path (string): The path to the file.

Returns: void

Example:

docStore.addToEndOfLookup("path/to/file.js");

Method: addToEndOfChunks

Description: Adds a StructuredFile to the end of the chunks array, creating a new subarray if necessary.

Parameters:

  • file (StructuredFile): The StructuredFile to add.

Returns: void

Example:

docStore.addToEndOfChunks(structuredFileContent);

Method: addFile

Description: Adds a StructuredFile to the DocumentStore.

Parameters:

  • file (StructuredFile): The StructuredFile to add.

Returns:

  • boolean: true if the file was added successfully, false otherwise.

Throws:

  • Error: Thrown if the chunks have not been loaded yet.

Example:

const success = docStore.addFile(structuredFileContent);

Method: updateFile

Description: Updates an existing StructuredFile in the DocumentStore.

Parameters:

  • file (any): The StructuredFile to update.

Returns:

  • StructuredFile | null: The updated file, or null if the file was not found.

Throws:

  • Error: Thrown if the chunks have not been loaded yet.

Example:

const updatedFile = await docStore.updateFile(structuredFileContent);

Method: outputSummary

Description: Outputs the current summary data as an object.

Parameters: None

Returns:

  • object: An object containing the meta and lookup data.

Example:

const summary = docStore.outputSummary();

Method: outputChunks

Description: Outputs the stored chunks as an object.

Parameters: None

Returns:

  • object: An object containing the chunks, keyed by chunk path.

Example:

const chunks = docStore.outputChunks();

==========