Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion packages/core/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import { indent } from './indent.js';
import { hasProperty } from './core.js';

declare var process: any;
declare var process: {
env: Record<string, string>;
} | undefined;

const indentCode = ('undefined' !== typeof process && process.env?.DEBUG || '').includes('deepkit');

Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ export function getInheritanceChain(classType: ClassType): ClassType[] {
}

declare var v8debug: any;
declare var process: {
execArgv: string[];
platform: string;
} | undefined;

export function inDebugMode() {
return typeof v8debug === 'object' ||
Expand Down Expand Up @@ -497,7 +501,7 @@ export function getCurrentFileName(offset: number = 0): string {
if (path.indexOf('file') >= 0) {
path = new URL(path).pathname;
}
if (path[0] === '/' && process.platform === 'win32') {
if (path[0] === '/' && 'undefined' !== typeof process && process.platform === 'win32') {
path = path.slice(1);
}
return path;
Expand Down
6 changes: 1 addition & 5 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
"es2020",
"es2022.error"
],
"types": [
"dot-prop",
"node"
],
"skipLibCheck": true
},
"reflection": true,
Expand All @@ -38,4 +34,4 @@
"path": "../bench/tsconfig.json"
}
]
}
}
30 changes: 13 additions & 17 deletions packages/http/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@
* You should have received a copy of the MIT License along with this program.
*/
import { ClassType, CompilerContext, getClassName, isArray, isClass, urlJoin } from '@deepkit/core';
import {
entity,
ReflectionClass,
ReflectionFunction,
ReflectionKind,
ReflectionParameter,
SerializationOptions,
serializer,
Serializer,
Type,
ValidationError,
} from '@deepkit/type';
import { entity, ReflectionClass, ReflectionFunction, ReflectionKind, ReflectionParameter, SerializationOptions, serializer, Serializer, Type, ValidationError } from '@deepkit/type';
import { getActions, HttpAction, httpClass, HttpController, HttpDecorator } from './decorator.js';
import { HttpRequest, HttpRequestPositionedParameters, HttpRequestQuery, HttpRequestResolvedParameters } from './model.js';
import { InjectorContext, InjectorModule } from '@deepkit/injector';
Expand All @@ -30,7 +19,7 @@ import { HttpMiddlewareConfig, HttpMiddlewareFn } from './middleware.js';

//@ts-ignore
import qs from 'qs';
import { HtmlResponse, JSONResponse, Response } from './http.js';
import { HtmlResponse, JSONResponse, Redirect, Response } from './http.js';
import { getRequestParserCodeForParameters, ParameterForRequestParser, parseRoutePathToRegex } from './request-parser.js';
import { HttpConfig } from './module.config.js';

Expand Down Expand Up @@ -352,7 +341,7 @@ export interface HttpRouterFunctionOptions {
function convertOptions(methods: string[], pathOrOptions: string | HttpRouterFunctionOptions, defaultOptions: Partial<HttpRouterFunctionOptions>): HttpRouterFunctionOptions {
const options = 'string' === typeof pathOrOptions ? { path: pathOrOptions } : pathOrOptions;
if (options.methods) return options;
return { ...options, methods };
return { ...defaultOptions, ...options, methods };
}

/**
Expand Down Expand Up @@ -444,6 +433,13 @@ export abstract class HttpRouterRegistryFunctionRegistrar {
this.register(convertOptions(['HEAD'], pathOrOptions, this.defaultOptions), callback);
}

public redirectCallback(pathOrOptions: string | HttpRouterFunctionOptions, callback: (request: HttpRequest) => string, redirectCode: number = 302) {
const options = convertOptions(['GET'], pathOrOptions, this.defaultOptions);
this.register(options, (request: HttpRequest) => {
return Redirect.toUrl(callback(request), redirectCode);
});
}

private register(options: HttpRouterFunctionOptions, callback: (...args: any[]) => any, module?: InjectorModule<any>) {
const fn = ReflectionFunction.from(callback);

Expand Down Expand Up @@ -536,7 +532,7 @@ export class HttpRouterRegistry extends HttpRouterRegistryFunctionRegistrar {
type: 'controller',
controller,
module,
methodName: action.methodName
methodName: action.methodName,
};
const routeConfig = createRouteConfigFromHttpAction(routeAction, action, module, controllerData);

Expand Down Expand Up @@ -578,7 +574,7 @@ export class HttpRouter {
controllers: (ClassType | { module: InjectorModule<any>, controller: ClassType })[],
middlewareRegistry: MiddlewareRegistry = new MiddlewareRegistry(),
module: InjectorModule<any> = new InjectorModule(),
config: HttpConfig = new HttpConfig()
config: HttpConfig = new HttpConfig(),
): HttpRouter {
return new this(new HttpControllers(controllers.map(v => {
return isClass(v) ? { controller: v, module } : v;
Expand Down Expand Up @@ -636,7 +632,7 @@ export class HttpRouter {
resolverForToken: routeConfig.resolverForToken,
resolverForParameterName: routeConfig.resolverForParameterName,
pathParameterNames: parsedRoute.pathParameterNames,
routeConfig
routeConfig,
});

let methodCheck = '';
Expand Down
2 changes: 1 addition & 1 deletion packages/type/src/reflection/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ export class Processor {
case ReflectionOp.parameter: {
const ref = this.eatParameter() as number;
const t: Type = { kind: ReflectionKind.parameter, parent: undefined as any, name: program.stack[ref] as string, type: this.pop() as Type };
t.type.parent = t;
if (t.type) t.type.parent = t;
this.pushType(t);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion sync-tsconfig-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ for (const name of packages) {
}

function filter(name) {
return !['api-console-gui', 'framework-debug-gui', 'orm-browser-gui'].includes(name);
return !['api-console-gui', 'framework-debug-gui', 'orm-browser-gui', 'desktop-ui'].includes(name);
}

for (const [name, config] of Object.entries(packageConfigs)) {
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
{
"path": "./packages/create-app/tsconfig.json"
},
{
"path": "./packages/desktop-ui/tsconfig.json"
},
{
"path": "./packages/devtool/tsconfig.json"
},
Expand Down Expand Up @@ -161,4 +158,4 @@
"path": "./packages/workflow/tsconfig.json"
}
]
}
}
8 changes: 8 additions & 0 deletions website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ cd website/
docker build -t website2 -f Dockerfile ../
docker run --rm -p 8080:8080 -e app_databaseHost=host.docker.internal website2
```


## Translate

```sh
export APP_OPENAI_API_KEY=your_openai_api_key
npm run translate de
```
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "npm run api-docs && BUILD=angular NODE_OPTIONS=--preserve-symlinks ng build --configuration production",
"test": "jest"
},
"type": "commonjs",
"private": true,
"devDependencies": {
"@angular-devkit/build-angular": "^20.0.3",
Expand Down
60 changes: 40 additions & 20 deletions website/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import { ActivatedRouteSnapshot, CanActivate, Route, Routes } from '@angular/router';
import { ActivatedRouteSnapshot, CanActivate, Route, Router, Routes, UrlMatcher, UrlSegment } from '@angular/router';
import { StartpageComponent } from '@app/app/pages/startpage.component';
import { DocumentationComponent } from '@app/app/pages/documentation.component';
import { EmptyComponent } from '@app/app/pages/empty.component';
import { CommunityQuestionsComponent } from '@app/app/pages/documentation/community-questions.component';
import { DocumentationPageComponent } from '@app/app/pages/documentation/page.component';
import { CommunityQuestionComponent } from '@app/app/pages/documentation/community-question.component';
import { ExamplesComponent } from '@app/app/pages/documentation/examples.component';
import { ExampleComponent } from '@app/app/pages/documentation/example.component';
import { DocuSearchComponent } from '@app/app/pages/documentation/search.component';
import { StaticPageComponent } from '@app/app/pages/static-page.component';
import { NotFoundComponent } from '@app/app/pages/not-found.component';
import { Injectable } from '@angular/core';
import { BlogComponent, BlogListComponent, BlogPostDetailComponent } from '@app/app/pages/blog.component';
import { BookComponent } from '@app/app/pages/documentation/book.component.js';

export const legacyDocMatcher: UrlMatcher = (segments: UrlSegment[]) => {
if (segments.length === 0 || segments[0].path !== 'documentation') return null;
const rest = segments.slice(1).map(s => s.path).join('/');
return { consumed: segments, posParams: { rest: new UrlSegment(rest, {}) } };
};

@Injectable({ providedIn: 'root' })
export class LegacyDocRedirectGuard implements CanActivate {
constructor(private router: Router) {}
canActivate(route: ActivatedRouteSnapshot): false {
const rest = (route.params['rest'] as string) || '';
const target = rest ? `/en/documentation/${rest}` : `/en/documentation`;
this.router.navigateByUrl(target, { replaceUrl: true });
return false;
}
}

function redirect(from: string, to: string): Route {
return {
path: from,
Expand All @@ -36,12 +48,20 @@ export const routes: Routes = [
redirect('documentation/type/serialization', 'documentation/runtime-types/serialization'),
redirect('documentation/framework/rpc/controller', 'documentation/rpc/getting-started'),

{ path: 'documentation', pathMatch: 'full', redirectTo: 'en/documentation' },
{ matcher: legacyDocMatcher, canActivate: [LegacyDocRedirectGuard], component: EmptyComponent },

// {
// path: 'benchmarks',
// loadChildren: () => import('./benchmarks/benchmarks.module').then(m => m.BenchmarksModule),
// },

{ path: '', pathMatch: 'full', component: StartpageComponent, data: { floatHeader: true } },
{ path: '', pathMatch: 'full', component: StartpageComponent },
{ path: 'zh', pathMatch: 'full', component: StartpageComponent },
{ path: 'ko', pathMatch: 'full', component: StartpageComponent },
{ path: 'ja', pathMatch: 'full', component: StartpageComponent },
{ path: 'de', pathMatch: 'full', component: StartpageComponent },

{ path: 'admin', loadComponent: () => import('./pages/admin/admin.component').then(v => v.AdminComponent) },
// { path: 'library', component: LibrariesComponent },
// { path: 'library/:id', component: LibraryComponent },
Expand All @@ -51,29 +71,29 @@ export const routes: Routes = [
{ path: 'about-us', component: StaticPageComponent, data: { page: 'about-us' } },
{ path: 'contact', component: StaticPageComponent, data: { page: 'contact' } },
{ path: 'data-protection', component: StaticPageComponent, data: { page: 'data-protection' } },
{ path: 'documentation/book', component: BookComponent },
{ path: ':lang/documentation/book', component: BookComponent },
{
path: 'blog', component: BlogComponent, children: [
path: ':lang/blog', component: BlogComponent, children: [
{ path: '', pathMatch: 'full', component: BlogListComponent },
{ path: ':slug', component: BlogPostDetailComponent },
],
},
{
path: 'documentation',
path: ':lang/documentation',
component: DocumentationComponent,
data: { search: true, footer: false, hideLogo: true },
children: [
{
path: 'questions', component: EmptyComponent, children: [
{ path: 'post/:slug', component: CommunityQuestionComponent },
{ path: '**', component: CommunityQuestionsComponent },
],
},
{ path: 'search', component: DocuSearchComponent },
{ path: 'examples', component: ExamplesComponent },
// {
// path: 'questions', component: EmptyComponent, children: [
// { path: 'post/:slug', component: CommunityQuestionComponent },
// { path: '**', component: CommunityQuestionsComponent },
// ],
// },
// { path: 'search', component: DocuSearchComponent },
// { path: 'examples', component: ExamplesComponent },
{ path: 'desktop-ui', loadChildren: () => import('./pages/documentation/desktop-ui/desktop-ui.module').then(v => v.DocDesktopUIModule) },
{ path: ':category/examples/:slug', component: ExampleComponent },
{ path: ':category/examples', component: ExamplesComponent },
// { path: ':category/examples/:slug', component: ExampleComponent },
// { path: ':category/examples', component: ExamplesComponent },
{ path: '**', component: DocumentationPageComponent },
],
},
Expand Down
10 changes: 8 additions & 2 deletions website/src/app/components/content-render.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Router } from '@angular/router';
import { AppImagesComponent } from '@app/app/components/images.component';
import { ImageComponent } from '@app/app/components/image.component';
import { DomSanitizer } from '@angular/platform-browser';
import { ContentApiDocsComponent } from '@app/app/components/content-api-docs.component.js';
import { ContentApiDocsComponent } from '@app/app/components/content-api-docs.component';
import { Translation } from '@app/app/components/translation';

const whitelist = ['div', 'p', 'a', 'button', 'iframe', 'pre', 'span', 'code', 'strong', 'hr', 'ul', 'li', 'ol', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img', 'table', 'tbody', 'tr', 'td', 'th', 'boxes', 'box'];

Expand Down Expand Up @@ -164,6 +165,7 @@ export class ContentRenderComponent implements OnInit, OnChanges {
private renderer: Renderer2,
private router: Router,
private injector: EnvironmentInjector,
private translation: Translation,
private app: ApplicationRef,
) {
}
Expand Down Expand Up @@ -353,7 +355,8 @@ export class ContentRenderComponent implements OnInit, OnChanges {
component.setInput('title', meta.title || '');

component.instance.onRender.subscribe(() => {
this.onRender.emit()
console.log('coder rendered');
this.onRender.emit();
});
this.app.attachView(component.hostView);
return [{ node: component.location.nativeElement }];
Expand Down Expand Up @@ -393,6 +396,9 @@ export class ContentRenderComponent implements OnInit, OnChanges {
const url = new URL(content.props.href, new URL(this.linkRelativeTo || this.router.url, base));
let href = url.pathname.replace('.md', '');
if (url.hash) href += url.hash;
if (href.startsWith('/documentation')) {
href = this.translation.lang() + href;
}
this.renderer.setAttribute(element, 'href', href);
}
this.hookRouter(element);
Expand Down
10 changes: 7 additions & 3 deletions website/src/app/components/footer.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.wrapper.made-in {
margin-top: 0;
font-size: 13px;
color: var(--color-grey2);
color: var(--color-grey);
padding-top: 0px;
padding-bottom: 43px;
justify-content: center;
Expand All @@ -40,7 +40,7 @@
}

.text {
color: var(--color-grey2);
color: var(--color-grey);
margin-top: 20px;
}
}
Expand All @@ -51,13 +51,17 @@ nav {
flex-direction: column;

a, a:link {
color: var(--color-grey2);
color: var(--color-grey);
font-size: 12px;
letter-spacing: 1px;
line-height: 16px;
text-align: right;
text-decoration: none;
}

a.active {
color: var(--color-link);
}
}

nav.social {
Expand Down
Loading