@gaganref/confect-alchemy 10.6.0-fork.2 → 10.6.0-fork.21

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.
@@ -29,10 +29,14 @@ declare const CommandError_base: Schema.Class<CommandError, Schema.TaggedStruct<
29
29
  readonly operation: Schema.Literals<readonly ["prepare", "deploy"]>;
30
30
  readonly reason: Schema.Literals<readonly ["configuration", "spawn", "exit"]>;
31
31
  readonly exitCode: Schema.optionalKey<Schema.Finite>;
32
+ readonly signal: Schema.optionalKey<Schema.String>;
33
+ readonly stdout: Schema.optionalKey<Schema.String>;
34
+ readonly stderr: Schema.optionalKey<Schema.String>;
32
35
  }>, import("effect/Cause").YieldableError & {
33
36
  readonly brand: unique symbol;
34
37
  }>;
35
38
  export declare class CommandError extends CommandError_base {
39
+ get message(): string;
36
40
  }
37
41
  declare const CommandRunner_base: Context.ServiceClass<CommandRunner, "@confect/alchemy/internal/CommandRunner", {
38
42
  readonly prepare: (command: PrepareCommand, cwd?: string) => Effect.Effect<void, CommandError>;
@@ -1 +1 @@
1
- {"version":3,"file":"CommandRunner.d.ts","sources":["../../src/internal/CommandRunner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAgB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEnE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ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AAK,gHAqMjB,CAAC"}
@@ -6,7 +6,14 @@ import * as Config from "effect/Config";
6
6
  import * as Context from "effect/Context";
7
7
  import * as Redacted from "effect/Redacted";
8
8
  import * as Schema from "effect/Schema";
9
+ import * as Stream from "effect/Stream";
10
+ import * as Str from "effect/String";
11
+ import * as Arr from "effect/Array";
12
+ import * as Result from "effect/Result";
13
+ import * as Deferred from "effect/Deferred";
9
14
  import { ChildProcess, ChildProcessSpawner } from "effect/process";
15
+ import { Buffer } from "node:buffer";
16
+ import { stripVTControlCharacters } from "node:util";
10
17
  // src/internal/CommandRunner.ts
11
18
  const selection = (target) => target._tag === "Cloud" ? `CONVEX_DEPLOY_KEY=${Redacted.value(target.deployKey)}\n` : `CONVEX_SELF_HOSTED_URL=${target.url}\nCONVEX_SELF_HOSTED_ADMIN_KEY=${Redacted.value(target.adminKey)}\n`;
12
19
  var CommandError = class extends Schema.TaggedError()("CommandError", {
@@ -16,8 +23,16 @@ var CommandError = class extends Schema.TaggedError()("CommandError", {
16
23
  "spawn",
17
24
  "exit"
18
25
  ]),
19
- exitCode: Schema.optionalKey(Schema.Finite)
20
- }) {};
26
+ exitCode: Schema.optionalKey(Schema.Finite),
27
+ signal: Schema.optionalKey(Schema.String),
28
+ stdout: Schema.optionalKey(Schema.String),
29
+ stderr: Schema.optionalKey(Schema.String)
30
+ }) {
31
+ get message() {
32
+ const status = this.signal === void 0 ? this.exitCode === void 0 ? this.reason : `exit code ${this.exitCode}` : `signal ${this.signal}`;
33
+ return `${this.operation} command failed (${status})${this.stdout === void 0 ? "" : `\nstdout:\n${this.stdout}`}${this.stderr === void 0 ? "" : `\nstderr:\n${this.stderr}`}`;
34
+ }
35
+ };
21
36
  var CommandRunner = class extends Context.Service()("@confect/alchemy/internal/CommandRunner") {};
22
37
  /**
23
38
  * The ambient variables a child process needs to run on every platform; the
@@ -50,6 +65,39 @@ const packageBin = Effect.fn("CommandRunner.packageBin")(function* (fs, path, cw
50
65
  directory = parent;
51
66
  }
52
67
  });
68
+ const outputTailSize = 8192;
69
+ const redaction = "<REDACTED>";
70
+ const minimumCredentialLength = 8;
71
+ const outputTail = (stream, secrets) => {
72
+ const credentials = Arr.flatMap(Arr.filter(secrets, (value) => value.length >= minimumCredentialLength), (value) => {
73
+ const bytes = Buffer.from(value);
74
+ return [value, ...Arr.flatMap(["base64", "base64url"], (encoding) => [Str.replace(/=+$/, "")(bytes.toString(encoding)), ...Arr.map([
75
+ 0,
76
+ 1,
77
+ 2
78
+ ], (offset) => Str.slice(Math.ceil(offset * 8 / 6), Math.floor((offset + bytes.length) * 8 / 6))(Buffer.concat([Buffer.alloc(offset), bytes]).toString(encoding)))])];
79
+ });
80
+ const percentEncoded = Arr.map(Arr.filter(secrets, (value) => value.length >= minimumCredentialLength), (value) => Arr.join(Arr.map(Str.split(/(%[0-9A-F]{2})/)(encodeURIComponent(value)), (part) => Str.startsWith("%")(part) ? Arr.join(Arr.map(Str.split("")(part), (char) => /[A-F]/.test(char) ? `[${char}${Str.toLowerCase(char)}]` : char), "") : Str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")(part)), ""));
81
+ return stream.pipe(Stream.decodeText(), Stream.runFold(() => ({
82
+ text: "",
83
+ truncated: false
84
+ }), (tail, chunk) => {
85
+ const text = tail.text + chunk;
86
+ return {
87
+ text: Str.slice(-8192)(text),
88
+ truncated: tail.truncated || text.length > outputTailSize
89
+ };
90
+ }), Effect.map(({ text, truncated }) => {
91
+ text = stripVTControlCharacters(text);
92
+ if (truncated) text = Str.replace(/^\S*/, "")(text);
93
+ const pattern = new RegExp(Arr.join([
94
+ "(?:prod|dev|preview|project|custom):[^\\s|]+\\|[^\\s\\\\\"'&)]+",
95
+ ...percentEncoded,
96
+ ...Arr.map(credentials, (value) => Str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")(value))
97
+ ], "|"), "g");
98
+ return Str.slice(-8192)(Str.replace(pattern, redaction)(text));
99
+ }));
100
+ };
53
101
  /**
54
102
  * @internal
55
103
  */
@@ -57,7 +105,45 @@ const layer = Layer.effect(CommandRunner, Effect.gen(function* () {
57
105
  const fs = yield* FileSystem.FileSystem;
58
106
  const path = yield* Path.Path;
59
107
  const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
60
- const run = Effect.fn("CommandRunner.run")(function* (operation, command, args, cwd, env) {
108
+ const run = Effect.fn("CommandRunner.run")(function* (operation, command, args, cwd, env, credentials = []) {
109
+ if (operation === "deploy") return yield* Effect.scoped(Effect.gen(function* () {
110
+ const child = yield* spawner.spawn(ChildProcess.make(command, args, {
111
+ cwd,
112
+ env,
113
+ extendEnv: false,
114
+ stdin: "ignore",
115
+ stdout: "pipe",
116
+ stderr: "pipe"
117
+ }));
118
+ const exited = yield* Deferred.make();
119
+ const drainDeadline = Deferred.await(exited).pipe(Effect.andThen(Effect.sleep("1 second")));
120
+ const [code, stdout, stderr] = yield* Effect.all([
121
+ child.exitCode.pipe(Effect.result, Effect.tap(() => Deferred.succeed(exited, void 0))),
122
+ outputTail(child.stdout.pipe(Stream.interruptWhen(drainDeadline)), credentials),
123
+ outputTail(child.stderr.pipe(Stream.interruptWhen(drainDeadline)), credentials)
124
+ ], { concurrency: "unbounded" });
125
+ if (Result.isFailure(code)) {
126
+ const cause = code.failure.cause;
127
+ const signal = cause instanceof Error ? /^Process interrupted due to receipt of signal: '(SIG[A-Z0-9]+)'$/.exec(cause.message)?.[1] : void 0;
128
+ return yield* CommandError.make({
129
+ operation,
130
+ reason: "exit",
131
+ ...signal === void 0 ? {} : { signal },
132
+ stdout,
133
+ stderr
134
+ });
135
+ }
136
+ if (code.success !== 0) return yield* CommandError.make({
137
+ operation,
138
+ reason: "exit",
139
+ exitCode: Number(code.success),
140
+ stdout,
141
+ stderr
142
+ });
143
+ })).pipe(Effect.mapError((error) => Schema.is(CommandError)(error) ? error : CommandError.make({
144
+ operation,
145
+ reason: "spawn"
146
+ })));
61
147
  const code = yield* spawner.exitCode(ChildProcess.make(command, args, {
62
148
  cwd,
63
149
  env,
@@ -115,7 +201,7 @@ const layer = Layer.effect(CommandRunner, Effect.gen(function* () {
115
201
  USERPROFILE: temp,
116
202
  LOCALAPPDATA: temp,
117
203
  XDG_CONFIG_HOME: temp
118
- });
204
+ }, [Redacted.value(target._tag === "Cloud" ? target.deployKey : target.adminKey)]);
119
205
  }).pipe(Effect.mapError((error) => Schema.is(CommandError)(error) ? error : CommandError.make({
120
206
  operation: "deploy",
121
207
  reason: "configuration"
@@ -1 +1 @@
1
- {"version":3,"file":"CommandRunner.js","names":[],"sources":["../../src/internal/CommandRunner.ts"],"sourcesContent":["import * as Config from \"effect/Config\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Layer from \"effect/Layer\";\nimport * as Path from \"effect/Path\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\n\nexport interface PrepareCommand {\n readonly command: string;\n readonly args: ReadonlyArray<string>;\n}\n\n/**\n * Where a push goes: a cloud deployment through its deploy key, or a local\n * backend through the CLI's self-hosted target and its admin key.\n */\nexport type PushTarget =\n | {\n readonly _tag: \"Cloud\";\n readonly deploymentName: string;\n readonly deployKey: Redacted.Redacted<string>;\n }\n | {\n readonly _tag: \"SelfHosted\";\n readonly deploymentName: string;\n readonly url: string;\n readonly adminKey: Redacted.Redacted<string>;\n };\n\nconst selection = (target: PushTarget) =>\n target._tag === \"Cloud\"\n ? `CONVEX_DEPLOY_KEY=${Redacted.value(target.deployKey)}\\n`\n : `CONVEX_SELF_HOSTED_URL=${target.url}\\nCONVEX_SELF_HOSTED_ADMIN_KEY=${Redacted.value(target.adminKey)}\\n`;\n\nexport class CommandError extends Schema.TaggedError<\n CommandError,\n { readonly brand: unique symbol }\n>()(\"CommandError\", {\n operation: Schema.Literals([\"prepare\", \"deploy\"]),\n reason: Schema.Literals([\"configuration\", \"spawn\", \"exit\"]),\n exitCode: Schema.optionalKey(Schema.Finite),\n}) {}\n\nexport class CommandRunner extends Context.Service<\n CommandRunner,\n {\n readonly prepare: (\n command: PrepareCommand,\n cwd?: string,\n ) => Effect.Effect<void, CommandError>;\n readonly deploy: (\n target: PushTarget,\n cwd?: string,\n ) => Effect.Effect<void, CommandError>;\n }\n>()(\"@confect/alchemy/internal/CommandRunner\") {}\n\n/**\n * The ambient variables a child process needs to run on every platform; the\n * rest of the parent environment, credentials included, is withheld.\n */\nexport const processEnvironment = Config.all({\n PATH: Config.String(\"PATH\").pipe(\n Config.orElse(() => Config.String(\"Path\")),\n Config.withDefault(\"\"),\n ),\n HOME: Config.String(\"HOME\").pipe(Config.withDefault(\"\")),\n USERPROFILE: Config.String(\"USERPROFILE\").pipe(Config.withDefault(\"\")),\n SystemRoot: Config.String(\"SystemRoot\").pipe(\n Config.orElse(() => Config.String(\"SYSTEMROOT\")),\n Config.withDefault(\"\"),\n ),\n TMPDIR: Config.String(\"TMPDIR\").pipe(Config.withDefault(\"\")),\n TEMP: Config.String(\"TEMP\").pipe(Config.withDefault(\"\")),\n});\n\nconst packageBin = Effect.fn(\"CommandRunner.packageBin\")(function* (\n fs: FileSystem.FileSystem,\n path: Path.Path,\n cwd: string,\n packageName: string,\n binName: string,\n) {\n const invalid = () =>\n CommandError.make({\n operation: packageName === \"convex\" ? \"deploy\" : \"prepare\",\n reason: \"configuration\",\n });\n let directory = cwd;\n while (true) {\n const manifestPath = path.join(\n directory,\n \"node_modules\",\n packageName,\n \"package.json\",\n );\n if (yield* fs.exists(manifestPath).pipe(Effect.mapError(invalid))) {\n const manifest = yield* fs.readFileString(manifestPath).pipe(\n Effect.flatMap(\n Schema.decodeEffect(\n Schema.fromJsonString(\n Schema.Struct({\n bin: Schema.Union([\n Schema.String,\n Schema.Record(Schema.String, Schema.String),\n ]),\n }),\n ),\n ),\n ),\n Effect.mapError(invalid),\n );\n const relative =\n typeof manifest.bin === \"string\" ? manifest.bin : manifest.bin[binName];\n if (relative === undefined || relative === \"\") return yield* invalid();\n return path.resolve(path.dirname(manifestPath), relative);\n }\n const parent = path.dirname(directory);\n if (parent === directory) return yield* invalid();\n directory = parent;\n }\n});\n\n/**\n * @internal\n */\nexport const layer = Layer.effect(\n CommandRunner,\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n const run = Effect.fn(\"CommandRunner.run\")(function* (\n operation: \"prepare\" | \"deploy\",\n command: string,\n args: ReadonlyArray<string>,\n cwd: string,\n env: Record<string, string | undefined>,\n ) {\n const code = yield* spawner\n .exitCode(\n ChildProcess.make(command, args, {\n cwd,\n env,\n extendEnv: false,\n stdin: \"ignore\",\n stdout: \"ignore\",\n stderr: \"ignore\",\n }),\n )\n .pipe(\n Effect.mapError(() =>\n CommandError.make({ operation, reason: \"spawn\" }),\n ),\n );\n if (code !== 0)\n return yield* CommandError.make({\n operation,\n reason: \"exit\",\n exitCode: Number(code),\n });\n });\n const environment = processEnvironment.pipe(\n Effect.map((env) => ({ ...env, CI: \"true\", DO_NOT_TRACK: \"1\" })),\n );\n return CommandRunner.of({\n prepare: Effect.fn(\"CommandRunner.prepare\")(function* (\n command,\n cwd = process.cwd(),\n ) {\n const directory = path.resolve(cwd);\n const env = yield* environment.pipe(\n Effect.mapError(() =>\n CommandError.make({\n operation: \"prepare\",\n reason: \"configuration\",\n }),\n ),\n );\n if (command.command === \"confect\") {\n const bin = yield* packageBin(\n fs,\n path,\n directory,\n \"@confect/cli\",\n \"confect\",\n );\n yield* run(\n \"prepare\",\n process.execPath,\n [bin, ...command.args],\n directory,\n env,\n );\n } else {\n yield* run(\"prepare\", command.command, command.args, directory, env);\n }\n }),\n deploy: Effect.fn(\"CommandRunner.deploy\")(function* (\n target,\n cwd = process.cwd(),\n ) {\n const directory = path.resolve(cwd);\n const bin = yield* packageBin(fs, path, directory, \"convex\", \"convex\");\n const env = yield* environment.pipe(\n Effect.mapError(() =>\n CommandError.make({\n operation: \"deploy\",\n reason: \"configuration\",\n }),\n ),\n );\n yield* Effect.scoped(\n Effect.gen(function* () {\n const temp = yield* fs.makeTempDirectoryScoped({\n prefix: \"confect-deploy-\",\n });\n const envFile = path.join(temp, \"deployment.env\");\n yield* fs.writeFileString(envFile, selection(target), {\n mode: 0o600,\n });\n yield* run(\n \"deploy\",\n process.execPath,\n [bin, \"deploy\", \"--yes\", \"--env-file\", envFile],\n directory,\n {\n ...env,\n HOME: temp,\n USERPROFILE: temp,\n LOCALAPPDATA: temp,\n XDG_CONFIG_HOME: temp,\n },\n );\n }).pipe(\n Effect.mapError((error) =>\n Schema.is(CommandError)(error)\n ? error\n : CommandError.make({\n operation: \"deploy\",\n reason: \"configuration\",\n }),\n ),\n ),\n );\n }),\n });\n }),\n);\n"],"mappings":";;;;;;;;;;AAgCA,MAAM,aAAa,WACjB,OAAO,SAAS,UACZ,qBAAqB,SAAS,MAAM,OAAO,SAAS,EAAE,MACtD,0BAA0B,OAAO,IAAI,iCAAiC,SAAS,MAAM,OAAO,QAAQ,EAAE;AAE5G,IAAa,eAAb,cAAkC,OAAO,YAGvC,CAAC,CAAC,gBAAgB;CAClB,WAAW,OAAO,SAAS,CAAC,WAAW,QAAQ,CAAC;CAChD,QAAQ,OAAO,SAAS;EAAC;EAAiB;EAAS;CAAM,CAAC;CAC1D,UAAU,OAAO,YAAY,OAAO,MAAM;AAC5C,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,gBAAb,cAAmC,QAAQ,QAYzC,CAAC,CAAC,yCAAyC,CAAC,CAAC,CAAC;;;;;AAMhD,MAAa,qBAAqB,OAAO,IAAI;CAC3C,MAAM,OAAO,OAAO,MAAM,CAAC,CAAC,KAC1B,OAAO,aAAa,OAAO,OAAO,MAAM,CAAC,GACzC,OAAO,YAAY,EAAE,CACvB;CACA,MAAM,OAAO,OAAO,MAAM,CAAC,CAAC,KAAK,OAAO,YAAY,EAAE,CAAC;CACvD,aAAa,OAAO,OAAO,aAAa,CAA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GAClC,MAAM,MAAM,OAAO,WAAW,IAAI,MAAM,WAAW,UAAU,QAAQ;GACrE,MAAM,MAAM,OAAO,YAAY,KAC7B,OAAO,eACL,aAAa,KAAK;IAChB,WAAW;IACX,QAAQ;GACV,CAAC,CACH,CACF;GACA,OAAO,OAAO,OACZ,OAAO,IAAI,aAAa;IACtB,MAAM,OAAO,OAAO,GAAG,wBAAwB,EAC7C,QAAQ,kBACV,CAAC;IACD,MAAM,UAAU,KAAK,KAAK,MAAM,gBAAgB;IAChD,OAAO,GAAG,gBAAgB,SAAS,UAAU,MAAM,GAAG,EACpD,MAAM,IACR,CAAC;IACD,OAAO,IACL,UACA,QAAQ,UACR;KAAC;KAAK;KAAU;KAAS;KAAc;IAAO,GAC9C,WACA;KACE,GAAG;KACH,MAAM;KACN,aAAa;KACb,cAAc;KACd,iBAAiB;IACnB,CACF;GACF,CAAC,CAAC,CAAC,KACD,OAAO,UAAU,UACf,OAAO,GAAG,YAAY,CAAC,CAAC,KAAK,IACzB,QACA,aAAa,KAAK;IAChB,WAAW;IACX,QAAQ;GACV,CAAC,CACP,CACF,CACF;EACF,CAAC;CACH,CAAC;AACH,CAAC,CACH"}
1
+ {"version":3,"file":"CommandRunner.js","names":[],"sources":["../../src/internal/CommandRunner.ts"],"sourcesContent":["import * as Arr from \"effect/Array\";\nimport * as Str from \"effect/String\";\nimport * as Config from \"effect/Config\";\nimport * as Context from \"effect/Context\";\nimport * as Deferred from \"effect/Deferred\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Layer from \"effect/Layer\";\nimport * as Path from \"effect/Path\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as Stream from \"effect/Stream\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\nimport { Buffer } from \"node:buffer\";\nimport { stripVTControlCharacters } from \"node:util\";\n\nexport interface PrepareCommand {\n readonly command: string;\n readonly args: ReadonlyArray<string>;\n}\n\n/**\n * Where a push goes: a cloud deployment through its deploy key, or a local\n * backend through the CLI's self-hosted target and its admin key.\n */\nexport type PushTarget =\n | {\n readonly _tag: \"Cloud\";\n readonly deploymentName: string;\n readonly deployKey: Redacted.Redacted<string>;\n }\n | {\n readonly _tag: \"SelfHosted\";\n readonly deploymentName: string;\n readonly url: string;\n readonly adminKey: Redacted.Redacted<string>;\n };\n\nconst selection = (target: PushTarget) =>\n target._tag === \"Cloud\"\n ? `CONVEX_DEPLOY_KEY=${Redacted.value(target.deployKey)}\\n`\n : `CONVEX_SELF_HOSTED_URL=${target.url}\\nCONVEX_SELF_HOSTED_ADMIN_KEY=${Redacted.value(target.adminKey)}\\n`;\n\nexport class CommandError extends Schema.TaggedError<\n CommandError,\n { readonly brand: unique symbol }\n>()(\"CommandError\", {\n operation: Schema.Literals([\"prepare\", \"deploy\"]),\n reason: Schema.Literals([\"configuration\", \"spawn\", \"exit\"]),\n exitCode: Schema.optionalKey(Schema.Finite),\n signal: Schema.optionalKey(Schema.String),\n stdout: Schema.optionalKey(Schema.String),\n stderr: Schema.optionalKey(Schema.String),\n}) {\n override get message(): string {\n const status =\n this.signal === undefined\n ? this.exitCode === undefined\n ? this.reason\n : `exit code ${this.exitCode}`\n : `signal ${this.signal}`;\n return `${this.operation} command failed (${status})${this.stdout === undefined ? \"\" : `\\nstdout:\\n${this.stdout}`}${this.stderr === undefined ? \"\" : `\\nstderr:\\n${this.stderr}`}`;\n }\n}\n\nexport class CommandRunner extends Context.Service<\n CommandRunner,\n {\n readonly prepare: (\n command: PrepareCommand,\n cwd?: string,\n ) => Effect.Effect<void, CommandError>;\n readonly deploy: (\n target: PushTarget,\n cwd?: string,\n ) => Effect.Effect<void, CommandError>;\n }\n>()(\"@confect/alchemy/internal/CommandRunner\") {}\n\n/**\n * The ambient variables a child process needs to run on every platform; the\n * rest of the parent environment, credentials included, is withheld.\n */\nexport const processEnvironment = Config.all({\n PATH: Config.String(\"PATH\").pipe(\n Config.orElse(() => Config.String(\"Path\")),\n Config.withDefault(\"\"),\n ),\n HOME: Config.String(\"HOME\").pipe(Config.withDefault(\"\")),\n USERPROFILE: Config.String(\"USERPROFILE\").pipe(Config.withDefault(\"\")),\n SystemRoot: Config.String(\"SystemRoot\").pipe(\n Config.orElse(() => Config.String(\"SYSTEMROOT\")),\n Config.withDefault(\"\"),\n ),\n TMPDIR: Config.String(\"TMPDIR\").pipe(Config.withDefault(\"\")),\n TEMP: Config.String(\"TEMP\").pipe(Config.withDefault(\"\")),\n});\n\nconst packageBin = Effect.fn(\"CommandRunner.packageBin\")(function* (\n fs: FileSystem.FileSystem,\n path: Path.Path,\n cwd: string,\n packageName: string,\n binName: string,\n) {\n const invalid = () =>\n CommandError.make({\n operation: packageName === \"convex\" ? \"deploy\" : \"prepare\",\n reason: \"configuration\",\n });\n let directory = cwd;\n while (true) {\n const manifestPath = path.join(\n directory,\n \"node_modules\",\n packageName,\n \"package.json\",\n );\n if (yield* fs.exists(manifestPath).pipe(Effect.mapError(invalid))) {\n const manifest = yield* fs.readFileString(manifestPath).pipe(\n Effect.flatMap(\n Schema.decodeEffect(\n Schema.fromJsonString(\n Schema.Struct({\n bin: Schema.Union([\n Schema.String,\n Schema.Record(Schema.String, Schema.String),\n ]),\n }),\n ),\n ),\n ),\n Effect.mapError(invalid),\n );\n const relative =\n typeof manifest.bin === \"string\" ? manifest.bin : manifest.bin[binName];\n if (relative === undefined || relative === \"\") return yield* invalid();\n return path.resolve(path.dirname(manifestPath), relative);\n }\n const parent = path.dirname(directory);\n if (parent === directory) return yield* invalid();\n directory = parent;\n }\n});\n\nconst outputTailSize = 8192;\nconst redaction = \"<REDACTED>\";\n// Short needles match common diagnostic text rather than useful credentials.\nconst minimumCredentialLength = 8;\n\nconst outputTail = <E>(\n stream: Stream.Stream<Uint8Array, E>,\n secrets: ReadonlyArray<string>,\n) => {\n const credentials = Arr.flatMap(\n Arr.filter(secrets, (value) => value.length >= minimumCredentialLength),\n (value: string) => {\n const bytes = Buffer.from(value);\n const base64 = Arr.flatMap(\n [\"base64\", \"base64url\"] as const,\n (encoding) => [\n Str.replace(/=+$/, \"\")(bytes.toString(encoding)),\n ...Arr.map([0, 1, 2], (offset) =>\n // The first and last partial sextets depend on bytes outside the key.\n Str.slice(\n Math.ceil((offset * 8) / 6),\n Math.floor(((offset + bytes.length) * 8) / 6),\n )(Buffer.concat([Buffer.alloc(offset), bytes]).toString(encoding)),\n ),\n ],\n );\n return [value, ...base64];\n },\n );\n const percentEncoded = Arr.map(\n Arr.filter(secrets, (value) => value.length >= minimumCredentialLength),\n (value) =>\n Arr.join(\n Arr.map(\n Str.split(/(%[0-9A-F]{2})/)(encodeURIComponent(value)),\n (part) =>\n Str.startsWith(\"%\")(part)\n ? Arr.join(\n Arr.map(Str.split(\"\")(part), (char) =>\n /[A-F]/.test(char)\n ? `[${char}${Str.toLowerCase(char)}]`\n : char,\n ),\n \"\",\n )\n : Str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")(part),\n ),\n \"\",\n ),\n );\n return stream.pipe(\n Stream.decodeText(),\n Stream.runFold(\n () => ({ text: \"\", truncated: false }),\n (tail, chunk) => {\n const text = tail.text + chunk;\n return {\n text: Str.slice(-outputTailSize)(text),\n truncated: tail.truncated || text.length > outputTailSize,\n };\n },\n ),\n Effect.map(({ text, truncated }) => {\n text = stripVTControlCharacters(text);\n if (truncated) {\n // A clipped token may be an unrecognised deploy key. Drop it whole.\n text = Str.replace(/^\\S*/, \"\")(text);\n }\n const pattern = new RegExp(\n Arr.join(\n [\n \"(?:prod|dev|preview|project|custom):[^\\\\s|]+\\\\|[^\\\\s\\\\\\\\\\\"'&)]+\",\n ...percentEncoded,\n ...Arr.map(credentials, (value) =>\n Str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")(value),\n ),\n ],\n \"|\",\n ),\n \"g\",\n );\n return Str.slice(-outputTailSize)(Str.replace(pattern, redaction)(text));\n }),\n );\n};\n\n/**\n * @internal\n */\nexport const layer = Layer.effect(\n CommandRunner,\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n const run = Effect.fn(\"CommandRunner.run\")(function* (\n operation: \"prepare\" | \"deploy\",\n command: string,\n args: ReadonlyArray<string>,\n cwd: string,\n env: Record<string, string | undefined>,\n credentials: ReadonlyArray<string> = [],\n ) {\n if (operation === \"deploy\") {\n return yield* Effect.scoped(\n Effect.gen(function* () {\n const child = yield* spawner.spawn(\n ChildProcess.make(command, args, {\n cwd,\n env,\n extendEnv: false,\n stdin: \"ignore\",\n stdout: \"pipe\",\n stderr: \"pipe\",\n }),\n );\n const exited = yield* Deferred.make<void>();\n // Descendants can inherit pipes and keep them open after the CLI exits.\n const drainDeadline = Deferred.await(exited).pipe(\n Effect.andThen(Effect.sleep(\"1 second\")),\n );\n const [code, stdout, stderr] = yield* Effect.all(\n [\n child.exitCode.pipe(\n Effect.result,\n Effect.tap(() => Deferred.succeed(exited, undefined)),\n ),\n outputTail(\n child.stdout.pipe(Stream.interruptWhen(drainDeadline)),\n credentials,\n ),\n outputTail(\n child.stderr.pipe(Stream.interruptWhen(drainDeadline)),\n credentials,\n ),\n ],\n { concurrency: \"unbounded\" },\n );\n if (Result.isFailure(code)) {\n // The spawner exposes a terminating signal only in its cause message.\n const cause = code.failure.cause;\n const signal =\n cause instanceof Error\n ? /^Process interrupted due to receipt of signal: '(SIG[A-Z0-9]+)'$/.exec(\n cause.message,\n )?.[1]\n : undefined;\n return yield* CommandError.make({\n operation,\n reason: \"exit\",\n ...(signal === undefined ? {} : { signal }),\n stdout,\n stderr,\n });\n }\n if (code.success !== 0)\n return yield* CommandError.make({\n operation,\n reason: \"exit\",\n exitCode: Number(code.success),\n stdout,\n stderr,\n });\n }),\n ).pipe(\n Effect.mapError((error) =>\n Schema.is(CommandError)(error)\n ? error\n : CommandError.make({ operation, reason: \"spawn\" }),\n ),\n );\n }\n const code = yield* spawner\n .exitCode(\n ChildProcess.make(command, args, {\n cwd,\n env,\n extendEnv: false,\n stdin: \"ignore\",\n stdout: \"ignore\",\n stderr: \"ignore\",\n }),\n )\n .pipe(\n Effect.mapError(() =>\n CommandError.make({ operation, reason: \"spawn\" }),\n ),\n );\n if (code !== 0)\n return yield* CommandError.make({\n operation,\n reason: \"exit\",\n exitCode: Number(code),\n });\n });\n const environment = processEnvironment.pipe(\n Effect.map((env) => ({ ...env, CI: \"true\", DO_NOT_TRACK: \"1\" })),\n );\n return CommandRunner.of({\n prepare: Effect.fn(\"CommandRunner.prepare\")(function* (\n command,\n cwd = process.cwd(),\n ) {\n const directory = path.resolve(cwd);\n const env = yield* environment.pipe(\n Effect.mapError(() =>\n CommandError.make({\n operation: \"prepare\",\n reason: \"configuration\",\n }),\n ),\n );\n if (command.command === \"confect\") {\n const bin = yield* packageBin(\n fs,\n path,\n directory,\n \"@confect/cli\",\n \"confect\",\n );\n yield* run(\n \"prepare\",\n process.execPath,\n [bin, ...command.args],\n directory,\n env,\n );\n } else {\n yield* run(\"prepare\", command.command, command.args, directory, env);\n }\n }),\n deploy: Effect.fn(\"CommandRunner.deploy\")(function* (\n target,\n cwd = process.cwd(),\n ) {\n const directory = path.resolve(cwd);\n const bin = yield* packageBin(fs, path, directory, \"convex\", \"convex\");\n const env = yield* environment.pipe(\n Effect.mapError(() =>\n CommandError.make({\n operation: \"deploy\",\n reason: \"configuration\",\n }),\n ),\n );\n yield* Effect.scoped(\n Effect.gen(function* () {\n const temp = yield* fs.makeTempDirectoryScoped({\n prefix: \"confect-deploy-\",\n });\n const envFile = path.join(temp, \"deployment.env\");\n yield* fs.writeFileString(envFile, selection(target), {\n mode: 0o600,\n });\n yield* run(\n \"deploy\",\n process.execPath,\n [bin, \"deploy\", \"--yes\", \"--env-file\", envFile],\n directory,\n {\n ...env,\n HOME: temp,\n USERPROFILE: temp,\n LOCALAPPDATA: temp,\n XDG_CONFIG_HOME: temp,\n },\n [\n Redacted.value(\n target._tag === \"Cloud\" ? target.deployKey : target.adminKey,\n ),\n ],\n );\n }).pipe(\n Effect.mapError((error) =>\n Schema.is(CommandError)(error)\n ? error\n : CommandError.make({\n operation: \"deploy\",\n reason: \"configuration\",\n }),\n ),\n ),\n );\n }),\n });\n }),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;AAuCA,MAAM,aAAa,WACjB,OAAO,SAAS,UACZ,qBAAqB,SAAS,MAAM,OAAO,SAAS,EAAE,MACtD,0BAA0B,OAAO,IAAI,iCAAiC,SAAS,MAAM,OAAO,QAAQ,EAAE;AAE5G,IAAa,eAAb,cAAkC,OAAO,YAGvC,CAAC,CAAC,gBAAgB;CAClB,WAAW,OAAO,SAAS,CAAC,WAAW,QAAQ,CAAC;CAChD,QAAQ,OAAO,SAAS;EAAC;EAAiB;EAAS;CAAM,CAAC;CAC1D,UAAU,OAAO,YAAY,OAAO,MAAM;CAC1C,QAAQ,OAAO,YAAY,OAAO,MAAM;CACxC,QAAQ,OAAO,YAAY,OAAO,MAAM;CACxC,QAAQ,OAAO,YAAY,OAAO,MAAM;AAC1C,CAAC,CAAC,CAAC;CACD,IAAa,UAAkB;EAC7B,MAAM,SACJ,KAAK,WAAW,KAAA,IACZ,KAAK,aAAa,KAAA,IAChB,KAAK,SACL,aAAa,KAAK,aACpB,UAAU,KAAK;EACrB,OAAO,GAAG,KAAK,UAAU,mBAAmB,OAAO,GAAG,KAAK,WAAW,KAAA,IAAY,KAAK,cAAc,KAAK,WAAW,KAAK,WAAW,KAAA,IAAY,KAAK,cAAc,KAAK;CAC3K;AACF;AAEA,IAAa,gBAAb,cAAmC,QAAQ,QAYzC,CAAC,CAAC,yCAAyC,CAAC,CAAC,CAAC;;;;;AAMhD,MAAa,qBAAqB,OAAO,IAAI;CAC3C,MAAM,OAAO,OAAO,MAAM,CAAC,CAAC,KAC1B,OAAO,aAAa,OAAO,OAAO,MAAM,CAAC,GACzC,OAAO,YAAY,EAAE,CACvB;CACA,MA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UACf,OAAO,GAAG,YAAY,CAAC,CAAC,KAAK,IACzB,QACA,aAAa,KAAK;IAChB,WAAW;IACX,QAAQ;GACV,CAAC,CACP,CACF,CACF;EACF,CAAC;CACH,CAAC;AACH,CAAC,CACH"}
@@ -9,11 +9,13 @@ import * as Path from "effect/Path";
9
9
  import * as Config from "effect/Config";
10
10
  import * as Redacted from "effect/Redacted";
11
11
  import * as Schema from "effect/Schema";
12
+ import * as Stream from "effect/Stream";
12
13
  import * as HttpClient from "effect/http/HttpClient";
13
14
  import * as Option from "effect/Option";
14
15
  import * as Str from "effect/String";
15
16
  import { pipe } from "effect/Function";
16
17
  import * as Array from "effect/Array";
18
+ import * as Deferred from "effect/Deferred";
17
19
  import { ChildProcess, ChildProcessSpawner } from "effect/process";
18
20
  import * as SecureRandom from "effect/crypto/SecureRandom";
19
21
  import * as Scope from "effect/Scope";
@@ -21,10 +23,8 @@ import * as Schedule from "effect/Schedule";
21
23
  import { dotAlchemyDirectory } from "alchemy/AlchemyContext";
22
24
  import { Stack } from "alchemy/Stack";
23
25
  import { createServer } from "node:net";
24
- import * as Deferred from "effect/Deferred";
25
26
  import * as Exit from "effect/Exit";
26
27
  import * as Semaphore from "effect/Semaphore";
27
- import * as Stream from "effect/Stream";
28
28
  // src/internal/LocalBackend.ts
29
29
  /**
30
30
  * The backend release a new local deployment runs. An existing data directory
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@gaganref/confect-alchemy",
3
- "version": "10.6.0-fork.2",
3
+ "version": "10.6.0-fork.21",
4
4
  "dependencies": {
5
5
  "@convex-dev/platform": "^0.1.10"
6
6
  },
7
7
  "peerDependencies": {
8
- "@confect/cli": "npm:@gaganref/confect-cli@10.6.0-fork.2",
9
- "@confect/core": "npm:@gaganref/confect-core@10.6.0-fork.2",
10
- "alchemy": "2.0.0-beta.86",
8
+ "@confect/cli": "npm:@gaganref/confect-cli@10.6.0-fork.21",
9
+ "@confect/core": "npm:@gaganref/confect-core@10.6.0-fork.21",
10
+ "alchemy": ">=2.0.0-beta.85 <2.0.0",
11
11
  "convex": "^1.32.0",
12
12
  "effect": "~4.1.4"
13
13
  },
@@ -7,6 +7,7 @@ import * as Effect from "effect/Effect";
7
7
  import * as Layer from "effect/Layer";
8
8
  import * as Redacted from "effect/Redacted";
9
9
  import * as Schema from "effect/Schema";
10
+ import * as Stream from "effect/Stream";
10
11
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
11
12
  import * as HttpClient from "effect/http/HttpClient";
12
13
  import * as HttpClientRequest from "effect/http/HttpClientRequest";
@@ -36,11 +37,11 @@ export type UpdateProjectInput = Pick<
36
37
  >;
37
38
  export type CreateDeploymentInput = Pick<
38
39
  ManagementApi.PlatformCreateDeploymentArgs,
39
- "type" | "region" | "class"
40
+ "type" | "region" | "class" | "expiresAt"
40
41
  > & { readonly reference: string };
41
42
  export type UpdateDeploymentInput = Pick<
42
43
  ManagementApi.PlatformUpdateDeploymentArgs,
43
- "reference" | "expiresAt" | "sendLogsToClient"
44
+ "reference" | "expiresAt" | "sendLogsToClient" | "class"
44
45
  >;
45
46
  export type CreateDeployKeyInput = ManagementApi.PlatformCreateDeployKeyArgs;
46
47
  export type CreatedDeployKey = {
@@ -68,6 +69,7 @@ export type EnvironmentVariables = Readonly<
68
69
  const errorFields = {
69
70
  operation: Schema.String,
70
71
  status: Schema.optionalKey(Schema.Finite),
72
+ serverCode: Schema.optionalKey(Schema.String),
71
73
  code: Schema.Literals([
72
74
  "HttpError",
73
75
  "TransportError",
@@ -78,20 +80,45 @@ const errorFields = {
78
80
  ]),
79
81
  };
80
82
 
83
+ const errorMessage = (error: {
84
+ readonly operation: string;
85
+ readonly status?: number;
86
+ readonly code: string;
87
+ readonly serverCode?: string;
88
+ }) => {
89
+ const classification =
90
+ error.status === undefined ? error.code : `${error.status}, ${error.code}`;
91
+ const serverCode =
92
+ error.serverCode === undefined ? "" : `, ${error.serverCode}`;
93
+ return `${error.operation} failed (${classification}${serverCode})`;
94
+ };
95
+
81
96
  export class ConvexApiError extends Schema.TaggedError<
82
97
  ConvexApiError,
83
98
  { readonly brand: unique symbol }
84
- >()("ConvexApiError", errorFields) {}
99
+ >()("ConvexApiError", errorFields) {
100
+ override get message() {
101
+ return errorMessage(this);
102
+ }
103
+ }
85
104
 
86
105
  export class ConvexNotFound extends Schema.TaggedError<
87
106
  ConvexNotFound,
88
107
  { readonly brand: unique symbol }
89
- >()("ConvexNotFound", errorFields) {}
108
+ >()("ConvexNotFound", errorFields) {
109
+ override get message() {
110
+ return errorMessage(this);
111
+ }
112
+ }
90
113
 
91
114
  export class ConvexConflict extends Schema.TaggedError<
92
115
  ConvexConflict,
93
116
  { readonly brand: unique symbol }
94
- >()("ConvexConflict", errorFields) {}
117
+ >()("ConvexConflict", errorFields) {
118
+ override get message() {
119
+ return errorMessage(this);
120
+ }
121
+ }
95
122
 
96
123
  /**
97
124
  * A function the deployment ran failed, with the message Convex reports.
@@ -200,6 +227,52 @@ const ProjectsPageSchema = Schema.Struct({
200
227
  }),
201
228
  });
202
229
 
230
+ // Retain at most 8 KiB before parsing an error body. Stop the stream on overflow.
231
+ const maxErrorBodyBytes = 8 * 1024;
232
+ const httpFailure = Effect.fn("ConvexClient.httpFailure")(function* (
233
+ operation: string,
234
+ response: HttpClientResponse.HttpClientResponse,
235
+ ) {
236
+ const fallback = ConvexApiError.make({
237
+ operation,
238
+ status: response.status,
239
+ code: "HttpError",
240
+ });
241
+ const serverCode = yield* response.stream.pipe(
242
+ Stream.mapAccum(
243
+ () => 0,
244
+ (size, bytes) => {
245
+ const total = size + bytes.byteLength;
246
+ return [total, [{ size: total, bytes }]] as const;
247
+ },
248
+ ),
249
+ Stream.mapEffect(({ size, bytes }) =>
250
+ size > maxErrorBodyBytes ? Effect.fail(fallback) : Effect.succeed(bytes),
251
+ ),
252
+ Stream.mkArrayBuffer,
253
+ Effect.timeout("5 seconds"),
254
+ Effect.map((bytes) => new TextDecoder().decode(bytes)),
255
+ Effect.flatMap(
256
+ Schema.decodeEffect(
257
+ Schema.fromJsonString(Schema.Struct({ code: Schema.String })),
258
+ ),
259
+ ),
260
+ Effect.map(({ code }) =>
261
+ /^[A-Za-z][A-Za-z0-9]{0,63}$/.test(code) ? code : undefined,
262
+ ),
263
+ Effect.orElseSucceed(() => undefined),
264
+ );
265
+ const fields = {
266
+ operation,
267
+ status: response.status,
268
+ code: "HttpError" as const,
269
+ ...(serverCode === undefined ? {} : { serverCode }),
270
+ };
271
+ if (response.status === 404) return yield* ConvexNotFound.make(fields);
272
+ if (response.status === 409) return yield* ConvexConflict.make(fields);
273
+ return yield* ConvexApiError.make(fields);
274
+ });
275
+
203
276
  const make = Effect.fn("ConvexClient.make")(function* (options?: {
204
277
  readonly token?: Redacted.Redacted<string>;
205
278
  readonly mode?: ProviderMode;
@@ -249,27 +322,8 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
249
322
  ConvexApiError.make({ operation, code: "TransportError" }),
250
323
  ),
251
324
  );
252
- if (response.status === 404) {
253
- return yield* ConvexNotFound.make({
254
- operation,
255
- status: 404,
256
- code: "HttpError",
257
- });
258
- }
259
- if (response.status === 409) {
260
- return yield* ConvexConflict.make({
261
- operation,
262
- status: 409,
263
- code: "HttpError",
264
- });
265
- }
266
- if (response.status < 200 || response.status >= 300) {
267
- return yield* ConvexApiError.make({
268
- operation,
269
- status: response.status,
270
- code: "HttpError",
271
- });
272
- }
325
+ if (response.status < 200 || response.status >= 300)
326
+ return yield* httpFailure(operation, response);
273
327
  return response;
274
328
  });
275
329
 
@@ -402,11 +456,7 @@ const make = Effect.fn("ConvexClient.make")(function* (options?: {
402
456
  );
403
457
  // Convex answers a function that threw with 560 and its message.
404
458
  if (response.status !== 200 && response.status !== 560)
405
- return yield* ConvexApiError.make({
406
- operation,
407
- status: response.status,
408
- code: "HttpError",
409
- });
459
+ return yield* httpFailure(operation, response);
410
460
  const result = yield* decode(operation, response, FunctionResponse);
411
461
  if (result.status === "error")
412
462
  return yield* ConvexFunctionError.make({
package/src/Deployment.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  CreateDeploymentType,
3
+ DeploymentClass,
3
4
  PlatformDeploymentResponse,
4
5
  RegionName,
5
6
  } from "@convex-dev/platform/managementApi";
@@ -25,6 +26,12 @@ export interface DeploymentProps {
25
26
  readonly type: CreateDeploymentType;
26
27
  readonly reference?: string;
27
28
  readonly region?: RegionName;
29
+ readonly class?: DeploymentClass;
30
+ /**
31
+ * Safe integer milliseconds since the Unix epoch. Omit to preserve the
32
+ * current cloud expiry; only null clears it.
33
+ */
34
+ readonly expiresAt?: number | null;
28
35
  }
29
36
 
30
37
  export interface DeploymentAttributes {
@@ -37,6 +44,14 @@ export interface DeploymentAttributes {
37
44
  * Always set in the cloud; a local deployment echoes the requested region.
38
45
  */
39
46
  readonly region?: RegionName;
47
+ /**
48
+ * Always set in the cloud; local deployments do not have a cloud class.
49
+ */
50
+ readonly class?: string;
51
+ /**
52
+ * Cloud expiry in milliseconds since the Unix epoch, or null when unset.
53
+ */
54
+ readonly expiresAt?: number | null;
40
55
  }
41
56
 
42
57
  export type Deployment = Resource<
@@ -73,6 +88,26 @@ export class AmbiguousDeployment extends Schema.TaggedError<
73
88
  reference: Schema.String,
74
89
  }) {}
75
90
 
91
+ export class InvalidDeploymentExpiry extends Schema.TaggedError<
92
+ InvalidDeploymentExpiry,
93
+ { readonly brand: unique symbol }
94
+ >()("InvalidDeploymentExpiry", {
95
+ requested: Schema.String,
96
+ }) {
97
+ override get message() {
98
+ return "Deployment expiresAt must be a safe integer timestamp in milliseconds, or null to clear the expiry.";
99
+ }
100
+ }
101
+
102
+ const validateExpiry = Effect.fn("Deployment.validateExpiry")(function* ({
103
+ expiresAt,
104
+ }: DeploymentProps) {
105
+ if (expiresAt != null && !Number.isSafeInteger(expiresAt))
106
+ return yield* InvalidDeploymentExpiry.make({
107
+ requested: String(expiresAt),
108
+ });
109
+ });
110
+
76
111
  export const provider = Effect.gen(function* () {
77
112
  const client = yield* ConvexClient;
78
113
  const attributes = Effect.fn("Deployment.attributes")(function* (
@@ -89,6 +124,8 @@ export const provider = Effect.gen(function* () {
89
124
  type: deployment.deploymentType,
90
125
  url: deployment.deploymentUrl,
91
126
  region: deployment.region,
127
+ class: deployment.class,
128
+ expiresAt: deployment.expiresAt ?? null,
92
129
  } satisfies DeploymentAttributes;
93
130
  });
94
131
  const find = Effect.fn("Deployment.find")(function* (
@@ -121,7 +158,10 @@ export const provider = Effect.gen(function* () {
121
158
  });
122
159
  return {
123
160
  diff: Effect.fn("Deployment.diff")(function* ({ news, output }) {
124
- if (!isResolved(news) || output === undefined) return;
161
+ if (!isResolved(news)) return;
162
+ yield* validateExpiry(news);
163
+ if (output === undefined) return;
164
+ const expiresAt = news.expiresAt;
125
165
  yield* validate(output, news);
126
166
  const deployment = yield* client
127
167
  .getDeployment(output.name)
@@ -129,7 +169,11 @@ export const provider = Effect.gen(function* () {
129
169
  if (deployment === undefined) return { action: "update" };
130
170
  const current = yield* attributes(deployment);
131
171
  yield* validate(current, news);
132
- if ((news.reference ?? output.reference) !== current.reference)
172
+ if (
173
+ (news.reference ?? output.reference) !== current.reference ||
174
+ (news.class !== undefined && news.class !== current.class) ||
175
+ (expiresAt !== undefined && expiresAt !== (current.expiresAt ?? null))
176
+ )
133
177
  return { action: "update" };
134
178
  }),
135
179
  read: Effect.fn("Deployment.read")(function* ({
@@ -161,6 +205,7 @@ export const provider = Effect.gen(function* () {
161
205
  news,
162
206
  output,
163
207
  }) {
208
+ yield* validateExpiry(news);
164
209
  if (output === undefined) yield* checkpointCreate(fqn, instanceId, news);
165
210
  if (output !== undefined) yield* validate(output, news);
166
211
  let deployment =
@@ -173,6 +218,7 @@ export const provider = Effect.gen(function* () {
173
218
  news.reference ??
174
219
  output?.reference ??
175
220
  (yield* resourceName("deployment", fqn, instanceId));
221
+ const expiresAt = news.expiresAt;
176
222
  if (deployment === undefined) {
177
223
  const existing = yield* find(news.projectId, reference);
178
224
  if (existing !== undefined && !(yield* shouldAdopt(fqn)))
@@ -191,21 +237,36 @@ export const provider = Effect.gen(function* () {
191
237
  type: news.type,
192
238
  reference,
193
239
  ...(news.region === undefined ? {} : { region: news.region }),
240
+ ...(news.class === undefined ? {} : { class: news.class }),
241
+ ...(expiresAt === undefined ? {} : { expiresAt }),
194
242
  });
195
243
  }
196
244
  }
197
245
  const current = yield* attributes(deployment);
198
246
  yield* validate(current, news);
199
- if (current.reference !== reference) {
200
- const existing = yield* find(news.projectId, reference);
201
- if (existing !== undefined && existing.name !== current.name)
202
- return yield* new OwnedBySomeoneElse({
203
- message: "The requested deployment reference is already in use.",
204
- resourceType: Deployment.Type,
205
- physicalName: reference,
206
- });
247
+ if (
248
+ current.reference !== reference ||
249
+ (news.class !== undefined && news.class !== current.class) ||
250
+ (expiresAt !== undefined && expiresAt !== (current.expiresAt ?? null))
251
+ ) {
252
+ if (current.reference !== reference) {
253
+ const existing = yield* find(news.projectId, reference);
254
+ if (existing !== undefined && existing.name !== current.name)
255
+ return yield* new OwnedBySomeoneElse({
256
+ message: "The requested deployment reference is already in use.",
257
+ resourceType: Deployment.Type,
258
+ physicalName: reference,
259
+ });
260
+ }
207
261
  yield* client.updateDeployment(current.name, {
208
262
  reference,
263
+ ...(news.class === undefined || news.class === current.class
264
+ ? {}
265
+ : { class: news.class }),
266
+ ...(expiresAt === undefined ||
267
+ expiresAt === (current.expiresAt ?? null)
268
+ ? {}
269
+ : { expiresAt }),
209
270
  });
210
271
  deployment = yield* client.getDeployment(current.name);
211
272
  }
@@ -221,7 +282,7 @@ export const provider = Effect.gen(function* () {
221
282
 
222
283
  interface LocalConfig {
223
284
  readonly name: string;
224
- readonly props: DeploymentProps;
285
+ readonly props: Omit<DeploymentProps, "class" | "expiresAt">;
225
286
  }
226
287
 
227
288
  /**
@@ -248,9 +309,10 @@ export const localLayer = LocalProvider.make(
248
309
  instanceId,
249
310
  news,
250
311
  }) {
312
+ const { class: _class, expiresAt: _expiresAt, ...props } = news;
251
313
  return {
252
314
  name: yield* resourceName("deployment", fqn, instanceId),
253
- props: news,
315
+ props,
254
316
  } satisfies LocalConfig;
255
317
  }),
256
318
  start: Effect.fn("Deployment.localStart")(function* ({