@fragno-dev/db 0.2.0 → 0.2.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/.turbo/turbo-build.log +20 -20
- package/CHANGELOG.md +17 -0
- package/dist/db-fragment-definition-builder.d.ts +55 -1
- package/dist/db-fragment-definition-builder.d.ts.map +1 -1
- package/dist/db-fragment-definition-builder.js +49 -5
- package/dist/db-fragment-definition-builder.js.map +1 -1
- package/dist/fragments/internal-fragment.d.ts.map +1 -1
- package/dist/fragments/internal-fragment.js.map +1 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/query/unit-of-work/execute-unit-of-work.d.ts +37 -1
- package/dist/query/unit-of-work/execute-unit-of-work.d.ts.map +1 -1
- package/dist/query/unit-of-work/execute-unit-of-work.js +133 -1
- package/dist/query/unit-of-work/execute-unit-of-work.js.map +1 -1
- package/dist/query/unit-of-work/unit-of-work.d.ts +18 -3
- package/dist/query/unit-of-work/unit-of-work.d.ts.map +1 -1
- package/dist/query/unit-of-work/unit-of-work.js +25 -11
- package/dist/query/unit-of-work/unit-of-work.js.map +1 -1
- package/dist/schema/create.d.ts +0 -3
- package/dist/schema/create.d.ts.map +1 -1
- package/dist/schema/create.js +0 -4
- package/dist/schema/create.js.map +1 -1
- package/dist/sql-driver/dialects/durable-object-dialect.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/adapters/drizzle/drizzle-adapter-pglite.test.ts +1 -0
- package/src/db-fragment-definition-builder.ts +187 -7
- package/src/fragments/internal-fragment.ts +0 -1
- package/src/hooks/hooks.test.ts +28 -16
- package/src/query/unit-of-work/execute-unit-of-work.test.ts +555 -1
- package/src/query/unit-of-work/execute-unit-of-work.ts +312 -4
- package/src/query/unit-of-work/unit-of-work-coordinator.test.ts +249 -1
- package/src/query/unit-of-work/unit-of-work.ts +39 -17
- package/src/schema/create.ts +0 -5
|
@@ -917,7 +917,11 @@ export interface IUnitOfWork {
|
|
|
917
917
|
getCreatedIds(): FragnoId[];
|
|
918
918
|
|
|
919
919
|
// Parent-child relationships
|
|
920
|
-
restrict(): IUnitOfWork;
|
|
920
|
+
restrict(options?: { readyFor?: "mutation" | "retrieval" | "none" }): IUnitOfWork;
|
|
921
|
+
|
|
922
|
+
// Coordination for restricted UOWs
|
|
923
|
+
signalReadyForRetrieval(): void;
|
|
924
|
+
signalReadyForMutation(): void;
|
|
921
925
|
|
|
922
926
|
// Reset for retry support
|
|
923
927
|
reset(): void;
|
|
@@ -1275,8 +1279,15 @@ export class UnitOfWork<const TRawInput = unknown> implements IUnitOfWork {
|
|
|
1275
1279
|
* Create a restricted child UOW that cannot execute phases.
|
|
1276
1280
|
* The child shares the same operation storage but must signal readiness
|
|
1277
1281
|
* before the parent can execute each phase.
|
|
1282
|
+
*
|
|
1283
|
+
* @param options.readyFor - Controls automatic readiness signaling:
|
|
1284
|
+
* - "mutation" (default): Signals ready for both retrieval and mutation immediately
|
|
1285
|
+
* - "retrieval": Signals ready for retrieval only
|
|
1286
|
+
* - "none": No automatic signaling, caller must signal manually
|
|
1278
1287
|
*/
|
|
1279
|
-
restrict(): UnitOfWork<TRawInput> {
|
|
1288
|
+
restrict(options?: { readyFor?: "mutation" | "retrieval" | "none" }): UnitOfWork<TRawInput> {
|
|
1289
|
+
const readyFor = options?.readyFor ?? "mutation";
|
|
1290
|
+
|
|
1280
1291
|
const child = new UnitOfWork(
|
|
1281
1292
|
this.#compiler,
|
|
1282
1293
|
this.#executor,
|
|
@@ -1287,8 +1298,6 @@ export class UnitOfWork<const TRawInput = unknown> implements IUnitOfWork {
|
|
|
1287
1298
|
);
|
|
1288
1299
|
child.#coordinator.setAsRestricted(this, this.#coordinator);
|
|
1289
1300
|
|
|
1290
|
-
// Share state with parent
|
|
1291
|
-
child.#state = this.#state;
|
|
1292
1301
|
child.#retrievalOps = this.#retrievalOps;
|
|
1293
1302
|
child.#mutationOps = this.#mutationOps;
|
|
1294
1303
|
child.#retrievalResults = this.#retrievalResults;
|
|
@@ -1301,10 +1310,13 @@ export class UnitOfWork<const TRawInput = unknown> implements IUnitOfWork {
|
|
|
1301
1310
|
|
|
1302
1311
|
this.#coordinator.addChild(child);
|
|
1303
1312
|
|
|
1304
|
-
//
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1313
|
+
// Signal readiness based on options
|
|
1314
|
+
if (readyFor === "mutation" || readyFor === "retrieval") {
|
|
1315
|
+
child.signalReadyForRetrieval();
|
|
1316
|
+
}
|
|
1317
|
+
if (readyFor === "mutation") {
|
|
1318
|
+
child.signalReadyForMutation();
|
|
1319
|
+
}
|
|
1308
1320
|
|
|
1309
1321
|
return child;
|
|
1310
1322
|
}
|
|
@@ -1375,7 +1387,7 @@ export class UnitOfWork<const TRawInput = unknown> implements IUnitOfWork {
|
|
|
1375
1387
|
}
|
|
1376
1388
|
|
|
1377
1389
|
get state(): UOWState {
|
|
1378
|
-
return this.#state;
|
|
1390
|
+
return this.#coordinator.parent?.state ?? this.#state;
|
|
1379
1391
|
}
|
|
1380
1392
|
|
|
1381
1393
|
get name(): string | undefined {
|
|
@@ -1502,7 +1514,9 @@ export class UnitOfWork<const TRawInput = unknown> implements IUnitOfWork {
|
|
|
1502
1514
|
this.#state = "executed";
|
|
1503
1515
|
|
|
1504
1516
|
if (result.success) {
|
|
1505
|
-
|
|
1517
|
+
// Mutate array in-place to preserve shared references with child UOWs
|
|
1518
|
+
this.#createdInternalIds.length = 0;
|
|
1519
|
+
this.#createdInternalIds.push(...result.createdInternalIds);
|
|
1506
1520
|
}
|
|
1507
1521
|
|
|
1508
1522
|
// Resolve the mutation phase promise to unblock waiting service methods
|
|
@@ -1536,9 +1550,9 @@ export class UnitOfWork<const TRawInput = unknown> implements IUnitOfWork {
|
|
|
1536
1550
|
* Add a retrieval operation (used by TypedUnitOfWork)
|
|
1537
1551
|
*/
|
|
1538
1552
|
addRetrievalOperation(op: RetrievalOperation<AnySchema>): number {
|
|
1539
|
-
if (this
|
|
1553
|
+
if (this.state !== "building-retrieval") {
|
|
1540
1554
|
throw new Error(
|
|
1541
|
-
`Cannot add retrieval operation in state ${this
|
|
1555
|
+
`Cannot add retrieval operation in state ${this.state}. Must be in building-retrieval state.`,
|
|
1542
1556
|
);
|
|
1543
1557
|
}
|
|
1544
1558
|
this.#retrievalOps.push(op);
|
|
@@ -1550,7 +1564,7 @@ export class UnitOfWork<const TRawInput = unknown> implements IUnitOfWork {
|
|
|
1550
1564
|
* Add a mutation operation (used by TypedUnitOfWork)
|
|
1551
1565
|
*/
|
|
1552
1566
|
addMutationOperation(op: MutationOperation<AnySchema>): void {
|
|
1553
|
-
if (this
|
|
1567
|
+
if (this.state === "executed") {
|
|
1554
1568
|
throw new Error(`Cannot add mutation operation in executed state.`);
|
|
1555
1569
|
}
|
|
1556
1570
|
this.#mutationOps.push(op);
|
|
@@ -1565,9 +1579,9 @@ export class UnitOfWork<const TRawInput = unknown> implements IUnitOfWork {
|
|
|
1565
1579
|
* @returns Array of FragnoIds in the same order as create() calls
|
|
1566
1580
|
*/
|
|
1567
1581
|
getCreatedIds(): FragnoId[] {
|
|
1568
|
-
if (this
|
|
1582
|
+
if (this.state !== "executed") {
|
|
1569
1583
|
throw new Error(
|
|
1570
|
-
`getCreatedIds() can only be called after executeMutations(). Current state: ${this
|
|
1584
|
+
`getCreatedIds() can only be called after executeMutations(). Current state: ${this.state}`,
|
|
1571
1585
|
);
|
|
1572
1586
|
}
|
|
1573
1587
|
|
|
@@ -1712,8 +1726,16 @@ export class TypedUnitOfWork<
|
|
|
1712
1726
|
return this.#uow.executeMutations();
|
|
1713
1727
|
}
|
|
1714
1728
|
|
|
1715
|
-
restrict(): IUnitOfWork {
|
|
1716
|
-
return this.#uow.restrict();
|
|
1729
|
+
restrict(options?: { readyFor?: "mutation" | "retrieval" | "none" }): IUnitOfWork {
|
|
1730
|
+
return this.#uow.restrict(options);
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
signalReadyForRetrieval(): void {
|
|
1734
|
+
this.#uow.signalReadyForRetrieval();
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
signalReadyForMutation(): void {
|
|
1738
|
+
this.#uow.signalReadyForMutation();
|
|
1717
1739
|
}
|
|
1718
1740
|
|
|
1719
1741
|
reset(): void {
|
package/src/schema/create.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createId } from "../id";
|
|
2
|
-
import { inspect } from "node:util";
|
|
3
2
|
|
|
4
3
|
export type AnySchema = Schema<Record<string, AnyTable>>;
|
|
5
4
|
|
|
@@ -548,10 +547,6 @@ export class FragnoId {
|
|
|
548
547
|
valueOf(): string {
|
|
549
548
|
return this.#externalId;
|
|
550
549
|
}
|
|
551
|
-
|
|
552
|
-
[inspect.custom](): string {
|
|
553
|
-
return `FragnoId { externalId: ${this.#externalId}, internalId: ${this.#internalId?.toString()} }`;
|
|
554
|
-
}
|
|
555
550
|
}
|
|
556
551
|
|
|
557
552
|
/**
|