Skip to content

Commit

Permalink
cleanup legacy model
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Nov 22, 2023
1 parent 85e2e6c commit f436ce5
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 188 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-ligers-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-app/schema": minor
---

cleanup legacy model
2 changes: 1 addition & 1 deletion packages/cli/_src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function packagejson(p: string, levels = 0) {
...Object
.keys(t)
.reduce((prev, cur) => {
if (cur !== "./index") prev[cur] = t[cur]
if (cur !== "./index" && !cur.includes("/internal/")) prev[cur] = t[cur]
return prev
}, {} as Record<string, unknown>)
// ...pkg.name === "@effect-app/core" ? {
Expand Down
6 changes: 3 additions & 3 deletions packages/infra/_src/api/express/schema/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type Request<
HeaderA,
ReqA extends PathA & QueryA & BodyA
> = MO.ReqResSchemed<unknown, ReqA> & {
method: Methods
method: Methods.Methods
path: string
Cookie?: MO.ReqRes<Record<string, string>, CookieA>
Path?: MO.ReqRes<Record<string, string>, PathA>
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface RouteDescriptor<
HeaderA,
ReqA extends PathA & QueryA & BodyA,
ResA,
METHOD extends Methods = Methods
METHOD extends Methods.Methods = Methods.Methods
> {
_tag: "Schema"
path: string
Expand Down Expand Up @@ -91,7 +91,7 @@ export function makeRouteDescriptor<
HeaderA,
ReqA extends PathA & QueryA & BodyA,
ResA = void,
METHOD extends Methods = Methods
METHOD extends Methods.Methods = Methods.Methods
>(
path: string,
method: METHOD,
Expand Down
2 changes: 1 addition & 1 deletion packages/prelude/_src/client/clientFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export * from "./config.js"

type Requests = Record<string, Record<string, any>>
type AnyRequest = Omit<QueryRequest<any, any, any, any, any>, "method"> & {
method: Methods
method: Methods.Methods
} & RequestSchemed<any, any>

const cache = new Map<any, Client<any>>()
Expand Down
10 changes: 0 additions & 10 deletions packages/prelude/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@
"default": "./_cjs/Config/SecretURL.cjs"
}
},
"./Config/internal/configSecretURL": {
"import": {
"types": "./dist/Config/internal/configSecretURL.d.ts",
"default": "./dist/Config/internal/configSecretURL.js"
},
"require": {
"types": "./dist/Config/internal/configSecretURL.d.ts",
"default": "./_cjs/Config/internal/configSecretURL.cjs"
}
},
"./Function": {
"import": {
"types": "./dist/Function.d.ts",
Expand Down
111 changes: 3 additions & 108 deletions packages/schema/_src/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ export interface Model<ParsedShape, Self extends MO.SchemaAny> extends
>
{}

export interface Model3<ParsedShape, ParsedShape2, Self extends MO.SchemaAny> extends
Model2<
ParsedShape,
Self,
EncSchemaForModel<ParsedShape, Self, MO.EncodedOf<Self>>,
ParsedShape2
>
{}

export interface ModelEnc<
ParsedShape,
Self extends MO.SchemaAny,
Expand All @@ -65,18 +56,6 @@ export interface ModelEnc<
>
{}

export interface ModelEnc3<ParsedShape, ParsedShape2, Self extends MO.SchemaAny, MEnc> extends
MM<
Self,
EncSchemaForModel<ParsedShape, Self, MEnc>,
ParsedShape,
MO.ConstructorInputOf<Self>,
MEnc,
GetApiProps<Self>,
ParsedShape2
>
{}

export interface Model2<
M,
Self extends MO.SchemaAny,
Expand Down Expand Up @@ -141,36 +120,19 @@ export interface MM<
readonly Arbitrary: MO.ArbitraryFor<SelfM>
}

/** opaque model only on ParsedShape type param */
export function Model<ParsedShape>(__name?: string) {
return <ProvidedProps extends MO.PropertyOrSchemaRecord = {}>(propsOrSchemas: ProvidedProps) =>
ModelSpecial<ParsedShape>(__name)(MO.props(propsOrSchemas))
}

/** opaque model on ParsedShape and Encoded type params */
export function ModelEnc<ParsedShape, Encoded>(__name?: string) {
return <ProvidedProps extends MO.PropertyOrSchemaRecord = {}>(propsOrSchemas: ProvidedProps) =>
ModelSpecialEnc<ParsedShape, Encoded>(__name)(MO.props(propsOrSchemas))
}

export function Model3<ParsedShape, ParsedShape2>(__name?: string) {
return <ProvidedProps extends MO.PropertyOrSchemaRecord = {}>(propsOrSchemas: ProvidedProps) =>
ModelSpecial3<ParsedShape, ParsedShape2>(__name)(MO.props(propsOrSchemas))
}

export function Model4<ParsedShape>(__name?: string) {
return <ProvidedProps extends MO.PropertyOrSchemaRecord = {}>(propsOrSchemas: ProvidedProps) =>
ModelSpecial3<ParsedShape, {}>(__name)(MO.props(propsOrSchemas))
}

export function ModelEnc3<ParsedShape, ParsedShape2, Encoded>(__name?: string) {
return <ProvidedProps extends MO.PropertyOrSchemaRecord = {}>(propsOrSchemas: ProvidedProps) =>
ModelSpecialEnc3<ParsedShape, ParsedShape2, Encoded>(__name)(MO.props(propsOrSchemas))
}

export function ModelEnc4<ParsedShape, Encoded>(__name?: string) {
return <ProvidedProps extends MO.PropertyOrSchemaRecord = {}>(propsOrSchemas: ProvidedProps) =>
ModelSpecialEnc3<ParsedShape, {}, Encoded>(__name)(MO.props(propsOrSchemas))
}

/** fully opaque model on all type params */
export function MNModel<ParsedShape, ConstructorInput, Encoded, Props>(
__name?: string
) {
Expand All @@ -186,45 +148,8 @@ export function MNModel<ParsedShape, ConstructorInput, Encoded, Props>(
>
& PropsExtensions<Props>
}
// MNModelSpecial<M, MEnc>(__name)(MO.props(props))
}

// export function MNModel3<ParsedShape, ParsedShape2, ConstructorInput, Encoded, Props>(
// __name?: string
// ) {
// return <ProvidedProps extends MO.PropertyRecord = {}>(props: ProvidedProps) => {
// const self = MO.props(props)
// return makeSpecial(__name, self) as MNModel<
// typeof self,
// ParsedShape,
// ConstructorInput,
// Encoded,
// Props,
// > &
// PropsExtensions<Props>
// }
// //MNModelSpecial<M, MEnc>(__name)(MO.props(props))
// }

// export function MNModel4<ParsedShape, ConstructorInput, Encoded, Props>(
// __name?: string
// ) {
// return <ProvidedProps extends MO.PropertyRecord = {}>(props: ProvidedProps) => {
// const self = MO.props(props)
// return makeSpecial(__name, self) as MNModel<
// typeof self,
// ParsedShape,
// ConstructorInput,
// Encoded,
// Props,
// ProvidedProps,
// {}
// > &
// PropsExtensions<Props>
// }
// //MNModelSpecial<M, MEnc>(__name)(MO.props(props))
// }

export function fromModel<ParsedShape>(__name?: string) {
return <Props extends FromPropertyRecord = {}>(props: Props) => ModelSpecial<ParsedShape>(__name)(fromProps(props))
}
Expand Down Expand Up @@ -376,33 +301,6 @@ export function ModelSpecialEnc<ParsedShape, Encoded>(__name?: string) {
}
}

export function ModelSpecial3<ParsedShape, ParsedShape2>(__name?: string) {
return <Self extends MO.SchemaAny & { Api: { props: any } }>(
self: Self
): Model3<ParsedShape, ParsedShape2, Self> & PropsExtensions<GetModelProps<Self>> => {
return makeSpecial(__name, self)
}
}

export function ModelSpecialEnc3<ParsedShape, ParsedShape2, Encoded>(__name?: string) {
return <Self extends MO.SchemaAny & { Api: { props: any } }>(
self: Self
):
& ModelEnc3<ParsedShape, ParsedShape2, Self, Encoded>
& PropsExtensions<GetModelProps<Self>> =>
{
return makeSpecial(__name, self)
}
}

// export function MNModelSpecial<ParsedShape, MEnc>(__name?: string) {
// return <Self extends MO.SchemaAny & { Api: { props: any } }>(
// self: Self
// ): MNModel<M, Self, MEnc> & PropsExtensions<GetModelProps<Self>> => {
// return makeSpecial(__name, self)
// }
// }

function makeSpecial<Self extends MO.SchemaAny>(__name: any, self: Self): any {
const schema = __name ? self >= MO.named(__name) : self // TODO ?? "Model(Anonymous)", but atm auto deriving openapiRef from this.
const of_ = MO.Constructor.for(schema) >= unsafe
Expand Down Expand Up @@ -478,8 +376,5 @@ function makeSpecial<Self extends MO.SchemaAny>(__name: any, self: Self): any {
}
return eq
}
// static copy(this, that) {
// return fromFields(that, this)
// }
}
}
70 changes: 5 additions & 65 deletions packages/schema/_src/REST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,16 @@ import { Path } from "path-parser"
import { Void } from "./_api.js"
import * as MO from "./_schema.js"
import { schemaField } from "./_schema.js"
import type { Methods, ReadMethods, WriteMethods } from "./internal/Methods.js"
import type { AnyRecord, AnyRecordSchema, GetModelProps, Model, PropsExtensions, StringRecord } from "./Model.js"
import { ModelSpecial, setSchema } from "./Model.js"

export type StringRecordSchema = MO.Schema<unknown, any, any, StringRecord, any>

export const GET = "GET"
export type GET = typeof GET

export const POST = "POST"
export type POST = typeof POST

export const PUT = "PUT"
export type PUT = typeof PUT

export const PATCH = "PATCH"
export type PATCH = typeof PATCH

export const DELETE = "DELETE"
export type DELETE = typeof DELETE

export const UPDATE = "UPDATE"
export type UPDATE = typeof UPDATE

export const OPTIONS = "OPTIONS"
export type OPTIONS = typeof OPTIONS

export const HEAD = "HEAD"
export type HEAD = typeof HEAD

export const TRACE = "TRACE"
export type TRACE = typeof TRACE

export type ReadMethods = GET
export type WriteMethods = POST | PUT | PATCH | DELETE

export type Methods = ReadMethods | WriteMethods

const RequestTag = Tag<never, never>()

export * as Methods from "./internal/Methods.js"

export const reqBrand = Symbol()

// Actually GET + DELETE
Expand Down Expand Up @@ -526,9 +497,6 @@ export type IfPathPropsProvided<Path extends string, B extends MO.PropertyRecord
export function Delete<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReqProps2_("DELETE", path, config)
}
export function DeleteSpecial<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReqProps2_("POST", path, config)
}
/**
* PUT http method.
* Input parameters other than Path, will be sent as Body.
Expand All @@ -537,9 +505,6 @@ export function DeleteSpecial<Path extends string, Config extends object = {}>(p
export function Put<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReqProps2_("PUT", path, config)
}
export function PutSpecial<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReq_("PUT", path, config)
}

/**
* GET http method.
Expand All @@ -549,9 +514,6 @@ export function PutSpecial<Path extends string, Config extends object = {}>(path
export function Get<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReqProps2_("GET", path, config)
}
export function GetSpecial<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReq_("GET", path, config)
}
/**
* PATCH http method.
* Input parameters other than Path, will be sent as Body.
Expand All @@ -560,9 +522,6 @@ export function GetSpecial<Path extends string, Config extends object = {}>(path
export function Patch<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReqProps2_("PATCH", path, config)
}
export function PatchSpecial<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReq_("PATCH", path, config)
}
/**
* POST http method.
* Input parameters other than Path, will be sent as Body.
Expand All @@ -571,16 +530,8 @@ export function PatchSpecial<Path extends string, Config extends object = {}>(pa
export function Post<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReqProps2_("POST", path, config)
}
export function PostSpecial<Path extends string, Config extends object = {}>(path: Path, config?: Config) {
return MethodReq_("POST", path, config)
}

export function MethodReqProps2<Method extends Methods>(method: Method) {
return <Path extends string, Config extends object = {}>(path: Path, config?: Config) =>
MethodReqProps2_(method, path, config)
}

export function MethodReqProps2_<Method extends Methods, Path extends string, Config extends object = {}>(
function MethodReqProps2_<Method extends Methods, Path extends string, Config extends object = {}>(
method: Method,
path: Path,
config?: Config
Expand All @@ -606,21 +557,10 @@ export function MethodReqProps2_<Method extends Methods, Path extends string, Co
}
}

export function MethodReq_<Method extends Methods, Path extends string, Config extends object = {}>(
method: Method,
path: Path,
config?: Config
) {
return <M>(__name?: string) => <Props extends MO.PropertyRecord>(self: MO.SchemaProperties<Props>) => {
const req = Req<M>(__name)
return req(method, path, self, config)
}
}

/**
* Automatically picks path, query and body, based on Path params and Request Method.
*/
export function Req<M>(__name?: string) {
function Req<M>(__name?: string) {
function a<
Path extends string,
Method extends Methods,
Expand Down
31 changes: 31 additions & 0 deletions packages/schema/_src/internal/Methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const GET = "GET"
export type GET = typeof GET

export const POST = "POST"
export type POST = typeof POST

export const PUT = "PUT"
export type PUT = typeof PUT

export const PATCH = "PATCH"
export type PATCH = typeof PATCH

export const DELETE = "DELETE"
export type DELETE = typeof DELETE

export const UPDATE = "UPDATE"
export type UPDATE = typeof UPDATE

export const OPTIONS = "OPTIONS"
export type OPTIONS = typeof OPTIONS

export const HEAD = "HEAD"
export type HEAD = typeof HEAD

export const TRACE = "TRACE"
export type TRACE = typeof TRACE

export type ReadMethods = GET
export type WriteMethods = POST | PUT | PATCH | DELETE

export type Methods = ReadMethods | WriteMethods

0 comments on commit f436ce5

Please sign in to comment.