@deslop/deploy 0.1.1331 → 0.1.1332

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
@@ -3526,6 +3526,8 @@ SuccessImpl.prototype = SuccessProto;
3526
3526
  const succeed$11 = (success) => new SuccessImpl(success);
3527
3527
  /** @internal */
3528
3528
  const getSuccess$1 = (self) => isFailure$2(self) ? none$1 : some$2(self.success);
3529
+ /** @internal */
3530
+ const fromOption$3 = /*#__PURE__*/ dual(2, (self, onNone) => isNone$1(self) ? fail$12(onNone()) : succeed$11(self.value));
3529
3531
  // ../../node_modules/.pnpm/effect@4.1.4/node_modules/effect/dist/Order.js
3530
3532
  /**
3531
3533
  * Defines comparison functions for ordered values.
@@ -5683,6 +5685,39 @@ const succeed$10 = succeed$11;
5683
5685
  * @since 4.0.0
5684
5686
  */
5685
5687
  const fail$11 = fail$12;
5688
+ /**
5689
+ * Converts an `Option<A>` into a `Result<A, E>`.
5690
+ *
5691
+ * **When to use**
5692
+ *
5693
+ * Use when an existing `Option` should become a `Result`, preserving `Some` as
5694
+ * success and turning `None` into a caller-provided failure.
5695
+ *
5696
+ * **Details**
5697
+ *
5698
+ * - `Some<A>` becomes `Success<A>`
5699
+ * - `None` becomes `Failure<E>` using the provided function
5700
+ * - Supports both data-first and data-last (piped) usage
5701
+ *
5702
+ * **Example** (Converting an Option to a Result)
5703
+ *
5704
+ * ```ts import.meta.vitest
5705
+ * import { Option, Result } from "effect"
5706
+ *
5707
+ * Result.fromOption(Option.some(1), () => "missing") // => Result.succeed(1)
5708
+ *
5709
+ * Result.fromOption(Option.none(), () => "missing") // => Result.fail("missing")
5710
+ * ```
5711
+ *
5712
+ * @see {@link getSuccess} to extract the success value as an Option
5713
+ * @see {@link getFailure} to extract the failure value as an Option
5714
+ * @see {@link fromNullishOr} to build a Result from nullable values
5715
+ *
5716
+ * @stability stable
5717
+ * @category constructors
5718
+ * @since 2.0.0
5719
+ */
5720
+ const fromOption$2 = fromOption$3;
5686
5721
  const try_$2 = (evaluate) => {
5687
5722
  if (isFunction(evaluate)) try {
5688
5723
  return succeed$10(evaluate());
@@ -12008,6 +12043,19 @@ const all$2 = (arg, options) => {
12008
12043
  return suspend$4(() => map$9(forEach$2(Object.entries(arg), ([key, effect]) => map$9(options?.mode === "result" ? result$2(effect) : effect, (value) => [key, value]), { concurrency: options?.concurrency }), Object.fromEntries));
12009
12044
  };
12010
12045
  /** @internal */
12046
+ const findFirstFilter$1 = /*#__PURE__*/ dual((args) => isIterable(args[0]) && !isEffect$1(args[0]), (elements, filter) => suspend$4(() => {
12047
+ const iterator = elements[Symbol.iterator]();
12048
+ const next = iterator.next();
12049
+ if (!next.done) return findFirstFilterLoop(iterator, 0, filter, next.value);
12050
+ return succeed$9(none());
12051
+ }));
12052
+ const findFirstFilterLoop = (iterator, index, filter, value) => flatMap$5(filter(value, index), (result) => {
12053
+ if (isSuccess$1(result)) return succeed$9(some$1(result.success));
12054
+ const next = iterator.next();
12055
+ if (!next.done) return findFirstFilterLoop(iterator, index + 1, filter, next.value);
12056
+ return succeed$9(none());
12057
+ });
12058
+ /** @internal */
12011
12059
  const whileLoop$1 = /*#__PURE__*/ makePrimitive$1({
12012
12060
  op: "While",
12013
12061
  [contA](value, fiber) {
@@ -18516,6 +18564,26 @@ const isEffect = isEffect$1;
18516
18564
  */
18517
18565
  const all$1 = all$2;
18518
18566
  /**
18567
+ * Returns the first value that passes an effectful `FilterEffect`.
18568
+ *
18569
+ * **When to use**
18570
+ *
18571
+ * Use when you need to find the first element that satisfies an effectful
18572
+ * filter returning a `Result`, which also transforms the matching element.
18573
+ *
18574
+ * **Details**
18575
+ *
18576
+ * The filter receives the element and index. Evaluation short-circuits on the
18577
+ * first `Result.succeed` and returns the transformed value in `Option.some`.
18578
+ *
18579
+ * @see {@link findFirst} for the simpler effectful predicate-based variant
18580
+ *
18581
+ * @stability stable
18582
+ * @category collecting
18583
+ * @since 4.0.0
18584
+ */
18585
+ const findFirstFilter = findFirstFilter$1;
18586
+ /**
18519
18587
  * Executes an effectful operation for each element in an `Iterable`.
18520
18588
  *
18521
18589
  * **When to use**
@@ -112680,14 +112748,17 @@ var Sample = class extends Class("Sample")({
112680
112748
  static table = "samples";
112681
112749
  };
112682
112750
  Struct$2(omit(Sample.fields, ["since", "step"]));
112751
+ const Disk = Struct$2({
112752
+ mount: String$6,
112753
+ total: Finite,
112754
+ used: Finite
112755
+ });
112756
+ const Platform = Literals(["linux", "darwin"]);
112683
112757
  const MachineHistory = Struct$2({
112684
- disks: ArraySchema(Struct$2({
112685
- mount: String$6,
112686
- total: Finite,
112687
- used: Finite
112688
- })),
112758
+ disks: ArraySchema(Disk),
112689
112759
  error: TextFromEmpty,
112690
112760
  load: ArraySchema(Finite),
112761
+ platform: OptionFromOptionalKey(Platform),
112691
112762
  samples: ArraySchema(Sample.json),
112692
112763
  stale: Boolean$5,
112693
112764
  time: DateTimeUtcFromFiniteMillis,
@@ -112958,6 +113029,15 @@ function unitFailures(text) {
112958
113029
  }));
112959
113030
  }
112960
113031
  // src/services/inventory/lib/launchd.ts
113032
+ function applicationBundle(path) {
113033
+ return pipe(match$2(/^(\/[^\n]*?\.app)(?:\/|$)/u)(path), map$13((match) => match[1] ?? ""), filter$7(isNonEmpty$1));
113034
+ }
113035
+ function launchProgram(text) {
113036
+ return pipe(match$2(/^\tprogram = (\/[^\n]+)$/mu)(text), map$13((match) => match[1] ?? ""), filter$7(isNonEmpty$1));
113037
+ }
113038
+ function systemProgram(path) {
113039
+ return isSome(match$2(/^(?:\/System|\/usr|\/bin|\/sbin|\/Library\/Apple)(?:\/|$)/u)(path));
113040
+ }
112961
113041
  function launchAgents(text) {
112962
113042
  return getSomes(pipe(text, split$1("\n"), map$10((line) => {
112963
113043
  const [pid, status = "", label = ""] = split$1(trim(line), " ");
@@ -112965,34 +113045,56 @@ function launchAgents(text) {
112965
113045
  const processId = filter$7(decodeOption(ProcessIdFromString)(pid), (value) => value > 0);
112966
113046
  if (isNone(processId) && pid !== "-") return none();
112967
113047
  return some$1({
113048
+ bundle: none(),
112968
113049
  detail: "user · launch agent",
112969
113050
  label: UnitId.make(label),
113051
+ name: label,
112970
113052
  pid: processId,
112971
113053
  status: parse$2(status)
112972
113054
  });
112973
113055
  })));
112974
113056
  }
112975
- function dockApplications(text) {
113057
+ function dockApplications(text, agentBundles = []) {
112976
113058
  return getSomes(pipe(text, split$1(/\n(?=\s*[0-9]+\))/u), map$10((block) => {
113059
+ const bundle = flatMap$8(match$2(/^\s+bundle path="([^"\n]+)"\s*$/mu)(block), (match) => applicationBundle(match[1] ?? ""));
113060
+ const agentApplication = exists(bundle, (value) => contains$1(agentBundles, value));
112977
113061
  const name = pipe(match$2(/^\s*[0-9]+\) "(.+)" ASN:/u)(block), map$13((match) => match[1] ?? ""), filter$7(isNonEmpty$1));
112978
- const pid = pipe(match$2(/^\s+pid = ([0-9]+) .*\btype="Foreground"(?:\s|$)/mu)(block), flatMap$8((match) => decodeOption(ProcessIdFromString)(match[1] ?? "")), filter$7((value) => value > 0));
113062
+ const pid = pipe(match$2(/^\s+pid = ([0-9]+) .*\btype="(Foreground|UIElement)"(?:\s|$)/mu)(block), filter$7((match) => match[2] === "Foreground" || agentApplication), flatMap$8((match) => decodeOption(ProcessIdFromString)(match[1] ?? "")), filter$7((value) => value > 0));
112979
113063
  return map$13(all$4({
112980
113064
  name,
112981
113065
  pid
112982
113066
  }), (app) => ({
113067
+ bundle,
112983
113068
  detail: "user · application",
112984
113069
  label: UnitId.make(app.name),
113070
+ name: app.name,
112985
113071
  pid: app.pid
112986
113072
  }));
112987
113073
  })));
112988
113074
  }
112989
113075
  function macApplications(agents, applications) {
112990
- const running = getSomes(map$10(agents, (agent) => map$13(agent.pid, (pid) => ({
112991
- detail: agent.detail,
112992
- label: agent.label,
113076
+ const running = pipe(agents, map$10((agent) => map$13(agent.pid, (pid) => ({
113077
+ ...agent,
112993
113078
  pid
112994
- }))));
112995
- return dedupeWith([...applications, ...running], (left, right) => left.pid === right.pid);
113079
+ }))), getSomes);
113080
+ return pipe([...applications, ...running], map$10((app) => {
113081
+ const dock = findFirst(applications, (candidate) => candidate.pid === app.pid || exists(app.bundle, (bundle) => contains$2(candidate.bundle, bundle)));
113082
+ return {
113083
+ ...app,
113084
+ detail: match$8(dock, {
113085
+ onNone: () => app.detail,
113086
+ onSome: (candidate) => candidate.detail
113087
+ }),
113088
+ label: UnitId.make(getOrElse$1(app.bundle, () => pipe(dock, map$13((candidate) => candidate.label), getOrElse$1(() => app.label)))),
113089
+ name: pipe(running, findFirst((candidate) => exists(app.bundle, (bundle) => contains$2(candidate.bundle, bundle))), match$8({
113090
+ onNone: () => match$8(dock, {
113091
+ onNone: () => app.name,
113092
+ onSome: (candidate) => candidate.name
113093
+ }),
113094
+ onSome: (agent) => agent.name
113095
+ }))
113096
+ };
113097
+ }), dedupeWith((left, right) => left.pid === right.pid));
112996
113098
  }
112997
113099
  // src/services/inventory/lib/command.ts
112998
113100
  const WRAPPERS = [
@@ -113214,9 +113316,13 @@ function important(item) {
113214
113316
  function ports(items) {
113215
113317
  return pipe(items, filter$5((item) => appPort(item) && contains$2(item.http, true)), sort(mapInput(String$10, (item) => `${item.worker}:${getOrUndefined$1(item.port)}:${getOrUndefined$1(item.address)}`)), dedupeWith((a, b) => a.worker === b.worker && makeEquivalence$5((x, y) => x === y)(a.port, b.port)));
113216
113318
  }
113319
+ function serviceUnit(item) {
113320
+ if (item.kind === "service") return getOrElse$1(item.unit, () => item.name);
113321
+ return UnitId.make(item.name);
113322
+ }
113217
113323
  function itemOwner(item) {
113218
113324
  if (item.kind === "container") return AppId.make(`container:${slice(0, 12)(getOrElse$1(last$1(split$1(item.id, ":docker:")), constant("")))}`);
113219
- return AppId.make(`service:${getOrElse$1(item.scope, constant("system"))}:${item.name}`);
113325
+ return AppId.make(`service:${getOrElse$1(item.scope, constant("system"))}:${serviceUnit(item)}`);
113220
113326
  }
113221
113327
  function fullName(item) {
113222
113328
  if (item.kind === "port") return getOrElse$1(item.process, () => item.name);
@@ -113251,7 +113357,8 @@ function workloads(items) {
113251
113357
  }))));
113252
113358
  const bySocket = fromIterable$5(map$10(reverse(filter$5(listeners, (listener) => !contains$2(listener.address, "container"))), (listener) => [socket(listener.worker, listener), listener]));
113253
113359
  const grouped = pipe(items, filter$5((item) => item.kind === "service" || item.kind === "container"), map$10((item) => {
113254
- const attached = filter$5(byUnit[item.worker]?.[`unit:${item.name}`] ?? [], (listener) => exists(listener.unit, (unit) => unit === item.name));
113360
+ const unit = serviceUnit(item);
113361
+ const attached = filter$5(byUnit[item.worker]?.[`unit:${unit}`] ?? [], (listener) => contains$2(listener.unit, unit));
113255
113362
  const bindings = pipe(item.bindings, getOrElse$1(empty$15), map$10((binding) => ({
113256
113363
  ...item,
113257
113364
  ...pipe(get$8(bySocket, socket(item.worker, {
@@ -113266,7 +113373,7 @@ function workloads(items) {
113266
113373
  port: some$1(binding.port),
113267
113374
  process: some$1(item.name),
113268
113375
  protocol: some$1(binding.protocol),
113269
- unit: pipe(item, liftPredicate((owner) => owner.kind === "service"), map$13((owner) => owner.name)),
113376
+ unit: pipe(item, liftPredicate((owner) => owner.kind === "service"), map$13(serviceUnit)),
113270
113377
  url: none()
113271
113378
  })));
113272
113379
  return {
@@ -113274,7 +113381,7 @@ function workloads(items) {
113274
113381
  listeners: [...attached, ...bindings]
113275
113382
  };
113276
113383
  }));
113277
- const services = fromIterable$3(pipe(grouped, filter$5((row) => row.item.kind === "service"), map$10((row) => make$92(row.item.worker, row.item.name))));
113384
+ const services = fromIterable$3(pipe(grouped, filter$5((row) => row.item.kind === "service"), map$10((row) => make$92(row.item.worker, serviceUnit(row.item)))));
113278
113385
  const represented = fromIterable$3(flatMap$6(grouped, (row) => pipe(row.listeners, filter$5((binding) => !contains$2(binding.address, "container")), map$10((binding) => socket(row.item.worker, {
113279
113386
  address: binding.address,
113280
113387
  port: binding.port,
@@ -113990,9 +114097,36 @@ var Inventory = class extends Service$1()("@deslop/deploy/services/inventory/ser
113990
114097
  ]
113991
114098
  });
113992
114099
  const darwin = gen(function* () {
113993
- const launchd = yield* all$1({
113994
- agents: result$1(map$7(command("launchctl", ["list"]), launchAgents)),
113995
- applications: result$1(map$7(command("/usr/bin/lsappinfo", ["list"]), dockApplications)),
114100
+ const namedAgents = gen(function* () {
114101
+ return getSomes(yield* forEach$1(launchAgents(yield* command("launchctl", ["list"])), fnUntraced(function* (agent) {
114102
+ if (startsWith("deslop-")(agent.label)) return some$1(agent);
114103
+ const program = flatMap$8(yield* option$1(command("launchctl", ["print", `gui/${userInfo().uid}/${agent.label}`])), launchProgram);
114104
+ if (exists(program, systemProgram)) return none();
114105
+ return yield* pipe(program, flatMap$8(applicationBundle), match$8({
114106
+ onNone: () => succeedSome(agent),
114107
+ onSome: fnUntraced(function* (bundle) {
114108
+ const name = yield* findFirstFilter(["CFBundleDisplayName", "CFBundleName"], (key) => pipe(command("/usr/bin/plutil", [
114109
+ "-extract",
114110
+ key,
114111
+ "raw",
114112
+ "-expect",
114113
+ "string",
114114
+ "-o",
114115
+ "-",
114116
+ `${bundle}/Contents/Info.plist`
114117
+ ]), option$1, map$7((value) => pipe(value, map$13(trim), filter$7(isNonEmpty$1), fromOption$2(constUndefined)))));
114118
+ return some$1({
114119
+ ...agent,
114120
+ bundle: some$1(bundle),
114121
+ name: getOrElse$1(name, () => pipe(bundle, split$1("/"), last$1, getOrElse$1(constant("")), slice(0, -4)))
114122
+ });
114123
+ })
114124
+ }));
114125
+ }), { concurrency: 4 }));
114126
+ });
114127
+ const collected = yield* all$1({
114128
+ agents: result$1(namedAgents),
114129
+ applications: result$1(command("/usr/bin/lsappinfo", ["list"])),
113996
114130
  table: result$1(command("env", [
113997
114131
  "LC_ALL=C",
113998
114132
  "ps",
@@ -114001,22 +114135,27 @@ var Inventory = class extends Service$1()("@deslop/deploy/services/inventory/ser
114001
114135
  "pid=,ppid=,rss=,time=,lstart=,args="
114002
114136
  ]))
114003
114137
  }, { concurrency: "unbounded" });
114138
+ const launchd = {
114139
+ ...collected,
114140
+ applications: map$12(collected.applications, (text) => dockApplications(text, pipe(getOrElse(collected.agents, () => []), map$10((agent) => agent.bundle), getSomes)))
114141
+ };
114004
114142
  const time = yield* now;
114005
- const total = millis(sumAll(flatMap$6(cpus(), (cpu) => values(cpu.times))));
114143
+ const total = pipe(cpus(), flatMap$6((cpu) => values(cpu.times)), sumAll, millis);
114006
114144
  const apps = macApplications(getOrElse(launchd.agents, () => []), getOrElse(launchd.applications, () => []));
114007
114145
  function appItems(found) {
114008
- return map$10(found, (app) => InventoryItem.make({
114146
+ return pipe(found, dedupeWith((left, right) => left.label === right.label), map$10((app) => InventoryItem.make({
114009
114147
  active: true,
114010
114148
  detail: app.detail,
114011
114149
  id: ItemId.make(`${worker}:user:${app.label}`),
114012
114150
  kind: "service",
114013
- name: app.label,
114151
+ name: UnitId.make(app.name),
114014
114152
  running: true,
114015
114153
  scope: some$1("user"),
114016
114154
  state: "running",
114155
+ unit: some$1(app.label),
114017
114156
  url: none(),
114018
114157
  worker
114019
- }));
114158
+ })));
114020
114159
  }
114021
114160
  const records = map$12(launchd.table, (text) => {
114022
114161
  const agents = fromIterable$5(map$10(apps, (app) => [app.pid, app.label]));
@@ -114030,9 +114169,9 @@ var Inventory = class extends Service$1()("@deslop/deploy/services/inventory/ser
114030
114169
  total
114031
114170
  })),
114032
114171
  sources: [
114033
- collect("Launch agents", map$7(fromResult(launchd.agents), (agents) => pipe(agents, filter$5((agent) => match$8(agent.pid, {
114172
+ collect("Launch agents", map$7(fromResult(launchd.agents), (agents) => [...appItems(filter$5(apps, (app) => app.detail === "user · launch agent")), ...pipe(agents, filter$5((agent) => match$8(agent.pid, {
114034
114173
  onNone: () => exists(agent.status, (status) => status !== 0),
114035
- onSome: (id) => some(apps, (app) => app.pid === id && app.label === agent.label)
114174
+ onSome: constFalse$1
114036
114175
  })), map$10((agent) => InventoryItem.make({
114037
114176
  active: isSome(agent.pid),
114038
114177
  detail: agent.detail,
@@ -114046,7 +114185,7 @@ var Inventory = class extends Service$1()("@deslop/deploy/services/inventory/ser
114046
114185
  }),
114047
114186
  id: ItemId.make(`${worker}:user:${agent.label}`),
114048
114187
  kind: "service",
114049
- name: agent.label,
114188
+ name: UnitId.make(agent.name),
114050
114189
  running: isSome(agent.pid),
114051
114190
  scope: some$1("user"),
114052
114191
  state: match$8(agent.pid, {
@@ -114055,8 +114194,8 @@ var Inventory = class extends Service$1()("@deslop/deploy/services/inventory/ser
114055
114194
  }),
114056
114195
  url: none(),
114057
114196
  worker
114058
- }))))),
114059
- collect("Applications", map$7(fromResult(launchd.applications), appItems)),
114197
+ })))])),
114198
+ collect("Applications", map$7(fromResult(launchd.applications), () => appItems(filter$5(apps, (app) => app.detail === "user · application")))),
114060
114199
  collect("Listening ports", flatMap$3(command("lsof", [
114061
114200
  "-nP",
114062
114201
  "+c0",
@@ -114686,6 +114825,10 @@ var Metrics = class extends Service$1()("@deslop/deploy/services/metrics/service
114686
114825
  disks: now$2.disks,
114687
114826
  error: yield* get$2(failure),
114688
114827
  load: now$2.load,
114828
+ platform: some$1(match(platform === "darwin", {
114829
+ onFalse: constant("linux"),
114830
+ onTrue: constant("darwin")
114831
+ })),
114689
114832
  samples: history(samples, query.minutes, time),
114690
114833
  stale: match$8(last$1(samples), {
114691
114834
  onNone: constTrue,
@@ -114742,6 +114885,7 @@ function cachedHistory(query, time, saved) {
114742
114885
  onNone: () => [],
114743
114886
  onSome: (machine) => machine.load
114744
114887
  }),
114888
+ platform: flatMap$8(saved, (machine) => machine.platform),
114745
114889
  samples: history(match$8(saved, {
114746
114890
  onNone: () => [],
114747
114891
  onSome: (machine) => machine.samples
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deslop/deploy",
3
- "version": "0.1.1331",
3
+ "version": "0.1.1332",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/MP281X/deslop.git",
@@ -40,5 +40,5 @@
40
40
  "engines": {
41
41
  "node": ">=26"
42
42
  },
43
- "fingerprint": "d630d49a864553a1fe85f5e63eb1eeb951f0b04937389aad8c005cdf81ff5996"
43
+ "fingerprint": "701bd55d372e8c15adaff4b436ee7439e9b9cbcc7f2d835c3c600667f009141b"
44
44
  }