@duraxis/orm 0.2.2 → 0.3.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,16 @@
1
1
  # @duraxis/orm changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - eb56e40: Add transactional collection alteration/removal, final-schema validation, schema-aware index rebuilding, and protected subsystem metadata. Add standalone ORM schema export and opt-in strict managed validation. Introduce the migration runtime and CLI with snapshots, schema comparison, atomic history, conservative rollback, baseline adoption, and recovery-aware publication. Document deployment sequencing and transaction memory limits.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [eb56e40]
12
+ - @duraxis/core@0.3.0
13
+
3
14
  ## 0.2.2
4
15
 
5
16
  ### Patch Changes
package/README.md CHANGED
@@ -55,4 +55,18 @@ await orm.close();
55
55
  O ORM exige inicialização antes de obter repositórios. O modo `create` cria estruturas
56
56
  ausentes, mas não é uma ferramenta geral de migrações destrutivas; `validate` verifica o schema
57
57
  existente. Decorators registram metadados quando a classe é avaliada, por isso este pacote não é
58
- marcado como livre de efeitos colaterais. Requer Node.js 22.12+.
58
+ marcado como livre de efeitos colaterais. Requer Node.js 24.15.0+.
59
+
60
+ ## Schema export and migrations
61
+
62
+ `exportSchema(entities)` returns deterministic normalized Core collection
63
+ definitions without opening a database. It reuses finalized decorator metadata,
64
+ including inherited fields, junction collections, foreign keys, and supporting
65
+ indexes. Use this API with `@duraxis/migrations` schema comparison, or use
66
+ [`@duraxis/cli`](../cli/README.md) for snapshot-based generation.
67
+
68
+ The opt-in `schema: { mode: "validate-managed" }` also rejects unexpected indexes
69
+ on registered entity/junction collections. Unrelated collections remain allowed.
70
+ Existing `create` and `validate` modes preserve their behavior and declaration
71
+ order. Production can run `duraxis migrate:up` before ORM initialization with
72
+ schema validation; startup does not automatically execute migrations.
package/dist/index.cjs CHANGED
@@ -1224,6 +1224,17 @@ function mapJunctionSchemas(metadata) {
1224
1224
  }
1225
1225
  return [...schemas.values()];
1226
1226
  }
1227
+ // src/schema/schema-exporter.ts
1228
+ function exportRegistrySchema(registry) {
1229
+ return [...registry.all().map(mapEntitySchema), ...mapJunctionSchemas(registry.all())].map(_duraxis_core.normalizeCollection);
1230
+ }
1231
+ function exportSchema(entities) {
1232
+ return exportRegistrySchema(new MetadataRegistry(entities).finalize()).map((schema) => ({
1233
+ ...schema,
1234
+ indexes: [...schema.indexes].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0),
1235
+ ...schema.foreignKeys ? { foreignKeys: [...schema.foreignKeys].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0) } : {}
1236
+ })).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
1237
+ }
1227
1238
  // src/schema/schema-manager.ts
1228
1239
  function same(left, right) {
1229
1240
  return JSON.stringify(left) == JSON.stringify(right);
@@ -1242,9 +1253,9 @@ var SchemaManager = class {
1242
1253
  }
1243
1254
  async initialize() {
1244
1255
  const persisted = new Map((await this.database.getCollectionDefinitions()).map((definition) => [definition.name, (0, _duraxis_core.normalizeCollection)(definition)]));
1245
- const expectedSchemas = [...this.registry.all().map((metadata) => mapEntitySchema(metadata)), ...mapJunctionSchemas(this.registry.all())].map((schema) => (0, _duraxis_core.normalizeCollection)(schema));
1256
+ const expectedSchemas = exportRegistrySchema(this.registry);
1246
1257
  const missing = expectedSchemas.filter((schema) => !persisted.has(schema.name));
1247
- if (missing.length && this.mode == "validate") throw new SchemaViolationError(`Missing collection: ${missing[0].name}`);
1258
+ if (missing.length && this.mode != "create") throw new SchemaViolationError(`Missing collection: ${missing[0].name}`);
1248
1259
  if (missing.length) {
1249
1260
  await this.mutate(() => this.database.defineCollections(missing), `Could not create collections: ${missing.map((schema) => schema.name).join(", ")}`);
1250
1261
  for (const schema of missing) persisted.set(schema.name, schema);
@@ -1254,11 +1265,12 @@ var SchemaManager = class {
1254
1265
  if (!current) throw new SchemaViolationError(`Missing collection: ${expected.name}`);
1255
1266
  this.validateFields(expected, current);
1256
1267
  if (!same(expected.foreignKeys ?? [], current.foreignKeys ?? [])) throw new SchemaViolationError(`Incompatible foreign keys: ${expected.name}`);
1268
+ if (this.mode == "validate-managed" && current.indexes.length != expected.indexes.length) throw new SchemaViolationError(`Unexpected managed index: ${expected.name}`);
1257
1269
  const actualIndexes = indexMap(current);
1258
1270
  for (const expectedIndex of expected.indexes) {
1259
1271
  const actual = actualIndexes.get(expectedIndex.name);
1260
1272
  if (!actual) {
1261
- if (this.mode == "validate") throw new SchemaViolationError(`Missing index: ${expected.name}/${expectedIndex.name}`);
1273
+ if (this.mode != "create") throw new SchemaViolationError(`Missing index: ${expected.name}/${expectedIndex.name}`);
1262
1274
  await this.mutate(() => this.database.addIndex(expected.name, expectedIndex), `Could not create index: ${expected.name}/${expectedIndex.name}`);
1263
1275
  continue;
1264
1276
  }
@@ -1430,5 +1442,6 @@ Object.defineProperty(exports, "TransactionConflictError", {
1430
1442
  exports.TransactionManagerClosedError = TransactionManagerClosedError;
1431
1443
  exports.UniqueIndexViolationOrmError = UniqueIndexViolationOrmError;
1432
1444
  exports.ValueTransformer = ValueTransformer;
1445
+ exports.exportSchema = exportSchema;
1433
1446
 
1434
1447
  //# sourceMappingURL=index.cjs.map