markdown-sql 0.0.0-stage → 0.1.1
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/LICENSE +201 -0
- package/README.md +421 -2
- package/dist/core-BGXPYnlj.d.cts +143 -0
- package/dist/core-BGXPYnlj.d.ts +143 -0
- package/dist/drizzle.cjs +1034 -0
- package/dist/drizzle.cjs.map +1 -0
- package/dist/drizzle.d.cts +39 -0
- package/dist/drizzle.d.ts +39 -0
- package/dist/drizzle.js +1028 -0
- package/dist/drizzle.js.map +1 -0
- package/dist/engine-rSx4jmMV.d.cts +7 -0
- package/dist/engine-rSx4jmMV.d.ts +7 -0
- package/dist/index.cjs +1101 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +86 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +1095 -0
- package/dist/index.js.map +1 -0
- package/dist/pg.cjs +1289 -0
- package/dist/pg.cjs.map +1 -0
- package/dist/pg.d.cts +79 -0
- package/dist/pg.d.ts +79 -0
- package/dist/pg.js +1279 -0
- package/dist/pg.js.map +1 -0
- package/dist/schema-B1HlomD9.d.cts +16 -0
- package/dist/schema-D3mwSEnX.d.ts +16 -0
- package/package.json +116 -4
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
type DiagnosticCode = 'invalid-frontmatter' | 'missing-required' | 'type-mismatch' | 'invalid-key' | 'read-error' | 'sql-error' | 'watch-error' | 'startup-warning';
|
|
2
|
+
/**
|
|
3
|
+
* A problem found in one markdown file; the file is left out of the index. `watch-error` and
|
|
4
|
+
* `startup-warning` are not about one file: their `table` and `file` may be empty, and they are
|
|
5
|
+
* only passed to `onDiagnostic`.
|
|
6
|
+
*/
|
|
7
|
+
interface Diagnostic {
|
|
8
|
+
readonly code: DiagnosticCode;
|
|
9
|
+
/** Schema key of the table, as passed in `schema`. */
|
|
10
|
+
readonly table: string;
|
|
11
|
+
/** File path relative to `root`, with forward slashes. */
|
|
12
|
+
readonly file: string;
|
|
13
|
+
/** Frontmatter key (the column's property name), when the problem is in one column. */
|
|
14
|
+
readonly column?: string;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
}
|
|
17
|
+
type MarkdownSqlErrorCode = 'READ_ONLY' | 'VALIDATION' | 'CONFIG' | 'CLOSED';
|
|
18
|
+
interface MarkdownSqlError extends Error {
|
|
19
|
+
readonly name: 'MarkdownSqlError';
|
|
20
|
+
readonly code: MarkdownSqlErrorCode;
|
|
21
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Finds a MarkdownSQL error in `error` or its `cause` chain. Drizzle wraps errors thrown while
|
|
25
|
+
* running a query in its own `DrizzleQueryError`, so check the chain rather than the top error.
|
|
26
|
+
*/
|
|
27
|
+
declare const findMarkdownSqlError: <T>(error: T) => MarkdownSqlError | undefined;
|
|
28
|
+
declare const isMarkdownSqlError: <T>(error: T, code?: MarkdownSqlErrorCode) => boolean;
|
|
29
|
+
declare const formatDiagnostic: (diagnostic: Diagnostic) => string;
|
|
30
|
+
|
|
31
|
+
/** A value that YAML frontmatter can hold once parsed with the YAML 1.2 core schema. */
|
|
32
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
33
|
+
interface JsonObject {
|
|
34
|
+
readonly [key: string]: JsonValue;
|
|
35
|
+
}
|
|
36
|
+
type JsonArray = readonly JsonValue[];
|
|
37
|
+
type JsonValue = JsonPrimitive | JsonArray | JsonObject;
|
|
38
|
+
|
|
39
|
+
type ColumnRole = 'key' | 'body' | 'data';
|
|
40
|
+
/** Per-table settings. Every field is optional. */
|
|
41
|
+
interface TableOptions {
|
|
42
|
+
/** Folder under `root` that holds this table's files. Defaults to the SQL table name. */
|
|
43
|
+
readonly dir?: string;
|
|
44
|
+
/** Name of the column filled from the file name (without extension). Defaults to `id`. */
|
|
45
|
+
readonly key?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Name of the column filled from the markdown body. Defaults to `body`; when the table has no
|
|
48
|
+
* such column the body is not stored. Pass `false` to never store it.
|
|
49
|
+
*/
|
|
50
|
+
readonly body?: string | false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface MarkdownFile {
|
|
54
|
+
readonly data: JsonObject;
|
|
55
|
+
readonly body: string;
|
|
56
|
+
}
|
|
57
|
+
type ParseResult = {
|
|
58
|
+
readonly ok: true;
|
|
59
|
+
readonly file: MarkdownFile;
|
|
60
|
+
} | {
|
|
61
|
+
readonly ok: false;
|
|
62
|
+
readonly message: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Splits a markdown file into its YAML frontmatter and body. A file without a leading `---` fence
|
|
66
|
+
* has no frontmatter and its whole content is the body.
|
|
67
|
+
*/
|
|
68
|
+
declare const parseMarkdown: (source: string) => ParseResult;
|
|
69
|
+
|
|
70
|
+
type ChangeType = 'add' | 'change' | 'unlink' | 'invalid';
|
|
71
|
+
/** One file whose row was added, changed, removed, or dropped because it became invalid. */
|
|
72
|
+
interface ChangeEvent {
|
|
73
|
+
readonly type: ChangeType;
|
|
74
|
+
/** Schema key of the table. */
|
|
75
|
+
readonly table: string;
|
|
76
|
+
/** File path relative to `root`, with forward slashes. */
|
|
77
|
+
readonly file: string;
|
|
78
|
+
/** File name without extension, which is the row's key. */
|
|
79
|
+
readonly key: string;
|
|
80
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
81
|
+
}
|
|
82
|
+
interface TableReport {
|
|
83
|
+
readonly table: string;
|
|
84
|
+
readonly dir: string;
|
|
85
|
+
/** Files loaded as rows. */
|
|
86
|
+
readonly rows: number;
|
|
87
|
+
/** Files left out because of diagnostics. */
|
|
88
|
+
readonly skipped: number;
|
|
89
|
+
/** Frontmatter keys that match no column, with the number of files that use each. */
|
|
90
|
+
readonly unknownKeys: Readonly<Record<string, number>>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface WatchOptions {
|
|
94
|
+
/** Wait this long after the last event for a file before reading it. Defaults to 50 ms. */
|
|
95
|
+
readonly debounceMs?: number;
|
|
96
|
+
/** Keep the process alive while watching. Defaults to true. */
|
|
97
|
+
readonly persistent?: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type InvalidFileMode = 'throw' | 'skip';
|
|
101
|
+
/** Options shared by every MarkdownSQL entry point. */
|
|
102
|
+
interface BaseOptions {
|
|
103
|
+
/** Folder that holds one sub-folder per table. Relative paths resolve from the working directory. */
|
|
104
|
+
readonly root: string;
|
|
105
|
+
/**
|
|
106
|
+
* What to do with files that fail validation on the first load. `throw` (default) rejects with
|
|
107
|
+
* every diagnostic; `skip` leaves those files out and reports them. While watching, invalid files
|
|
108
|
+
* are always skipped and reported, so a typo in one file never stops the dev server.
|
|
109
|
+
*/
|
|
110
|
+
readonly onInvalid?: InvalidFileMode;
|
|
111
|
+
/** Called for every diagnostic, on the first load and while watching. */
|
|
112
|
+
readonly onDiagnostic?: (diagnostic: Diagnostic) => void;
|
|
113
|
+
/** Start watching right away. Pass options to tune the watcher. */
|
|
114
|
+
readonly watch?: boolean | WatchOptions;
|
|
115
|
+
/** File extensions that count as rows. Defaults to `['.md']`. */
|
|
116
|
+
readonly extensions?: readonly string[];
|
|
117
|
+
}
|
|
118
|
+
interface IndexReport {
|
|
119
|
+
/** Hash of the table structure. It changes when the schema or table options change. */
|
|
120
|
+
readonly schemaHash: string;
|
|
121
|
+
readonly tables: readonly TableReport[];
|
|
122
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
123
|
+
}
|
|
124
|
+
type ChangeListener = (events: readonly ChangeEvent[]) => void;
|
|
125
|
+
/** The index lifecycle every MarkdownSQL instance has, whatever its query surface. */
|
|
126
|
+
interface MarkdownSqlIndex {
|
|
127
|
+
/** Current diagnostics for files that are left out of the index. */
|
|
128
|
+
readonly diagnostics: () => readonly Diagnostic[];
|
|
129
|
+
/** Row counts, skipped files and frontmatter keys that match no column, per table. */
|
|
130
|
+
readonly report: () => IndexReport;
|
|
131
|
+
/** Re-scans every folder. Unchanged files are skipped by checksum. */
|
|
132
|
+
readonly reload: () => Promise<readonly ChangeEvent[]>;
|
|
133
|
+
/** Starts watching the table folders. Calling it again does nothing. */
|
|
134
|
+
readonly watch: (options?: WatchOptions) => void;
|
|
135
|
+
/** Listens for batches of row changes from the watcher or `reload`. Returns an unsubscribe function. */
|
|
136
|
+
readonly subscribe: (listener: ChangeListener) => () => void;
|
|
137
|
+
/** Resolves once every queued file update has been applied. */
|
|
138
|
+
readonly settled: () => Promise<void>;
|
|
139
|
+
/** Stops watching and closes the in-memory database. */
|
|
140
|
+
readonly close: () => Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { type BaseOptions as B, type ChangeEvent as C, type Diagnostic as D, type IndexReport as I, type JsonArray as J, type MarkdownSqlIndex as M, type TableOptions as T, type WatchOptions as W, type ChangeListener as a, type ChangeType as b, type DiagnosticCode as c, type InvalidFileMode as d, type JsonObject as e, type JsonPrimitive as f, type JsonValue as g, type MarkdownFile as h, type MarkdownSqlError as i, type MarkdownSqlErrorCode as j, type TableReport as k, findMarkdownSqlError as l, formatDiagnostic as m, isMarkdownSqlError as n, type ColumnRole as o, parseMarkdown as p };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
type DiagnosticCode = 'invalid-frontmatter' | 'missing-required' | 'type-mismatch' | 'invalid-key' | 'read-error' | 'sql-error' | 'watch-error' | 'startup-warning';
|
|
2
|
+
/**
|
|
3
|
+
* A problem found in one markdown file; the file is left out of the index. `watch-error` and
|
|
4
|
+
* `startup-warning` are not about one file: their `table` and `file` may be empty, and they are
|
|
5
|
+
* only passed to `onDiagnostic`.
|
|
6
|
+
*/
|
|
7
|
+
interface Diagnostic {
|
|
8
|
+
readonly code: DiagnosticCode;
|
|
9
|
+
/** Schema key of the table, as passed in `schema`. */
|
|
10
|
+
readonly table: string;
|
|
11
|
+
/** File path relative to `root`, with forward slashes. */
|
|
12
|
+
readonly file: string;
|
|
13
|
+
/** Frontmatter key (the column's property name), when the problem is in one column. */
|
|
14
|
+
readonly column?: string;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
}
|
|
17
|
+
type MarkdownSqlErrorCode = 'READ_ONLY' | 'VALIDATION' | 'CONFIG' | 'CLOSED';
|
|
18
|
+
interface MarkdownSqlError extends Error {
|
|
19
|
+
readonly name: 'MarkdownSqlError';
|
|
20
|
+
readonly code: MarkdownSqlErrorCode;
|
|
21
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Finds a MarkdownSQL error in `error` or its `cause` chain. Drizzle wraps errors thrown while
|
|
25
|
+
* running a query in its own `DrizzleQueryError`, so check the chain rather than the top error.
|
|
26
|
+
*/
|
|
27
|
+
declare const findMarkdownSqlError: <T>(error: T) => MarkdownSqlError | undefined;
|
|
28
|
+
declare const isMarkdownSqlError: <T>(error: T, code?: MarkdownSqlErrorCode) => boolean;
|
|
29
|
+
declare const formatDiagnostic: (diagnostic: Diagnostic) => string;
|
|
30
|
+
|
|
31
|
+
/** A value that YAML frontmatter can hold once parsed with the YAML 1.2 core schema. */
|
|
32
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
33
|
+
interface JsonObject {
|
|
34
|
+
readonly [key: string]: JsonValue;
|
|
35
|
+
}
|
|
36
|
+
type JsonArray = readonly JsonValue[];
|
|
37
|
+
type JsonValue = JsonPrimitive | JsonArray | JsonObject;
|
|
38
|
+
|
|
39
|
+
type ColumnRole = 'key' | 'body' | 'data';
|
|
40
|
+
/** Per-table settings. Every field is optional. */
|
|
41
|
+
interface TableOptions {
|
|
42
|
+
/** Folder under `root` that holds this table's files. Defaults to the SQL table name. */
|
|
43
|
+
readonly dir?: string;
|
|
44
|
+
/** Name of the column filled from the file name (without extension). Defaults to `id`. */
|
|
45
|
+
readonly key?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Name of the column filled from the markdown body. Defaults to `body`; when the table has no
|
|
48
|
+
* such column the body is not stored. Pass `false` to never store it.
|
|
49
|
+
*/
|
|
50
|
+
readonly body?: string | false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface MarkdownFile {
|
|
54
|
+
readonly data: JsonObject;
|
|
55
|
+
readonly body: string;
|
|
56
|
+
}
|
|
57
|
+
type ParseResult = {
|
|
58
|
+
readonly ok: true;
|
|
59
|
+
readonly file: MarkdownFile;
|
|
60
|
+
} | {
|
|
61
|
+
readonly ok: false;
|
|
62
|
+
readonly message: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Splits a markdown file into its YAML frontmatter and body. A file without a leading `---` fence
|
|
66
|
+
* has no frontmatter and its whole content is the body.
|
|
67
|
+
*/
|
|
68
|
+
declare const parseMarkdown: (source: string) => ParseResult;
|
|
69
|
+
|
|
70
|
+
type ChangeType = 'add' | 'change' | 'unlink' | 'invalid';
|
|
71
|
+
/** One file whose row was added, changed, removed, or dropped because it became invalid. */
|
|
72
|
+
interface ChangeEvent {
|
|
73
|
+
readonly type: ChangeType;
|
|
74
|
+
/** Schema key of the table. */
|
|
75
|
+
readonly table: string;
|
|
76
|
+
/** File path relative to `root`, with forward slashes. */
|
|
77
|
+
readonly file: string;
|
|
78
|
+
/** File name without extension, which is the row's key. */
|
|
79
|
+
readonly key: string;
|
|
80
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
81
|
+
}
|
|
82
|
+
interface TableReport {
|
|
83
|
+
readonly table: string;
|
|
84
|
+
readonly dir: string;
|
|
85
|
+
/** Files loaded as rows. */
|
|
86
|
+
readonly rows: number;
|
|
87
|
+
/** Files left out because of diagnostics. */
|
|
88
|
+
readonly skipped: number;
|
|
89
|
+
/** Frontmatter keys that match no column, with the number of files that use each. */
|
|
90
|
+
readonly unknownKeys: Readonly<Record<string, number>>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface WatchOptions {
|
|
94
|
+
/** Wait this long after the last event for a file before reading it. Defaults to 50 ms. */
|
|
95
|
+
readonly debounceMs?: number;
|
|
96
|
+
/** Keep the process alive while watching. Defaults to true. */
|
|
97
|
+
readonly persistent?: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type InvalidFileMode = 'throw' | 'skip';
|
|
101
|
+
/** Options shared by every MarkdownSQL entry point. */
|
|
102
|
+
interface BaseOptions {
|
|
103
|
+
/** Folder that holds one sub-folder per table. Relative paths resolve from the working directory. */
|
|
104
|
+
readonly root: string;
|
|
105
|
+
/**
|
|
106
|
+
* What to do with files that fail validation on the first load. `throw` (default) rejects with
|
|
107
|
+
* every diagnostic; `skip` leaves those files out and reports them. While watching, invalid files
|
|
108
|
+
* are always skipped and reported, so a typo in one file never stops the dev server.
|
|
109
|
+
*/
|
|
110
|
+
readonly onInvalid?: InvalidFileMode;
|
|
111
|
+
/** Called for every diagnostic, on the first load and while watching. */
|
|
112
|
+
readonly onDiagnostic?: (diagnostic: Diagnostic) => void;
|
|
113
|
+
/** Start watching right away. Pass options to tune the watcher. */
|
|
114
|
+
readonly watch?: boolean | WatchOptions;
|
|
115
|
+
/** File extensions that count as rows. Defaults to `['.md']`. */
|
|
116
|
+
readonly extensions?: readonly string[];
|
|
117
|
+
}
|
|
118
|
+
interface IndexReport {
|
|
119
|
+
/** Hash of the table structure. It changes when the schema or table options change. */
|
|
120
|
+
readonly schemaHash: string;
|
|
121
|
+
readonly tables: readonly TableReport[];
|
|
122
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
123
|
+
}
|
|
124
|
+
type ChangeListener = (events: readonly ChangeEvent[]) => void;
|
|
125
|
+
/** The index lifecycle every MarkdownSQL instance has, whatever its query surface. */
|
|
126
|
+
interface MarkdownSqlIndex {
|
|
127
|
+
/** Current diagnostics for files that are left out of the index. */
|
|
128
|
+
readonly diagnostics: () => readonly Diagnostic[];
|
|
129
|
+
/** Row counts, skipped files and frontmatter keys that match no column, per table. */
|
|
130
|
+
readonly report: () => IndexReport;
|
|
131
|
+
/** Re-scans every folder. Unchanged files are skipped by checksum. */
|
|
132
|
+
readonly reload: () => Promise<readonly ChangeEvent[]>;
|
|
133
|
+
/** Starts watching the table folders. Calling it again does nothing. */
|
|
134
|
+
readonly watch: (options?: WatchOptions) => void;
|
|
135
|
+
/** Listens for batches of row changes from the watcher or `reload`. Returns an unsubscribe function. */
|
|
136
|
+
readonly subscribe: (listener: ChangeListener) => () => void;
|
|
137
|
+
/** Resolves once every queued file update has been applied. */
|
|
138
|
+
readonly settled: () => Promise<void>;
|
|
139
|
+
/** Stops watching and closes the in-memory database. */
|
|
140
|
+
readonly close: () => Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { type BaseOptions as B, type ChangeEvent as C, type Diagnostic as D, type IndexReport as I, type JsonArray as J, type MarkdownSqlIndex as M, type TableOptions as T, type WatchOptions as W, type ChangeListener as a, type ChangeType as b, type DiagnosticCode as c, type InvalidFileMode as d, type JsonObject as e, type JsonPrimitive as f, type JsonValue as g, type MarkdownFile as h, type MarkdownSqlError as i, type MarkdownSqlErrorCode as j, type TableReport as k, findMarkdownSqlError as l, formatDiagnostic as m, isMarkdownSqlError as n, type ColumnRole as o, parseMarkdown as p };
|