turbine-orm 0.49.0 → 0.50.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.
Files changed (157) hide show
  1. package/README.md +122 -39
  2. package/dist/cjs/adapters/cockroachdb.d.ts +39 -0
  3. package/dist/cjs/adapters/index.d.ts +110 -0
  4. package/dist/cjs/adapters/yugabytedb.d.ts +51 -0
  5. package/dist/cjs/cli/config.d.ts +181 -0
  6. package/dist/cjs/cli/config.js +32 -6
  7. package/dist/cjs/cli/destructive.d.ts +38 -0
  8. package/dist/cjs/cli/index.d.ts +359 -0
  9. package/dist/cjs/cli/index.js +228 -56
  10. package/dist/cjs/cli/loader.d.ts +61 -0
  11. package/dist/cjs/cli/mcp.d.ts +42 -0
  12. package/dist/cjs/cli/migrate.d.ts +356 -0
  13. package/dist/cjs/cli/migrate.js +131 -40
  14. package/dist/cjs/cli/observe-ui.d.ts +1 -0
  15. package/dist/cjs/cli/observe-ui.js +14 -5
  16. package/dist/cjs/cli/observe.d.ts +25 -0
  17. package/dist/cjs/cli/observe.js +49 -12
  18. package/dist/cjs/cli/pii-tags.d.ts +53 -0
  19. package/dist/cjs/cli/prisma-report.d.ts +33 -0
  20. package/dist/cjs/cli/prisma-report.js +73 -0
  21. package/dist/cjs/cli/prisma-resolve.d.ts +106 -0
  22. package/dist/cjs/cli/prisma-resolve.js +1 -0
  23. package/dist/cjs/cli/prisma-schema.d.ts +176 -0
  24. package/dist/cjs/cli/prisma-schema.js +82 -4
  25. package/dist/cjs/cli/rate-limit.d.ts +32 -0
  26. package/dist/cjs/cli/rate-limit.js +45 -0
  27. package/dist/cjs/cli/studio-demo.d.ts +43 -0
  28. package/dist/cjs/cli/studio-ui.generated.d.ts +1 -0
  29. package/dist/cjs/cli/studio.d.ts +207 -0
  30. package/dist/cjs/cli/studio.js +136 -71
  31. package/dist/cjs/cli/ui.d.ts +73 -0
  32. package/dist/cjs/cli/ui.js +51 -9
  33. package/dist/cjs/client.d.ts +837 -0
  34. package/dist/cjs/client.js +3 -0
  35. package/dist/cjs/dialect.d.ts +516 -0
  36. package/dist/cjs/dialect.js +37 -12
  37. package/dist/cjs/errors.d.ts +370 -0
  38. package/dist/cjs/generate.d.ts +137 -0
  39. package/dist/cjs/generate.js +39 -6
  40. package/dist/cjs/index-advisor.d.ts +153 -0
  41. package/dist/cjs/index-stats.d.ts +384 -0
  42. package/dist/cjs/index.d.ts +55 -0
  43. package/dist/cjs/index.js +7 -2
  44. package/dist/cjs/introspect.d.ts +269 -0
  45. package/dist/cjs/mssql.d.ts +232 -0
  46. package/dist/cjs/mssql.js +6 -0
  47. package/dist/cjs/mysql.d.ts +173 -0
  48. package/dist/cjs/mysql.js +16 -0
  49. package/dist/cjs/nested-write.d.ts +96 -0
  50. package/dist/cjs/nested-write.js +414 -24
  51. package/dist/cjs/observe.d.ts +115 -0
  52. package/dist/cjs/optional-peer-import.d.cts +72 -0
  53. package/dist/cjs/pipeline-submittable.d.ts +93 -0
  54. package/dist/cjs/pipeline.d.ts +71 -0
  55. package/dist/cjs/powdb-introspect.d.ts +84 -0
  56. package/dist/cjs/powdb.d.ts +931 -0
  57. package/dist/cjs/powdb.js +106 -21
  58. package/dist/cjs/powql.d.ts +592 -0
  59. package/dist/cjs/powql.js +42 -6
  60. package/dist/cjs/prisma-compat.d.ts +283 -0
  61. package/dist/cjs/prisma-compat.js +167 -9
  62. package/dist/cjs/query/aggregates.d.ts +92 -0
  63. package/dist/cjs/query/aggregates.js +7 -3
  64. package/dist/cjs/query/batched-loader.d.ts +193 -0
  65. package/dist/cjs/query/builder.d.ts +849 -0
  66. package/dist/cjs/query/builder.js +571 -65
  67. package/dist/cjs/query/compound-unique.d.ts +51 -0
  68. package/dist/cjs/query/deferred.d.ts +223 -0
  69. package/dist/cjs/query/filters.d.ts +201 -0
  70. package/dist/cjs/query/index.d.ts +14 -0
  71. package/dist/cjs/query/index.js +6 -1
  72. package/dist/cjs/query/relations.d.ts +609 -0
  73. package/dist/cjs/query/relations.js +693 -46
  74. package/dist/cjs/query/types.d.ts +1300 -0
  75. package/dist/cjs/query/utils.d.ts +209 -0
  76. package/dist/cjs/query/utils.js +208 -1
  77. package/dist/cjs/query/warn-registry.d.ts +68 -0
  78. package/dist/cjs/query/warn-registry.js +9 -0
  79. package/dist/cjs/query/where-compile.d.ts +139 -0
  80. package/dist/cjs/query/where.d.ts +548 -0
  81. package/dist/cjs/query/where.js +58 -22
  82. package/dist/cjs/query/writes.d.ts +172 -0
  83. package/dist/cjs/query/writes.js +105 -12
  84. package/dist/cjs/realtime.d.ts +70 -0
  85. package/dist/cjs/schema-builder.d.ts +354 -0
  86. package/dist/cjs/schema-metadata.d.ts +83 -0
  87. package/dist/cjs/schema-sql.d.ts +217 -0
  88. package/dist/cjs/schema-sql.js +23 -5
  89. package/dist/cjs/schema.d.ts +356 -0
  90. package/dist/cjs/schema.js +125 -0
  91. package/dist/cjs/seed.d.ts +15 -0
  92. package/dist/cjs/serverless.d.ts +142 -0
  93. package/dist/cjs/sqlite.d.ts +143 -0
  94. package/dist/cjs/sqlite.js +4 -0
  95. package/dist/cjs/typed-sql.d.ts +102 -0
  96. package/dist/cli/config.d.ts +18 -4
  97. package/dist/cli/config.js +31 -6
  98. package/dist/cli/index.d.ts +123 -0
  99. package/dist/cli/index.js +223 -58
  100. package/dist/cli/migrate.d.ts +59 -10
  101. package/dist/cli/migrate.js +128 -41
  102. package/dist/cli/observe-ui.d.ts +1 -1
  103. package/dist/cli/observe-ui.js +14 -5
  104. package/dist/cli/observe.d.ts +7 -1
  105. package/dist/cli/observe.js +48 -12
  106. package/dist/cli/prisma-report.d.ts +14 -0
  107. package/dist/cli/prisma-report.js +72 -0
  108. package/dist/cli/prisma-resolve.d.ts +6 -0
  109. package/dist/cli/prisma-resolve.js +1 -0
  110. package/dist/cli/prisma-schema.d.ts +62 -2
  111. package/dist/cli/prisma-schema.js +81 -4
  112. package/dist/cli/rate-limit.d.ts +32 -0
  113. package/dist/cli/rate-limit.js +40 -0
  114. package/dist/cli/studio.d.ts +5 -5
  115. package/dist/cli/studio.js +135 -70
  116. package/dist/cli/ui.d.ts +1 -1
  117. package/dist/cli/ui.js +51 -9
  118. package/dist/client.d.ts +40 -0
  119. package/dist/client.js +3 -0
  120. package/dist/dialect.d.ts +17 -1
  121. package/dist/dialect.js +37 -12
  122. package/dist/generate.js +40 -7
  123. package/dist/index.d.ts +1 -1
  124. package/dist/index.js +1 -1
  125. package/dist/mssql.js +6 -0
  126. package/dist/mysql.js +16 -0
  127. package/dist/nested-write.d.ts +2 -0
  128. package/dist/nested-write.js +415 -25
  129. package/dist/powdb.d.ts +4 -2
  130. package/dist/powdb.js +106 -21
  131. package/dist/powql.d.ts +5 -0
  132. package/dist/powql.js +42 -6
  133. package/dist/prisma-compat.d.ts +2 -0
  134. package/dist/prisma-compat.js +166 -8
  135. package/dist/query/aggregates.js +7 -3
  136. package/dist/query/builder.d.ts +292 -21
  137. package/dist/query/builder.js +570 -64
  138. package/dist/query/deferred.d.ts +39 -0
  139. package/dist/query/index.d.ts +1 -1
  140. package/dist/query/index.js +1 -1
  141. package/dist/query/relations.d.ts +173 -5
  142. package/dist/query/relations.js +688 -47
  143. package/dist/query/types.d.ts +123 -39
  144. package/dist/query/utils.d.ts +116 -0
  145. package/dist/query/utils.js +198 -0
  146. package/dist/query/warn-registry.d.ts +9 -0
  147. package/dist/query/warn-registry.js +9 -0
  148. package/dist/query/where.d.ts +38 -1
  149. package/dist/query/where.js +58 -23
  150. package/dist/query/writes.d.ts +42 -1
  151. package/dist/query/writes.js +104 -13
  152. package/dist/schema-sql.d.ts +14 -0
  153. package/dist/schema-sql.js +23 -5
  154. package/dist/schema.d.ts +38 -0
  155. package/dist/schema.js +123 -0
  156. package/dist/sqlite.js +4 -0
  157. package/package.json +77 -28
package/dist/cjs/powdb.js CHANGED
@@ -200,8 +200,11 @@ exports.PowdbFloatParam = PowdbFloatParam;
200
200
  */
201
201
  class PowdbJsonParam {
202
202
  value;
203
- constructor(value) {
203
+ column;
204
+ /** `column` is diagnostic only: it names the target column when serialization fails. */
205
+ constructor(value, column) {
204
206
  this.value = value;
207
+ this.column = column;
205
208
  }
206
209
  }
207
210
  exports.PowdbJsonParam = PowdbJsonParam;
@@ -657,9 +660,10 @@ function powqlSchemaDDL(schema, opts = {}) {
657
660
  // Declared indexes: PowDB doc-field expression indexes (docPath) and plain
658
661
  // single-column indexes. A doc-field index MUST be parenthesized (the engine
659
662
  // rejects a bare JSON path); string path segments emit lexer-exact via the
660
- // shared `encodePowqlString`, integer array indexes emit bare. A json
661
- // document column reference stays dotted-bare (`.col`), which bypasses
662
- // keyword lookup on every engine version exactly like a filter path.
663
+ // shared `encodePowqlString`, integer array indexes emit bare. The json
664
+ // document column goes through `quotePowqlIdent` exactly like the plain
665
+ // index branch below, so a keyword or non-bare identifier is backtick-quoted
666
+ // instead of being spliced raw into the statement.
663
667
  for (const idx of meta.indexes) {
664
668
  const kind = idx.unique ? 'unique' : 'index';
665
669
  if (idx.docPath) {
@@ -670,7 +674,7 @@ function powqlSchemaDDL(schema, opts = {}) {
670
674
  throw new errors_js_1.ValidationError(`[turbine] Doc-field index "${idx.name}" on ${meta.name} has no target json column.`);
671
675
  }
672
676
  const segs = idx.docPath.map((s) => (typeof s === 'number' ? `->${s}` : `->${encodePowqlString(s)}`)).join('');
673
- stmts.push(`alter ${quotePowqlIdent(meta.name)} add ${kind} (.${column}${segs})`);
677
+ stmts.push(`alter ${quotePowqlIdent(meta.name)} add ${kind} (.${quotePowqlIdent(column)}${segs})`);
674
678
  }
675
679
  else {
676
680
  // Plain column index. PowDB has no composite index (`add index` takes a
@@ -778,6 +782,36 @@ async function listPowdbLinks(exec) {
778
782
  function powdbCell(v) {
779
783
  return v === null || v === undefined ? '' : String(v);
780
784
  }
785
+ /**
786
+ * Serialize a json-column value to the canonical JSON text both transports
787
+ * send. `JSON.stringify` can throw (circular structure, a BigInt cell, a
788
+ * throwing `toJSON`) and can return `undefined` (a value that serializes to
789
+ * nothing, e.g. a `toJSON` returning undefined); both surface as a typed E003
790
+ * naming the column instead of a raw TypeError or an undefined param.
791
+ */
792
+ function powdbJsonText(param, position) {
793
+ const where = `for column "${param.column ?? '(unknown)'}"${position ? ` (${position})` : ''}`;
794
+ let json;
795
+ try {
796
+ json = JSON.stringify(param.value);
797
+ }
798
+ catch (err) {
799
+ throw new errors_js_1.ValidationError(`[turbine] The json value ${where} cannot be serialized for PowDB: ${err.message}`);
800
+ }
801
+ if (json === undefined) {
802
+ throw new errors_js_1.ValidationError(`[turbine] The json value ${where} serializes to nothing (JSON.stringify returned undefined); ` +
803
+ 'write `null` explicitly instead.');
804
+ }
805
+ return json;
806
+ }
807
+ /** Convert a Date to PowDB epoch micros, refusing an invalid Date (getTime() is NaN). */
808
+ function powdbDateMicros(value, position) {
809
+ const ms = value.getTime();
810
+ if (!Number.isFinite(ms)) {
811
+ throw new errors_js_1.ValidationError(`[turbine] Invalid Date${position ? ` (${position})` : ''} cannot be encoded as a PowDB timestamp.`);
812
+ }
813
+ return BigInt(ms) * 1000n;
814
+ }
781
815
  /** Coerce a JS value into a PowDB positional param (the write side). */
782
816
  function toPowdbParam(value, col) {
783
817
  if (value instanceof PowdbFloatParam)
@@ -785,11 +819,11 @@ function toPowdbParam(value, col) {
785
819
  // json document: serialize to canonical JSON text and bind as a str param,
786
820
  // the engine validates it as JSON and stores the canonical binary form.
787
821
  if (value instanceof PowdbJsonParam)
788
- return JSON.stringify(value.value);
822
+ return powdbJsonText(value);
789
823
  if (value === undefined || value === null)
790
824
  return null;
791
825
  if (value instanceof Date)
792
- return BigInt(value.getTime()) * 1000n; // ms → micros (int column)
826
+ return powdbDateMicros(value); // ms → micros (int column)
793
827
  if (col && isDateColumn(col) && typeof value === 'number')
794
828
  return BigInt(value) * 1000n;
795
829
  if (typeof value === 'boolean' ||
@@ -1646,36 +1680,74 @@ function normalizeEmbeddedResult(r) {
1646
1680
  * quotes, backslashes, `$N`, `"); drop … --`, raw CR, and emoji all round-trip
1647
1681
  * as data and cannot break out of the literal or inject a second statement.
1648
1682
  */
1649
- function encodePowqlLiteral(value) {
1683
+ function encodePowqlLiteral(value, position) {
1684
+ const at = position ? ` (${position})` : '';
1650
1685
  if (value instanceof PowdbFloatParam) {
1651
1686
  const n = value.value;
1652
1687
  if (!Number.isFinite(n))
1653
- throw new errors_js_1.ValidationError(`[turbine] Non-finite float cannot be encoded for PowDB.`);
1688
+ throw new errors_js_1.ValidationError(`[turbine] Non-finite float cannot be encoded for PowDB${at}.`);
1654
1689
  // Force a float-form literal so an integer-valued float column stays a float.
1655
- return Number.isInteger(n) ? `${n}.0` : String(n);
1690
+ const text = powqlNumberText(n);
1691
+ return text.includes('.') ? text : `${text}.0`;
1656
1692
  }
1657
1693
  // json document: emit the canonical JSON text as a PowQL string literal (the
1658
1694
  // embedded engine validates and stores it as a json document).
1659
1695
  if (value instanceof PowdbJsonParam)
1660
- return encodePowqlString(JSON.stringify(value.value));
1696
+ return encodePowqlString(powdbJsonText(value, position), position);
1661
1697
  if (value === undefined || value === null)
1662
1698
  return 'null';
1663
1699
  if (value instanceof Date)
1664
- return `${BigInt(value.getTime()) * 1000n}`; // epoch micros (int column)
1700
+ return `${powdbDateMicros(value, position)}`; // epoch micros (int column)
1665
1701
  if (typeof value === 'boolean')
1666
1702
  return value ? 'true' : 'false';
1667
1703
  if (typeof value === 'bigint')
1668
1704
  return value.toString();
1669
1705
  if (typeof value === 'number') {
1670
1706
  if (!Number.isFinite(value))
1671
- throw new errors_js_1.ValidationError(`[turbine] Non-finite number cannot be encoded for PowDB.`);
1672
- // `String(n)` renders an integer as an int literal (`42`) and a fractional
1673
- // number as a float literal (`4.2`) — PowQL distinguishes them by the dot.
1674
- return String(value);
1707
+ throw new errors_js_1.ValidationError(`[turbine] Non-finite number cannot be encoded for PowDB${at}.`);
1708
+ // Renders an integer as an int literal (`42`) and a fractional number as a
1709
+ // float literal (`4.2`); PowQL distinguishes them by the dot.
1710
+ return powqlNumberText(value);
1675
1711
  }
1676
1712
  if (typeof value === 'string')
1677
- return encodePowqlString(value);
1678
- throw new errors_js_1.ValidationError(`[turbine] Value of type ${typeof value} cannot be encoded as a PowDB literal.`);
1713
+ return encodePowqlString(value, position);
1714
+ throw new errors_js_1.ValidationError(`[turbine] Value of type ${typeof value} cannot be encoded as a PowDB literal${at}.`);
1715
+ }
1716
+ /**
1717
+ * Render a finite JS number as PowQL numeric text.
1718
+ *
1719
+ * `String(n)` is used verbatim for every ordinary magnitude (an integer becomes
1720
+ * `42`, a fractional number `4.2`), but it switches to exponential notation at
1721
+ * `1e21` and below `1e-6` (`1e+21`, `1.5e-7`), which the PowQL lexer does not
1722
+ * accept as a number token (and which the float path would further mangle into
1723
+ * `1e+21.0`). Those two ranges are expanded into plain decimal digits so any
1724
+ * finite double round-trips to a literal the engine can parse.
1725
+ */
1726
+ function powqlNumberText(n) {
1727
+ const s = String(n);
1728
+ if (!s.includes('e') && !s.includes('E'))
1729
+ return s;
1730
+ // Integer-valued doubles (|n| >= 1e21) expand exactly through BigInt.
1731
+ if (Number.isInteger(n))
1732
+ return BigInt(n).toString();
1733
+ const m = /^(-?)(\d+)(?:\.(\d+))?[eE]([+-]?\d+)$/.exec(s);
1734
+ if (!m) {
1735
+ throw new errors_js_1.ValidationError(`[turbine] Number ${s} cannot be rendered as a PowDB literal.`);
1736
+ }
1737
+ const sign = m[1] ?? '';
1738
+ const intPart = m[2] ?? '';
1739
+ const fracPart = m[3] ?? '';
1740
+ const exp = Number(m[4]);
1741
+ const digits = intPart + fracPart;
1742
+ const pointPos = intPart.length + exp;
1743
+ let body;
1744
+ if (pointPos <= 0)
1745
+ body = `0.${'0'.repeat(-pointPos)}${digits}`;
1746
+ else if (pointPos >= digits.length)
1747
+ body = digits + '0'.repeat(pointPos - digits.length);
1748
+ else
1749
+ body = `${digits.slice(0, pointPos)}.${digits.slice(pointPos)}`;
1750
+ return sign + body;
1679
1751
  }
1680
1752
  /**
1681
1753
  * The newest PowDB engine LINE (major.minor) whose lexer escape handling
@@ -1707,8 +1779,21 @@ function encodePowqlLiteral(value) {
1707
1779
  * already covers every 0.19.x patch — no bump is needed for 0.19.1.
1708
1780
  */
1709
1781
  exports.POWQL_LEXER_TESTED_CEILING = '0.19';
1710
- /** Escape a string into a PowQL `"…"` literal, matching the engine lexer's escape rules. */
1711
- function encodePowqlString(s) {
1782
+ /**
1783
+ * Escape a string into a PowQL `"…"` literal, matching the engine lexer's
1784
+ * escape rules.
1785
+ *
1786
+ * A raw NUL (U+0000) is REFUSED rather than emitted: the lexer defines no `\0`
1787
+ * escape (its escape set is exactly `\"`, `\\`, `\n`, `\t`, see
1788
+ * {@link POWQL_LEXER_TESTED_CEILING}), so a NUL would travel into the query
1789
+ * text as a raw byte and any layer that treats that text as a C string would
1790
+ * silently truncate the statement there.
1791
+ */
1792
+ function encodePowqlString(s, position) {
1793
+ if (s.includes('\0')) {
1794
+ throw new errors_js_1.ValidationError(`[turbine] String value${position ? ` (${position})` : ''} contains a NUL byte (U+0000), which PowQL string ` +
1795
+ 'literals cannot represent. Strip it before writing.');
1796
+ }
1712
1797
  let out = '"';
1713
1798
  for (const ch of s) {
1714
1799
  if (ch === '\\')
@@ -1738,7 +1823,7 @@ function materializePowql(powql, params) {
1738
1823
  if (idx < 0 || idx >= params.length) {
1739
1824
  throw new errors_js_1.ValidationError(`[turbine] PowQL placeholder $${n} has no bound parameter (have ${params.length}).`);
1740
1825
  }
1741
- return encodePowqlLiteral(params[idx]);
1826
+ return encodePowqlLiteral(params[idx], `parameter $${n}`);
1742
1827
  });
1743
1828
  }
1744
1829
  /**