@duraxis/orm 0.3.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @duraxis/orm changelog
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a4bed1c: Harden bounded production pilots with hierarchical resource admission, query and transaction deadlines, tracked pending I/O, bounded materialization, weighted caches, incremental listings and journal replay, and verified single-owner garbage collection.
8
+
9
+ Breaking pre-1.0 changes: Core requires bounded-read adapter capabilities; resource limits now reject oversized work; destructive S3 GC fails closed; encrypted expiring v3 cursors replace signed database cursors. Restart pagination and provision stable encryption keys. Tenant context checks strengthen application isolation but do not authorize raw storage access.
10
+
11
+ Add conservative commit reconciliation and bounded atomic idempotency receipts without callback retries. Preserve manifest CAS, physical persistence formats and migration checksum identities. See docs/PRODUCTION-HARDENING.md for defaults, deployment constraints, receipt retention and remaining index/FK accounting limitations.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [a4bed1c]
16
+ - @duraxis/core@0.4.0
17
+
3
18
  ## 0.3.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -70,3 +70,7 @@ on registered entity/junction collections. Unrelated collections remain allowed.
70
70
  Existing `create` and `validate` modes preserve their behavior and declaration
71
71
  order. Production can run `duraxis migrate:up` before ORM initialization with
72
72
  schema validation; startup does not automatically execute migrations.
73
+
74
+ ## Production resource and lifecycle limits
75
+
76
+ See the [production hardening guide](../../docs/PRODUCTION-HARDENING.md) for bounded defaults, cancellation, verified maintenance, tenant trust boundaries, encrypted cursors, upgrade instructions and remaining pilot limitations. Core rejects storage adapters without bounded-read capability; destructive shared-storage garbage collection is unsupported.
@@ -10,6 +10,7 @@ export declare class DuraxisORM {
10
10
  initialize(): Promise<void>;
11
11
  getRepository<TEntity extends object>(entity: EntityClass<TEntity>): Repository<TEntity>;
12
12
  transaction<TResult>(callback: (manager: TransactionContext) => Promise<TResult> | TResult): Promise<TResult>;
13
+ resolveCommitOutcome(transactionId: string): Promise<"COMMITTED" | "NOT_COMMITTED" | "UNKNOWN">;
13
14
  close(): Promise<void>;
14
15
  get metadata(): MetadataRegistry;
15
16
  private assertReady;
package/dist/index.cjs CHANGED
@@ -761,17 +761,25 @@ var MAX_RELATED_ENTITIES = 1e5;
761
761
  var RelationLoader = class {
762
762
  metadata;
763
763
  runtime;
764
- #loaded = 0;
765
764
  constructor(metadata, runtime) {
766
765
  this.metadata = metadata;
767
766
  this.runtime = runtime;
768
767
  }
769
768
  async load(entities, requested, signal) {
770
769
  if (!requested || entities.length == 0) return entities;
771
- await this.loadLevel(this.metadata, entities, requested, signal, 0, /* @__PURE__ */ new Set());
772
- return entities;
770
+ const state = {
771
+ loaded: 0,
772
+ budget: this.runtime.database.createMaterializationBudget()
773
+ };
774
+ try {
775
+ for (const entity of entities) state.budget.add(entity);
776
+ await this.loadLevel(this.metadata, entities, requested, signal, 0, /* @__PURE__ */ new Set(), state);
777
+ return entities;
778
+ } finally {
779
+ state.budget.close();
780
+ }
773
781
  }
774
- async loadLevel(metadata, entities, requested, signal, depth, path) {
782
+ async loadLevel(metadata, entities, requested, signal, depth, path, state) {
775
783
  if (depth >= MAX_DEPTH) throw new Error(`Relation depth exceeds ${MAX_DEPTH}`);
776
784
  for (const [property, nested] of Object.entries(requested)) {
777
785
  if (!nested) continue;
@@ -781,11 +789,12 @@ var RelationLoader = class {
781
789
  const edge = `${metadata.collection}.${property}`;
782
790
  if (path.has(edge)) continue;
783
791
  const related = await this.loadRelation(metadata, entities, relation, signal);
784
- this.#loaded += related.length;
785
- if (this.#loaded > MAX_RELATED_ENTITIES) throw new Error("Related entity expansion limit exceeded");
792
+ state.loaded += related.length;
793
+ for (const entity of related) state.budget.add(entity);
794
+ if (state.loaded > MAX_RELATED_ENTITIES) throw new Error("Related entity expansion limit exceeded");
786
795
  if (nested !== true && related.length) {
787
796
  const target = this.runtime.registry.get(relation.target);
788
- await this.loadLevel(target, related, nested, signal, depth + 1, /* @__PURE__ */ new Set([...path, edge]));
797
+ await this.loadLevel(target, related, nested, signal, depth + 1, /* @__PURE__ */ new Set([...path, edge]), state);
789
798
  }
790
799
  }
791
800
  }
@@ -851,22 +860,30 @@ var RelationLoader = class {
851
860
  async queryBatches(collection, field, values, signal) {
852
861
  const all = [...values];
853
862
  const rows = [];
854
- for (let offset = 0; offset < all.length; offset += BATCH_SIZE) {
855
- signal?.throwIfAborted();
856
- const batch = all.slice(offset, offset + BATCH_SIZE);
857
- if (!batch.length) continue;
858
- const query = {
859
- collection,
860
- where: {
861
- type: "in",
862
- field,
863
- values: batch
863
+ const memory = this.runtime.database.createMaterializationBudget();
864
+ try {
865
+ for (let offset = 0; offset < all.length; offset += BATCH_SIZE) {
866
+ signal?.throwIfAborted();
867
+ const batch = all.slice(offset, offset + BATCH_SIZE);
868
+ if (!batch.length) continue;
869
+ const query = {
870
+ collection,
871
+ where: {
872
+ type: "in",
873
+ field,
874
+ values: batch
875
+ }
876
+ };
877
+ const source = this.runtime.transaction ? this.runtime.transaction.query(query, { signal }) : this.runtime.database.query(query, { signal });
878
+ for await (const row of source) {
879
+ memory.add(row);
880
+ rows.push(row);
864
881
  }
865
- };
866
- const source = this.runtime.transaction ? this.runtime.transaction.query(query, { signal }) : this.runtime.database.query(query, { signal });
867
- for await (const row of source) rows.push(row);
882
+ }
883
+ return rows;
884
+ } finally {
885
+ memory.close();
868
886
  }
869
- return rows;
870
887
  }
871
888
  values(entities, property) {
872
889
  const result = /* @__PURE__ */ new Set();
@@ -1100,7 +1117,15 @@ var Repository = class {
1100
1117
  async queryRows(query, signal) {
1101
1118
  this.runtime.assertUsable();
1102
1119
  const rows = [];
1103
- for await (const row of this.sourceQuery(query, signal)) rows.push(row);
1120
+ const memory = this.runtime.database.createMaterializationBudget();
1121
+ try {
1122
+ for await (const row of this.sourceQuery(query, signal)) {
1123
+ memory.add(row);
1124
+ rows.push(row);
1125
+ }
1126
+ } finally {
1127
+ memory.close();
1128
+ }
1104
1129
  return rows;
1105
1130
  }
1106
1131
  queryPage(query, signal) {
@@ -1297,10 +1322,16 @@ var OrmTransactionManager = class {
1297
1322
  registry;
1298
1323
  #repositories = /* @__PURE__ */ new Map();
1299
1324
  #active = true;
1325
+ #abort = () => this.close();
1326
+ get signal() {
1327
+ return this.transaction.signal;
1328
+ }
1300
1329
  constructor(database, transaction, registry) {
1301
1330
  this.database = database;
1302
1331
  this.transaction = transaction;
1303
1332
  this.registry = registry;
1333
+ this.transaction.signal.addEventListener("abort", this.#abort, { once: true });
1334
+ if (this.transaction.signal.aborted) this.close();
1304
1335
  }
1305
1336
  getRepository(entity) {
1306
1337
  this.assertActive();
@@ -1317,10 +1348,11 @@ var OrmTransactionManager = class {
1317
1348
  }
1318
1349
  close() {
1319
1350
  this.#active = false;
1351
+ this.transaction.signal.removeEventListener("abort", this.#abort);
1320
1352
  this.#repositories.clear();
1321
1353
  }
1322
1354
  assertActive() {
1323
- if (!this.#active) throw new TransactionManagerClosedError();
1355
+ if (!this.#active || this.transaction.state != "ACTIVE") throw new TransactionManagerClosedError();
1324
1356
  }
1325
1357
  };
1326
1358
  // src/database/duraxis-orm.ts
@@ -1330,6 +1362,8 @@ var DuraxisORM = class {
1330
1362
  #repositories = /* @__PURE__ */ new Map();
1331
1363
  #lifecycle = "new";
1332
1364
  #initialization;
1365
+ #closing;
1366
+ #resourcesClosed = false;
1333
1367
  constructor(options) {
1334
1368
  this.options = options;
1335
1369
  this.#registry = new MetadataRegistry(options.entities).finalize();
@@ -1380,13 +1414,23 @@ var DuraxisORM = class {
1380
1414
  throw cause;
1381
1415
  }
1382
1416
  }
1383
- async close() {
1384
- if (this.#lifecycle == "closed") return;
1385
- const initialization = this.#initialization;
1386
- if (initialization) await initialization.catch(() => void 0);
1417
+ resolveCommitOutcome(transactionId) {
1418
+ return this.options.database.resolveCommitOutcome(transactionId);
1419
+ }
1420
+ close() {
1421
+ if (this.#resourcesClosed) return Promise.resolve();
1422
+ if (this.#closing) return this.#closing;
1387
1423
  this.#lifecycle = "closed";
1388
1424
  this.#repositories.clear();
1389
- if (this.options.closeDatabase || this.options.closeStorage) await this.options.database.close({ closeStorage: this.options.closeStorage ?? false });
1425
+ this.#closing = (async () => {
1426
+ if (this.#initialization) await this.#initialization.catch(() => void 0);
1427
+ if (this.options.closeDatabase || this.options.closeStorage) await this.options.database.close({ closeStorage: this.options.closeStorage ?? false });
1428
+ this.#resourcesClosed = true;
1429
+ })();
1430
+ this.#closing.catch(() => {
1431
+ this.#closing = void 0;
1432
+ });
1433
+ return this.#closing;
1390
1434
  }
1391
1435
  get metadata() {
1392
1436
  return this.#registry;