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.
- package/README.md +122 -39
- package/dist/cjs/adapters/cockroachdb.d.ts +39 -0
- package/dist/cjs/adapters/index.d.ts +110 -0
- package/dist/cjs/adapters/yugabytedb.d.ts +51 -0
- package/dist/cjs/cli/config.d.ts +181 -0
- package/dist/cjs/cli/config.js +32 -6
- package/dist/cjs/cli/destructive.d.ts +38 -0
- package/dist/cjs/cli/index.d.ts +359 -0
- package/dist/cjs/cli/index.js +228 -56
- package/dist/cjs/cli/loader.d.ts +61 -0
- package/dist/cjs/cli/mcp.d.ts +42 -0
- package/dist/cjs/cli/migrate.d.ts +356 -0
- package/dist/cjs/cli/migrate.js +131 -40
- package/dist/cjs/cli/observe-ui.d.ts +1 -0
- package/dist/cjs/cli/observe-ui.js +14 -5
- package/dist/cjs/cli/observe.d.ts +25 -0
- package/dist/cjs/cli/observe.js +49 -12
- package/dist/cjs/cli/pii-tags.d.ts +53 -0
- package/dist/cjs/cli/prisma-report.d.ts +33 -0
- package/dist/cjs/cli/prisma-report.js +73 -0
- package/dist/cjs/cli/prisma-resolve.d.ts +106 -0
- package/dist/cjs/cli/prisma-resolve.js +1 -0
- package/dist/cjs/cli/prisma-schema.d.ts +176 -0
- package/dist/cjs/cli/prisma-schema.js +82 -4
- package/dist/cjs/cli/rate-limit.d.ts +32 -0
- package/dist/cjs/cli/rate-limit.js +45 -0
- package/dist/cjs/cli/studio-demo.d.ts +43 -0
- package/dist/cjs/cli/studio-ui.generated.d.ts +1 -0
- package/dist/cjs/cli/studio.d.ts +207 -0
- package/dist/cjs/cli/studio.js +136 -71
- package/dist/cjs/cli/ui.d.ts +73 -0
- package/dist/cjs/cli/ui.js +51 -9
- package/dist/cjs/client.d.ts +837 -0
- package/dist/cjs/client.js +3 -0
- package/dist/cjs/dialect.d.ts +516 -0
- package/dist/cjs/dialect.js +37 -12
- package/dist/cjs/errors.d.ts +370 -0
- package/dist/cjs/generate.d.ts +137 -0
- package/dist/cjs/generate.js +39 -6
- package/dist/cjs/index-advisor.d.ts +153 -0
- package/dist/cjs/index-stats.d.ts +384 -0
- package/dist/cjs/index.d.ts +55 -0
- package/dist/cjs/index.js +7 -2
- package/dist/cjs/introspect.d.ts +269 -0
- package/dist/cjs/mssql.d.ts +232 -0
- package/dist/cjs/mssql.js +6 -0
- package/dist/cjs/mysql.d.ts +173 -0
- package/dist/cjs/mysql.js +16 -0
- package/dist/cjs/nested-write.d.ts +96 -0
- package/dist/cjs/nested-write.js +414 -24
- package/dist/cjs/observe.d.ts +115 -0
- package/dist/cjs/optional-peer-import.d.cts +72 -0
- package/dist/cjs/pipeline-submittable.d.ts +93 -0
- package/dist/cjs/pipeline.d.ts +71 -0
- package/dist/cjs/powdb-introspect.d.ts +84 -0
- package/dist/cjs/powdb.d.ts +931 -0
- package/dist/cjs/powdb.js +106 -21
- package/dist/cjs/powql.d.ts +592 -0
- package/dist/cjs/powql.js +42 -6
- package/dist/cjs/prisma-compat.d.ts +283 -0
- package/dist/cjs/prisma-compat.js +167 -9
- package/dist/cjs/query/aggregates.d.ts +92 -0
- package/dist/cjs/query/aggregates.js +7 -3
- package/dist/cjs/query/batched-loader.d.ts +193 -0
- package/dist/cjs/query/builder.d.ts +849 -0
- package/dist/cjs/query/builder.js +571 -65
- package/dist/cjs/query/compound-unique.d.ts +51 -0
- package/dist/cjs/query/deferred.d.ts +223 -0
- package/dist/cjs/query/filters.d.ts +201 -0
- package/dist/cjs/query/index.d.ts +14 -0
- package/dist/cjs/query/index.js +6 -1
- package/dist/cjs/query/relations.d.ts +609 -0
- package/dist/cjs/query/relations.js +693 -46
- package/dist/cjs/query/types.d.ts +1300 -0
- package/dist/cjs/query/utils.d.ts +209 -0
- package/dist/cjs/query/utils.js +208 -1
- package/dist/cjs/query/warn-registry.d.ts +68 -0
- package/dist/cjs/query/warn-registry.js +9 -0
- package/dist/cjs/query/where-compile.d.ts +139 -0
- package/dist/cjs/query/where.d.ts +548 -0
- package/dist/cjs/query/where.js +58 -22
- package/dist/cjs/query/writes.d.ts +172 -0
- package/dist/cjs/query/writes.js +105 -12
- package/dist/cjs/realtime.d.ts +70 -0
- package/dist/cjs/schema-builder.d.ts +354 -0
- package/dist/cjs/schema-metadata.d.ts +83 -0
- package/dist/cjs/schema-sql.d.ts +217 -0
- package/dist/cjs/schema-sql.js +23 -5
- package/dist/cjs/schema.d.ts +356 -0
- package/dist/cjs/schema.js +125 -0
- package/dist/cjs/seed.d.ts +15 -0
- package/dist/cjs/serverless.d.ts +142 -0
- package/dist/cjs/sqlite.d.ts +143 -0
- package/dist/cjs/sqlite.js +4 -0
- package/dist/cjs/typed-sql.d.ts +102 -0
- package/dist/cli/config.d.ts +18 -4
- package/dist/cli/config.js +31 -6
- package/dist/cli/index.d.ts +123 -0
- package/dist/cli/index.js +223 -58
- package/dist/cli/migrate.d.ts +59 -10
- package/dist/cli/migrate.js +128 -41
- package/dist/cli/observe-ui.d.ts +1 -1
- package/dist/cli/observe-ui.js +14 -5
- package/dist/cli/observe.d.ts +7 -1
- package/dist/cli/observe.js +48 -12
- package/dist/cli/prisma-report.d.ts +14 -0
- package/dist/cli/prisma-report.js +72 -0
- package/dist/cli/prisma-resolve.d.ts +6 -0
- package/dist/cli/prisma-resolve.js +1 -0
- package/dist/cli/prisma-schema.d.ts +62 -2
- package/dist/cli/prisma-schema.js +81 -4
- package/dist/cli/rate-limit.d.ts +32 -0
- package/dist/cli/rate-limit.js +40 -0
- package/dist/cli/studio.d.ts +5 -5
- package/dist/cli/studio.js +135 -70
- package/dist/cli/ui.d.ts +1 -1
- package/dist/cli/ui.js +51 -9
- package/dist/client.d.ts +40 -0
- package/dist/client.js +3 -0
- package/dist/dialect.d.ts +17 -1
- package/dist/dialect.js +37 -12
- package/dist/generate.js +40 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mssql.js +6 -0
- package/dist/mysql.js +16 -0
- package/dist/nested-write.d.ts +2 -0
- package/dist/nested-write.js +415 -25
- package/dist/powdb.d.ts +4 -2
- package/dist/powdb.js +106 -21
- package/dist/powql.d.ts +5 -0
- package/dist/powql.js +42 -6
- package/dist/prisma-compat.d.ts +2 -0
- package/dist/prisma-compat.js +166 -8
- package/dist/query/aggregates.js +7 -3
- package/dist/query/builder.d.ts +292 -21
- package/dist/query/builder.js +570 -64
- package/dist/query/deferred.d.ts +39 -0
- package/dist/query/index.d.ts +1 -1
- package/dist/query/index.js +1 -1
- package/dist/query/relations.d.ts +173 -5
- package/dist/query/relations.js +688 -47
- package/dist/query/types.d.ts +123 -39
- package/dist/query/utils.d.ts +116 -0
- package/dist/query/utils.js +198 -0
- package/dist/query/warn-registry.d.ts +9 -0
- package/dist/query/warn-registry.js +9 -0
- package/dist/query/where.d.ts +38 -1
- package/dist/query/where.js +58 -23
- package/dist/query/writes.d.ts +42 -1
- package/dist/query/writes.js +104 -13
- package/dist/schema-sql.d.ts +14 -0
- package/dist/schema-sql.js +23 -5
- package/dist/schema.d.ts +38 -0
- package/dist/schema.js +123 -0
- package/dist/sqlite.js +4 -0
- 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
|
-
|
|
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.
|
|
661
|
-
// document column
|
|
662
|
-
//
|
|
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
|
|
822
|
+
return powdbJsonText(value);
|
|
789
823
|
if (value === undefined || value === null)
|
|
790
824
|
return null;
|
|
791
825
|
if (value instanceof Date)
|
|
792
|
-
return
|
|
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
|
-
|
|
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(
|
|
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 `${
|
|
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
|
-
//
|
|
1673
|
-
//
|
|
1674
|
-
return
|
|
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
|
-
/**
|
|
1711
|
-
|
|
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
|
/**
|