### Install haute-couture Source: https://github.com/hapipal/haute-couture/blob/main/README.md Installs the haute-couture package using npm. ```sh npm install @hapipal/haute-couture ``` -------------------------------- ### Hapi Plugin Registration Example Source: https://github.com/hapipal/haute-couture/blob/main/API.md Example of registering a hapi plugin that utilizes HauteCouture.compose to manage server composition. ```javascript const HauteCouture = require('@hapipal/haute-couture'); module.exports = { name: 'my-hapi-plugin', async register(server, options) { // Custom plugin code can go here await HauteCouture.compose(server, options); } }; ``` -------------------------------- ### HauteCouture.default Amendment Example Source: https://github.com/hapipal/haute-couture/blob/main/API.md Demonstrates using HauteCouture.default as a key in amendments to specify default configurations, such as disabling recursive directory traversal. ```javascript await HauteCouture.compose(server, options, { amendments: { // Do not look recursively into directories anywhere aside from routes/ [HauteCouture.default]: { recursive: false }, routes: HauteCouture.amendment('routes', { recursive: true }) } }); ``` -------------------------------- ### Basic hapi Plugin with haute-couture Source: https://github.com/hapipal/haute-couture/blob/main/README.md Example of a hapi plugin that uses haute-couture to compose its components. It registers a 'pinger' route. ```javascript const HauteCouture = require('@hapipal/haute-couture'); module.exports = { name: 'my-hapi-plugin', register: async (server, options) => { // Custom plugin code can go here await HauteCouture.compose(server, options); } }; ``` ```javascript module.exports = { method: 'get', path: '/', options: { handler(request) { return { ping: 'pong' }; } } }; ``` -------------------------------- ### Mapping File Contents to Hapi Calls Source: https://github.com/hapipal/haute-couture/blob/main/API.md Explains the convention where files export values that are mapped to hapi server calls. For example, exporting { method, path, handler } from a route file results in server.route() being called. ```javascript // Example: routes/my-route.js exports { method, path, handler } // Haute-Couture calls: server.route({ method, path, handler }) ``` -------------------------------- ### HauteCouture.amendment() with Patch Source: https://github.com/hapipal/haute-couture/blob/main/API.md Shows how to use HauteCouture.amendment to retrieve a default amendment and apply a patch to modify it. This example modifies the 'routes' amendment. ```javascript await HauteCouture.compose(server, options, { amendments: { routes: HauteCouture.amendment('routes', { recursive: false }) } }); ``` -------------------------------- ### Haute-Couture .hc.js Amendment Configuration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Defines custom amendments for Haute-Couture using a .hc.js file. This example configures model handling for Mongoose, including scaffolding support. ```javascript 'use strict'; module.exports = { models: { list: true, signature: ['name', 'schema'], method: (server, options, name, schema) => { const { connection } = server.app; // Access the Dog model as such in a route handler: // const { Dog } = request.server.app.models; server.app.models = server.app.models || {}; server.app.models[name] = connection.model(name, schema); }, // This example below isn't essential. But it allows you to use // `hpal make model ` in order to scaffold your // Mongoose models from the command line. example: { $requires: ['mongoose'], $value: { name: 'ModelName', schema: { $literal: 'new Mongoose.Schema({})'} } } } }; ``` -------------------------------- ### Hapi server.cache.provision() Mapping Source: https://github.com/hapipal/haute-couture/blob/main/API.md Explains the mapping for server cache provisioning. Files like 'caches.js', 'caches/index.js', or 'caches/some-cache-name.js' export cache options or functions returning them. ```javascript // caches.js or caches/index.js exports array of options or function(server, options) { return array of options } // caches/some-cache-name.js exports options or function(server, options) { return options } ``` -------------------------------- ### Hapi Server Decorations Source: https://github.com/hapipal/haute-couture/blob/main/API.md Allows decorating the Hapi server instance with custom properties and methods. Supports various file naming conventions for defining decorations. ```APIDOC server.decorate(type, property, method, [options]) - Decorates the server with custom functionality. - Supported file structures: `decorations.js`, `decorations/index.js`, `decorations/decoration-name.js`, `decorations/[type].decoration-name.js`, `decorations/[type]/decoration-name.js`. ``` -------------------------------- ### Exporting Server Method Configuration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Illustrates how to export configuration for server methods. A file exporting an object with 'name' and 'method' keys will result in a call to server.method(name, method). ```javascript // Example: server-methods/my-method.js exports { name, method } // Haute-Couture calls: server.method(name, method) ``` -------------------------------- ### Hapi server.register() Mapping Source: https://github.com/hapipal/haute-couture/blob/main/API.md Describes how files map to server.register() calls for plugin registrations. Files like 'plugins.js', 'plugins/index.js', or 'plugins/plugin-name.js' export plugin configurations. ```javascript // plugins.js or plugins/index.js exports array of plugins or function(server, options) { return array of plugins } // plugins/plugin-name.js exports plugins or function(server, options) { return plugins } ``` -------------------------------- ### Hapi Server Extensions Configuration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Details how to configure server extensions in Hapi, including event types and handler registration. Supports various file structures for organizing extension points. ```APIDOC server.ext(events) - **`extensions.js`**: export an array of `events` or `function(server, options)` that returns an array of `events`. - **`extensions/index.js`**: export an array of `events` or `function(server, options)` that returns an array of `events`. - **`extensions/[event-type].js`**: export `events` or `function(server, options)` that returns `events`. The `type` (of each item if there are multiple) will be assigned `[event-type]` camel-cased from the filename if it isn't already specified. E.g. `onPreHandler`-type events can be placed in `extensions/on-pre-handler.js`. - **`extensions/[event-type]/name.js`**: export `events` or `function(server, options)` that returns `events`. The `type` (of each item if there are multiple) will be assigned `[event-type]` camel-cased from the path if it isn't already specified. E.g. `onPreHandler`-type events can be placed in `extensions/on-pre-handler/my-handlers.js`. ``` -------------------------------- ### Exporting Functions for Hapi Calls Source: https://github.com/hapipal/haute-couture/blob/main/API.md Shows how files can export functions that accept 'server' and 'options' and return the intended value or array of values for hapi calls. ```javascript // Example: files can export function(server, options) { ... } // or async function(server, options) { ... } ``` -------------------------------- ### Hapi Subscriptions Configuration (nes) Source: https://github.com/hapipal/haute-couture/blob/main/API.md Outlines how to configure subscriptions for the 'nes' module in Hapi. Supports defining subscriptions via arrays of objects or factory functions, with file naming for specific services. ```APIDOC server.subscription(path, [options]) - **`subscriptions.js`**: export an array of objects `{ path, options }` or `function(server, options)` that returns an array of objects. - **`subscriptions/index.js`**: export an array of objects `{ path, options }` or `function(server, options)` that returns an array of objects. - **`subscriptions/service-name.js`**: export an object `{ path, options }` or `function(server, options)` that returns an object. ``` -------------------------------- ### Hapi Server Methods Configuration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Defines how to configure server methods in Hapi. Methods can be exported as an array of objects or a function returning an array, with specific file naming conventions for individual methods. ```APIDOC server.method(name, method, [options]) - **`methods.js`**: export an array of objects `{ name, method, options }` or `function(server, options)` that returns an array of objects. - **`methods/index.js`**: export an array of objects or `function(server, options)` that returns an array of objects. - **`methods/method-name.js`**: export an object or `function(server, options)` that returns an object. The `name` will be assigned `'methodName'` camel-cased from the filename if it isn't already specified. ``` -------------------------------- ### Hapi Authentication Strategies Configuration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Details how to configure authentication strategies in Hapi, linking them to schemes and options. File structure conventions are provided for organizing strategies. ```APIDOC server.auth.strategy(name, scheme, [options]) - **`auth/strategies.js`**: export an array of objects `{ name, scheme, options }` or `function(server, options)` that returns an array of objects. - **`auth/strategies/index.js`**: export an array of objects or `function(server, options)` that returns an array of objects. - **`auth/strategies/strategy-name.js`**: export an object or `function(server, options)` that returns an object. The `name` will be assigned `'strategy-name'` from the filename if it isn't already specified. ``` -------------------------------- ### Hapi Routes Configuration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Details how to define and register routes in Hapi. Supports exporting routes as arrays or individual route objects, with file naming conventions for route IDs or groups. ```APIDOC server.route(route) - **`routes.js`**: export an array of `route` or `function(server, options)` that returns an array of `route`. - **`routes/index.js`**: export an array of `route` or `function(server, options)` that returns an array of `route`. - **`routes/route-id.js`**: export `route` or `function(server, options)` that returns `route`. If `route` is a single route config object, the route's `config.id` will be assigned `'route-id'` from the filename if it isn't already specified. The filename could just as easily represent a group of routes (rather than an id) and the file could export an array of route configs. ``` -------------------------------- ### HauteCouture.composeWith() Usage Source: https://github.com/hapipal/haute-couture/blob/main/API.md Demonstrates using HauteCouture.composeWith to create a Hapi plugin with predefined amendments. This is useful for setting default configurations. ```javascript module.exports = { name: 'my-plugin', register: HauteCouture.composeWith({ amendments: { $default: { recursive: false } } }) }; ``` -------------------------------- ### HauteCouture.manifest() Usage Source: https://github.com/hapipal/haute-couture/blob/main/API.md Explains the usage of HauteCouture.manifest, mainly for tooling, to generate a Hapi manifest with optional amendments and directory information. ```javascript Returns the hapi [haute](https://github.com/devinivy/haute) manifest, incorporating optional `amendments` to the manifest as described in documentation for [`HauteCouture.compose()`](#await-hautecouturecomposeserver-options-composeoptions). Haute requires each manifest item have an `item.dirname`, which will be set if `dirname` is specified. ``` -------------------------------- ### Hapi server.path() Mapping Source: https://github.com/hapipal/haute-couture/blob/main/API.md Details how files named 'path.js' or 'path/index.js' map to server.path() calls, exporting either the relativeTo path or a function that returns it. ```javascript // path.js or path/index.js exports relativeTo or function(server, options) { return relativeTo } ``` -------------------------------- ### HauteCouture.compose Method Source: https://github.com/hapipal/haute-couture/blob/main/API.md Composes a hapi server by processing files and directories to make calls into the hapi interface. Supports custom plugin registration options and amendment configurations for interpreting directory contents. ```APIDOC HauteCouture.compose(server, options, [composeOptions]) Composes `server` by making calls into hapi from file and directory contents. Parameters: server: The hapi server instance. options: Plugin registration options. composeOptions: Optional object to define `dirname` and `amendments`. dirname: Absolute directory path to look for files and directories. amendments: Object defining configuration for interpreting directory contents into hapi calls. - recursive: Boolean, whether to pick up files recursively within a directory. - stopAtIndexes: Boolean, when true with `recursive`, prevents recursion into directories adjacent to an index file. - include: Function or RegExp to filter files based on filename and path. - exclude: Function or RegExp to filter files, defaults to excluding files in `helpers/` directories. - meta: Object for meta information, primarily for integration with other tools. - before: String or array of `place` values for ordering calls prior to other items. - after: String or array of `place` values for ordering calls subsequent to other items. - example: Example value for an item, used by the hpal CLI. ``` -------------------------------- ### Hapi Server Exposed Properties Source: https://github.com/hapipal/haute-couture/blob/main/API.md Exposes key-value pairs on the Hapi server instance. Supports defining exposed properties through various file structures. ```APIDOC server.expose(key, value) - Exposes a property on the server instance. - Supported file structures: `expose.js`, `expose/index.js`, `expose/property-name.js`. ``` -------------------------------- ### Hapi Default Authentication Strategy Source: https://github.com/hapipal/haute-couture/blob/main/API.md Describes how to set the default authentication strategy for a Hapi server. Configuration can be exported directly or via a factory function. ```APIDOC server.auth.default(options) - **`auth/default.js`**: export `options` or `function(server, options)` that returns `options`. - **`auth/default/index.js`**: export `options` or `function(server, options)` that returns `options`. ``` -------------------------------- ### Hapi Authentication Schemes Configuration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Explains how to register custom authentication schemes in Hapi. Schemes can be defined as objects or factory functions, with file naming conventions for specific schemes. ```APIDOC server.auth.scheme(name, scheme) - **`auth/schemes.js`**: export an array of objects `{ name, scheme }` or `function(server, options)` that returns an array of objects. - **`auth/schemes/index.js`**: export an array of objects or `function(server, options)` that returns an array of objects. - **`auth/schemes/scheme-name.js`**: export an object or `function(server, options)` that returns an object. The `name` will be assigned `'scheme-name'` from the filename if it isn't already specified. ``` -------------------------------- ### Hapi View Manager Configuration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Configures the view manager for Hapi.js applications using the vision plugin. Supports exporting options directly or via a function that returns options. ```APIDOC server.views(options) - Configures the view manager for Hapi.js applications. - Supported file structures: `view-manager.js`, `view-manager/index.js`. ``` -------------------------------- ### Hapi Dependencies Management Source: https://github.com/hapipal/haute-couture/blob/main/API.md Manages plugin dependencies for Hapi.js applications, allowing specification of dependencies and an optional callback function. Supports defining dependencies in various file structures. ```APIDOC server.dependency(dependencies, [after]) - Manages plugin dependencies. - Supported file structures: `dependencies.js`, `dependencies/index.js`, `dependencies/plugin-name.js`. ``` -------------------------------- ### Hapi Globally Bound Context Source: https://github.com/hapipal/haute-couture/blob/main/API.md Binds a context object globally to the Hapi server instance, making it accessible throughout the application. Supports defining context in various file structures. ```APIDOC server.bind(context) - Binds a context object globally. - Supported file structures: `bind.js`, `bind/index.js`. ``` -------------------------------- ### Haute-Couture Plugin Registration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Registers a Hapi plugin that uses Haute-Couture to compose server configurations. It connects to MongoDB using Mongoose and applies amendments. ```javascript 'use strict'; const HauteCouture = require('@hapipal/haute-couture'); const Mongoose = require('mongoose'); module.exports = { name: 'my-hapi-plugin', register: async (server, options) => { // When registering this plugin pass something like this as plugin options: // { mongoURI: 'mongodb://localhost/test' } server.app.connection = Mongoose.createConnection(options.mongoURI); await HauteCouture.compose(server, options); } }; ``` -------------------------------- ### Mongoose Model Definition Source: https://github.com/hapipal/haute-couture/blob/main/API.md Defines a Mongoose model for a 'Dog' with a 'name' property. This file is intended to be scaffolded by the hpal CLI. ```javascript 'use strict'; // Scaffolded using the CLI: // npx hpal make model dog const Mongoose = require('mongoose'); module.exports = { name: 'Dog', schema: new Mongoose.Schema({ name: String }) }; ``` -------------------------------- ### Hapi Service Definitions Source: https://github.com/hapipal/haute-couture/blob/main/API.md Registers service factories for use with the schmervice plugin in Hapi.js applications. Supports defining services in various file structures. ```APIDOC server.registerService(serviceFactory) - Registers service factories. - Supported file structures: `services.js`, `services/index.js`, `services/service-name.js`. ``` -------------------------------- ### Hapi Validator Configuration Source: https://github.com/hapipal/haute-couture/blob/main/API.md Explains how to set a custom validator for the Hapi server. The validator can be exported directly or provided via a factory function. ```APIDOC server.validator(validator) - **`validator.js`**: export `validator` or `function(server, options)` that returns `validator`. - **`validator/index.js`**: export `validator` or `function(server, options)` that returns `validator`. ``` -------------------------------- ### HauteCouture.amendments() Usage Source: https://github.com/hapipal/haute-couture/blob/main/API.md Illustrates the use of HauteCouture.amendments, primarily for tooling, to generate default amendments with specified overrides. ```javascript Returns haute-couture's default amendments with `amendments` overrides applied. The result is an object whose keys are `place`s and values are amendments as described in documentation for [`HauteCouture.compose()`](#await-hautecouturecomposeserver-options-composeoptions). ``` -------------------------------- ### Haute Manifest Item Structure Source: https://github.com/hapipal/haute-couture/blob/main/API.md Defines the structure of a 'haute' manifest item, used to map file system elements to hapi plugin API calls. It specifies how file contents are passed as arguments to plugin methods. ```APIDOC Haute Manifest Item: - place: Relative path to file/directory (e.g., 'auth/strategies'). - method: Name of the hapi plugin API method (e.g., 'auth.strategy'). Can be a deep method or a function `(server, options, ...values) => void`. - signature: (Optional) Array of argument names for the method. If omitted, entire file contents are passed as a single argument. Optional arguments can be denoted with brackets `[]` (e.g., `['name', '[options]']`). - list: (Optional) If true, calls the method for each item in an array exported at 'place' or for each value exported by files within 'place' if 'place' is a directory. - useFilename: (Optional) When 'list' is true and 'place' is a directory without an index file, this function `(filename, value, path) => newValue` modifies contents using the filename. - recursive: (Optional) When 'list' is true, enables recursive file picking within 'place'. - stopAtIndexes: (Optional) When 'recursive' is true, stops recursion at directories containing an index file. - include: (Optional) Function `(filename, path) => Boolean` or RegExp to filter files based on filename (without extension) and path relative to 'place'. - exclude: (Optional) Function or RegExp, similar to 'include', to exclude files. Defaults to excluding files in 'helpers/' directories. - meta: (Optional) Object for meta-information, useful for integration with other tools. ``` -------------------------------- ### Hapi Model Definitions Source: https://github.com/hapipal/haute-couture/blob/main/API.md Registers model definitions for use with the schwifty ORM in Hapi.js applications. Supports defining models in various file structures. ```APIDOC server.registerModel(models) - Registers model definitions. - Supported file structures: `models.js`, `models/index.js`, `models/model-name.js`. ``` -------------------------------- ### Hapi Cookie State Management Source: https://github.com/hapipal/haute-couture/blob/main/API.md Manages cookie state for Hapi.js applications, allowing definition of cookie names and options. Supports various file structures for cookie definitions. ```APIDOC server.state(name, [options]) - Manages cookie state. - Supported file structures: `cookies.js`, `cookies/index.js`, `cookies/cookie-name.js`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.