@poe-platform/safe-bash 0.1.793 → 0.1.795

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.
Files changed (34) hide show
  1. package/dist/safe-bash/chunks/{chunk-BENDQWMV.js → chunk-6IBTC4YL.js} +16 -2
  2. package/dist/safe-bash/chunks/{chunk-HEENNMEW.js → chunk-ZXKVOJNL.js} +18 -22
  3. package/dist/safe-bash/command-chunks/{chunk-JCORWQ2I.js → chunk-7FKUC34S.js} +1 -1
  4. package/dist/safe-bash/command-chunks/{chunk-ZJB7XJXD.js → chunk-XAFSZDY2.js} +1 -1
  5. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  6. package/dist/safe-bash/commands/python/llm-capability.js +11 -2
  7. package/dist/safe-bash/commands/python/llm-module.js +6 -0
  8. package/dist/safe-bash/contracts/escaping.d.ts +2 -0
  9. package/dist/safe-bash/contracts/escaping.js +2 -0
  10. package/dist/safe-bash/full-core.browser.js +2 -2
  11. package/dist/safe-bash/opt-in/optional/commands/shuf/args.js +270 -168
  12. package/dist/safe-bash/opt-in/optional/commands/shuf/filesystem-output.js +19 -1
  13. package/dist/safe-bash/opt-in/optional/commands/shuf/input.js +121 -5
  14. package/dist/safe-bash/opt-in/optional/commands/shuf/random.d.ts +3 -0
  15. package/dist/safe-bash/opt-in/optional/commands/shuf/random.js +31 -23
  16. package/dist/safe-bash/opt-in/optional/commands/shuf/shuf.js +39 -37
  17. package/dist/safe-bash/shell/runtime.d.ts +1 -1
  18. package/dist/safe-bash/shell/runtime.js +14 -17
  19. package/dist/safe-bash/shell-entry.browser.js +1 -1
  20. package/dist/safe-bash-command-shuf/args.d.ts +6 -4
  21. package/dist/safe-bash-command-shuf/args.js +270 -168
  22. package/dist/safe-bash-command-shuf/filesystem-output.js +19 -1
  23. package/dist/safe-bash-command-shuf/input.d.ts +19 -1
  24. package/dist/safe-bash-command-shuf/input.js +121 -5
  25. package/dist/safe-bash-command-shuf/random.d.ts +3 -0
  26. package/dist/safe-bash-command-shuf/random.js +31 -23
  27. package/dist/safe-bash-command-shuf/shuf.js +39 -37
  28. package/dist/safe-bash-command-sqlite3/btree.d.ts +1 -1
  29. package/dist/safe-bash-command-sqlite3/engine.d.ts +1 -1
  30. package/dist/safe-bash-command-sqlite3/index.js +61 -63
  31. package/dist/safe-bash-io-engine/commands/search/requirements.js +2 -2
  32. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +2 -2
  33. package/dist/safe-bash-io-engine/internal.js +1 -1
  34. package/package.json +3 -3
@@ -228,8 +228,8 @@ function encodeRecordValue(val) {
228
228
  view.setFloat64(0, val, false);
229
229
  return { serialType: 7, body: b };
230
230
  }
231
- if (typeof val === "string") {
232
- const encoded = textEncoder.encode(val);
231
+ if (typeof val === "string" || val instanceof String) {
232
+ const encoded = textEncoder.encode(String(val));
233
233
  return { serialType: encoded.byteLength * 2 + 13, body: encoded };
234
234
  }
235
235
  const u8 = val;
@@ -574,7 +574,7 @@ function compareSqlValuesForBTree(a, b) {
574
574
  const rank = (v) => {
575
575
  if (v === null || v === void 0) return 0;
576
576
  if (typeof v === "number" || typeof v === "bigint" || v instanceof Number) return 1;
577
- if (typeof v === "string") return 2;
577
+ if (typeof v === "string" || v instanceof String) return 2;
578
578
  return 3;
579
579
  };
580
580
  const ra = rank(a);
@@ -786,6 +786,8 @@ function writeSqliteDatabaseBytes(image) {
786
786
 
787
787
  // packages/safe-bash-command-sqlite3/src/engine.ts
788
788
  function serializeSqlJson(value, preserveRealType = true) {
789
+ if (value instanceof JsonText && preserveRealType) return value.valueOf();
790
+ if (value instanceof String) return JSON.stringify(value.valueOf());
789
791
  if (typeof value === "bigint") return value.toString();
790
792
  if (value instanceof Number) {
791
793
  const number = value.valueOf();
@@ -799,6 +801,8 @@ function serializeSqlJson(value, preserveRealType = true) {
799
801
  }
800
802
  return JSON.stringify(value) ?? "null";
801
803
  }
804
+ var JsonText = class extends String {
805
+ };
802
806
  var textEncoder2 = new TextEncoder();
803
807
  var textDecoder2 = new TextDecoder("utf-8", { fatal: false });
804
808
  function cloneSqlValue(v) {
@@ -1535,7 +1539,7 @@ function typeRank(v) {
1535
1539
  if (typeof v === "number" || typeof v === "bigint" || v instanceof Number) {
1536
1540
  return 1;
1537
1541
  }
1538
- if (typeof v === "string") {
1542
+ if (typeof v === "string" || v instanceof String) {
1539
1543
  return 2;
1540
1544
  }
1541
1545
  return 3;
@@ -1558,8 +1562,8 @@ function compareSqlValues(a, b, collation = "BINARY") {
1558
1562
  return nA < nB ? -1 : nA > nB ? 1 : 0;
1559
1563
  }
1560
1564
  if (rA === 2) {
1561
- let sA = a;
1562
- let sB = b;
1565
+ let sA = String(a);
1566
+ let sB = String(b);
1563
1567
  const col = collation.toUpperCase();
1564
1568
  if (col === "RTRIM") {
1565
1569
  sA = sA.replace(/ +$/, "");
@@ -1593,8 +1597,8 @@ function toSqlNumber(v) {
1593
1597
  if (typeof v === "number") {
1594
1598
  return v;
1595
1599
  }
1596
- if (typeof v === "string") {
1597
- const trimmed = v.trim();
1600
+ if (typeof v === "string" || v instanceof String) {
1601
+ const trimmed = String(v).trim();
1598
1602
  const m = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(trimmed);
1599
1603
  return m ? Number(m[0]) : 0;
1600
1604
  }
@@ -1651,7 +1655,8 @@ function arithmeticNumber(value) {
1651
1655
  }
1652
1656
  return real ? new Number(Number(text.slice(0, end))) : integerResult(BigInt(text.slice(0, end)));
1653
1657
  }
1654
- function applyColumnAffinity(value, declaredType) {
1658
+ function applyColumnAffinity(storedValue, declaredType) {
1659
+ let value = storedValue instanceof String ? storedValue.valueOf() : storedValue;
1655
1660
  if (value === null || value instanceof Uint8Array) return value;
1656
1661
  const type = declaredType.toUpperCase();
1657
1662
  const integer = type.includes("INT");
@@ -1683,8 +1688,8 @@ function toSqlString(v) {
1683
1688
  if (v === null || v === void 0) {
1684
1689
  return "";
1685
1690
  }
1686
- if (typeof v === "string") {
1687
- return v;
1691
+ if (typeof v === "string" || v instanceof String) {
1692
+ return String(v);
1688
1693
  }
1689
1694
  if (typeof v === "bigint") {
1690
1695
  return v.toString();
@@ -3261,9 +3266,12 @@ var SqliteDatabase = class {
3261
3266
  const defVal = colDef.defaultExpr ? yield* this.evalScalarSql(colDef.defaultExpr, {}, []) : null;
3262
3267
  for (const r of tbl.rows) {
3263
3268
  yield;
3264
- r.data[colDef.name] = defVal;
3269
+ r.data[colDef.name] = applyColumnAffinity(defVal, colDef.type);
3265
3270
  }
3266
- tbl.sql = tbl.sql.replace(/\)\s*$/, `, ${colDef.name} ${colDef.type})`);
3271
+ const schemaTokens = tokenizeSql(tbl.sql);
3272
+ const closingIndex = schemaTokens.map((token) => token.value).lastIndexOf(")");
3273
+ schemaTokens.splice(closingIndex, 0, ...tokenizeSql(","), ...tokens.slice(idx));
3274
+ tbl.sql = reconstructTokensSql(schemaTokens);
3267
3275
  return;
3268
3276
  }
3269
3277
  if (action === "DROP") {
@@ -3341,8 +3349,8 @@ var SqliteDatabase = class {
3341
3349
  const n = val.valueOf();
3342
3350
  return Number.isFinite(n) && Number.isInteger(n) ? `${n}.0` : String(n);
3343
3351
  }
3344
- if (typeof val === "string") {
3345
- return `'${val.replace(/'/g, "''")}'`;
3352
+ if (typeof val === "string" || val instanceof String) {
3353
+ return `'${String(val).replace(/'/g, "''")}'`;
3346
3354
  }
3347
3355
  let hex = "";
3348
3356
  for (const b of val) {
@@ -4822,12 +4830,8 @@ var SqliteDatabase = class {
4822
4830
  }
4823
4831
  }
4824
4832
  return {
4825
- columns: selectTargets.map((t) => {
4826
- return t.alias;
4827
- }),
4828
- rows: finalProjected.map((p) => {
4829
- return p.values;
4830
- })
4833
+ columns: selectTargets.map((t) => t.alias),
4834
+ rows: finalProjected.map((p) => p.values.map((value) => value instanceof String ? value.valueOf() : value))
4831
4835
  };
4832
4836
  }
4833
4837
  *evaluateFromClause(fromTokens, positionalParams, cteScope) {
@@ -5978,16 +5982,16 @@ var SqliteDatabase = class {
5978
5982
  return vals2.length;
5979
5983
  }
5980
5984
  if (u === "JSON_GROUP_OBJECT") {
5981
- const obj = {};
5985
+ const entries = [];
5982
5986
  for (const r of filteredGroup) {
5983
5987
  yield;
5984
5988
  const k = yield* this.evalExprSteps(expr.args[0], r, positionalParams, cteScope);
5985
5989
  const v = yield* this.evalExprSteps(expr.args[1], r, positionalParams, cteScope);
5986
5990
  if (k !== null && k !== void 0) {
5987
- obj[toSqlString(k)] = this.sqlValToJsJson(v);
5991
+ entries.push(`${JSON.stringify(toSqlString(k))}:${serializeSqlJson(v)}`);
5988
5992
  }
5989
5993
  }
5990
- return serializeSqlJson(obj);
5994
+ return new JsonText(`{${entries.join(",")}}`);
5991
5995
  }
5992
5996
  let vals = yield* stepMap(filteredGroup, function* (r) {
5993
5997
  return expr.args[0] ? yield* this.evalExprSteps(expr.args[0], r, positionalParams, cteScope) : null;
@@ -6005,11 +6009,7 @@ var SqliteDatabase = class {
6005
6009
  return true;
6006
6010
  }, this);
6007
6011
  }
6008
- return serializeSqlJson(
6009
- vals.map((v) => {
6010
- return this.sqlValToJsJson(v);
6011
- })
6012
- );
6012
+ return new JsonText(serializeSqlJson(vals));
6013
6013
  }
6014
6014
  const nonNull = vals.filter((v) => v !== null && v !== void 0);
6015
6015
  let activeVals = nonNull;
@@ -6119,23 +6119,6 @@ var SqliteDatabase = class {
6119
6119
  }
6120
6120
  return null;
6121
6121
  }
6122
- sqlValToJsJson(v) {
6123
- if (v === null || v === void 0) {
6124
- return null;
6125
- }
6126
- if (typeof v === "string") {
6127
- const trimmed = v.trim();
6128
- if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
6129
- try {
6130
- return JSON.parse(trimmed);
6131
- } catch {
6132
- return v;
6133
- }
6134
- }
6135
- return v;
6136
- }
6137
- return v;
6138
- }
6139
6122
  *validateColumns(node, scope, positionalParams, cteScope) {
6140
6123
  if (!node || typeof node !== "object") return;
6141
6124
  if ("kind" in node && node.kind === "column") {
@@ -6448,7 +6431,8 @@ var SqliteDatabase = class {
6448
6431
  const parsed = JSON.parse(toSqlString(l));
6449
6432
  const path = typeof r === "number" ? `$[${r}]` : toSqlString(r).startsWith("$") ? toSqlString(r) : `$.${toSqlString(r)}`;
6450
6433
  const extracted = extractByJsonPath(parsed, path);
6451
- return jsonValueToSql(extracted, op === "->>");
6434
+ const value = jsonValueToSql(extracted, op === "->>");
6435
+ return op === "->" && typeof value === "string" ? new JsonText(value) : value;
6452
6436
  } catch {
6453
6437
  return null;
6454
6438
  }
@@ -6545,6 +6529,12 @@ var SqliteDatabase = class {
6545
6529
  return Number.isInteger(n) ? n : n;
6546
6530
  }
6547
6531
  *evalScalarFunction(name, args) {
6532
+ const value = yield* this.evalScalarFunctionValue(name, args);
6533
+ const u = name.toUpperCase();
6534
+ const jsonResult = ["JSON", "JSON_ARRAY", "JSON_OBJECT", "JSON_QUOTE", "JSON_PATCH", "JSON_REMOVE", "JSON_SET", "JSON_INSERT", "JSON_REPLACE"].includes(u);
6535
+ return jsonResult && typeof value === "string" ? new JsonText(value) : value;
6536
+ }
6537
+ *evalScalarFunctionValue(name, args) {
6548
6538
  const u = name.toUpperCase();
6549
6539
  const a0 = args[0] ?? null;
6550
6540
  const a1 = args[1] ?? null;
@@ -6576,7 +6566,7 @@ var SqliteDatabase = class {
6576
6566
  if (typeof a0 === "number") {
6577
6567
  return Number.isInteger(a0) ? "integer" : "real";
6578
6568
  }
6579
- if (typeof a0 === "string") {
6569
+ if (typeof a0 === "string" || a0 instanceof String) {
6580
6570
  return "text";
6581
6571
  }
6582
6572
  return "blob";
@@ -6901,7 +6891,17 @@ var SqliteDatabase = class {
6901
6891
  if (a0 === null) {
6902
6892
  return null;
6903
6893
  }
6904
- return JSON.stringify(JSON.parse(toSqlString(a0)));
6894
+ const text = toSqlString(a0);
6895
+ JSON.parse(text);
6896
+ let quoted = false;
6897
+ let escaped = false;
6898
+ let compact = "";
6899
+ for (const char of text) {
6900
+ if (quoted || ![" ", "\n", "\r", " "].includes(char)) compact += char;
6901
+ if (!escaped && char === '"') quoted = !quoted;
6902
+ escaped = quoted && !escaped && char === "\\";
6903
+ }
6904
+ return compact;
6905
6905
  }
6906
6906
  case "JSON_VALID": {
6907
6907
  if (a0 === null) {
@@ -6915,22 +6915,18 @@ var SqliteDatabase = class {
6915
6915
  }
6916
6916
  }
6917
6917
  case "JSON_QUOTE":
6918
- return a0 === null ? "null" : serializeSqlJson(this.sqlValToJsJson(a0));
6918
+ return a0 === null ? "null" : serializeSqlJson(a0);
6919
6919
  case "JSON_ARRAY":
6920
- return serializeSqlJson(
6921
- args.map((x) => {
6922
- return this.sqlValToJsJson(x);
6923
- })
6924
- );
6920
+ return serializeSqlJson(args);
6925
6921
  case "JSON_OBJECT": {
6926
- const obj = {};
6922
+ const entries = [];
6927
6923
  for (let i = 0; i + 1 < args.length; i += 2) {
6928
6924
  yield;
6929
6925
  if (args[i] !== null && args[i] !== void 0) {
6930
- obj[toSqlString(args[i])] = this.sqlValToJsJson(args[i + 1] ?? null);
6926
+ entries.push(`${JSON.stringify(toSqlString(args[i]))}:${serializeSqlJson(args[i + 1] ?? null)}`);
6931
6927
  }
6932
6928
  }
6933
- return serializeSqlJson(obj);
6929
+ return `{${entries.join(",")}}`;
6934
6930
  }
6935
6931
  case "JSON_EXTRACT": {
6936
6932
  if (a0 === null) {
@@ -6940,13 +6936,14 @@ var SqliteDatabase = class {
6940
6936
  const parsed = JSON.parse(toSqlString(a0));
6941
6937
  if (args.length <= 2) {
6942
6938
  const extracted = extractByJsonPath(parsed, toSqlString(a1 ?? "$"));
6943
- return jsonValueToSql(extracted, true);
6939
+ const value = jsonValueToSql(extracted, true);
6940
+ return extracted !== null && typeof extracted === "object" && typeof value === "string" ? new JsonText(value) : value;
6944
6941
  }
6945
6942
  const arr = args.slice(1).map((p) => {
6946
6943
  const v = extractByJsonPath(parsed, toSqlString(p ?? "$"));
6947
6944
  return v === void 0 ? null : v;
6948
6945
  });
6949
- return JSON.stringify(arr);
6946
+ return new JsonText(JSON.stringify(arr));
6950
6947
  } catch {
6951
6948
  return null;
6952
6949
  }
@@ -7005,7 +7002,8 @@ var SqliteDatabase = class {
7005
7002
  for (let i = 1; i + 1 < args.length; i += 2) {
7006
7003
  yield;
7007
7004
  const p = toSqlString(args[i] ?? "$");
7008
- const v = this.sqlValToJsJson(args[i + 1] ?? null);
7005
+ const value = args[i + 1] ?? null;
7006
+ const v = value instanceof JsonText ? JSON.parse(value.valueOf()) : value;
7009
7007
  cur = setByJsonPath(cur, p, v, mode);
7010
7008
  }
7011
7009
  return serializeSqlJson(cur);
@@ -7094,8 +7092,8 @@ function formatSqlQuote(v) {
7094
7092
  if (typeof v === "number") {
7095
7093
  return String(v);
7096
7094
  }
7097
- if (typeof v === "string") {
7098
- return `'${v.replace(/'/g, "''")}'`;
7095
+ if (typeof v === "string" || v instanceof String) {
7096
+ return `'${String(v).replace(/'/g, "''")}'`;
7099
7097
  }
7100
7098
  let hex = "";
7101
7099
  for (const b of v) {
@@ -5,8 +5,8 @@ import {
5
5
  requiredFileInput,
6
6
  searchRequirements,
7
7
  sedRequirements
8
- } from "../../../safe-bash/command-chunks/chunk-JCORWQ2I.js";
9
- import "../../../safe-bash/command-chunks/chunk-ZJB7XJXD.js";
8
+ } from "../../../safe-bash/command-chunks/chunk-7FKUC34S.js";
9
+ import "../../../safe-bash/command-chunks/chunk-XAFSZDY2.js";
10
10
  import "../../../safe-bash/command-chunks/chunk-PM2PFWPC.js";
11
11
  import "../../../safe-bash/command-chunks/chunk-RHKBCQYQ.js";
12
12
  import "../../../safe-bash/command-chunks/chunk-773DWG4H.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  requiredFileInput
3
- } from "../../../safe-bash/command-chunks/chunk-JCORWQ2I.js";
3
+ } from "../../../safe-bash/command-chunks/chunk-7FKUC34S.js";
4
4
  import {
5
5
  RESOLVED_EXIT_ONE,
6
6
  RESOLVED_EXIT_ZERO,
7
7
  builtInDirectContextExecutors
8
- } from "../../../safe-bash/command-chunks/chunk-ZJB7XJXD.js";
8
+ } from "../../../safe-bash/command-chunks/chunk-XAFSZDY2.js";
9
9
  import "../../../safe-bash/command-chunks/chunk-PM2PFWPC.js";
10
10
  import "../../../safe-bash/command-chunks/chunk-RHKBCQYQ.js";
11
11
  import {
@@ -44,7 +44,7 @@ import {
44
44
  requireOperands,
45
45
  syncCommandEvaluators,
46
46
  value
47
- } from "../safe-bash/command-chunks/chunk-ZJB7XJXD.js";
47
+ } from "../safe-bash/command-chunks/chunk-XAFSZDY2.js";
48
48
  import "../safe-bash/command-chunks/chunk-PM2PFWPC.js";
49
49
  import "../safe-bash/command-chunks/chunk-RHKBCQYQ.js";
50
50
  import "../safe-bash/command-chunks/chunk-773DWG4H.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.793",
3
+ "version": "0.1.795",
4
4
  "description": "Extensible virtual shell with pluggable filesystems and streaming commands",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -869,7 +869,7 @@
869
869
  "access": "public"
870
870
  },
871
871
  "dependencies": {
872
- "@poe-platform/safe-fs": "0.1.793",
872
+ "@poe-platform/safe-fs": "0.1.795",
873
873
  "pdf-lib": "1.17.1",
874
874
  "@noble/hashes": "2.4.0",
875
875
  "pako": "3.0.1",
@@ -1383,7 +1383,7 @@
1383
1383
  "./dist/safe-bash-xml-engine/json.js",
1384
1384
  "./dist/safe-bash-xml-engine/limits.js",
1385
1385
  "./dist/safe-bash-xml-engine/query.js",
1386
- "./dist/safe-bash/chunks/chunk-BENDQWMV.js",
1386
+ "./dist/safe-bash/chunks/chunk-6IBTC4YL.js",
1387
1387
  "./dist/safe-bash/chunks/chunk-D2XB7XIC.js",
1388
1388
  "./dist/safe-bash/chunks/chunk-KV7PKOHV.js",
1389
1389
  "./dist/safe-bash/chunks/chunk-NX2SQVON.js",