forked from GomaGoma676/restapi-todo-nestjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Add Link Resolver Module with CRUD functionality and DTOs #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wolfwithcode
wants to merge
11
commits into
staging
Choose a base branch
from
feat/interface-to-s3
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3ce6f2d
Add Link Resolver Module with CRUD functionality and DTOs
wolfwithcode c893dd6
feat: Refactor code style and formatting across multiple files in the…
wolfwithcode 5d4a025
chore: Update comment in link-resolver.repository.ts to clarify purpo…
wolfwithcode 45e1297
feat: Integrate MinIO storage for link resolver with new repository a…
wolfwithcode 2a41046
fix: Update MinIO service configuration with hardcoded endpoint and d…
wolfwithcode da16d1d
feat: Implement GS1 identity resolver module with initialization, CRU…
wolfwithcode ba34577
feat: Add data integrity mechanisms for GS1 identity resolver, includ…
wolfwithcode ed34a58
feat: Implement ETag-based concurrency control for GS1 Identity Resol…
wolfwithcode 953ee86
feat: Add Swagger documentation for NestJS API and integrate ETag-bas…
wolfwithcode 4396f10
chore: Downgrade @nestjs/swagger to version 6.3.0 and update swagger-…
wolfwithcode a164dd2
chore: Update CLI commands and scripts to remove redundant flags, sta…
wolfwithcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
version: '3.7' | ||
|
||
services: | ||
minio: | ||
image: minio/minio | ||
ports: | ||
- "9000:9000" | ||
- "9001:9001" | ||
environment: | ||
MINIO_ROOT_USER: minioadmin | ||
MINIO_ROOT_PASSWORD: minioadmin | ||
volumes: | ||
- minio-data:/data | ||
command: server --console-address ":9001" /data | ||
|
||
volumes: | ||
minio-data: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
# Start MinIO in the background | ||
echo "Starting MinIO..." | ||
docker-compose -f docker-compose.minio.yml up -d | ||
|
||
# Wait for MinIO to start | ||
echo "Waiting for MinIO to start..." | ||
sleep 5 | ||
|
||
# Save the sample data | ||
echo "Saving sample data to MinIO..." | ||
yarn save-sample | ||
|
||
echo "Done!" | ||
echo "The MinIO console is available at http://localhost:9001 (login with minioadmin/minioadmin)" | ||
echo "The link resolver data is saved to the 'link-resolvers' bucket" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CommandFactory } from 'nest-commander'; | ||
import { LinkResolverCommandsModule } from './link-resolver/commands/commands.module'; | ||
import { StorageModule } from './storage/storage.module'; | ||
|
||
async function bootstrap() { | ||
await CommandFactory.run(LinkResolverCommandsModule, { | ||
logger: ['error', 'warn'], | ||
}); | ||
} | ||
|
||
bootstrap(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Common Barrel File | ||
* | ||
* This file exports all common elements from the common directory, | ||
* making them easier to import elsewhere in the application. | ||
*/ | ||
|
||
export * from './interfaces'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Interfaces Barrel File | ||
* | ||
* This file exports all interfaces from the interfaces directory, | ||
* making them easier to import elsewhere in the application. | ||
*/ | ||
|
||
export * from './repository.interface'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Repository Provider Interface | ||
* | ||
* This file defines a TypeScript interface for a repository provider, | ||
* which is a common pattern in software architecture for abstracting data access operations. | ||
*/ | ||
|
||
/** | ||
* Defines the structure for data being saved | ||
* Requires an id property as a string | ||
* Allows any additional properties | ||
*/ | ||
export type SaveParams = { | ||
id: string; | ||
[k: string]: any; | ||
}; | ||
|
||
/** | ||
* Repository Provider Interface | ||
* | ||
* Defines four standard CRUD operations: | ||
* - save: Stores data with the given parameters | ||
* - one: Retrieves a single item by ID | ||
* - all: Retrieves all items of a specific category | ||
* - delete: Removes an item by ID | ||
*/ | ||
export interface IRepositoryProvider { | ||
/** | ||
* Stores data with the given parameters | ||
* @param data The data to be saved | ||
* @returns A promise resolving to void | ||
*/ | ||
save(data: SaveParams): Promise<void>; | ||
|
||
/** | ||
* Retrieves a single item by ID | ||
* @param id The unique identifier of the item | ||
* @returns A promise resolving to the requested item or null if not found | ||
*/ | ||
one<T>(id: string): Promise<T | null>; | ||
|
||
/** | ||
* Retrieves all items of a specific category | ||
* @param filter Optional filtering criteria | ||
* @returns A promise resolving to an array of items | ||
*/ | ||
all<T>(filter?: object): Promise<T[]>; | ||
|
||
/** | ||
* Removes an item by ID | ||
* @param id The unique identifier of the item to delete | ||
* @returns A promise resolving to void | ||
*/ | ||
delete(id: string): Promise<void>; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SaveSampleDataCommand } from './save-sample-data.command'; | ||
import { LinkResolverModule } from '../link-resolver.module'; | ||
|
||
@Module({ | ||
imports: [LinkResolverModule], | ||
providers: [SaveSampleDataCommand], | ||
exports: [SaveSampleDataCommand], | ||
}) | ||
export class LinkResolverCommandsModule {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Command, CommandRunner } from 'nest-commander'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { LinkResolverService } from '../link-resolver.service'; | ||
|
||
@Injectable() | ||
@Command({ | ||
name: 'save-sample', | ||
description: 'Save sample link resolver data to MinIO', | ||
}) | ||
export class SaveSampleDataCommand extends CommandRunner { | ||
constructor(private readonly linkResolverService: LinkResolverService) { | ||
super(); | ||
} | ||
|
||
async run(): Promise<void> { | ||
console.log('Saving sample link resolver data to MinIO...'); | ||
|
||
const sampleData = { | ||
id: 'gs1/01/12345678901234/10/123456789012345678902.json', | ||
createdAt: '2024-09-02T06:19:58.783Z', | ||
linkset: { | ||
anchor: | ||
'http://localhost:3000/gs1/01/12345678901234/10/123456789012345678902', | ||
'http://localhost:3000/voc/certificationInfo': [ | ||
{ | ||
href: 'https://example.com', | ||
title: 'Certification Information', | ||
type: 'application/json', | ||
hreflang: ['en'], | ||
'title*': [{ value: 'Certification Information', language: 'en' }], | ||
}, | ||
], | ||
}, | ||
linkHeaderText: | ||
'<https://example.com>; rel="gs1:certificationInfo"; type="application/json"; hreflang="en"; title="Certification Information", <http://localhost:3000/gs1/01/12345678901234/10/123456789012345678902>; rel="owl:sameAs"', | ||
namespace: 'gs1', | ||
identificationKeyType: 'gtin', | ||
identificationKey: '12345678901234', | ||
itemDescription: 'Product description', | ||
qualifierPath: '/10/123456789012345678902', | ||
active: true, | ||
responses: [ | ||
{ | ||
defaultLinkType: true, | ||
defaultMimeType: true, | ||
fwqs: false, | ||
active: true, | ||
linkType: 'gs1:certificationInfo', | ||
title: 'Certification Information', | ||
targetUrl: 'https://example.com', | ||
mimeType: 'application/json', | ||
ianaLanguage: 'en', | ||
context: 'au', | ||
defaultContext: true, | ||
defaultIanaLanguage: true, | ||
}, | ||
], | ||
}; | ||
|
||
try { | ||
await this.linkResolverService.create(sampleData); | ||
console.log('Sample data saved successfully!'); | ||
console.log(`ID: ${sampleData.id}`); | ||
} catch (error: unknown) { | ||
const errorMessage = error instanceof Error ? error.message : String(error); | ||
console.error('Failed to save sample data:', errorMessage); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
IsString, | ||
IsBoolean, | ||
IsOptional, | ||
IsArray, | ||
IsObject, | ||
ValidateNested, | ||
} from 'class-validator'; | ||
import { Type } from 'class-transformer'; | ||
import { Linkset, Response } from '../entities/link-resolver.entity'; | ||
|
||
/** | ||
* Data Transfer Object for creating a Link Resolver entry | ||
*/ | ||
export class CreateLinkResolverDto { | ||
@IsString() | ||
namespace: string; | ||
|
||
@IsString() | ||
identificationKeyType: string; | ||
|
||
@IsString() | ||
identificationKey: string; | ||
|
||
@IsString() | ||
@IsOptional() | ||
itemDescription?: string; | ||
|
||
@IsString() | ||
@IsOptional() | ||
qualifierPath?: string; | ||
|
||
@IsBoolean() | ||
active: boolean; | ||
|
||
@IsObject() | ||
@ValidateNested() | ||
@Type(() => Object) // We can't directly validate Linkset due to dynamic keys | ||
linkset: Linkset; | ||
|
||
@IsArray() | ||
@ValidateNested({ each: true }) | ||
@Type(() => ResponseDto) | ||
responses: Response[]; | ||
} | ||
|
||
export class ResponseDto implements Response { | ||
@IsBoolean() | ||
defaultLinkType: boolean; | ||
|
||
@IsBoolean() | ||
defaultMimeType: boolean; | ||
|
||
@IsBoolean() | ||
fwqs: boolean; | ||
|
||
@IsBoolean() | ||
active: boolean; | ||
|
||
@IsString() | ||
linkType: string; | ||
|
||
@IsString() | ||
title: string; | ||
|
||
@IsString() | ||
targetUrl: string; | ||
|
||
@IsString() | ||
mimeType: string; | ||
|
||
@IsString() | ||
ianaLanguage: string; | ||
|
||
@IsString() | ||
context: string; | ||
|
||
@IsBoolean() | ||
defaultContext: boolean; | ||
|
||
@IsBoolean() | ||
defaultIanaLanguage: boolean; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify compatibility with NestJS.
The
@nestjs/config
version has been updated to^4.0.2
. Verify that this version is compatible with the other NestJS packages still at version^9.0.0
.🌐 Web query:
💡 Result:
The compatibility between
@nestjs/[email protected]
and@nestjs/[email protected]
poses potential issues due to breaking changes introduced in@nestjs/config
versions beyond v3.x. Here's the analysis:Breaking Changes in
@nestjs/[email protected]
Version 4.0.0 introduced significant adjustments to environment variable handling:
process.env
) [3][7]ignoreEnvVars
option in favor ofskipProcessEnv
[3][7]These changes were designed for NestJS v11+ infrastructure.
Core Version Context
@nestjs/[email protected]
is part of the NestJS v9 ecosystem (released in 2023), while@nestjs/[email protected]
targets NestJS v11 (released January 2025) [6][8]. The major version mismatch suggests incompatibility.Version Compatibility Guidance
NestJS follows semantic versioning where major versions indicate breaking changes. The
@nestjs/config
package at v4.x requires:@nestjs/[email protected]
Recommendation
For
@nestjs/[email protected]
projects:@nestjs/[email protected]
(last v3 release was 3.2.0)@nestjs/[email protected]
featuresThe configuration module's v4.x release notes explicitly require NestJS v11+ core dependencies [3][7], making it incompatible with older core versions like 9.0.0.
Citations:
Action: Resolve incompatibility between @nestjs/config and NestJS core
The analysis confirms that using
@nestjs/[email protected]
with@nestjs/[email protected]
is incompatible. Version 4.x of@nestjs/config
introduces breaking changes (such as changes in environment variable handling and deprecation of certain options) and explicitly requires a minimum of@nestjs/[email protected]
. You’ll need to either:@nestjs/config
to version^3.x
(for example,3.2.0
) to maintain compatibility with NestJS v9or
@nestjs/[email protected]
.Please update the dependency in your
package.json
accordingly.