@yolean/evidence-sdk 0.0.0-stage → 4.1.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.
- package/CHANGELOG.md +538 -0
- package/LICENSE.md +9 -0
- package/README.md +237 -2
- package/package.json +161 -3
- package/src/build-dev/cli/add/addServerHook.js +30 -0
- package/src/build-dev/cli/add/addTypeRef.js +19 -0
- package/src/build-dev/cli/add/updateGitIgnore.js +33 -0
- package/src/build-dev/cli/add/updatePackageJson.js +26 -0
- package/src/build-dev/cli/add/updateSvelteConfig.js +199 -0
- package/src/build-dev/cli/add/updateViteConfig.js +152 -0
- package/src/build-dev/cli/add.js +95 -0
- package/src/build-dev/cli/build.js +30 -0
- package/src/build-dev/cli/dev.js +49 -0
- package/src/build-dev/cli/index.js +14 -0
- package/src/build-dev/cli/upgrade.js +54 -0
- package/src/build-dev/svelte/index.js +54 -0
- package/src/build-dev/svelte/lib/isTargetFile.js +6 -0
- package/src/build-dev/svelte/metadatas.js +39 -0
- package/src/build-dev/svelte/processors/addBasePathToHrefAndSrc/addBasePathToHrefAndSrc.js +29 -0
- package/src/build-dev/svelte/processors/addBasePathToHrefAndSrc/addBasePathToHrefAndSrc.spec.js +82 -0
- package/src/build-dev/svelte/processors/addScriptTags.js +17 -0
- package/src/build-dev/svelte/processors/convertToHtml/convertToHtml.js +19 -0
- package/src/build-dev/svelte/processors/convertToHtml/convertToHtml.spec.js +123 -0
- package/src/build-dev/svelte/processors/convertToHtml/processMarkdown.js +59 -0
- package/src/build-dev/svelte/processors/extractQueries/extractQueries.js +49 -0
- package/src/build-dev/svelte/processors/extractQueries/extractQueries.spec.js +54 -0
- package/src/build-dev/svelte/processors/highlight/highlight.js +52 -0
- package/src/build-dev/svelte/processors/highlight/highlight.spec.js +31 -0
- package/src/build-dev/svelte/processors/initializeUniversalSql.js +15 -0
- package/src/build-dev/svelte/processors/injectComponents/injectComponents.js +56 -0
- package/src/build-dev/svelte/processors/injectHighlightStyles.js +14 -0
- package/src/build-dev/svelte/processors/injectQueries/injectQueries.js +77 -0
- package/src/build-dev/svelte/processors/markRootLayoutPrerenderable.js +56 -0
- package/src/build-dev/svelte/processors/obfuscateCode/obfuscateCode.js +17 -0
- package/src/build-dev/svelte/processors/obfuscateCode/obfuscateCode.spec.js +21 -0
- package/src/build-dev/svelte/processors/transformQueries/transformQueries.js +58 -0
- package/src/build-dev/vite/config-virtual.js +24 -0
- package/src/build-dev/vite/constants.js +7 -0
- package/src/build-dev/vite/datasource-plugins/source-query-hmr.js +117 -0
- package/src/build-dev/vite/evidence-config.d.ts +6 -0
- package/src/build-dev/vite/index.js +214 -0
- package/src/build-dev/vite/layout-plugins/copy-to-layout.js +71 -0
- package/src/build-dev/vite/plugins.js +4 -0
- package/src/build-dev/vite/query-directory-hmr.js +32 -0
- package/src/build-dev/vite/sidecar-app.js +79 -0
- package/src/build-dev/vite/virtuals/QuerySSR.svelte +13 -0
- package/src/build-dev/vite/virtuals/__tests/proxyStack.spec.js +52 -0
- package/src/build-dev/vite/virtuals/bootstrapContexts.svelte.js +27 -0
- package/src/build-dev/vite/virtuals/browser/static-assets.js +3 -0
- package/src/build-dev/vite/virtuals/contextKeys.js +3 -0
- package/src/build-dev/vite/virtuals/initUsql.js +23 -0
- package/src/build-dev/vite/virtuals/node/static-assets.js +56 -0
- package/src/build-dev/vite/virtuals/proxyStack.js +37 -0
- package/src/build-dev/vite/virtuals/queries.svelte.js +150 -0
- package/src/build-dev/vite/virtuals/ssrHook.svelte.js +60 -0
- package/src/build-dev/vite/virtuals/updateQueryContext.svelte.js +31 -0
- package/src/build-dev/vite/virtuals-dynamic.js +12 -0
- package/src/cli.js +5 -0
- package/src/cli.root.js +90 -0
- package/src/configuration/cli/create.js +20 -0
- package/src/configuration/cli/index.js +12 -0
- package/src/configuration/createEvidenceConfig.js +51 -0
- package/src/configuration/getEvidenceConfig.js +60 -0
- package/src/configuration/getEvidenceConfig.legacy.js +27 -0
- package/src/configuration/index.js +1 -0
- package/src/configuration/schemas/config.schema.js +11 -0
- package/src/configuration/schemas/deployment.schema.js +9 -0
- package/src/configuration/schemas/deployment.schema.spec.js +34 -0
- package/src/configuration/updateEvidenceConfig.js +25 -0
- package/src/legacy-compat.js +8 -0
- package/src/lib/EvidenceError.js +35 -0
- package/src/lib/b64Deep.js +55 -0
- package/src/lib/check-import.js +12 -0
- package/src/lib/cleanZodErrors.js +22 -0
- package/src/lib/cli/cmdFail.js +33 -0
- package/src/lib/cli/notices.js +44 -0
- package/src/lib/debug.js +40 -0
- package/src/lib/flows.d.ts +21 -0
- package/src/lib/forceLink.js +28 -0
- package/src/lib/history/index.js +70 -0
- package/src/lib/history/types.d.ts +8 -0
- package/src/lib/pkg-types.helpers.js +16 -0
- package/src/lib/processing-queue.js +96 -0
- package/src/lib/processing-queue.spec.js +148 -0
- package/src/lib/projectPaths.js +29 -0
- package/src/lib/projectRoot.js +12 -0
- package/src/lib/sharedPromise.js +77 -0
- package/src/lib/sharedPromise.spec.js +23 -0
- package/src/lib/strict.js +19 -0
- package/src/lib/tests/fs.js +21 -0
- package/src/lib/tokens.js +7 -0
- package/src/lib/unnest-zod-error.js +14 -0
- package/src/logger/EvidenceLogger.js +164 -0
- package/src/logger/index.js +4 -0
- package/src/meta.js +8 -0
- package/src/plugins/cli/index.js +13 -0
- package/src/plugins/cli/install.js +26 -0
- package/src/plugins/cli/install.prompt.js +121 -0
- package/src/plugins/components/getAllComponents.js +82 -0
- package/src/plugins/components/getComponentsInPlugin.js +33 -0
- package/src/plugins/components/loadComponentPlugins.js +48 -0
- package/src/plugins/components/loaders/file-loader.js +125 -0
- package/src/plugins/components/loaders/manifest-loader.js +53 -0
- package/src/plugins/components/schemas/component-manifest.schema.js +5 -0
- package/src/plugins/components/types.d.ts +21 -0
- package/src/plugins/components/validateOverrides.js +30 -0
- package/src/plugins/components/validateOverrides.spec.js +32 -0
- package/src/plugins/datasources/Datasources.js +85 -0
- package/src/plugins/datasources/Datasources.spec.js +78 -0
- package/src/plugins/datasources/SourceResultCache.js +62 -0
- package/src/plugins/datasources/buildSourceDirectoryProxy.js +21 -0
- package/src/plugins/datasources/cli/edit/Options.fixtures.js +69 -0
- package/src/plugins/datasources/cli/edit/Options.js +253 -0
- package/src/plugins/datasources/cli/edit/Options.spec.js +496 -0
- package/src/plugins/datasources/cli/edit/editSourceConfig.js +201 -0
- package/src/plugins/datasources/cli/edit.js +20 -0
- package/src/plugins/datasources/cli/edit.prompt.js +100 -0
- package/src/plugins/datasources/cli/index.js +18 -0
- package/src/plugins/datasources/cli/sources.js +77 -0
- package/src/plugins/datasources/evalSources.js +257 -0
- package/src/plugins/datasources/getPublishedDatasources.js +62 -0
- package/src/plugins/datasources/index.js +6 -0
- package/src/plugins/datasources/loadSourceConfig.js +147 -0
- package/src/plugins/datasources/loadSourceConfig.spec.js +127 -0
- package/src/plugins/datasources/loadSourcePlugins.js +49 -0
- package/src/plugins/datasources/loadSources.js +48 -0
- package/src/plugins/datasources/schemas/datasource.schema.js +52 -0
- package/src/plugins/datasources/schemas/datasourceCache.schema.js +3 -0
- package/src/plugins/datasources/schemas/datasourcePlugin.schema.js +37 -0
- package/src/plugins/datasources/schemas/datasourcePluginOptions.schema.js +64 -0
- package/src/plugins/datasources/schemas/index.js +2 -0
- package/src/plugins/datasources/schemas/manifest.schema.js +8 -0
- package/src/plugins/datasources/schemas/results.schema.js +126 -0
- package/src/plugins/datasources/sub-source-vars.js +55 -0
- package/src/plugins/datasources/sub-source-vars.spec.js +46 -0
- package/src/plugins/datasources/types.d.ts +53 -0
- package/src/plugins/datasources/updateManifest.js +115 -0
- package/src/plugins/datasources/updateManifest.spec.js +200 -0
- package/src/plugins/datasources/wrapSimpleConnector.js +95 -0
- package/src/plugins/datasources/writeSourceConfig.js +60 -0
- package/src/plugins/index.js +2 -0
- package/src/plugins/layouts/copyMethods/index.js +10 -0
- package/src/plugins/layouts/copyMethods/svelte.js +53 -0
- package/src/plugins/layouts/copyMethods/sveltekit.js +75 -0
- package/src/plugins/layouts/copyToLayout.js +106 -0
- package/src/plugins/layouts/loadLayoutPlugin.js +23 -0
- package/src/plugins/loadPluginPackage.js +77 -0
- package/src/plugins/schemas/index.js +1 -0
- package/src/plugins/schemas/plugin-config.schema.js +41 -0
- package/src/plugins/schemas/plugin-config.schema.spec.js +21 -0
- package/src/plugins/schemas/plugin-package.schema.js +154 -0
- package/src/plugins/schemas/plugin-package.schema.spec.js +30 -0
- package/src/query-builder.d.ts +1 -0
- package/src/query-builder.js +1 -0
- package/src/types/duckdb-wellknown.d.ts +35 -0
- package/src/types/html-attributes.ts +13 -0
- package/src/types/index.d.ts +18 -0
- package/src/types/mosaic-sql.d.ts +27 -0
- package/src/types/sveltekit-autoimport.d.ts +13 -0
- package/src/types/virtuals.d.ts +113 -0
- package/src/types.d.ts +1 -0
- package/src/usql/index.d.ts +4 -0
- package/src/usql/index.js +3 -0
- package/src/usql/query/Query.js +1391 -0
- package/src/usql/query/Query.spec.js +827 -0
- package/src/usql/query/queryScore.js +92 -0
- package/src/usql/query/queryScore.spec.js +26 -0
- package/src/usql/query/sterilizeQuery.js +89 -0
- package/src/usql/query/sterilizeQuery.spec.js +172 -0
- package/src/usql/setTrackProxy/setTrackProxy.js +80 -0
- package/src/usql/setTrackProxy/setTrackProxy.spec.js +166 -0
- package/src/usql/types.ts +86 -0
- package/src/usql/utilities/duckdbSerialize.js +29 -0
- package/src/usql/utilities/index.js +2 -0
- package/src/usql/utilities/resolveMaybePromise.js +30 -0
- package/src/utils/batchUp.js +22 -0
- package/src/utils/batchUp.spec.js +69 -0
- package/src/utils/browserDebounce.js +16 -0
- package/src/utils/index.js +7 -0
- package/src/utils/svelte/addBasePath.js +45 -0
- package/src/utils/svelte/addBasePath.spec.js +86 -0
- package/src/utils/svelte/index.js +5 -0
- package/src/utils/svelte/inputs.js +138 -0
- package/tsconfig.json +22 -0
- package/vite.config.js +3 -0
- package/vitest.config.js +15 -0
package/README.md
CHANGED
|
@@ -1,3 +1,238 @@
|
|
|
1
|
-
|
|
1
|
+
<img src="../../../sites/docs/static/img/wordmark.svg" alt="evidence-logo" width="100%" />
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
<h1> Evidence SDK </h1>
|
|
6
|
+
The fastest way to build highly interactive data apps
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
[](https://slack.evidence.dev)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
**_This documentation has not been updated for the latest versions of the SDK_**
|
|
16
|
+
|
|
17
|
+
## How it works
|
|
18
|
+
|
|
19
|
+
The Evidence SDK contains all the tools needed to build interactive data apps, all the way from the database to the browser.
|
|
20
|
+
|
|
21
|
+
- **Datasource Connectors** - Plugins to connect to a variety of datasoures, including Databases, APIs, Flat files, and more
|
|
22
|
+
- **Run queries in the browser** - Universal SQL is the fastest way to use DuckDB WASM with your databases
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
1. (If needed), create your SvelteKit project (e.g. `npm create svelte`)
|
|
27
|
+
2. Install the SDK `npm i @evidence-dev/sdk@preview`
|
|
28
|
+
3. Add the SDK to your project using `npx evidence-sdk add`
|
|
29
|
+
4. Use `npx evidence-sdk plugins install` if you did not install a plugin during `add`
|
|
30
|
+
5. If the data source you want to use is not listed, and there is an Evidence plugin for it, you can install the package and add it to `evidence.config.yaml` manually.
|
|
31
|
+
5. Create a new connection with `npx evidence-sdk connections edit`
|
|
32
|
+
1. Once the connection is created, there will be a new `sources/[connection]` directory, for most connectors, you will need to create some source queries.
|
|
33
|
+
6. Populate the data with `npx evidence-sdk sources`
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
See [the wiki](https://github.com/evidence-dev/sdk/wiki)
|
|
38
|
+
|
|
39
|
+
There are 2 methods for executing queries using the Evidence SDK; using `<code/>` elements, and calling `runQuery` directly.
|
|
40
|
+
`<code/>` elements automatically make their results available to child components (or pages, if used in a layout), while
|
|
41
|
+
`runQuery` keeps the query scoped to the current page.
|
|
42
|
+
|
|
43
|
+
### Using `<code/>`
|
|
44
|
+
|
|
45
|
+
#### Writing Queries
|
|
46
|
+
|
|
47
|
+
To add a query to your page, use a `<code/>` element with an `evidence-query-name` attribute (`lang=sql` is optional but recommended).
|
|
48
|
+
|
|
49
|
+
Wrapping this in a `<pre>` tag will prevent formatters from changing your SQL.
|
|
50
|
+
|
|
51
|
+
Example:
|
|
52
|
+
|
|
53
|
+
```svelte
|
|
54
|
+
<pre><code evidence-query-name="myFirstQuery" lang="sql">
|
|
55
|
+
SELECT * FROM my_first_table
|
|
56
|
+
</code></pre>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
When using `<code/>`, you can interpolate variables from the page using _template string syntax_, Svelte syntax is not supported.
|
|
60
|
+
|
|
61
|
+
Working Example:
|
|
62
|
+
|
|
63
|
+
```svelte
|
|
64
|
+
<pre><code evidence-query-name="myFirstQuery" lang="sql">
|
|
65
|
+
SELECT * FROM my_first_table WHERE user_id = '${selectedUserId}'
|
|
66
|
+
</code></pre>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Broken Example:
|
|
70
|
+
|
|
71
|
+
```svelte
|
|
72
|
+
<pre><code evidence-query-name="myFirstQuery" lang="sql">
|
|
73
|
+
SELECT * FROM my_first_table WHERE user_id = '{selectedUserId}'
|
|
74
|
+
</code></pre>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Accessing Queries
|
|
78
|
+
|
|
79
|
+
To load queries that are placed on the page, create a reference to the queries store from `$evidence/queries`
|
|
80
|
+
|
|
81
|
+
```svelte
|
|
82
|
+
<script>
|
|
83
|
+
import { getQueries } from '$evidence/queries';
|
|
84
|
+
const queries = getQueries();
|
|
85
|
+
/** @type {import("@evidence-dev/query-store").QueryStore} */
|
|
86
|
+
let { myFirstQuery } = $queries;
|
|
87
|
+
$: ({ myFirstQuery } = $queries);
|
|
88
|
+
</script>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`$queries` is a set of [`QueryStore`](https://github.com/evidence-dev/evidence/tree/main/packages/query-store) based on what is provided on the page.
|
|
92
|
+
|
|
93
|
+
#### Full Example
|
|
94
|
+
|
|
95
|
+
```svelte
|
|
96
|
+
<script>
|
|
97
|
+
import { getQueries } from '$evidence/queries';
|
|
98
|
+
const queries = getQueries();
|
|
99
|
+
/** @type {import("@evidence-dev/query-store").QueryStore} */
|
|
100
|
+
let { myFirstQuery } = $queries;
|
|
101
|
+
$: ({ myFirstQuery } = $queries);
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<pre><code evidence-query-name="myFirstQuery" lang="sql">
|
|
105
|
+
SELECT * FROM my_first_table
|
|
106
|
+
</code></pre>
|
|
107
|
+
|
|
108
|
+
{#if !$myFirstQuery.loaded}
|
|
109
|
+
<!--
|
|
110
|
+
The query has not yet loaded.
|
|
111
|
+
$myFirstQuery.loading is also available,
|
|
112
|
+
but will be false if the store has not yet started to load.
|
|
113
|
+
|
|
114
|
+
QueryStore should begin loading automatically when attempting to access data,
|
|
115
|
+
but can be induced with .fetch()
|
|
116
|
+
-->
|
|
117
|
+
Loading...
|
|
118
|
+
{:else if $myFirstQuery.error}
|
|
119
|
+
<!-- An error has been encountered -->
|
|
120
|
+
Error: {$myFirstQuery.error.message}
|
|
121
|
+
{:else}
|
|
122
|
+
<!-- Results have been loaded -->
|
|
123
|
+
{#each $myFirstQuery as row (row.id)}
|
|
124
|
+
Row ID: {row.id}
|
|
125
|
+
{:else}
|
|
126
|
+
No resuls available
|
|
127
|
+
{/each}
|
|
128
|
+
{/if}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Using `runQuery`
|
|
132
|
+
|
|
133
|
+
#### Full Example
|
|
134
|
+
|
|
135
|
+
```svelte
|
|
136
|
+
<script>
|
|
137
|
+
import { runQuery } from '$evidence/queries';
|
|
138
|
+
|
|
139
|
+
const myFirstQuery = runQuery('myFirstQuery', 'SELECT 1');
|
|
140
|
+
myFirstQuery.fetch(); // This is not done for you when using runQuery
|
|
141
|
+
|
|
142
|
+
// Queries can by dynamic
|
|
143
|
+
let x = 0;
|
|
144
|
+
// declare here to ensure it is defined
|
|
145
|
+
let dynamicQuery = runQuery('dynamicQuery', `SELECT ${x}`);
|
|
146
|
+
// react to updates in the query string
|
|
147
|
+
$: dynamicQuery = runQuery('dynamicQuery', `SELECT ${x}`);
|
|
148
|
+
$: dynamicQuery.fetch();
|
|
149
|
+
</script>
|
|
150
|
+
|
|
151
|
+
<!-- Usage is the exact same as above -->
|
|
152
|
+
{#if !$myFirstQuery.loaded}
|
|
153
|
+
<!--
|
|
154
|
+
The query has not yet loaded.
|
|
155
|
+
$myFirstQuery.loading is also available,
|
|
156
|
+
but will be false if the store has not yet started to load.
|
|
157
|
+
|
|
158
|
+
QueryStore should begin loading automatically when attempting to access data,
|
|
159
|
+
but can be induced with .fetch()
|
|
160
|
+
-->
|
|
161
|
+
Loading...
|
|
162
|
+
{:else if $myFirstQuery.error}
|
|
163
|
+
<!-- An error has been encountered -->
|
|
164
|
+
Error: {$myFirstQuery.error.message}
|
|
165
|
+
{:else}
|
|
166
|
+
<!-- Results have been loaded -->
|
|
167
|
+
{#each $myFirstQuery as row (row.id)}
|
|
168
|
+
Row ID: {row.id}
|
|
169
|
+
{:else}
|
|
170
|
+
No resuls available
|
|
171
|
+
{/each}
|
|
172
|
+
{/if}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Enabling SSR
|
|
176
|
+
|
|
177
|
+
If you are using the [`<code/>`](#using-code) method, all you need to do is make sure the server hook is installed.
|
|
178
|
+
|
|
179
|
+
If you are using the [`runQuery`](#using-runquery) method, you will need to use the `<QuerySSR/>` component.
|
|
180
|
+
|
|
181
|
+
#### Configuring SSR Hook
|
|
182
|
+
|
|
183
|
+
1. Ensure that you have a `./src/hooks.server.[js|ts]` file
|
|
184
|
+
2. Create or update the `handle` function to match:
|
|
185
|
+
|
|
186
|
+
- To create:
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
import { ssrHook } from '$evidence/ssrHook.svelte.js';
|
|
190
|
+
|
|
191
|
+
/** @type {import('@sveltejs/kit').Handle} */
|
|
192
|
+
export async function handle({ event, resolve }) {
|
|
193
|
+
/** @type {{ name: string, queryString: string}[]} */
|
|
194
|
+
const presentQueries = [];
|
|
195
|
+
const response = await resolve(event, {
|
|
196
|
+
transformPageChunk: ssrHook(presentQueries)
|
|
197
|
+
});
|
|
198
|
+
return response;
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
- If you already use `resolve` and `transformPageChunk`, you can chain the functions like so:
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
import { ssrHook } from '$evidence/ssrHook.svelte.js';
|
|
206
|
+
|
|
207
|
+
/** @type {import('@sveltejs/kit').Handle} */
|
|
208
|
+
export async function handle({ event, resolve }) {
|
|
209
|
+
/** @type {{ name: string, queryString: string}[]} */
|
|
210
|
+
const presentQueries = []
|
|
211
|
+
const evidenceChunkTransform = ssrHook(presentQueries)
|
|
212
|
+
|
|
213
|
+
const response = await resolve(event, {
|
|
214
|
+
transformPageChunk: ({html, done}) => {
|
|
215
|
+
// ... Do something to html
|
|
216
|
+
html = await evidenceChunkTransform({ html, done })
|
|
217
|
+
// ... Do other things to html
|
|
218
|
+
return html
|
|
219
|
+
});
|
|
220
|
+
return response;
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### Using `<QuerySSR/>`
|
|
225
|
+
|
|
226
|
+
`<QuerySSR/>` registers your queries with the Evidence Preprocessor, which enables correct rehydration of your queries.
|
|
227
|
+
|
|
228
|
+
```svelte
|
|
229
|
+
<script>
|
|
230
|
+
import { runQuery } from '$evidence/queries';
|
|
231
|
+
import QuerySSR from '$evidence/QuerySSR.svelte';
|
|
232
|
+
|
|
233
|
+
let manualQuery = runQuery('x', `SELECT * FROM users`);
|
|
234
|
+
$: manualQuery = runQuery('x', `SELECT * FROM users`);
|
|
235
|
+
</script>
|
|
236
|
+
|
|
237
|
+
<QuerySSR queries={[manualQuery]} />
|
|
238
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,164 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolean/evidence-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "4.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"bin": {
|
|
6
|
+
"evidence-sdk": "./src/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"default": null,
|
|
11
|
+
"import": null,
|
|
12
|
+
"node": null,
|
|
13
|
+
"require": null,
|
|
14
|
+
"types": "./src/types.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./usql": {
|
|
17
|
+
"default": "./src/usql/index.js",
|
|
18
|
+
"import": "./src/usql/index.js",
|
|
19
|
+
"require": null,
|
|
20
|
+
"types": "./src/usql/index.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./utils": {
|
|
23
|
+
"default": "./src/utils/index.js",
|
|
24
|
+
"import": "./src/utils/index.js",
|
|
25
|
+
"require": null,
|
|
26
|
+
"types": "./src/utils/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./utils/svelte": {
|
|
29
|
+
"default": "./src/utils/svelte/index.js",
|
|
30
|
+
"import": "./src/utils/svelte/index.js",
|
|
31
|
+
"require": null,
|
|
32
|
+
"types": "./src/utils/svelte/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./build/svelte": {
|
|
35
|
+
"default": "./src/build-dev/svelte/index.js",
|
|
36
|
+
"import": "./src/build-dev/svelte/index.js",
|
|
37
|
+
"require": null,
|
|
38
|
+
"types": "./src/build-dev/svelte/index.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./build/vite": {
|
|
41
|
+
"default": "./src/build-dev/vite/plugins.js",
|
|
42
|
+
"import": "./src/build-dev/vite/plugins.js",
|
|
43
|
+
"types": "./types/build-dev/vite/plugins.js",
|
|
44
|
+
"require": null
|
|
45
|
+
},
|
|
46
|
+
"./legacy-compat": {
|
|
47
|
+
"default": "./src/legacy-compat.js",
|
|
48
|
+
"import": "./src/legacy-compat.js",
|
|
49
|
+
"require": null,
|
|
50
|
+
"types": "./src/legacy-compat.d.ts"
|
|
51
|
+
},
|
|
52
|
+
"./meta": {
|
|
53
|
+
"default": "./src/meta.js",
|
|
54
|
+
"import": "./src/meta.js",
|
|
55
|
+
"require": null,
|
|
56
|
+
"types": "./src/meta.js"
|
|
57
|
+
},
|
|
58
|
+
"./query-builder": {
|
|
59
|
+
"default": "./src/query-builder.js",
|
|
60
|
+
"import": "./src/query-builder.js",
|
|
61
|
+
"require": null,
|
|
62
|
+
"types": "./src/query-builder.js"
|
|
63
|
+
},
|
|
64
|
+
"./config": {
|
|
65
|
+
"default": "./src/configuration/index.js",
|
|
66
|
+
"import": "./src/configuration/index.js",
|
|
67
|
+
"require": null,
|
|
68
|
+
"types": "./src/configuration/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./logger": {
|
|
71
|
+
"default": "./src/logger/index.js",
|
|
72
|
+
"import": "./src/logger/index.js",
|
|
73
|
+
"require": null,
|
|
74
|
+
"types": "./src/logger/index.js"
|
|
75
|
+
},
|
|
76
|
+
"./plugins": {
|
|
77
|
+
"default": "./src/plugins/index.js",
|
|
78
|
+
"import": "./src/plugins/index.js",
|
|
79
|
+
"require": null,
|
|
80
|
+
"types": "./src/plugins/index.js"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"keywords": [],
|
|
84
|
+
"author": "",
|
|
85
|
+
"license": "MIT",
|
|
86
|
+
"type": "module",
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"@brianmd/citty": "^0.0.1",
|
|
89
|
+
"@clack/prompts": "^0.7.0",
|
|
90
|
+
"@evidence-dev/icons": "npm:@yolean/evidence-icons@^1.0.3",
|
|
91
|
+
"@evidence-dev/telemetry": "npm:@yolean/evidence-telemetry@^2.1.4",
|
|
92
|
+
"@evidence-dev/universal-sql": "npm:@yolean/evidence-universal-sql@3.0.2",
|
|
93
|
+
"@steeze-ui/simple-icons": "^1.7.1",
|
|
94
|
+
"@steeze-ui/tabler-icons": "^2.1.1",
|
|
95
|
+
"@types/estree": "^1.0.5",
|
|
96
|
+
"@types/express": "^4.17.21",
|
|
97
|
+
"@types/jsdom": "^21.1.6",
|
|
98
|
+
"@types/lodash.chunk": "^4.2.7",
|
|
99
|
+
"@types/lodash.merge": "^4.6.9",
|
|
100
|
+
"@types/node": "^20.11.0",
|
|
101
|
+
"@typescript-eslint/typescript-estree": "^6.18.1",
|
|
102
|
+
"@uwdata/mosaic-sql": "^0.10.0",
|
|
103
|
+
"@vitest/coverage-v8": "3.0.5",
|
|
104
|
+
"chalk": "^5.3.0",
|
|
105
|
+
"chokidar": "^3.5.3",
|
|
106
|
+
"deep-object-diff": "^1.1.9",
|
|
107
|
+
"eslint": "^8.56.0",
|
|
108
|
+
"eslint-config-prettier": "^9.1.0",
|
|
109
|
+
"eslint-plugin-svelte": "^2.35.1",
|
|
110
|
+
"estree-walker": "^3.0.3",
|
|
111
|
+
"express": "^4.18.2",
|
|
112
|
+
"highlight.js": "^11.9.0",
|
|
113
|
+
"jsdom": "^23.2.0",
|
|
114
|
+
"lodash.chunk": "^4.2.0",
|
|
115
|
+
"lodash.merge": "^4.6.2",
|
|
116
|
+
"mdsvex": "^0.12.8",
|
|
117
|
+
"nanoid": "3.3.8",
|
|
118
|
+
"ora": "^8.0.1",
|
|
119
|
+
"perfect-debounce": "^1.0.0",
|
|
120
|
+
"pkg-types": "^1.0.3",
|
|
121
|
+
"prettier": "^3.1.1",
|
|
122
|
+
"prettier-plugin-svelte": "^3.1.2",
|
|
123
|
+
"recast": "^0.23.4",
|
|
124
|
+
"svelte-sequential-preprocessor": "^2.0.1",
|
|
125
|
+
"sveltekit-autoimport": "^1.7.1",
|
|
126
|
+
"vite": "8.3.8",
|
|
127
|
+
"vitest": "^2.1.9",
|
|
128
|
+
"yaml": "^2.3.4",
|
|
129
|
+
"zod": "^3.23.7"
|
|
130
|
+
},
|
|
131
|
+
"devDependencies": {
|
|
132
|
+
"@changesets/cli": "^2.27.1",
|
|
133
|
+
"@types/estree": "^1.0.5",
|
|
134
|
+
"@types/express": "^4.17.21",
|
|
135
|
+
"@types/jsdom": "^21.1.6",
|
|
136
|
+
"@types/lodash.merge": "^4.6.9",
|
|
137
|
+
"@types/node": "^20.11.0",
|
|
138
|
+
"@typescript-eslint/typescript-estree": "^6.18.1",
|
|
139
|
+
"memfs": "^4.6.0",
|
|
140
|
+
"svelte": "5.57.3",
|
|
141
|
+
"typescript": "^5.3.3"
|
|
142
|
+
},
|
|
143
|
+
"peerDependencies": {
|
|
144
|
+
"@evidence-dev/universal-sql": "npm:@yolean/evidence-universal-sql@*",
|
|
145
|
+
"nanoid": "3.3.8",
|
|
146
|
+
"perfect-debounce": "^1.0.0",
|
|
147
|
+
"svelte": "^5.46.4"
|
|
148
|
+
},
|
|
149
|
+
"peerDependenciesMeta": {
|
|
150
|
+
"svelte": {
|
|
151
|
+
"optional": true
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"scripts": {
|
|
155
|
+
"test": "vitest",
|
|
156
|
+
"check:types": "tsc -p tsconfig.json --noEmit",
|
|
157
|
+
"check": "tsc -p tsconfig.json --noEmit && eslint src",
|
|
158
|
+
"build:types": "npm run check && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
159
|
+
"build": "npm run check && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
160
|
+
"format": "prettier src -w",
|
|
161
|
+
"lint": "eslint src --fix",
|
|
162
|
+
"cli": "node ./src/cli.js"
|
|
163
|
+
}
|
|
6
164
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { findFile } from 'pkg-types';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import { log } from '@clack/prompts';
|
|
4
|
+
|
|
5
|
+
const defaultContent = `
|
|
6
|
+
import { ssrHook } from '$evidence/ssrHook.svelte.js';
|
|
7
|
+
|
|
8
|
+
/** @type {import('@sveltejs/kit').Handle} */
|
|
9
|
+
export async function handle({ event, resolve }) {
|
|
10
|
+
/** @type {{ name: string, queryString: string}[]} */
|
|
11
|
+
const presentQueries = []
|
|
12
|
+
const response = await resolve(event, {
|
|
13
|
+
transformPageChunk: ssrHook(presentQueries)
|
|
14
|
+
});
|
|
15
|
+
return response;
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export const addServerHook = async () => {
|
|
20
|
+
const hooks = await findFile('./src/hooks.server.js')
|
|
21
|
+
.catch(() => findFile('./src/hooks.server.ts'))
|
|
22
|
+
.catch(() => false);
|
|
23
|
+
if (hooks) {
|
|
24
|
+
log.warn(
|
|
25
|
+
'Server hooks file already exists. Please see the wiki for information on configuring SSR. https://github.com/evidence-dev/sdk/wiki/Configuring-SSR'
|
|
26
|
+
);
|
|
27
|
+
} else {
|
|
28
|
+
await fs.writeFile('./src/hooks.server.js', defaultContent);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { findFile } from 'pkg-types';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import { log } from '@clack/prompts';
|
|
4
|
+
|
|
5
|
+
export const addTypeRef = async () => {
|
|
6
|
+
const appDTs = await findFile('src/app.d.ts').catch(() => {
|
|
7
|
+
log.warn('Could not find app.d.ts file; types will not be installed');
|
|
8
|
+
return;
|
|
9
|
+
});
|
|
10
|
+
if (!appDTs) return;
|
|
11
|
+
|
|
12
|
+
const appDTsContent = await fs.readFile(appDTs, 'utf-8');
|
|
13
|
+
const lines = appDTsContent.split('\n');
|
|
14
|
+
const refLine = `/// <reference types="@evidence-dev/sdk" />`;
|
|
15
|
+
if (!lines.includes(refLine)) {
|
|
16
|
+
lines.splice(0, 0, refLine); // Insert at beginning of file
|
|
17
|
+
await fs.writeFile(appDTs, lines.join('\n'));
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { findFile } from 'pkg-types';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export const updateGitIgnore = async () => {
|
|
6
|
+
const gitIgnorePath = await findFile('.gitignore').catch(() =>
|
|
7
|
+
path.join(process.cwd(), '.gitignore')
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
const gitIgnoreContent = await fs.readFile(gitIgnorePath, 'utf-8').catch(() => '');
|
|
11
|
+
const gitIgnoreLines = gitIgnoreContent.split('\n');
|
|
12
|
+
const initialLines = gitIgnoreLines.length;
|
|
13
|
+
|
|
14
|
+
const evidenceIgnorePatterns = [
|
|
15
|
+
'.evidence', // internal directory
|
|
16
|
+
'connection.options.yaml' // can contain credentials
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
for (const pattern of evidenceIgnorePatterns) {
|
|
20
|
+
// This matches case sensitive and exact matches intentionally
|
|
21
|
+
|
|
22
|
+
if (!gitIgnoreLines.some((line) => line.trim() === pattern.trim()))
|
|
23
|
+
gitIgnoreLines.push(
|
|
24
|
+
`# Automatically ignored by Evidence, this should not be source controlled`,
|
|
25
|
+
`${pattern}`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (gitIgnoreLines.length > initialLines) {
|
|
30
|
+
// added lines, rewrite file
|
|
31
|
+
await fs.writeFile(gitIgnorePath, gitIgnoreLines.join('\n'));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { resolvePackageJSON, readPackageJSON, writePackageJSON } from 'pkg-types';
|
|
2
|
+
import { EvidenceError } from '../../../lib/EvidenceError.js';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
|
|
5
|
+
export const updatePackageJson = async () => {
|
|
6
|
+
const packageJson = await readPackageJSON().catch(() => {
|
|
7
|
+
throw new EvidenceError(
|
|
8
|
+
'Could not find an package.json file',
|
|
9
|
+
'Are you running this in a valid javascript package?'
|
|
10
|
+
);
|
|
11
|
+
});
|
|
12
|
+
if (!packageJson.dependencies) packageJson.dependencies = {};
|
|
13
|
+
|
|
14
|
+
// Install needed dependencies
|
|
15
|
+
// TODO: How do we determine variables? (Can we literally steal from the SDK's package.json?)
|
|
16
|
+
if (
|
|
17
|
+
'@evidence-dev/sdk' in packageJson.dependencies ||
|
|
18
|
+
'@evidence-dev/sdk' in (packageJson.devDependencies ?? {})
|
|
19
|
+
) {
|
|
20
|
+
console.debug(chalk.dim('Did not update @evidence-dev/sdk dependency, it already exists!'));
|
|
21
|
+
} else {
|
|
22
|
+
packageJson.dependencies['@evidence-dev/sdk'] = 'preview';
|
|
23
|
+
}
|
|
24
|
+
const packagePath = await resolvePackageJSON();
|
|
25
|
+
await writePackageJSON(packagePath, packageJson);
|
|
26
|
+
};
|