@gjermundgaraba/effect-actions 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -41
- package/dist/Action.d.mts +140 -48
- package/dist/Action.mjs +88 -44
- package/dist/ActionCli.d.mts +70 -35
- package/dist/ActionCli.mjs +53 -34
- package/dist/ActionHttp.d.mts +70 -38
- package/dist/ActionHttp.mjs +76 -25
- package/dist/ActionMcp.d.mts +56 -24
- package/dist/ActionMcp.mjs +104 -61
- package/dist/ActionRpc.d.mts +222 -57
- package/dist/ActionRpc.mjs +301 -49
- package/dist/ActionToolkit.d.mts +22 -7
- package/dist/ActionToolkit.mjs +37 -14
- package/dist/Authentication.d.mts +42 -12
- package/dist/Authentication.mjs +38 -32
- package/dist/Event.d.mts +370 -0
- package/dist/Event.mjs +103 -0
- package/dist/Testing.d.mts +1 -3
- package/dist/Testing.mjs +2 -3
- package/dist/Webhook.d.mts +146 -0
- package/dist/Webhook.mjs +72 -0
- package/dist/authentication/provider.d.mts +35 -12
- package/dist/authentication/provider.mjs +2 -3
- package/dist/authentication/refusal.mjs +3 -4
- package/dist/cli/commands.d.mts +9 -7
- package/dist/cli/commands.mjs +85 -35
- package/dist/contract/ast.mjs +5 -3
- package/dist/contract/authorizer.d.mts +8 -0
- package/dist/contract/authorizer.mjs +20 -0
- package/dist/contract/call.d.mts +9 -8
- package/dist/contract/call.mjs +49 -8
- package/dist/contract/callback.d.mts +7 -0
- package/dist/contract/callback.mjs +27 -0
- package/dist/contract/caller.d.mts +12 -3
- package/dist/contract/caller.mjs +23 -5
- package/dist/contract/canonical.mjs +10 -0
- package/dist/contract/codec.d.mts +9 -0
- package/dist/contract/codec.mjs +9 -0
- package/dist/contract/codes.mjs +81 -0
- package/dist/contract/declared.d.mts +0 -2
- package/dist/contract/declared.mjs +26 -11
- package/dist/contract/digest.mjs +6 -0
- package/dist/contract/errors.d.mts +9 -5
- package/dist/contract/errors.mjs +2 -3
- package/dist/contract/feed.d.mts +127 -0
- package/dist/contract/feed.mjs +249 -0
- package/dist/contract/hints.mjs +1 -2
- package/dist/contract/hub.d.mts +94 -0
- package/dist/contract/hub.mjs +133 -0
- package/dist/contract/idempotency.d.mts +47 -0
- package/dist/contract/idempotency.mjs +99 -0
- package/dist/contract/implementation.d.mts +73 -51
- package/dist/contract/implementation.mjs +94 -60
- package/dist/contract/input-check.d.mts +15 -0
- package/dist/contract/input-check.mjs +16 -0
- package/dist/contract/lease.mjs +28 -0
- package/dist/contract/listed.d.mts +4 -0
- package/dist/contract/listed.mjs +22 -0
- package/dist/contract/log.d.mts +41 -0
- package/dist/contract/log.mjs +144 -0
- package/dist/contract/media.d.mts +1 -3
- package/dist/contract/media.mjs +1 -2
- package/dist/contract/names.mjs +15 -6
- package/dist/contract/occurrence.d.mts +29 -0
- package/dist/contract/occurrence.mjs +45 -0
- package/dist/contract/pages.d.mts +13 -0
- package/dist/contract/pages.mjs +39 -0
- package/dist/contract/progress.d.mts +26 -0
- package/dist/contract/progress.mjs +72 -0
- package/dist/contract/push.d.mts +20 -0
- package/dist/contract/push.mjs +96 -0
- package/dist/contract/receiving.d.mts +29 -0
- package/dist/contract/receiving.mjs +42 -0
- package/dist/contract/recent.mjs +12 -0
- package/dist/contract/reported.mjs +16 -0
- package/dist/contract/serving.mjs +63 -0
- package/dist/contract/status.mjs +15 -7
- package/dist/contract/stream.d.mts +34 -0
- package/dist/contract/stream.mjs +31 -0
- package/dist/contract/subscribe.d.mts +45 -0
- package/dist/contract/subscribe.mjs +50 -0
- package/dist/contract/transient.mjs +28 -0
- package/dist/contract/watch.d.mts +18 -0
- package/dist/contract/watch.mjs +105 -0
- package/dist/contract/webhooks.d.mts +42 -0
- package/dist/contract/webhooks.mjs +53 -0
- package/dist/http/client.d.mts +37 -14
- package/dist/http/client.mjs +52 -14
- package/dist/http/events.d.mts +56 -0
- package/dist/http/events.mjs +102 -0
- package/dist/http/placed.d.mts +36 -0
- package/dist/http/placed.mjs +71 -0
- package/dist/http/schema-errors.mjs +2 -3
- package/dist/http/streamed.d.mts +21 -0
- package/dist/http/streamed.mjs +94 -0
- package/dist/http/watch.mjs +50 -0
- package/dist/mcp/bridge.mjs +283 -0
- package/dist/mcp/client.d.mts +30 -99
- package/dist/mcp/client.mjs +60 -134
- package/dist/mcp/events.mjs +142 -0
- package/dist/mcp/progress.mjs +34 -0
- package/dist/mcp/protocol.mjs +40 -15
- package/dist/mcp/reply.d.mts +79 -0
- package/dist/mcp/reply.mjs +99 -0
- package/dist/mcp/request.d.mts +40 -0
- package/dist/mcp/request.mjs +51 -0
- package/dist/mcp/watch.mjs +115 -0
- package/dist/rpc/watch.mjs +39 -0
- package/dist/stdio/console.mjs +14 -7
- package/dist/testing/memory.d.mts +1 -3
- package/dist/testing/memory.mjs +4 -5
- package/dist/webhook/address.mjs +47 -0
- package/dist/webhook/attempt.mjs +65 -0
- package/dist/webhook/receiver.mjs +67 -0
- package/dist/webhook/signing.mjs +28 -0
- package/dist/webhook/stored.mjs +57 -0
- package/dist/webhook/subscriptions.mjs +342 -0
- package/docs/Action-failures.md +2 -2
- package/docs/Action-streams.md +115 -0
- package/docs/Action.md +58 -124
- package/docs/ActionCli-failures.md +1 -2
- package/docs/ActionCli.md +83 -88
- package/docs/ActionHttp-failures.md +3 -3
- package/docs/ActionHttp.md +90 -70
- package/docs/ActionMcp-failures.md +2 -1
- package/docs/ActionMcp.md +120 -92
- package/docs/ActionRpc-events.md +126 -0
- package/docs/ActionRpc-failures.md +1 -2
- package/docs/ActionRpc.md +108 -79
- package/docs/ActionToolkit-failures.md +1 -2
- package/docs/ActionToolkit.md +33 -90
- package/docs/Authentication-advanced.md +57 -61
- package/docs/Authentication-failures.md +5 -4
- package/docs/Authentication.md +23 -58
- package/docs/Event-failures.md +15 -0
- package/docs/Event.md +281 -0
- package/docs/README.md +51 -82
- package/docs/Testing-failures.md +1 -5
- package/docs/Testing.md +126 -86
- package/docs/Webhook-failures.md +8 -0
- package/docs/Webhook.md +319 -0
- package/docs/setup-failures.md +2 -3
- package/docs/setup.md +32 -53
- package/examples/README.md +12 -37
- package/examples/assistant/README.md +21 -26
- package/examples/assistant/src/agent.ts +66 -24
- package/examples/assistant/src/cli.ts +7 -4
- package/examples/assistant/src/commands.ts +9 -4
- package/examples/assistant/src/identity/Identity.ts +5 -4
- package/examples/assistant/src/identity/authorize.ts +13 -5
- package/examples/assistant/src/identity/handlers.ts +3 -2
- package/examples/assistant/src/identity/permissions.ts +9 -3
- package/examples/assistant/src/platform/tasks-file.ts +15 -11
- package/examples/assistant/src/scripted.ts +7 -4
- package/examples/assistant/src/tasks/Tasks.ts +20 -6
- package/examples/assistant/src/tasks/handlers.ts +9 -5
- package/examples/assistant/src/tasks/store.ts +38 -11
- package/examples/assistant/src/toolkit.ts +11 -7
- package/examples/assistant/test/commands.test.ts +53 -27
- package/examples/assistant/test/identity/identity.test.ts +27 -11
- package/examples/assistant/test/platform/tasks-file.test.ts +39 -23
- package/examples/assistant/test/tasks/tasks.test.ts +62 -34
- package/examples/assistant/test/toolkit.test.ts +104 -75
- package/examples/build-events/README.md +83 -0
- package/examples/build-events/src/Api.ts +27 -0
- package/examples/build-events/src/Rpc.ts +26 -0
- package/examples/build-events/src/builds/Builds.ts +108 -0
- package/examples/build-events/src/builds/events.ts +54 -0
- package/examples/build-events/src/builds/handlers.ts +58 -0
- package/examples/build-events/src/builds/log.ts +30 -0
- package/examples/build-events/src/builds/status.ts +28 -0
- package/examples/build-events/src/builds/store.ts +130 -0
- package/examples/build-events/src/cli.ts +18 -0
- package/examples/build-events/src/commands.ts +32 -0
- package/examples/build-events/src/deploys/Deploys.ts +44 -0
- package/examples/build-events/src/deploys/approvers.ts +55 -0
- package/examples/build-events/src/deploys/events.ts +32 -0
- package/examples/build-events/src/deploys/handlers.ts +38 -0
- package/examples/build-events/src/identity/Identity.ts +29 -0
- package/examples/build-events/src/identity/members.ts +7 -0
- package/examples/build-events/src/identity/verifier.ts +22 -0
- package/examples/build-events/src/notifier/Notices.ts +26 -0
- package/examples/build-events/src/notifier/routes.ts +71 -0
- package/examples/build-events/src/notifier.ts +48 -0
- package/examples/build-events/src/routes.ts +71 -0
- package/examples/build-events/src/server.ts +62 -0
- package/examples/build-events/test/builds/events.test.ts +68 -0
- package/examples/build-events/test/builds/log.test.ts +71 -0
- package/examples/build-events/test/builds/progress.test.ts +57 -0
- package/examples/build-events/test/builds/status.test.ts +42 -0
- package/examples/build-events/test/commands.test.ts +103 -0
- package/examples/build-events/test/deploys/events.test.ts +52 -0
- package/examples/build-events/test/http.test.ts +95 -0
- package/examples/build-events/test/notifier.test.ts +80 -0
- package/examples/build-events/test/routes.test.ts +96 -0
- package/examples/build-events/test/rpc.test.ts +84 -0
- package/examples/build-events/test/support/as.ts +8 -0
- package/examples/build-events/test/support/memory.ts +43 -0
- package/examples/build-events/test/webhooks.test.ts +143 -0
- package/examples/kitchen-sink/README.md +178 -166
- package/examples/kitchen-sink/src/Actions.ts +11 -3
- package/examples/kitchen-sink/src/Api.ts +12 -6
- package/examples/kitchen-sink/src/Rpc.ts +7 -5
- package/examples/kitchen-sink/src/admin/Admin.ts +21 -10
- package/examples/kitchen-sink/src/admin/authenticate.ts +8 -4
- package/examples/kitchen-sink/src/admin/authorize.ts +13 -5
- package/examples/kitchen-sink/src/admin/grants.ts +5 -3
- package/examples/kitchen-sink/src/admin/handlers.ts +9 -5
- package/examples/kitchen-sink/src/agent.ts +14 -6
- package/examples/kitchen-sink/src/assistant/Assistant.ts +21 -15
- package/examples/kitchen-sink/src/assistant/conversations.ts +14 -9
- package/examples/kitchen-sink/src/assistant/demo-model.ts +2 -2
- package/examples/kitchen-sink/src/assistant/handlers.ts +42 -22
- package/examples/kitchen-sink/src/attachments/Attachments.ts +6 -6
- package/examples/kitchen-sink/src/attachments/download.ts +7 -6
- package/examples/kitchen-sink/src/attachments/handlers.ts +9 -4
- package/examples/kitchen-sink/src/attachments/store.ts +25 -18
- package/examples/kitchen-sink/src/browser.ts +10 -4
- package/examples/kitchen-sink/src/cli.ts +28 -12
- package/examples/kitchen-sink/src/config.ts +1 -1
- package/examples/kitchen-sink/src/identity/Identity.ts +24 -10
- package/examples/kitchen-sink/src/identity/authenticate.ts +19 -11
- package/examples/kitchen-sink/src/identity/authorize.ts +14 -4
- package/examples/kitchen-sink/src/identity/directory.ts +16 -7
- package/examples/kitchen-sink/src/identity/handlers.ts +1 -0
- package/examples/kitchen-sink/src/identity/members.ts +7 -2
- package/examples/kitchen-sink/src/identity/quota.ts +23 -20
- package/examples/kitchen-sink/src/issues/Issues.ts +91 -15
- package/examples/kitchen-sink/src/issues/assistant.ts +4 -2
- package/examples/kitchen-sink/src/issues/events.ts +46 -0
- package/examples/kitchen-sink/src/issues/export.ts +35 -0
- package/examples/kitchen-sink/src/issues/guide.ts +4 -3
- package/examples/kitchen-sink/src/issues/handlers.ts +20 -7
- package/examples/kitchen-sink/src/issues/store.ts +156 -67
- package/examples/kitchen-sink/src/issues/write-limit.ts +44 -18
- package/examples/kitchen-sink/src/memory.ts +11 -2
- package/examples/kitchen-sink/src/ops.ts +10 -5
- package/examples/kitchen-sink/src/request-policy.ts +25 -9
- package/examples/kitchen-sink/src/routes.ts +67 -27
- package/examples/kitchen-sink/src/sdk.ts +22 -12
- package/examples/kitchen-sink/src/seed.ts +15 -9
- package/examples/kitchen-sink/src/server.ts +24 -10
- package/examples/kitchen-sink/src/stdio.ts +9 -3
- package/examples/kitchen-sink/src/workspaces/Workspaces.ts +10 -7
- package/examples/kitchen-sink/src/workspaces/handlers.ts +3 -2
- package/examples/kitchen-sink/src/workspaces/registry.ts +16 -10
- package/examples/kitchen-sink/src/workspaces/tenant.ts +12 -5
- package/examples/kitchen-sink/test/admin/admin.test.ts +38 -23
- package/examples/kitchen-sink/test/assistant/assistant.test.ts +471 -299
- package/examples/kitchen-sink/test/attachments/attachments.test.ts +135 -94
- package/examples/kitchen-sink/test/identity/identity.test.ts +110 -82
- package/examples/kitchen-sink/test/identity/session.test.ts +65 -43
- package/examples/kitchen-sink/test/issues/assistant.test.ts +50 -31
- package/examples/kitchen-sink/test/issues/events.test.ts +273 -0
- package/examples/kitchen-sink/test/issues/export.test.ts +120 -0
- package/examples/kitchen-sink/test/issues/issues.test.ts +105 -75
- package/examples/kitchen-sink/test/request-policy.test.ts +130 -33
- package/examples/kitchen-sink/test/routes.test.ts +102 -57
- package/examples/kitchen-sink/test/support/as.ts +9 -0
- package/examples/kitchen-sink/test/support/scripted.ts +6 -5
- package/examples/kitchen-sink/test/support/services.ts +17 -0
- package/examples/live-rpc/README.md +33 -35
- package/examples/live-rpc/src/Rpc.ts +9 -5
- package/examples/live-rpc/src/browser.ts +39 -11
- package/examples/live-rpc/src/chat/Chat.ts +30 -16
- package/examples/live-rpc/src/chat/authorize.ts +2 -1
- package/examples/live-rpc/src/chat/events.ts +74 -0
- package/examples/live-rpc/src/chat/handlers.ts +13 -5
- package/examples/live-rpc/src/chat/room.ts +9 -5
- package/examples/live-rpc/src/chat/store.ts +51 -14
- package/examples/live-rpc/src/client.ts +22 -5
- package/examples/live-rpc/src/identity/Identity.ts +3 -3
- package/examples/live-rpc/src/identity/verifier.ts +8 -4
- package/examples/live-rpc/src/page.ts +58 -12
- package/examples/live-rpc/src/routes.ts +14 -10
- package/examples/live-rpc/src/server.ts +15 -5
- package/examples/live-rpc/test/browser.test.ts +127 -50
- package/examples/live-rpc/test/chat/chat.test.ts +215 -23
- package/examples/live-rpc/test/routes.test.ts +130 -46
- package/examples/live-rpc/test/server.test.ts +94 -33
- package/examples/mcp-tools/README.md +24 -38
- package/examples/mcp-tools/src/platform/fake-farm.ts +63 -24
- package/examples/mcp-tools/src/platform/print-farm.ts +59 -29
- package/examples/mcp-tools/src/printers/Printers.ts +18 -7
- package/examples/mcp-tools/src/printers/farm.ts +15 -5
- package/examples/mcp-tools/src/printers/handlers.ts +12 -6
- package/examples/mcp-tools/src/routes.ts +8 -6
- package/examples/mcp-tools/src/server.ts +12 -5
- package/examples/mcp-tools/src/stdio.ts +3 -2
- package/examples/mcp-tools/test/printers/printers.test.ts +132 -89
- package/examples/mcp-tools/test/routes.test.ts +140 -81
- package/examples/notes-service/README.md +30 -45
- package/examples/notes-service/src/Api.ts +1 -0
- package/examples/notes-service/src/browser.ts +15 -14
- package/examples/notes-service/src/cli.ts +8 -3
- package/examples/notes-service/src/commands.ts +46 -20
- package/examples/notes-service/src/identity/Identity.ts +2 -2
- package/examples/notes-service/src/identity/authorize.ts +6 -2
- package/examples/notes-service/src/identity/handlers.ts +3 -2
- package/examples/notes-service/src/identity/users.ts +2 -1
- package/examples/notes-service/src/identity/verifier.ts +12 -6
- package/examples/notes-service/src/notes/Notes.ts +46 -22
- package/examples/notes-service/src/notes/handlers.ts +18 -9
- package/examples/notes-service/src/notes/store.ts +70 -43
- package/examples/notes-service/src/routes.ts +7 -5
- package/examples/notes-service/src/server.ts +12 -5
- package/examples/notes-service/src/status/Status.ts +1 -1
- package/examples/notes-service/src/status/handlers.ts +5 -3
- package/examples/notes-service/src/stdio.ts +7 -3
- package/examples/notes-service/src/worker.ts +6 -3
- package/examples/notes-service/test/commands.test.ts +164 -91
- package/examples/notes-service/test/notes/as.ts +3 -1
- package/examples/notes-service/test/notes/idempotency.test.ts +97 -67
- package/examples/notes-service/test/notes/in-process.test.ts +26 -15
- package/examples/notes-service/test/notes/notes.test.ts +49 -31
- package/examples/notes-service/test/routes.test.ts +106 -71
- package/examples/notes-service/test/worker.test.ts +21 -13
- package/examples/quickstart/README.md +2 -6
- package/examples/quickstart/src/Api.ts +1 -0
- package/examples/quickstart/src/client.ts +6 -3
- package/examples/quickstart/src/greeting/Greeting.ts +1 -1
- package/examples/quickstart/src/greeting/handlers.ts +5 -2
- package/examples/quickstart/src/routes.ts +3 -2
- package/examples/quickstart/src/server.ts +6 -2
- package/examples/quickstart/test/routes.test.ts +3 -2
- package/package.json +19 -17
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NodeServices } from "@effect/platform-node";
|
|
2
2
|
import { describe, expect, it } from "@effect/vitest";
|
|
3
|
+
import * as ActionHttp from "@gjermundgaraba/effect-actions/ActionHttp";
|
|
4
|
+
import * as Testing from "@gjermundgaraba/effect-actions/Testing";
|
|
3
5
|
import {
|
|
4
6
|
Arbitrary,
|
|
5
7
|
ConfigProvider,
|
|
@@ -13,8 +15,7 @@ import {
|
|
|
13
15
|
import { CliError, Command } from "effect/cli";
|
|
14
16
|
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
15
17
|
import { TestConsole } from "effect/testing";
|
|
16
|
-
|
|
17
|
-
import * as Testing from "@gjermundgaraba/effect-actions/Testing";
|
|
18
|
+
|
|
18
19
|
import { Http } from "../src/Api.js";
|
|
19
20
|
import { commands } from "../src/commands.js";
|
|
20
21
|
import { ImportNotes, Note, NoteNotFound } from "../src/notes/Notes.js";
|
|
@@ -30,21 +31,30 @@ const served = Testing.layer(routes).pipe(Layer.provide(NoteStore.layerMemory));
|
|
|
30
31
|
// the environment as a Layer, so the test decides whether a token is configured, whatever the
|
|
31
32
|
// shell holds. The console of `it.effect` keeps every line printed, so a run returns the lines
|
|
32
33
|
// it added.
|
|
33
|
-
const connected = (
|
|
34
|
+
const connected = (
|
|
35
|
+
environment: Record<string, string>,
|
|
36
|
+
args: readonly string[],
|
|
37
|
+
stdin = ""
|
|
38
|
+
) =>
|
|
34
39
|
Effect.gen(function* () {
|
|
35
40
|
const before = (yield* TestConsole.logLines).length;
|
|
36
41
|
|
|
37
42
|
yield* Command.runWith(commands, { version: "0" })(args).pipe(
|
|
38
|
-
Effect.provide(
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
Effect.provide(
|
|
44
|
+
Layer.merge(
|
|
45
|
+
ConfigProvider.layer(ConfigProvider.fromEnvRecord(environment)),
|
|
46
|
+
Stdio.layerTest({
|
|
47
|
+
stdin: Stream.make(new TextEncoder().encode(stdin)),
|
|
48
|
+
})
|
|
49
|
+
).pipe(Layer.provideMerge(NodeServices.layer))
|
|
50
|
+
)
|
|
41
51
|
);
|
|
42
52
|
|
|
43
53
|
return (yield* TestConsole.logLines).slice(before);
|
|
44
54
|
});
|
|
45
55
|
|
|
46
56
|
// A run as the caller `token` names.
|
|
47
|
-
const run = (token: string, args:
|
|
57
|
+
const run = (token: string, args: readonly string[], stdin = "") =>
|
|
48
58
|
connected({ NOTES_TOKEN: token }, args, stdin);
|
|
49
59
|
|
|
50
60
|
const fitsAFile = (text: string) =>
|
|
@@ -61,8 +71,8 @@ const trickyLines = Arbitrary.array(
|
|
|
61
71
|
"#tag",
|
|
62
72
|
"\r# After a carriage return",
|
|
63
73
|
"\u2028# After a line separator",
|
|
64
|
-
])
|
|
65
|
-
)
|
|
74
|
+
])
|
|
75
|
+
)
|
|
66
76
|
);
|
|
67
77
|
|
|
68
78
|
const importable = Arbitrary.all([
|
|
@@ -73,35 +83,62 @@ const importable = Arbitrary.all([
|
|
|
73
83
|
notes.map(({ title, body }, place) => ({
|
|
74
84
|
title,
|
|
75
85
|
body: [body, ...(extra[place] ?? [])].join("\n"),
|
|
76
|
-
}))
|
|
86
|
+
}))
|
|
77
87
|
),
|
|
78
88
|
Arbitrary.filter((notes) =>
|
|
79
|
-
notes.every(({ title, body }) => fitsAFile(title) && fitsAFile(body))
|
|
80
|
-
)
|
|
89
|
+
notes.every(({ title, body }) => fitsAFile(title) && fitsAFile(body))
|
|
90
|
+
)
|
|
81
91
|
);
|
|
82
92
|
|
|
93
|
+
const as = (token: string) =>
|
|
94
|
+
ActionHttp.client(Http).pipe(
|
|
95
|
+
Effect.updateService(
|
|
96
|
+
HttpClient.HttpClient,
|
|
97
|
+
HttpClient.mapRequest(HttpClientRequest.bearerToken(token))
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
|
|
83
101
|
describe("the commands", () => {
|
|
84
|
-
it.effect(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
it.effect(
|
|
103
|
+
"take an argument, a flag and stdin, and print what `render` returns",
|
|
104
|
+
() =>
|
|
105
|
+
Effect.gen(function* () {
|
|
106
|
+
// A command without `render` prints its result as JSON.
|
|
107
|
+
const [created] = yield* run(
|
|
108
|
+
"ada",
|
|
109
|
+
["create-note", "--title", "Plan"],
|
|
110
|
+
"First draft\n"
|
|
111
|
+
);
|
|
89
112
|
|
|
90
|
-
|
|
113
|
+
const { id } = yield* Schema.decodeUnknownEffect(
|
|
114
|
+
Schema.fromJsonString(Note)
|
|
115
|
+
)(created);
|
|
91
116
|
|
|
92
|
-
|
|
117
|
+
expect(yield* run("ada", ["get-note", id])).toStrictEqual([
|
|
118
|
+
"# Plan\n\nFirst draft",
|
|
119
|
+
]);
|
|
93
120
|
|
|
94
|
-
|
|
95
|
-
|
|
121
|
+
yield* run(
|
|
122
|
+
"ada",
|
|
123
|
+
["update-note", id, "--revision", "1"],
|
|
124
|
+
"Second draft\n"
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
expect(yield* run("ada", ["get-note", id])).toStrictEqual([
|
|
128
|
+
"# Plan\n\nSecond draft",
|
|
129
|
+
]);
|
|
130
|
+
}).pipe(Effect.provide(served))
|
|
96
131
|
);
|
|
97
132
|
|
|
98
|
-
it.effect(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
133
|
+
it.effect(
|
|
134
|
+
"describe a flag in `--help` as the contract describes its field",
|
|
135
|
+
() =>
|
|
136
|
+
Effect.gen(function* () {
|
|
137
|
+
// Help is one printed text. The description is the `revision` field's, from Notes.ts.
|
|
138
|
+
expect(yield* run("ada", ["update-note", "--help"])).toStrictEqual([
|
|
139
|
+
expect.stringContaining("The revision you read: 1 for a new note"),
|
|
140
|
+
]);
|
|
141
|
+
}).pipe(Effect.provide(served))
|
|
105
142
|
);
|
|
106
143
|
|
|
107
144
|
it.effect("run a command of their own beside the derived ones", () =>
|
|
@@ -113,11 +150,13 @@ describe("the commands", () => {
|
|
|
113
150
|
const files = yield* FileSystem.FileSystem;
|
|
114
151
|
const file = `${yield* files.makeTempDirectoryScoped()}/notes.md`;
|
|
115
152
|
|
|
116
|
-
expect(yield* run("ada", ["export", file])).
|
|
153
|
+
expect(yield* run("ada", ["export", file])).toStrictEqual([
|
|
154
|
+
`Wrote 2 notes to ${file}`,
|
|
155
|
+
]);
|
|
117
156
|
expect(yield* files.readFileString(file)).toBe(
|
|
118
|
-
"# Plan\n\nFirst draft\n\n# Budget\n\nToo small"
|
|
157
|
+
"# Plan\n\nFirst draft\n\n# Budget\n\nToo small"
|
|
119
158
|
);
|
|
120
|
-
}).pipe(Effect.provide(served
|
|
159
|
+
}).pipe(Effect.provide(Layer.merge(served, NodeServices.layer)))
|
|
121
160
|
);
|
|
122
161
|
|
|
123
162
|
it.effect("import a file `export` wrote, all its notes or none", () =>
|
|
@@ -126,38 +165,52 @@ describe("the commands", () => {
|
|
|
126
165
|
const directory = yield* files.makeTempDirectoryScoped();
|
|
127
166
|
const file = `${directory}/notes.md`;
|
|
128
167
|
|
|
129
|
-
yield* files.writeFileString(
|
|
168
|
+
yield* files.writeFileString(
|
|
169
|
+
file,
|
|
170
|
+
"# Plan\n\nFirst draft\n\n# Budget\n\nToo small"
|
|
171
|
+
);
|
|
130
172
|
|
|
131
|
-
expect(yield* run("ada", ["import", file])).
|
|
132
|
-
|
|
173
|
+
expect(yield* run("ada", ["import", file])).toStrictEqual([
|
|
174
|
+
"Created 2 notes",
|
|
175
|
+
]);
|
|
176
|
+
expect(yield* run("grace", ["import", file])).toStrictEqual([
|
|
177
|
+
"Created 2 notes",
|
|
178
|
+
]);
|
|
133
179
|
|
|
134
|
-
yield* files.writeFileString(
|
|
180
|
+
yield* files.writeFileString(
|
|
181
|
+
`${directory}/untitled.md`,
|
|
182
|
+
"# Plan\n\nKept?\n\n# \n\nNo title"
|
|
183
|
+
);
|
|
135
184
|
|
|
136
|
-
const refused = yield* Effect.flip(
|
|
185
|
+
const refused = yield* Effect.flip(
|
|
186
|
+
run("ada", ["import", `${directory}/untitled.md`])
|
|
187
|
+
);
|
|
137
188
|
|
|
138
189
|
expect(refused).toHaveProperty(
|
|
139
190
|
"userMessage",
|
|
140
|
-
expect.stringContaining("A note needs a title.")
|
|
191
|
+
expect.stringContaining("A note needs a title.")
|
|
141
192
|
);
|
|
142
193
|
const [listed = ""] = yield* run("ada", ["list-notes"]);
|
|
143
194
|
|
|
144
195
|
const { notes } = yield* Schema.decodeUnknownEffect(
|
|
145
196
|
Schema.fromJsonString(
|
|
146
|
-
Schema.Struct({
|
|
147
|
-
|
|
197
|
+
Schema.Struct({
|
|
198
|
+
notes: Schema.Array(Schema.Struct({ title: Schema.String })),
|
|
199
|
+
})
|
|
200
|
+
)
|
|
148
201
|
)(listed);
|
|
149
202
|
|
|
150
|
-
expect(notes.map(({ title }) => title)).
|
|
203
|
+
expect(notes.map(({ title }) => title)).toStrictEqual(["Plan", "Budget"]);
|
|
151
204
|
|
|
152
205
|
// A missing file is a usage error: the command's help, and the file named on stderr.
|
|
153
206
|
yield* Effect.flip(run("ada", ["import", `${directory}/nowhere.md`]));
|
|
154
207
|
|
|
155
208
|
expect(yield* TestConsole.errorLines).toContainEqual(
|
|
156
209
|
expect.stringMatching(
|
|
157
|
-
/Invalid value for argument <file>: .*nowhere\.md.*File does not exist/su
|
|
158
|
-
)
|
|
210
|
+
/Invalid value for argument <file>: .*nowhere\.md.*File does not exist/su
|
|
211
|
+
)
|
|
159
212
|
);
|
|
160
|
-
}).pipe(Effect.provide(served
|
|
213
|
+
}).pipe(Effect.provide(Layer.merge(served, NodeServices.layer)))
|
|
161
214
|
);
|
|
162
215
|
|
|
163
216
|
// Any notes the contract accepts, generated from its schema, with lines that start as a title
|
|
@@ -171,14 +224,6 @@ describe("the commands", () => {
|
|
|
171
224
|
const files = yield* FileSystem.FileSystem;
|
|
172
225
|
const file = `${yield* files.makeTempDirectoryScoped()}/notes.md`;
|
|
173
226
|
|
|
174
|
-
const as = (token: string) =>
|
|
175
|
-
ActionHttp.client(Http).pipe(
|
|
176
|
-
Effect.updateService(
|
|
177
|
-
HttpClient.HttpClient,
|
|
178
|
-
HttpClient.mapRequest(HttpClientRequest.bearerToken(token)),
|
|
179
|
-
),
|
|
180
|
-
);
|
|
181
|
-
|
|
182
227
|
const [ada, grace] = [yield* as("ada"), yield* as("grace")];
|
|
183
228
|
|
|
184
229
|
yield* ada.importNotes({ notes });
|
|
@@ -186,11 +231,16 @@ describe("the commands", () => {
|
|
|
186
231
|
yield* run("grace", ["import", file]);
|
|
187
232
|
|
|
188
233
|
const { notes: listed } = yield* grace.listNotes();
|
|
189
|
-
const read = yield* Effect.forEach(listed, ({ id }) => grace.getNote({ id }));
|
|
190
234
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
235
|
+
const read = yield* Effect.forEach(listed, ({ id }) =>
|
|
236
|
+
grace.getNote({ id })
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
expect(read.map(({ title, body }) => ({ title, body }))).toStrictEqual(
|
|
240
|
+
notes
|
|
241
|
+
);
|
|
242
|
+
}).pipe(Effect.provide(Layer.merge(served, NodeServices.layer))),
|
|
243
|
+
{ arbitrary: { runs: 50 } }
|
|
194
244
|
);
|
|
195
245
|
|
|
196
246
|
it.effect(
|
|
@@ -202,82 +252,105 @@ describe("the commands", () => {
|
|
|
202
252
|
|
|
203
253
|
yield* files.writeFileString(`${directory}/empty.md`, "");
|
|
204
254
|
|
|
205
|
-
expect(
|
|
206
|
-
"
|
|
207
|
-
]);
|
|
255
|
+
expect(
|
|
256
|
+
yield* run("grace", ["import", `${directory}/empty.md`])
|
|
257
|
+
).toStrictEqual(["Created 0 notes"]);
|
|
208
258
|
|
|
209
|
-
yield* files.writeFileString(
|
|
259
|
+
yield* files.writeFileString(
|
|
260
|
+
`${directory}/preamble.md`,
|
|
261
|
+
"My notes\n\n# Plan\n\nDraft"
|
|
262
|
+
);
|
|
210
263
|
|
|
211
264
|
expect(
|
|
212
|
-
yield* Effect.flip(
|
|
265
|
+
yield* Effect.flip(
|
|
266
|
+
run("grace", ["import", `${directory}/preamble.md`])
|
|
267
|
+
)
|
|
213
268
|
).toHaveProperty(
|
|
214
269
|
"userMessage",
|
|
215
|
-
"The file does not start with a `# ` title, as `notes export` writes one."
|
|
270
|
+
"The file does not start with a `# ` title, as `notes export` writes one."
|
|
216
271
|
);
|
|
217
272
|
|
|
218
|
-
const many = Array.from(
|
|
273
|
+
const many = Array.from(
|
|
274
|
+
{ length: 101 },
|
|
275
|
+
(_, place) => `# Note ${place}\n\nBody`
|
|
276
|
+
);
|
|
219
277
|
|
|
220
278
|
yield* files.writeFileString(`${directory}/many.md`, many.join("\n\n"));
|
|
221
279
|
|
|
222
|
-
expect(
|
|
280
|
+
expect(
|
|
281
|
+
yield* Effect.flip(run("grace", ["import", `${directory}/many.md`]))
|
|
282
|
+
).toHaveProperty(
|
|
223
283
|
"userMessage",
|
|
224
|
-
expect.stringContaining("An import holds at most 100 notes.")
|
|
284
|
+
expect.stringContaining("An import holds at most 100 notes.")
|
|
225
285
|
);
|
|
226
286
|
|
|
227
|
-
expect(yield* run("grace", ["list-notes"])).
|
|
287
|
+
expect(yield* run("grace", ["list-notes"])).toStrictEqual([
|
|
228
288
|
JSON.stringify({ notes: [] }, null, 2),
|
|
229
289
|
]);
|
|
230
|
-
}).pipe(Effect.provide(served
|
|
290
|
+
}).pipe(Effect.provide(Layer.merge(served, NodeServices.layer)))
|
|
231
291
|
);
|
|
232
292
|
|
|
233
293
|
it.effect("fail as the server refuses, a command of their own included", () =>
|
|
234
294
|
Effect.gen(function* () {
|
|
235
|
-
const refused = yield* Effect.flip(
|
|
295
|
+
const refused = yield* Effect.flip(
|
|
296
|
+
run("mallory", ["export", "notes.md"])
|
|
297
|
+
);
|
|
236
298
|
|
|
237
299
|
expect(refused).toBeInstanceOf(CliError.UserError);
|
|
238
300
|
expect(refused).toHaveProperty(
|
|
239
301
|
"userMessage",
|
|
240
|
-
'{"_tag":"Unauthenticated","message":"Unknown demo token."}'
|
|
302
|
+
'{"_tag":"Unauthenticated","message":"Unknown demo token."}'
|
|
241
303
|
);
|
|
242
304
|
// The command's own context is a line of its own on stderr, the JSON left as it is.
|
|
243
|
-
expect(yield* TestConsole.errorLines).toContain(
|
|
305
|
+
expect(yield* TestConsole.errorLines).toContain(
|
|
306
|
+
"The export to notes.md did not finish."
|
|
307
|
+
);
|
|
244
308
|
|
|
245
309
|
// Not an action's error: the file system's, named in the message.
|
|
246
|
-
const unwritable = yield* Effect.flip(
|
|
310
|
+
const unwritable = yield* Effect.flip(
|
|
311
|
+
run("ada", ["export", "no-such-directory/notes.md"])
|
|
312
|
+
);
|
|
247
313
|
|
|
248
314
|
expect(unwritable).toBeInstanceOf(CliError.UserError);
|
|
249
|
-
expect(unwritable).toHaveProperty(
|
|
315
|
+
expect(unwritable).toHaveProperty(
|
|
316
|
+
"userMessage",
|
|
317
|
+
expect.stringMatching(/^PlatformError: /u)
|
|
318
|
+
);
|
|
250
319
|
|
|
251
320
|
const missing = yield* Effect.flip(run("ada", ["get-note", "9"]));
|
|
252
321
|
|
|
253
322
|
expect(missing).toHaveProperty("cause", new NoteNotFound({ id: "9" }));
|
|
254
|
-
}).pipe(Effect.provide(served))
|
|
323
|
+
}).pipe(Effect.provide(served))
|
|
255
324
|
);
|
|
256
325
|
|
|
257
|
-
it.effect(
|
|
258
|
-
|
|
259
|
-
|
|
326
|
+
it.effect(
|
|
327
|
+
"call as the configured token names, and ask for one where none is configured",
|
|
328
|
+
() =>
|
|
329
|
+
Effect.gen(function* () {
|
|
330
|
+
yield* connected({ NOTES_TOKEN: "reader" }, ["who-am-i"]);
|
|
260
331
|
|
|
261
|
-
|
|
332
|
+
expect(yield* TestConsole.logLines).toStrictEqual([
|
|
333
|
+
expect.stringContaining('"id": "reader"'),
|
|
334
|
+
]);
|
|
262
335
|
|
|
263
|
-
|
|
336
|
+
const refused = yield* Effect.flip(connected({}, ["list-notes"]));
|
|
264
337
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
338
|
+
expect(refused).toBeInstanceOf(CliError.UserError);
|
|
339
|
+
expect(refused).toHaveProperty("cause._tag", "MissingToken");
|
|
340
|
+
expect(refused).toHaveProperty(
|
|
341
|
+
"userMessage",
|
|
342
|
+
"MissingToken: NOTES_TOKEN is not set. Set it to your token: export NOTES_TOKEN=<your token>"
|
|
343
|
+
);
|
|
271
344
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
345
|
+
// What a person sees: that message, once, on stderr, and no report of a `ConfigError`.
|
|
346
|
+
expect(yield* TestConsole.errorLines).toStrictEqual([
|
|
347
|
+
expect.stringContaining("NOTES_TOKEN is not set."),
|
|
348
|
+
]);
|
|
276
349
|
|
|
277
|
-
|
|
278
|
-
|
|
350
|
+
// The token is read when a command runs, so help needs none.
|
|
351
|
+
yield* connected({}, ["list-notes", "--help"]);
|
|
279
352
|
|
|
280
|
-
|
|
281
|
-
|
|
353
|
+
expect(yield* TestConsole.logLines).toHaveLength(2);
|
|
354
|
+
}).pipe(Effect.provide(served))
|
|
282
355
|
);
|
|
283
356
|
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
|
|
2
3
|
import { CurrentUser } from "../../src/identity/Identity.js";
|
|
3
4
|
import { users } from "../../src/identity/users.js";
|
|
4
5
|
|
|
5
6
|
// The caller of one call, as a server provides it per request.
|
|
6
|
-
export const as = (user: keyof typeof users) =>
|
|
7
|
+
export const as = (user: keyof typeof users) =>
|
|
8
|
+
Effect.provideService(CurrentUser, users[user]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expect, it } from "@effect/vitest";
|
|
2
|
-
import { Arbitrary, Array, Effect, References, Schema } from "effect";
|
|
3
2
|
import * as Action from "@gjermundgaraba/effect-actions/Action";
|
|
3
|
+
import { Arbitrary, Array, Effect, References, Schema } from "effect";
|
|
4
|
+
|
|
4
5
|
import { notes } from "../../src/notes/handlers.js";
|
|
5
6
|
import { CreateNote, RequestConflict } from "../../src/notes/Notes.js";
|
|
6
7
|
import { NoteStore } from "../../src/notes/store.js";
|
|
@@ -14,13 +15,13 @@ it.effect("creates a new note on every call without a request key", () =>
|
|
|
14
15
|
const second = yield* client.createNote(input);
|
|
15
16
|
|
|
16
17
|
expect(second.id).not.toBe(first.id);
|
|
17
|
-
expect(yield* client.listNotes()).
|
|
18
|
+
expect(yield* client.listNotes()).toStrictEqual({
|
|
18
19
|
notes: [
|
|
19
20
|
{ id: first.id, title: input.title },
|
|
20
21
|
{ id: second.id, title: input.title },
|
|
21
22
|
],
|
|
22
23
|
});
|
|
23
|
-
}).pipe(as("ada"), Effect.provide(NoteStore.layerMemory))
|
|
24
|
+
}).pipe(as("ada"), Effect.provide(NoteStore.layerMemory))
|
|
24
25
|
);
|
|
25
26
|
|
|
26
27
|
it.effect.prop(
|
|
@@ -30,7 +31,7 @@ it.effect.prop(
|
|
|
30
31
|
Schema.Struct({
|
|
31
32
|
...CreateNote.input.fields,
|
|
32
33
|
requestId: Schema.requiredKey(CreateNote.input.fields.requestId),
|
|
33
|
-
})
|
|
34
|
+
})
|
|
34
35
|
),
|
|
35
36
|
},
|
|
36
37
|
({ input }) =>
|
|
@@ -39,12 +40,16 @@ it.effect.prop(
|
|
|
39
40
|
const first = yield* client.createNote(input);
|
|
40
41
|
const replay = yield* client.createNote(input);
|
|
41
42
|
|
|
42
|
-
expect(first).toMatchObject({
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
expect(first).toMatchObject({
|
|
44
|
+
title: input.title,
|
|
45
|
+
body: input.body,
|
|
46
|
+
revision: 1,
|
|
47
|
+
});
|
|
48
|
+
expect(replay).toStrictEqual(first);
|
|
49
|
+
expect(yield* client.listNotes()).toStrictEqual({
|
|
45
50
|
notes: [{ id: first.id, title: input.title }],
|
|
46
51
|
});
|
|
47
|
-
}).pipe(as("ada"), Effect.provide(NoteStore.layerMemory))
|
|
52
|
+
}).pipe(as("ada"), Effect.provide(NoteStore.layerMemory))
|
|
48
53
|
);
|
|
49
54
|
|
|
50
55
|
it.effect.each([
|
|
@@ -57,73 +62,98 @@ it.effect.each([
|
|
|
57
62
|
const first = yield* client.createNote(input);
|
|
58
63
|
|
|
59
64
|
expect(
|
|
60
|
-
yield* Effect.flip(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
yield* Effect.flip(
|
|
66
|
+
client.createNote({ requestId: input.requestId, ...changed })
|
|
67
|
+
)
|
|
68
|
+
).toStrictEqual(new RequestConflict({ requestId: input.requestId }));
|
|
69
|
+
expect(yield* client.createNote(input)).toStrictEqual(first);
|
|
70
|
+
expect(yield* client.listNotes()).toStrictEqual({
|
|
71
|
+
notes: [{ id: first.id, title: "Plan" }],
|
|
72
|
+
});
|
|
73
|
+
}).pipe(as("ada"), Effect.provide(NoteStore.layerMemory))
|
|
65
74
|
);
|
|
66
75
|
|
|
67
|
-
it.effect(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
it.effect(
|
|
77
|
+
"scopes keys to the caller, and treats a new key as a new creation",
|
|
78
|
+
() =>
|
|
79
|
+
Effect.gen(function* () {
|
|
80
|
+
const client = yield* Action.client(notes);
|
|
81
|
+
const input = { requestId: "plan", title: "Plan", body: "Draft" };
|
|
82
|
+
const ada = yield* client.createNote(input).pipe(as("ada"));
|
|
83
|
+
|
|
84
|
+
const grace = yield* client
|
|
85
|
+
.createNote({ ...input, body: "Grace's draft" })
|
|
86
|
+
.pipe(as("grace"));
|
|
87
|
+
|
|
88
|
+
const another = yield* client
|
|
89
|
+
.createNote({ ...input, requestId: "another" })
|
|
90
|
+
.pipe(as("ada"));
|
|
91
|
+
|
|
92
|
+
expect(new Set([ada.id, grace.id, another.id]).size).toBe(3);
|
|
93
|
+
expect(yield* client.createNote(input).pipe(as("ada"))).toStrictEqual(
|
|
94
|
+
ada
|
|
95
|
+
);
|
|
96
|
+
expect(yield* client.listNotes().pipe(as("ada"))).toStrictEqual({
|
|
97
|
+
notes: [
|
|
98
|
+
{ id: ada.id, title: "Plan" },
|
|
99
|
+
{ id: another.id, title: "Plan" },
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
expect(yield* client.listNotes().pipe(as("grace"))).toStrictEqual({
|
|
103
|
+
notes: [{ id: grace.id, title: "Plan" }],
|
|
104
|
+
});
|
|
105
|
+
}).pipe(Effect.provide(NoteStore.layerMemory))
|
|
87
106
|
);
|
|
88
107
|
|
|
89
|
-
it.effect(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
it.effect(
|
|
109
|
+
"retains the original result after the note changes or is deleted",
|
|
110
|
+
() =>
|
|
111
|
+
Effect.gen(function* () {
|
|
112
|
+
const client = yield* Action.client(notes);
|
|
113
|
+
const input = { requestId: "plan", title: "Plan", body: "Draft" };
|
|
114
|
+
const original = yield* client.createNote(input);
|
|
94
115
|
|
|
95
|
-
|
|
116
|
+
yield* client.updateNote({ id: original.id, body: "Final", revision: 1 });
|
|
96
117
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
118
|
+
expect(yield* client.createNote(input)).toStrictEqual(original);
|
|
119
|
+
expect(yield* client.getNote({ id: original.id })).toMatchObject({
|
|
120
|
+
body: "Final",
|
|
121
|
+
revision: 2,
|
|
122
|
+
});
|
|
102
123
|
|
|
103
|
-
|
|
124
|
+
yield* client.deleteNote({ id: original.id });
|
|
104
125
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
126
|
+
expect(yield* client.createNote(input)).toStrictEqual(original);
|
|
127
|
+
expect(yield* client.listNotes()).toStrictEqual({ notes: [] });
|
|
128
|
+
}).pipe(as("ada"), Effect.provide(NoteStore.layerMemory))
|
|
108
129
|
);
|
|
109
130
|
|
|
110
|
-
it.effect(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
it.effect(
|
|
132
|
+
"creates one note for concurrent duplicates, including under frequent fiber yields",
|
|
133
|
+
() =>
|
|
134
|
+
Effect.gen(function* () {
|
|
135
|
+
const client = yield* Action.client(notes);
|
|
136
|
+
const steps = Array.range(3, 60);
|
|
137
|
+
|
|
138
|
+
yield* Effect.forEach(steps, (limit) =>
|
|
139
|
+
Effect.gen(function* () {
|
|
140
|
+
const input = {
|
|
141
|
+
requestId: `concurrent-${limit}`,
|
|
142
|
+
title: "Plan",
|
|
143
|
+
body: "Draft",
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const created = yield* Effect.all(
|
|
147
|
+
Array.replicate(client.createNote(input), 3),
|
|
148
|
+
{
|
|
149
|
+
concurrency: "unbounded",
|
|
150
|
+
}
|
|
151
|
+
).pipe(Effect.provideService(References.MaxOpsBeforeYield, limit));
|
|
152
|
+
|
|
153
|
+
expect(created).toStrictEqual(Array.replicate(created[0], 3));
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect((yield* client.listNotes()).notes).toHaveLength(steps.length);
|
|
158
|
+
}).pipe(as("ada"), Effect.provide(NoteStore.layerMemory))
|
|
129
159
|
);
|