first commit

This commit is contained in:
vel 2023-03-22 12:45:19 -07:00
commit de285d7316
Signed by: velvox
GPG Key ID: 59D9762F674151DF
31 changed files with 3190 additions and 0 deletions

60
app/.eslintrc.cjs Normal file
View File

@ -0,0 +1,60 @@
module.exports = {
root: true,
env: {
browser: true,
es2017: true,
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
extraFileExtension: ['.svelte'],
},
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:svelte/recommended',
],
plugins: ['@typescript-eslint'],
overrides: [
{
files: ['*.cjs'],
env: {
node: true,
},
},
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
},
rules: {
'no-self-assign': 'off',
},
},
{
files: ['*.ts'],
extends: ['plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
rules: {
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
},
],
},
},
],
settings: {
'svelte3/typescript': () => require('typescript'),
},
rules: {
'prettier/prettier': 'warn',
},
};

203
app/.gitignore vendored Normal file
View File

@ -0,0 +1,203 @@
# Created by https://www.toptal.com/developers/gitignore/api/macos,svelte,node,yarn,dotenv
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,svelte,node,yarn,dotenv
### dotenv ###
.env
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### macOS Patch ###
# iCloud generated files
*.icloud
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
### Node Patch ###
# Serverless Webpack directories
.webpack/
# Optional stylelint cache
# SvelteKit build / generate output
.svelte-kit
### Svelte ###
# gitignore template for the SvelteKit, frontend web component framework
# website: https://kit.svelte.dev/
.svelte-kit/
package
### yarn ###
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.yarn/*
!.yarn/releases
!.yarn/patches
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
# if you are NOT using Zero-installs, then:
# comment the following lines
!.yarn/cache
# and uncomment the following lines
# .pnp.*
# End of https://www.toptal.com/developers/gitignore/api/macos,svelte,node,yarn,dotenv

1
app/.prettierignore Normal file
View File

@ -0,0 +1 @@
src/lib/db/schema.d.ts

20
app/.prettierrc Normal file
View File

@ -0,0 +1,20 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"useTabs": true,
"plugins": [
"prettier-plugin-svelte"
],
"pluginSearchDirs": [
"."
],
"overrides": [
{
"files": "*.svelte",
"options": {
"parser": "svelte"
}
}
]
}

52
app/package.json Normal file
View File

@ -0,0 +1,52 @@
{
"name": "app",
"version": "0.0.0",
"type": "module",
"scripts": {
"build": "vite build",
"preview": "vite preview",
"lint": "eslint --max-warnings 0 --fix . && svelte-check",
"postinstall": "node ./prisma/generate.cjs",
"dev": "vite dev",
"db:push": "prisma db push && node ./prisma/generate.cjs"
},
"dependencies": {
"trpc-svelte-query": "^0.0.2",
"@sveltejs/kit": "^1.8.6",
"kysely-codegen": "^0.9.0",
"dotenv": "^16.0.3",
"devalue": "^4.2.3",
"@tanstack/svelte-query": "^4.24.4",
"svelte": "^3.55.1",
"@trpc/server": "^10.9.1",
"@planetscale/database": "^1.5.0",
"kysely-planetscale": "^1.2.1",
"kysely": "^0.23.4",
"@trpc/client": "^10.9.1",
"zod": "^3.20.2"
},
"devDependencies": {
"postcss": "^8.4.21",
"prettier-plugin-tailwindcss": "^0.2.2",
"@sveltejs/adapter-cloudflare": "^2.0.1",
"@cloudflare/workers-types": "^4.20230115.0",
"mysql2": "2.3.3",
"vite": "^4.0.4",
"prisma": "^4.9.0",
"kysely-codegen": "^0.9.0",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"typescript": "~4.9.5",
"tailwindcss": "^3.2.4",
"svelte-check": "^3.0.3",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"autoprefixer": "^10.4.13",
"postcss-load-config": "^4.0.1",
"eslint-plugin-svelte": "^2.15.0",
"svelte-preprocess": "^5.0.1",
"prettier-plugin-svelte": "^2.9.0",
"eslint-plugin-prettier": "^4.2.1",
"@typescript-eslint/parser": "^5.50.0",
"prettier": "^2.8.3"
}
}

2547
app/pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

9
app/postcss.config.mjs Normal file
View File

@ -0,0 +1,9 @@
import autoprefixer from 'autoprefixer';
import tailwind from 'tailwindcss';
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: [tailwind, autoprefixer],
};
export default config;

46
app/prisma/generate.cjs Normal file
View File

@ -0,0 +1,46 @@
const { Logger, DialectManager, Generator } = require('kysely-codegen');
const { join } = require('node:path');
require('dotenv').config();
async function generate() {
const { DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_HOST, DATABASE_NAME } =
process.env;
if (
!DATABASE_USERNAME ||
!DATABASE_PASSWORD ||
!DATABASE_HOST ||
!DATABASE_NAME
) {
console.warn(
'DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_HOST and DATABASE_NAME must be set'
);
return;
}
const logger = new Logger(2);
const databaseUrl = `mysql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?ssl={"rejectUnauthorized":true}`;
const dialectManager = new DialectManager();
const dialect = dialectManager.getDialect('mysql');
const db = await dialect.introspector.connect({
connectionString: databaseUrl,
dialect,
});
const generator = new Generator();
await generator.generate({
camelCase: true,
db,
dialect,
logger,
outFile: join(__dirname, '../src/lib/db/schema.d.ts'),
});
await db.destroy();
}
generate();

10
app/prisma/schema.prisma Normal file
View File

@ -0,0 +1,10 @@
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
model Example {
id Int @id @default(autoincrement())
name String
}

3
app/src/app.css Normal file
View File

@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

16
app/src/app.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
/// <reference types="@sveltejs/kit" />
/// <reference types="@cloudflare/workers-types" />
declare namespace App {
interface Platform {
env: {
// KV: KVNamespace;
};
context: ExecutionContext;
}
// interface Locals {}
// interface Error {}
// interface Session {}
// interface Stuff {}
}

16
app/src/app.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="Create o7 App" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body>
%sveltekit.body%
</body>
</html>

25
app/src/lib/db/index.ts Normal file
View File

@ -0,0 +1,25 @@
import { Kysely, type RawBuilder, sql } from 'kysely';
import { PlanetScaleDialect, inflateDates } from 'kysely-planetscale';
import type { DB } from './schema';
import {
DATABASE_HOST,
DATABASE_USERNAME,
DATABASE_PASSWORD,
} from '$env/static/private';
export const db = new Kysely<DB>({
dialect: new PlanetScaleDialect({
host: DATABASE_HOST,
username: DATABASE_USERNAME,
password: DATABASE_PASSWORD,
cast: (field, value) => {
if (field.type === 'INT8' && value === '1') return true;
if (field.type === 'INT8' && value === '0') return false;
return inflateDates(field, value);
},
}),
});
export function json<T>(obj: T): RawBuilder<T> {
return sql`${JSON.stringify(obj)}`;
}

14
app/src/lib/db/schema.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
import type { ColumnType } from "kysely";
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;
export interface Example {
id: Generated<number>;
name: string;
}
export interface DB {
Example: Example;
}

View File

@ -0,0 +1,15 @@
import type { inferAsyncReturnType } from '@trpc/server';
import type { FetchCreateContextFnOptions } from '@trpc/server/adapters/fetch';
import type { RequestEvent } from '@sveltejs/kit';
export function createContext(event: RequestEvent) {
return (_opts: FetchCreateContextFnOptions) => {
return {
env: event.platform?.env,
context: event.platform?.context,
};
};
}
export type Context = inferAsyncReturnType<
inferAsyncReturnType<typeof createContext>
>;

View File

@ -0,0 +1,16 @@
import { router, publicProcedure } from '../trpc';
import { z } from 'zod';
export const appRouter = router({
greeting: publicProcedure
.input(
z.object({
name: z.string().optional(),
})
)
.query(({ input }) => {
return `Hello, ${input.name ?? 'world'}!`;
}),
});
export type AppRouter = typeof appRouter;

View File

@ -0,0 +1,12 @@
import { initTRPC } from '@trpc/server';
import type { Context } from './context';
import { transformer } from '$lib/trpc/transformer';
const t = initTRPC.context<Context>().create({
transformer,
// errorFormatter: (shape) => ({ ...shape }),
});
export const router = t.router;
export const publicProcedure = t.procedure;

14
app/src/lib/trpc/index.ts Normal file
View File

@ -0,0 +1,14 @@
import { createTRPCSvelte } from 'trpc-svelte-query';
import { ssrLink } from 'trpc-svelte-query/ssr';
import { httpBatchLink } from '@trpc/client';
import type { AppRouter } from '$lib/server/routes/_app';
import { transformer } from './transformer';
export const trpc = createTRPCSvelte<AppRouter>({
links: [
ssrLink(httpBatchLink)({
url: '/api/trpc',
}),
],
transformer,
});

View File

@ -0,0 +1,12 @@
import { parse, stringify } from 'devalue';
export const transformer = {
// input: {
serialize: (object: unknown) => stringify(object),
deserialize: (object: string) => parse(object),
// },
// output: {
// serialize: (object: unknown) => uneval(object),
// deserialize: (object: string) => (0, eval)(`(${object})`),
// },
};

View File

@ -0,0 +1,8 @@
import { trpc } from '$lib/trpc';
import type { LayoutServerLoad } from './$types';
export const load: LayoutServerLoad = async (event) => {
return {
trpc: trpc.ssr(event),
};
};

View File

@ -0,0 +1,14 @@
<script lang="ts">
import '../app.css';
import { QueryClientProvider } from '@tanstack/svelte-query';
import type { LayoutData } from './$types';
import { trpc } from '$lib/trpc';
export let data: LayoutData;
const queryClient = trpc.hydrateQueryClient(data.trpc);
</script>
<QueryClientProvider client={queryClient}>
<slot />
</QueryClientProvider>

View File

@ -0,0 +1 @@
<h1>You are using the o7 stack</h1>

View File

@ -0,0 +1,16 @@
import { appRouter } from '$lib/server/routes/_app';
import { createContext } from '$lib/server/context';
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import type { RequestHandler } from './$types';
const handler: RequestHandler = async (event) => {
return fetchRequestHandler({
endpoint: '/api/trpc',
req: event.request,
router: appRouter,
createContext: createContext(event),
});
};
export const GET = handler;
export const POST = handler;

BIN
app/static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

16
app/svelte.config.js Normal file
View File

@ -0,0 +1,16 @@
import adapter from '@sveltejs/adapter-cloudflare';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [
preprocess({
postcss: true,
}),
],
kit: {
adapter: adapter(),
},
};
export default config;

8
app/tailwind.config.cjs Normal file
View File

@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{html,js,svelte,ts}'],
theme: {
extend: {},
},
plugins: [],
};

16
app/tsconfig.json Normal file
View File

@ -0,0 +1,16 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"alwaysStrict": true,
"allowSyntheticDefaultImports": true,
"noUncheckedIndexedAccess": true,
}
}

8
app/vite.config.mjs Normal file
View File

@ -0,0 +1,8 @@
import { sveltekit } from '@sveltejs/kit/vite';
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()],
};
export default config;

1
rust/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

8
rust/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

3
rust/src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}