@yolean/evidence 0.0.0-stage → 40.3.0

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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/cli.js +436 -0
  3. package/package.json +66 -3
  4. package/template/README.md +11 -0
  5. package/template/postcss.config.cjs +15 -0
  6. package/template/src/app.css +327 -0
  7. package/template/src/app.html +96 -0
  8. package/template/src/fix-tprotocol-service-worker.js +36 -0
  9. package/template/src/global.d.ts +1 -0
  10. package/template/src/hooks.client.js +19 -0
  11. package/template/src/hooks.server.js +41 -0
  12. package/template/src/pages/+error.svelte +57 -0
  13. package/template/src/pages/+layout.js +220 -0
  14. package/template/src/pages/+layout.svelte +10 -0
  15. package/template/src/pages/+page.md +16 -0
  16. package/template/src/pages/api/[...route]/evidencemeta.json/+server.js +48 -0
  17. package/template/src/pages/api/[route_hash]/[additional_hash]/all-queries.json/+server.js +10 -0
  18. package/template/src/pages/api/customFormattingSettings.json/+server.js +82 -0
  19. package/template/src/pages/api/customFormattingSettings.json/GET.json/+server.js +6 -0
  20. package/template/src/pages/api/pagesManifest.json/+server.js +92 -0
  21. package/template/src/pages/api/pagesManifest.json/buildPageManifest.spec.js +274 -0
  22. package/template/src/pages/api/prerendered_queries/[query_hash].arrow/+server.js +10 -0
  23. package/template/src/pages/api/settings.json/+server.js +107 -0
  24. package/template/src/pages/explore/+layout.js +5 -0
  25. package/template/src/pages/explore/console/+page.svelte +5 -0
  26. package/template/src/pages/explore/schema/+page.svelte +13 -0
  27. package/template/src/pages/fix-tprotocol-service-worker.js/+server.js +20 -0
  28. package/template/src/pages/manifest.webmanifest/+server.js +21 -0
  29. package/template/src/pages/settings/+layout.server.js +1 -0
  30. package/template/src/pages/settings/+page.js +25 -0
  31. package/template/src/pages/settings/+page.server.js +110 -0
  32. package/template/src/pages/settings/+page.svelte +111 -0
  33. package/template/static/apple-touch-icon.png +0 -0
  34. package/template/static/favicon.ico +0 -0
  35. package/template/static/icon-192.png +0 -0
  36. package/template/static/icon-512.png +0 -0
  37. package/template/static/icon.svg +6 -0
  38. package/template/svelte.config.js +106 -0
  39. package/template/tailwind.config.cjs +48 -0
  40. package/template/vite.config.js +99 -0
  41. package/README.md +0 -3
@@ -0,0 +1,274 @@
1
+ import { _buildPageManifest } from './+server';
2
+ import { describe, it, expect } from 'vitest';
3
+
4
+ describe('_buildPageManifest', () => {
5
+ it('should return the correct page manifest for a single page', () => {
6
+ const pages = {
7
+ '/src/pages/+page.md': '---\ntitle: Home\n---\n\nThis is the home page.'
8
+ };
9
+
10
+ const expectedManifest = {
11
+ label: 'Home',
12
+ href: '/',
13
+ children: {},
14
+ frontMatter: { title: 'Home' },
15
+ isTemplated: false,
16
+ isPage: true
17
+ };
18
+
19
+ const manifest = _buildPageManifest(pages);
20
+
21
+ expect(manifest).toEqual(expectedManifest);
22
+ });
23
+
24
+ it('should return the correct page manifest for multiple pages with a single child', () => {
25
+ const pages = {
26
+ '/src/pages/+page.md': '---\ntitle: Home\n---\n\nThis is the home page.',
27
+ '/src/pages/about/+page.md': '---\ntitle: About\n---\n\nThis is the about page.'
28
+ };
29
+
30
+ const expectedManifest = {
31
+ label: 'Home',
32
+ href: '/',
33
+ children: {
34
+ about: {
35
+ label: 'about',
36
+ href: '/about',
37
+ children: {},
38
+ frontMatter: { title: 'About' },
39
+ isTemplated: false,
40
+ isPage: true
41
+ }
42
+ },
43
+ frontMatter: { title: 'Home' },
44
+ isTemplated: false,
45
+ isPage: true
46
+ };
47
+
48
+ const manifest = _buildPageManifest(pages);
49
+
50
+ expect(manifest).toEqual(expectedManifest);
51
+ });
52
+
53
+ it('should return the correct page manifest for multiple pages', () => {
54
+ const pages = {
55
+ '/src/pages/+page.md': '---\ntitle: Home\n---\n\nThis is the home page.',
56
+ '/src/pages/about/+page.md': '---\ntitle: About\n---\n\nThis is the about page.',
57
+ '/src/pages/contact/+page.md': '---\ntitle: Contact\n---\n\nThis is the contact page.'
58
+ };
59
+
60
+ const expectedManifest = {
61
+ label: 'Home',
62
+ href: '/',
63
+ children: {
64
+ about: {
65
+ label: 'about',
66
+ href: '/about',
67
+ children: {},
68
+ frontMatter: { title: 'About' },
69
+ isTemplated: false,
70
+ isPage: true
71
+ },
72
+ contact: {
73
+ label: 'contact',
74
+ href: '/contact',
75
+ children: {},
76
+ frontMatter: { title: 'Contact' },
77
+ isTemplated: false,
78
+ isPage: true
79
+ }
80
+ },
81
+ frontMatter: { title: 'Home' },
82
+ isTemplated: false,
83
+ isPage: true
84
+ };
85
+
86
+ const manifest = _buildPageManifest(pages);
87
+
88
+ expect(manifest).toEqual(expectedManifest);
89
+ });
90
+
91
+ it('should return the correct page manifest for templated pages', () => {
92
+ const pages = {
93
+ '/src/pages/[slug]/+page.md':
94
+ '---\nbreadcrumb: "SELECT title as breadcrumb FROM table WHERE id = {params.id}"\n---\n\nThis is the [slug] page.'
95
+ };
96
+
97
+ const expectedManifest = {
98
+ label: 'Home',
99
+ href: undefined,
100
+ children: {
101
+ '[slug]': {
102
+ label: undefined,
103
+ href: undefined,
104
+ children: {},
105
+ frontMatter: {
106
+ breadcrumb: 'SELECT title as breadcrumb FROM table WHERE id = {params.id}'
107
+ },
108
+ isTemplated: true,
109
+ isPage: true
110
+ }
111
+ },
112
+ frontMatter: {},
113
+ isTemplated: false,
114
+ isPage: false
115
+ };
116
+
117
+ const manifest = _buildPageManifest(pages);
118
+
119
+ expect(manifest).toEqual(expectedManifest);
120
+ });
121
+
122
+ it('should return the correct page manifest for templated pages with children', () => {
123
+ const pages = {
124
+ '/src/pages/[slug]/+page.md':
125
+ '---\nbreadcrumb: "SELECT title as breadcrumb FROM table WHERE id = {params.id}"\n---\n\nThis is the [slug] page.',
126
+ '/src/pages/[slug]/child/+page.md': '---\ntitle: Child\n---\n\nThis is the child page.'
127
+ };
128
+
129
+ const expectedManifest = {
130
+ label: 'Home',
131
+ href: undefined,
132
+ children: {
133
+ '[slug]': {
134
+ label: undefined,
135
+ href: undefined,
136
+ children: {
137
+ child: {
138
+ label: 'child',
139
+ href: undefined,
140
+ children: {},
141
+ frontMatter: { title: 'Child' },
142
+ isTemplated: false,
143
+ isPage: true
144
+ }
145
+ },
146
+ frontMatter: {
147
+ breadcrumb: 'SELECT title as breadcrumb FROM table WHERE id = {params.id}'
148
+ },
149
+ isTemplated: true,
150
+ isPage: true
151
+ }
152
+ },
153
+ frontMatter: {},
154
+ isTemplated: false,
155
+ isPage: false
156
+ };
157
+
158
+ const manifest = _buildPageManifest(pages);
159
+
160
+ expect(manifest).toEqual(expectedManifest);
161
+ });
162
+
163
+ it('should return the correct page manifest for templated pages with multiple children', () => {
164
+ const pages = {
165
+ '/src/pages/[slug]/+page.md':
166
+ '---\nbreadcrumb: "SELECT title as breadcrumb FROM table WHERE id = {params.id}"\n---\n\nThis is the [slug] page.',
167
+ '/src/pages/[slug]/child/+page.md': '---\ntitle: Child\n---\n\nThis is the child page.',
168
+ '/src/pages/[slug]/grandchild/+page.md':
169
+ '---\ntitle: Grandchild\n---\n\nThis is the grandchild page.'
170
+ };
171
+
172
+ const expectedManifest = {
173
+ label: 'Home',
174
+ href: undefined,
175
+ children: {
176
+ '[slug]': {
177
+ label: undefined,
178
+ href: undefined,
179
+ children: {
180
+ child: {
181
+ label: 'child',
182
+ href: undefined,
183
+ children: {},
184
+ frontMatter: { title: 'Child' },
185
+ isTemplated: false,
186
+ isPage: true
187
+ },
188
+ grandchild: {
189
+ label: 'grandchild',
190
+ href: undefined,
191
+ children: {},
192
+ frontMatter: { title: 'Grandchild' },
193
+ isTemplated: false,
194
+ isPage: true
195
+ }
196
+ },
197
+ frontMatter: {
198
+ breadcrumb: 'SELECT title as breadcrumb FROM table WHERE id = {params.id}'
199
+ },
200
+ isTemplated: true,
201
+ isPage: true
202
+ }
203
+ },
204
+ frontMatter: {},
205
+ isTemplated: false,
206
+ isPage: false
207
+ };
208
+
209
+ const manifest = _buildPageManifest(pages);
210
+
211
+ expect(manifest).toEqual(expectedManifest);
212
+ });
213
+
214
+ it('should return the correct page manifest for templated pages with multiple children and nested templated pages', () => {
215
+ const pages = {
216
+ '/src/pages/[slug]/+page.md':
217
+ '---\nbreadcrumb: "SELECT title as breadcrumb FROM table WHERE id = {params.id}"\n---\n\nThis is the [slug] page.',
218
+ '/src/pages/[slug]/child/+page.md': '---\ntitle: Child\n---\n\nThis is the child page.',
219
+ '/src/pages/[slug]/[id]/+page.md': '---\ntitle: ID\n---\n\nThis is the [id] page.',
220
+ '/src/pages/[slug]/[id]/grandchild/+page.md':
221
+ '---\ntitle: Grandchild\n---\n\nThis is the grandchild page.'
222
+ };
223
+
224
+ const expectedManifest = {
225
+ label: 'Home',
226
+ href: undefined,
227
+ children: {
228
+ '[slug]': {
229
+ label: undefined,
230
+ href: undefined,
231
+ children: {
232
+ child: {
233
+ label: 'child',
234
+ href: undefined,
235
+ children: {},
236
+ frontMatter: { title: 'Child' },
237
+ isTemplated: false,
238
+ isPage: true
239
+ },
240
+ '[id]': {
241
+ label: undefined,
242
+ href: undefined,
243
+ children: {
244
+ grandchild: {
245
+ label: 'grandchild',
246
+ href: undefined,
247
+ children: {},
248
+ frontMatter: { title: 'Grandchild' },
249
+ isTemplated: false,
250
+ isPage: true
251
+ }
252
+ },
253
+ frontMatter: { title: 'ID' },
254
+ isTemplated: true,
255
+ isPage: true
256
+ }
257
+ },
258
+ frontMatter: {
259
+ breadcrumb: 'SELECT title as breadcrumb FROM table WHERE id = {params.id}'
260
+ },
261
+ isTemplated: true,
262
+ isPage: true
263
+ }
264
+ },
265
+ frontMatter: {},
266
+ isTemplated: false,
267
+ isPage: false
268
+ };
269
+
270
+ const manifest = _buildPageManifest(pages);
271
+
272
+ expect(manifest).toEqual(expectedManifest);
273
+ });
274
+ });
@@ -0,0 +1,10 @@
1
+ import { get_cache_for_hash } from '@evidence-dev/universal-sql';
2
+ import { error } from '@sveltejs/kit';
3
+
4
+ export const GET = ({ params }) => {
5
+ try {
6
+ return new Response(get_cache_for_hash(params.query_hash));
7
+ } catch (e) {
8
+ throw error(404, 'not found');
9
+ }
10
+ };
@@ -0,0 +1,107 @@
1
+ export const prerender = false;
2
+
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import gitRemoteOriginUrl from 'git-remote-origin-url'; // get the git repo
6
+ import { dev } from '$app/environment';
7
+ import { logEvent } from '@evidence-dev/telemetry';
8
+ import { json } from '@sveltejs/kit';
9
+
10
+ function getLocalGitRepo() {
11
+ if (fs.existsSync(path.join(path.resolve('../../'), '.git'))) {
12
+ return path.resolve('../../');
13
+ }
14
+ }
15
+
16
+ export async function GET() {
17
+ if (!dev) {
18
+ return new Response(undefined, { status: 404 });
19
+ } else {
20
+ let settings = {};
21
+ let gitIgnore;
22
+ if (fs.existsSync('evidence.settings.json')) {
23
+ settings = JSON.parse(fs.readFileSync('evidence.settings.json', 'utf8'));
24
+ }
25
+ if (fs.existsSync('../../.gitignore')) {
26
+ gitIgnore = fs.readFileSync('../../.gitignore', 'utf8');
27
+ }
28
+ try {
29
+ settings.localGitRepo = getLocalGitRepo();
30
+ settings.gitRepo = await gitRemoteOriginUrl();
31
+ } catch {
32
+ /* ignore errors */
33
+ }
34
+ return json({ settings, gitIgnore });
35
+ }
36
+ }
37
+
38
+ function removeFromGitignore(extensions, hasGitIgnore, gitIgnore) {
39
+ if (hasGitIgnore) {
40
+ extensions.forEach((ext) => {
41
+ // Find newline plus extension and only match those strings which are directly
42
+ // followed by either a new line or the end of the file contents
43
+ // (stops the issue of matching .sqlite within the .sqlite3 string)
44
+ // g means global match - same behaviour as replaceAll
45
+ let regex = new RegExp(`\n${ext}(?=\n|$)`, 'g');
46
+ gitIgnore = gitIgnore.replace(regex, '');
47
+ });
48
+ fs.writeFileSync('../../.gitignore', gitIgnore);
49
+ }
50
+ }
51
+
52
+ function addToGitignore(extensions, gitIgnore) {
53
+ extensions.forEach((ext) => {
54
+ let regex = new RegExp(`\n${ext}(?=\n|$)`, 'g');
55
+ if (!gitIgnore.match(regex)) {
56
+ gitIgnore = gitIgnore + ('\n' + ext);
57
+ }
58
+ });
59
+ fs.writeFileSync('../../.gitignore', gitIgnore);
60
+ }
61
+
62
+ export async function POST({ request }) {
63
+ const { settings } = await request.json();
64
+ // read original settings file
65
+ let originalSettings = {};
66
+ if (fs.existsSync('evidence.settings.json')) {
67
+ originalSettings = JSON.parse(fs.readFileSync('evidence.settings.json', 'utf8'));
68
+ }
69
+ // check if send_anonymous_usage_stats has changed and log an event if it has changed from not 'no' (or undefined) to no
70
+ if (
71
+ originalSettings.send_anonymous_usage_stats != 'no' &&
72
+ settings.send_anonymous_usage_stats === 'no'
73
+ ) {
74
+ logEvent('usageStatsDisabled', dev, originalSettings);
75
+ }
76
+ fs.writeFileSync('evidence.settings.json', JSON.stringify(settings));
77
+
78
+ // gitignore settings
79
+ let gitIgnore;
80
+ let hasGitIgnore = fs.existsSync('../../.gitignore');
81
+ gitIgnore = hasGitIgnore ? fs.readFileSync('../../.gitignore', 'utf8') : '';
82
+ let extensions;
83
+
84
+ if (settings.database === 'sqlite') {
85
+ extensions = ['.db', '.sqlite', '.sqlite3'];
86
+ if (settings.credentials.gitignoreSqlite === false) {
87
+ removeFromGitignore(extensions, hasGitIgnore, gitIgnore);
88
+ } else if (settings.credentials.gitignoreSqlite === true) {
89
+ addToGitignore(extensions, gitIgnore);
90
+ }
91
+ } else if (settings.database === 'duckdb') {
92
+ extensions = ['.duckdb', '.db'];
93
+ if (settings.credentials.gitignoreDuckdb === false) {
94
+ removeFromGitignore(extensions, hasGitIgnore, gitIgnore);
95
+ } else if (settings.credentials.gitignoreDuckdb === true) {
96
+ addToGitignore(extensions, gitIgnore);
97
+ }
98
+ } else if (settings.database === 'csv') {
99
+ extensions = ['.csv'];
100
+ if (settings.credentials.gitignoreCsv === false) {
101
+ removeFromGitignore(extensions, hasGitIgnore, gitIgnore);
102
+ } else if (settings.credentials.gitignoreCsv === true) {
103
+ addToGitignore(extensions, gitIgnore);
104
+ }
105
+ }
106
+ return json(settings);
107
+ }
@@ -0,0 +1,5 @@
1
+ import { dev } from '$app/environment';
2
+
3
+ export const ssr = dev;
4
+ export const csr = dev;
5
+ export const prerender = dev;
@@ -0,0 +1,5 @@
1
+ <script>
2
+ import { SqlConsole } from '@evidence-dev/core-components';
3
+ </script>
4
+
5
+ <SqlConsole />
@@ -0,0 +1,13 @@
1
+ <script>
2
+ import { SchemaExplorer } from '@evidence-dev/core-components';
3
+ export let data;
4
+ </script>
5
+
6
+ <h1 class="markdown">Project Schema</h1>
7
+ <p class="markdown">
8
+ This page details the tables and columns that are currently loaded in your project.
9
+ </p>
10
+
11
+ <h2 class="markdown">Sources</h2>
12
+
13
+ <SchemaExplorer {data} />
@@ -0,0 +1,20 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ export const prerender = true;
5
+
6
+ /** @type {import('@sveltejs/kit').RequestHandler} */
7
+ export const GET = () => {
8
+ const swPath = path.join(process.cwd(), 'src', 'fix-tprotocol-service-worker.js');
9
+ let content = fs.readFileSync(swPath, 'utf-8');
10
+
11
+ if (import.meta.env.VITE_EVIDENCE_DISABLE_WINDOWS_CACHE_SERVICE_WORKER === 'true') {
12
+ content = content.replace('const disabled = false;', `const disabled = true;`);
13
+ }
14
+
15
+ return new Response(content, {
16
+ headers: {
17
+ 'Content-Type': 'application/javascript'
18
+ }
19
+ });
20
+ };
@@ -0,0 +1,21 @@
1
+ import { base } from '$app/paths';
2
+
3
+ export const prerender = true;
4
+
5
+ const webmanifest = {
6
+ icons: [
7
+ {
8
+ src: `${base}/icon-192.png`,
9
+ type: 'image/png',
10
+ sizes: '192x192'
11
+ },
12
+ {
13
+ src: `${base}/icon-512.png`,
14
+ type: 'image/png',
15
+ sizes: '512x512'
16
+ }
17
+ ]
18
+ };
19
+
20
+ /** @type {import('./$types').RequestHandler} */
21
+ export const GET = () => new Response(JSON.stringify(webmanifest));
@@ -0,0 +1 @@
1
+ export const prerender = false;
@@ -0,0 +1,25 @@
1
+ import { dev } from '$app/environment';
2
+ import { addBasePath } from '@evidence-dev/sdk/utils/svelte';
3
+
4
+ export const load = async ({ fetch, data }) => {
5
+ if (dev) {
6
+ const settingsRes = await fetch(addBasePath('/api/settings.json'));
7
+ const customFormattingSettingsRes = await fetch(
8
+ addBasePath('/api/customFormattingSettings.json')
9
+ );
10
+ const { settings, gitIgnore } = await settingsRes.json();
11
+ const { customFormattingSettings } = await customFormattingSettingsRes.json();
12
+ return {
13
+ ...data,
14
+ settings,
15
+ gitIgnore,
16
+ customFormattingSettings
17
+ };
18
+ } else {
19
+ return {
20
+ ...data,
21
+ settings: {},
22
+ gitIgnore: ''
23
+ };
24
+ }
25
+ };
@@ -0,0 +1,110 @@
1
+ // @ts-check
2
+
3
+ import { dev } from '$app/environment';
4
+ import { fail } from '@sveltejs/kit';
5
+ import { logQueryEvent } from '@evidence-dev/telemetry';
6
+ import {
7
+ loadSources,
8
+ loadSourcePlugins,
9
+ DatasourceSpecFileSchema,
10
+ Options,
11
+ writeSourceConfig,
12
+ getDatasourceConfigAsEnvironmentVariables
13
+ } from '@evidence-dev/sdk/plugins';
14
+ import { log } from '@evidence-dev/sdk/logger';
15
+
16
+ export const load = async () => {
17
+ if (dev) {
18
+ const sources = await loadSources();
19
+ const datasources = await loadSourcePlugins();
20
+
21
+ const plugins = Object.entries(datasources.bySource).reduce((acc, [name, v]) => {
22
+ acc[name] = {
23
+ package: { package: v[0] },
24
+ options: v[1].options
25
+ };
26
+ return acc;
27
+ }, {});
28
+
29
+ return {
30
+ sources: sources.map((source) => ({
31
+ ...source,
32
+ environmentVariables: getDatasourceConfigAsEnvironmentVariables(source)
33
+ })),
34
+ plugins
35
+ };
36
+ }
37
+ return {};
38
+ };
39
+
40
+ /** @type {import("@sveltejs/kit").Actions} */
41
+ export const actions = {
42
+ updateSource: async (e) => {
43
+ // editSourceConfig, refactor to use logic without prompts
44
+ const formData = Object.fromEntries(/** @type {any} */ (await e.request.formData()));
45
+ const source = formData.source ? JSON.parse(formData.source) : null;
46
+
47
+ if (!source) {
48
+ return fail(400, { message: "Missing required field 'source'" });
49
+ }
50
+
51
+ const r = DatasourceSpecFileSchema.safeParse(source);
52
+
53
+ if (!r.success) {
54
+ return fail(400, r.error.format());
55
+ }
56
+
57
+ const datasourcePlugins = await loadSourcePlugins();
58
+ const [, pluginSpec] = datasourcePlugins.getBySource(r.data.type);
59
+ const opts = Options(pluginSpec.options, r.data.options);
60
+ // Possible holdovers from the loading process
61
+ delete source.environmentVariables;
62
+ delete source.initialName;
63
+
64
+ try {
65
+ return {
66
+ updatedSource: await writeSourceConfig(opts, source)
67
+ };
68
+ } catch (e) {
69
+ log.debug(`error updating sources: ${e}`, { error: e });
70
+ return fail(500, e.message);
71
+ }
72
+ },
73
+ testSource: async (e) => {
74
+ // loadSourcePlugins().getByPackageName('')[1].testConnection
75
+ const formData = Object.fromEntries(/** @type {any} */ (await e.request.formData()));
76
+ if (!formData?.source) {
77
+ return fail(400, { message: "Missing required field 'source'" });
78
+ }
79
+
80
+ const source = formData.source ? JSON.parse(formData.source) : null;
81
+
82
+ if (!source) {
83
+ return fail(400, { message: "Missing required field 'source'" });
84
+ }
85
+
86
+ const r = DatasourceSpecFileSchema.safeParse(source);
87
+
88
+ if (!r.success) {
89
+ return fail(400, r.error.format());
90
+ }
91
+ const datasourcePlugins = await loadSourcePlugins();
92
+ const [_, pluginSpec] = datasourcePlugins.getBySource(r.data.type);
93
+
94
+ if (!pluginSpec) {
95
+ logQueryEvent('db-plugin-unvailable', r.data.type, undefined, undefined, dev);
96
+ return fail(400, { message: `Plugin for datasource "${r.data.type}" not found.` });
97
+ }
98
+ const valid = await pluginSpec.testConnection(r.data.options, source.dir);
99
+
100
+ if (valid !== true) {
101
+ logQueryEvent('db-connection-error', r.data.type, r.data.name, undefined, dev);
102
+ return fail(200, { message: valid.reason });
103
+ } else {
104
+ logQueryEvent('db-connection-success', r.data.type, r.data.name, undefined, dev);
105
+ return {
106
+ success: true
107
+ };
108
+ }
109
+ }
110
+ };