/** * A freezed javascript object used like an enum. * @typedef {object} Enum * @constant * @example * var Meal = toEnum( { * Food: 'Tartiflette', * Drink: 'Saint-Emilion', * Dessert: 'Mousse au chocolat' * } ) * * if( Foo.includes('Tartiflette') { * // Happy * } * * var myDrink = 'coke' * if( myDrink === Meal.Drink ) { * * } else { * // Your life is a pain * } * * var MealTypes = Meal.types * // ['Tartiflette', 'Saint-Emilion', 'Mousse au chocolat' ] * */ import { toEnum } from 'itee-utils' /** * @typedef {Enum} FileFormat * @property {String} Asc="asc" - The ascii file format * @property {String} Dae="dae" - The dae file format * @property {String} Dbf="dbf" - The dbf file format * @property {String} Fbx="fbx" - The fbx file format * @property {String} Mtl="mtl" - The material file format * @property {String} Json="json" - The json file format * @property {String} Obj="obj" - The object file format * @property {String} Shp="shp" - The shape file format * @property {String} Stl="stl" - The stereolithographie file format * * @constant * @type {FileFormat} * @description The FileFormat Enum give some commonly used file format in 3d context */ const FileFormat = toEnum( { Asc: { value: 'asc' }, Dae: { value: 'dae' }, Dbf: { value: 'dbf' }, Fbx: { value: 'fbx' }, Mtl: { value: 'mtl' }, Json: { value: 'json' }, Obj: { value: 'obj' }, Shp: { value: 'shp' }, Stl: { value: 'stl' } } ) /** * @typedef {Enum} HttpStatusCode * @property {number} Continue=100 - Waiting for the continuation of the request. * @property {number} SwitchingProtocols=101 - The requester has asked the server to switch protocols and the server has agreed to do so. * @property {number} Processing=102 - WebDAV: Processing in progress (prevents the client from exceeding the limited waiting time). * @property {number} Ok=200 - Query successfully processed. * @property {number} Created=201 - Query successfully processed and a document was created. * @property {number} Accepted=202 - Query processed, but without guarantee of result. * @property {number} NonAuthoritativeInformation=203 - Information returned, but generated by an uncertified source. * @property {number} NoContent=204 - Query successfully processed but no information returned. * @property {number} ResetContent=205 - Query successfully processed, the current page can be cleared. * @property {number} PartialContent=206 - Only part of the resource has been transmitted. * @property {number} MultiStatus=207 - WebDAV: Multiple Response. * @property {number} AlreadyReported=208 - WebDAV: The document was previously sent to this collection. * @property {number} ContentDifferent=210 - WebDAV: The copy of the client-side resource differs from that of the server (content or properties). * @property {number} IMUsed=226 - The server has completed the request for the resource, and the response is a representation of the result of one or more instance manipulations applied to the * current instance. * @property {number} MultipleChoices=300 - The requested URI refers to multiple resources. * @property {number} MovedPermanently=301 - Document moved permanently. * @property {number} Found=302 - Document moved temporarily. * @property {number} SeeOther=303 - The answer to this query is elsewhere. * @property {number} NotModified=304 - Document not modified since the last request. * @property {number} UseProxy=305 - The request must be re-addressed to the proxy. * @property {number} Unused=306 - Code used by an older version of RFC 2616, now reserved. * @property {number} TemporaryRedirect=307 - The request must be temporarily redirected to the specified URI. * @property {number} PermanentRedirect=308 - The request must be redirected permanently to the specified URI. * @property {number} TooManyRedirects=310 - The request must be redirected too many times, or is the victim of a redirection loop. * @property {number} BadRequest=400 - The syntax of the query is wrong. * @property {number} Unauthorized=401 - Authentication is required to access the resource. * @property {number} PaymentRequired=402 - Payment required to access the resource. * @property {number} Forbidden=403 - The server understood the request, but refuses to execute it. Unlike error 401, authenticating will not make any difference. On servers where authentication is * required, this usually means that authentication has been accepted but access rights do not allow the client to access the resource. * @property {number} NotFound=404 - Resource not found. * @property {number} MethodNotAllowed=405 - Unauthorized request method. * @property {number} NotAcceptable=406 - The requested resource is not available in a format that would respect the "Accept" headers of the request. * @property {number} ProxyAuthenticationRequired=407 - Access to the authorized resource by identification with the proxy. * @property {number} RequestTimeOut=408 - Waiting time for an elapsed client request. * @property {number} Conflict=409 - The request can not be processed in the current state. * @property {number} Gone=410 - The resource is no longer available and no redirection address is known. * @property {number} LengthRequired=411 - The length of the request has not been specified. * @property {number} PreconditionFailed=412 - Preconditions sent by the query unverified. * @property {number} RequestEntityTooLarge=413 - Abandoned processing due to excessive request * @property {number} RequestURITooLong=414 - URI too long * @property {number} UnsupportedMediaType=415 - Unsupported query format for a given method and resource. * @property {number} RequestRangeUnsatisfiable=416 - Invalid "range" request header fields. * @property {number} ExpectationFailed=417 - Expected behavior and defined in the header of the unsatisfactory request. * @property {number} ImATeapot=418 - "I am a teapot". This code is defined in RFC 2324 dated April 1, 1998, Hyper Text Coffee Pot Control Protocol. * @property {number} BadMapping=421 - The request was sent to a server that is not able to produce a response (for example, because a connection has been reused). * @property {number} UnprocessableEntity=422 - WebDAV: The entity provided with the request is incomprehensible or incomplete. * @property {number} Locked=423 - WebDAV: The operation can not take place because the resource is locked. * @property {number} MethodFailure=424 - WebDAV: A method of the transaction failed. * @property {number} UnorderedCollection=425 - WebDAV RFC 3648. This code is defined in the WebDAV Advanced Collections Protocol draft , but is absent from the Web Distributed Authoring and * Versioning (WebDAV) Ordered Collections Protocol. * @property {number} UpgradeRequired=426 - RFC 2817 The client should change protocol, for example to TLS / 1.0 . * @property {number} PreconditionRequired=428 - RFC 6585 The request must be conditional. * @property {number} TooManyRequests=429 - RFC 6585 The client has issued too many requests within a given time. * @property {number} RequestHeaderFieldsTooLarge=431 - RFC 6585 HTTP headers issued exceed the maximum size allowed by the server. * @property {number} NoResponse=444 - Indicates that the server did not return any information to the client and closed the connection. * @property {number} RetryWith=449 - Code defined by Microsoft . The request should be returned after performing an action. * @property {number} BlockedByWindowsParentalControls=450 - Code defined by Microsoft. This error is generated when Windows Parental Control tools are enabled and block access to the page. * @property {number} UnavailableForLegalReasons=451 - This error code indicates that the requested resource is inaccessible for legal reasons * @property {number} UnrecoverableError=456 - WebDAV: Fatal error. * @property {number} SSLCertificateError=495 - An extension of the 400 Bad Request error, used when the client provided an invalid certificate. * @property {number} SSLCertificateRequired=496 - An extension of the 400 Bad Request error, used when a required client certificate is not provided. * @property {number} HTTPRequestSentToHTTPSPort=497 - An extension of the 400 Bad Request error, used when the client sends an HTTP request to port 443 normally intended for HTTPS requests. * @property {number} ClientClosedRequest=499 - The client closed the connection before receiving the response. This error occurs when the processing is too long on the server side. * @property {number} InternalServerError=500 - Internal server error. * @property {number} NotImplemented=501 - Functionality claimed not supported by the server. * @property {number} BadGateway=502 - Wrong response sent to an intermediate server by another server. * @property {number} ServiceUnavailable=503 - Service temporarily unavailable or under maintenance. * @property {number} GatewayTimeOut=504 - Waiting time for a response from a server to an intermediate server that has elapsed. * @property {number} HTTPVersionNotSupported=505 - HTTP version not managed by the server. * @property {number} VariantAlsoNegotiates=506 - RFC 2295: Negotiation Error. Transparent content negociation. * @property {number} InsufficientStorage=507 - WebDAV: Insufficient space to modify properties or build the collection. * @property {number} LoopDetected=508 - WebDAV: Loop in a Resource Match * @property {number} BandwidthLimitExceeded=509 - Used by many servers to indicate a quota overrun. * @property {number} NotExtended=510 - RFC 2774: The request does not respect the policy for accessing extended HTTP resources. * @property {number} NetworkAuthenticationRequired=511 - RFC 6585: The client must authenticate to access the network. Used by captive portals to redirect clients to the authentication page. * @property {number} UnknownError=520 - Error 520 is used as a wildcard response when the origin server returns an unexpected result. * @property {number} WebServerIsDown=521 - The server has refused the connection from Cloudflare. * @property {number} ConnectionTimedOut=522 - Cloudflare could not negotiate a TCP handshake with the origin server. * @property {number} OriginIsUnreachable=523 - Cloudflare failed to reach the origin server. This can occur if DNS server name resolution fails. * @property {number} ATimeoutOccured=524 - Cloudflare established a TCP connection with the origin server but did not receive an HTTP response before the login timeout. * @property {number} SSLHandshakeFailed=525 - Cloudflare could not negotiate SSL / TLS handshake with the origin server. * @property {number} InvalidSSLCertificate=526 - Cloudflare could not validate the SSL certificate presented by the origin server. * @property {number} RailgunError=527 - Error 527 indicates that the request has timed out or failed after the WAN connection was established. * * @constant * @type {HttpStatusCode} * @description HttpStatusCode contains all http status code available to check and process correctly server response. * @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes} for further information. */ const HttpStatusCode = toEnum( { // 100 Continue: { value: 100 }, SwitchingProtocols: { value: 101 }, Processing: { value: 102 }, // 200 Ok: { value: 200 }, Created: { value: 201 }, Accepted: { value: 202 }, NonAuthoritativeInformation: { value: 203 }, NoContent: { value: 204 }, ResetContent: { value: 205 }, PartialContent: { value: 206 }, MultiStatus: { value: 207 }, AlreadyReported: { value: 208 }, ContentDifferent: { value: 210 }, IMUsed: { value: 226 }, // 300 MultipleChoices: { value: 300 }, MovedPermanently: { value: 301 }, Found: { value: 302 }, SeeOther: { value: 303 }, NotModified: { value: 304 }, UseProxy: { value: 305 }, Unused: { value: 306 }, TemporaryRedirect: { value: 307 }, PermanentRedirect: { value: 308 }, TooManyRedirects: { value: 310 }, // 400 BadRequest: { value: 400 }, Unauthorized: { value: 401 }, PaymentRequired: { value: 402 }, Forbidden: { value: 403 }, NotFound: { value: 404 }, MethodNotAllowed: { value: 405 }, NotAcceptable: { value: 406 }, ProxyAuthenticationRequired: { value: 407 }, RequestTimeOut: { value: 408 }, Conflict: { value: 409 }, Gone: { value: 410 }, LengthRequired: { value: 411 }, PreconditionFailed: { value: 412 }, RequestEntityTooLarge: { value: 413 }, RequestRangeUnsatisfiable: { value: 416 }, ExpectationFailed: { value: 417 }, ImATeapot: { value: 418 }, BadMapping: { value: 421 }, UnprocessableEntity: { value: 422 }, Locked: { value: 423 }, MethodFailure: { value: 424 }, UnorderedCollection: { value: 425 }, UpgradeRequired: { value: 426 }, PreconditionRequired: { value: 428 }, TooManyRequests: { value: 429 }, RequestHeaderFieldsTooLarge: { value: 431 }, NoResponse: { value: 444 }, RetryWith: { value: 449 }, BlockedByWindowsParentalControls: { value: 450 }, UnavailableForLegalReasons: { value: 451 }, UnrecoverableError: { value: 456 }, SSLCertificateError: { value: 495 }, SSLCertificateRequired: { value: 496 }, HTTPRequestSentToHTTPSPort: { value: 497 }, ClientClosedRequest: { value: 499 }, // 500 InternalServerError: { value: 500 }, NotImplemented: { value: 501 }, BadGateway: { value: 502 }, ServiceUnavailable: { value: 503 }, GatewayTimeOut: { value: 504 }, HTTPVersionNotSupported: { value: 505 }, VariantAlsoNegotiates: { value: 506 }, InsufficientStorage: { value: 507 }, LoopDetected: { value: 508 }, BandwidthLimitExceeded: { value: 509 }, NotExtended: { value: 510 }, NetworkAuthenticationRequired: { value: 511 }, UnknownError: { value: 520 }, WebServerIsDown: { value: 521 }, ConnectionTimedOut: { value: 522 }, OriginIsUnreachable: { value: 523 }, ATimeoutOccured: { value: 524 }, SSLHandshakeFailed: { value: 525 }, InvalidSSLCertificate: { value: 526 }, RailgunError: { value: 527 } } ) /** * @typedef {Enum} HttpVerb * @property {String} Create="PUT" - Corresponding to the create http verb for an itee server, namely "PUT". * @property {String} Read="POST" - Corresponding to the read http verb for an itee server, namely "POST". * @property {String} Update="PATCH" - Corresponding to the update http verb for an itee server, namely "PATCH". * @property {String} Delete="DELETE" - Corresponding to the delete http verb for an itee server, namely "DELETE". * * @constant * @type {HttpVerb} * @description HttpVerb contains the CRUD actions with corresponding http verb to request an itee server. * @see {@link https://en.wikipedia.org/wiki/Create,_read,_update_and_delete} for further information. */ const HttpVerb = toEnum( { Create: { value: 'PUT' }, Read: { value: 'POST' }, Update: { value: 'PATCH' }, Delete: { value: 'DELETE' } } ) /** * @typedef {Enum} Keys * @property {Number} BACKSPACE=8 - The backspace key code * @property {Number} TAB=9 - The tab key code * @property {Number} ENTER=13 - The enter key code * @property {Number} Etc...=* - All the rest * * @constant * @type {Keys} * @description Keys contains common keyboard key values, this allow to write semantic code instead of integer when dealing with key codes. */ const Keys = toEnum( { BACKSPACE: { value: 8 }, TAB: { value: 9 }, ENTER: { value: 13 }, SHIFT: { value: 16 }, CTRL: { value: 17 }, ALT: { value: 18 }, PAUSE: { value: 19 }, CAPS_LOCK: { value: 20 }, ESCAPE: { value: 27 }, SPACE: { value: 32 }, PAGE_UP: { value: 33 }, PAGE_DOWN: { value: 34 }, END: { value: 35 }, HOME: { value: 36 }, LEFT_ARROW: { value: 37 }, UP_ARROW: { value: 38 }, RIGHT_ARROW: { value: 39 }, DOWN_ARROW: { value: 40 }, INSERT: { value: 45 }, DELETE: { value: 46 }, ZERO: { value: 48 }, ONE: { value: 49 }, TWO: { value: 50 }, THREE: { value: 51 }, FOUR: { value: 52 }, FIVE: { value: 53 }, SIX: { value: 54 }, SEVEN: { value: 55 }, HEIGHT: { value: 56 }, NINE: { value: 57 }, A: { value: 65 }, B: { value: 66 }, C: { value: 67 }, D: { value: 68 }, E: { value: 69 }, F: { value: 70 }, G: { value: 71 }, H: { value: 72 }, I: { value: 73 }, J: { value: 74 }, K: { value: 75 }, L: { value: 76 }, M: { value: 77 }, N: { value: 78 }, O: { value: 79 }, P: { value: 80 }, Q: { value: 81 }, R: { value: 82 }, S: { value: 83 }, T: { value: 84 }, U: { value: 85 }, V: { value: 86 }, W: { value: 87 }, X: { value: 88 }, Y: { value: 89 }, Z: { value: 90 }, LEFT_WINDOW_KEY: { value: 91 }, RIGHT_WINDOW_KEY: { value: 92 }, SELECT_KEY: { value: 93 }, NUMPAD_0: { value: 96 }, NUMPAD_1: { value: 97 }, NUMPAD_2: { value: 98 }, NUMPAD_3: { value: 99 }, NUMPAD_4: { value: 100 }, NUMPAD_5: { value: 101 }, NUMPAD_6: { value: 102 }, NUMPAD_7: { value: 103 }, NUMPAD_8: { value: 104 }, NUMPAD_9: { value: 105 }, MULTIPLY: { value: 106 }, ADD: { value: 107 }, SUBSTRACT: { value: 109 }, DECIMAL_POINT: { value: 110 }, DIVIDE: { value: 111 }, F1: { value: 112 }, F2: { value: 113 }, F3: { value: 114 }, F4: { value: 115 }, F5: { value: 116 }, F6: { value: 117 }, F7: { value: 118 }, F8: { value: 119 }, F9: { value: 120 }, F10: { value: 121 }, F11: { value: 122 }, F12: { value: 123 }, NUM_LOCK: { value: 144 }, SCROLL_LOCK: { value: 145 }, SEMICOLON: { value: 186 }, EQUAL: { value: 187 }, COMMA: { value: 188 }, DASH: { value: 189 }, PERIODE: { value: 190 }, SLASH: { value: 191 }, GRAVE_ACCENT: { value: 192 }, OPEN_SQUARE_BRACKET: { value: 219 }, BACKSLASH: { value: 220 }, CLOSE_SQUARE_BRACKET: { value: 221 }, SINGLE_QUOTE: { value: 222 } } ) /** * @typedef {Enum} MimeType * @property {Number} ... * * @constant * @type {MimeType} * @description Todo... */ const MimeType = toEnum( {} ) /** * @typedef {Enum} Mouse * @property {Number} Wheel=-1 - The enter key code * @property {Number} Left=0 - The enter key code * @property {Number} Middle=1 - The enter key code * @property {Number} Right=2 - The enter key code * * @constant * @type {Mouse} * @description This Mouse Enum expose 4 common state of mouse button values (Wheel, Left, Middle and Right), this allow to write semantic code instead of integer when dealing with mouse button codes. */ const Mouse = toEnum( { Wheel: { value: -1 }, Left: { value: 0 }, Middle: { value: 1 }, Right: { value: 2 } } ) /** * @typedef {Enum} ResponseType * @property {String} ArrayBuffer="arraybuffer" - The "arraybuffer" server response type. * @property {String} Blob="blob" - The "blob" server response type. * @property {String} Document="document" - The "document" server response type. * @property {String} Json="json" - The "json" server response type. * @property {String} DOMString="text" - The "text" server response type. * @property {String} Default="text" - The "" server response type ( equivalent to DOMString ). * * @constant * @type {ResponseType} * @description ResponseType allow to filter wich type of response is recieved from the server. * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType} for further information. */ const ResponseType = toEnum( { ArrayBuffer: { value: 'arraybuffer' }, Blob: { value: 'blob' }, Document: { value: 'document' }, Json: { value: 'json' }, DOMString: { value: 'text' }, Default: { value: '' } } ) export { FileFormat, HttpStatusCode, HttpVerb, Keys, MimeType, Mouse, ResponseType }