@staff0rd/assist 0.454.0 → 0.455.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/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.454.0",
9
+ version: "0.455.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -3587,7 +3587,7 @@ function unwrapSchemaNode(node) {
3587
3587
  return { inner: current, defaultValue };
3588
3588
  }
3589
3589
 
3590
- // src/shared/describeConfigLeaves.ts
3590
+ // src/shared/scalarUnionMembers.ts
3591
3591
  var LEAF_TYPES = {
3592
3592
  string: "string",
3593
3593
  number: "number",
@@ -3596,9 +3596,39 @@ var LEAF_TYPES = {
3596
3596
  array: "array",
3597
3597
  record: "record"
3598
3598
  };
3599
- function leafType(node) {
3599
+ var SCALAR_LEAF_TYPES = /* @__PURE__ */ new Set([
3600
+ "string",
3601
+ "number",
3602
+ "boolean",
3603
+ "enum"
3604
+ ]);
3605
+ function leafTypeOf(node) {
3600
3606
  return LEAF_TYPES[node.def?.type ?? ""] ?? "other";
3601
3607
  }
3608
+ function isScalarLeafType(type) {
3609
+ return SCALAR_LEAF_TYPES.has(type);
3610
+ }
3611
+ function scalarUnionMembers(node) {
3612
+ const options2 = node.def?.options;
3613
+ if (node.def?.type !== "union" || !options2?.length) return void 0;
3614
+ const members = [];
3615
+ for (const option of options2) {
3616
+ const type = leafTypeOf(unwrapSchemaNode(option).inner);
3617
+ if (!isScalarLeafType(type)) return void 0;
3618
+ members.push(type);
3619
+ }
3620
+ return members;
3621
+ }
3622
+
3623
+ // src/shared/scalarArrayItemType.ts
3624
+ function scalarArrayItemType(node) {
3625
+ const element = node.def?.element;
3626
+ if (node.def?.type !== "array" || !element) return void 0;
3627
+ const type = leafTypeOf(unwrapSchemaNode(element).inner);
3628
+ return isScalarLeafType(type) ? type : void 0;
3629
+ }
3630
+
3631
+ // src/shared/describeConfigLeaves.ts
3602
3632
  function enumValues(node) {
3603
3633
  const entries = node.def?.entries;
3604
3634
  if (!entries) return void 0;
@@ -3607,9 +3637,13 @@ function enumValues(node) {
3607
3637
  );
3608
3638
  }
3609
3639
  function toLeaf(key, node, defaultValue) {
3610
- const type = leafType(node);
3640
+ const unionTypes = scalarUnionMembers(node);
3641
+ const type = unionTypes ? "union" : leafTypeOf(node);
3611
3642
  const leaf = { key, type };
3612
3643
  if (type === "enum") leaf.enumValues = enumValues(node);
3644
+ if (unionTypes) leaf.unionTypes = unionTypes;
3645
+ const itemType = scalarArrayItemType(node);
3646
+ if (itemType) leaf.itemType = itemType;
3613
3647
  if (defaultValue !== void 0) leaf.defaultValue = defaultValue;
3614
3648
  return leaf;
3615
3649
  }
@@ -10052,21 +10086,10 @@ function applyConfigSet(key, coerced, global, cwd = process.cwd()) {
10052
10086
  return { ok: true, target: "project" };
10053
10087
  }
10054
10088
 
10055
- // src/commands/config/coerceConfigValue.ts
10056
- var EDITABLE_TYPES = /* @__PURE__ */ new Set(["string", "number", "boolean", "enum"]);
10057
- function coerceConfigValue(key, raw) {
10058
- const leaf = describeConfigLeaves(assistConfigSchema).find(
10059
- (candidate) => candidate.key === key
10060
- );
10061
- if (!leaf) return { ok: false, error: `Unknown config key "${key}"` };
10062
- if (!EDITABLE_TYPES.has(leaf.type)) {
10063
- return {
10064
- ok: false,
10065
- error: `"${key}" is a ${leaf.type} value and is read-only here`
10066
- };
10067
- }
10068
- if (leaf.type === "boolean") return coerceBoolean(key, raw);
10069
- if (leaf.type === "number") return coerceNumber(key, raw);
10089
+ // src/commands/config/coerceConfigScalar.ts
10090
+ function coerceConfigScalar(key, raw, type) {
10091
+ if (type === "boolean") return coerceBoolean(key, raw);
10092
+ if (type === "number") return coerceNumber(key, raw);
10070
10093
  return coerceString(key, raw);
10071
10094
  }
10072
10095
  function coerceBoolean(key, raw) {
@@ -10090,6 +10113,53 @@ function coerceString(key, raw) {
10090
10113
  return { ok: false, error: `${key}: expected a string` };
10091
10114
  }
10092
10115
 
10116
+ // src/commands/config/coerceConfigValue.ts
10117
+ var EDITABLE_TYPES = /* @__PURE__ */ new Set([
10118
+ "string",
10119
+ "number",
10120
+ "boolean",
10121
+ "enum",
10122
+ "union"
10123
+ ]);
10124
+ function coerceConfigValue(key, raw) {
10125
+ const leaf = describeConfigLeaves(assistConfigSchema).find(
10126
+ (candidate) => candidate.key === key
10127
+ );
10128
+ if (!leaf) return { ok: false, error: `Unknown config key "${key}"` };
10129
+ if (leaf.itemType) return coerceScalarList(key, raw, leaf.itemType);
10130
+ if (!EDITABLE_TYPES.has(leaf.type)) {
10131
+ return {
10132
+ ok: false,
10133
+ error: `"${key}" is a ${leaf.type} value and is read-only here`
10134
+ };
10135
+ }
10136
+ if (leaf.type === "union")
10137
+ return coerceUnion(key, raw, leaf.unionTypes ?? []);
10138
+ return coerceConfigScalar(key, raw, leaf.type);
10139
+ }
10140
+ function coerceScalarList(key, raw, itemType) {
10141
+ if (!Array.isArray(raw)) {
10142
+ return {
10143
+ ok: false,
10144
+ error: `${key}: expected a list of ${itemType} values`
10145
+ };
10146
+ }
10147
+ const values = [];
10148
+ for (const item of raw) {
10149
+ const result = coerceConfigScalar(key, item, itemType);
10150
+ if (!result.ok) return result;
10151
+ values.push(result.value);
10152
+ }
10153
+ return { ok: true, value: values };
10154
+ }
10155
+ function coerceUnion(key, raw, types) {
10156
+ for (const type of types) {
10157
+ const result = coerceConfigScalar(key, raw, type);
10158
+ if (result.ok) return result;
10159
+ }
10160
+ return { ok: false, error: `${key}: expected ${types.join(" or ")}` };
10161
+ }
10162
+
10093
10163
  // src/commands/sessions/web/readJsonBody.ts
10094
10164
  async function readJsonBody(req) {
10095
10165
  const chunks = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.454.0",
3
+ "version": "0.455.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {