@contember/migrations-client 2.2.0-alpha.7 → 2.2.0-alpha.8

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.
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schemaUtils = require("@contember/schema-utils");
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
4
7
  class SchemaVersionBuilder {
5
8
  constructor(migrationsResolver, schemaMigrator, schemaStateManager) {
6
9
  this.migrationsResolver = migrationsResolver;
7
10
  this.schemaMigrator = schemaMigrator;
8
11
  this.schemaStateManager = schemaStateManager;
12
+ __publicField(this, "lastBuildUntil", null);
9
13
  }
10
14
  async buildSchema(targetVersion) {
11
15
  let schema = await this.buildSchemaAdvanced(schemaUtils.emptySchema, (version) => !targetVersion || version <= targetVersion);
@@ -15,14 +19,28 @@ class SchemaVersionBuilder {
15
19
  }
16
20
  return schema;
17
21
  }
22
+ /**
23
+ * Content migrations call this once each, with ascending versions. Continuing from the previous
24
+ * build keeps a run linear instead of replaying every schema migration from scratch each time.
25
+ */
18
26
  async buildSchemaUntil(targetVersion) {
19
- return this.buildSchemaAdvanced(schemaUtils.emptySchema, (version) => version < targetVersion);
27
+ const migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => version < targetVersion);
28
+ const previous = this.lastBuildUntil;
29
+ const canContinue = previous !== null && previous.migrations.length <= migrations.length && previous.migrations.every((migration, index) => migration === migrations[index]);
30
+ const start = canContinue ? previous : { migrations: [], schema: schemaUtils.emptySchema };
31
+ const schema = this.applyMigrations(start.schema, migrations.slice(start.migrations.length));
32
+ this.lastBuildUntil = { migrations, schema };
33
+ return schema;
20
34
  }
21
35
  async continue(schema, previousVersion, targetVersion) {
22
36
  return this.buildSchemaAdvanced(schema, (version) => version <= targetVersion && version > (previousVersion || ""));
23
37
  }
24
38
  async buildSchemaAdvanced(initialSchema, condition) {
25
- return (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version)).reduce(
39
+ const migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version));
40
+ return this.applyMigrations(initialSchema, migrations);
41
+ }
42
+ applyMigrations(initialSchema, migrations) {
43
+ return migrations.reduce(
26
44
  (schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),
27
45
  initialSchema
28
46
  );
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaVersionBuilder.cjs","sources":["../../../../packages/migrations-client/src/SchemaVersionBuilder.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { emptySchema } from '@contember/schema-utils'\nimport { SchemaMigrator } from '@contember/schema-migrations'\nimport { MigrationsResolver } from './MigrationsResolver.js'\nimport { SchemaStateManager } from './SchemaStateManager.js'\n\nexport class SchemaVersionBuilder {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {}\n\n\tasync buildSchema(targetVersion?: string): Promise<Schema> {\n\t\tlet schema = await this.buildSchemaAdvanced(emptySchema, version => !targetVersion || version <= targetVersion)\n\t\tif (!targetVersion && await this.schemaStateManager.isStateMode()) {\n\t\t\tconst state = await this.schemaStateManager.readState()\n\t\t\tschema = { ...schema, ...state }\n\t\t}\n\t\treturn schema\n\t}\n\n\tasync buildSchemaUntil(targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(emptySchema, version => version < targetVersion)\n\t}\n\n\tasync continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''))\n\t}\n\n\tpublic async buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema> {\n\t\treturn (await this.migrationsResolver.getSchemaMigrations())\n\t\t\t.filter(({ version }) => condition(version))\n\t\t\t.reduce<Schema>(\n\t\t\t\t(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),\n\t\t\t\tinitialSchema,\n\t\t\t)\n\t}\n}\n"],"names":["emptySchema"],"mappings":";;;AAMO,MAAM,qBAAqB;AAAA,EACjC,YACkB,oBACA,gBACA,oBAChB;AAHgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,qBAAA;AAAA,EACf;AAAA,EAEH,MAAM,YAAY,eAAyC;AAC1D,QAAI,SAAS,MAAM,KAAK,oBAAoBA,YAAAA,aAAa,CAAA,YAAW,CAAC,iBAAiB,WAAW,aAAa;AAC9G,QAAI,CAAC,iBAAiB,MAAM,KAAK,mBAAmB,eAAe;AAClE,YAAM,QAAQ,MAAM,KAAK,mBAAmB,UAAA;AAC5C,eAAS,EAAE,GAAG,QAAQ,GAAG,MAAA;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,iBAAiB,eAAwC;AAC9D,WAAO,KAAK,oBAAoBA,YAAAA,aAAa,CAAA,YAAW,UAAU,aAAa;AAAA,EAChF;AAAA,EAEA,MAAM,SAAS,QAAgB,iBAAgC,eAAwC;AACtG,WAAO,KAAK,oBAAoB,QAAQ,CAAA,YAAW,WAAW,iBAAiB,WAAW,mBAAmB,GAAG;AAAA,EACjH;AAAA,EAEA,MAAa,oBAAoB,eAAuB,WAA0D;AACjH,YAAQ,MAAM,KAAK,mBAAmB,oBAAA,GACpC,OAAO,CAAC,EAAE,QAAA,MAAc,UAAU,OAAO,CAAC,EAC1C;AAAA,MACA,CAAC,QAAQ,EAAE,eAAe,oBAAoB,KAAK,eAAe,mBAAmB,QAAQ,eAAe,aAAa;AAAA,MACzH;AAAA,IAAA;AAAA,EAEH;AACD;;"}
1
+ {"version":3,"file":"SchemaVersionBuilder.cjs","sources":["../../../../packages/migrations-client/src/SchemaVersionBuilder.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { emptySchema } from '@contember/schema-utils'\nimport { Migration, SchemaMigrator } from '@contember/schema-migrations'\nimport { MigrationsResolver } from './MigrationsResolver.js'\nimport { SchemaStateManager } from './SchemaStateManager.js'\n\nexport class SchemaVersionBuilder {\n\tprivate lastBuildUntil: { migrations: Migration[]; schema: Schema } | null = null\n\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {}\n\n\tasync buildSchema(targetVersion?: string): Promise<Schema> {\n\t\tlet schema = await this.buildSchemaAdvanced(emptySchema, version => !targetVersion || version <= targetVersion)\n\t\tif (!targetVersion && await this.schemaStateManager.isStateMode()) {\n\t\t\tconst state = await this.schemaStateManager.readState()\n\t\t\tschema = { ...schema, ...state }\n\t\t}\n\t\treturn schema\n\t}\n\n\t/**\n\t * Content migrations call this once each, with ascending versions. Continuing from the previous\n\t * build keeps a run linear instead of replaying every schema migration from scratch each time.\n\t */\n\tasync buildSchemaUntil(targetVersion: string): Promise<Schema> {\n\t\tconst migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => version < targetVersion)\n\t\tconst previous = this.lastBuildUntil\n\t\tconst canContinue = previous !== null\n\t\t\t&& previous.migrations.length <= migrations.length\n\t\t\t&& previous.migrations.every((migration, index) => migration === migrations[index])\n\t\tconst start = canContinue ? previous : { migrations: [], schema: emptySchema }\n\n\t\tconst schema = this.applyMigrations(start.schema, migrations.slice(start.migrations.length))\n\t\tthis.lastBuildUntil = { migrations, schema }\n\t\treturn schema\n\t}\n\n\tasync continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''))\n\t}\n\n\tpublic async buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema> {\n\t\tconst migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version))\n\t\treturn this.applyMigrations(initialSchema, migrations)\n\t}\n\n\tprivate applyMigrations(initialSchema: Schema, migrations: Migration[]): Schema {\n\t\treturn migrations.reduce<Schema>(\n\t\t\t(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),\n\t\t\tinitialSchema,\n\t\t)\n\t}\n}\n"],"names":["emptySchema"],"mappings":";;;;;;AAMO,MAAM,qBAAqB;AAAA,EAGjC,YACkB,oBACA,gBACA,oBAChB;AAHgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,qBAAA;AALlB,kBAAA,MAAQ,kBAAqE,IAAA;AAAA,EAM1E;AAAA,EAEH,MAAM,YAAY,eAAyC;AAC1D,QAAI,SAAS,MAAM,KAAK,oBAAoBA,YAAAA,aAAa,CAAA,YAAW,CAAC,iBAAiB,WAAW,aAAa;AAC9G,QAAI,CAAC,iBAAiB,MAAM,KAAK,mBAAmB,eAAe;AAClE,YAAM,QAAQ,MAAM,KAAK,mBAAmB,UAAA;AAC5C,eAAS,EAAE,GAAG,QAAQ,GAAG,MAAA;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,iBAAiB,eAAwC;AAC9D,UAAM,cAAc,MAAM,KAAK,mBAAmB,oBAAA,GAAuB,OAAO,CAAC,EAAE,cAAc,UAAU,aAAa;AACxH,UAAM,WAAW,KAAK;AACtB,UAAM,cAAc,aAAa,QAC7B,SAAS,WAAW,UAAU,WAAW,UACzC,SAAS,WAAW,MAAM,CAAC,WAAW,UAAU,cAAc,WAAW,KAAK,CAAC;AACnF,UAAM,QAAQ,cAAc,WAAW,EAAE,YAAY,CAAA,GAAI,QAAQA,wBAAA;AAEjE,UAAM,SAAS,KAAK,gBAAgB,MAAM,QAAQ,WAAW,MAAM,MAAM,WAAW,MAAM,CAAC;AAC3F,SAAK,iBAAiB,EAAE,YAAY,OAAA;AACpC,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,SAAS,QAAgB,iBAAgC,eAAwC;AACtG,WAAO,KAAK,oBAAoB,QAAQ,CAAA,YAAW,WAAW,iBAAiB,WAAW,mBAAmB,GAAG;AAAA,EACjH;AAAA,EAEA,MAAa,oBAAoB,eAAuB,WAA0D;AACjH,UAAM,cAAc,MAAM,KAAK,mBAAmB,oBAAA,GAAuB,OAAO,CAAC,EAAE,QAAA,MAAc,UAAU,OAAO,CAAC;AACnH,WAAO,KAAK,gBAAgB,eAAe,UAAU;AAAA,EACtD;AAAA,EAEQ,gBAAgB,eAAuB,YAAiC;AAC/E,WAAO,WAAW;AAAA,MACjB,CAAC,QAAQ,EAAE,eAAe,oBAAoB,KAAK,eAAe,mBAAmB,QAAQ,eAAe,aAAa;AAAA,MACzH;AAAA,IAAA;AAAA,EAEF;AACD;;"}
@@ -1,9 +1,13 @@
1
1
  import { emptySchema } from "@contember/schema-utils";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
2
5
  class SchemaVersionBuilder {
3
6
  constructor(migrationsResolver, schemaMigrator, schemaStateManager) {
4
7
  this.migrationsResolver = migrationsResolver;
5
8
  this.schemaMigrator = schemaMigrator;
6
9
  this.schemaStateManager = schemaStateManager;
10
+ __publicField(this, "lastBuildUntil", null);
7
11
  }
8
12
  async buildSchema(targetVersion) {
9
13
  let schema = await this.buildSchemaAdvanced(emptySchema, (version) => !targetVersion || version <= targetVersion);
@@ -13,14 +17,28 @@ class SchemaVersionBuilder {
13
17
  }
14
18
  return schema;
15
19
  }
20
+ /**
21
+ * Content migrations call this once each, with ascending versions. Continuing from the previous
22
+ * build keeps a run linear instead of replaying every schema migration from scratch each time.
23
+ */
16
24
  async buildSchemaUntil(targetVersion) {
17
- return this.buildSchemaAdvanced(emptySchema, (version) => version < targetVersion);
25
+ const migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => version < targetVersion);
26
+ const previous = this.lastBuildUntil;
27
+ const canContinue = previous !== null && previous.migrations.length <= migrations.length && previous.migrations.every((migration, index) => migration === migrations[index]);
28
+ const start = canContinue ? previous : { migrations: [], schema: emptySchema };
29
+ const schema = this.applyMigrations(start.schema, migrations.slice(start.migrations.length));
30
+ this.lastBuildUntil = { migrations, schema };
31
+ return schema;
18
32
  }
19
33
  async continue(schema, previousVersion, targetVersion) {
20
34
  return this.buildSchemaAdvanced(schema, (version) => version <= targetVersion && version > (previousVersion || ""));
21
35
  }
22
36
  async buildSchemaAdvanced(initialSchema, condition) {
23
- return (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version)).reduce(
37
+ const migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version));
38
+ return this.applyMigrations(initialSchema, migrations);
39
+ }
40
+ applyMigrations(initialSchema, migrations) {
41
+ return migrations.reduce(
24
42
  (schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),
25
43
  initialSchema
26
44
  );
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaVersionBuilder.js","sources":["../../../../packages/migrations-client/src/SchemaVersionBuilder.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { emptySchema } from '@contember/schema-utils'\nimport { SchemaMigrator } from '@contember/schema-migrations'\nimport { MigrationsResolver } from './MigrationsResolver.js'\nimport { SchemaStateManager } from './SchemaStateManager.js'\n\nexport class SchemaVersionBuilder {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {}\n\n\tasync buildSchema(targetVersion?: string): Promise<Schema> {\n\t\tlet schema = await this.buildSchemaAdvanced(emptySchema, version => !targetVersion || version <= targetVersion)\n\t\tif (!targetVersion && await this.schemaStateManager.isStateMode()) {\n\t\t\tconst state = await this.schemaStateManager.readState()\n\t\t\tschema = { ...schema, ...state }\n\t\t}\n\t\treturn schema\n\t}\n\n\tasync buildSchemaUntil(targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(emptySchema, version => version < targetVersion)\n\t}\n\n\tasync continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''))\n\t}\n\n\tpublic async buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema> {\n\t\treturn (await this.migrationsResolver.getSchemaMigrations())\n\t\t\t.filter(({ version }) => condition(version))\n\t\t\t.reduce<Schema>(\n\t\t\t\t(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),\n\t\t\t\tinitialSchema,\n\t\t\t)\n\t}\n}\n"],"names":[],"mappings":";AAMO,MAAM,qBAAqB;AAAA,EACjC,YACkB,oBACA,gBACA,oBAChB;AAHgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,qBAAA;AAAA,EACf;AAAA,EAEH,MAAM,YAAY,eAAyC;AAC1D,QAAI,SAAS,MAAM,KAAK,oBAAoB,aAAa,CAAA,YAAW,CAAC,iBAAiB,WAAW,aAAa;AAC9G,QAAI,CAAC,iBAAiB,MAAM,KAAK,mBAAmB,eAAe;AAClE,YAAM,QAAQ,MAAM,KAAK,mBAAmB,UAAA;AAC5C,eAAS,EAAE,GAAG,QAAQ,GAAG,MAAA;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,iBAAiB,eAAwC;AAC9D,WAAO,KAAK,oBAAoB,aAAa,CAAA,YAAW,UAAU,aAAa;AAAA,EAChF;AAAA,EAEA,MAAM,SAAS,QAAgB,iBAAgC,eAAwC;AACtG,WAAO,KAAK,oBAAoB,QAAQ,CAAA,YAAW,WAAW,iBAAiB,WAAW,mBAAmB,GAAG;AAAA,EACjH;AAAA,EAEA,MAAa,oBAAoB,eAAuB,WAA0D;AACjH,YAAQ,MAAM,KAAK,mBAAmB,oBAAA,GACpC,OAAO,CAAC,EAAE,QAAA,MAAc,UAAU,OAAO,CAAC,EAC1C;AAAA,MACA,CAAC,QAAQ,EAAE,eAAe,oBAAoB,KAAK,eAAe,mBAAmB,QAAQ,eAAe,aAAa;AAAA,MACzH;AAAA,IAAA;AAAA,EAEH;AACD;"}
1
+ {"version":3,"file":"SchemaVersionBuilder.js","sources":["../../../../packages/migrations-client/src/SchemaVersionBuilder.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { emptySchema } from '@contember/schema-utils'\nimport { Migration, SchemaMigrator } from '@contember/schema-migrations'\nimport { MigrationsResolver } from './MigrationsResolver.js'\nimport { SchemaStateManager } from './SchemaStateManager.js'\n\nexport class SchemaVersionBuilder {\n\tprivate lastBuildUntil: { migrations: Migration[]; schema: Schema } | null = null\n\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {}\n\n\tasync buildSchema(targetVersion?: string): Promise<Schema> {\n\t\tlet schema = await this.buildSchemaAdvanced(emptySchema, version => !targetVersion || version <= targetVersion)\n\t\tif (!targetVersion && await this.schemaStateManager.isStateMode()) {\n\t\t\tconst state = await this.schemaStateManager.readState()\n\t\t\tschema = { ...schema, ...state }\n\t\t}\n\t\treturn schema\n\t}\n\n\t/**\n\t * Content migrations call this once each, with ascending versions. Continuing from the previous\n\t * build keeps a run linear instead of replaying every schema migration from scratch each time.\n\t */\n\tasync buildSchemaUntil(targetVersion: string): Promise<Schema> {\n\t\tconst migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => version < targetVersion)\n\t\tconst previous = this.lastBuildUntil\n\t\tconst canContinue = previous !== null\n\t\t\t&& previous.migrations.length <= migrations.length\n\t\t\t&& previous.migrations.every((migration, index) => migration === migrations[index])\n\t\tconst start = canContinue ? previous : { migrations: [], schema: emptySchema }\n\n\t\tconst schema = this.applyMigrations(start.schema, migrations.slice(start.migrations.length))\n\t\tthis.lastBuildUntil = { migrations, schema }\n\t\treturn schema\n\t}\n\n\tasync continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''))\n\t}\n\n\tpublic async buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema> {\n\t\tconst migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version))\n\t\treturn this.applyMigrations(initialSchema, migrations)\n\t}\n\n\tprivate applyMigrations(initialSchema: Schema, migrations: Migration[]): Schema {\n\t\treturn migrations.reduce<Schema>(\n\t\t\t(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),\n\t\t\tinitialSchema,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;;;AAMO,MAAM,qBAAqB;AAAA,EAGjC,YACkB,oBACA,gBACA,oBAChB;AAHgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,qBAAA;AALlB,kBAAA,MAAQ,kBAAqE,IAAA;AAAA,EAM1E;AAAA,EAEH,MAAM,YAAY,eAAyC;AAC1D,QAAI,SAAS,MAAM,KAAK,oBAAoB,aAAa,CAAA,YAAW,CAAC,iBAAiB,WAAW,aAAa;AAC9G,QAAI,CAAC,iBAAiB,MAAM,KAAK,mBAAmB,eAAe;AAClE,YAAM,QAAQ,MAAM,KAAK,mBAAmB,UAAA;AAC5C,eAAS,EAAE,GAAG,QAAQ,GAAG,MAAA;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,iBAAiB,eAAwC;AAC9D,UAAM,cAAc,MAAM,KAAK,mBAAmB,oBAAA,GAAuB,OAAO,CAAC,EAAE,cAAc,UAAU,aAAa;AACxH,UAAM,WAAW,KAAK;AACtB,UAAM,cAAc,aAAa,QAC7B,SAAS,WAAW,UAAU,WAAW,UACzC,SAAS,WAAW,MAAM,CAAC,WAAW,UAAU,cAAc,WAAW,KAAK,CAAC;AACnF,UAAM,QAAQ,cAAc,WAAW,EAAE,YAAY,CAAA,GAAI,QAAQ,YAAA;AAEjE,UAAM,SAAS,KAAK,gBAAgB,MAAM,QAAQ,WAAW,MAAM,MAAM,WAAW,MAAM,CAAC;AAC3F,SAAK,iBAAiB,EAAE,YAAY,OAAA;AACpC,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,SAAS,QAAgB,iBAAgC,eAAwC;AACtG,WAAO,KAAK,oBAAoB,QAAQ,CAAA,YAAW,WAAW,iBAAiB,WAAW,mBAAmB,GAAG;AAAA,EACjH;AAAA,EAEA,MAAa,oBAAoB,eAAuB,WAA0D;AACjH,UAAM,cAAc,MAAM,KAAK,mBAAmB,oBAAA,GAAuB,OAAO,CAAC,EAAE,QAAA,MAAc,UAAU,OAAO,CAAC;AACnH,WAAO,KAAK,gBAAgB,eAAe,UAAU;AAAA,EACtD;AAAA,EAEQ,gBAAgB,eAAuB,YAAiC;AAC/E,WAAO,WAAW;AAAA,MACjB,CAAC,QAAQ,EAAE,eAAe,oBAAoB,KAAK,eAAe,mBAAmB,QAAQ,eAAe,aAAa;AAAA,MACzH;AAAA,IAAA;AAAA,EAEF;AACD;"}
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schemaUtils = require("@contember/schema-utils");
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
4
7
  class SchemaVersionBuilder {
5
8
  constructor(migrationsResolver, schemaMigrator, schemaStateManager) {
6
9
  this.migrationsResolver = migrationsResolver;
7
10
  this.schemaMigrator = schemaMigrator;
8
11
  this.schemaStateManager = schemaStateManager;
12
+ __publicField(this, "lastBuildUntil", null);
9
13
  }
10
14
  async buildSchema(targetVersion) {
11
15
  let schema = await this.buildSchemaAdvanced(schemaUtils.emptySchema, (version) => !targetVersion || version <= targetVersion);
@@ -15,14 +19,28 @@ class SchemaVersionBuilder {
15
19
  }
16
20
  return schema;
17
21
  }
22
+ /**
23
+ * Content migrations call this once each, with ascending versions. Continuing from the previous
24
+ * build keeps a run linear instead of replaying every schema migration from scratch each time.
25
+ */
18
26
  async buildSchemaUntil(targetVersion) {
19
- return this.buildSchemaAdvanced(schemaUtils.emptySchema, (version) => version < targetVersion);
27
+ const migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => version < targetVersion);
28
+ const previous = this.lastBuildUntil;
29
+ const canContinue = previous !== null && previous.migrations.length <= migrations.length && previous.migrations.every((migration, index) => migration === migrations[index]);
30
+ const start = canContinue ? previous : { migrations: [], schema: schemaUtils.emptySchema };
31
+ const schema = this.applyMigrations(start.schema, migrations.slice(start.migrations.length));
32
+ this.lastBuildUntil = { migrations, schema };
33
+ return schema;
20
34
  }
21
35
  async continue(schema, previousVersion, targetVersion) {
22
36
  return this.buildSchemaAdvanced(schema, (version) => version <= targetVersion && version > (previousVersion || ""));
23
37
  }
24
38
  async buildSchemaAdvanced(initialSchema, condition) {
25
- return (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version)).reduce(
39
+ const migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version));
40
+ return this.applyMigrations(initialSchema, migrations);
41
+ }
42
+ applyMigrations(initialSchema, migrations) {
43
+ return migrations.reduce(
26
44
  (schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),
27
45
  initialSchema
28
46
  );
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaVersionBuilder.cjs","sources":["../../../../packages/migrations-client/src/SchemaVersionBuilder.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { emptySchema } from '@contember/schema-utils'\nimport { SchemaMigrator } from '@contember/schema-migrations'\nimport { MigrationsResolver } from './MigrationsResolver.js'\nimport { SchemaStateManager } from './SchemaStateManager.js'\n\nexport class SchemaVersionBuilder {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {}\n\n\tasync buildSchema(targetVersion?: string): Promise<Schema> {\n\t\tlet schema = await this.buildSchemaAdvanced(emptySchema, version => !targetVersion || version <= targetVersion)\n\t\tif (!targetVersion && await this.schemaStateManager.isStateMode()) {\n\t\t\tconst state = await this.schemaStateManager.readState()\n\t\t\tschema = { ...schema, ...state }\n\t\t}\n\t\treturn schema\n\t}\n\n\tasync buildSchemaUntil(targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(emptySchema, version => version < targetVersion)\n\t}\n\n\tasync continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''))\n\t}\n\n\tpublic async buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema> {\n\t\treturn (await this.migrationsResolver.getSchemaMigrations())\n\t\t\t.filter(({ version }) => condition(version))\n\t\t\t.reduce<Schema>(\n\t\t\t\t(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),\n\t\t\t\tinitialSchema,\n\t\t\t)\n\t}\n}\n"],"names":["emptySchema"],"mappings":";;;AAMO,MAAM,qBAAqB;AAAA,EACjC,YACkB,oBACA,gBACA,oBAChB;AAHgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,qBAAA;AAAA,EACf;AAAA,EAEH,MAAM,YAAY,eAAyC;AAC1D,QAAI,SAAS,MAAM,KAAK,oBAAoBA,YAAAA,aAAa,CAAA,YAAW,CAAC,iBAAiB,WAAW,aAAa;AAC9G,QAAI,CAAC,iBAAiB,MAAM,KAAK,mBAAmB,eAAe;AAClE,YAAM,QAAQ,MAAM,KAAK,mBAAmB,UAAA;AAC5C,eAAS,EAAE,GAAG,QAAQ,GAAG,MAAA;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,iBAAiB,eAAwC;AAC9D,WAAO,KAAK,oBAAoBA,YAAAA,aAAa,CAAA,YAAW,UAAU,aAAa;AAAA,EAChF;AAAA,EAEA,MAAM,SAAS,QAAgB,iBAAgC,eAAwC;AACtG,WAAO,KAAK,oBAAoB,QAAQ,CAAA,YAAW,WAAW,iBAAiB,WAAW,mBAAmB,GAAG;AAAA,EACjH;AAAA,EAEA,MAAa,oBAAoB,eAAuB,WAA0D;AACjH,YAAQ,MAAM,KAAK,mBAAmB,oBAAA,GACpC,OAAO,CAAC,EAAE,QAAA,MAAc,UAAU,OAAO,CAAC,EAC1C;AAAA,MACA,CAAC,QAAQ,EAAE,eAAe,oBAAoB,KAAK,eAAe,mBAAmB,QAAQ,eAAe,aAAa;AAAA,MACzH;AAAA,IAAA;AAAA,EAEH;AACD;;"}
1
+ {"version":3,"file":"SchemaVersionBuilder.cjs","sources":["../../../../packages/migrations-client/src/SchemaVersionBuilder.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { emptySchema } from '@contember/schema-utils'\nimport { Migration, SchemaMigrator } from '@contember/schema-migrations'\nimport { MigrationsResolver } from './MigrationsResolver.js'\nimport { SchemaStateManager } from './SchemaStateManager.js'\n\nexport class SchemaVersionBuilder {\n\tprivate lastBuildUntil: { migrations: Migration[]; schema: Schema } | null = null\n\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {}\n\n\tasync buildSchema(targetVersion?: string): Promise<Schema> {\n\t\tlet schema = await this.buildSchemaAdvanced(emptySchema, version => !targetVersion || version <= targetVersion)\n\t\tif (!targetVersion && await this.schemaStateManager.isStateMode()) {\n\t\t\tconst state = await this.schemaStateManager.readState()\n\t\t\tschema = { ...schema, ...state }\n\t\t}\n\t\treturn schema\n\t}\n\n\t/**\n\t * Content migrations call this once each, with ascending versions. Continuing from the previous\n\t * build keeps a run linear instead of replaying every schema migration from scratch each time.\n\t */\n\tasync buildSchemaUntil(targetVersion: string): Promise<Schema> {\n\t\tconst migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => version < targetVersion)\n\t\tconst previous = this.lastBuildUntil\n\t\tconst canContinue = previous !== null\n\t\t\t&& previous.migrations.length <= migrations.length\n\t\t\t&& previous.migrations.every((migration, index) => migration === migrations[index])\n\t\tconst start = canContinue ? previous : { migrations: [], schema: emptySchema }\n\n\t\tconst schema = this.applyMigrations(start.schema, migrations.slice(start.migrations.length))\n\t\tthis.lastBuildUntil = { migrations, schema }\n\t\treturn schema\n\t}\n\n\tasync continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''))\n\t}\n\n\tpublic async buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema> {\n\t\tconst migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version))\n\t\treturn this.applyMigrations(initialSchema, migrations)\n\t}\n\n\tprivate applyMigrations(initialSchema: Schema, migrations: Migration[]): Schema {\n\t\treturn migrations.reduce<Schema>(\n\t\t\t(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),\n\t\t\tinitialSchema,\n\t\t)\n\t}\n}\n"],"names":["emptySchema"],"mappings":";;;;;;AAMO,MAAM,qBAAqB;AAAA,EAGjC,YACkB,oBACA,gBACA,oBACh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,UAAU;AAAA,EACtD;AAAA,EAEQ,gBAAgB,eAAuB,YAAiC;AAC/E,WAAO,WAAW;AAAA,MACjB,CAAC,QAAQ,EAAE,eAAe,oBAAoB,KAAK,eAAe,mBAAmB,QAAQ,eAAe,aAAa;AAAA,MACzH;AAAA,IAAA;AAAA,EAEF;AACD;;"}
@@ -1,9 +1,13 @@
1
1
  import { emptySchema } from "@contember/schema-utils";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
2
5
  class SchemaVersionBuilder {
3
6
  constructor(migrationsResolver, schemaMigrator, schemaStateManager) {
4
7
  this.migrationsResolver = migrationsResolver;
5
8
  this.schemaMigrator = schemaMigrator;
6
9
  this.schemaStateManager = schemaStateManager;
10
+ __publicField(this, "lastBuildUntil", null);
7
11
  }
8
12
  async buildSchema(targetVersion) {
9
13
  let schema = await this.buildSchemaAdvanced(emptySchema, (version) => !targetVersion || version <= targetVersion);
@@ -13,14 +17,28 @@ class SchemaVersionBuilder {
13
17
  }
14
18
  return schema;
15
19
  }
20
+ /**
21
+ * Content migrations call this once each, with ascending versions. Continuing from the previous
22
+ * build keeps a run linear instead of replaying every schema migration from scratch each time.
23
+ */
16
24
  async buildSchemaUntil(targetVersion) {
17
- return this.buildSchemaAdvanced(emptySchema, (version) => version < targetVersion);
25
+ const migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => version < targetVersion);
26
+ const previous = this.lastBuildUntil;
27
+ const canContinue = previous !== null && previous.migrations.length <= migrations.length && previous.migrations.every((migration, index) => migration === migrations[index]);
28
+ const start = canContinue ? previous : { migrations: [], schema: emptySchema };
29
+ const schema = this.applyMigrations(start.schema, migrations.slice(start.migrations.length));
30
+ this.lastBuildUntil = { migrations, schema };
31
+ return schema;
18
32
  }
19
33
  async continue(schema, previousVersion, targetVersion) {
20
34
  return this.buildSchemaAdvanced(schema, (version) => version <= targetVersion && version > (previousVersion || ""));
21
35
  }
22
36
  async buildSchemaAdvanced(initialSchema, condition) {
23
- return (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version)).reduce(
37
+ const migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version));
38
+ return this.applyMigrations(initialSchema, migrations);
39
+ }
40
+ applyMigrations(initialSchema, migrations) {
41
+ return migrations.reduce(
24
42
  (schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),
25
43
  initialSchema
26
44
  );
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaVersionBuilder.js","sources":["../../../../packages/migrations-client/src/SchemaVersionBuilder.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { emptySchema } from '@contember/schema-utils'\nimport { SchemaMigrator } from '@contember/schema-migrations'\nimport { MigrationsResolver } from './MigrationsResolver.js'\nimport { SchemaStateManager } from './SchemaStateManager.js'\n\nexport class SchemaVersionBuilder {\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {}\n\n\tasync buildSchema(targetVersion?: string): Promise<Schema> {\n\t\tlet schema = await this.buildSchemaAdvanced(emptySchema, version => !targetVersion || version <= targetVersion)\n\t\tif (!targetVersion && await this.schemaStateManager.isStateMode()) {\n\t\t\tconst state = await this.schemaStateManager.readState()\n\t\t\tschema = { ...schema, ...state }\n\t\t}\n\t\treturn schema\n\t}\n\n\tasync buildSchemaUntil(targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(emptySchema, version => version < targetVersion)\n\t}\n\n\tasync continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''))\n\t}\n\n\tpublic async buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema> {\n\t\treturn (await this.migrationsResolver.getSchemaMigrations())\n\t\t\t.filter(({ version }) => condition(version))\n\t\t\t.reduce<Schema>(\n\t\t\t\t(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),\n\t\t\t\tinitialSchema,\n\t\t\t)\n\t}\n}\n"],"names":[],"mappings":";AAMO,MAAM,qBAAqB;AAAA,EACjC,YACkB,oBACA,gBACA,oBAChB;AAHgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,qBAAA;AAAA,EACf;AAAA,EAEH,MAAM,YAAY,eAAyC;AAC1D,QAAI,SAAS,MAAM,KAAK,oBAAoB,aAAa,CAAA,YAAW,CAAC,iBAAiB,WAAW,aAAa;AAC9G,QAAI,CAAC,iBAAiB,MAAM,KAAK,mBAAmB,eAAe;AAClE,YAAM,QAAQ,MAAM,KAAK,mBAAmB,UAAA;AAC5C,eAAS,EAAE,GAAG,QAAQ,GAAG,MAAA;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,iBAAiB,eAAwC;AAC9D,WAAO,KAAK,oBAAoB,aAAa,CAAA,YAAW,UAAU,aAAa;AAAA,EAChF;AAAA,EAEA,MAAM,SAAS,QAAgB,iBAAgC,eAAwC;AACtG,WAAO,KAAK,oBAAoB,QAAQ,CAAA,YAAW,WAAW,iBAAiB,WAAW,mBAAmB,GAAG;AAAA,EACjH;AAAA,EAEA,MAAa,oBAAoB,eAAuB,WAA0D;AACjH,YAAQ,MAAM,KAAK,mBAAmB,oBAAA,GACpC,OAAO,CAAC,EAAE,QAAA,MAAc,UAAU,OAAO,CAAC,EAC1C;AAAA,MACA,CAAC,QAAQ,EAAE,eAAe,oBAAoB,KAAK,eAAe,mBAAmB,QAAQ,eAAe,aAAa;AAAA,MACzH;AAAA,IAAA;AAAA,EAEH;AACD;"}
1
+ {"version":3,"file":"SchemaVersionBuilder.js","sources":["../../../../packages/migrations-client/src/SchemaVersionBuilder.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { emptySchema } from '@contember/schema-utils'\nimport { Migration, SchemaMigrator } from '@contember/schema-migrations'\nimport { MigrationsResolver } from './MigrationsResolver.js'\nimport { SchemaStateManager } from './SchemaStateManager.js'\n\nexport class SchemaVersionBuilder {\n\tprivate lastBuildUntil: { migrations: Migration[]; schema: Schema } | null = null\n\n\tconstructor(\n\t\tprivate readonly migrationsResolver: MigrationsResolver,\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly schemaStateManager: SchemaStateManager,\n\t) {}\n\n\tasync buildSchema(targetVersion?: string): Promise<Schema> {\n\t\tlet schema = await this.buildSchemaAdvanced(emptySchema, version => !targetVersion || version <= targetVersion)\n\t\tif (!targetVersion && await this.schemaStateManager.isStateMode()) {\n\t\t\tconst state = await this.schemaStateManager.readState()\n\t\t\tschema = { ...schema, ...state }\n\t\t}\n\t\treturn schema\n\t}\n\n\t/**\n\t * Content migrations call this once each, with ascending versions. Continuing from the previous\n\t * build keeps a run linear instead of replaying every schema migration from scratch each time.\n\t */\n\tasync buildSchemaUntil(targetVersion: string): Promise<Schema> {\n\t\tconst migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => version < targetVersion)\n\t\tconst previous = this.lastBuildUntil\n\t\tconst canContinue = previous !== null\n\t\t\t&& previous.migrations.length <= migrations.length\n\t\t\t&& previous.migrations.every((migration, index) => migration === migrations[index])\n\t\tconst start = canContinue ? previous : { migrations: [], schema: emptySchema }\n\n\t\tconst schema = this.applyMigrations(start.schema, migrations.slice(start.migrations.length))\n\t\tthis.lastBuildUntil = { migrations, schema }\n\t\treturn schema\n\t}\n\n\tasync continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema> {\n\t\treturn this.buildSchemaAdvanced(schema, version => version <= targetVersion && version > (previousVersion || ''))\n\t}\n\n\tpublic async buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema> {\n\t\tconst migrations = (await this.migrationsResolver.getSchemaMigrations()).filter(({ version }) => condition(version))\n\t\treturn this.applyMigrations(initialSchema, migrations)\n\t}\n\n\tprivate applyMigrations(initialSchema: Schema, migrations: Migration[]): Schema {\n\t\treturn migrations.reduce<Schema>(\n\t\t\t(schema, { modifications, formatVersion }) => this.schemaMigrator.applyModifications(schema, modifications, formatVersion),\n\t\t\tinitialSchema,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;;;AAMO,MAAM,qBAAqB;AAAA,EAGjC,YACkB,oBACA,gBACA,oBAChB;AAHgB,SAAA,qBAAA;AACA,SAAA,iBAAA;AACA,SAAA,qBAAA;AALlB,kBAAA,MAAQ,kBAAqE,IAAA;AAAA,EAM1E;AAAA,EAEH,MAAM,YAAY,eAAyC;AAC1D,QAAI,SAAS,MAAM,KAAK,oBAAoB,aAAa,CAAA,YAAW,CAAC,iBAAiB,WAAW,aAAa;AAC9G,QAAI,CAAC,iBAAiB,MAAM,KAAK,mBAAmB,eAAe;AAClE,YAAM,QAAQ,MAAM,KAAK,mBAAmB,UAAA;AAC5C,eAAS,EAAE,GAAG,QAAQ,GAAG,MAAA;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,iBAAiB,eAAwC;AAC9D,UAAM,cAAc,MAAM,KAAK,mBAAmB,oBAAA,GAAuB,OAAO,CAAC,EAAE,cAAc,UAAU,aAAa;AACxH,UAAM,WAAW,KAAK;AACtB,UAAM,cAAc,aAAa,QAC7B,SAAS,WAAW,UAAU,WAAW,UACzC,SAAS,WAAW,MAAM,CAAC,WAAW,UAAU,cAAc,WAAW,KAAK,CAAC;AACnF,UAAM,QAAQ,cAAc,WAAW,EAAE,YAAY,CAAA,GAAI,QAAQ,YAAA;AAEjE,UAAM,SAAS,KAAK,gBAAgB,MAAM,QAAQ,WAAW,MAAM,MAAM,WAAW,MAAM,CAAC;AAC3F,SAAK,iBAAiB,EAAE,YAAY,OAAA;AACpC,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,SAAS,QAAgB,iBAAgC,eAAwC;AACtG,WAAO,KAAK,oBAAoB,QAAQ,CAAA,YAAW,WAAW,iBAAiB,WAAW,mBAAmB,GAAG;AAAA,EACjH;AAAA,EAEA,MAAa,oBAAoB,eAAuB,WAA0D;AACjH,UAAM,cAAc,MAAM,KAAK,mBAAmB,oBAAA,GAAuB,OAAO,CAAC,EAAE,QAAA,MAAc,UAAU,OAAO,CAAC;AACnH,WAAO,KAAK,gBAAgB,eAAe,UAAU;AAAA,EACtD;AAAA,EAEQ,gBAAgB,eAAuB,YAAiC;AAC/E,WAAO,WAAW;AAAA,MACjB,CAAC,QAAQ,EAAE,eAAe,oBAAoB,KAAK,eAAe,mBAAmB,QAAQ,eAAe,aAAa;AAAA,MACzH;AAAA,IAAA;AAAA,EAEF;AACD;"}
@@ -6,10 +6,16 @@ export declare class SchemaVersionBuilder {
6
6
  private readonly migrationsResolver;
7
7
  private readonly schemaMigrator;
8
8
  private readonly schemaStateManager;
9
+ private lastBuildUntil;
9
10
  constructor(migrationsResolver: MigrationsResolver, schemaMigrator: SchemaMigrator, schemaStateManager: SchemaStateManager);
10
11
  buildSchema(targetVersion?: string): Promise<Schema>;
12
+ /**
13
+ * Content migrations call this once each, with ascending versions. Continuing from the previous
14
+ * build keeps a run linear instead of replaying every schema migration from scratch each time.
15
+ */
11
16
  buildSchemaUntil(targetVersion: string): Promise<Schema>;
12
17
  continue(schema: Schema, previousVersion: string | null, targetVersion: string): Promise<Schema>;
13
18
  buildSchemaAdvanced(initialSchema: Schema, condition: (version: string) => boolean): Promise<Schema>;
19
+ private applyMigrations;
14
20
  }
15
21
  //# sourceMappingURL=SchemaVersionBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaVersionBuilder.d.ts","sourceRoot":"","sources":["../../src/SchemaVersionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM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