Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ body:
validations:
required: true

projects: ['atls/11']
projects: ['atls/11']
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ body:
validations:
required: true

projects: ['atls/11']
projects: ['atls/11']
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ body:
validations:
required: true

projects: ['atls/11']
projects: ['atls/11']
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ body:
label: Материалы
placeholder: Ссылка на репу, статью

projects: ['atls/11']
projects: ['atls/11']
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ package.tgz
*.iml
.vscode

.data
.data
schema.gql
2,216 changes: 2,122 additions & 94 deletions .pnp.cjs

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ packageExtensions:
dependencies:
'@fastify/static': '*'
'@fastify/view': '*'
'@nestjs/graphql@*':
dependencies:
'ts-morph': '*'
'@apollo/subgraph': '*'
'@nestjs/apollo@*':
dependencies:
'@apollo/gateway': '*'
'@apollo/subgraph': '*'
'@as-integrations/fastify': '*'
'@mikro-orm/knex@*':
dependencies:
'mariadb': '*'
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ services:
- FILES_BUCKETS_PUBLIC_CONDITIONS_SIZE_MIN=1
- FILES_BUCKETS_PUBLIC_CONDITIONS_SIZE_MAX=5242880

files-gateway:
image: node:22
working_dir: /workspace
volumes:
- yarn:/.yarn/berry
- ./:/workspace
entrypoint: yarn workspace @files/gateway-entrypoint dev
environment:
- FILES_SERVICE_URL=http://files:50051
ports:
- 3000:3000

gcs:
image: fsouza/fake-gcs-server
command: -scheme http -external-url http://localhost:4443
Expand Down
50 changes: 50 additions & 0 deletions files/service/gateway-entrypoint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@files/gateway-entrypoint",
"version": "0.0.1",
"private": true,
"license": "BSD-3-Clause",
"type": "module",
"exports": {
".": "./src/index.ts"
},
"scripts": {
"build": "yarn service build",
"dev": "yarn service dev",
"prepack": "run build",
"postpack": "rm -rf dist",
"start": "yarn node dist/index.js"
},
"devDependencies": {
"@apollo/server": "4.12.0",
"@atls/nestjs-logger": "0.2.41",
"@atls/protobuf-rpc": "0.0.6",
"@bufbuild/protobuf": "1.10.0",
"@faker-js/faker": "9.6.0",
"@files-engine/gateway-module": "workspace:*",
"@nestjs/apollo": "12.2.2",
"@nestjs/common": "10.4.15",
"@nestjs/core": "10.4.15",
"@nestjs/cqrs": "10.2.8",
"@nestjs/graphql": "12.2.2",
"@nestjs/microservices": "10.4.15",
"@nestjs/platform-express": "10.4.15",
"@nestjs/platform-fastify": "10.4.15",
"@nestjs/testing": "10.4.15",
"@nestjs/websockets": "10.4.15",
"@testcontainers/kafka": "10.20.0",
"@types/amqplib": "0.10.6",
"@types/jsonwebtoken": "9.0.8",
"@types/node": "22.13.10",
"amqp-connection-manager": "4.1.14",
"amqplib": "0.10.5",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"get-port": "7.1.0",
"graphql": "16.10.0",
"jsonwebtoken": "9.0.2",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1",
"testcontainers": "10.20.0",
"uuid": "11.0.5"
}
}
29 changes: 29 additions & 0 deletions files/service/gateway-entrypoint/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { NestFastifyApplication } from '@nestjs/platform-fastify'

import { NestLogger } from '@atls/nestjs-logger'
import { NestFactory } from '@nestjs/core'
import { FastifyAdapter } from '@nestjs/platform-fastify'

import { LISTEN_PORT } from './files-engine-gateway-entrypoint.constants.js'
import { FilesEngineGatewayEntrypointModule } from './files-engine-gateway-entrypoint.module.js'

const bootstrap = async (): Promise<void> => {
const app = await NestFactory.create<NestFastifyApplication>(
FilesEngineGatewayEntrypointModule,
new FastifyAdapter(),
{ logger: new NestLogger() }
)

app.enableShutdownHooks()

await app.listen(LISTEN_PORT, '0.0.0.0')

if (import.meta.webpackHot) {
import.meta.webpackHot.accept()
import.meta.webpackHot.dispose(() => {
app.close()
})
}
}

bootstrap()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LISTEN_PORT = 3000
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ApolloDriverConfig } from '@nestjs/apollo'

import { join } from 'node:path'

import { ApolloDriver } from '@nestjs/apollo'
import { Module } from '@nestjs/common'
import { GraphQLModule } from '@nestjs/graphql'

import { FilesGatewayModule } from '@files-engine/gateway-module'

@Module({
imports: [
FilesGatewayModule.register(),
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
playground: true,
introspection: true,
autoSchemaFile:
process.env.NODE_ENV === 'production'
? join(process.cwd(), 'dist/schema.gql')
: join(process.cwd(), 'schema.gql'),
sortSchema: true,
}),
],
})
export class FilesEngineGatewayEntrypointModule {}
1 change: 1 addition & 0 deletions files/service/gateway-entrypoint/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './bootstrap.js'
35 changes: 35 additions & 0 deletions files/service/gateway-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@files-engine/gateway-module",
"version": "0.0.1",
"private": true,
"license": "BSD-3-Clause",
"type": "module",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
},
"main": "src/index.ts",
"dependencies": {
"@atls/files-rpc-client": "workspace:*",
"@atls/protobuf-rpc": "0.0.6",
"dataloader": "2.2.3"
},
"devDependencies": {
"@bufbuild/protobuf": "1.10.0",
"@nestjs/common": "10.4.15",
"@nestjs/core": "10.4.15",
"@nestjs/graphql": "12.2.2",
"graphql": "16.10.0",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1"
},
"peerDependencies": {
"@bufbuild/protobuf": "^1",
"@nestjs/common": "^10",
"@nestjs/core": "^10",
"@nestjs/graphql": "^12",
"graphql": "^16",
"reflect-metadata": "^0.2",
"rxjs": "^7"
}
}
34 changes: 34 additions & 0 deletions files/service/gateway-module/src/data-loaders/file.data-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { File } from '@atls/files-rpc-client'

import type { NestDataLoader } from '../interfaces/index.js'

import { Injectable } from '@nestjs/common'
import DataLoader from 'dataloader'

import { client } from '@atls/files-rpc-client'

@Injectable()
export class FileDataLoader implements NestDataLoader<string, File | undefined> {
async getFiles(ids: ReadonlyArray<string>): Promise<Array<File | undefined>> {
const { files } = await client.listFiles({
query: {
id: {
conditions: {
in: { values: ids as Array<string> },
},
},
},
})

const filesById: Map<string, File> = files.reduce(
(result, file) => result.set(file.id, file),
new Map<string, File>()
)

return ids.map((id) => filesById.get(id))
}

generateDataLoader(): DataLoader<string, File | undefined> {
return new DataLoader<string, File | undefined>(async (ids) => this.getFiles(ids))
}
}
1 change: 1 addition & 0 deletions files/service/gateway-module/src/data-loaders/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './file.data-loader.js'
1 change: 1 addition & 0 deletions files/service/gateway-module/src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './input-arg.decorator.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Args } from '@nestjs/graphql'

export const InputArg = <T>(inputType: T): ParameterDecorator =>
Args('input', { type: () => inputType })
10 changes: 10 additions & 0 deletions files/service/gateway-module/src/errors/confirm-upload.errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Field } from '@nestjs/graphql'
import { ObjectType } from '@nestjs/graphql'

import { ValidationErrorType } from '../types/index.js'

@ObjectType()
export class ConfirmUploadErrors {
@Field(() => ValidationErrorType, { nullable: true })
id?: ValidationErrorType
}
16 changes: 16 additions & 0 deletions files/service/gateway-module/src/errors/create-upload.errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Field } from '@nestjs/graphql'
import { ObjectType } from '@nestjs/graphql'

import { ValidationErrorType } from '../types/index.js'

@ObjectType()
export class CreateUploadErrors {
@Field(() => ValidationErrorType, { nullable: true })
bucket?: ValidationErrorType

@Field(() => ValidationErrorType, { nullable: true })
name?: ValidationErrorType

@Field(() => ValidationErrorType, { nullable: true })
size?: ValidationErrorType
}
2 changes: 2 additions & 0 deletions files/service/gateway-module/src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './confirm-upload.errors.js'
export * from './create-upload.errors.js'
6 changes: 6 additions & 0 deletions files/service/gateway-module/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './data-loaders/index.js'
export * from './inputs/index.js'
export * from './module/index.js'
export * from './mutations/index.js'
export * from './queries/index.js'
export * from './types/index.js'
12 changes: 12 additions & 0 deletions files/service/gateway-module/src/inputs/confirm-upload.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Field } from '@nestjs/graphql'
import { ID } from '@nestjs/graphql'
import { InputType } from '@nestjs/graphql'

@InputType()
export class ConfirmUploadInput {
@Field(() => ID)
id!: string

@Field()
ownerId!: string
}
17 changes: 17 additions & 0 deletions files/service/gateway-module/src/inputs/create-upload.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Field } from '@nestjs/graphql'
import { InputType } from '@nestjs/graphql'

@InputType()
export class CreateUploadInput {
@Field()
bucket!: string

@Field()
name!: string

@Field()
ownerId!: string

@Field()
size!: number
}
2 changes: 2 additions & 0 deletions files/service/gateway-module/src/inputs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './confirm-upload.input.js'
export * from './create-upload.input.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type DataLoader from 'dataloader'

export interface NestDataLoader<ID, Type> {
generateDataLoader: () => DataLoader<ID, Type>
}
1 change: 1 addition & 0 deletions files/service/gateway-module/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from './data-loader.interfaces.js'
24 changes: 24 additions & 0 deletions files/service/gateway-module/src/module/files-gateway.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { DynamicModule } from '@nestjs/common'

import { Module } from '@nestjs/common'

import * as dataLoaders from '../data-loaders/index.js'
import * as mutations from '../mutations/index.js'
import * as queries from '../queries/index.js'

@Module({})
export class FilesGatewayModule {
static register(): DynamicModule {
const providers = [
...Object.values(mutations),
...Object.values(queries),
...Object.values(dataLoaders),
]

return {
module: FilesGatewayModule,
providers,
exports: providers,
}
}
}
1 change: 1 addition & 0 deletions files/service/gateway-module/src/module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './files-gateway.module.js'
1 change: 1 addition & 0 deletions files/service/gateway-module/src/mutations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './upload.mutations.js'
Loading
Loading