Skip to content

Commit

Permalink
chore: update packages, including trpc-svelte-query
Browse files Browse the repository at this point in the history
  • Loading branch information
ottomated committed May 19, 2023
1 parent aeaddf0 commit 7fe2185
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 98 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"rust-analyzer.linkedProjects": [
"Cargo.toml",
"template_builder/Cargo.toml",
"dependency_upgrader/Cargo.toml"
]
}
28 changes: 14 additions & 14 deletions template_builder/templates/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
"lint": "eslint --max-warnings 0 --fix . && svelte-check"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"@sveltejs/adapter-auto": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-svelte": "^2.15.0",
"prettier": "^2.8.3",
"prettier-plugin-svelte": "^2.9.0",
"svelte-check": "^3.0.3",
"svelte-preprocess": "^5.0.1",
"typescript": "~4.9.5",
"vite": "^4.0.4"
"eslint-plugin-svelte": "^2.28.0",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.0",
"svelte-check": "^3.3.2",
"svelte-preprocess": "^5.0.3",
"typescript": "~5.0.4",
"vite": "^4.3.8"
},
"dependencies": {
"@sveltejs/kit": "^1.8.6",
"svelte": "^3.55.1"
"@sveltejs/kit": "^1.18.0",
"svelte": "^3.59.1"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RequestEvent } from '@sveltejs/kit';
import type { inferAsyncReturnType } from '@trpc/server';
import type { FetchCreateContextFnOptions } from '@trpc/server/adapters/fetch';

export async function createContext(_opts: FetchCreateContextFnOptions) {
export async function createContext(_opts: RequestEvent) {
return {};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createTRPCSvelteServer } from 'trpc-svelte-query/server';
import { appRouter } from './routes/_app';
import { createContext } from './context';

export const trpcServer = createTRPCSvelteServer({
endpoint: '/api/trpc',
router: appRouter,
createContext,
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { transformer } from '$lib/trpc/transformer';

const t = initTRPC.context<Context>().create({
transformer,
// errorFormatter: (shape) => ({ ...shape }),
});

export const router = t.router;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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)({
httpBatchLink({
url: '/api/trpc',
}),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { parse, stringify } from 'devalue';
import { parse, stringify, uneval } 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})`),
// },
input: {
serialize: (object: unknown) => stringify(object),
deserialize: (object: string) => parse(object),
},
output: {
serialize: (object: unknown) => uneval(object),
deserialize: (object: string) => (0, eval)(`(${object})`),
},
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
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';
import { trpcServer } from '$lib/server/server';

const handler: RequestHandler = async (event) => {
return fetchRequestHandler({
endpoint: '/api/trpc',
req: event.request,
router: appRouter,
createContext,
});
};

export const GET = handler;
export const POST = handler;
export const GET = trpcServer.handler;
export const POST = trpcServer.handler;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export let data: LayoutData;
const queryClient = trpc.hydrateQueryClient(data.trpc);
const queryClient = trpc.hydrateFromServer(data.trpc);
</script>

<QueryClientProvider client={queryClient}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { trpc } from '$lib/trpc';
import { trpcServer } from '$lib/server/server';
import type { LayoutServerLoad } from './$types';

export const load: LayoutServerLoad = async (event) => {
return {
trpc: trpc.ssr(event),
trpc: trpcServer.hydrateToClient(event),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export let data: LayoutData;
const queryClient = trpc.hydrateQueryClient(data.trpc);
const queryClient = trpc.hydrateFromServer(data.trpc);
</script>

<QueryClientProvider client={queryClient}>
Expand Down
11 changes: 5 additions & 6 deletions template_builder/templates/extras/{Database}package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
"build": "vite build"
},
"dependencies": {
"better-sqlite3": "^8.1.0",
"kysely": "^0.23.4",
"kysely-codegen": "^0.9.0",
"better-sqlite3": "^8.3.0",
"kysely": "^0.24.2",
"dotenv": "^16.0.3"
},
"devDependencies": {
"@types/better-sqlite3": "^7.6.3",
"kysely-codegen": "^0.9.0",
"prisma": "^4.9.0"
"@types/better-sqlite3": "^7.6.4",
"kysely-codegen": "^0.10.0",
"prisma": "^4.14.1"
}
}
4 changes: 2 additions & 2 deletions template_builder/templates/extras/{Edge,Database}package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"postinstall": "node ./prisma/generate.cjs"
},
"dependencies": {
"@planetscale/database": "^1.5.0",
"@planetscale/database": "^1.7.0",
"better-sqlite3": null,
"kysely-planetscale": "^1.2.1"
"kysely-planetscale": "^1.3.0"
},
"devDependencies": {
"@types/better-sqlite3": null,
Expand Down
4 changes: 2 additions & 2 deletions template_builder/templates/extras/{Edge}package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"devDependencies": {
"@cloudflare/workers-types": "^4.20230115.0",
"@sveltejs/adapter-cloudflare": "^2.0.1",
"@cloudflare/workers-types": "^4.20230511.0",
"@sveltejs/adapter-cloudflare": "^2.2.4",
"@sveltejs/adapter-auto": null
}
}
8 changes: 4 additions & 4 deletions template_builder/templates/extras/{Tailwind}package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"devDependencies": {
"autoprefixer": "^10.4.13",
"postcss": "^8.4.21",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.23",
"postcss-load-config": "^4.0.1",
"prettier-plugin-tailwindcss": "^0.2.2",
"tailwindcss": "^3.2.4"
"prettier-plugin-tailwindcss": "^0.3.0",
"tailwindcss": "^3.3.2"
}
}
12 changes: 6 additions & 6 deletions template_builder/templates/extras/{Trpc}package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"dependencies": {
"@tanstack/svelte-query": "^4.24.4",
"@trpc/client": "^10.9.1",
"@trpc/server": "^10.9.1",
"devalue": "^4.2.3",
"trpc-svelte-query": "^0.0.2",
"zod": "^3.20.2"
"@tanstack/svelte-query": "^4.29.7",
"@trpc/client": "^10.27.0",
"@trpc/server": "^10.27.0",
"devalue": "^4.3.1",
"trpc-svelte-query": "1.0.0",
"zod": "^3.21.4"
}
}
59 changes: 59 additions & 0 deletions update_deps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { resolve, basename } from 'node:path';
import { fileURLToPath } from 'node:url';
import { readdir, readFile } from 'node:fs/promises';

const root = resolve(fileURLToPath(import.meta.url), '../template_builder/templates');

const dependencies = new Map();

for await (const f of getFiles(root)) {
if (!/^(\{[^{}]*\})?package\.json$/.test(basename(f))) continue;
const pkg = JSON.parse(await readFile(f, 'utf8'));
const entries = [
...Object.entries(pkg.dependencies || {}),
...Object.entries(pkg.devDependencies || {})
];
for (const [name, version] of entries) {
if (version === null) continue;
dependencies.set(name, [version, basename(f)]);
}
}

const neededUpgrades = new Map();

for (const [name, [version, file]] of dependencies) {
const latest = await latestVersion(name);
if (!latest) continue;
if (latest !== version.replace(/^[\^~]/, '')) {
if (!neededUpgrades.has(file)) neededUpgrades.set(file, []);
neededUpgrades.get(file).push([name, version, latest]);
}
}

for (const [file, upgrades] of neededUpgrades) {
console.log('\n' + file);
for (const [name, version, latest] of upgrades) {
console.log(` ${name}: ${version} -> ${latest}`);
}
}

async function latestVersion(packageName) {
const url = new URL(encodeURIComponent(packageName).replace(/^%40/, '@'), 'https://registry.npmjs.org/');
const res = await fetch(url, {
headers: { accept: 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*' }
});
const data = await res.json();
return data?.['dist-tags']?.latest;
}

async function* getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true });
for (const dirent of dirents) {
const res = resolve(dir, dirent.name);
if (dirent.isDirectory()) {
yield* getFiles(res);
} else {
yield res;
}
}
}

0 comments on commit 7fe2185

Please sign in to comment.