@rebasepro/server-mongo 0.16.0 → 0.16.1-canary.g1ad04b7

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,8 +1,8 @@
1
1
  import { Db, MongoClient } from "mongodb";
2
2
  import type { BackendBootstrapper } from "@rebasepro/types";
3
- import { MongoDriver } from "./services/MongoDriver";
4
- import { MongoRealtimeService } from "./services/MongoRealtimeService";
5
- import { MongoCollectionRegistry } from "./factory";
3
+ import { MongoDriver } from "./services/MongoDriver.js";
4
+ import { MongoRealtimeService } from "./services/MongoRealtimeService.js";
5
+ import { MongoCollectionRegistry } from "./factory.js";
6
6
  export interface MongoDriverConfig {
7
7
  connection: Db;
8
8
  client: MongoClient;
package/dist/factory.d.ts CHANGED
@@ -6,10 +6,10 @@
6
6
  */
7
7
  import { Db, MongoClient } from "mongodb";
8
8
  import { DataDriver, CollectionConfig } from "@rebasepro/types";
9
- import { MongoDataService } from "./db/MongoDataService";
10
- import { MongoRealtimeService } from "./services/MongoRealtimeService";
11
- import { MongoDriver } from "./services/MongoDriver";
12
- import { MongoHistoryService, HistoryRetentionConfig } from "./services/MongoHistoryService";
9
+ import { MongoDataService } from "./db/MongoDataService.js";
10
+ import { MongoRealtimeService } from "./services/MongoRealtimeService.js";
11
+ import { MongoDriver } from "./services/MongoDriver.js";
12
+ import { MongoHistoryService, HistoryRetentionConfig } from "./services/MongoHistoryService.js";
13
13
  import { BackendConfig, BackendInstance, CollectionRegistryInterface, DataRepository, DatabaseAdmin } from "@rebasepro/types";
14
14
  /**
15
15
  * Configuration for creating a MongoDB backend.
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAyB,MAAM,kBAAkB,CAAC;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E,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAI/D;;OAEG;IACH,cAAc,IAAI,gBAAgB,EAAE;IAIpC;;OAEG;IACH,kBAAkB,IAAI,GAAG,GAAG,SAAS;IAIrC;;OAEG;IACH,kBAAkB,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI;CAG3C;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,oBAAoB,CA4GnF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAC/B,EAAE,EAAE,EAAE,EACN,eAAe,CAAC,EAAE,oBAAoB,EACtC,cAAc,CAAC,EAAE,mBAAmB,EACpC,QAAQ,CAAC,EAAE,2BAA2B,GACvC,WAAW,CAIb;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,EAAE,GAAG,oBAAoB,CAEvE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,EAAE,GAAG,cAAc,CAElE;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,IAAI,kBAAkB,CAIxF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,EAAE,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAOjH"}
package/dist/index.d.ts CHANGED
@@ -8,11 +8,11 @@
8
8
  * The package implements the abstract interfaces from @rebasepro/server
9
9
  * (DataRepository, RealtimeProvider, CollectionRegistryInterface, etc.)
10
10
  */
11
- export * from "./connection";
12
- export * from "./factory";
13
- export * from "./db/MongoDataService";
14
- export * from "./db/MongoConditionBuilder";
15
- export * from "./services/MongoRealtimeService";
16
- export * from "./services/MongoDriver";
17
- export * from "./MongoBootstrapper";
11
+ export * from "./connection.js";
12
+ export * from "./factory.js";
13
+ export * from "./db/MongoDataService.js";
14
+ export * from "./db/MongoConditionBuilder.js";
15
+ export * from "./services/MongoRealtimeService.js";
16
+ export * from "./services/MongoDriver.js";
17
+ export * from "./MongoBootstrapper.js";
18
18
  //# sourceMappingURL=index.d.ts.map
package/dist/index.es.js CHANGED
@@ -1892,6 +1892,98 @@ function rowToEntityForCheck(row, path) {
1892
1892
  };
1893
1893
  }
1894
1894
  //#endregion
1895
+ //#region src/schema/plan-schema-change.ts
1896
+ var bySlug = (collections) => {
1897
+ const map = /* @__PURE__ */ new Map();
1898
+ for (const collection of collections) if (collection.slug) map.set(collection.slug, collection);
1899
+ return map;
1900
+ };
1901
+ var propertiesOf = (collection) => collection.properties ?? {};
1902
+ /**
1903
+ * What changed, in the terms a document database makes true.
1904
+ *
1905
+ * Exported because it is the interesting half and worth testing without a
1906
+ * driver: the shape of the answer is the product, and the rest is plumbing.
1907
+ */
1908
+ function classifyMongoChanges(before, after) {
1909
+ const previous = bySlug(before);
1910
+ const next = bySlug(after);
1911
+ const changes = [];
1912
+ for (const [slug, collection] of next) {
1913
+ if (!previous.has(slug)) {
1914
+ changes.push({
1915
+ kind: "add-collection",
1916
+ verdict: "safe",
1917
+ collection: slug,
1918
+ detail: `New collection "${slug}". MongoDB creates it on the first write; nothing is created now.`
1919
+ });
1920
+ continue;
1921
+ }
1922
+ const oldProps = propertiesOf(previous.get(slug));
1923
+ const newProps = propertiesOf(collection);
1924
+ for (const name of Object.keys(newProps)) {
1925
+ if (name in oldProps) continue;
1926
+ changes.push({
1927
+ kind: "add-property",
1928
+ verdict: "safe",
1929
+ collection: slug,
1930
+ property: name,
1931
+ detail: `New property "${name}". Existing documents do not have it and are not rewritten; reads return it as absent until something writes it.`
1932
+ });
1933
+ }
1934
+ for (const name of Object.keys(oldProps)) {
1935
+ if (name in newProps) continue;
1936
+ changes.push({
1937
+ kind: "remove-property",
1938
+ verdict: "safe",
1939
+ collection: slug,
1940
+ property: name,
1941
+ detail: `"${name}" is no longer served. Documents that have it keep it — MongoDB stores no schema, so nothing is removed from the data.`
1942
+ });
1943
+ }
1944
+ }
1945
+ for (const [slug] of previous) {
1946
+ if (next.has(slug)) continue;
1947
+ changes.push({
1948
+ kind: "remove-collection",
1949
+ verdict: "safe",
1950
+ collection: slug,
1951
+ detail: `Collection "${slug}" is no longer served. The MongoDB collection and every document in it are left exactly as they are.`
1952
+ });
1953
+ }
1954
+ return changes;
1955
+ }
1956
+ /** A commit message that says what changed rather than that something did. */
1957
+ function commitMessage(changes) {
1958
+ if (changes.length === 0) return "chore(schema): no change";
1959
+ const collections = [...new Set(changes.map((c) => c.collection))].sort();
1960
+ const added = changes.filter((c) => c.kind === "add-collection");
1961
+ const properties = changes.filter((c) => c.kind === "add-property");
1962
+ return `feat(schema): ${added.length === 1 && changes.length === 1 ? `add the ${added[0].collection} collection` : properties.length === 1 && changes.length === 1 ? `add ${properties[0].property} to ${properties[0].collection}` : collections.length === 1 ? `${changes.length} change(s) to ${collections[0]}` : `${changes.length} change(s) across ${collections.length} collections`}\n\n${changes.map((c) => `- ${c.detail}`).join("\n")}\n`;
1963
+ }
1964
+ /**
1965
+ * The plan: a commit, and nothing to run.
1966
+ *
1967
+ * `files` is empty here and filled by the caller with the rewritten collection
1968
+ * source. Postgres adds generated artifacts — a Drizzle schema, declarative
1969
+ * DDL — because a stale one breaks the next deploy. MongoDB generates none, so
1970
+ * the collection file is the whole of the change.
1971
+ */
1972
+ async function planMongoSchemaChange(before, after) {
1973
+ const changes = classifyMongoChanges(before, after);
1974
+ return {
1975
+ files: [],
1976
+ statements: [],
1977
+ classified: {
1978
+ changes,
1979
+ verdict: "safe",
1980
+ applicable: true
1981
+ },
1982
+ message: commitMessage(changes),
1983
+ withheldConstraints: []
1984
+ };
1985
+ }
1986
+ //#endregion
1895
1987
  //#region src/factory.ts
1896
1988
  /**
1897
1989
  * Simple in-memory collection registry for MongoDB.
@@ -1987,6 +2079,7 @@ function createMongoBackend(config) {
1987
2079
  realtimeProvider: realtimeService,
1988
2080
  collectionRegistry,
1989
2081
  admin: {
2082
+ planSchemaChange: async (before, after) => planMongoSchemaChange(before, after),
1990
2083
  async executeAggregate(pipeline) {
1991
2084
  const firstStage = pipeline[0];
1992
2085
  const collName = typeof firstStage.$from === "string" ? firstStage.$from : "__admin__";