Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
blaine-arcjet committed Feb 20, 2024
1 parent 17992f9 commit 8249876
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
44 changes: 23 additions & 21 deletions arcjet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ type LiteralCheck<
| boolean
| symbol
| bigint,
> = IsNever<T> extends false // Must be wider than `never`
? [T] extends [LiteralType] // Must be narrower than `LiteralType`
? [LiteralType] extends [T] // Cannot be wider than `LiteralType`
? false
: true
: false
: false;
> =
IsNever<T> extends false // Must be wider than `never`
? [T] extends [LiteralType] // Must be narrower than `LiteralType`
? [LiteralType] extends [T] // Cannot be wider than `LiteralType`
? false
: true
: false
: false;
type IsStringLiteral<T> = LiteralCheck<T, string>;

export interface RemoteClient {
Expand Down Expand Up @@ -586,20 +587,21 @@ export type Product<Props extends PlainObject = {}> = ArcjetRule<Props>[];
// Note: If a user doesn't provide the object literal to our primitives
// directly, we fallback to no required props. They can opt-in by adding the
// `as const` suffix to the characteristics array.
type PropsForCharacteristic<T> = IsStringLiteral<T> extends true
? T extends
| "ip.src"
| "http.host"
| "http.method"
| "http.request.uri.path"
| `http.request.headers["${string}"]`
| `http.request.cookie["${string}"]`
| `http.request.uri.args["${string}"]`
? {}
: T extends string
? Record<T, string | number | boolean>
: never
: {};
type PropsForCharacteristic<T> =
IsStringLiteral<T> extends true
? T extends
| "ip.src"
| "http.host"
| "http.method"
| "http.request.uri.path"
| `http.request.headers["${string}"]`
| `http.request.cookie["${string}"]`
| `http.request.uri.args["${string}"]`
? {}
: T extends string
? Record<T, string | number | boolean>
: never
: {};
// Rules can specify they require specific props on an ArcjetRequest
type PropsForRule<R> = R extends ArcjetRule<infer Props> ? Props : {};
// We theoretically support an arbitrary amount of rule flattening,
Expand Down
14 changes: 6 additions & 8 deletions arcjet/test/index.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,15 @@ import arcjet, {
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B
? 1
: 2
? true
: false;
type IsEqual<A, B> =
(<G>() => G extends A ? 1 : 2) extends <G>() => G extends B ? 1 : 2
? true
: false;

// Type testing utilities
type Assert<T extends true> = T;
type Props<P extends Primitive> = P extends Primitive<infer Props>
? Props
: never;
type Props<P extends Primitive> =
P extends Primitive<infer Props> ? Props : never;
type RequiredProps<P extends Primitive, E> = IsEqual<Props<P>, E>;

// Instances of Headers contain symbols that may be different depending
Expand Down

0 comments on commit 8249876

Please sign in to comment.