Compare commits
6 Commits
master
...
696976b52f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
696976b52f | ||
|
|
67bf12d7a9 | ||
|
|
a6ef4defe6 | ||
|
|
9ee50bfd19 | ||
|
|
7b3ed49369 | ||
|
|
9348178b0f |
@@ -71,6 +71,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@effect/schema": "^0.71.1",
|
||||
"@prisma/studio-server": "^0.502.0",
|
||||
"@types/jsonwebtoken": "^9.0.6",
|
||||
"bun-types": "^1.1.26",
|
||||
"effect": "^3.6.5",
|
||||
|
||||
29
src/Layers/PrismaStudioRoute.ts
Normal file
29
src/Layers/PrismaStudioRoute.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
// import { StudioServer } from "@prisma/studio-server"
|
||||
// import { Config, Effect, Layer } from "effect"
|
||||
|
||||
|
||||
// export const PrismaStudioRouteLive = ({
|
||||
// httpPort = Config.succeed(5555),
|
||||
// schemaPath = Config.succeed(""),
|
||||
// schemaText = Config.succeed(""),
|
||||
// }: {
|
||||
// httpPort: Config.Config<number>
|
||||
// schemaPath: Config.Config<string>
|
||||
// schemaText: Config.Config<string>
|
||||
// }) =>
|
||||
// Layer.effectDiscard(Effect.gen(function*() {
|
||||
|
||||
// return Effect.acquireRelease(
|
||||
// Effect.gen(function*() {
|
||||
// const server = new StudioServer({
|
||||
// port: yield* httpPort,
|
||||
// schemaPath: yield* schemaPath,
|
||||
// schemaText: yield* schemaText,
|
||||
// })
|
||||
// }),
|
||||
|
||||
// () => Effect.gen(function*() {
|
||||
|
||||
// }),
|
||||
// )
|
||||
// }))
|
||||
@@ -8,10 +8,10 @@ interface ObservableClassSelf {
|
||||
readonly fields: { readonly [K in keyof Schema.Struct.Fields]: Schema.Struct.Fields[K] }
|
||||
}
|
||||
|
||||
export const ObservableClass = <Self extends ObservableClassSelf>(
|
||||
self: Self,
|
||||
options?: Omit<CreateObservableOptions, "proxy">,
|
||||
) =>
|
||||
interface ObservableClassOptions extends Omit<CreateObservableOptions, "proxy"> {}
|
||||
|
||||
export const ObservableClass = (options?: ObservableClassOptions) =>
|
||||
<Self extends ObservableClassSelf>(self: Self) =>
|
||||
class Observable extends self {
|
||||
declare ["constructor"]: typeof Observable
|
||||
|
||||
|
||||
@@ -10,4 +10,4 @@ export const toJsonifiable = <
|
||||
jsonifiableSchema: Schema.Schema<JsonifiableA, JsonifiableI, JsonifiableR>
|
||||
) =>
|
||||
<A, R>(decodedSchema: Schema.Schema<A, JsonifiableA, R>) =>
|
||||
Schema.compose(jsonifiableSchema, decodedSchema)
|
||||
Schema.compose(jsonifiableSchema, decodedSchema, { strict: true })
|
||||
|
||||
20
src/tests.ts
20
src/tests.ts
@@ -1,5 +1,5 @@
|
||||
import { Schema as S } from "@effect/schema"
|
||||
import { reaction, runInAction } from "mobx"
|
||||
import { computed, makeObservable, reaction, runInAction } from "mobx"
|
||||
import type { Simplify } from "type-fest"
|
||||
import { MutableTaggedClass, toJsonifiable } from "./Schema"
|
||||
import { ObservableClass } from "./Schema/MobX"
|
||||
@@ -18,12 +18,24 @@ type TestB = {
|
||||
type Merged = Simplify<ExtendAll<[TestA, TestB]>>
|
||||
|
||||
|
||||
class User extends MutableTaggedClass<User>()("User", {
|
||||
|
||||
const UserSchema = MutableTaggedClass<User>()("User", {
|
||||
id: S.BigIntFromSelf,
|
||||
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
|
||||
}).pipe(
|
||||
ObservableClass
|
||||
) {}
|
||||
ObservableClass()
|
||||
)
|
||||
|
||||
class User extends UserSchema {
|
||||
constructor(...args: ConstructorParameters<typeof UserSchema>) {
|
||||
super(...args)
|
||||
makeObservable(this, { idAsString: computed })
|
||||
}
|
||||
|
||||
get idAsString() {
|
||||
return this.id.toString()
|
||||
}
|
||||
}
|
||||
|
||||
const JsonifiableUser = User.pipe(
|
||||
toJsonifiable(S.Struct({
|
||||
|
||||
Reference in New Issue
Block a user