tsoa
This commit is contained in:
11
node_modules/@hapi/mimos/LICENSE.md
generated
vendored
Executable file
11
node_modules/@hapi/mimos/LICENSE.md
generated
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
Copyright (c) 2014-2022, Project contributors
|
||||
Copyright (c) 2014-2020, Sideway Inc
|
||||
Copyright (c) 2014, Walmart.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* The names of any contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
17
node_modules/@hapi/mimos/README.md
generated
vendored
Normal file
17
node_modules/@hapi/mimos/README.md
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<a href="https://hapi.dev"><img src="https://raw.githubusercontent.com/hapijs/assets/master/images/family.png" width="180px" align="right" /></a>
|
||||
|
||||
# @hapi/mimos
|
||||
|
||||
#### Mime database interface.
|
||||
|
||||
**mimos** is part of the **hapi** ecosystem and was designed to work seamlessly with the [hapi web framework](https://hapi.dev) and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out [hapi](https://hapi.dev) – they work even better together.
|
||||
|
||||
### Visit the [hapi.dev](https://hapi.dev) Developer Portal for tutorials, documentation, and support
|
||||
|
||||
## Useful resources
|
||||
|
||||
- [Documentation and API](https://hapi.dev/family/mimos/)
|
||||
- [Versions status](https://hapi.dev/resources/status/#mimos) (builds, dependencies, node versions, licenses, eol)
|
||||
- [Changelog](https://hapi.dev/family/mimos/changelog/)
|
||||
- [Project policies](https://hapi.dev/policies/)
|
||||
- [Free and commercial support options](https://hapi.dev/support/)
|
||||
134
node_modules/@hapi/mimos/lib/index.d.ts
generated
vendored
Normal file
134
node_modules/@hapi/mimos/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
// Declare our own interface to mime-db data
|
||||
|
||||
declare namespace MimeDb {
|
||||
|
||||
type MimeSource = 'iana' | 'apache' | 'nginx';
|
||||
|
||||
interface MimeEntry {
|
||||
|
||||
/**
|
||||
* String with identifier for the source of the data.
|
||||
*/
|
||||
source?: MimeSource;
|
||||
|
||||
/**
|
||||
* Array of strings with possible lowercased file extensions, without the
|
||||
* dot.
|
||||
*/
|
||||
extensions?: ReadonlyArray<string>;
|
||||
|
||||
/**
|
||||
* Boolean that indicates if the contents is likely to become smaller if
|
||||
* gzip or similar compression is applied.
|
||||
*/
|
||||
compressible?: boolean;
|
||||
|
||||
/**
|
||||
* Charset for type.
|
||||
*/
|
||||
charset?: string;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Helpers
|
||||
|
||||
type NoInfer<T> = [T][T extends any ? 0 : never];
|
||||
|
||||
|
||||
export class MimosEntry {
|
||||
|
||||
/**
|
||||
* String with the content-type.
|
||||
*/
|
||||
type: string;
|
||||
|
||||
/**
|
||||
* String with identifier for the source of the data.
|
||||
*/
|
||||
source: MimeDb.MimeSource | 'mime-db' | 'mimos';
|
||||
|
||||
/**
|
||||
* Array of strings with possible lowercased file extensions, without the
|
||||
* dot.
|
||||
*/
|
||||
extensions: ReadonlyArray<string>;
|
||||
|
||||
/**
|
||||
* Boolean that indicates if the contents is likely to become smaller if
|
||||
* gzip or similar compression is applied.
|
||||
*/
|
||||
compressible: boolean;
|
||||
|
||||
/**
|
||||
* Optional charset for type.
|
||||
*/
|
||||
charset?: string;
|
||||
|
||||
private constructor();
|
||||
}
|
||||
|
||||
export interface MimosDeclaration<P extends object = {}> extends MimeDb.MimeEntry {
|
||||
|
||||
/**
|
||||
* The `type` value of result objects, defaults to `key`.
|
||||
*/
|
||||
type?: string;
|
||||
|
||||
/**
|
||||
* Method with signature `function(mime)`.
|
||||
*
|
||||
* When this mime type is found in the database, this function will run.
|
||||
* This allows you make customizations to `mime` based on developer criteria.
|
||||
*/
|
||||
predicate?: (mime: MimosEntry & P) => MimosEntry;
|
||||
}
|
||||
|
||||
export interface MimosOptions<P extends object = {}> {
|
||||
|
||||
/**
|
||||
* An object hash that is merged into the built-in mime information from
|
||||
* {@link https://github.com/jshttp/mime-db}.
|
||||
*
|
||||
* Each key value pair represents a single mime object override.
|
||||
*
|
||||
* Each override entry should follow this schema:
|
||||
* * The key is the lower-cased correct mime-type. (Ex. "application/javascript").
|
||||
* * The value should be an object following the structure from
|
||||
* {@link https://github.com/jshttp/mime-db#data-structure} with additional
|
||||
* optional values:
|
||||
* * type - Specify the `type` value of result objects, defaults to `key`.
|
||||
* * predicate - Method that is called with mime entry on lookup, that
|
||||
* must return an entry. This allows you make customizations to `mime`
|
||||
* based on developer criteria.
|
||||
*/
|
||||
override?: {
|
||||
[type: string]: MimosDeclaration<P> & P;
|
||||
};
|
||||
}
|
||||
|
||||
export class Mimos<P extends object = {}> {
|
||||
|
||||
/**
|
||||
* Create a Mimos object for mime lookups.
|
||||
*/
|
||||
constructor(options?: MimosOptions<NoInfer<P>>);
|
||||
|
||||
/**
|
||||
* Extract extension from file path and lookup mime information.
|
||||
*
|
||||
* @param path - Path to file
|
||||
*
|
||||
* @return Found mime object, or {} if no match.
|
||||
*/
|
||||
path(path: string): (Readonly<MimosEntry & Partial<P>>) | {};
|
||||
|
||||
/**
|
||||
* Lookup mime information.
|
||||
*
|
||||
* @param type - The content-type to find mime information about.
|
||||
*
|
||||
* @return Mime object for provided type.
|
||||
*/
|
||||
type(type: string): Readonly<MimosEntry & Partial<P>>;
|
||||
}
|
||||
147
node_modules/@hapi/mimos/lib/index.js
generated
vendored
Executable file
147
node_modules/@hapi/mimos/lib/index.js
generated
vendored
Executable file
@@ -0,0 +1,147 @@
|
||||
'use strict';
|
||||
|
||||
const Path = require('path');
|
||||
|
||||
const Hoek = require('@hapi/hoek');
|
||||
const MimeDb = require('mime-db/db.json'); // Load JSON file to prevent loading or executing code
|
||||
|
||||
|
||||
const internals = {
|
||||
compressibleRx: /^text\/|\+json$|\+text$|\+xml$/
|
||||
};
|
||||
|
||||
|
||||
exports.MimosEntry = class {
|
||||
|
||||
constructor(type, mime) {
|
||||
|
||||
this.type = type;
|
||||
this.source = 'mime-db';
|
||||
this.extensions = [];
|
||||
this.compressible = undefined;
|
||||
|
||||
Object.assign(this, mime);
|
||||
|
||||
if (this.compressible === undefined) {
|
||||
this.compressible = internals.compressibleRx.test(type);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
internals.insertEntry = function (type, entry, db) {
|
||||
|
||||
db.byType.set(type, entry);
|
||||
for (const ext of entry.extensions) {
|
||||
db.byExtension.set(ext, entry);
|
||||
if (ext.length > db.maxExtLength) {
|
||||
db.maxExtLength = ext.length;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
internals.compile = function (mimedb) {
|
||||
|
||||
const db = {
|
||||
byType: new Map(),
|
||||
byExtension: new Map(),
|
||||
maxExtLength: 0
|
||||
};
|
||||
|
||||
for (const type in mimedb) {
|
||||
const entry = new exports.MimosEntry(type, mimedb[type]);
|
||||
internals.insertEntry(type, entry, db);
|
||||
}
|
||||
|
||||
return db;
|
||||
};
|
||||
|
||||
|
||||
internals.getTypePart = function (fulltype) {
|
||||
|
||||
const splitAt = fulltype.indexOf(';');
|
||||
return splitAt === -1 ? fulltype : fulltype.slice(0, splitAt);
|
||||
};
|
||||
|
||||
|
||||
internals.applyPredicate = function (mime) {
|
||||
|
||||
if (mime.predicate) {
|
||||
return mime.predicate(Hoek.clone(mime));
|
||||
}
|
||||
|
||||
return mime;
|
||||
};
|
||||
|
||||
|
||||
exports.Mimos = class Mimos {
|
||||
|
||||
#db = internals.base;
|
||||
|
||||
constructor(options = {}) {
|
||||
|
||||
if (options.override) {
|
||||
Hoek.assert(typeof options.override === 'object', 'overrides option must be an object');
|
||||
|
||||
// Shallow clone db
|
||||
|
||||
this.#db = {
|
||||
...this.#db,
|
||||
byType: new Map(this.#db.byType),
|
||||
byExtension: new Map(this.#db.byExtension)
|
||||
};
|
||||
|
||||
// Apply overrides
|
||||
|
||||
for (const type in options.override) {
|
||||
const override = options.override[type];
|
||||
Hoek.assert(!override.predicate || typeof override.predicate === 'function', 'predicate option must be a function');
|
||||
|
||||
const from = this.#db.byType.get(type);
|
||||
const baseEntry = from ? Hoek.applyToDefaults(from, override) : override;
|
||||
|
||||
const entry = new exports.MimosEntry(type, baseEntry);
|
||||
internals.insertEntry(type, entry, this.#db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path(path) {
|
||||
|
||||
const extension = Path.extname(path).slice(1).toLowerCase();
|
||||
const mime = this.#db.byExtension.get(extension) ?? {};
|
||||
|
||||
return internals.applyPredicate(mime);
|
||||
}
|
||||
|
||||
type(type) {
|
||||
|
||||
type = internals.getTypePart(type);
|
||||
|
||||
let mime = this.#db.byType.get(type);
|
||||
if (!mime) {
|
||||
// Retry with more expensive adaptations
|
||||
|
||||
type = type.trim().toLowerCase();
|
||||
mime = this.#db.byType.get(type);
|
||||
}
|
||||
|
||||
if (!mime) {
|
||||
mime = new exports.MimosEntry(type, {
|
||||
source: 'mimos'
|
||||
});
|
||||
|
||||
// Cache the entry
|
||||
|
||||
internals.insertEntry(type, mime, this.#db);
|
||||
|
||||
return mime;
|
||||
}
|
||||
|
||||
return internals.applyPredicate(mime);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
internals.base = internals.compile(MimeDb);
|
||||
37
node_modules/@hapi/mimos/package.json
generated
vendored
Normal file
37
node_modules/@hapi/mimos/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@hapi/mimos",
|
||||
"description": "Mime database interface",
|
||||
"version": "7.0.1",
|
||||
"repository": "git://github.com/hapijs/mimos",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"keywords": [
|
||||
"mime",
|
||||
"database",
|
||||
"content-type"
|
||||
],
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"plugin:@hapi/module"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@hapi/hoek": "^11.0.2",
|
||||
"mime-db": "^1.52.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@hapi/code": "^9.0.0",
|
||||
"@hapi/eslint-plugin": "*",
|
||||
"@hapi/lab": "^25.0.1",
|
||||
"@types/node": "^17.0.31",
|
||||
"typescript": "~4.6.4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "lab -m 5000 -t 100 -L -a @hapi/code -Y",
|
||||
"test-cov-html": "lab -a @hapi/code -r html -o coverage.html -L"
|
||||
},
|
||||
"license": "BSD-3-Clause"
|
||||
}
|
||||
Reference in New Issue
Block a user