Skip to content

Commit

Permalink
Merge pull request #527 from riccardoperra/next
Browse files Browse the repository at this point in the history
Merge next in main
  • Loading branch information
riccardoperra authored May 20, 2023
2 parents 47e571c + dd5f668 commit a8a9ee5
Show file tree
Hide file tree
Showing 169 changed files with 4,808 additions and 2,073 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-panthers-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@codeimage/api': minor
---

Add ESM, TypeScript 5.0, Vitest and nodenext support
5 changes: 5 additions & 0 deletions .changeset/six-pumas-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codeimage/app": minor
---

feat: custom background image
5 changes: 5 additions & 0 deletions .changeset/sixty-rabbits-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@codeimage/ui': patch
---

fix: segmented field different size auto-fit
6 changes: 6 additions & 0 deletions .changeset/witty-nails-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@codeimage/app": minor
"@codeimage/dom-export": patch
---

feat: customizable export options
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ jobs:
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}} #Required
alias-domains: | #Optional
codeimage-app-pr-{{PR_NUMBER}}.vercel.app
next.codeimage.dev
build-highlight-dev:
name: '@codeimage/highlight dev and Preview'
Expand Down Expand Up @@ -377,7 +378,7 @@ jobs:

build-api:
name: Build Api
needs: [ install, typecheck-packages, build-packages ]
needs: [ install, build-packages ]
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -507,15 +508,16 @@ jobs:
pnpm --filter=@codeimage/api exec prisma migrate deploy
env:
DATABASE_URL: ${{ secrets.NEXT_DATABASE_URL }}
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}

- name: Deploy
run: |
find -type f -name '.gitignore' -delete
pnpm railway link --environment next $RAILWAY_API_PROJECT_ID
cd dist/api-bundle
pnpm railway up --detach
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
RAILWAY_API_PROJECT_ID: ${{ secrets.RAILWAY_API_PROJECT_ID }}

concurrency:
group: main-${{ github.head_ref }}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/api-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export type {
GetPresetByIdApi,
UpdatePresetApi,
GetAllPresetApi,
} from '../dist/schemas';
} from '../dist/schemas/index.js';
38 changes: 22 additions & 16 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.2.0",
"description": "CodeImage api rest server",
"main": "app.ts",
"type": "module",
"directories": {
"test": "test"
},
Expand All @@ -12,22 +13,24 @@
}
},
"scripts": {
"test": "dotenv -e .env.test -- tap --ts --reporter=terse './test/**/*.test.ts' --before=test/before-test.ts",
"test:coverage": "dotenv -e .env.test -- tap --ts --reporter=terse --coverage-report=html './test/**/*.test.ts' --before=test/before-test.ts --save=tests.txt",
"test:ci": "dotenv -e .env.test -- tap --no-check-coverage --ts './test/**/*.test.ts' --before=test/before-test.ts",
"test": "vitest",
"test:coverage": "vitest --coverage",
"test:ci": "vitest run",
"test:ui": "vitest --ui",
"start": "npm run build:ts && fastify start -l info dist/app.js",
"start:railway": "fastify start -l info dist/app.js",
"typecheck": "tsc --noEmit --skipLibCheck --project tsconfig.json",
"typecheck:ci": "tsc --skipLibCheck --project tsconfig.dts.json",
"dev": "NODE_OPTIONS='--enable-source-maps' && tsup --watch --onSuccess \"fastify start --port 3000 --options -d -l info -P dist/app.js\"",
"build:ts": "tsc",
"build:types": "tsc -p tsconfig.schema.json",
"watch:ts": "tsc -w",
"prisma:migrate:dev": "prisma migrate dev",
"prisma:migrate:test": "dotenv -e .env.test -- pnpm exec prisma migrate dev",
"prisma:migrate:deploy": "prisma migrate deploy",
"prisma:migrate:deploy-test": "dotenv -e .env.test -- pnpm exec prisma migrate deploy",
"prisma:generate": "prisma generate dev && pnpm --filter=@codeimage/prisma-models build",
"docker:dev": "docker compose -f docker-compose.dev.yml up",
"dev": "concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"blue.bold,cyan.bold\" \"npm:dev:start\"",
"dev:start": "tsx watch node_modules/fastify-cli/cli.js start --ignore-watch=.ts$ -w -l info -P src/app.ts"
},
"keywords": [],
Expand All @@ -36,34 +39,37 @@
"dependencies": {
"@codeimage/prisma-models": "workspace:*",
"@fastify/autoload": "^5.7.1",
"@fastify/cors": "^8.2.0",
"@fastify/cors": "^8.2.1",
"@fastify/env": "^4.2.0",
"@fastify/jwt": "^6.6.0",
"@fastify/jwt": "^6.7.1",
"@fastify/sensible": "^5.2.0",
"@fastify/swagger": "^8.3.1",
"@fastify/type-provider-typebox": "^2.4.0",
"@prisma/client": "^4.11.0",
"@sinclair/typebox": "^0.25.24",
"@fastify/swagger-ui": "^1.8.1",
"@fastify/type-provider-typebox": "^3.2.0",
"@prisma/client": "^4.13.0",
"@sinclair/typebox": "^0.28.9",
"close-with-grace": "^1.1.0",
"dotenv": "^16.0.3",
"dotenv-cli": "^6.0.0",
"fastify": "^4.14.0",
"fastify-auth0-verify": "^1.0.0",
"fastify": "^4.17.0",
"fastify-auth0-verify": "^1.1.1",
"fastify-cli": "^5.7.1",
"fastify-healthcheck": "^4.4.0",
"fastify-plugin": "^4.5.0",
"fluent-json-schema": "^4.1.0",
"prisma": "^4.11.0"
"prisma": "^4.13.0"
},
"devDependencies": {
"@types/node": "^18.14.6",
"@types/sinon": "^10.0.13",
"@types/tap": "^15.0.8",
"@vitest/ui": "^0.31.0",
"concurrently": "^7.6.0",
"fastify-tsconfig": "^1.0.1",
"sinon": "^15.0.1",
"tap": "^16.3.4",
"typescript": "^4.9.5",
"vitest": "0.26.2"
"tsup": "6.7.0",
"tsx": "3.12.7",
"typescript": "^5.0.4",
"vitest": "^0.31.0",
"vite": "^4.3.5"
}
}
11 changes: 9 additions & 2 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import AutoLoad, {AutoloadPluginOptions} from '@fastify/autoload';
import fastifyEnv from '@fastify/env';
import {Type} from '@sinclair/typebox';
import {FastifyPluginAsync} from 'fastify';
import {join} from 'path';
import path, {join} from 'node:path';
import {fileURLToPath} from 'node:url';

declare module 'fastify' {
interface FastifyInstance {
Expand All @@ -23,6 +24,9 @@ declare module 'fastify' {
}
}

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export type AppOptions = {
authProvider: FastifyPluginAsync;
// Place your custom options for app below here.
Expand Down Expand Up @@ -56,6 +60,7 @@ const app: FastifyPluginAsync<AppOptions> = async (
await fastify.register(AutoLoad, {
dir: join(__dirname, 'plugins'),
options: opts,
forceESM: true,
});

// This loads all plugins defined in routes
Expand All @@ -64,16 +69,18 @@ const app: FastifyPluginAsync<AppOptions> = async (
dir: join(__dirname, 'routes'),
options: {prefix: '/api/'},
routeParams: true,
forceESM: true,
});

await fastify.register(AutoLoad, {
dir: join(__dirname, 'modules'),
options: opts,
encapsulate: false,
maxDepth: 1,
forceESM: true,
});

fastify.ready(() => fastify.log.info(`\n${fastify.printRoutes()}`));
fastify.ready(() => fastify.log.info(fastify.printRoutes()));
};

export default app;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/common/domainFunctions/builder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {Handler, HandlerCallbackMetadata, Wrap} from '@api/domain';
import {$HANDLER} from './handlers';
import {$HANDLER} from './handlers.js';

type HandlerBuilderData = {
dependencies: any;
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/common/domainFunctions/handlers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {DomainHandlerMap, ResolvedDomainHandlerMap} from '@api/domain';
import {expect, test, vi} from 'vitest';
import {$HANDLER, createModuleHandlers, registerHandlers} from './handlers';
import {HandlerRegistry} from './registry';
import {$HANDLER, createModuleHandlers, registerHandlers} from './handlers.js';
import {HandlerRegistry} from './registry.js';

test('create handler', () => {
type Deps = {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/common/domainFunctions/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
MergeHandlerDependencies,
Wrap,
} from '@api/domain';
import {HandlerBuilder} from './builder';
import {HandlerRegistry} from './registry';
import {HandlerBuilder} from './builder.js';
import {HandlerRegistry} from './registry.js';

export const $HANDLER: unique symbol = Symbol('handler-metadata');

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/common/domainFunctions/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
GenericHandler,
ResolvedDomainHandlerMap,
} from '@api/domain';
import {getHandlerMetadata} from './handlers';
import {getHandlerMetadata} from './handlers.js';

export class HandlerRegistry<T extends object = DomainHandlerMap> {
#events = new Map<string, GenericHandler>();
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/common/exceptions/NotFoundEntityException.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {HandlerError} from './HandlerError';
import {HandlerError} from './HandlerError.js';

export abstract class NotFoundEntityException<
Args extends Record<string, string | number> | void = void,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {HandlerError} from './HandlerError';
import {HandlerError} from './HandlerError.js';

export abstract class UnprocessableEntityException<
Args extends Record<string, string | number> | void = void,
Expand Down
9 changes: 0 additions & 9 deletions apps/api/src/common/schemas/baserResponse.ts

This file was deleted.

14 changes: 12 additions & 2 deletions apps/api/src/common/typebox/nullable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import {SchemaOptions, TSchema, Type} from '@sinclair/typebox';

export const Nullable = <T extends TSchema>(type: T, options?: SchemaOptions) =>
Type.Union([type, Type.Null()], options);
export const Nullable = <T extends TSchema>(tType: T, optional = true) => {
const options: SchemaOptions | undefined = Reflect.has(tType, 'default')
? {default: tType.default}
: undefined;

const resolvedType = Type.Union([tType, Type.Null()], options);

if (optional) {
return Type.Optional(resolvedType);
}
return resolvedType;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {UnprocessableEntityException} from '../../../common/exceptions/UnprocessableEntityException';
import {UnprocessableEntityException} from '../../../common/exceptions/UnprocessableEntityException.js';

export class ExceedPresetLimitException extends UnprocessableEntityException<{
limit: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NotFoundEntityException} from '../../../common/exceptions/NotFoundEntityException';
import {NotFoundEntityException} from '../../../common/exceptions/NotFoundEntityException.js';

type Params = {
id: string;
Expand Down
10 changes: 5 additions & 5 deletions apps/api/src/modules/preset/handlers/create.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {HandlerBuilder} from '../../../common/domainFunctions/builder';
import {ExceedPresetLimitException} from '../exceptions/ExceedPresetLimitException';
import {PresetCreateDto} from '../schema/preset-create-dto.schema';
import {PresetDto} from '../schema/preset-dto.schema';
import {PresetHandlerDependencies} from './';
import {HandlerBuilder} from '../../../common/domainFunctions/builder.js';
import {ExceedPresetLimitException} from '../exceptions/ExceedPresetLimitException.js';
import {PresetCreateDto} from '../schema/preset-create-dto.schema.js';
import {PresetDto} from '../schema/preset-dto.schema.js';
import type {PresetHandlerDependencies} from './index.js';

export const create =
HandlerBuilder.withDependencies<PresetHandlerDependencies>()
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/modules/preset/handlers/delete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {HandlerBuilder} from '../../../common/domainFunctions/builder';
import {PresetHandlerDependencies} from './';
import {HandlerBuilder} from '../../../common/domainFunctions/builder.js';
import {PresetHandlerDependencies} from './index.js';

export const remove =
HandlerBuilder.withDependencies<PresetHandlerDependencies>()
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/modules/preset/handlers/findAll.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {HandlerBuilder} from '../../../common/domainFunctions/builder';
import {PresetDto} from '../schema/preset-dto.schema';
import {PresetHandlerDependencies} from './';
import {HandlerBuilder} from '../../../common/domainFunctions/builder.js';
import {PresetDto} from '../schema/preset-dto.schema.js';
import {PresetHandlerDependencies} from './index.js';

export const findAll =
HandlerBuilder.withDependencies<PresetHandlerDependencies>()
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/modules/preset/handlers/findById.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {HandlerBuilder} from '../../../common/domainFunctions/builder';
import {NotFoundPresetException} from '../exceptions/NotFoundPresetException';
import {PresetDto} from '../schema/preset-dto.schema';
import {PresetHandlerDependencies} from './';
import {HandlerBuilder} from '../../../common/domainFunctions/builder.js';
import {NotFoundPresetException} from '../exceptions/NotFoundPresetException.js';
import {PresetDto} from '../schema/preset-dto.schema.js';
import {PresetHandlerDependencies} from './index.js';

export const findById =
HandlerBuilder.withDependencies<PresetHandlerDependencies>()
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/modules/preset/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {FastifyInstance} from 'fastify';
import {PresetMapper} from '../mapper';
import {PresetRepository} from '../repository';
import {PresetMapper} from '../mapper/index.js';
import type {PresetRepository} from '../repository/index.js';

export type PresetHandlerDependencies = {
repository: PresetRepository;
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/modules/preset/handlers/update.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {HandlerBuilder} from '../../../common/domainFunctions/builder';
import {PresetDto} from '../schema/preset-dto.schema';
import {PresetUpdateDto} from '../schema/preset-update-dto.schema';
import {PresetHandlerDependencies} from './';
import {HandlerBuilder} from '../../../common/domainFunctions/builder.js';
import {PresetDto} from '../schema/preset-dto.schema.js';
import {PresetUpdateDto} from '../schema/preset-update-dto.schema.js';
import {PresetHandlerDependencies} from './index.js';

export const update =
HandlerBuilder.withDependencies<PresetHandlerDependencies>()
Expand Down
18 changes: 9 additions & 9 deletions apps/api/src/modules/preset/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {ComposeHandlers} from '@api/domain';
import {FastifyPluginAsync} from 'fastify';
import {registerHandlers} from '../../common/domainFunctions/handlers';
import {create} from './handlers/create';
import {remove} from './handlers/delete';
import {findAll} from './handlers/findAll';
import {findById} from './handlers/findById';
import {update} from './handlers/update';
import {PresetMapper} from './mapper';
import {PresetRepository} from './repository';
import {PrismaPresetRepository} from './repository/prisma-preset.repository';
import {registerHandlers} from '../../common/domainFunctions/handlers.js';
import {create} from './handlers/create.js';
import {remove} from './handlers/delete.js';
import {findAll} from './handlers/findAll.js';
import {findById} from './handlers/findById.js';
import {update} from './handlers/update.js';
import {PresetMapper} from './mapper/index.js';
import {PresetRepository} from './repository/index.js';
import {PrismaPresetRepository} from './repository/prisma-preset.repository.js';

const handlers = [create, remove, findById, update, findAll] as const;

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/preset/mapper/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Preset} from '@codeimage/prisma-models';
import {PresetDataDto, PresetDto} from '../schema/preset-dto.schema';
import {PresetDataDto, PresetDto} from '../schema/preset-dto.schema.js';

export interface PresetMapper {
fromEntityToDto(entity: Preset): PresetDto;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/preset/repository/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './preset.repository';
export * from './preset.repository.js';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Preset} from '@codeimage/prisma-models';
import {PresetCreateRequest, PresetUpdateRequest} from '../domain';
import {PresetCreateRequest, PresetUpdateRequest} from '../domain/index.js';

export interface PresetRepository {
findByIdAndOwnerId(id: string, ownerId: string): Promise<Preset | null>;
Expand Down
Loading

0 comments on commit a8a9ee5

Please sign in to comment.