postgresdk 0.19.0 → 0.19.1
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 +1 -1
- package/dist/cli.js +28 -9
- package/dist/index.js +28 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -594,7 +594,7 @@ const [order, updatedUser] = await sdk.$transaction([
|
|
|
594
594
|
// TypeScript infers: [SelectOrders, SelectUsers | null]
|
|
595
595
|
```
|
|
596
596
|
|
|
597
|
-
- `$create`, `$update`, `$
|
|
597
|
+
- `$create`, `$update`, `$softDelete`, `$hardDelete`, `$upsert` are **lazy builders** — nothing executes until `$transaction` is called
|
|
598
598
|
- All ops are Zod-validated **before** `BEGIN` is issued (fail-fast, no partial state)
|
|
599
599
|
- On any failure the transaction rolls back; an error is thrown with a `.failedAt` index
|
|
600
600
|
|
package/dist/cli.js
CHANGED
|
@@ -3662,6 +3662,20 @@ function emitClient(table, graph, opts, model) {
|
|
|
3662
3662
|
deleteMethodParts.push(buildDeleteMethod("hardDelete", hasSoftDelete));
|
|
3663
3663
|
const deleteMethodsCode = deleteMethodParts.join(`
|
|
3664
3664
|
|
|
3665
|
+
`);
|
|
3666
|
+
const txDeleteParts = [];
|
|
3667
|
+
if (hasSoftDelete)
|
|
3668
|
+
txDeleteParts.push(` /** Build a lazy soft-DELETE descriptor for use with sdk.$transaction([...]) */
|
|
3669
|
+
` + ` $softDelete(pk: ${pkType}): TxOp<Select${Type} | null> {
|
|
3670
|
+
` + ` return { _table: "${table.name}", _op: "softDelete", _pk: ${hasCompositePk ? "pk as Record<string, unknown>" : "pk"} };
|
|
3671
|
+
` + ` }`);
|
|
3672
|
+
if (exposeHard)
|
|
3673
|
+
txDeleteParts.push(` /** Build a lazy hard-DELETE descriptor for use with sdk.$transaction([...]) */
|
|
3674
|
+
` + ` $hardDelete(pk: ${pkType}): TxOp<Select${Type} | null> {
|
|
3675
|
+
` + ` return { _table: "${table.name}", _op: "hardDelete", _pk: ${hasCompositePk ? "pk as Record<string, unknown>" : "pk"} };
|
|
3676
|
+
` + ` }`);
|
|
3677
|
+
const txDeleteMethodsCode = txDeleteParts.join(`
|
|
3678
|
+
|
|
3665
3679
|
`);
|
|
3666
3680
|
return `/**
|
|
3667
3681
|
* AUTO-GENERATED FILE - DO NOT EDIT
|
|
@@ -4178,10 +4192,7 @@ ${deleteMethodsCode}
|
|
|
4178
4192
|
return { _table: "${table.name}", _op: "update", _pk: ${hasCompositePk ? "pk as Record<string, unknown>" : "pk"}, _data: data as Record<string, unknown> };
|
|
4179
4193
|
}
|
|
4180
4194
|
|
|
4181
|
-
|
|
4182
|
-
$delete(pk: ${pkType}): TxOp<Select${Type} | null> {
|
|
4183
|
-
return { _table: "${table.name}", _op: "delete", _pk: ${hasCompositePk ? "pk as Record<string, unknown>" : "pk"} };
|
|
4184
|
-
}
|
|
4195
|
+
${txDeleteMethodsCode}
|
|
4185
4196
|
|
|
4186
4197
|
/** Build a lazy UPSERT descriptor for use with sdk.$transaction([...]) */
|
|
4187
4198
|
$upsert(args: { where: Update${Type}; create: Insert${Type}; update: Update${Type} }): TxOp<Select${Type}> {
|
|
@@ -4535,13 +4546,13 @@ export abstract class BaseClient {
|
|
|
4535
4546
|
}
|
|
4536
4547
|
|
|
4537
4548
|
/**
|
|
4538
|
-
* Lazy operation descriptor returned by $create/$update/$
|
|
4549
|
+
* Lazy operation descriptor returned by $create/$update/$softDelete/$hardDelete/$upsert.
|
|
4539
4550
|
* \`__resultType\` is a phantom field — never assigned at runtime, exists only
|
|
4540
4551
|
* so TypeScript can infer the correct tuple element type inside \`$transaction\`.
|
|
4541
4552
|
*/
|
|
4542
4553
|
export type TxOp<T = unknown> = {
|
|
4543
4554
|
readonly _table: string;
|
|
4544
|
-
readonly _op: "create" | "update" | "
|
|
4555
|
+
readonly _op: "create" | "update" | "softDelete" | "hardDelete" | "upsert";
|
|
4545
4556
|
readonly _data?: Record<string, unknown>;
|
|
4546
4557
|
readonly _pk?: string | Record<string, unknown>;
|
|
4547
4558
|
/** @internal */
|
|
@@ -5619,11 +5630,16 @@ function emitHonoRouter(tables, hasAuth, useJsExtensions, pullToken, opts) {
|
|
|
5619
5630
|
return c.json({ error: \`Missing pk at index \${i}\`, failedAt: i }, 400);
|
|
5620
5631
|
}
|
|
5621
5632
|
validatedOps.push({ op: "update", table: item.table, pk: item.pk, data: parsed.data });
|
|
5622
|
-
} else if (item.op === "
|
|
5633
|
+
} else if (item.op === "softDelete") {
|
|
5634
|
+
if (item.pk == null) {
|
|
5635
|
+
return c.json({ error: \`Missing pk at index \${i}\`, failedAt: i }, 400);
|
|
5636
|
+
}
|
|
5637
|
+
validatedOps.push({ op: "softDelete", table: item.table, pk: item.pk });
|
|
5638
|
+
} else if (item.op === "hardDelete") {
|
|
5623
5639
|
if (item.pk == null) {
|
|
5624
5640
|
return c.json({ error: \`Missing pk at index \${i}\`, failedAt: i }, 400);
|
|
5625
5641
|
}
|
|
5626
|
-
validatedOps.push({ op: "
|
|
5642
|
+
validatedOps.push({ op: "hardDelete", table: item.table, pk: item.pk });
|
|
5627
5643
|
} else {
|
|
5628
5644
|
return c.json({ error: \`Unknown op "\${item?.op}" at index \${i}\`, failedAt: i }, 400);
|
|
5629
5645
|
}
|
|
@@ -6873,7 +6889,8 @@ export interface TransactionTableMetadata {
|
|
|
6873
6889
|
export type TransactionOperation =
|
|
6874
6890
|
| { op: "create"; table: string; data: Record<string, unknown> }
|
|
6875
6891
|
| { op: "update"; table: string; pk: string | Record<string, unknown>; data: Record<string, unknown> }
|
|
6876
|
-
| { op: "
|
|
6892
|
+
| { op: "softDelete"; table: string; pk: string | Record<string, unknown> }
|
|
6893
|
+
| { op: "hardDelete"; table: string; pk: string | Record<string, unknown> }
|
|
6877
6894
|
| { op: "upsert"; table: string; data: { where: Record<string, unknown>; create: Record<string, unknown>; update: Record<string, unknown> } };
|
|
6878
6895
|
|
|
6879
6896
|
/**
|
|
@@ -6941,6 +6958,8 @@ export async function executeTransaction(
|
|
|
6941
6958
|
: [op.pk];
|
|
6942
6959
|
result = op.op === "update"
|
|
6943
6960
|
? await updateRecord(ctx, pkValues as string[], op.data)
|
|
6961
|
+
: op.op === "hardDelete"
|
|
6962
|
+
? await deleteRecord(ctx, pkValues as string[], { hard: true })
|
|
6944
6963
|
: await deleteRecord(ctx, pkValues as string[]);
|
|
6945
6964
|
}
|
|
6946
6965
|
|
package/dist/index.js
CHANGED
|
@@ -2702,6 +2702,20 @@ function emitClient(table, graph, opts, model) {
|
|
|
2702
2702
|
deleteMethodParts.push(buildDeleteMethod("hardDelete", hasSoftDelete));
|
|
2703
2703
|
const deleteMethodsCode = deleteMethodParts.join(`
|
|
2704
2704
|
|
|
2705
|
+
`);
|
|
2706
|
+
const txDeleteParts = [];
|
|
2707
|
+
if (hasSoftDelete)
|
|
2708
|
+
txDeleteParts.push(` /** Build a lazy soft-DELETE descriptor for use with sdk.$transaction([...]) */
|
|
2709
|
+
` + ` $softDelete(pk: ${pkType}): TxOp<Select${Type} | null> {
|
|
2710
|
+
` + ` return { _table: "${table.name}", _op: "softDelete", _pk: ${hasCompositePk ? "pk as Record<string, unknown>" : "pk"} };
|
|
2711
|
+
` + ` }`);
|
|
2712
|
+
if (exposeHard)
|
|
2713
|
+
txDeleteParts.push(` /** Build a lazy hard-DELETE descriptor for use with sdk.$transaction([...]) */
|
|
2714
|
+
` + ` $hardDelete(pk: ${pkType}): TxOp<Select${Type} | null> {
|
|
2715
|
+
` + ` return { _table: "${table.name}", _op: "hardDelete", _pk: ${hasCompositePk ? "pk as Record<string, unknown>" : "pk"} };
|
|
2716
|
+
` + ` }`);
|
|
2717
|
+
const txDeleteMethodsCode = txDeleteParts.join(`
|
|
2718
|
+
|
|
2705
2719
|
`);
|
|
2706
2720
|
return `/**
|
|
2707
2721
|
* AUTO-GENERATED FILE - DO NOT EDIT
|
|
@@ -3218,10 +3232,7 @@ ${deleteMethodsCode}
|
|
|
3218
3232
|
return { _table: "${table.name}", _op: "update", _pk: ${hasCompositePk ? "pk as Record<string, unknown>" : "pk"}, _data: data as Record<string, unknown> };
|
|
3219
3233
|
}
|
|
3220
3234
|
|
|
3221
|
-
|
|
3222
|
-
$delete(pk: ${pkType}): TxOp<Select${Type} | null> {
|
|
3223
|
-
return { _table: "${table.name}", _op: "delete", _pk: ${hasCompositePk ? "pk as Record<string, unknown>" : "pk"} };
|
|
3224
|
-
}
|
|
3235
|
+
${txDeleteMethodsCode}
|
|
3225
3236
|
|
|
3226
3237
|
/** Build a lazy UPSERT descriptor for use with sdk.$transaction([...]) */
|
|
3227
3238
|
$upsert(args: { where: Update${Type}; create: Insert${Type}; update: Update${Type} }): TxOp<Select${Type}> {
|
|
@@ -3575,13 +3586,13 @@ export abstract class BaseClient {
|
|
|
3575
3586
|
}
|
|
3576
3587
|
|
|
3577
3588
|
/**
|
|
3578
|
-
* Lazy operation descriptor returned by $create/$update/$
|
|
3589
|
+
* Lazy operation descriptor returned by $create/$update/$softDelete/$hardDelete/$upsert.
|
|
3579
3590
|
* \`__resultType\` is a phantom field — never assigned at runtime, exists only
|
|
3580
3591
|
* so TypeScript can infer the correct tuple element type inside \`$transaction\`.
|
|
3581
3592
|
*/
|
|
3582
3593
|
export type TxOp<T = unknown> = {
|
|
3583
3594
|
readonly _table: string;
|
|
3584
|
-
readonly _op: "create" | "update" | "
|
|
3595
|
+
readonly _op: "create" | "update" | "softDelete" | "hardDelete" | "upsert";
|
|
3585
3596
|
readonly _data?: Record<string, unknown>;
|
|
3586
3597
|
readonly _pk?: string | Record<string, unknown>;
|
|
3587
3598
|
/** @internal */
|
|
@@ -4659,11 +4670,16 @@ function emitHonoRouter(tables, hasAuth, useJsExtensions, pullToken, opts) {
|
|
|
4659
4670
|
return c.json({ error: \`Missing pk at index \${i}\`, failedAt: i }, 400);
|
|
4660
4671
|
}
|
|
4661
4672
|
validatedOps.push({ op: "update", table: item.table, pk: item.pk, data: parsed.data });
|
|
4662
|
-
} else if (item.op === "
|
|
4673
|
+
} else if (item.op === "softDelete") {
|
|
4674
|
+
if (item.pk == null) {
|
|
4675
|
+
return c.json({ error: \`Missing pk at index \${i}\`, failedAt: i }, 400);
|
|
4676
|
+
}
|
|
4677
|
+
validatedOps.push({ op: "softDelete", table: item.table, pk: item.pk });
|
|
4678
|
+
} else if (item.op === "hardDelete") {
|
|
4663
4679
|
if (item.pk == null) {
|
|
4664
4680
|
return c.json({ error: \`Missing pk at index \${i}\`, failedAt: i }, 400);
|
|
4665
4681
|
}
|
|
4666
|
-
validatedOps.push({ op: "
|
|
4682
|
+
validatedOps.push({ op: "hardDelete", table: item.table, pk: item.pk });
|
|
4667
4683
|
} else {
|
|
4668
4684
|
return c.json({ error: \`Unknown op "\${item?.op}" at index \${i}\`, failedAt: i }, 400);
|
|
4669
4685
|
}
|
|
@@ -5913,7 +5929,8 @@ export interface TransactionTableMetadata {
|
|
|
5913
5929
|
export type TransactionOperation =
|
|
5914
5930
|
| { op: "create"; table: string; data: Record<string, unknown> }
|
|
5915
5931
|
| { op: "update"; table: string; pk: string | Record<string, unknown>; data: Record<string, unknown> }
|
|
5916
|
-
| { op: "
|
|
5932
|
+
| { op: "softDelete"; table: string; pk: string | Record<string, unknown> }
|
|
5933
|
+
| { op: "hardDelete"; table: string; pk: string | Record<string, unknown> }
|
|
5917
5934
|
| { op: "upsert"; table: string; data: { where: Record<string, unknown>; create: Record<string, unknown>; update: Record<string, unknown> } };
|
|
5918
5935
|
|
|
5919
5936
|
/**
|
|
@@ -5981,6 +5998,8 @@ export async function executeTransaction(
|
|
|
5981
5998
|
: [op.pk];
|
|
5982
5999
|
result = op.op === "update"
|
|
5983
6000
|
? await updateRecord(ctx, pkValues as string[], op.data)
|
|
6001
|
+
: op.op === "hardDelete"
|
|
6002
|
+
? await deleteRecord(ctx, pkValues as string[], { hard: true })
|
|
5984
6003
|
: await deleteRecord(ctx, pkValues as string[]);
|
|
5985
6004
|
}
|
|
5986
6005
|
|