diff --git a/package-lock.json b/package-lock.json index 23626cf..5642f8d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,8 @@ "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", + "@nestjs/swagger": "^8.1.0", + "class-validator": "^0.14.1", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1" }, @@ -1563,6 +1565,12 @@ "node": ">=8" } }, + "node_modules/@microsoft/tsdoc": { + "version": "0.15.1", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.15.1.tgz", + "integrity": "sha512-4aErSrCR/On/e5G2hDP0wjooqDdauzEbIq8hIkIe5pXV0rtWJZvdCEKL0ykZxex+IxIwBp0eGeV48hQN07dXtw==", + "license": "MIT" + }, "node_modules/@nestjs/cli": { "version": "10.4.9", "resolved": "https://registry.npmjs.org/@nestjs/cli/-/cli-10.4.9.tgz", @@ -1676,6 +1684,26 @@ } } }, + "node_modules/@nestjs/mapped-types": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-2.0.6.tgz", + "integrity": "sha512-84ze+CPfp1OWdpRi1/lOu59hOhTz38eVzJvRKrg9ykRFwDz+XleKfMsG0gUqNZYFa6v53XYzeD+xItt8uDW7NQ==", + "license": "MIT", + "peerDependencies": { + "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0", + "class-transformer": "^0.4.0 || ^0.5.0", + "class-validator": "^0.13.0 || ^0.14.0", + "reflect-metadata": "^0.1.12 || ^0.2.0" + }, + "peerDependenciesMeta": { + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, "node_modules/@nestjs/platform-express": { "version": "10.4.15", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.4.15.tgz", @@ -1721,6 +1749,39 @@ "dev": true, "license": "MIT" }, + "node_modules/@nestjs/swagger": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-8.1.0.tgz", + "integrity": "sha512-8hzH+r/31XshzXHC9vww4T0xjDAxMzvOaT1xAOvvY1LtXTWyNRCUP2iQsCYJOnnMrR+vydWjvRZiuB3hdvaHxA==", + "license": "MIT", + "dependencies": { + "@microsoft/tsdoc": "^0.15.0", + "@nestjs/mapped-types": "2.0.6", + "js-yaml": "4.1.0", + "lodash": "4.17.21", + "path-to-regexp": "3.3.0", + "swagger-ui-dist": "5.18.2" + }, + "peerDependencies": { + "@fastify/static": "^6.0.0 || ^7.0.0", + "@nestjs/common": "^9.0.0 || ^10.0.0", + "@nestjs/core": "^9.0.0 || ^10.0.0", + "class-transformer": "*", + "class-validator": "*", + "reflect-metadata": "^0.1.12 || ^0.2.0" + }, + "peerDependenciesMeta": { + "@fastify/static": { + "optional": true + }, + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, "node_modules/@nestjs/testing": { "version": "10.4.15", "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-10.4.15.tgz", @@ -1924,6 +1985,13 @@ "url": "https://opencollective.com/unts" } }, + "node_modules/@scarf/scarf": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@scarf/scarf/-/scarf-1.4.0.tgz", + "integrity": "sha512-xxeapPiUXdZAE3che6f3xogoJPeZgig6omHEy1rIY5WVsB3H2BHNnZH+gHG6x91SCWyQCzWGsuL2Hh3ClO5/qQ==", + "hasInstallScript": true, + "license": "Apache-2.0" + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -2261,6 +2329,12 @@ "@types/superagent": "^8.1.0" } }, + "node_modules/@types/validator": { + "version": "13.12.2", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.12.2.tgz", + "integrity": "sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA==", + "license": "MIT" + }, "node_modules/@types/yargs": { "version": "17.0.33", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz", @@ -2858,7 +2932,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true, "license": "Python-2.0" }, "node_modules/array-flatten": { @@ -3455,6 +3528,17 @@ "dev": true, "license": "MIT" }, + "node_modules/class-validator": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.1.tgz", + "integrity": "sha512-2VEG9JICxIqTpoK1eMzZqaV+u/EiwEJkMGzTrZf6sU/fwsnOITVgYJ8yojSy6CaXtO9V0Cc6ZQZ8h8m4UBuLwQ==", + "license": "MIT", + "dependencies": { + "@types/validator": "^13.11.8", + "libphonenumber-js": "^1.10.53", + "validator": "^13.9.0" + } + }, "node_modules/cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -6664,7 +6748,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, "license": "MIT", "dependencies": { "argparse": "^2.0.1" @@ -6804,6 +6887,12 @@ "node": ">= 0.8.0" } }, + "node_modules/libphonenumber-js": { + "version": "1.11.17", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.11.17.tgz", + "integrity": "sha512-Jr6v8thd5qRlOlc6CslSTzGzzQW03uiscab7KHQZX1Dfo4R6n6FDhZ0Hri6/X7edLIDv9gl4VMZXhxTjLnl0VQ==", + "license": "MIT" + }, "node_modules/lie": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", @@ -6851,7 +6940,6 @@ "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true, "license": "MIT" }, "node_modules/lodash.memoize": { @@ -8806,6 +8894,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/swagger-ui-dist": { + "version": "5.18.2", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.18.2.tgz", + "integrity": "sha512-J+y4mCw/zXh1FOj5wGJvnAajq6XgHOyywsa9yITmwxIlJbMqITq3gYRZHaeqLVH/eV/HOPphE6NjF+nbSNC5Zw==", + "license": "Apache-2.0", + "dependencies": { + "@scarf/scarf": "=1.4.0" + } + }, "node_modules/symbol-observable": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", @@ -9447,6 +9544,15 @@ "node": ">=10.12.0" } }, + "node_modules/validator": { + "version": "13.12.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz", + "integrity": "sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 05aa407..13c9e1f 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,8 @@ "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", + "@nestjs/swagger": "^8.1.0", + "class-validator": "^0.14.1", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1" }, diff --git a/src/app.controller.ts b/src/app.controller.ts index 10614d0..05f9feb 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -1,30 +1,15 @@ -import { Body, Controller, Get, Header, StreamableFile } from '@nestjs/common'; +import { Body, Controller, Get, Header, Post, RawBody, RawBodyRequest, Req, StreamableFile } from '@nestjs/common'; import { AppService } from './app.service'; +import { ExportToDocxDto } from './export-to-docx.dto'; @Controller() export class AppController { constructor(private readonly appService: AppService) {} - @Get('docx') - @Header('Content-Disposition', `attachment; filename="hello.docx"`) - async getHello() { - const htmlData = ` -

Here’s an enhanced version of the blog post, including a table for clarity and a simple script to illustrate the wavefunction's temporal evolution. These additions add variety and make the post more dynamic.

The Elegance of the Schrödinger Equation: A Gateway to Quantum Realms

The Schrödinger equation is more than a mathematical formula—it’s a bridge connecting the realms of physics and philosophy. Conceived by Erwin Schrödinger in 1926, this equation is the foundation of quantum mechanics, describing phenomena that defy classical intuition.

At the Heart of the Equation

The Schrödinger equation is a poetic balance of time, space, and energy:

iℏ∂ψ(r,t)∂t=[−ℏ22m∇2+V(r,t)]ψ(r,t)i\\hbar \\frac{\\partial \\psi(\\mathbf{r}, t)}{\\partial t} = \\left[ -\\frac{\\hbar^2}{2m} \\nabla^2 + V(\\mathbf{r}, t) \\right] \\psi(\\mathbf{r}, t)

Key Components

TermMeaning
ψ(r,t)\\psi(\\mathbf{r}, t)
The wavefunction: encodes all quantum information about the system.
iℏ∂ψ∂ti\\hbar \\frac{\\partial \\psi}{\\partial t}
Describes the temporal evolution of the system.
−ℏ22m∇2-\\frac{\\hbar^2}{2m} \\nabla^2
Represents the kinetic energy operator, involving the Laplacian (∇2\\nabla^2).
V(r,t)V(\\mathbf{r}, t)
The potential energy as a function of position and time.

This equation is a masterpiece of simplicity and universality, governing everything from electrons in atoms to photons in cavities.

Visualizing the Wavefunction

To illustrate the wavefunction's evolution, consider a simple script. The wavefunction for a particle in a 1D potential can be modeled as:

function waveFunction(x, t) {
-    const hBar = 1.0545718e-34; // Reduced Planck's constant (in Joule seconds)
-    const m = 9.11e-31;         // Mass of an electron (in kilograms)
-    const E = 1.6e-19;          // Energy (in Joules)
-    
-    const k = Math.sqrt(2 * m * E) / hBar; // Wave number
-    const omega = E / hBar;               // Angular frequency
-    
-    return Math.cos(k * x - omega * t);
-}
-
-// Example usage: visualize the wavefunction at x = 1nm and t = 1fs
-console.log(waveFunction(1e-9, 1e-15));
-

This script simulates a 1D wavefunction, showcasing how position (xx) and time (tt) interact. Plugging in different values reveals the oscillatory nature of the quantum world.

Applications in the Modern World

The Schrödinger equation has far-reaching implications across science and technology. Here’s a quick overview:

FieldApplication
Quantum ComputingHarnessing quantum states for computation.
NanotechnologyUnderstanding matter at atomic and subatomic scales.
PhilosophyChallenging classical notions of determinism and exploring the nature of reality.
Material SciencePredicting and designing new materials with quantum properties.

Philosophical Implications

The equation challenges our understanding of reality itself. Particles, once considered discrete, are revealed as waves of probability. The deterministic certainties of classical physics dissolve into the quantum world’s probabilistic dance.

Its beauty lies in this duality: it predicts with precision, yet opens doors to infinite philosophical interpretations. Is reality inherently deterministic, or does it weave a tapestry of probabilities? The Schrödinger equation invites us to ponder these profound questions.

A Quantum Symphony

In summary, the Schrödinger equation is more than just a formula—it is a celebration of the universe's quantum mysteries. Its beauty lies in its ability to unify science, mathematics, and philosophy into a coherent framework that continues to inspire.

Share Your Quantum Journey

What fascinates you about quantum mechanics? Have you explored the mysteries of the wavefunction before? Share your thoughts below and join the discussion on this quantum odyssey.

This version integrates technical depth, engaging visuals (like the table), and a dynamic script to attract and educate readers in a compelling way. Let me know if you’d like further tweaks!

- ` - const data = await this.appService.getHello(htmlData); + @Post('docx') + @Header('Content-Disposition', `attachment; filename="docx.docx"`) + async getDocx(@Body() exportToDocxDto: ExportToDocxDto): Promise { + const data = await this.appService.getDocx(exportToDocxDto.htmlData); return new StreamableFile(data); } } diff --git a/src/app.service.ts b/src/app.service.ts index bb3f327..2a69a00 100644 --- a/src/app.service.ts +++ b/src/app.service.ts @@ -7,7 +7,7 @@ import { Blob } from "buffer"; @Injectable() export class AppService { - async getHello(htmlData: string) { + async getDocx(htmlData: string) { const data = await HTMLtoDOCX(htmlData); return data; } diff --git a/src/export-to-docx.dto.ts b/src/export-to-docx.dto.ts new file mode 100644 index 0000000..04e45bd --- /dev/null +++ b/src/export-to-docx.dto.ts @@ -0,0 +1,11 @@ +import { ApiProperty } from "@nestjs/swagger"; +import { IsString } from "class-validator"; + +export class ExportToDocxDto { + @IsString() + @ApiProperty({ + type: String, + description: 'HTML data to convert to DOCX', + }) + htmlData: string; +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index f76bc8d..e4fc3ad 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,22 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; +import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule, { cors: true }); + + const config = new DocumentBuilder() + .setTitle('Cats example') + .setDescription('The cats API description') + .setVersion('1.0') + .addTag('cats') + .build(); + const documentFactory = () => SwaggerModule.createDocument(app, config); + SwaggerModule.setup('api', app, documentFactory); + await app.listen(process.env.PORT ?? 3000); + + console.log(`Application is running on: ${await app.getUrl()}`); + console.log(`Swagger is running on: ${await app.getUrl()}/api`); } bootstrap();