mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
feat: organising project
This commit is contained in:
parent
12001a1a6d
commit
7ec769268c
22 changed files with 74 additions and 116 deletions
|
|
@ -51,7 +51,7 @@ const workerPlugin = {
|
|||
build.onLoad({ filter: /.*/, namespace: 'worker-code' }, async () => {
|
||||
// Build worker code
|
||||
const result = await esbuild.build({
|
||||
entryPoints: ['src/database-worker.ts'],
|
||||
entryPoints: ['src/database/worker/database.ts'],
|
||||
bundle: true,
|
||||
write: false,
|
||||
format: 'iife',
|
||||
|
|
@ -83,7 +83,7 @@ const context = await esbuild.context({
|
|||
banner: {
|
||||
js: banner,
|
||||
},
|
||||
entryPoints: ["main.ts"],
|
||||
entryPoints: ["src/main.ts"],
|
||||
bundle: true,
|
||||
external: [
|
||||
"obsidian",
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
import { App, MarkdownPostProcessorContext, MarkdownRenderChild, normalizePath, Vault } from "obsidian"
|
||||
import { displayError, displayNotice } from "./ui"
|
||||
import { SqlSealDatabase } from "./database"
|
||||
import { Logger } from "./logger"
|
||||
import { parseLanguage, Table } from "./grammar/newParser"
|
||||
import { RendererRegistry, RenderReturn } from "./rendererRegistry"
|
||||
import { Sync } from "./datamodel/sync"
|
||||
import { OmnibusRegistrator } from "@hypersphere/omnibus"
|
||||
import { transformQuery } from "./datamodel/transformer"
|
||||
import { OmnibusRegistrator } from "@hypersphere/omnibus";
|
||||
import { App, MarkdownPostProcessorContext, MarkdownRenderChild } from "obsidian";
|
||||
import { SqlSealDatabase } from "src/database/database";
|
||||
import { Sync } from "src/datamodel/sync";
|
||||
import { transformQuery } from "src/datamodel/transformer";
|
||||
import { parseLanguage, Table } from "src/grammar/newParser";
|
||||
import { RendererRegistry, RenderReturn } from "src/renderer/rendererRegistry";
|
||||
import { displayError, displayNotice } from "src/utils/ui";
|
||||
|
||||
class CodeblockProcessor extends MarkdownRenderChild {
|
||||
export class CodeblockProcessor extends MarkdownRenderChild {
|
||||
|
||||
registrator: OmnibusRegistrator
|
||||
renderer: RenderReturn
|
||||
|
|
@ -95,22 +94,4 @@ class CodeblockProcessor extends MarkdownRenderChild {
|
|||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class SqlSealCodeblockHandler {
|
||||
constructor(
|
||||
private readonly app: App,
|
||||
private readonly db: SqlSealDatabase,
|
||||
private sync: Sync,
|
||||
private rendererRegistry: RendererRegistry
|
||||
) {
|
||||
}
|
||||
|
||||
getHandler() {
|
||||
return async (source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
|
||||
const processor = new CodeblockProcessor(el, source, ctx, this.rendererRegistry, this.db, this.app, this.sync)
|
||||
ctx.addChild(processor)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/codeblockHandler/SqlSealCodeblockHandler.ts
Normal file
31
src/codeblockHandler/SqlSealCodeblockHandler.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { App, MarkdownPostProcessorContext } from "obsidian"
|
||||
import { SqlSealDatabase } from "../database/database"
|
||||
import { RendererRegistry } from "../renderer/rendererRegistry"
|
||||
import { Sync } from "../datamodel/sync"
|
||||
import { CodeblockProcessor } from "./CodeblockProcessor"
|
||||
|
||||
|
||||
export class SqlSealCodeblockHandler {
|
||||
constructor(
|
||||
private readonly app: App,
|
||||
private readonly db: SqlSealDatabase,
|
||||
private sync: Sync,
|
||||
private rendererRegistry: RendererRegistry
|
||||
) {
|
||||
}
|
||||
|
||||
getHandler() {
|
||||
return async (source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
|
||||
const processor = new CodeblockProcessor(
|
||||
el,
|
||||
source,
|
||||
ctx,
|
||||
this.rendererRegistry,
|
||||
this.db,
|
||||
this.app,
|
||||
this.sync
|
||||
)
|
||||
ctx.addChild(processor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
import { App } from "obsidian"
|
||||
import { FieldTypes, toTypeStatements } from "./utils"
|
||||
import { FieldTypes, toTypeStatements } from "../utils/typePredictions"
|
||||
import * as Comlink from 'comlink'
|
||||
import workerCode from 'virtual:worker-code'
|
||||
import { WorkerDatabase } from "./database-worker"
|
||||
|
||||
import { WorkerDatabase } from "./worker/database";
|
||||
|
||||
export interface FieldDefinition {
|
||||
name: string;
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
import * as Comlink from "comlink"
|
||||
import initSqlJs from '@jlongster/sql.js';
|
||||
import wasmBinary from '../node_modules/@jlongster/sql.js/dist/sql-wasm.wasm'
|
||||
import wasmBinary from '../../../node_modules/@jlongster/sql.js/dist/sql-wasm.wasm'
|
||||
import { SQLiteFS } from 'absurd-sql';
|
||||
import IndexedDBBackend from '../node_modules/absurd-sql/dist/indexeddb-backend.js';
|
||||
import IndexedDBBackend from '../../../node_modules/absurd-sql/dist/indexeddb-backend.js';
|
||||
import type { BindParams, Database, Statement } from "sql.js";
|
||||
import { sanitise } from "./utils/sanitiseColumn";
|
||||
import { FieldTypes } from "./utils";
|
||||
import { sanitise } from "../../utils/sanitiseColumn";
|
||||
import { FieldTypes } from "../../utils/typePredictions";
|
||||
|
||||
|
||||
function toObjectArray(stmt: Statement) {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { SqlSealDatabase } from "src/database";
|
||||
import { SqlSealDatabase } from "src/database/database";
|
||||
|
||||
export abstract class Repository {
|
||||
constructor(protected readonly db: SqlSealDatabase) { }
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { SqlSealDatabase } from "src/database";
|
||||
import { SqlSealDatabase } from "src/database/database";
|
||||
import { FileLog, FileLogRepository } from "./repository/fileLog";
|
||||
import { TableMapLogRepository } from "./repository/tableMapLog";
|
||||
import { TAbstractFile, TFile, Vault } from "obsidian";
|
||||
import { parse } from "papaparse";
|
||||
import { sanitise } from "src/utils/sanitiseColumn";
|
||||
import { FieldTypes, toTypeStatements } from "src/utils";
|
||||
import { FieldTypes, toTypeStatements } from "src/utils/typePredictions";
|
||||
import { FilepathHasher } from "./hasher";
|
||||
import { Omnibus } from "@hypersphere/omnibus";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import { Menu, Plugin, TAbstractFile, Tasks, TFile } from 'obsidian';
|
||||
import { FilesFileSyncTable } from 'src/fileSyncTable/filesTable';
|
||||
import { TagsFileSyncTable } from 'src/fileSyncTable/tagsTable';
|
||||
import { TasksFileSyncTable } from 'src/fileSyncTable/tasksTable';
|
||||
import { GridRenderer } from 'src/renderer/GridRenderer';
|
||||
import { MarkdownRenderer } from 'src/renderer/MarkdownRenderer';
|
||||
import { TableRenderer } from 'src/renderer/TableRenderer';
|
||||
import { RendererConfig, RendererRegistry } from 'src/rendererRegistry';
|
||||
import { SealFileSync } from 'src/SealFileSync';
|
||||
import { RendererConfig, RendererRegistry } from 'src/renderer/rendererRegistry';
|
||||
import { DEFAULT_SETTINGS, SQLSealSettings, SQLSealSettingsTab } from 'src/settings/SQLSealSettingsTab';
|
||||
import { SqlSeal } from 'src/sqlSeal';
|
||||
import { SealFileSync } from 'src/vaultSync/SealFileSync';
|
||||
import { FilesFileSyncTable } from 'src/vaultSync/tables/filesTable';
|
||||
import { TagsFileSyncTable } from 'src/vaultSync/tables/tagsTable';
|
||||
import { TasksFileSyncTable } from 'src/vaultSync/tables/tasksTable';
|
||||
import { CSV_VIEW_TYPE, CSVView } from 'src/view/CSVView';
|
||||
|
||||
const GLOBAL_KEY = 'sqlSealApi'
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import { createGrid, GridApi, GridOptions, themeQuartz } from "ag-grid-community";
|
||||
import { merge } from "lodash";
|
||||
import { App } from "obsidian";
|
||||
import { RendererConfig } from "src/rendererRegistry";
|
||||
import { RendererConfig } from "src/renderer/rendererRegistry";
|
||||
import { parse } from 'json5'
|
||||
import { displayError, displayNotice, parseCell } from "src/ui";
|
||||
import { parseCell } from "src/utils/ui";
|
||||
|
||||
const getCurrentTheme = () => {
|
||||
return document.body.classList.contains('theme-dark') ? 'dark' : 'light';
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// This is renderer for a very basic Table view.
|
||||
import { getMarkdownTable } from "markdown-table-ts";
|
||||
import { App } from "obsidian";
|
||||
import { RendererConfig } from "src/rendererRegistry";
|
||||
import { displayError, parseCell } from "src/ui";
|
||||
import { RendererConfig } from "src/renderer/rendererRegistry";
|
||||
import { displayError, parseCell } from "src/utils/ui";
|
||||
|
||||
const mapDataFromHeaders = (columns: string[], data: Record<string, any>[]) => {
|
||||
return data.map(d => columns.map(c => String(d[c])))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// This is renderer for a very basic Table view.
|
||||
import { App } from "obsidian";
|
||||
import { RendererConfig } from "src/rendererRegistry";
|
||||
import { displayError, parseCell } from "src/ui";
|
||||
import { RendererConfig } from "src/renderer/rendererRegistry";
|
||||
import { displayError, parseCell } from "src/utils/ui";
|
||||
|
||||
export class TableRenderer implements RendererConfig {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { SqlSealDatabase } from "./database";
|
||||
import { SqlSealDatabase } from "./database/database";
|
||||
import { App } from "obsidian";
|
||||
import { SqlSealCodeblockHandler } from "./SqlSealCodeblockHandler";
|
||||
import { Logger } from "./logger";
|
||||
import { RendererRegistry } from "./rendererRegistry";
|
||||
import { SqlSealCodeblockHandler } from "./codeblockHandler/SqlSealCodeblockHandler";
|
||||
import { Logger } from "./utils/logger";
|
||||
import { RendererRegistry } from "./renderer/rendererRegistry";
|
||||
import { Sync } from "./datamodel/sync";
|
||||
|
||||
export class SqlSeal {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { describe, it, expect } from '@jest/globals'
|
||||
import { predictJson, predictType } from './utils'
|
||||
import { predictJson, predictType } from './typePredictions'
|
||||
|
||||
describe('Utils', () => {
|
||||
|
||||
it('should properly predict TEXT type', () => {
|
||||
expect(predictType('xxx', [{ 'xxx': 'dhjkafhkjafhkfas' }])).toEqual('TEXT')
|
||||
})
|
||||
|
|
@ -1,56 +1,7 @@
|
|||
|
||||
import { get } from "https"
|
||||
import { parse } from 'json5'
|
||||
import * as fs from 'fs'
|
||||
import { camelCase } from "lodash";
|
||||
|
||||
export const fetchBlobData = async (url: string, filePath: string) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
get(url, (response) => {
|
||||
const statusCode = response.statusCode;
|
||||
const contentType = response.headers['content-type'];
|
||||
|
||||
let error;
|
||||
if (statusCode === 301 || statusCode === 302) {
|
||||
// Handle redirect
|
||||
const redirectUrl = response.headers.location;
|
||||
if (!redirectUrl) {
|
||||
reject('Redirect URL not found')
|
||||
return;
|
||||
}
|
||||
fetchBlobData(redirectUrl, filePath).then(resolve).catch(reject);
|
||||
return;
|
||||
}
|
||||
if (statusCode !== 200) {
|
||||
error = new Error(`Request Failed. Status Code: ${statusCode}`);
|
||||
} else if (!/^application\/octet-stream/.test(contentType ?? '')) {
|
||||
error = new Error(`Invalid content-type. Expected application/octet-stream but received ${contentType}`);
|
||||
}
|
||||
if (error) {
|
||||
console.error(error.message);
|
||||
// Consume response data to free up memory
|
||||
response.resume();
|
||||
return;
|
||||
}
|
||||
|
||||
const fileStream = fs.createWriteStream(filePath);
|
||||
response.pipe(fileStream);
|
||||
|
||||
fileStream.on('finish', () => {
|
||||
resolve()
|
||||
fileStream.close()
|
||||
});
|
||||
|
||||
fileStream.on('error', (err) => {
|
||||
console.error(`Error writing to ${filePath}: ${err}`);
|
||||
reject(`Error writing to ${filePath}: ${err}`)
|
||||
});
|
||||
}).on('error', (err) => {
|
||||
console.error(`Error fetching blob data: ${err.message}`);
|
||||
reject(`Error writing to ${filePath}: ${err}`)
|
||||
});
|
||||
})
|
||||
};
|
||||
export const predictType = (field: string, data: Array<Record<string, string | Object>>) => {
|
||||
|
||||
if (field === 'id') {
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
import { App } from "obsidian"
|
||||
import { createGrid, GridOptions } from 'ag-grid-community';
|
||||
import { themeQuartz } from '@ag-grid-community/theming';
|
||||
|
||||
export const displayNotice = (el: HTMLElement, text: string) => {
|
||||
el.empty()
|
||||
|
|
@ -51,7 +49,6 @@ const generateLink = (config: SqlSealAnchorElement, app: App) => {
|
|||
|
||||
link.addEventListener('click', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
// Open the file in the active leaf (same tab)
|
||||
const leaf = app.workspace.getLeaf();
|
||||
const file = app.vault.getFileByPath(config.href)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { App, Plugin, TAbstractFile, TFile } from "obsidian";
|
||||
import { FieldTypes } from "./utils";
|
||||
import { sanitise } from "./utils/sanitiseColumn";
|
||||
import { AFileSyncTable } from "./fileSyncTable/abstractFileSyncTable";
|
||||
import { App, Plugin, TFile } from "obsidian";
|
||||
import { FieldTypes } from "src/utils/typePredictions";
|
||||
import { sanitise } from "src/utils/sanitiseColumn";
|
||||
import { AFileSyncTable } from "./tables/abstractFileSyncTable";
|
||||
|
||||
const extractFrontmatterFromFile = async (file: TFile, plugin: Plugin) => {
|
||||
const frontmatter = plugin.app.metadataCache.getFileCache(file)?.frontmatter || {}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { App, TFile } from "obsidian";
|
||||
import { SqlSealDatabase } from "src/database";
|
||||
import { SqlSealDatabase } from "src/database/database";
|
||||
|
||||
export abstract class AFileSyncTable {
|
||||
constructor(
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import { App, Plugin, TAbstractFile, TFile } from "obsidian";
|
||||
import { AFileSyncTable } from "./abstractFileSyncTable";
|
||||
import { sanitise } from "src/utils/sanitiseColumn";
|
||||
import { SqlSealDatabase } from "src/database";
|
||||
import { predictType } from "src/utils";
|
||||
import { SqlSealDatabase } from "src/database/database";
|
||||
import { predictType } from "src/utils/typePredictions";
|
||||
|
||||
|
||||
const extractFrontmatterFromFile = async (file: TFile, plugin: Plugin) => {
|
||||
Loading…
Reference in a new issue