-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): removed experimental decorators (#259)
- Loading branch information
1 parent
48be7c9
commit 88af5a7
Showing
19 changed files
with
200 additions
and
140 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
20 changes: 15 additions & 5 deletions
20
packages/server-nodejs/src/configuration/GatewayConfiguration.ts
This file contains 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 |
---|---|---|
@@ -1,12 +1,22 @@ | ||
|
||
import { IsOptional, IsNumber, IsUrl } from 'class-validator'; | ||
import { z } from 'zod'; | ||
|
||
export const gatewaySchema = z | ||
.object({ | ||
monitor: z.number().optional(), | ||
repository: z.string().url().optional() | ||
}) | ||
.strict() | ||
.transform((value) => new GatewayConfiguration(value.monitor, value.repository)); | ||
|
||
export default class GatewayConfiguration | ||
{ | ||
@IsNumber() | ||
@IsOptional() | ||
monitor?: number; | ||
repository?: string; | ||
|
||
@IsUrl() | ||
repository = ''; | ||
constructor(monitor?: number, repository?: string) | ||
{ | ||
this.monitor = monitor; | ||
this.repository = repository; | ||
} | ||
} |
26 changes: 18 additions & 8 deletions
26
packages/server-nodejs/src/configuration/NodeConfiguration.ts
This file contains 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 |
---|---|---|
@@ -1,15 +1,25 @@ | ||
|
||
import { IsArray, IsUrl, IsOptional } from 'class-validator'; | ||
import { z } from 'zod'; | ||
|
||
export const nodeSchema = z | ||
.object({ | ||
gateway: z.string().url().optional(), | ||
repository: z.string().url().optional(), | ||
segments: z.array(z.string()).nonempty() | ||
}) | ||
.strict() | ||
.transform((value) => new NodeConfiguration(value.gateway, value.repository, value.segments)); | ||
|
||
export default class NodeConfiguration | ||
{ | ||
@IsUrl() | ||
@IsOptional() | ||
gateway?: string; | ||
repository?: string; | ||
segments: string[]; | ||
|
||
@IsUrl() | ||
repository = ''; | ||
|
||
@IsArray() | ||
segments?: string[]; | ||
constructor(gateway: string | undefined, repository: string | undefined, segments: string[]) | ||
{ | ||
this.gateway = gateway; | ||
this.repository = repository; | ||
this.segments = segments; | ||
} | ||
} |
46 changes: 38 additions & 8 deletions
46
packages/server-nodejs/src/configuration/ProxyConfiguration.ts
This file contains 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 |
---|---|---|
@@ -1,16 +1,46 @@ | ||
|
||
import { IsUrl, IsOptional } from 'class-validator'; | ||
import { z } from 'zod'; | ||
|
||
export const proxySchema = z | ||
.object({ | ||
node: z.string().url().optional(), | ||
gateway: z.string().url().optional(), | ||
repository: z.string().url() | ||
}) | ||
.strict() | ||
.superRefine((value, ctx) => | ||
{ | ||
if (value.node === undefined && value.gateway === undefined) | ||
{ | ||
ctx.addIssue({ | ||
code: z.ZodIssueCode.custom, | ||
message: 'Either node or gateway must be defined', | ||
path: ['node', 'gateway'] | ||
}); | ||
} | ||
|
||
if (value.node !== undefined && value.gateway !== undefined) | ||
{ | ||
ctx.addIssue({ | ||
code: z.ZodIssueCode.custom, | ||
message: 'Only node or gateway must be defined', | ||
path: ['node', 'gateway'], | ||
|
||
}); | ||
} | ||
}) | ||
.transform((value) => new ProxyConfiguration(value.node, value.gateway, value.repository)); | ||
|
||
export default class ProxyConfiguration | ||
{ | ||
@IsUrl() | ||
@IsOptional() | ||
node?: string; | ||
|
||
@IsUrl() | ||
@IsOptional() | ||
gateway?: string; | ||
repository: string; | ||
|
||
@IsUrl() | ||
repository?: string; | ||
constructor(node: string | undefined, gateway: string | undefined, repository: string) | ||
{ | ||
this.node = node; | ||
this.gateway = gateway; | ||
this.repository = repository; | ||
} | ||
} |
31 changes: 19 additions & 12 deletions
31
packages/server-nodejs/src/configuration/RepositoryConfiguration.ts
This file contains 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 |
---|---|---|
@@ -1,21 +1,28 @@ | ||
|
||
import { IsArray, IsOptional, IsString } from 'class-validator'; | ||
import { z } from 'zod'; | ||
|
||
export const repositorySchema = z | ||
.object({ | ||
source: z.string().optional(), | ||
cache: z.string().optional(), | ||
index: z.string().optional(), | ||
assets: z.array(z.string()).optional() | ||
}) | ||
.strict() | ||
.transform((value) => new RepositoryConfiguration(value.source, value.cache, value.index, value.assets)); | ||
|
||
export default class RepositoryConfiguration | ||
{ | ||
@IsString() | ||
@IsOptional() | ||
source?: string; | ||
|
||
@IsString() | ||
@IsOptional() | ||
cache?: string; | ||
|
||
@IsString() | ||
@IsOptional() | ||
index?: string; | ||
|
||
@IsArray() | ||
@IsOptional() | ||
assets?: string[]; | ||
|
||
constructor(source?: string, cache?: string, index?: string, assets?: string[]) | ||
{ | ||
this.source = source; | ||
this.cache = cache; | ||
this.index = index; | ||
this.assets = assets; | ||
} | ||
} |
48 changes: 29 additions & 19 deletions
48
packages/server-nodejs/src/configuration/RuntimeConfiguration.ts
This file contains 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 |
---|---|---|
@@ -1,30 +1,40 @@ | ||
|
||
import { IsOptional, IsUrl } from 'class-validator'; | ||
|
||
import GatewayConfiguration from './GatewayConfiguration.js'; | ||
import NodeConfiguration from './NodeConfiguration.js'; | ||
import ProxyConfiguration from './ProxyConfiguration.js'; | ||
import RepositoryConfiguration from './RepositoryConfiguration.js'; | ||
import StandaloneConfiguration from './StandaloneConfiguration.js'; | ||
import { z } from 'zod'; | ||
|
||
import GatewayConfiguration, { gatewaySchema } from './GatewayConfiguration.js'; | ||
import NodeConfiguration, { nodeSchema } from './NodeConfiguration.js'; | ||
import ProxyConfiguration, { proxySchema } from './ProxyConfiguration.js'; | ||
import RepositoryConfiguration, { repositorySchema } from './RepositoryConfiguration.js'; | ||
import StandaloneConfiguration, { standaloneSchema } from './StandaloneConfiguration.js'; | ||
|
||
export const runtimeSchema = z | ||
.object({ | ||
url: z.string().optional(), | ||
standalone: standaloneSchema.optional(), | ||
repository: repositorySchema.optional(), | ||
gateway: gatewaySchema.optional(), | ||
node: nodeSchema.optional(), | ||
proxy: proxySchema.optional(), | ||
}) | ||
.strict() | ||
.transform((value) => new RuntimeConfiguration(value.url, value.standalone, value.repository, value.gateway, value.node, value.proxy)); | ||
|
||
export default class RuntimeConfiguration | ||
{ | ||
@IsUrl() | ||
@IsOptional() | ||
url?: string; | ||
|
||
@IsOptional() | ||
standalone?: StandaloneConfiguration; | ||
|
||
@IsOptional() | ||
repository?: RepositoryConfiguration; | ||
|
||
@IsOptional() | ||
gateway?: GatewayConfiguration; | ||
|
||
@IsOptional() | ||
node?: NodeConfiguration; | ||
|
||
@IsOptional() | ||
proxy?: ProxyConfiguration; | ||
|
||
constructor(url?: string, standalone?: StandaloneConfiguration, repository?: RepositoryConfiguration, gateway?: GatewayConfiguration, node?: NodeConfiguration, proxy?: ProxyConfiguration) | ||
{ | ||
this.url = url; | ||
this.standalone = standalone; | ||
this.repository = repository; | ||
this.gateway = gateway; | ||
this.node = node; | ||
this.proxy = proxy; | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
|
||
import { Contains, IsEnum, IsOptional, IsString } from 'class-validator'; | ||
import { z } from 'zod'; | ||
import { LogLevel } from '../utils/LogBuilder.js'; | ||
|
||
export const serverOptionsSchema = z | ||
.object({ | ||
loglevel: z.nativeEnum(LogLevel).optional(), | ||
config: z.string().endsWith('.json').optional() | ||
}) | ||
.transform((value) => new ServerOptions(value.loglevel, value.config)); | ||
|
||
export default class ServerOptions | ||
{ | ||
@IsString() | ||
@IsOptional() | ||
@IsEnum(LogLevel) | ||
loglevel = 'info'; | ||
|
||
@IsString() | ||
@Contains('.json') | ||
@IsOptional() | ||
config = 'config.json'; | ||
|
||
constructor(loglevel = 'info', config = 'config.json') | ||
{ | ||
this.loglevel = loglevel; | ||
this.config = config; | ||
} | ||
} |
36 changes: 21 additions & 15 deletions
36
packages/server-nodejs/src/configuration/StandaloneConfiguration.ts
This file contains 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 |
---|---|---|
@@ -1,25 +1,31 @@ | ||
|
||
import { IsArray, IsOptional, IsString } from 'class-validator'; | ||
import { z } from 'zod'; | ||
|
||
export const standaloneSchema = z | ||
.object({ | ||
source: z.string().optional(), | ||
cache: z.string().optional(), | ||
index: z.string().optional(), | ||
segments: z.array(z.string()).optional(), | ||
assets: z.array(z.string()).optional() | ||
}) | ||
.strict() | ||
.transform((value) => new StandaloneConfiguration(value.source, value.cache, value.index, value.segments, value.assets)); | ||
|
||
export default class StandaloneConfiguration | ||
{ | ||
@IsString() | ||
@IsOptional() | ||
source?: string; | ||
|
||
@IsString() | ||
@IsOptional() | ||
cache?: string; | ||
|
||
@IsString() | ||
@IsOptional() | ||
index?: string; | ||
|
||
@IsArray() | ||
@IsOptional() | ||
segments?: string[]; | ||
|
||
@IsArray() | ||
@IsOptional() | ||
assets?: string[]; | ||
|
||
constructor(source?: string, cache?: string, index?: string, segments?: string[], assets?: string[]) | ||
{ | ||
this.source = source; | ||
this.cache = cache; | ||
this.index = index; | ||
this.segments = segments; | ||
this.assets = assets; | ||
} | ||
} |
This file contains 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
8 changes: 0 additions & 8 deletions
8
packages/server-nodejs/src/errors/MissingConfigurationValue.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.