Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code to have clean interface between parse layer and write to database and focus tests on parse layer #47

Closed
5 of 6 tasks
rufuspollock opened this issue Nov 9, 2023 · 1 comment
Assignees

Comments

@rufuspollock
Copy link
Member

rufuspollock commented Nov 9, 2023

Refactor to focus the code on the first steps to get a JS/TS objects representing essential "data". Create clear separation of concerns so that we can rapidly add new well tested features e.g. tag parsing, computed fields.

graph TD

markdown --remark-parse--> st[syntax tree]
st --extract features--> jsobj1[TS Object eg. File plus Metadata plus Tags plus Links]
jsobj1 --computing--> jsobj[TS Objects]
jsobj --convert to sql--> sqlite[SQLite markdown.db]
jsobj --write to disk--> json[JSON on disk in .markdowndb folder]
jsobj --tests--> testoutput[Test results]

Comment: we should write most of our tests at the js object level. Not at sqlite level.

Acceptance

See design sketch below.

FUTURE

  • Bonus: Split out the sqlite wrapper to write to sqlite in a separate file and refactored current code to use the processFile function

Comment: we can ignore sqlite right now in this branch not worry about refactoring that code to write to sqlite from JS objects. This would simplify code and allow us to use typescript for everything for now. It is easy to convert json to sqlite later if we want.

Notes

  • Use micromark to parse the markdown file? ✅2023-11-10 ❌ just use remark-parse for now

Sample code

// FUTURE - to show how code path will run
function buildMarkdownSQLDb(folder) {
  walkFolder(folder)
  for each file in folder:
    parseFile => File
    storeFileInDb(File) // or storeAllFiles at once later
}

// what we want to add ...
function parseFile(path) returns File
  getKeyInfoOnFile(path)
  if(isMarkdown) {
    parseMarkdownFile(string) // returns Metadata, Links, Tags, Tasks
    // add this info to the FileInfo ...
  } else {
    return FileInfo
 } 
}

interface FileInfo {
  path
  
}

interface MarkdownFile extend File {
  // adds Metadata
  // adds Tags?
}

Schema

interface File {
  path: string; // relative path on disk, also will be primary key
  extension: string;
  metadata: MetaData | null; // frontmatter
}

interface Metadata {
  key: value
}

interface Link {
  link_type: "normal" | "embed";
  from: string; // path
  to: string; // to path or url
}

Design sketch for JSON on disk

NB: ❌ we don't need this atm

.markdowndb/
  files.json
  links.json

Define the schema for that in typescript

This was referenced Nov 10, 2023
@rufuspollock rufuspollock changed the title Try-out having a simple JSON-based db (rather than / before sqlite) Refactor code to have clean interface between parse layer and write to database and focus tests on parse layer Nov 10, 2023
rufuspollock added a commit that referenced this issue Nov 15, 2023
@rufuspollock
Copy link
Member Author

rufuspollock commented Nov 15, 2023

FIXED. Completed in 8fcda1d

Took longer than estimated b/c confusion over whether we refactored existing code to use the new function.

mohamedsalem401 added a commit that referenced this issue Nov 22, 2023
* [#47,refactor][m]: create a process.ts file that just does extraction of file info to a JS/TS object.

* update index.mdx for testing

* Add process function and add some tests

* [ #4 , extract links ] add link extraction

* [#49, Add body tags extraction]

* #58 refactor mddb code

* Integrate extracting tags from body

* Integrate links extraction

* Add changeset

* update include config

* Restore pathToUrlResolver

* update tests

* Implement obsidian links

* No need for this

* Update tests for links

* Update tests for links

* undo changing tests

* Update obsidian links test

---------

Co-authored-by: Rufus Pollock <rufus.pollock@datopian.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants