@sequenceholdings/orm 2.8.2 → 2.8.3
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 +5 -0
- package/dist/cli.cjs +26 -23
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +30 -27
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readdir, readFile, mkdir, writeFile, stat, rm, realpath } from 'fs/promises';
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
3
|
import { basename, resolve, join, dirname, sep, extname } from 'path';
|
|
4
|
+
import { text } from 'stream/consumers';
|
|
4
5
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
5
6
|
import { createJiti } from 'jiti';
|
|
6
7
|
import { createHash } from 'crypto';
|
|
@@ -8,7 +9,7 @@ import { z } from 'zod';
|
|
|
8
9
|
import { buildSchema, parse, validate, Kind, valueFromASTUntyped, visit, print } from 'graphql';
|
|
9
10
|
import { PgParser } from '@supabase/pg-parser';
|
|
10
11
|
import { sql } from 'drizzle-orm';
|
|
11
|
-
import { pgSchema, PgDialect, QueryBuilder, getViewConfig, extractUsedTable, check, foreignKey, uniqueIndex, index, primaryKey, jsonb, date, timestamp, boolean, doublePrecision, numeric, bigint, integer, text, uuid } from 'drizzle-orm/pg-core';
|
|
12
|
+
import { pgSchema, PgDialect, QueryBuilder, getViewConfig, extractUsedTable, check, foreignKey, uniqueIndex, index, primaryKey, jsonb, date, timestamp, boolean, doublePrecision, numeric, bigint, integer, text as text$1, uuid } from 'drizzle-orm/pg-core';
|
|
12
13
|
import { generateDrizzleJson, upPgSnapshot, generateMigration } from 'drizzle-kit/api';
|
|
13
14
|
import { load } from 'js-yaml';
|
|
14
15
|
import { capabilityPinsSchema, customRolesBlockSchema, validateCapabilityPins } from '@sequenceholdings/custom-roles-manifest';
|
|
@@ -5461,8 +5462,8 @@ var SqlEmitter = class {
|
|
|
5461
5462
|
}
|
|
5462
5463
|
const result = node.op === "SETOP_UNION" ? this.union(node, scope) : this.projection(node, scope);
|
|
5463
5464
|
const { columns } = result;
|
|
5464
|
-
let
|
|
5465
|
-
if (list(node.sortClause).length)
|
|
5465
|
+
let text5 = `${ctes.length ? `WITH ${ctes.join(", ")} ` : ""}${result.text}`;
|
|
5466
|
+
if (list(node.sortClause).length) text5 += ` ORDER BY ${list(node.sortClause).map((n) => {
|
|
5466
5467
|
const sort = obj(obj(n).SortBy);
|
|
5467
5468
|
only(sort, ["node", "sortby_dir", "sortby_nulls", "location"]);
|
|
5468
5469
|
const direction = sort.sortby_dir === "SORTBY_DESC" ? "DESC" : sort.sortby_dir === "SORTBY_ASC" || sort.sortby_dir === "SORTBY_DEFAULT" ? "ASC" : fail3("unsupported SQL sort");
|
|
@@ -5473,10 +5474,10 @@ var SqlEmitter = class {
|
|
|
5473
5474
|
return `${projected.length === 1 ? quoteIdentifier(projected[0].name) : this.expr(value, scope).text} ${direction}${nulls}`;
|
|
5474
5475
|
}).join(", ")}`;
|
|
5475
5476
|
for (const [key, keyword] of [["limitCount", "LIMIT"], ["limitOffset", "OFFSET"]]) {
|
|
5476
|
-
if (node[key])
|
|
5477
|
+
if (node[key]) text5 += ` ${keyword} ${this.expr(obj(node[key]), scope).text}`;
|
|
5477
5478
|
}
|
|
5478
5479
|
this.depth--;
|
|
5479
|
-
return { text:
|
|
5480
|
+
return { text: text5, columns: resolveUnknown ? columns.map((c) => c.type === "unknown" ? { ...c, type: "text" } : c) : columns };
|
|
5480
5481
|
}
|
|
5481
5482
|
union(node, scope) {
|
|
5482
5483
|
for (const key of ["targetList", "fromClause", "whereClause", "groupClause", "havingClause"]) {
|
|
@@ -5517,11 +5518,11 @@ var SqlEmitter = class {
|
|
|
5517
5518
|
}
|
|
5518
5519
|
}
|
|
5519
5520
|
if (!targets.length || targets.length > 256) fail3("invalid SQL projection");
|
|
5520
|
-
let
|
|
5521
|
-
if (node.whereClause)
|
|
5522
|
-
if (list(node.groupClause).length)
|
|
5523
|
-
if (node.havingClause)
|
|
5524
|
-
return { text:
|
|
5521
|
+
let text5 = `SELECT ${targets.join(", ")}${from ? ` FROM ${from}` : ""}`;
|
|
5522
|
+
if (node.whereClause) text5 += ` WHERE ${this.expr(obj(node.whereClause), scope).text}`;
|
|
5523
|
+
if (list(node.groupClause).length) text5 += ` GROUP BY ${list(node.groupClause).map((n) => this.expr(obj(n), scope).text).join(", ")}`;
|
|
5524
|
+
if (node.havingClause) text5 += ` HAVING ${this.expr(obj(node.havingClause), scope).text}`;
|
|
5525
|
+
return { text: text5, columns };
|
|
5525
5526
|
}
|
|
5526
5527
|
from(node, scope) {
|
|
5527
5528
|
this.budget();
|
|
@@ -6080,7 +6081,7 @@ function isSeqView(value) {
|
|
|
6080
6081
|
}
|
|
6081
6082
|
var QUERY_COLUMN_FACTORIES = {
|
|
6082
6083
|
uuid: (name2) => uuid(name2),
|
|
6083
|
-
text: (name2) => text(name2),
|
|
6084
|
+
text: (name2) => text$1(name2),
|
|
6084
6085
|
integer: (name2) => integer(name2),
|
|
6085
6086
|
bigint: (name2) => bigint(name2, { mode: "bigint" }),
|
|
6086
6087
|
numeric: (name2) => numeric(name2),
|
|
@@ -7118,8 +7119,8 @@ function renderEnum(name2, values) {
|
|
|
7118
7119
|
${values.map((value) => ` ${value}`).join("\n")}
|
|
7119
7120
|
}`;
|
|
7120
7121
|
}
|
|
7121
|
-
function descriptionLines(
|
|
7122
|
-
const escaped =
|
|
7122
|
+
function descriptionLines(text5, indent) {
|
|
7123
|
+
const escaped = text5.replace(/"""/g, '\\"""');
|
|
7123
7124
|
return [`${indent}"""`, ...escaped.split("\n").map((line) => `${indent}${line}`), `${indent}"""`];
|
|
7124
7125
|
}
|
|
7125
7126
|
var PATTERN_COMPARISON_TYPES = /* @__PURE__ */ new Set(["String", "Int", "bigint", "uuid"]);
|
|
@@ -8454,7 +8455,7 @@ function comparisonTypeIssue(left, right, columns) {
|
|
|
8454
8455
|
}
|
|
8455
8456
|
var FACTORIES = {
|
|
8456
8457
|
uuid: (name2) => uuid(name2),
|
|
8457
|
-
text: (name2) => text(name2),
|
|
8458
|
+
text: (name2) => text$1(name2),
|
|
8458
8459
|
integer: (name2) => integer(name2),
|
|
8459
8460
|
// Mode 'bigint' keeps int8 lossless — mode 'number' silently rounds past
|
|
8460
8461
|
// 2^53. The read executor serializes BigInt to string for JSON.
|
|
@@ -8838,7 +8839,7 @@ function refreshFunctionStatements({ namespace, previous, current }) {
|
|
|
8838
8839
|
// src/engine/canonical2.ts
|
|
8839
8840
|
var FACTORIES2 = {
|
|
8840
8841
|
uuid: (name2) => uuid(name2),
|
|
8841
|
-
text: (name2) => text(name2),
|
|
8842
|
+
text: (name2) => text$1(name2),
|
|
8842
8843
|
integer: (name2) => integer(name2),
|
|
8843
8844
|
// Mode 'bigint' keeps int8 lossless — mode 'number' silently rounds past
|
|
8844
8845
|
// 2^53. The read executor serializes BigInt to string for JSON.
|
|
@@ -10290,7 +10291,7 @@ async function readMigrationSql(dir, entry) {
|
|
|
10290
10291
|
throw new OrmDefinitionError("missing migration file", path);
|
|
10291
10292
|
});
|
|
10292
10293
|
}
|
|
10293
|
-
var checksumOf = (
|
|
10294
|
+
var checksumOf = (text5) => createHash("sha256").update(text5).digest("hex");
|
|
10294
10295
|
var migrationName = (ordinal, contentHash) => `${pad(ordinal)}_${contentHash.slice(0, 12)}`;
|
|
10295
10296
|
function renderMigrationSql({
|
|
10296
10297
|
name: name2,
|
|
@@ -10659,10 +10660,10 @@ function createOrmMigrationExport({ schemaHash, payload }) {
|
|
|
10659
10660
|
return { ...contents, checksum: checksum(contents) };
|
|
10660
10661
|
}
|
|
10661
10662
|
function renderOrmMigrationExport(exported) {
|
|
10662
|
-
const
|
|
10663
|
+
const text5 = `${JSON.stringify(exported, null, 2)}
|
|
10663
10664
|
`;
|
|
10664
|
-
if (Buffer.byteLength(
|
|
10665
|
-
return
|
|
10665
|
+
if (Buffer.byteLength(text5, "utf8") > ORM_MIGRATION_EXPORT_MAX_BYTES) throw new Error("ORM migration export exceeds the size limit");
|
|
10666
|
+
return text5;
|
|
10666
10667
|
}
|
|
10667
10668
|
|
|
10668
10669
|
// src/compiler-gql/role-warnings.ts
|
|
@@ -10882,7 +10883,7 @@ function renderImportScript({
|
|
|
10882
10883
|
const procedure = renderProcedure({ targetSql, sourceSql, mapped, keys, onConflict, batchSize });
|
|
10883
10884
|
const call = `CALL pg_temp.seq_orm_import(${resume.join(", ")});`;
|
|
10884
10885
|
const omittedLine = omitted.length > 0 ? `-- Omitted columns keep their database default or NULL: ${omitted.join(", ")}` : "-- Every column is mapped.";
|
|
10885
|
-
const
|
|
10886
|
+
const text5 = [
|
|
10886
10887
|
"-- Sequence ORM data import",
|
|
10887
10888
|
`-- namespace: ${namespace}`,
|
|
10888
10889
|
`-- target: ${schemaName}.${table.table}`,
|
|
@@ -10906,7 +10907,7 @@ function renderImportScript({
|
|
|
10906
10907
|
call,
|
|
10907
10908
|
""
|
|
10908
10909
|
].join("\n");
|
|
10909
|
-
return { probeSql, text:
|
|
10910
|
+
return { probeSql, text: text5 };
|
|
10910
10911
|
}
|
|
10911
10912
|
function renderProbe({
|
|
10912
10913
|
sourceSql,
|
|
@@ -11279,10 +11280,10 @@ async function readSpec(flags) {
|
|
|
11279
11280
|
if (flags["--table"] || flags["--from"] || flags["--map"]) {
|
|
11280
11281
|
return { error: "--spec replaces --table, --from, and --map" };
|
|
11281
11282
|
}
|
|
11282
|
-
const
|
|
11283
|
+
const text5 = await readFile(resolve(flags["--spec"]), "utf8");
|
|
11283
11284
|
let parsed;
|
|
11284
11285
|
try {
|
|
11285
|
-
parsed = JSON.parse(
|
|
11286
|
+
parsed = JSON.parse(text5);
|
|
11286
11287
|
} catch {
|
|
11287
11288
|
return { error: `--spec ${flags["--spec"]} is not valid JSON` };
|
|
11288
11289
|
}
|
|
@@ -11362,6 +11363,7 @@ var USAGE = `usage:
|
|
|
11362
11363
|
--no-wait returns once the apply is queued
|
|
11363
11364
|
seq-studio orm execute <operation> [dir] --variables-file <file> -e <env>
|
|
11364
11365
|
execute one named persisted operation from this checkout's manifest as the signed-in caller
|
|
11366
|
+
variables-file accepts - or /dev/stdin to read JSON from stdin until EOF
|
|
11365
11367
|
seq-studio orm execute <namespace> <operation> -e <env> [--variables-file <file>] [--var <name>=<value>]...
|
|
11366
11368
|
execute the deployed version's operation by name (no checkout; seq-studio only)
|
|
11367
11369
|
seq-studio orm diff [dir] write/verify the committed migration standalone (--check is the offline CI gate; --allow-destructive consents; --rebase records a v1 -> v2 conversion as a verified no-op)
|
|
@@ -11642,21 +11644,21 @@ async function generateCommand(rest) {
|
|
|
11642
11644
|
schema_snapshot: workspace.tipSnapshot,
|
|
11643
11645
|
...migration ? { migration } : {}
|
|
11644
11646
|
} });
|
|
11645
|
-
const
|
|
11647
|
+
const text5 = renderOrmMigrationExport(exported);
|
|
11646
11648
|
const path = join(dir, ORM_MIGRATION_EXPORT_FILE);
|
|
11647
11649
|
if (check) {
|
|
11648
11650
|
const committed = await readFile(path, "utf8").catch((error) => {
|
|
11649
11651
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") return void 0;
|
|
11650
11652
|
throw error;
|
|
11651
11653
|
});
|
|
11652
|
-
if (committed !==
|
|
11654
|
+
if (committed !== text5) {
|
|
11653
11655
|
console.error(`${ORM_MIGRATION_EXPORT_FILE} is missing or stale; run seq-studio orm generate ${dir} --migration-export and commit it`);
|
|
11654
11656
|
return 1;
|
|
11655
11657
|
}
|
|
11656
11658
|
console.log(`${ORM_MIGRATION_EXPORT_FILE} matches the current definitions, operations, and committed migration`);
|
|
11657
11659
|
return 0;
|
|
11658
11660
|
}
|
|
11659
|
-
await writeFile(path,
|
|
11661
|
+
await writeFile(path, text5);
|
|
11660
11662
|
console.log(`wrote ${ORM_MIGRATION_EXPORT_FILE} (${exported.checksum.slice(0, 12)})`);
|
|
11661
11663
|
}
|
|
11662
11664
|
await writeGenerateOutputs(dir, compiled.project);
|
|
@@ -11747,7 +11749,8 @@ function parseExecuteArgs(rest) {
|
|
|
11747
11749
|
async function readExecuteVariables(variablesFile) {
|
|
11748
11750
|
let parsed;
|
|
11749
11751
|
try {
|
|
11750
|
-
|
|
11752
|
+
const contents = variablesFile === "-" || variablesFile === "/dev/stdin" ? await text(process.stdin) : await readFile(resolve(variablesFile), "utf8");
|
|
11753
|
+
parsed = JSON.parse(contents);
|
|
11751
11754
|
} catch (error) {
|
|
11752
11755
|
throw new OrmDefinitionError(
|
|
11753
11756
|
`could not read JSON variables from ${variablesFile}: ${error instanceof Error ? error.message : String(error)}`
|