@k2b/cloud 0.14.0 → 0.15.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k2b/cloud",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Application platform library for independently deployed Hono and SolidJS services behind a dynamic gateway.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "repository": {
@@ -99,7 +99,7 @@
99
99
  "@tailwindcss/typography": "0.5.20",
100
100
  "@k2b/nessi": "0.12.1",
101
101
  "@k2b/ssr": "0.14.0",
102
- "@k2b/ui": "0.6.1",
102
+ "@k2b/ui": "0.6.2",
103
103
  "@k2b/stdlib": "0.26.0",
104
104
  "@k2b/sync": "6.5.0",
105
105
  "@nats-io/transport-node": "3.4.0",
@@ -0,0 +1,46 @@
1
+ import type { CloudCliText } from "./locale";
2
+
3
+ /**
4
+ * The syntactic form of a resource argument. Parsing never contacts the
5
+ * server; each application resolves the result against its own API.
6
+ *
7
+ * - `local`: starts with `/`, `./`, `../`, or `~`, so it names a local file;
8
+ * - `path`: `<container>:<path>`, split at the first colon;
9
+ * - `ref`: anything else, usually an ID or an exact container name.
10
+ */
11
+ export type CloudCliAddress =
12
+ | { kind: "local"; path: string }
13
+ | { kind: "path"; container: string; path: string }
14
+ | { kind: "ref"; ref: string };
15
+
16
+ const LOCAL_PATH = /^(?:\/|\.{1,2}(?:\/|$)|~(?:\/|$))/;
17
+
18
+ export const parseCliAddress = (raw: string): CloudCliAddress => {
19
+ if (LOCAL_PATH.test(raw)) return { kind: "local", path: raw };
20
+ const colon = raw.indexOf(":");
21
+ if (colon > 0) return { kind: "path", container: raw.slice(0, colon), path: raw.slice(colon + 1) };
22
+ return { kind: "ref", ref: raw };
23
+ };
24
+
25
+ /** One resource that an ambiguous name or path matched. */
26
+ export type CloudCliCandidate = { path: string; id: string };
27
+
28
+ /** Candidates as `path (id), path (id)`. */
29
+ export const formatCliCandidates = (candidates: readonly CloudCliCandidate[]): string =>
30
+ candidates.map((candidate) => `${candidate.path} (${candidate.id})`).join(", ");
31
+
32
+ /**
33
+ * The shared ambiguity message. `resources` is the plural resource noun, in
34
+ * German in the dative (`{ en: "notes", de: "Notizen" }`).
35
+ */
36
+ export const cliAmbiguityText = (params: {
37
+ value: string;
38
+ resources: CloudCliText;
39
+ candidates: readonly CloudCliCandidate[];
40
+ }): CloudCliText => {
41
+ const list = formatCliCandidates(params.candidates);
42
+ return {
43
+ en: `"${params.value}" matches several ${params.resources.en}: ${list}. Use one of these paths or IDs.`,
44
+ de: `„${params.value}“ passt zu mehreren ${params.resources.de}: ${list}. Verwende einen dieser Pfade oder eine ID.`,
45
+ };
46
+ };
package/src/cli/index.ts CHANGED
@@ -57,6 +57,7 @@ export type CloudCliModule = {
57
57
  };
58
58
 
59
59
  export * from "./access";
60
+ export * from "./address";
60
61
  export * from "./commands";
61
62
  export * from "./locale";
62
63
  export * from "./output";