{"_id":"o-children","_rev":"3-7435db260083e826c8f6b4d0975fff90","time":{"created":"2024-01-20T18:29:12.461Z","3.14.0":"2024-01-19T17:28:34.563Z","modified":"2024-02-01T22:26:23.214Z","10.0.0":"2024-01-20T18:29:12.613Z","10.1.0-beta.0":"2024-02-01T22:26:23.047Z"},"name":"o-children","dist-tags":{"latest":"10.1.0-beta.0"},"versions":{"10.0.0":{"name":"o-children","version":"10.0.0","bin":{"o-children":"src/bin.mjs"},"repository":{"type":"git","url":"git+https://github.com/kostyandrew/o-children.git"},"license":"MIT","author":{"name":"Andrii Kostetskyi","email":"kostyandrew@gmail.com"},"imports":{"#framework/*":"./src/framework/*","#internal/*":"./src/internal/*"},"exports":{"./*":"./src/framework/*.mjs"},"dependencies":{"express":"^4.18.2","lodash-es":"^4.17.21","nodemon":"^3.0.3"},"devDependencies":{"prettier":"^3.2.4"},"_id":"o-children@10.0.0","gitHead":"c61458b7d571d37117b98f02f6c9c611f14c8c54","description":"o-children is a Node.js server library that leverages Express to provide a file-system-based routing mechanism. Designed for testing and educational purposes, this library facilitates an intuitive way to organize and handle HTTP routes. It is not recommen","bugs":{"url":"https://github.com/kostyandrew/o-children/issues"},"homepage":"https://github.com/kostyandrew/o-children#readme","_nodeVersion":"20.11.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-8x1o5Zz7zRi5xaPXupEUYah+gyM2Cu9YsBIP2wpEbTJDxge8tzNLD5PqdpvLFZRhTO2kLAPqSrjlEhc1jKehGA==","shasum":"2a0a53812c0aa26ae09d0cb96653284db08287c0","tarball":"https://registry.npmjs.org/o-children/-/o-children-10.0.0.tgz","fileCount":21,"unpackedSize":18951,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDUm3QuDUNNEPutJ6kjmfRI9gYmFZjEW+yKOd/yZrbUagIhAL1fZT4AFMqf4omKS+onnk/bjz/doJIBYPNdpF5K7Lma"}]},"_npmUser":{"name":"kostyandrew","email":"kostyandrew@gmail.com"},"directories":{},"maintainers":[{"name":"kostyandrew","email":"kostyandrew@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o-children_10.0.0_1705775352462_0.8770458137296642"},"_hasShrinkwrap":false},"10.1.0-beta.0":{"name":"o-children","version":"10.1.0-beta.0","bin":{"o-children":"dist/module/bin.mjs"},"types":"./dist/module","type":"module","repository":{"type":"git","url":"git+https://github.com/kostyandrew/o-children.git"},"license":"MIT","author":{"name":"Andrii Kostetskyi","email":"kostyandrew@gmail.com"},"imports":{"#framework/*":{"import":"./dist/module/framework/*.mjs","require":"./dist/commonjs/framework/*.cjs"},"#internal/*":{"import":"./dist/module/*.mjs","require":"./dist/commonjs/*.cjs"}},"scripts":{"build:commonjs":"(rimraf dist/commonjs || true) && tsc -p tsconfig.commonjs.json && node renameExtensions.mjs commonjs && tsc-alias -p tsconfig.commonjs.json && chmod +x ./dist/commonjs/bin.cjs","build:module":"(rimraf dist/module || true) && tsc -p tsconfig.module.json && node renameExtensions.mjs module && tsc-alias -p tsconfig.module.json && chmod +x ./dist/module/bin.mjs","build":"(rimraf dist || true) && npm run build:commonjs && npm run build:module"},"exports":{"./*":{"import":"./dist/module/framework/*.mjs","require":"./dist/commonjs/framework/*.cjs"}},"dependencies":{"express":"^4.18.2","lodash":"^4.17.21","nodemon":"^3.0.3"},"devDependencies":{"@types/express":"^4.17.21","@types/lodash-es":"^4.17.12","@types/node":"^20.11.5","@types/nodemon":"^1.19.6","prettier":"^3.2.4","rimraf":"^5.0.5","tsc-alias":"^1.8.8"},"peerDependencies":{"typescript":"^5.3.3"},"_id":"o-children@10.1.0-beta.0","gitHead":"4706687550ffd41e698d3c756cf4e0027d1bfc18","description":"o-children is a Node.js server library that leverages Express to provide a file-system-based routing mechanism. Designed for testing and educational purposes, this library facilitates an intuitive way to organize and handle HTTP routes. It is not recommen","bugs":{"url":"https://github.com/kostyandrew/o-children/issues"},"homepage":"https://github.com/kostyandrew/o-children#readme","_nodeVersion":"20.11.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-8QMuj//UmsYZGiMKad0eCwlYXa0cL3K+B/E4OiWwakLBswd0tyGfupy8F7gDxFl2tSlzPIhaxjblRFBkPlQmpw==","shasum":"249850b4d32b8fc864fa4d894355ef31960112f1","tarball":"https://registry.npmjs.org/o-children/-/o-children-10.1.0-beta.0.tgz","fileCount":59,"unpackedSize":50502,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICYPrt9ieN3u10dhuUkA4fcoffauWHmHjEJEHoDnW+roAiEA4T0sUtqm/iBYNx8Fzvw79WzN32OqbSTRu4LgNLCm/gg="}]},"_npmUser":{"name":"kostyandrew","email":"kostyandrew@gmail.com"},"directories":{},"maintainers":[{"name":"kostyandrew","email":"kostyandrew@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o-children_10.1.0-beta.0_1706826382762_0.7992603100692064"},"_hasShrinkwrap":false}},"maintainers":[{"name":"kostyandrew","email":"kostyandrew@gmail.com"}],"description":"o-children is a Node.js server library that leverages Express to provide a file-system-based routing mechanism. Designed for testing and educational purposes, this library facilitates an intuitive way to organize and handle HTTP routes. It is not recommen","homepage":"https://github.com/kostyandrew/o-children#readme","repository":{"type":"git","url":"git+https://github.com/kostyandrew/o-children.git"},"author":{"name":"Andrii Kostetskyi","email":"kostyandrew@gmail.com"},"bugs":{"url":"https://github.com/kostyandrew/o-children/issues"},"license":"MIT","readme":"# o-children\n\no-children is a Node.js server library that leverages Express to provide a file-system-based routing mechanism. Designed for testing and educational purposes, this library facilitates an intuitive way to organize and handle HTTP routes. It is not recommended for production.\n\n## Features\n\n- **Express-Based**: Built upon Express for robust HTTP request handling.\n- **Filesystem Routing**: Allows for routes to be defined by the filesystem, making route management straightforward and scalable.\n- **Helper Functions**: Includes functions like `json` for returning JSON responses with ease.\n- **Return Objects from Handlers**: Enables handlers to return objects directly, streamlining the response creation process.\n- **Middleware Support**: Offers the capability to include middleware files that apply logic to multiple routes in a directory.\n\n## Installation\n\n```bash\nnpm install o-children\n```\n\n## Directory Structure and Route Mapping\n\nThe `o-children` library maps the directory structure of your project to HTTP routes. Here’s how different files correspond to URL paths:\n\n### Products\n\n```\napp/\n├── products/\n│   ├── :productId.mjs     # Handles requests for specific products by ID.\n│   └── index.mjs          # Manages requests to the products listing.\n```\n\n- `app/products/:productId.mjs`: This file will handle requests to URLs like `/products/1`, where `1` is the ID of the product. The `:productId` in the filename indicates a dynamic segment in the URL path.\n\n  Example:\n\n  ```javascript\n  // app/products/:productId.mjs\n  import { params } from 'o-children/request';\n  import { json } from 'o-children/response';\n\n  export function GET() {\n  \tconst productId = params().get('productId');\n  \t// Logic to retrieve product details...\n  \treturn { productId, name: 'Example Product' };\n  }\n  ```\n\n- `app/products/index.mjs`: This file responds to the `/products` endpoint and is typically used to list all products.\n\n  Example:\n\n  ```javascript\n  // app/products/index.mjs\n\n  export function GET() {\n  \t// Logic to retrieve all products...\n  \treturn [\n  \t\t{ productId: 1, name: 'Example Product 1' },\n  \t\t{ productId: 2, name: 'Example Product 2' },\n  \t];\n  }\n  ```\n\n### Checkout\n\n```\napp/\n└── checkout/\n    └── summary.mjs        # Serves the summary page of the checkout process.\n```\n\n- `app/checkout/summary.mjs`: Maps to the `/checkout/summary` URL, which could display a summary of the items in the user's cart and the total cost.\n\n  Example:\n\n  ```javascript\n  // app/checkout/summary.mjs\n  import { json } from 'o-children/response';\n\n  export function GET() {\n  \t// Logic to create a summary of the checkout...\n  \treturn json({ itemCount: 3, totalCost: 150.0 });\n  }\n  ```\n\n## Middleware and Metadata\n\nIn `o-children`, middleware functions are used to process and augment requests before they reach the route handlers. Unlike some other frameworks, middleware functions in `o-children` do not directly receive `req`, `res`, and `next` parameters. Instead, they return a function that can interact with the request and response objects.\n\nTo access metadata set in middleware, use the `getMeta` function provided by the library.\n\nExample of setting metadata in `_middleware.mjs`:\n\n```javascript\n// _middleware.mjs\nexport default function () {\n\treturn {\n\t\ttimestamp: Date.now(),\n\t};\n}\n```\n\nTo retrieve the metadata in your route handler:\n\n```javascript\n// In your route handler file\nimport { meta } from 'o-children/request';\n\nexport function GET() {\n\t// You can now use the metadata, for example:\n\tconst timestamp = meta().timestamp;\n\t//...\n}\n```\n\nPlease note, any object returned by a middleware function will not be sent as a response (use `json` function instead`). Instead, it is stored as metadata for the request, which can then be accessed by route handlers.\n\n## Configuration\n\nConfigure your `o-children` application with an `o.config.mjs` file in the root of your project. This file should define the server and application settings using the `defineConfig` function provided by the library. Below is an example of how to structure your configuration with TypeScript type annotations:\n\n```typescript\n/**\n * Main configuration object for the o-children application.\n */\ntype Config = {\n\tserver?: ServerConfig;\n\tapp?: AppConfig;\n};\n\n/**\n * Application-specific configuration.\n */\ntype AppConfig = {\n\t// Directory where application files are located. Defaults to 'app'.\n\tdir?: string;\n};\n\n/**\n * Server configuration options.\n */\ntype ServerConfig = {\n\t// The port number the server listens on.\n\tport?: number;\n\t// The host name or IP address the server listens on.\n\thost?: string;\n};\n```\n\n```javascript\nimport defineConfig from 'o-children/defineConfig';\n// Example configuration using defineConfig\nexport default defineConfig({\n\tserver: {\n\t\tport: 8080,\n\t},\n\tapp: {\n\t\tdir: 'src',\n\t},\n});\n```\n\nMake sure to adjust your configuration according to your application's needs and the `o-children` library's capabilities.\n\n## Running the Server\n\n- To start the server, use the command: `o-children start`\n- To watch for file changes and automatically restart the server, use the command: `o-children watch`\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Disclaimer\n\n`o-children` is intended solely for testing and development purposes and should not be deployed in a production setting.\n","readmeFilename":"README.md"}