diff --git a/eslint.config.mjs b/eslint.config.mjs index 1160b3ba..1f14f890 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -26,6 +26,7 @@ export default getStormConfig({ "react/jsx-closing-bracket-location": 0, "no-undef": 0, "no-unused-vars": "warn", + "no-redeclare": 0, "unicorn/consistent-function-scoping": 0, "class-methods-use-this": 0, "operator-linebreak": 0, diff --git a/packages/serialization/src/types.ts b/packages/serialization/src/types.ts index 5896b8a2..5c237bfc 100644 --- a/packages/serialization/src/types.ts +++ b/packages/serialization/src/types.ts @@ -189,7 +189,7 @@ export type StormURL = ParsedURL & { */ export interface CookieSerializeOptions { /** - * Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no + * Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3 | Domain Set-Cookie attribute}. By default, no * domain is set, and most clients will consider the cookie to apply to only * the current domain. */ @@ -208,18 +208,18 @@ export interface CookieSerializeOptions { encode?(value: string): string; /** - * Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default, + * Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1 | `Expires` `Set-Cookie` attribute}. By default, * no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete * it on a condition like exiting a web browser application. * - * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} + * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3 | cookie storage model specification} * states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is * possible not all clients by obey this, so if both are set, they should * point to the same date and time. */ expires?: Date | undefined; /** - * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}. + * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6 | `HttpOnly` `Set-Cookie` attribute}. * When truthy, the `HttpOnly` attribute is set, otherwise it is not. By * default, the `HttpOnly` attribute is not set. * @@ -232,7 +232,7 @@ export interface CookieSerializeOptions { * `Set-Cookie` attribute. The given number will be converted to an integer * by rounding down. By default, no maximum age is set. * - * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} + * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3 | cookie storage model specification} * states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is * possible not all clients by obey this, so if both are set, they should * point to the same date and time. @@ -276,7 +276,7 @@ export interface CookieSerializeOptions { */ sameSite?: true | false | "lax" | "strict" | "none" | undefined; /** - * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the + * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5 | `Secure` `Set-Cookie` attribute}. When truthy, the * `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set. * * *Note* be careful when setting this to `true`, as compliant clients will diff --git a/packages/types/src/utility-types/form.ts b/packages/types/src/utility-types/form.ts index 358a6f75..389c81ec 100644 --- a/packages/types/src/utility-types/form.ts +++ b/packages/types/src/utility-types/form.ts @@ -15,6 +15,8 @@ -------------------------------------------------------------------*/ +import { NameValuePair } from "./utilities"; + export type SelectOptionValue = string | number | boolean | null; /** @@ -23,22 +25,12 @@ export type SelectOptionValue = string | number | boolean | null; export interface SelectOption< TValue extends SelectOptionValue = SelectOptionValue, TName = string -> { +> extends NameValuePair { /** * The index of the select option */ index: number; - /** - * The string value to display in the field - */ - name: TName; - - /** - * The value stored behind the scenes when selected - */ - value: TValue; - /** * The description of the select option */ diff --git a/packages/types/src/utility-types/index.ts b/packages/types/src/utility-types/index.ts index 2bc90076..03c03146 100644 --- a/packages/types/src/utility-types/index.ts +++ b/packages/types/src/utility-types/index.ts @@ -37,5 +37,6 @@ export * from "./object"; export * from "./package-json"; export * from "./string"; export * from "./tsconfig"; +export * from "./user"; export * from "./utilities"; export * from "./validations"; diff --git a/packages/types/src/utility-types/user.ts b/packages/types/src/utility-types/user.ts new file mode 100644 index 00000000..85427c8e --- /dev/null +++ b/packages/types/src/utility-types/user.ts @@ -0,0 +1,53 @@ +/*------------------------------------------------------------------- + + ⚡ Storm Software - Storm Stack + + This code was released as part of the Storm Stack project. Storm Stack + is maintained by Storm Software under the Apache-2.0 License, and is + free for commercial and private use. For more information, please visit + our licensing page. + + Website: https://stormsoftware.com + Repository: https://github.com/storm-software/storm-stack + Documentation: https://stormsoftware.com/projects/storm-stack/docs + Contact: https://stormsoftware.com/contact + License: https://stormsoftware.com/projects/storm-stack/license + + -------------------------------------------------------------------*/ + +export type UserType = "internal" | "external" | "service"; + +export const UserType = { + INTERNAL: "internal" as UserType, + EXTERNAL: "external" as UserType, + SERVICE: "service" as UserType +}; + +export interface UserBase { + /** + * The user's ID. + */ + id: string; + + /** + * The user's full name. + */ + username?: string; + + /** + * The user's type. + * + * @defaultValue "external" + */ + type: UserType; + + /** + * The user's email address. + */ + email?: string; + + /** + * The user's role. + */ + role?: string; +} diff --git a/packages/types/src/utility-types/utilities.ts b/packages/types/src/utility-types/utilities.ts index 33081af2..b6a97376 100644 --- a/packages/types/src/utility-types/utilities.ts +++ b/packages/types/src/utility-types/utilities.ts @@ -29,7 +29,6 @@ type NarrowRaw = | (A extends [] ? [] : never) | (A extends Narrowable ? A : never) | { - // eslint-disable-next-line @typescript-eslint/ban-types [K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw; }; @@ -38,7 +37,6 @@ export type Narrow = Try>; export type Try = A1 extends A2 ? A1 : Catch; // Hack to get TypeScript to show simplified types in error messages -// eslint-disable-next-line @typescript-eslint/ban-types export type Pretty = { [K in keyof T]: T[K] } & {}; export type ComputeRange< @@ -49,3 +47,18 @@ export type ComputeRange< : ComputeRange; export type Index40 = ComputeRange<40>[number]; + +/** + * A utility type for specifying a name/value pair. + */ +export interface NameValuePair { + /** + * The name of the pair + */ + name: TName; + + /** + * The value of the pair + */ + value: TValue; +} diff --git a/packages/types/src/utility-types/validations.ts b/packages/types/src/utility-types/validations.ts index 8c066dc1..fa16dd35 100644 --- a/packages/types/src/utility-types/validations.ts +++ b/packages/types/src/utility-types/validations.ts @@ -31,7 +31,7 @@ export type ValidationDetails< | typeof MessageType.SUCCESS > = MessageDetails & { /** - * The field that the message is related to. + * The field path that the message is related to. * * @remarks * If `undefined` or `null`, the message is not related to a specific field - in this case it is likely a global/form message.