@tablecraft-app/plugin-api 1.1.0 → 1.3.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/dist/url.d.ts CHANGED
@@ -24,6 +24,7 @@ export interface ConnectionUrlSpec {
24
24
  readonly key: string;
25
25
  readonly values?: Readonly<Record<string, string>> | undefined;
26
26
  }[] | undefined;
27
+ readonly sets?: Readonly<Record<string, Readonly<Record<string, ConnectionValue>>>> | undefined;
27
28
  }
28
29
  interface UrlField {
29
30
  readonly key: string;
@@ -45,7 +46,8 @@ export interface ConnectionForm {
45
46
  */
46
47
  export declare function parseConnectionUrl(form: ConnectionForm, text: string): ParsedConnectionUrl;
47
48
  /**
48
- * The connection URL of `config`, in the plugin's first scheme. Never carries a secret field, so
49
+ * The connection URL of `config`, in the first scheme whose `sets` the config holds, else the first
50
+ * that sets nothing. Never carries a secret field, so
49
51
  * the result is safe to copy, show and log; params equal to their field's default are left out.
50
52
  */
51
53
  export declare function formatConnectionUrl(form: ConnectionForm, config: Readonly<Record<string, unknown>>): string;
package/dist/url.js CHANGED
@@ -112,6 +112,7 @@ function parseServer(form, url, text) {
112
112
  throw new ConnectionUrlError(`That is not a valid ${scheme}:// URL; check the port is a number and special characters are percent-encoded.`);
113
113
  }
114
114
  const collected = new Collected(form, url);
115
+ Object.assign(collected.values, url.sets?.[scheme]);
115
116
  collected.part("host", decoded(parsed.hostname.replace(/^\[(.*)\]$/, "$1")));
116
117
  collected.part("port", parsed.port);
117
118
  collected.part("database", decoded(parsed.pathname.replace(LEADING_SLASHES, "")));
@@ -178,12 +179,20 @@ function encodedPath(path) {
178
179
  return encodeURI(path).replaceAll("?", "%3F").replaceAll("#", "%23");
179
180
  }
180
181
  /**
181
- * The connection URL of `config`, in the plugin's first scheme. Never carries a secret field, so
182
+ * The connection URL of `config`, in the first scheme whose `sets` the config holds, else the first
183
+ * that sets nothing. Never carries a secret field, so
182
184
  * the result is safe to copy, show and log; params equal to their field's default are left out.
183
185
  */
184
186
  export function formatConnectionUrl(form, config) {
185
187
  const url = urlOf(form);
186
- const scheme = url.schemes[0] ?? "";
188
+ const implied = (candidate) => {
189
+ const sets = url.sets?.[candidate];
190
+ return sets !== undefined && Object.entries(sets).every(([key, value]) => config[key] === value);
191
+ };
192
+ const scheme = url.schemes.find(implied) ??
193
+ url.schemes.find((candidate) => url.sets?.[candidate] === undefined) ??
194
+ url.schemes[0] ??
195
+ "";
187
196
  const valueOf = (part) => {
188
197
  const key = url.parts[part];
189
198
  if (key === undefined || fieldOf(form, key)?.secret === true)
package/dist/version.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * The plugin contract's version, by semver (decision 106): a host loads a plugin built for the same
3
3
  * major and an older or equal minor. Typed `string` so a bump does not change the API report.
4
4
  */
5
- export const API_VERSION = "1.1.0";
5
+ export const API_VERSION = "1.3.0";
6
6
  const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
7
7
  /** `major.minor.patch` and nothing else; pre-release and build tags are not accepted. */
8
8
  export function parseVersion(text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablecraft-app/plugin-api",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "The datasource plugin contract for TableCraft",
5
5
  "license": "MIT",
6
6
  "type": "module",