@dxos/cli-util 0.8.4-main.d05673bc65 → 0.8.4-main.d9fc60f731

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/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2025 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -24,4 +24,4 @@ export {
24
24
  __export,
25
25
  CommandConfig
26
26
  };
27
- //# sourceMappingURL=chunk-6TKUDRM6.mjs.map
27
+ //# sourceMappingURL=chunk-N5LOOWPE.mjs.map
@@ -2,7 +2,7 @@ import { createRequire } from 'node:module';const require = createRequire(import
2
2
  import {
3
3
  CommandConfig,
4
4
  __export
5
- } from "./chunk-6TKUDRM6.mjs";
5
+ } from "./chunk-N5LOOWPE.mjs";
6
6
 
7
7
  // src/util/form-builder.ts
8
8
  var form_builder_exports = {};
@@ -16,8 +16,8 @@ __export(form_builder_exports, {
16
16
  set: () => set,
17
17
  when: () => when
18
18
  });
19
- import * as Doc from "@effect/printer/Doc";
20
19
  import * as Ansi from "@effect/printer-ansi/Ansi";
20
+ import * as Doc from "@effect/printer/Doc";
21
21
  import * as Option from "effect/Option";
22
22
  import * as Pipeable from "effect/Pipeable";
23
23
  var FormBuilderImpl = class {
@@ -44,16 +44,16 @@ var calculateDimensions = (entries, prefix) => {
44
44
  var buildKeyLine = (prefix, key, targetWidth) => {
45
45
  return Doc.annotate(Doc.fill(targetWidth)(Doc.text(prefix + key + ": ")), Ansi.blackBright);
46
46
  };
47
- var setImpl = (builder, key, value2, color) => {
48
- if (value2 !== void 0) {
47
+ var setImpl = (builder, key, value, color) => {
48
+ if (value !== void 0) {
49
49
  let valueDoc;
50
- if (typeof value2 === "object" && value2 !== null) {
51
- valueDoc = value2;
50
+ if (typeof value === "object" && value !== null) {
51
+ valueDoc = value;
52
52
  } else {
53
- valueDoc = Doc.text(String(value2));
53
+ valueDoc = Doc.text(String(value));
54
54
  }
55
55
  if (color) {
56
- const ansi = typeof color === "function" ? color(value2) : color;
56
+ const ansi = typeof color === "function" ? color(value) : color;
57
57
  valueDoc = Doc.annotate(valueDoc, ansi);
58
58
  }
59
59
  builder.entries.push({
@@ -68,13 +68,13 @@ function set(builderOrKey, keyOrValue, valueOrColor, color) {
68
68
  if (builderOrKey instanceof FormBuilderImpl) {
69
69
  const builder = builderOrKey;
70
70
  const key = keyOrValue;
71
- const value2 = valueOrColor;
72
- return setImpl(builder, key, value2, color);
71
+ const value = valueOrColor;
72
+ return setImpl(builder, key, value, color);
73
73
  } else {
74
74
  const key = builderOrKey;
75
- const value2 = keyOrValue;
75
+ const value = keyOrValue;
76
76
  const color2 = valueOrColor;
77
- return (builder) => setImpl(builder, key, value2, color2);
77
+ return (builder) => setImpl(builder, key, value, color2);
78
78
  }
79
79
  }
80
80
  var nestImpl = (parent, key, builder) => {
@@ -103,9 +103,9 @@ function nest(parentOrKey, keyOrBuilder, builder) {
103
103
  return (parent) => nestImpl(parent, key, builder2);
104
104
  }
105
105
  }
106
- var optionImpl = (builder, key, value2, color) => {
107
- if (Option.isSome(value2)) {
108
- return setImpl(builder, key, value2.value, color);
106
+ var optionImpl = (builder, key, value, color) => {
107
+ if (Option.isSome(value)) {
108
+ return setImpl(builder, key, value.value, color);
109
109
  }
110
110
  return builder;
111
111
  };
@@ -113,30 +113,30 @@ function option(builderOrKey, keyOrValue, valueOrColor, color) {
113
113
  if (builderOrKey instanceof FormBuilderImpl) {
114
114
  const builder = builderOrKey;
115
115
  const key = keyOrValue;
116
- const value2 = valueOrColor;
117
- return optionImpl(builder, key, value2, color);
116
+ const value = valueOrColor;
117
+ return optionImpl(builder, key, value, color);
118
118
  } else {
119
119
  const key = builderOrKey;
120
- const value2 = keyOrValue;
120
+ const value = keyOrValue;
121
121
  const color2 = valueOrColor;
122
- return (builder) => optionImpl(builder, key, value2, color2);
122
+ return (builder) => optionImpl(builder, key, value, color2);
123
123
  }
124
124
  }
125
- var nestedOptionImpl = (builder, key, value2) => {
126
- if (Option.isSome(value2)) {
127
- return nestImpl(builder, key, value2.value);
125
+ var nestedOptionImpl = (builder, key, value) => {
126
+ if (Option.isSome(value)) {
127
+ return nestImpl(builder, key, value.value);
128
128
  }
129
129
  return builder;
130
130
  };
131
- function nestedOption(builderOrKey, keyOrValue, value2) {
131
+ function nestedOption(builderOrKey, keyOrValue, value) {
132
132
  if (builderOrKey instanceof FormBuilderImpl) {
133
133
  const builder = builderOrKey;
134
134
  const key = keyOrValue;
135
- return nestedOptionImpl(builder, key, value2);
135
+ return nestedOptionImpl(builder, key, value);
136
136
  } else {
137
137
  const key = builderOrKey;
138
- const value3 = keyOrValue;
139
- return (builder) => nestedOptionImpl(builder, key, value3);
138
+ const value2 = keyOrValue;
139
+ return (builder) => nestedOptionImpl(builder, key, value2);
140
140
  }
141
141
  }
142
142
  var whenImpl = (builder, condition, ...ops) => {
@@ -179,18 +179,18 @@ function each(builderOrItems, itemsOrFn, fn3) {
179
179
  var build = (builder) => {
180
180
  const { targetWidth } = calculateDimensions(builder.entries, builder.prefix);
181
181
  const entryLines = [];
182
- builder.entries.forEach(({ key, value: value2, isNested }) => {
182
+ builder.entries.forEach(({ key, value, isNested }) => {
183
183
  const keyLine = buildKeyLine(builder.prefix, key, targetWidth);
184
184
  if (isNested) {
185
185
  entryLines.push(Doc.hcat([
186
186
  keyLine,
187
187
  Doc.hardLine,
188
- value2
188
+ value
189
189
  ]));
190
190
  } else {
191
191
  entryLines.push(Doc.hcat([
192
192
  keyLine,
193
- value2
193
+ value
194
194
  ]));
195
195
  }
196
196
  });
@@ -213,8 +213,8 @@ var Common = {
213
213
  };
214
214
 
215
215
  // src/util/platform.ts
216
- import { spawn } from "node:child_process";
217
216
  import * as Effect from "effect/Effect";
217
+ import { spawn } from "node:child_process";
218
218
  var copyToClipboard = (text3) => Effect.tryPromise({
219
219
  try: () => {
220
220
  return new Promise((resolve, reject) => {
@@ -303,8 +303,8 @@ var openBrowser = (url) => Effect.tryPromise({
303
303
  });
304
304
 
305
305
  // src/util/printer.ts
306
- import * as Doc2 from "@effect/printer/Doc";
307
306
  import * as AnsiDoc from "@effect/printer-ansi/AnsiDoc";
307
+ import * as Doc2 from "@effect/printer/Doc";
308
308
  var print = (doc) => AnsiDoc.render(doc, {
309
309
  style: "pretty"
310
310
  });
@@ -324,12 +324,12 @@ var withTypes = (...types) => Effect2.gen(function* () {
324
324
  import * as Console from "effect/Console";
325
325
  import * as Effect3 from "effect/Effect";
326
326
  import * as Layer from "effect/Layer";
327
- import * as Match from "effect/Match";
328
327
  import * as Option2 from "effect/Option";
328
+ import { getPersonalSpace } from "@dxos/app-toolkit";
329
329
  import { ClientService as ClientService2 } from "@dxos/client";
330
- import { Database } from "@dxos/echo";
330
+ import { Database, Feed } from "@dxos/echo";
331
+ import { createFeedServiceLayer } from "@dxos/echo-db";
331
332
  import { BaseError } from "@dxos/errors";
332
- import { QueueService } from "@dxos/functions";
333
333
  import { log as log2 } from "@dxos/log";
334
334
  import { EdgeReplicationSetting } from "@dxos/protocols/proto/dxos/echo/metadata";
335
335
  import { isBun } from "@dxos/util";
@@ -340,54 +340,51 @@ var getSpace = (spaceId) => Effect3.gen(function* () {
340
340
  }).pipe(Effect3.catchTag("NoSuchElementException", () => Effect3.fail(new SpaceNotFoundError(spaceId))));
341
341
  var spaceIdWithDefault = (spaceId) => Effect3.gen(function* () {
342
342
  const client = yield* ClientService2;
343
- yield* Effect3.promise(() => client.spaces.waitUntilReady());
344
- return Option2.getOrElse(spaceId, () => client.spaces.default.id);
343
+ return Option2.getOrElse(spaceId, () => {
344
+ const personal = getPersonalSpace(client);
345
+ if (!personal) {
346
+ throw new Error("No space ID provided and no personal space found.");
347
+ }
348
+ return personal.id;
349
+ });
345
350
  });
346
- var spaceLayer = (spaceId$, fallbackToDefaultSpace = false) => {
351
+ var spaceLayer = (spaceId$, fallbackToPersonalSpace = false) => {
347
352
  const getSpace2 = Effect3.fn(function* () {
348
353
  const client = yield* ClientService2;
349
- yield* Effect3.promise(() => client.spaces.waitUntilReady());
350
- const spaceId = Match.value(fallbackToDefaultSpace).pipe(Match.when(true, () => spaceId$.pipe(Option2.getOrElse(() => client.spaces.default.id), Option2.some)), Match.when(false, () => spaceId$), Match.exhaustive);
351
- const space = spaceId.pipe(Option2.flatMap((id) => Option2.fromNullable(client.spaces.get(id))), Option2.getOrUndefined);
354
+ const resolveSpace = () => {
355
+ if (!fallbackToPersonalSpace) {
356
+ return spaceId$.pipe(Option2.flatMap((id) => Option2.fromNullable(client.spaces.get(id))));
357
+ }
358
+ return spaceId$.pipe(Option2.flatMap((id) => Option2.fromNullable(client.spaces.get(id))), Option2.orElse(() => Option2.fromNullable(getPersonalSpace(client))), Option2.orElse(() => Option2.fromNullable(client.spaces.get()[0])));
359
+ };
360
+ const space = resolveSpace().pipe(Option2.getOrUndefined);
352
361
  if (space) {
353
362
  yield* Effect3.promise(() => space.waitUntilReady());
354
363
  }
355
364
  return space;
356
365
  });
366
+ const NO_DB_STUB = {
367
+ get db() {
368
+ throw new Error("Space not found");
369
+ }
370
+ };
357
371
  const db = Layer.scoped(Database.Service, Effect3.acquireRelease(Effect3.gen(function* () {
358
372
  const space = yield* getSpace2();
359
373
  if (!space) {
360
- return {
361
- get db() {
362
- throw new Error("Space not found");
363
- }
364
- };
374
+ return NO_DB_STUB;
365
375
  }
366
376
  return {
367
377
  db: space.db
368
378
  };
369
- }), ({ db: db2 }) => Effect3.promise(() => db2.flush())));
370
- const queue = Layer.effect(QueueService, Effect3.gen(function* () {
379
+ }), (holder) => holder === NO_DB_STUB ? Effect3.void : Effect3.promise(() => holder.db.flush())));
380
+ const feed = Layer.unwrapEffect(Effect3.gen(function* () {
371
381
  const space = yield* getSpace2();
372
382
  if (!space) {
373
- return {
374
- queues: {
375
- get: (_dxn) => {
376
- throw new Error("Queues not available");
377
- },
378
- create: () => {
379
- throw new Error("Queues not available");
380
- }
381
- },
382
- queue: void 0
383
- };
383
+ return Feed.notAvailable;
384
384
  }
385
- return {
386
- queues: space.queues,
387
- queue: void 0
388
- };
385
+ return createFeedServiceLayer(space.queues);
389
386
  }));
390
- return Layer.merge(db, queue);
387
+ return Layer.merge(db, feed);
391
388
  };
392
389
  var waitForSync = Effect3.fn(function* (space) {
393
390
  if (!isBun()) {
@@ -400,12 +397,7 @@ var waitForSync = Effect3.fn(function* (space) {
400
397
  yield* Effect3.promise(() => space.internal.syncToEdge({
401
398
  onProgress: (state) => log2.info("syncing", {
402
399
  state: state ?? "no connection to edge"
403
- }, {
404
- F: __dxlog_file,
405
- L: 125,
406
- S: this,
407
- C: (f, a) => f(...a)
408
- })
400
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 94, S: this })
409
401
  }));
410
402
  yield* Console.log("Sync complete");
411
403
  });
@@ -427,28 +419,61 @@ var SpaceNotFoundError = class extends BaseError.extend("SpaceNotFoundError", "S
427
419
  };
428
420
 
429
421
  // src/util/space-format.ts
422
+ import * as Duration from "effect/Duration";
430
423
  import * as Effect4 from "effect/Effect";
431
424
  import { SpaceState } from "@dxos/client/echo";
432
- var formatSpace = Effect4.fn(function* (space, options = {
425
+ var DEFAULT_OPTIONS = {
433
426
  verbose: false,
434
- truncateKeys: false
435
- }) {
436
- yield* Effect4.tryPromise(() => space.waitUntilReady());
437
- const { open, ready } = space.internal.data.metrics ?? {};
438
- const startup = open && ready && ready.getTime() - open.getTime();
439
- const pipeline = space.internal.data.pipeline;
427
+ truncateKeys: false,
428
+ waitSeconds: 0
429
+ };
430
+ var READ_TIMEOUT_SECONDS = 2;
431
+ var tryWithFallback = (label, run, fallback) => Effect4.tryPromise(run).pipe(Effect4.timeoutFail({
432
+ duration: Duration.seconds(READ_TIMEOUT_SECONDS),
433
+ onTimeout: () => new Error(`${label} timed out`)
434
+ }), Effect4.catchAll(() => Effect4.succeed(fallback)));
435
+ var tryWithFallbackSync = (read, fallback) => {
436
+ try {
437
+ return read();
438
+ } catch {
439
+ return fallback;
440
+ }
441
+ };
442
+ var formatSpace = Effect4.fn(function* (space, options = {}) {
443
+ const { waitSeconds } = {
444
+ ...DEFAULT_OPTIONS,
445
+ ...options
446
+ };
447
+ if (waitSeconds > 0) {
448
+ yield* Effect4.tryPromise(() => space.waitUntilReady()).pipe(Effect4.timeoutFail({
449
+ duration: Duration.seconds(waitSeconds),
450
+ onTimeout: () => new Error("waitUntilReady timed out")
451
+ }), Effect4.catchAll(() => Effect4.void));
452
+ }
453
+ const state = tryWithFallbackSync(() => space.state.get(), SpaceState.SPACE_INITIALIZING);
454
+ const ready = state === SpaceState.SPACE_READY;
455
+ const metrics = tryWithFallbackSync(() => space.internal.data.metrics, void 0);
456
+ const startup = metrics?.open && metrics?.ready ? metrics.ready.getTime() - metrics.open.getTime() : void 0;
457
+ const pipeline = tryWithFallbackSync(() => space.internal.data.pipeline, void 0);
440
458
  const epoch = pipeline?.currentEpoch?.subject.assertion.number;
441
- const syncState = aggregateSyncState(yield* Effect4.tryPromise(() => space.internal.db.coreDatabase.getSyncState()));
459
+ const syncStateRaw = yield* tryWithFallback("getSyncState", () => space.internal.db.coreDatabase.getSyncState(), {
460
+ peers: {}
461
+ });
462
+ const syncState = aggregateSyncState(syncStateRaw);
463
+ const name = ready ? tryWithFallbackSync(() => space.properties.name, void 0) : "loading...";
464
+ const members = tryWithFallbackSync(() => space.members.get().length, 0);
465
+ const objects = tryWithFallbackSync(() => space.internal.db.coreDatabase.getAllObjectIds().length, 0);
466
+ const key = options.truncateKeys ? tryWithFallbackSync(() => space.key.truncate(), "") : tryWithFallbackSync(() => space.key.toHex(), "");
442
467
  return {
443
468
  id: space.id,
444
- state: SpaceState[space.state.get()],
445
- name: space.state.get() === SpaceState.SPACE_READY ? space.properties.name : "loading...",
446
- members: space.members.get().length,
447
- objects: space.internal.db.coreDatabase.getAllObjectIds().length,
448
- key: options.truncateKeys ? space.key.truncate() : space.key.toHex(),
469
+ state: SpaceState[state],
470
+ name,
471
+ members,
472
+ objects,
473
+ key,
449
474
  epoch,
450
475
  startup,
451
- automergeRoot: space.internal.data.pipeline?.spaceRootUrl,
476
+ automergeRoot: pipeline?.spaceRootUrl,
452
477
  // appliedEpoch,
453
478
  syncState: `${syncState.count} ${getSyncIndicator(syncState.up, syncState.down)} (${syncState.peers} peers)`
454
479
  };
@@ -486,13 +511,13 @@ var printSpace = (spaceData) => make({
486
511
 
487
512
  // src/util/timeout.ts
488
513
  import * as Config from "effect/Config";
489
- import * as Duration from "effect/Duration";
514
+ import * as Duration2 from "effect/Duration";
490
515
  import * as Effect5 from "effect/Effect";
491
516
  import * as Option3 from "effect/Option";
492
- var withTimeout = Effect5.fnUntraced(function* (effect2) {
517
+ var withTimeout = Effect5.fnUntraced(function* (effect) {
493
518
  const timeout2 = yield* Config.integer("TIMEOUT").pipe(Config.option);
494
- const duration = timeout2.pipe(Option3.map(Duration.millis), Option3.getOrElse(() => Duration.infinity));
495
- return yield* effect2.pipe(Effect5.timeout(duration));
519
+ const duration = timeout2.pipe(Option3.map(Duration2.millis), Option3.getOrElse(() => Duration2.infinity));
520
+ return yield* effect.pipe(Effect5.timeout(duration));
496
521
  });
497
522
  export {
498
523
  CommandConfig,