@gaganref/confect-alchemy 10.6.0-fork.3 → 10.6.0-fork.31

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.
Files changed (100) hide show
  1. package/dist/Backend.d.ts +64 -5
  2. package/dist/Backend.d.ts.map +1 -1
  3. package/dist/Backend.js +187 -3
  4. package/dist/Backend.js.map +1 -1
  5. package/dist/Code.d.ts +14 -2
  6. package/dist/Code.d.ts.map +1 -1
  7. package/dist/Code.js +2 -2
  8. package/dist/Code.js.map +1 -1
  9. package/dist/Confect.d.ts +1 -1
  10. package/dist/Confect.d.ts.map +1 -1
  11. package/dist/Confect.js +8 -3
  12. package/dist/Confect.js.map +1 -1
  13. package/dist/Convex.d.ts +4 -1
  14. package/dist/Convex.d.ts.map +1 -1
  15. package/dist/Convex.js +10 -1
  16. package/dist/Convex.js.map +1 -1
  17. package/dist/ConvexClient.d.ts +92 -3
  18. package/dist/ConvexClient.d.ts.map +1 -1
  19. package/dist/ConvexClient.js +149 -27
  20. package/dist/ConvexClient.js.map +1 -1
  21. package/dist/CustomDomain.d.ts +156 -0
  22. package/dist/CustomDomain.d.ts.map +1 -0
  23. package/dist/CustomDomain.js +255 -0
  24. package/dist/CustomDomain.js.map +1 -0
  25. package/dist/DeployKey.js +3 -3
  26. package/dist/Deployment.d.ts +29 -3
  27. package/dist/Deployment.d.ts.map +1 -1
  28. package/dist/Deployment.js +39 -15
  29. package/dist/Deployment.js.map +1 -1
  30. package/dist/EnvironmentVariables.d.ts +76 -21
  31. package/dist/EnvironmentVariables.d.ts.map +1 -1
  32. package/dist/EnvironmentVariables.js +203 -19
  33. package/dist/EnvironmentVariables.js.map +1 -1
  34. package/dist/LogStream.d.ts +134 -0
  35. package/dist/LogStream.d.ts.map +1 -0
  36. package/dist/LogStream.js +324 -0
  37. package/dist/LogStream.js.map +1 -0
  38. package/dist/Project.js +2 -2
  39. package/dist/Providers.d.ts.map +1 -1
  40. package/dist/Providers.js +30 -15
  41. package/dist/Providers.js.map +1 -1
  42. package/dist/UsageLimit.d.ts +140 -0
  43. package/dist/UsageLimit.d.ts.map +1 -0
  44. package/dist/UsageLimit.js +145 -0
  45. package/dist/UsageLimit.js.map +1 -0
  46. package/dist/internal/CodeDeployment.d.ts +28 -1
  47. package/dist/internal/CodeDeployment.d.ts.map +1 -1
  48. package/dist/internal/CodeDeployment.js +85 -2
  49. package/dist/internal/CodeDeployment.js.map +1 -1
  50. package/dist/internal/CommandRunner.d.ts +4 -0
  51. package/dist/internal/CommandRunner.d.ts.map +1 -1
  52. package/dist/internal/CommandRunner.js +92 -6
  53. package/dist/internal/CommandRunner.js.map +1 -1
  54. package/dist/internal/FileLock.js +1 -1
  55. package/dist/internal/FunctionsDirectory.d.ts +12 -0
  56. package/dist/internal/FunctionsDirectory.d.ts.map +1 -0
  57. package/dist/internal/FunctionsDirectory.js +22 -0
  58. package/dist/internal/FunctionsDirectory.js.map +1 -0
  59. package/dist/internal/Lifecycle.d.ts +1 -0
  60. package/dist/internal/Lifecycle.d.ts.map +1 -1
  61. package/dist/internal/Lifecycle.js +24 -2
  62. package/dist/internal/Lifecycle.js.map +1 -1
  63. package/dist/internal/LocalBackend.d.ts +9 -0
  64. package/dist/internal/LocalBackend.d.ts.map +1 -1
  65. package/dist/internal/LocalBackend.js +14 -5
  66. package/dist/internal/LocalBackend.js.map +1 -1
  67. package/dist/internal/LogStream.d.ts +115 -0
  68. package/dist/internal/LogStream.d.ts.map +1 -0
  69. package/dist/internal/LogStream.js +123 -0
  70. package/dist/internal/LogStream.js.map +1 -0
  71. package/dist/internal/MountInit.d.ts +4 -5
  72. package/dist/internal/MountInit.d.ts.map +1 -1
  73. package/dist/internal/MountInit.js +17 -36
  74. package/dist/internal/MountInit.js.map +1 -1
  75. package/dist/internal/PushLock.d.ts +1 -0
  76. package/dist/internal/PushLock.d.ts.map +1 -1
  77. package/dist/internal/PushLock.js +4 -3
  78. package/dist/internal/PushLock.js.map +1 -1
  79. package/dist/internal/ResourceIdentity.js +1 -1
  80. package/dist/internal/Zip.js +1 -1
  81. package/package.json +4 -4
  82. package/src/Backend.ts +422 -12
  83. package/src/Code.ts +13 -0
  84. package/src/Confect.ts +7 -1
  85. package/src/Convex.ts +24 -1
  86. package/src/ConvexClient.ts +364 -31
  87. package/src/CustomDomain.ts +453 -0
  88. package/src/Deployment.ts +74 -12
  89. package/src/EnvironmentVariables.ts +505 -19
  90. package/src/LogStream.ts +662 -0
  91. package/src/Providers.ts +18 -0
  92. package/src/UsageLimit.ts +253 -0
  93. package/src/internal/CodeDeployment.ts +115 -0
  94. package/src/internal/CommandRunner.ts +182 -1
  95. package/src/internal/FunctionsDirectory.ts +27 -0
  96. package/src/internal/Lifecycle.ts +21 -1
  97. package/src/internal/LocalBackend.ts +9 -0
  98. package/src/internal/LogStream.ts +154 -0
  99. package/src/internal/MountInit.ts +24 -65
  100. package/src/internal/PushLock.ts +4 -1
@@ -195,6 +195,8 @@ const readIdentity = Effect.fn("LocalBackend.readIdentity")(function* (
195
195
 
196
196
  /**
197
197
  * The admin key of a local deployment, for its deploy key resource.
198
+ *
199
+ * @stability unstable
198
200
  */
199
201
  export const adminKey = Effect.fn("LocalBackend.adminKey")(function* (
200
202
  deploymentName: string,
@@ -209,6 +211,11 @@ export const adminKey = Effect.fn("LocalBackend.adminKey")(function* (
209
211
  return Redacted.make(identity.value.adminKey);
210
212
  });
211
213
 
214
+ /**
215
+ * Remove a local deployment's retained data.
216
+ *
217
+ * @stability unstable
218
+ */
212
219
  export const remove = Effect.fn("LocalBackend.remove")(function* (
213
220
  deploymentName: string,
214
221
  directory: string,
@@ -272,6 +279,8 @@ const install = Effect.fn("LocalBackend.install")(function* (
272
279
  * picks two free loopback ports; later boots reuse all of them, so stored
273
280
  * credentials and URLs stay valid. A saved port that something else now holds
274
281
  * is an error rather than a move, because resources keep the URL.
282
+ *
283
+ * @stability unstable
275
284
  */
276
285
  export const boot = Effect.fn("LocalBackend.boot")(function* (
277
286
  deploymentName: string,
@@ -0,0 +1,154 @@
1
+ import type * as DeploymentApi from "@convex-dev/platform/deploymentApi";
2
+ import type * as Redacted from "effect/Redacted";
3
+ import * as Schema from "effect/Schema";
4
+
5
+ export type SecretField =
6
+ | "apiKey"
7
+ | "ddApiKey"
8
+ | "dsn"
9
+ | "accessKeyId"
10
+ | "secretAccessKey";
11
+ export type RedactInput<A> = A extends unknown
12
+ ? {
13
+ readonly [K in keyof A]: K extends SecretField
14
+ ? Redacted.Redacted<string> | Exclude<A[K], string>
15
+ : K extends "url"
16
+ ? A[K] | Redacted.Redacted<string>
17
+ : A[K];
18
+ }
19
+ : never;
20
+ export type ReadonlyDeep<A> = A extends object
21
+ ? { readonly [K in keyof A]: ReadonlyDeep<A[K]> }
22
+ : A;
23
+
24
+ const Status = Schema.Union([
25
+ Schema.Struct({
26
+ type: Schema.Literals(["pending", "restarting", "active", "deleting"]),
27
+ }),
28
+ Schema.Struct({ type: Schema.Literal("failed"), reason: Schema.String }),
29
+ ]);
30
+ export const Topics = [
31
+ "verification",
32
+ "console",
33
+ "function_execution",
34
+ "exception",
35
+ "audit_log",
36
+ "scheduler_stats",
37
+ "scheduled_job_lag",
38
+ "current_storage_usage",
39
+ "concurrency_stats",
40
+ "storage_api_bandwidth",
41
+ "ai_gateway_usage",
42
+ "log_stream_egress",
43
+ "custom_audit",
44
+ ] as const;
45
+ const TopicSelection = Schema.Array(Schema.Literals(Topics)).pipe(
46
+ Schema.NullOr,
47
+ Schema.optionalKey,
48
+ );
49
+ const optionalString = Schema.String.pipe(Schema.NullOr, Schema.optionalKey);
50
+ const Tags = Schema.Record(Schema.String, Schema.String).pipe(
51
+ Schema.NullOr,
52
+ Schema.optionalKey,
53
+ );
54
+ // IDs enter recovery errors, so reject response text outside this bounded alphabet.
55
+ const Id = Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_+/-]{1,128}$/));
56
+ const base = { id: Id, status: Status };
57
+ const Inclusion = Schema.Literals(["included", "excluded"]);
58
+ const TableSelection = Schema.Union([
59
+ Schema.Literal("excluded"),
60
+ Schema.StructWithRest(Schema.Struct({ _other: Inclusion }), [
61
+ Schema.Record(Schema.String, Inclusion),
62
+ ]),
63
+ ]);
64
+ const ComponentSelection = Schema.Union([
65
+ Schema.Literal("excluded"),
66
+ Schema.StructWithRest(Schema.Struct({ _other: Inclusion }), [
67
+ Schema.Record(Schema.String, TableSelection),
68
+ ]),
69
+ ]);
70
+ const Selection = Schema.StructWithRest(Schema.Struct({ _other: Inclusion }), [
71
+ Schema.Record(Schema.String, ComponentSelection),
72
+ ]);
73
+
74
+ export const Config = Schema.Union([
75
+ Schema.Struct({
76
+ ...base,
77
+ logStreamType: Schema.Literal("datadog"),
78
+ siteLocation: Schema.Literals([
79
+ "US1",
80
+ "US3",
81
+ "US5",
82
+ "EU",
83
+ "US1_FED",
84
+ "AP1",
85
+ ]),
86
+ ddTags: Schema.Array(Schema.String),
87
+ service: optionalString,
88
+ topics: TopicSelection,
89
+ }),
90
+ Schema.Struct({
91
+ ...base,
92
+ logStreamType: Schema.Literal("webhook"),
93
+ url: Schema.String,
94
+ format: Schema.Literals(["json", "jsonl"]),
95
+ hmacSecret: Schema.String,
96
+ topics: TopicSelection,
97
+ }),
98
+ Schema.Struct({
99
+ ...base,
100
+ logStreamType: Schema.Literal("axiom"),
101
+ datasetName: Schema.String,
102
+ attributes: Schema.Array(
103
+ Schema.Struct({ key: Schema.String, value: Schema.String }),
104
+ ),
105
+ ingestUrl: optionalString,
106
+ topics: TopicSelection,
107
+ }),
108
+ Schema.Struct({
109
+ ...base,
110
+ logStreamType: Schema.Literal("sentry"),
111
+ tags: Tags,
112
+ }),
113
+ Schema.Struct({
114
+ ...base,
115
+ logStreamType: Schema.Literal("postHogLogs"),
116
+ host: optionalString,
117
+ serviceName: optionalString,
118
+ topics: TopicSelection,
119
+ }),
120
+ Schema.Struct({
121
+ ...base,
122
+ logStreamType: Schema.Literal("postHogErrorTracking"),
123
+ host: optionalString,
124
+ }),
125
+ Schema.Struct({
126
+ ...base,
127
+ logStreamType: Schema.Literal("s3Export"),
128
+ bucket: Schema.String,
129
+ region: Schema.String,
130
+ prefix: optionalString,
131
+ accessKeyId: Schema.String,
132
+ period: Schema.Literals(["continuous", "hourly", "daily"]),
133
+ selection: Selection,
134
+ }),
135
+ ]) satisfies Schema.Schema<ReadonlyDeep<DeploymentApi.LogStreamConfig>>;
136
+
137
+ export const Created = Schema.Union([
138
+ Schema.Struct({
139
+ logStreamType: Schema.Literal("webhook"),
140
+ id: Id,
141
+ hmacSecret: Schema.String,
142
+ }),
143
+ Schema.Struct({
144
+ logStreamType: Schema.Literals([
145
+ "datadog",
146
+ "axiom",
147
+ "sentry",
148
+ "postHogLogs",
149
+ "postHogErrorTracking",
150
+ "s3Export",
151
+ ]),
152
+ id: Id,
153
+ }),
154
+ ]) satisfies Schema.Schema<ReadonlyDeep<DeploymentApi.CreateLogStreamResponse>>;
@@ -1,9 +1,11 @@
1
+ import * as MountSteps from "@confect/core/MountSteps";
1
2
  import * as Effect from "effect/Effect";
2
3
  import * as FileSystem from "effect/FileSystem";
3
4
  import * as Path from "effect/Path";
4
5
  import type * as Redacted from "effect/Redacted";
5
6
  import * as Schema from "effect/Schema";
6
7
  import { ConvexClient, ConvexFunctionError } from "../ConvexClient.js";
8
+ import { functionsDirectory } from "./FunctionsDirectory.js";
7
9
 
8
10
  export class MountInitFailed extends Schema.TaggedError<
9
11
  MountInitFailed,
@@ -14,50 +16,23 @@ export class MountInitFailed extends Schema.TaggedError<
14
16
  }
15
17
  }
16
18
 
17
- const Steps = Schema.Array(
18
- Schema.Union([
19
- Schema.Struct({
20
- componentPath: Schema.String,
21
- nested: Schema.Boolean,
22
- init: Schema.NullOr(
23
- Schema.Struct({ functionName: Schema.String, args: Schema.Unknown }),
24
- ),
25
- }),
26
- Schema.Struct({ componentPath: Schema.String, failure: Schema.String }),
27
- ]),
28
- );
29
-
30
- const STEPS = "confectDeploy:steps";
31
-
32
- const ConvexJson = Schema.fromJsonString(
33
- Schema.Struct({ functions: Schema.optional(Schema.String) }),
34
- );
35
-
36
19
  /**
37
- * Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory,
38
- * which `convex.json` may move.
20
+ * Whether codegen wrote `confectDeploy.ts` into the backend's Convex directory.
39
21
  */
40
22
  const hasDeployModule = Effect.fn("MountInit.hasDeployModule")(function* (
41
23
  cwd: string,
42
24
  ) {
43
25
  const fs = yield* FileSystem.FileSystem;
44
26
  const path = yield* Path.Path;
45
- const config = path.join(cwd, "convex.json");
46
- const functions = (yield* fs.exists(config))
47
- ? ((yield* fs
48
- .readFileString(config)
49
- .pipe(Effect.flatMap(Schema.decodeEffect(ConvexJson)))).functions ??
50
- "convex")
51
- : "convex";
27
+ const functions = yield* functionsDirectory(cwd);
52
28
  return yield* fs.exists(path.join(cwd, functions, "confectDeploy.ts"));
53
29
  });
54
30
 
55
31
  /**
56
- * Run every mount's `init` against a pushed deployment: ask the backend's
57
- * deploy module for its steps, then run each mount's `init` at its component
58
- * path, one at a time, and visit a nested component's own steps after its
59
- * `init`. The first failing mount stops the run. Each `init` is its own
60
- * transaction, so earlier mounts stay applied and a rerun converges.
32
+ * Run every mount's `init` against a pushed deployment, in the order
33
+ * `MountSteps.run` walks them, the order the test backend uses too. The first
34
+ * failing mount stops the run. Each `init` is its own transaction, so earlier
35
+ * mounts stay applied and a rerun converges.
61
36
  *
62
37
  * @internal
63
38
  */
@@ -75,38 +50,22 @@ export const run = Effect.fn("MountInit.run")(function* (
75
50
  ? error.errorMessage
76
51
  : error._tag,
77
52
  });
78
- if (!(yield* hasDeployModule(cwd).pipe(Effect.mapError(failed(STEPS)))))
53
+ if (
54
+ !(yield* hasDeployModule(cwd).pipe(
55
+ Effect.mapError(failed(MountSteps.STEPS)),
56
+ ))
57
+ )
79
58
  return;
80
59
  const client = yield* ConvexClient;
81
- const visit = (
82
- prefix: string | undefined,
83
- ): Effect.Effect<void, MountInitFailed> =>
84
- Effect.gen(function* () {
85
- const steps = yield* client
86
- .runFunction(url, key, STEPS, {}, prefix)
87
- .pipe(
88
- Effect.flatMap(Schema.decodeUnknownEffect(Steps)),
89
- Effect.mapError(failed(prefix ?? STEPS)),
90
- );
91
- for (const step of steps) {
92
- const mount =
93
- prefix === undefined
94
- ? step.componentPath
95
- : `${prefix}/${step.componentPath}`;
96
- if ("failure" in step)
97
- return yield* MountInitFailed.make({ mount, detail: step.failure });
98
- if (step.init !== null)
99
- yield* client
100
- .runFunction(
101
- url,
102
- key,
103
- step.init.functionName,
104
- step.init.args,
105
- mount,
106
- )
107
- .pipe(Effect.mapError(failed(mount)));
108
- if (step.nested) yield* visit(mount);
109
- }
110
- });
111
- yield* visit(undefined);
60
+ yield* MountSteps.run({
61
+ steps: (prefix) =>
62
+ client
63
+ .runFunction(url, key, MountSteps.STEPS, {}, prefix)
64
+ .pipe(Effect.mapError(failed(prefix ?? MountSteps.STEPS))),
65
+ init: (mount, functionName, args) =>
66
+ client
67
+ .runFunction(url, key, functionName, args, mount)
68
+ .pipe(Effect.mapError(failed(mount))),
69
+ failed: (mount, detail) => MountInitFailed.make({ mount, detail }),
70
+ });
112
71
  });
@@ -17,11 +17,14 @@ export class PushLockError extends Schema.TaggedError<
17
17
  >()("PushLockError", {
18
18
  deploymentName: Schema.String,
19
19
  reason: Schema.Literals(["configuration", "timeout", "filesystem"]),
20
+ missing: Schema.Literals(["PushLock"]).pipe(Schema.optionalKey),
20
21
  }) {
21
22
  override get message() {
22
23
  switch (this.reason) {
23
24
  case "configuration":
24
- return `Push lock for ${this.deploymentName} needs a home directory to keep its lock file in`;
25
+ return this.missing === "PushLock"
26
+ ? `Push lock for ${this.deploymentName} needs the PushLock service to be provided`
27
+ : `Push lock for ${this.deploymentName} needs a home directory to keep its lock file in`;
25
28
  case "timeout":
26
29
  return `Timed out waiting for another push to ${this.deploymentName} to release its push lock`;
27
30
  case "filesystem":