This commit is contained in:
@@ -1,14 +1,37 @@
|
||||
import { Array, Predicate, Record, Schema } from "effect"
|
||||
import { Array, Predicate, Record, Schema, Tuple } from "effect"
|
||||
|
||||
|
||||
export const isStruct = (u: unknown): u is Schema.Struct<any> => (
|
||||
export const isTupleSchema = (u: unknown): u is Schema.Tuple<any> => (
|
||||
Schema.isSchema(u) &&
|
||||
Predicate.hasProperty(u, "elements") && Array.isArray(u.elements) &&
|
||||
Predicate.hasProperty(u, "rest") && Array.isArray(u.rest)
|
||||
)
|
||||
|
||||
export const isArraySchema = (u: unknown): u is Schema.Array$<any> => (
|
||||
Schema.isSchema(u) &&
|
||||
Predicate.hasProperty(u, "elements") && Array.isArray(u.elements) && Array.isEmptyArray(u.elements) &&
|
||||
Predicate.hasProperty(u, "rest") && Array.isArray(u.rest) && Tuple.isTupleOf(u.rest, 1) &&
|
||||
Predicate.hasProperty(u, "value")
|
||||
)
|
||||
|
||||
export const isStructSchema = (u: unknown): u is Schema.Struct<any> => (
|
||||
Schema.isSchema(u) &&
|
||||
Predicate.hasProperty(u, "fields") && Predicate.isObject(u.fields) &&
|
||||
Predicate.hasProperty(u, "record") && Array.isArray(u.record) && Array.isEmptyArray(u.record)
|
||||
Predicate.hasProperty(u, "records") && Array.isArray(u.records) && Array.isEmptyArray(u.records)
|
||||
)
|
||||
|
||||
export const isRecord = (u: unknown): u is Schema.Record$<any, any> => (
|
||||
export const isRecordSchema = (u: unknown): u is Schema.Record$<any, any> => (
|
||||
Schema.isSchema(u) &&
|
||||
Predicate.hasProperty(u, "fields") && Predicate.isObject(u.fields) && Record.isEmptyRecord(u.fields) &&
|
||||
Predicate.hasProperty(u, "record") && Array.isArray(u.record)
|
||||
Predicate.hasProperty(u, "records") && Array.isArray(u.records) &&
|
||||
Predicate.hasProperty(u, "key") &&
|
||||
Predicate.hasProperty(u, "value")
|
||||
)
|
||||
|
||||
|
||||
const myTuple = Schema.Tuple(Schema.String)
|
||||
const myArray = Schema.Array(Schema.String)
|
||||
const myStruct = Schema.Struct({})
|
||||
const myRecord = Schema.Record({ key: Schema.String, value: Schema.String })
|
||||
|
||||
console.log(isArraySchema(myTuple))
|
||||
|
||||
Reference in New Issue
Block a user