@deslop/deploy 0.1.1259 → 0.1.1261

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/dist/server.js CHANGED
@@ -4502,6 +4502,63 @@ const flatMapNullishOr = /*#__PURE__*/ dual(2, (self, f) => isNone(self) ? none(
4502
4502
  */
4503
4503
  const flatten$5 = /*#__PURE__*/ flatMap$7(identity);
4504
4504
  /**
4505
+ * Combines a structure of `Option`s (tuple, struct, or iterable) into a single
4506
+ * `Option` containing the unwrapped structure.
4507
+ *
4508
+ * **When to use**
4509
+ *
4510
+ * Use when you need to combine multiple `Option` values into one while
4511
+ * preserving the input shape, with any `None` making the result `None`.
4512
+ *
4513
+ * **Details**
4514
+ *
4515
+ * - Tuple input → `Option` of a tuple with the same length
4516
+ * - Struct input → `Option` of a struct with the same keys
4517
+ * - Iterable input → `Option` of an `Array`
4518
+ * - Any `None` in the input → entire result is `None`
4519
+ *
4520
+ * **Example** (Combining a tuple and a struct)
4521
+ *
4522
+ * ```ts import.meta.vitest
4523
+ * import { Option } from "effect"
4524
+ *
4525
+ * const maybeName: Option.Option<string> = Option.some("John")
4526
+ * const maybeAge: Option.Option<number> = Option.some(25)
4527
+ *
4528
+ * // ┌─── Option<[string, number]>
4529
+ * // ▼
4530
+ * const tuple = Option.all([maybeName, maybeAge]) // => Option.some(["John", 25])
4531
+ *
4532
+ * // ┌─── Option<{ name: string; age: number; }>
4533
+ * // ▼
4534
+ * const struct = Option.all({ name: maybeName, age: maybeAge }) // => Option.some({ name: "John", age: 25 })
4535
+ * ```
4536
+ *
4537
+ * @see {@link product} for combining exactly two
4538
+ * @see {@link productMany} for a homogeneous collection
4539
+ *
4540
+ * @stability stable
4541
+ * @category combining
4542
+ * @since 2.0.0
4543
+ */
4544
+ const all$4 = (input) => {
4545
+ if (Symbol.iterator in input) {
4546
+ const out = [];
4547
+ for (const o of input) {
4548
+ if (isNone(o)) return none();
4549
+ out.push(o.value);
4550
+ }
4551
+ return some$1(out);
4552
+ }
4553
+ const out = {};
4554
+ for (const key of Object.keys(input)) {
4555
+ const o = input[key];
4556
+ if (isNone(o)) return none();
4557
+ assignProperty(out, key, o.value);
4558
+ }
4559
+ return some$1(out);
4560
+ };
4561
+ /**
4505
4562
  * Converts an `Option` into an `Array`.
4506
4563
  *
4507
4564
  * **When to use**
@@ -5924,6 +5981,51 @@ const findFirst$1 = /*#__PURE__*/ dual(2, (self, f) => {
5924
5981
  }
5925
5982
  return none();
5926
5983
  });
5984
+ /**
5985
+ * Finds the last element for which a predicate holds.
5986
+ *
5987
+ * **Example** (Finding the last match)
5988
+ *
5989
+ * ```ts import.meta.vitest
5990
+ * import { Iterable, Option } from "effect"
5991
+ *
5992
+ * const numbers = [1, 3, 4, 6, 8, 2]
5993
+ * const lastEven = Iterable.findLast(numbers, (x) => x % 2 === 0)
5994
+ * lastEven // => Option.some(2)
5995
+ *
5996
+ * const lastGreaterThan10 = Iterable.findLast(numbers, (x) => x > 10)
5997
+ * lastGreaterThan10 // => Option.none()
5998
+ *
5999
+ * // With index
6000
+ * const letters = ["a", "b", "c", "d", "e"]
6001
+ * const lastAtEvenIndex = Iterable.findLast(letters, (_, i) => i % 2 === 0)
6002
+ * lastAtEvenIndex // => Option.some("e")
6003
+ *
6004
+ * // Type refinement
6005
+ * const mixed: Array<string | number> = [1, "hello", 2, "world", 3]
6006
+ * const lastString = Iterable.findLast(
6007
+ * mixed,
6008
+ * (x): x is string => typeof x === "string"
6009
+ * )
6010
+ * lastString // => Option.some("world")
6011
+ * ```
6012
+ *
6013
+ * @stability stable
6014
+ * @category searching
6015
+ * @since 2.0.0
6016
+ */
6017
+ const findLast$1 = /*#__PURE__*/ dual(2, (self, f) => {
6018
+ let i = 0;
6019
+ let last = none();
6020
+ for (const a of self) {
6021
+ const o = f(a, i);
6022
+ if (isBoolean$1(o)) {
6023
+ if (o) last = some$1(a);
6024
+ } else if (isSome(o)) last = o;
6025
+ i++;
6026
+ }
6027
+ return last;
6028
+ });
5927
6029
  const constEmpty = { [Symbol.iterator]() {
5928
6030
  return constEmptyIterator;
5929
6031
  } };
@@ -89971,6 +90073,9 @@ function layerOtlp(serviceName, url, runtime, version) {
89971
90073
  const ISSUER_PATH = "/api/auth";
89972
90074
  const APPS_PATH = "/api/apps";
89973
90075
  const SESSION_COOKIE = "__Host-session";
90076
+ function matchingSessions(saved, userId) {
90077
+ return sort(filter$3(getSomes(saved), (session) => session.value.user.id === userId), mapInput(flip$1(Number$6), (session) => session.value.expiresAt));
90078
+ }
89974
90079
  function bearerOf(headers) {
89975
90080
  return flatMapNullishOr(match$3(/^bearer +(?<token>\S+) *$/iu)(headers["authorization"] ?? ""), (found) => found.groups?.["token"]);
89976
90081
  }
@@ -91024,8 +91129,7 @@ var Sessions = class Sessions extends Service$1()("@deslop/runtime/auth/sessions
91024
91129
  key,
91025
91130
  value
91026
91131
  }))), { concurrency: "unbounded" });
91027
- const candidates = sort(filter$3(getSomes(saved), (session) => session.value.user.id === userId), mapInput(flip$1(Number$6), (session) => session.value.expiresAt));
91028
- for (const session of candidates) {
91132
+ for (const session of matchingSessions(saved, userId)) {
91029
91133
  if (yield* fresh(session.value)) return session.value.access;
91030
91134
  const renewed = yield* result$1(pipe(refreshed(session.key), rejected("AI access is temporarily unavailable")));
91031
91135
  if (renewed._tag === "Success") return renewed.success.access;
@@ -92186,6 +92290,33 @@ const SIGNALS = {
92186
92290
  11: "SIGSEGV",
92187
92291
  15: "SIGTERM"
92188
92292
  };
92293
+ function socketLine(line) {
92294
+ const fields = split$2(trim(line), /\s+/u);
92295
+ const address = fields[4] ?? "";
92296
+ return map$11(parse$3(getOrElse(last(split$2(address, ":")), () => "")), (port) => ({
92297
+ address,
92298
+ pid: map$11(match$3(/pid=([0-9]+)/u)(line), (match) => match[1]),
92299
+ port,
92300
+ process: map$11(match$3(/users:\(\("([^"]+)",pid=([0-9]+)/u)(line), (match) => ({
92301
+ name: match[1] ?? "",
92302
+ pid: match[2]
92303
+ })),
92304
+ protocol: fields[0],
92305
+ state: fields[1] ?? "listening"
92306
+ }));
92307
+ }
92308
+ function socketUnit(cgroup) {
92309
+ return getOrElse(map$11(findLast$1(matchAll(/\/([^/]+\.service)(?=\/|\n|$)/gu)(cgroup), () => true), (match) => match[1] ?? ""), () => "");
92310
+ }
92311
+ function socketProcess(name, cwd) {
92312
+ return match$8(match$3(/\/apps\/([^/]+)(?:\/|$)/u)(cwd), {
92313
+ onNone: () => name,
92314
+ onSome: (app) => app[1] ?? ""
92315
+ });
92316
+ }
92317
+ function probeSocket(listener, process) {
92318
+ return listener.protocol === "tcp" && listener.port >= 1024 && isSome(match$3(/^(?:127\.0\.0\.1|0\.0\.0\.0):/u)(listener.address)) && isNone(match$3(/^(?:postgres|redis|ssh|cloudflared|tailscaled|caddy)$/u)(process));
92319
+ }
92189
92320
  function failureReason(result, status, ran) {
92190
92321
  if (result === "exit-code" && !ran) return "Failed before starting";
92191
92322
  const signal = SIGNALS[status] ?? `signal ${status}`;
@@ -92334,31 +92465,24 @@ function attachProcesses(items, records) {
92334
92465
  }
92335
92466
  // src/services/inventory/service.ts
92336
92467
  function portItems(text, worker, fs, http) {
92337
- return forEach$1(filter$3(split$2(trim(text), "\n"), isNonEmpty$1), fnUntraced(function* (line) {
92338
- const fields = split$2(trim(line), /\s+/u);
92339
- const address = fields[4] ?? "";
92340
- const port = getOrElse(parse$3(getOrElse(last(split$2(address, ":")), () => "")), () => 0);
92341
- const cgroup = yield* match$8(match$3(/pid=([0-9]+)/u)(line), {
92468
+ return forEach$1(getSomes(map$8(split$2(trim(text), "\n"), socketLine)), fnUntraced(function* (socket) {
92469
+ const unit = socketUnit(yield* match$8(socket.pid, {
92342
92470
  onNone: () => succeed$5(""),
92343
- onSome: fnUntraced(function* (match) {
92344
- return getOrElse(yield* option$1(fs.readFileString(`/proc/${match[1]}/cgroup`)), () => "");
92471
+ onSome: fnUntraced(function* (pid) {
92472
+ return getOrElse(yield* option$1(fs.readFileString(`/proc/${pid}/cgroup`)), () => "");
92345
92473
  })
92346
- });
92347
- const unit = getOrElse(last(fromIterable$7(matchAll(/\/([^/]+\.service)(?=\/|\n|$)/gu)(cgroup))), () => ["", ""])[1] ?? "";
92348
- const process = yield* match$8(match$3(/users:\(\("([^"]+)",pid=([0-9]+)/u)(line), {
92474
+ }));
92475
+ const process = yield* match$8(socket.process, {
92349
92476
  onNone: () => succeed$5(""),
92350
92477
  onSome: fnUntraced(function* (match) {
92351
- if (!startsWith("node")(match[1] ?? "")) return match[1] ?? "";
92352
- return yield* pipe(fs.readLink(`/proc/${match[2]}/cwd`), map$5((cwd) => match$8(match$3(/\/apps\/([^/]+)(?:\/|$)/u)(cwd), {
92353
- onNone: () => match[1] ?? "",
92354
- onSome: (app) => app[1] ?? ""
92355
- })), orElseSucceed(() => match[1] ?? ""));
92478
+ if (!startsWith("node")(match.name)) return match.name;
92479
+ return yield* pipe(fs.readLink(`/proc/${match.pid}/cwd`), map$5((cwd) => socketProcess(match.name, cwd)), orElseSucceed(() => match.name));
92356
92480
  })
92357
92481
  });
92358
- const response = yield* match$1(fields[0] === "tcp" && port >= 1024 && isSome(match$3(/^(?:127\.0\.0\.1|0\.0\.0\.0):/u)(address)) && isNone(match$3(/^(?:postgres|redis|ssh|cloudflared|tailscaled|caddy)$/u)(process)), {
92482
+ const response = yield* match$1(probeSocket(socket, process), {
92359
92483
  onFalse: () => succeed$5(none()),
92360
92484
  onTrue: fnUntraced(function* () {
92361
- return yield* pipe(option$1(currentSpan), flatMap$2((parent) => http.head(`http://127.0.0.1:${port}/`, { headers: match$8(parent, {
92485
+ return yield* pipe(option$1(currentSpan), flatMap$2((parent) => http.head(`http://127.0.0.1:${socket.port}/`, { headers: match$8(parent, {
92362
92486
  onNone: () => ({}),
92363
92487
  onSome: toHeaders
92364
92488
  }) })), map$5((value) => ({
@@ -92372,18 +92496,18 @@ function portItems(text, worker, fs, http) {
92372
92496
  http: false,
92373
92497
  ui: false
92374
92498
  })),
92375
- address,
92376
- detail: `${address} · ${process || "process unavailable"}`,
92377
- id: `${worker}:port:${fields[0]}:${address}`,
92499
+ address: socket.address,
92500
+ detail: `${socket.address} · ${process || "process unavailable"}`,
92501
+ id: `${worker}:port:${socket.protocol}:${socket.address}`,
92378
92502
  kind: "port",
92379
- name: address,
92380
- port,
92503
+ name: socket.address,
92504
+ port: socket.port,
92381
92505
  process,
92382
- protocol: match$1(fields[0] === "udp", {
92506
+ protocol: match$1(socket.protocol === "udp", {
92383
92507
  onFalse: () => "tcp",
92384
92508
  onTrue: () => "udp"
92385
92509
  }),
92386
- state: fields[1] ?? "listening",
92510
+ state: socket.state,
92387
92511
  unit,
92388
92512
  url: "",
92389
92513
  worker
@@ -92632,15 +92756,17 @@ const TIERS = [
92632
92756
  keep: 6048e5
92633
92757
  }
92634
92758
  ];
92759
+ function cpuFields(fields) {
92760
+ return decodeSync(ArraySchema(FiniteFromString).check(isMinLength(5)))(take$3(drop$1(fields, 1), 8));
92761
+ }
92635
92762
  function counters(stat, network, disk, uptime, time) {
92636
- const cpu = pipe(stat, split$2("\n"), head, getOrElse(() => ""), trim, split$2(/\s+/u));
92637
- const values = decodeSync(ArraySchema(FiniteFromString).check(isMinLength(5)))(take$3(drop$1(cpu, 1), 8));
92763
+ const values = cpuFields(pipe(stat, split$2("\n"), head, getOrElse(() => ""), trim, split$2(/\s+/u)));
92638
92764
  const interfaces = pipe(network, split$2("\n"), filter$3((line) => isSome(match$3(/^\s*(?:eth|en|wl)[^:]*:/u)(line))), map$8((line) => split$2(trim(line), /\s+/u)));
92639
92765
  const devices = pipe(disk, split$2("\n"), map$8((line) => split$2(trim(line), /\s+/u)), filter$3((fields) => isSome(match$3(/^(?:[svh]d[a-z]+|nvme[0-9]+n[0-9]+)$/u)(fields[2] ?? ""))));
92640
92766
  return {
92641
92767
  cores: pipe(stat, split$2("\n"), filter$3((line) => isSome(match$3(/^cpu[0-9]+\s/u)(line))), map$8((line) => {
92642
92768
  const fields = split$2(trim(line), /\s+/u);
92643
- const counts = decodeSync(ArraySchema(FiniteFromString).check(isMinLength(5)))(take$3(drop$1(fields, 1), 8));
92769
+ const counts = cpuFields(fields);
92644
92770
  return {
92645
92771
  id: fields[0],
92646
92772
  idle: (counts[3] ?? 0) + (counts[4] ?? 0),
@@ -92824,13 +92950,19 @@ function appCgroup(path, siblings) {
92824
92950
  return exists(match$3(/\/user@[0-9]+\.service\/app\.slice\/app-([^/]+)\.slice$/u)(path), (match) => contains(siblings, `${match[1]}.service`));
92825
92951
  }
92826
92952
  function statField(text, name) {
92827
- return getOrElse(flatMap$7(match$3(new RegExp(`^${name} ([0-9]+)$`, "mu"))(text), (match) => parse$3(match[1] ?? "")), () => 0);
92953
+ return flatMap$7(match$3(new RegExp(`^${name} ([0-9]+)$`, "mu"))(text), (match) => parse$3(match[1] ?? ""));
92828
92954
  }
92829
92955
  function cgroupUsage(cpuStat, memoryStat) {
92830
- return {
92831
- memory: statField(memoryStat, "anon") + statField(memoryStat, "shmem") + max(0, statField(memoryStat, "kernel") - statField(memoryStat, "slab_reclaimable")),
92956
+ return map$11(all$4({
92957
+ anon: statField(memoryStat, "anon"),
92958
+ kernel: statField(memoryStat, "kernel"),
92959
+ reclaimable: statField(memoryStat, "slab_reclaimable"),
92960
+ shmem: statField(memoryStat, "shmem"),
92832
92961
  usage: statField(cpuStat, "usage_usec")
92833
- };
92962
+ }), (fields) => ({
92963
+ memory: fields.anon + fields.shmem + max(0, fields.kernel - fields.reclaimable),
92964
+ usage: fields.usage
92965
+ }));
92834
92966
  }
92835
92967
  function appShares(current, previous) {
92836
92968
  const elapsed = current.total - (previous?.total ?? current.total);
@@ -92893,10 +93025,19 @@ var Metrics = class Metrics extends Service$1()("@deslop/deploy/services/metrics
92893
93025
  const readings = yield* forEach$1(yield* appCgroups, (path) => pipe(all$1({
92894
93026
  cpu: fs.readFileString(`${CGROUP}${path}/cpu.stat`),
92895
93027
  memory: fs.readFileString(`${CGROUP}${path}/memory.stat`)
92896
- }, { concurrency: "unbounded" }), map$5((stats) => [path, {
92897
- id: processOwner(path),
92898
- ...cgroupUsage(stats.cpu, stats.memory)
92899
- }]), option$1), { concurrency: 8 });
93028
+ }, { concurrency: "unbounded" }), catchTag("PlatformError", (cause) => {
93029
+ if (cause.reason._tag === "NotFound") return undefined_$1;
93030
+ return fail$7(cause);
93031
+ }), flatMap$2((stats) => {
93032
+ if (stats === void 0) return succeedNone;
93033
+ return match$8(cgroupUsage(stats.cpu, stats.memory), {
93034
+ onNone: () => fail$7(DeployError.make({ message: `The cgroup counters for ${path} are missing or invalid.` })),
93035
+ onSome: (usage) => succeedSome([path, {
93036
+ id: processOwner(path),
93037
+ ...usage
93038
+ }])
93039
+ });
93040
+ })), { concurrency: 8 });
92900
93041
  return fromEntries(getSomes(readings));
92901
93042
  });
92902
93043
  const refreshStorage = pipe(scoped(execute("df", [
@@ -92941,7 +93082,7 @@ var Metrics = class Metrics extends Service$1()("@deslop/deploy/services/metrics
92941
93082
  total: current.cpuTotal
92942
93083
  };
92943
93084
  return [appShares(reading, getOrUndefined$1(last)), some$1(reading)];
92944
- })), option$1);
93085
+ })), asSome, catchTag("TimeoutError", () => succeedNone));
92945
93086
  const disks = yield* get$1(storage);
92946
93087
  const value = yield* pipe(try_({
92947
93088
  catch: (cause) => DeployError.make({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deslop/deploy",
3
- "version": "0.1.1259",
3
+ "version": "0.1.1261",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/MP281X/deslop.git",
@@ -38,5 +38,5 @@
38
38
  "engines": {
39
39
  "node": ">=26"
40
40
  },
41
- "fingerprint": "33707ca67057340394346c3963f93b83048648a6f81b35cb5d98d909553024c1"
41
+ "fingerprint": "85d38f2aab67c3f00577196a7d3eb3c741e4a58ce07995fb16cd846acff73479"
42
42
  }