Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

effect 3 #7

Merged
merged 7 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
10 changes: 5 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
restore-keys: |
${{ runner.os }}-turbo-

- name: Setup Node.js 18.x
- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: 'yarn'

- name: Auth with npm registry
Expand All @@ -43,7 +43,7 @@ jobs:
diachronic:
npmAlwaysAuth: true
npmRegistryServer: "https://registry.npmjs.org"
npmAuthToken: ${{ secrets.NPM_TOKEN }}' >> ~/.yarnrc.yml
npmAuthToken: ${{ secrets.DIACHRONIC_NPM_TOKEN }}' >> ~/.yarnrc.yml

- name: Install 📦
run: yarn --immutable
Expand All @@ -62,5 +62,5 @@ jobs:
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.DIACHRONIC_NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.DIACHRONIC_NPM_TOKEN }}
30 changes: 15 additions & 15 deletions examples/toaster/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ import * as S from '@effect/schema/Schema'
import { makeWorkflow } from '@diachronic/migrate'

export const ToasterContext = S.partial(
S.struct({
numberOfToasts: S.number.pipe(S.int(), S.positive()),
pluggedIn: S.boolean,
toastTimeDuration: S.number,
S.Struct({
numberOfToasts: S.Number.pipe(S.int(), S.positive()),
pluggedIn: S.Boolean,
toastTimeDuration: S.Number,
})
)

export type ToasterContext = S.Schema.To<typeof ToasterContext>
export type ToasterContext = S.Schema.Type<typeof ToasterContext>

const Signals = {
'set-toast-time': S.struct({
type: S.literal('set-toast-time'),
payload: S.struct({ duration: S.number }),
'set-toast-time': S.Struct({
type: S.Literal('set-toast-time'),
payload: S.Struct({ duration: S.Number }),
}),
'plug-it-in': S.struct({
type: S.literal('plug-it-in'),
payload: S.undefined,
'plug-it-in': S.Struct({
type: S.Literal('plug-it-in'),
payload: S.Undefined,
}),
'unplug-it': S.struct({
type: S.literal('unplug-it'),
payload: S.undefined,
'unplug-it': S.Struct({
type: S.Literal('unplug-it'),
payload: S.Undefined,
}),
}

type ToasterEvents = {
[K in keyof typeof Signals]: {
type: K
payload: S.Schema.To<(typeof Signals)[K]>['payload']
payload: S.Schema.Type<(typeof Signals)[K]>['payload']
}
}[keyof typeof Signals]

Expand Down
30 changes: 15 additions & 15 deletions examples/toaster/src/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@ import * as S from '@effect/schema/Schema'
import { makeWorkflow, MigrationFnV1 } from '@diachronic/migrate'
import * as V1 from '.'

const PosInt = S.number.pipe(S.int(), S.positive())
const PosInt = S.Number.pipe(S.int(), S.positive())

export const ToasterContext = S.partial(
S.struct({
S.Struct({
numberOfToasts: PosInt,
powered: S.boolean,
toastTimeDuration: S.number,
powered: S.Boolean,
toastTimeDuration: S.Number,
})
)

export type ToasterContext = S.Schema.To<typeof ToasterContext>
export type ToasterContext = S.Schema.Type<typeof ToasterContext>

const Signals = {
'set-toast-time': S.struct({
type: S.literal('set-toast-time'),
payload: S.struct({ duration: S.number }),
'set-toast-time': S.Struct({
type: S.Literal('set-toast-time'),
payload: S.Struct({ duration: S.Number }),
}),
'power-on': S.struct({
type: S.literal('power-on'),
payload: S.struct({ volts: PosInt }),
'power-on': S.Struct({
type: S.Literal('power-on'),
payload: S.Struct({ volts: PosInt }),
}),
'power-off': S.struct({
type: S.literal('power-off'),
payload: S.undefined,
'power-off': S.Struct({
type: S.Literal('power-off'),
payload: S.Undefined,
}),
}

type ToasterEvents = {
[K in keyof typeof Signals]: {
type: K
payload: S.Schema.To<(typeof Signals)[K]>['payload']
payload: S.Schema.Type<(typeof Signals)[K]>['payload']
}
}[keyof typeof Signals]

Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,34 @@
"release": "yarn workspaces foreach --from '@diachronic/*' --no-private npm publish --tolerate-republish && yarn changeset tag"
},
"devDependencies": {
"@changesets/cli": "2.26.1",
"@types/node": "20",
"changeset": "^0.2.6",
"rimraf": "^5.0.1",
"ts-node": "10.9.1",
"turbo": "1.10.13",
"typescript": "5.2.2"
"typescript": "5.4.5"
},
"resolutions": {
"effect": "2.2.3",
"@effect/schema": "0.61.5",
"@effect-use/gcp-logging": "4.0.0",
"@effect-use/temporal-config": "3.0.0",
"@effect-use/temporal-client": "3.0.0",
"effect": "3.2.5",
"@effect/schema": "0.67.14",
"@effect-use/gcp-gcs": "4.0.0",
"@effect-use/gcp-logging": "5.0.0",
"@effect-use/http-client": "4.0.0",
"@effect-use/temporal-config": "4.0.0",
"@effect-use/temporal-client": "4.0.0",
"@temporalio/activity": "1.8.6",
"@temporalio/workflow": "1.8.6",
"@temporalio/worker": "1.8.6",
"@temporalio/client": "1.8.6",
"@temporalio/testing": "1.8.6",
"typescript": "5.4.5",
"fast-check": "^3.19",
"mqtt": "5.0.5",
"xstate": "5.0.0-beta.27"
},
"engines": {
"node": ">=20"
},
"publishConfig": {
"access": "restricted"
},
"repository": {
"directory": ".",
"type": "git",
Expand Down
38 changes: 19 additions & 19 deletions packages/activity/src/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export const addActivityDef = createExtension<ActivityConfig, Key>(key)
export class ActivityInputSchemaError extends S.TaggedError<ActivityInputSchemaError>()(
'ActivityInputSchemaError',
{
activityName: S.string,
message: S.optional(S.string, {
activityName: S.String,
message: S.optional(S.String, {
default: () => `Activity called with wrong arguments`,
}),
error: S.instanceOf(ParseResult.ParseError),
Expand All @@ -92,8 +92,8 @@ export class ActivityInputSchemaError extends S.TaggedError<ActivityInputSchemaE
export class ActivityOutputSchemaError extends S.TaggedError<ActivityOutputSchemaError>()(
'ActivityOutputSchemaError',
{
activityName: S.string,
message: S.optional(S.string, {
activityName: S.String,
message: S.optional(S.String, {
default: () => `Activity returned unexpected output`,
}),
error: S.instanceOf(ParseResult.ParseError),
Expand All @@ -117,7 +117,7 @@ export const toInvokeActivity =
(
activityInput: InputType<A>,
runtimeOptions?: ActivityOptions
): Effect.Effect<never, ErrorType<A>, OutputType<A>> =>
): Effect.Effect<OutputType<A>, ErrorType<A>> =>
pipe(
Effect.tryPromise(() =>
scheduleActivityFn(
Expand Down Expand Up @@ -148,7 +148,7 @@ export const toInvokeActivity =
return e // orig
}
})
) as Effect.Effect<never, ErrorType<A>, OutputType<A>>
) as Effect.Effect<OutputType<A>, ErrorType<A>>

export const implement = asEffect

Expand All @@ -165,12 +165,12 @@ export type MakeActivitiesAsync = <
Schema extends Record<string, ActivityDef>,
API extends {
[K in keyof Schema]: (
args: S.Schema.To<Schema[K]['input']>
args: S.Schema.Type<Schema[K]['input']>
// should any be unknown or something?
) => Effect.Effect<
any,
S.Schema.To<Schema[K]['error']>,
S.Schema.To<Schema[K]['output']>
S.Schema.Type<Schema[K]['output']>,
S.Schema.Type<Schema[K]['error']>,
any
>
}
>(
Expand All @@ -180,7 +180,7 @@ export type MakeActivitiesAsync = <
runtime: Runtime.Runtime<
Effect.Effect.Context<{ [K in keyof API]: ReturnType<API[K]> }[keyof API]>
>
close: Effect.Effect<never, never, void>
close: Effect.Effect<void>
}>
) => Promise<{
[K in keyof API]: (
Expand All @@ -192,11 +192,11 @@ export type MakeActivities = <
Schema extends Record<string, ActivityDef>,
API extends {
[K in keyof Schema]: (
args: S.Schema.To<Schema[K]['input']>
args: S.Schema.Type<Schema[K]['input']>
) => Effect.Effect<
any,
S.Schema.To<Schema[K]['error']>,
S.Schema.To<Schema[K]['output']>
S.Schema.Type<Schema[K]['output']>,
S.Schema.Type<Schema[K]['error']>,
any
>
}
>(
Expand Down Expand Up @@ -301,11 +301,11 @@ export const makeActivitiesAsync: MakeActivitiesAsync = async (
}

export const makeActivitiesRuntime = <E, A>(
layer: Layer.Layer<Scope.Scope, E, A> | Layer.Layer<never, E, A>,
logLayer: Layer.Layer<never, never, never> = TemporalLogLayer('Info')
layer: Layer.Layer<A, E, Scope.Scope> | Layer.Layer<A, E>,
logLayer: Layer.Layer<never> = TemporalLogLayer('Info')
): Promise<{
runtime: Runtime.Runtime<A>
close: Effect.Effect<never, never, void>
close: Effect.Effect<void>
}> =>
pipe(
Effect.Do,
Expand All @@ -315,7 +315,7 @@ export const makeActivitiesRuntime = <E, A>(
),
Effect.map(({ runtime, scope }) => ({
runtime,
close: Scope.close(scope, Exit.unit),
close: Scope.close(scope, Exit.void),
})),
Effect.tapErrorCause(Effect.logError),
Effect.runPromise
Expand Down
Loading
Loading