Merge commit '36c66dd290d3ce6eb1ccd310d0c658d4a32bb8eb' as 'repos/effect'
This commit is contained in:
3
repos/effect/packages/tools/bundle/fixtures/basic.ts
Normal file
3
repos/effect/packages/tools/bundle/fixtures/basic.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
|
||||
Effect.succeed(123).pipe(Effect.runFork)
|
||||
25
repos/effect/packages/tools/bundle/fixtures/batching.ts
Normal file
25
repos/effect/packages/tools/bundle/fixtures/batching.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as Array from "effect/Array"
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Exit from "effect/Exit"
|
||||
import * as Request from "effect/Request"
|
||||
import * as Resolver from "effect/RequestResolver"
|
||||
|
||||
class GetNameById extends Request.TaggedClass("GetNameById")<{
|
||||
readonly id: number
|
||||
}, string> {}
|
||||
|
||||
const UserResolver = Resolver.make<GetNameById>((entries) =>
|
||||
Effect.sync(() => {
|
||||
for (const entry of entries) {
|
||||
entry.completeUnsafe(Exit.succeed(`User ${entry.request.id}`))
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
const effect = Effect.forEach(
|
||||
Array.range(1, 100_000),
|
||||
(id) => Effect.request(new GetNameById({ id }), UserResolver),
|
||||
{ concurrency: "unbounded" }
|
||||
)
|
||||
|
||||
Effect.runFork(effect)
|
||||
5
repos/effect/packages/tools/bundle/fixtures/brand.ts
Normal file
5
repos/effect/packages/tools/bundle/fixtures/brand.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as Brand from "effect/Brand"
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
type Positive = number & Brand.Brand<"Positive">
|
||||
const Positive = Brand.check<Positive>(Schema.isGreaterThan(0))
|
||||
10
repos/effect/packages/tools/bundle/fixtures/cache.ts
Normal file
10
repos/effect/packages/tools/bundle/fixtures/cache.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import * as Cache from "effect/Cache"
|
||||
import * as Effect from "effect/Effect"
|
||||
|
||||
Cache.make({
|
||||
capacity: 1024,
|
||||
lookup: (key: string) => Effect.succeed(key)
|
||||
}).pipe(
|
||||
Effect.flatMap(Cache.get("1")),
|
||||
Effect.runFork
|
||||
)
|
||||
13
repos/effect/packages/tools/bundle/fixtures/config.ts
Normal file
13
repos/effect/packages/tools/bundle/fixtures/config.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import * as Config from "effect/Config"
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
API_KEY: Schema.String,
|
||||
PORT: Schema.Int,
|
||||
LOCALHOST: Schema.URL
|
||||
})
|
||||
|
||||
const config = Config.schema(schema)
|
||||
|
||||
Effect.runFork(config)
|
||||
9
repos/effect/packages/tools/bundle/fixtures/differ.ts
Normal file
9
repos/effect/packages/tools/bundle/fixtures/differ.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
id: Schema.Number,
|
||||
name: Schema.String,
|
||||
price: Schema.Number
|
||||
})
|
||||
|
||||
Schema.toDifferJsonPatch(schema)
|
||||
12
repos/effect/packages/tools/bundle/fixtures/http-client.ts
Normal file
12
repos/effect/packages/tools/bundle/fixtures/http-client.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient"
|
||||
import * as HttpClient from "effect/unstable/http/HttpClient"
|
||||
|
||||
Effect.gen(function*() {
|
||||
const client = yield* HttpClient.HttpClient
|
||||
const res = yield* client.get("https://jsonplaceholder.typicode.com/posts/1")
|
||||
yield* res.json
|
||||
}).pipe(
|
||||
Effect.provide(FetchHttpClient.layer),
|
||||
Effect.runPromise
|
||||
)
|
||||
5
repos/effect/packages/tools/bundle/fixtures/logger.ts
Normal file
5
repos/effect/packages/tools/bundle/fixtures/logger.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
|
||||
Effect.log("hello").pipe(
|
||||
Effect.runFork
|
||||
)
|
||||
13
repos/effect/packages/tools/bundle/fixtures/metric.ts
Normal file
13
repos/effect/packages/tools/bundle/fixtures/metric.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Metric from "effect/Metric"
|
||||
|
||||
const program = Effect.gen(function*() {
|
||||
yield* Effect.succeed(1).pipe(
|
||||
Effect.forkChild({ startImmediately: true })
|
||||
)
|
||||
})
|
||||
|
||||
program.pipe(
|
||||
Metric.enableRuntimeMetrics,
|
||||
Effect.runFork
|
||||
)
|
||||
6
repos/effect/packages/tools/bundle/fixtures/optic.ts
Normal file
6
repos/effect/packages/tools/bundle/fixtures/optic.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import * as Optic from "effect/Optic"
|
||||
|
||||
type S = { readonly a: number }
|
||||
const optic = Optic.id<S>().key("a")
|
||||
|
||||
optic.getResult({ a: 1 })
|
||||
22
repos/effect/packages/tools/bundle/fixtures/pubsub.ts
Normal file
22
repos/effect/packages/tools/bundle/fixtures/pubsub.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as PubSub from "effect/PubSub"
|
||||
|
||||
const program = Effect.gen(function*() {
|
||||
const pubsub = yield* PubSub.unbounded<number>()
|
||||
|
||||
yield* Effect.gen(function*() {
|
||||
const subscription = yield* PubSub.subscribe(pubsub)
|
||||
while (true) {
|
||||
const element = yield* PubSub.take(subscription)
|
||||
console.log(element)
|
||||
}
|
||||
}).pipe(Effect.forkScoped({ startImmediately: true }))
|
||||
|
||||
yield* PubSub.publishAll(pubsub, [1, 2])
|
||||
yield* PubSub.publishAll(pubsub, [3, 4]).pipe(Effect.delay("100 millis"), Effect.forkScoped)
|
||||
yield* PubSub.publishAll(pubsub, [5, 6, 7, 8]).pipe(Effect.delay("200 millis"), Effect.forkScoped)
|
||||
|
||||
yield* Effect.sleep("500 millis")
|
||||
})
|
||||
|
||||
Effect.runFork(Effect.scoped(program))
|
||||
18
repos/effect/packages/tools/bundle/fixtures/queue.ts
Normal file
18
repos/effect/packages/tools/bundle/fixtures/queue.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Queue from "effect/Queue"
|
||||
|
||||
const program = Effect.gen(function*() {
|
||||
const queue = yield* Queue.make<number>()
|
||||
|
||||
yield* Effect.gen(function*() {
|
||||
yield* Queue.takeN(queue, 3)
|
||||
}).pipe(Effect.forever, Effect.forkScoped)
|
||||
|
||||
yield* Queue.offerAll(queue, [1, 2])
|
||||
yield* Queue.offerAll(queue, [3, 4]).pipe(Effect.delay("100 millis"), Effect.forkScoped)
|
||||
yield* Queue.offerAll(queue, [5, 6, 7, 8]).pipe(Effect.delay("200 millis"), Effect.forkScoped)
|
||||
|
||||
yield* Effect.sleep("500 millis")
|
||||
})
|
||||
|
||||
Effect.runFork(Effect.scoped(program))
|
||||
9
repos/effect/packages/tools/bundle/fixtures/schedule.ts
Normal file
9
repos/effect/packages/tools/bundle/fixtures/schedule.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Schedule from "effect/Schedule"
|
||||
|
||||
Effect.succeed(123).pipe(
|
||||
Effect.repeat({
|
||||
schedule: Schedule.spaced("100 millis")
|
||||
}),
|
||||
Effect.runFork
|
||||
)
|
||||
12
repos/effect/packages/tools/bundle/fixtures/schema-class.ts
Normal file
12
repos/effect/packages/tools/bundle/fixtures/schema-class.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
class A extends Schema.Class<A>("A")({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
}) {}
|
||||
|
||||
Schema.decodeUnknownEffect(A)({ a: "a", b: 1, c: ["c"] }).pipe(
|
||||
Effect.runFork
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as SchemaRepresentation from "effect/SchemaRepresentation"
|
||||
|
||||
const doc = SchemaRepresentation.fromJsonSchemaDocument({
|
||||
"dialect": "draft-2020-12",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {}
|
||||
})
|
||||
|
||||
console.dir(doc, { depth: null })
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as Schema from "effect/Schema"
|
||||
import * as SchemaRepresentation from "effect/SchemaRepresentation"
|
||||
|
||||
const schema = Schema.toCodecJson(Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
}))
|
||||
|
||||
const json = Schema.encodeSync(SchemaRepresentation.DocumentFromJson)(
|
||||
SchemaRepresentation.fromAST(schema.ast)
|
||||
)
|
||||
|
||||
SchemaRepresentation.toSchema(
|
||||
Schema.decodeSync(SchemaRepresentation.DocumentFromJson)(JSON.parse(JSON.stringify(json)))
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as Duration from "effect/Duration"
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Schema from "effect/Schema"
|
||||
import * as SchemaTransformation from "effect/SchemaTransformation"
|
||||
|
||||
const schema = Schema.String.pipe(Schema.decodeTo(
|
||||
Schema.String,
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (s) =>
|
||||
Effect.gen(function*() {
|
||||
yield* Effect.clockWith((clock) => clock.sleep(Duration.millis(300)))
|
||||
return s
|
||||
}),
|
||||
encode: (_) => Effect.succeed(_)
|
||||
})
|
||||
))
|
||||
|
||||
Schema.decodeUnknownEffect(schema)({ a: "a", b: 1, c: ["c"] }).pipe(
|
||||
Effect.runFork
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.String
|
||||
|
||||
Schema.decodeUnknownEffect(schema)("a").pipe(
|
||||
Effect.runFork
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.TemplateLiteral(["a", Schema.String])
|
||||
|
||||
Schema.decodeUnknownEffect(schema)("abc").pipe(
|
||||
Effect.runFork
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
})
|
||||
|
||||
Schema.toArbitraryLazy(schema)
|
||||
@@ -0,0 +1,12 @@
|
||||
import * as Schema from "effect/Schema"
|
||||
import * as SchemaRepresentation from "effect/SchemaRepresentation"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
})
|
||||
|
||||
const representation = Schema.toRepresentation(schema)
|
||||
|
||||
SchemaRepresentation.toCodeDocument(SchemaRepresentation.toMultiDocument(representation))
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
})
|
||||
|
||||
Schema.toCodecJson(schema)
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
})
|
||||
|
||||
Schema.toEquivalence(schema)
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
})
|
||||
|
||||
Schema.toFormatter(schema)
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
})
|
||||
|
||||
Schema.toJsonSchemaDocument(schema)
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
})
|
||||
|
||||
Schema.toRepresentation(schema)
|
||||
12
repos/effect/packages/tools/bundle/fixtures/schema.ts
Normal file
12
repos/effect/packages/tools/bundle/fixtures/schema.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Schema from "effect/Schema"
|
||||
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.optional(Schema.FiniteFromString),
|
||||
c: Schema.Array(Schema.String)
|
||||
})
|
||||
|
||||
Schema.decodeUnknownEffect(schema)({ a: "a", b: 1, c: ["c"] }).pipe(
|
||||
Effect.runFork
|
||||
)
|
||||
21
repos/effect/packages/tools/bundle/fixtures/stm.ts
Normal file
21
repos/effect/packages/tools/bundle/fixtures/stm.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as TxRef from "effect/TxRef"
|
||||
|
||||
const program = Effect.gen(function*() {
|
||||
const ref = yield* TxRef.make(0)
|
||||
|
||||
yield* Effect.forkChild(Effect.forever(
|
||||
TxRef.update(ref, (n) => n + 1).pipe(Effect.delay("100 millis"))
|
||||
))
|
||||
|
||||
yield* Effect.tx(Effect.gen(function*() {
|
||||
const value = yield* TxRef.get(ref)
|
||||
if (value < 10) {
|
||||
yield* Effect.log(`retry due to value: ${value}`)
|
||||
return yield* Effect.txRetry
|
||||
}
|
||||
yield* Effect.log(`transaction done with value: ${value}`)
|
||||
}))
|
||||
})
|
||||
|
||||
Effect.runPromise(program).catch(console.error)
|
||||
7
repos/effect/packages/tools/bundle/fixtures/stream.ts
Normal file
7
repos/effect/packages/tools/bundle/fixtures/stream.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import * as Effect from "effect/Effect"
|
||||
import * as Stream from "effect/Stream"
|
||||
|
||||
Stream.range(1, 100_000).pipe(
|
||||
Stream.runDrain,
|
||||
Effect.runSync
|
||||
)
|
||||
Reference in New Issue
Block a user