From f436ce5485a34bc83ae46a2738b729ad39f7c3a8 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Wed, 22 Nov 2023 10:33:14 +0100 Subject: [PATCH] cleanup legacy model --- .changeset/plenty-ligers-reply.md | 5 + packages/cli/_src/index.ts | 2 +- .../infra/_src/api/express/schema/routing.ts | 6 +- packages/prelude/_src/client/clientFor.ts | 2 +- packages/prelude/package.json | 10 -- packages/schema/_src/Model.ts | 111 +----------------- packages/schema/_src/REST.ts | 70 +---------- packages/schema/_src/internal/Methods.ts | 31 +++++ 8 files changed, 49 insertions(+), 188 deletions(-) create mode 100644 .changeset/plenty-ligers-reply.md create mode 100644 packages/schema/_src/internal/Methods.ts diff --git a/.changeset/plenty-ligers-reply.md b/.changeset/plenty-ligers-reply.md new file mode 100644 index 000000000..0281b1d84 --- /dev/null +++ b/.changeset/plenty-ligers-reply.md @@ -0,0 +1,5 @@ +--- +"@effect-app/schema": minor +--- + +cleanup legacy model diff --git a/packages/cli/_src/index.ts b/packages/cli/_src/index.ts index be763bf35..f0016545b 100644 --- a/packages/cli/_src/index.ts +++ b/packages/cli/_src/index.ts @@ -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) // ...pkg.name === "@effect-app/core" ? { diff --git a/packages/infra/_src/api/express/schema/routing.ts b/packages/infra/_src/api/express/schema/routing.ts index 9552ff634..dc15a5c05 100644 --- a/packages/infra/_src/api/express/schema/routing.ts +++ b/packages/infra/_src/api/express/schema/routing.ts @@ -16,7 +16,7 @@ export type Request< HeaderA, ReqA extends PathA & QueryA & BodyA > = MO.ReqResSchemed & { - method: Methods + method: Methods.Methods path: string Cookie?: MO.ReqRes, CookieA> Path?: MO.ReqRes, PathA> @@ -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 @@ -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, diff --git a/packages/prelude/_src/client/clientFor.ts b/packages/prelude/_src/client/clientFor.ts index 228ce3d12..fb5f426e0 100644 --- a/packages/prelude/_src/client/clientFor.ts +++ b/packages/prelude/_src/client/clientFor.ts @@ -21,7 +21,7 @@ export * from "./config.js" type Requests = Record> type AnyRequest = Omit, "method"> & { - method: Methods + method: Methods.Methods } & RequestSchemed const cache = new Map>() diff --git a/packages/prelude/package.json b/packages/prelude/package.json index cef549963..d976ec36e 100644 --- a/packages/prelude/package.json +++ b/packages/prelude/package.json @@ -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", diff --git a/packages/schema/_src/Model.ts b/packages/schema/_src/Model.ts index f31945c87..9b0133132 100644 --- a/packages/schema/_src/Model.ts +++ b/packages/schema/_src/Model.ts @@ -38,15 +38,6 @@ export interface Model extends > {} -export interface Model3 extends - Model2< - ParsedShape, - Self, - EncSchemaForModel>, - ParsedShape2 - > -{} - export interface ModelEnc< ParsedShape, Self extends MO.SchemaAny, @@ -65,18 +56,6 @@ export interface ModelEnc< > {} -export interface ModelEnc3 extends - MM< - Self, - EncSchemaForModel, - ParsedShape, - MO.ConstructorInputOf, - MEnc, - GetApiProps, - ParsedShape2 - > -{} - export interface Model2< M, Self extends MO.SchemaAny, @@ -141,36 +120,19 @@ export interface MM< readonly Arbitrary: MO.ArbitraryFor } +/** opaque model only on ParsedShape type param */ export function Model(__name?: string) { return (propsOrSchemas: ProvidedProps) => ModelSpecial(__name)(MO.props(propsOrSchemas)) } +/** opaque model on ParsedShape and Encoded type params */ export function ModelEnc(__name?: string) { return (propsOrSchemas: ProvidedProps) => ModelSpecialEnc(__name)(MO.props(propsOrSchemas)) } -export function Model3(__name?: string) { - return (propsOrSchemas: ProvidedProps) => - ModelSpecial3(__name)(MO.props(propsOrSchemas)) -} - -export function Model4(__name?: string) { - return (propsOrSchemas: ProvidedProps) => - ModelSpecial3(__name)(MO.props(propsOrSchemas)) -} - -export function ModelEnc3(__name?: string) { - return (propsOrSchemas: ProvidedProps) => - ModelSpecialEnc3(__name)(MO.props(propsOrSchemas)) -} - -export function ModelEnc4(__name?: string) { - return (propsOrSchemas: ProvidedProps) => - ModelSpecialEnc3(__name)(MO.props(propsOrSchemas)) -} - +/** fully opaque model on all type params */ export function MNModel( __name?: string ) { @@ -186,45 +148,8 @@ export function MNModel( > & PropsExtensions } - // MNModelSpecial(__name)(MO.props(props)) } -// export function MNModel3( -// __name?: string -// ) { -// return (props: ProvidedProps) => { -// const self = MO.props(props) -// return makeSpecial(__name, self) as MNModel< -// typeof self, -// ParsedShape, -// ConstructorInput, -// Encoded, -// Props, -// > & -// PropsExtensions -// } -// //MNModelSpecial(__name)(MO.props(props)) -// } - -// export function MNModel4( -// __name?: string -// ) { -// return (props: ProvidedProps) => { -// const self = MO.props(props) -// return makeSpecial(__name, self) as MNModel< -// typeof self, -// ParsedShape, -// ConstructorInput, -// Encoded, -// Props, -// ProvidedProps, -// {} -// > & -// PropsExtensions -// } -// //MNModelSpecial(__name)(MO.props(props)) -// } - export function fromModel(__name?: string) { return (props: Props) => ModelSpecial(__name)(fromProps(props)) } @@ -376,33 +301,6 @@ export function ModelSpecialEnc(__name?: string) { } } -export function ModelSpecial3(__name?: string) { - return ( - self: Self - ): Model3 & PropsExtensions> => { - return makeSpecial(__name, self) - } -} - -export function ModelSpecialEnc3(__name?: string) { - return ( - self: Self - ): - & ModelEnc3 - & PropsExtensions> => - { - return makeSpecial(__name, self) - } -} - -// export function MNModelSpecial(__name?: string) { -// return ( -// self: Self -// ): MNModel & PropsExtensions> => { -// return makeSpecial(__name, self) -// } -// } - function makeSpecial(__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 @@ -478,8 +376,5 @@ function makeSpecial(__name: any, self: Self): any { } return eq } - // static copy(this, that) { - // return fromFields(that, this) - // } } } diff --git a/packages/schema/_src/REST.ts b/packages/schema/_src/REST.ts index a95cffcc6..48f8b2633 100644 --- a/packages/schema/_src/REST.ts +++ b/packages/schema/_src/REST.ts @@ -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 -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() +export * as Methods from "./internal/Methods.js" + export const reqBrand = Symbol() // Actually GET + DELETE @@ -526,9 +497,6 @@ export type IfPathPropsProvided(path: Path, config?: Config) { return MethodReqProps2_("DELETE", path, config) } -export function DeleteSpecial(path: Path, config?: Config) { - return MethodReqProps2_("POST", path, config) -} /** * PUT http method. * Input parameters other than Path, will be sent as Body. @@ -537,9 +505,6 @@ export function DeleteSpecial(p export function Put(path: Path, config?: Config) { return MethodReqProps2_("PUT", path, config) } -export function PutSpecial(path: Path, config?: Config) { - return MethodReq_("PUT", path, config) -} /** * GET http method. @@ -549,9 +514,6 @@ export function PutSpecial(path export function Get(path: Path, config?: Config) { return MethodReqProps2_("GET", path, config) } -export function GetSpecial(path: Path, config?: Config) { - return MethodReq_("GET", path, config) -} /** * PATCH http method. * Input parameters other than Path, will be sent as Body. @@ -560,9 +522,6 @@ export function GetSpecial(path export function Patch(path: Path, config?: Config) { return MethodReqProps2_("PATCH", path, config) } -export function PatchSpecial(path: Path, config?: Config) { - return MethodReq_("PATCH", path, config) -} /** * POST http method. * Input parameters other than Path, will be sent as Body. @@ -571,16 +530,8 @@ export function PatchSpecial(pa export function Post(path: Path, config?: Config) { return MethodReqProps2_("POST", path, config) } -export function PostSpecial(path: Path, config?: Config) { - return MethodReq_("POST", path, config) -} -export function MethodReqProps2(method: Method) { - return (path: Path, config?: Config) => - MethodReqProps2_(method, path, config) -} - -export function MethodReqProps2_( +function MethodReqProps2_( method: Method, path: Path, config?: Config @@ -606,21 +557,10 @@ export function MethodReqProps2_( - method: Method, - path: Path, - config?: Config -) { - return (__name?: string) => (self: MO.SchemaProperties) => { - const req = Req(__name) - return req(method, path, self, config) - } -} - /** * Automatically picks path, query and body, based on Path params and Request Method. */ -export function Req(__name?: string) { +function Req(__name?: string) { function a< Path extends string, Method extends Methods, diff --git a/packages/schema/_src/internal/Methods.ts b/packages/schema/_src/internal/Methods.ts new file mode 100644 index 000000000..ea417b148 --- /dev/null +++ b/packages/schema/_src/internal/Methods.ts @@ -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