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

init sveltekit library #198

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This is a monorepo, for specific documentation, check out the different projects
* [`@axiomhq/js`](./packages/js): Official API bindings that let you ingest or query your data.
* [`@axiomhq/winston`](./packages/winston): A [winston](https://github.com/winstonjs/winston) transport which sends logs to Axiom.
* [`@axiomhq/pino`](./packages/pino): A [pino](https://github.com/pinojs/pino) transport which sends logs to Axiom.
* [`@axiomhq/sveltekit`](./packages/sveltekit): A [sveltekit](https://github.com/sveltejs/kit) library which sends logs to Axiom.


## Migrate to v1.x
Expand Down
13 changes: 13 additions & 0 deletions examples/svelte-app/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
31 changes: 31 additions & 0 deletions examples/svelte-app/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @type { import("eslint").Linter.Config } */
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
'prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
extraFileExtensions: ['.svelte']
},
env: {
browser: true,
es2017: true,
node: true
},
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
]
};
13 changes: 13 additions & 0 deletions examples/svelte-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
.vercel
.output
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/.turbo
1 change: 1 addition & 0 deletions examples/svelte-app/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
4 changes: 4 additions & 0 deletions examples/svelte-app/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
8 changes: 8 additions & 0 deletions examples/svelte-app/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
38 changes: 38 additions & 0 deletions examples/svelte-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# create-svelte

Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

```bash
# create a new project in the current directory
npm create svelte@latest

# create a new project in my-app
npm create svelte@latest my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```bash
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Building

To create a production version of your app:

```bash
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
38 changes: 38 additions & 0 deletions examples/svelte-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "svelte-app",
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"devDependencies": {
"@fontsource/fira-mono": "^4.5.10",
"@neoconfetti/svelte": "^1.0.0",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "^8.56.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^5.0.3"
},
"dependencies": {
"@axiomhq/js": "workspace:*",
"@axiomhq/sveltekit": "workspace:*"
},
"type": "module"
}
13 changes: 13 additions & 0 deletions examples/svelte-app/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
12 changes: 12 additions & 0 deletions examples/svelte-app/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="off">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
29 changes: 29 additions & 0 deletions examples/svelte-app/src/hooks.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { HandleClientError } from '@sveltejs/kit';

import { Logger } from '@axiomhq/sveltekit';

import { dev, browser, version } from '$app/environment'


const logger = new Logger({
args: { dev, browser, version }
});


export const handleError: HandleClientError = async ({ error, event, status, message }) => {

const url = new URL(event.url);

logger.error(`${message}`, {
exception: error, request: {
host: url.hostname,
path: url.pathname,
status: status
},
source: 'hooks',
});

await logger.flush()

return { message }
}
39 changes: 39 additions & 0 deletions examples/svelte-app/src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { Handle, HandleServerError } from '@sveltejs/kit';

import { resolveRuntime, withAxiom, Logger } from '@axiomhq/sveltekit';

import { AXIOM_TOKEN, AXIOM_DATASET, AXIOM_URL } from '$env/static/private';
import { dev, browser, version } from '$app/environment'


const logger = new Logger({
dataset: AXIOM_DATASET,
token: AXIOM_TOKEN,
url: AXIOM_URL,
runtime: resolveRuntime(),
args: { dev, browser, version }
});


export const handle: Handle = withAxiom(logger, async ({ event, resolve }) => {
return resolve(event);
})


export const handleError: HandleServerError = async ({ error, event, status, message }) => {

const url = new URL(event.request.url);
logger.error(`${message}`, {
exception: error, request: {
host: url.hostname,
path: url.pathname,
method: event.request.method,
status: status
},
source: 'hooks',
});

await logger.flush()

return { message }
}
53 changes: 53 additions & 0 deletions examples/svelte-app/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<script>
import Header from './Header.svelte';
import './styles.css';
</script>

<div class="app">
<Header />

<main>
<slot />
</main>

<footer>
<p>visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to learn SvelteKit</p>
</footer>
</div>

<style>
.app {
display: flex;
flex-direction: column;
min-height: 100vh;
}

main {
flex: 1;
display: flex;
flex-direction: column;
padding: 1rem;
width: 100%;
max-width: 64rem;
margin: 0 auto;
box-sizing: border-box;
}

footer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 12px;
}

footer a {
font-weight: bold;
}

@media (min-width: 480px) {
footer {
padding: 12px 0;
}
}
</style>
54 changes: 54 additions & 0 deletions examples/svelte-app/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script>
import Counter from './Counter.svelte';
</script>

<svelte:head>
<title>Home</title>
<meta name="description" content="Svelte demo app" />
</svelte:head>

<section>
<h1>
<span class="welcome">

</span>

to your new<br />SvelteKit app
</h1>

<h2>
try editing <strong>src/routes/+page.svelte</strong>
</h2>

<Counter />
</section>

<style>
section {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex: 0.6;
}

h1 {
width: 100%;
}

.welcome {
display: block;
position: relative;
width: 100%;
height: 0;
padding: 0 0 calc(100% * 495 / 2048) 0;
}

.welcome img {
position: absolute;
width: 100%;
height: 100%;
top: 0;
display: block;
}
</style>
3 changes: 3 additions & 0 deletions examples/svelte-app/src/routes/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// since there's no dynamic data here, we can prerender
// it so that it gets served as a static asset in production
export const prerender = true;
Loading
Loading