Skip to content

Commit

Permalink
Match changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Jan 7, 2025
1 parent 3d93774 commit f96c2f0
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 105 deletions.
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"dependencies": {
"@effect/platform": "^0.69.20",
"@effect/platform-node": "^0.64.22",
"@effect/schema": "^0.75.5",
"@geo-maps/countries-land-10km": "^0.6.0",
"@js-temporal/polyfill": "^0.4.4",
"@observablehq/framework": "^1.10.1",
Expand Down
15 changes: 7 additions & 8 deletions src/data/clubs.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Config, Effect, Record, Redacted } from 'effect'
import { NodeHttpClient, NodeTerminal } from '@effect/platform-node'
import { Config, Effect, Record, Redacted, Schema } from 'effect'

const Clubs = Schema.Array(
Schema.Struct({
Expand All @@ -13,6 +12,7 @@ const Clubs = Schema.Array(
const Output = Schema.Record({ key: Schema.String, value: Schema.String })

const program = Effect.gen(function* () {
const client = yield* HttpClient.HttpClient
const terminal = yield* Terminal.Terminal
const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false)

Expand All @@ -27,10 +27,9 @@ const program = Effect.gen(function* () {
Redacted.value(token),
)

const data = yield* HttpClient.fetchOk(request).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Clubs)),
Effect.scoped,
)
const data = yield* client
.execute(request)
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Clubs)), Effect.scoped)

const transformedData = Record.fromIterableWith(data, club => [club.id, club.name])

Expand All @@ -39,4 +38,4 @@ const program = Effect.gen(function* () {
yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer)))
await Effect.runPromise(program.pipe(Effect.provide(NodeHttpClient.layer), Effect.provide(NodeTerminal.layer)))
15 changes: 7 additions & 8 deletions src/data/openalex-domains.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Effect, Record } from 'effect'
import { NodeHttpClient, NodeTerminal } from '@effect/platform-node'
import { Effect, Record, Schema } from 'effect'
import { DomainIdFromUrlSchema, DomainIdSchema } from '../lib/OpenAlex.js'
import { UrlFromStringSchema } from '../lib/Url.js'

Expand All @@ -17,14 +16,14 @@ const Domains = Schema.Struct({
const DomainNames = Schema.Record({ key: DomainIdSchema, value: Schema.String })

const program = Effect.gen(function* () {
const client = yield* HttpClient.HttpClient
const terminal = yield* Terminal.Terminal

const request = HttpClientRequest.get('https://api.openalex.org/domains?per-page=200')

const data = yield* HttpClient.fetchOk(request).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Domains)),
Effect.scoped,
)
const data = yield* client
.execute(request)
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Domains)), Effect.scoped)

const transformedData = Record.fromIterableWith(data.results, domain => [domain.id, domain.display_name])

Expand All @@ -33,4 +32,4 @@ const program = Effect.gen(function* () {
yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer)))
await Effect.runPromise(program.pipe(Effect.provide(NodeHttpClient.layer), Effect.provide(NodeTerminal.layer)))
15 changes: 7 additions & 8 deletions src/data/openalex-fields.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Effect, Record } from 'effect'
import { NodeHttpClient, NodeTerminal } from '@effect/platform-node'
import { Effect, Record, Schema } from 'effect'
import { DomainIdFromUrlSchema, DomainIdSchema, FieldIdFromUrlSchema, FieldIdSchema } from '../lib/OpenAlex.js'
import { UrlFromStringSchema } from '../lib/Url.js'

Expand All @@ -23,14 +22,14 @@ const FieldNames = Schema.Record({
})

const program = Effect.gen(function* () {
const client = yield* HttpClient.HttpClient
const terminal = yield* Terminal.Terminal

const request = HttpClientRequest.get('https://api.openalex.org/fields?per-page=200')

const data = yield* HttpClient.fetchOk(request).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Fields)),
Effect.scoped,
)
const data = yield* client
.execute(request)
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Fields)), Effect.scoped)

const transformedData = Record.fromIterableWith(data.results, field => [
field.id,
Expand All @@ -42,4 +41,4 @@ const program = Effect.gen(function* () {
yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer)))
await Effect.runPromise(program.pipe(Effect.provide(NodeHttpClient.layer), Effect.provide(NodeTerminal.layer)))
22 changes: 10 additions & 12 deletions src/data/openalex-subfields.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Effect, Record } from 'effect'
import { NodeHttpClient, NodeTerminal } from '@effect/platform-node'
import { Effect, Record, Schema } from 'effect'
import { FieldIdFromUrlSchema, FieldIdSchema, SubfieldIdFromUrlSchema, SubfieldIdSchema } from '../lib/OpenAlex.js'
import { UrlFromStringSchema } from '../lib/Url.js'

Expand All @@ -23,21 +22,20 @@ const SubfieldNames = Schema.Record({
})

const program = Effect.gen(function* () {
const client = yield* HttpClient.HttpClient
const terminal = yield* Terminal.Terminal

const request1 = HttpClientRequest.get('https://api.openalex.org/subfields?per-page=200')

const data = yield* HttpClient.fetchOk(request1).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Subfields)),
Effect.scoped,
)
const data = yield* client
.execute(request1)
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Subfields)), Effect.scoped)

const request2 = HttpClientRequest.get('https://api.openalex.org/subfields?per-page=200&page=2')

const data2 = yield* HttpClient.fetchOk(request2).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Subfields)),
Effect.scoped,
)
const data2 = yield* client
.execute(request2)
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Subfields)), Effect.scoped)

const transformedData = Record.fromIterableWith([...data.results, ...data2.results], subfield => [
subfield.id,
Expand All @@ -49,4 +47,4 @@ const program = Effect.gen(function* () {
yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer)))
await Effect.runPromise(program.pipe(Effect.provide(NodeHttpClient.layer), Effect.provide(NodeTerminal.layer)))
3 changes: 1 addition & 2 deletions src/data/preprint-servers.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Effect } from 'effect'
import { Effect, Schema } from 'effect'
import * as PreprintServer from '../lib/PreprintServer.js'

const Output = Schema.Record({ key: Schema.String, value: Schema.String })
Expand Down
15 changes: 7 additions & 8 deletions src/data/requests.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Effect } from 'effect'
import { NodeHttpClient, NodeTerminal } from '@effect/platform-node'
import { Effect, Schema } from 'effect'
import * as Doi from '../lib/Doi.js'
import * as LanguageCode from '../lib/LanguageCode.js'
import { DomainIdSchema, FieldIdSchema, SubfieldIdSchema } from '../lib/OpenAlex.js'
Expand All @@ -21,18 +20,18 @@ const Requests = Schema.Array(
)

const program = Effect.gen(function* () {
const client = yield* HttpClient.HttpClient
const terminal = yield* Terminal.Terminal

const request = HttpClientRequest.get('https://coar-notify.prereview.org/requests')

const data = yield* HttpClient.fetchOk(request).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Requests)),
Effect.scoped,
)
const data = yield* client
.execute(request)
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Requests)), Effect.scoped)

const encoded = yield* Schema.encode(Schema.parseJson(Requests))(data)

yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer)))
await Effect.runPromise(program.pipe(Effect.provide(NodeHttpClient.layer), Effect.provide(NodeTerminal.layer)))
19 changes: 11 additions & 8 deletions src/data/reviews.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FileSystem, HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeFileSystem, NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Array, Config, Effect, Option, Redacted } from 'effect'
import { NodeFileSystem, NodeHttpClient, NodeTerminal } from '@effect/platform-node'
import { Array, Config, Effect, Option, Redacted, Schema } from 'effect'
import * as Doi from '../lib/Doi.js'
import * as LanguageCode from '../lib/LanguageCode.js'
import * as OrcidId from '../lib/OrcidId.js'
Expand Down Expand Up @@ -132,6 +131,7 @@ const getLegacyReviews = Effect.gen(function* () {
})

const getReviews = Effect.gen(function* () {
const client = yield* HttpClient.HttpClient
const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false)

if (sandbox) {
Expand All @@ -145,10 +145,7 @@ const getReviews = Effect.gen(function* () {
Redacted.value(token),
)

return yield* HttpClient.fetchOk(request).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Reviews)),
Effect.scoped,
)
return yield* client.execute(request).pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Reviews)), Effect.scoped)
})

const program = Effect.gen(function* () {
Expand All @@ -161,4 +158,10 @@ const program = Effect.gen(function* () {
yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer), Effect.provide(NodeFileSystem.layer)))
await Effect.runPromise(
program.pipe(
Effect.provide(NodeHttpClient.layer),
Effect.provide(NodeTerminal.layer),
Effect.provide(NodeFileSystem.layer),
),
)
15 changes: 7 additions & 8 deletions src/data/users.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Array, Config, Effect, Option, Redacted } from 'effect'
import { NodeHttpClient, NodeTerminal } from '@effect/platform-node'
import { Array, Config, Effect, Option, Redacted, Schema } from 'effect'
import * as Iso3166 from '../lib/Iso3166.js'
import * as OrcidId from '../lib/OrcidId.js'
import * as Temporal from '../lib/Temporal.js'
Expand All @@ -26,6 +25,7 @@ const Output = Schema.Array(
)

const program = Effect.gen(function* () {
const client = yield* HttpClient.HttpClient
const terminal = yield* Terminal.Terminal
const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false)

Expand All @@ -40,10 +40,9 @@ const program = Effect.gen(function* () {
Redacted.value(token),
)

const data = yield* HttpClient.fetchOk(request).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Users)),
Effect.scoped,
)
const data = yield* client
.execute(request)
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Users)), Effect.scoped)

const transformedData = Array.map(data, user => ({
...user,
Expand All @@ -55,4 +54,4 @@ const program = Effect.gen(function* () {
yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer)))
await Effect.runPromise(program.pipe(Effect.provide(NodeHttpClient.layer), Effect.provide(NodeTerminal.layer)))
15 changes: 7 additions & 8 deletions src/data/visitors-by-country.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Array, Config, Effect, Option, Redacted } from 'effect'
import { NodeHttpClient, NodeTerminal } from '@effect/platform-node'
import { Array, Config, Effect, Option, Redacted, Schema } from 'effect'
import * as Iso3166 from '../lib/Iso3166.js'
import * as Temporal from '../lib/Temporal.js'

Expand All @@ -22,6 +21,7 @@ const Output = Schema.Array(
)

const program = Effect.gen(function* () {
const client = yield* HttpClient.HttpClient
const terminal = yield* Terminal.Terminal
const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false)

Expand All @@ -44,10 +44,9 @@ const program = Effect.gen(function* () {
Redacted.value(token),
)

const data = yield* HttpClient.fetchOk(request).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Visitors)),
Effect.scoped,
)
const data = yield* client
.execute(request)
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Visitors)), Effect.scoped)

const transformedData = Array.map(data, visitors => ({
number: visitors.visits,
Expand All @@ -60,4 +59,4 @@ const program = Effect.gen(function* () {
yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer)))
await Effect.runPromise(program.pipe(Effect.provide(NodeHttpClient.layer), Effect.provide(NodeTerminal.layer)))
15 changes: 7 additions & 8 deletions src/data/visitors-by-referrer.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Array, Config, Effect, Redacted } from 'effect'
import { NodeHttpClient, NodeTerminal } from '@effect/platform-node'
import { Array, Config, Effect, Redacted, Schema } from 'effect'
import * as Temporal from '../lib/Temporal.js'
import * as Url from '../lib/Url.js'

Expand All @@ -22,6 +21,7 @@ const Output = Schema.Array(
)

const program = Effect.gen(function* () {
const client = yield* HttpClient.HttpClient
const terminal = yield* Terminal.Terminal
const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false)

Expand All @@ -44,10 +44,9 @@ const program = Effect.gen(function* () {
Redacted.value(token),
)

const data = yield* HttpClient.fetchOk(request).pipe(
Effect.andThen(HttpClientResponse.schemaBodyJson(Visitors)),
Effect.scoped,
)
const data = yield* client
.execute(request)
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(Visitors)), Effect.scoped)

const transformedData = Array.map(
Array.filter(data, visitors => visitors.visits > 0),
Expand All @@ -63,4 +62,4 @@ const program = Effect.gen(function* () {
yield* terminal.display(encoded)
})

await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer)))
await Effect.runPromise(program.pipe(Effect.provide(NodeHttpClient.layer), Effect.provide(NodeTerminal.layer)))
3 changes: 1 addition & 2 deletions src/lib/Doi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ParseResult, Schema } from '@effect/schema'
import { Brand, Either, Option, type Predicate, String, flow } from 'effect'
import { Brand, Either, Option, ParseResult, type Predicate, Schema, String, flow } from 'effect'

export type Doi = Brand.Branded<string, 'Doi'>

Expand Down
Loading

0 comments on commit f96c2f0

Please sign in to comment.