diff --git a/src/@shared/src/database/index.ts b/src/@shared/src/database/index.ts index 64b3d75..6a36d02 100644 --- a/src/@shared/src/database/index.ts +++ b/src/@shared/src/database/index.ts @@ -6,7 +6,7 @@ // By: maiboyer +#+ +:+ +#+ // // +#+#+#+#+#+ +#+ // // Created: 2025/07/28 17:36:22 by maiboyer #+# #+# // -// Updated: 2025/07/30 21:19:05 by maiboyer ### ########.fr // +// Updated: 2025/08/03 13:36:25 by maiboyer ### ########.fr // // // // ************************************************************************** // @@ -66,20 +66,6 @@ export class Database { this.st.set(query, st); return st; } - - public createUser(user: string): Result { - const st = this.prepare('INSERT INTO users VALUES (?, ?) RETURNING id'); - - try { - st.get(newUUIDv7(), user) - } - catch (e: any) { - console.log(e) - console.log(typeof e) - } - return Result.ok(newUUIDv7()); - } - } // When using .decorate you have to specify added properties for Typescript @@ -96,8 +82,7 @@ export type DatabaseOption = { export const uDatabase = fp(async function( _fastify: FastifyInstance, _options: DatabaseOption) { - - + console.log("Database has been hooked up to fastify ?!"); }); export default uDatabase; diff --git a/src/Dockerfile b/src/Dockerfile index 848dbc9..f716305 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -1,29 +1,34 @@ -FROM node:24-alpine as builder +FROM guergeiro/pnpm:22-10-alpine as builder +RUN apk add jq; ARG SERVICE -RUN apk add jq python3 musl-dev gcc g++ make; - WORKDIR /build COPY ./@shared/package.json /build/@shared/package.json COPY ./${SERVICE}/package.json /build/service/package.json +COPY ./${SERVICE}/package.json /build/package.json COPY ./tsconfig.base.json /build/tsconfig.base.json +COPY ./pnpm-workspace.yaml /build/pnpm-workspace.yaml -RUN echo "{\"name\":\"workspace\", \"workspaces\": [\"@shared\", \"${SERVICE}\" ]}" | jq . >/build/package.json; -RUN npm install && npm install --prefix=/build/service; +RUN pnpm install; +RUN ls -a *; COPY ./@shared/ /build/@shared/ COPY ./${SERVICE}/ /build/service/ -RUN (cd /build/service && npm run build:prod) \ - && jq -s '.[0] * .[1]' /build/@shared/package.json /build/service/package.json >/dist/package.json; +RUN cd /build/service && \ + pnpm run build:prod && \ + jq -s '.[0] * .[1]' /build/*/package.json >/dist/package.json && \ + cp /build/pnpm-workspace.yaml /dist/pnpm-workspace.yaml && \ + true; -FROM node:24 + +FROM guergeiro/pnpm:22-10-slim WORKDIR /src COPY --from=builder /dist /src -RUN npm install; +RUN pnpm install --prod; CMD ["node", "/src/run.cjs"] diff --git a/src/icons/src/app.ts b/src/icons/src/app.ts index f385cde..ffb6ffa 100644 --- a/src/icons/src/app.ts +++ b/src/icons/src/app.ts @@ -3,8 +3,11 @@ import fastifyFormBody from '@fastify/formbody' import fastifyMultipart from '@fastify/multipart' import { mkdir } from 'node:fs/promises' import fp from 'fastify-plugin' +import * as db from '@shared/database' +// @ts-ignore: import.meta.glob is a vite thing. Typescript doesn't know this... const plugins = import.meta.glob('./plugins/**/*.ts', { eager: true }); +// @ts-ignore: import.meta.glob is a vite thing. Typescript doesn't know this... const routes = import.meta.glob('./routes/**/*.ts', { eager: true }); @@ -21,13 +24,13 @@ const app: FastifyPluginAsync = async ( ): Promise => { // Place here your custom code! for (const plugin of Object.values(plugins)) { - void fastify.register(plugin, {}); + void fastify.register(plugin as any, {}); } for (const route of Object.values(routes)) { - void fastify.register(route, {}); + void fastify.register(route as any, {}); } - //void fastify.register(MyPlugin, {}) + void fastify.register(db.uDatabase as any, {}) void fastify.register(fastifyFormBody, {}) void fastify.register(fastifyMultipart, {}) diff --git a/src/icons/src/routes/set.ts b/src/icons/src/routes/set.ts index 1d315a6..7c8d9f4 100644 --- a/src/icons/src/routes/set.ts +++ b/src/icons/src/routes/set.ts @@ -2,7 +2,6 @@ import { FastifyPluginAsync } from 'fastify' import { join } from 'node:path' import { open } from 'node:fs/promises' import sharp from 'sharp' -import { newUUIDv7 } from '@shared/uuid' import rawBody from 'raw-body' const route: FastifyPluginAsync = async (fastify, opts): Promise => { @@ -12,7 +11,7 @@ const route: FastifyPluginAsync = async (fastify, opts): Promise => { // we register a route handler for: `/` // it sets some configuration options, and set the actual function that will handle the request - fastify.addContentTypeParser('*', function(request, payload, done) { + fastify.addContentTypeParser('*', function(request, payload, done: any) { done() }); diff --git a/src/icons/vite.config.js b/src/icons/vite.config.js index 2b9d86b..89a197c 100644 --- a/src/icons/vite.config.js +++ b/src/icons/vite.config.js @@ -2,12 +2,32 @@ import { defineConfig } from 'vite' import tsconfigPaths from 'vite-tsconfig-paths' import nodeExternals from 'rollup-plugin-node-externals' import path from 'node:path' +import fs from 'node:fs' + +function collectDeps(...pkgJsonPaths) { + const allDeps = new Set(); + for (const pkgPath of pkgJsonPaths) { + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); + for (const dep of Object.keys(pkg.dependencies || {})) { + allDeps.add(dep); + } + for (const peer of Object.keys(pkg.peerDependencies || {})) { + allDeps.add(peer); + } + } + return Array.from(allDeps); +} + +const externals = collectDeps( + './package.json', + '../@shared/package.json' +); + export default defineConfig({ root: __dirname, // service root plugins: [tsconfigPaths(), nodeExternals()], build: { - ssr: true, outDir: 'dist', emptyOutDir: true, @@ -17,9 +37,9 @@ export default defineConfig({ fileName: () => 'index.js', }, rollupOptions: { - external: [], + external: externals, }, - target: 'node24', // or whatever Node version you use + target: 'node22', // or whatever Node version you use sourcemap: true, minify: false, // for easier debugging } diff --git a/src/pnpm-workspace.yaml b/src/pnpm-workspace.yaml new file mode 100644 index 0000000..14297f8 --- /dev/null +++ b/src/pnpm-workspace.yaml @@ -0,0 +1,4 @@ +pacakges: + - ./* + +nodeLinker: hoisted diff --git a/src/tsconfig.base.json b/src/tsconfig.base.json index 93ec82a..c2a6aeb 100644 --- a/src/tsconfig.base.json +++ b/src/tsconfig.base.json @@ -2,7 +2,7 @@ "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { "target": "ES2023", - "module": "NodeNext", + "module": "esnext", "moduleResolution": "node", "newLine": "lf",