Skip to content

Commit ff58725

Browse files
Merge pull request #1231 from opencomponents/ts-types
add more types
2 parents 9cb6da2 + e987f7c commit ff58725

File tree

3 files changed

+116
-20
lines changed

3 files changed

+116
-20
lines changed

src/cli/logger.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,27 @@ type Color =
1212
| 'gray'
1313
| 'grey';
1414

15-
const logger = {
15+
const logFns = {
1616
// eslint-disable-next-line no-console
1717
writeLn: console.log,
1818
write: (msg: string) => process.stdout.write(msg.toString())
1919
};
2020

2121
const log = (msg: string, color: Color | null, newLine: boolean) =>
22-
logger[newLine ? 'writeLn' : 'write'](color ? colors[color](msg) : msg);
22+
logFns[newLine ? 'writeLn' : 'write'](color ? colors[color](msg) : msg);
2323

24-
export default {
24+
export interface Logger {
25+
err: (msg: string, noNewLine?: boolean) => void;
26+
log: (msg: string, noNewLine?: boolean) => void;
27+
ok: (msg: string, noNewLine?: boolean) => void;
28+
warn: (msg: string, noNewLine?: boolean) => void;
29+
}
30+
31+
const logger: Logger = {
2532
err: (msg: string, noNewLine?: boolean) => log(msg, 'red', !noNewLine),
2633
log: (msg: string, noNewLine?: boolean) => log(msg, null, !noNewLine),
2734
ok: (msg: string, noNewLine?: boolean) => log(msg, 'green', !noNewLine),
2835
warn: (msg: string, noNewLine?: boolean) => log(msg, 'yellow', !noNewLine)
2936
};
37+
38+
export default logger;

src/registry/views/partials/components-templates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function componentsTemplates(vm: VM): string {
1111
}: {
1212
type: string;
1313
version: string;
14-
externals: Array<{ global: string; url: string }>;
14+
externals: Array<{ global: string | string[]; url: string }>;
1515
}) => {
1616
const externalLinks = externals.map(externalLink).join(', ');
1717
const externalsLabel = externalLinks ? `(Externals: ${externalLinks})` : '';

src/types.ts

Lines changed: 103 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
interface External {
2-
global: string;
3-
name: string;
4-
url: string;
5-
}
1+
import { NextFunction, Request, Response } from 'express';
62

7-
interface Template {
8-
type: string;
9-
version: string;
10-
externals: External[];
11-
}
12-
13-
interface Author {
3+
export interface Author {
144
name?: string;
155
email?: string;
166
url?: string;
@@ -28,6 +18,16 @@ interface ComponentHistory {
2818
version: string;
2919
}
3020

21+
export interface TemplateInfo {
22+
type: string;
23+
version: string;
24+
externals: Array<{
25+
name: string;
26+
global: string | string[];
27+
url: string;
28+
}>;
29+
}
30+
3131
export interface ComponentsDetails {
3232
lastEdit: number;
3333
components: {
@@ -37,6 +37,11 @@ export interface ComponentsDetails {
3737
};
3838
}
3939

40+
export interface ComponentsList {
41+
lastEdit: number;
42+
components: Dictionary<string[]>;
43+
}
44+
4045
export interface OcParameter {
4146
description?: string;
4247
example?: string;
@@ -47,6 +52,7 @@ export interface OcParameter {
4752

4853
interface OcConfiguration {
4954
date: number;
55+
state?: 'deprecated' | 'experimental';
5056
files: {
5157
dataProvider: {
5258
hashKey: string;
@@ -65,11 +71,13 @@ interface OcConfiguration {
6571
parameters: Record<string, OcParameter>;
6672
stringifiedDate: string;
6773
version: string;
74+
plugins?: string[];
6875
}
6976

70-
interface Component {
77+
export interface Component {
7178
allVersions: string[];
7279
author: Author;
80+
repository?: string;
7381
dependencies: Record<string, string>;
7482
description: string;
7583
devDependencies: Record<string, string>;
@@ -88,7 +96,7 @@ export interface VM {
8896
link: string;
8997
}>;
9098
components: Component[];
91-
componentsHistory: ComponentHistory[];
99+
componentsHistory?: ComponentHistory[];
92100
componentsList: ComponentList[];
93101
componentsReleases: number;
94102
href: string;
@@ -98,12 +106,13 @@ export interface VM {
98106
deprecated?: number;
99107
experimental?: number;
100108
};
101-
templates: Template[];
109+
templates: TemplateInfo[];
102110
title: string;
103111
type: 'oc-registry' | 'oc-registry-local';
104112
}
105113

106114
export interface Config {
115+
beforePublish: (req: Request, res: Response, next: NextFunction) => void;
107116
baseUrl: string;
108117
baseUrlFunc: (opts: { host?: string; secure: boolean }) => string;
109118
discovery: boolean;
@@ -113,13 +122,91 @@ export interface Config {
113122
tempDir: string;
114123
port: number;
115124
postRequestPayloadSize?: number;
116-
verbosity: boolean;
125+
verbosity: number;
126+
prefix: string;
127+
path: string;
128+
publishAuth?: {
129+
type: string;
130+
username: string;
131+
password: string;
132+
};
133+
dependencies: string[];
134+
routes?: Array<{
135+
route: string;
136+
method: string;
137+
handler: (req: Request, res: Response) => void;
138+
}>;
139+
storage: {
140+
adapter: any;
141+
options: Dictionary<any> & { componentsDir: string };
142+
};
143+
s3?: {
144+
bucket: string;
145+
region: string;
146+
key?: string;
147+
secret?: string;
148+
componentsDir: string;
149+
};
150+
customHeadersToSkipOnWeakVersion: string[];
151+
fallbackRegistryUrl: string;
152+
pollingInterval: number;
153+
publishValidation: (
154+
data: unknown
155+
) =>
156+
| {
157+
isValid: boolean;
158+
error?: string;
159+
}
160+
| boolean;
161+
refreshInterval?: number;
162+
keepAliveTimeout?: number;
163+
templates: any[];
164+
env: Dictionary<string>;
165+
hotReloading: boolean;
166+
timeout: number;
167+
liveReloadPort: number;
168+
}
169+
170+
export interface Cdn {
171+
getJson: <T>(filePath: string, force: boolean, cb: Callback<T>) => void;
172+
listSubDirectories: (
173+
dir: string,
174+
cb: Callback<string[], Error & { code?: string }>
175+
) => void;
176+
putFileContent: (
177+
data: unknown,
178+
path: string,
179+
isPrivate: boolean,
180+
callback: Callback<unknown, string>
181+
) => void;
182+
maxConcurrentRequests: number;
183+
}
184+
185+
export interface Template {
186+
getInfo: () => TemplateInfo;
187+
getCompiledTemplate: Function;
188+
render: Function;
189+
compile?: Function;
190+
}
191+
192+
export interface Plugin {
193+
name: string;
194+
register: {
195+
register: Function;
196+
execute: Function;
197+
dependencies: string[];
198+
};
199+
description?: string;
200+
options?: any;
201+
callback: Function;
117202
}
118203

119204
declare global {
120205
namespace Express {
121206
interface Response {
122207
conf: Config;
208+
errorDetails?: string;
209+
errorCode?: string;
123210
}
124211
}
125212
}

0 commit comments

Comments
 (0)