@rebasepro/server-postgres 0.16.0 → 0.16.1-canary.g2d1aec8

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.
Files changed (63) hide show
  1. package/dist/PostgresAdapter.d.ts +1 -1
  2. package/dist/PostgresBackendDriver.d.ts +16 -7
  3. package/dist/PostgresBootstrapper.d.ts +6 -6
  4. package/dist/auth/services.d.ts +1 -1
  5. package/dist/backup/backup-cron.d.ts +1 -1
  6. package/dist/backup/backup-service.d.ts +2 -2
  7. package/dist/backup/index.d.ts +4 -4
  8. package/dist/collections/PostgresCollectionRegistry.d.ts +1 -1
  9. package/dist/collections/buildRegistry.d.ts +1 -1
  10. package/dist/collections/validate-relations.d.ts +1 -1
  11. package/dist/data-transformer.d.ts +1 -1
  12. package/dist/{ensure-collection-policies-BVFb2olB.js → ensure-collection-policies-CVfVHS6o.js} +3 -3
  13. package/dist/{ensure-collection-policies-BVFb2olB.js.map → ensure-collection-policies-CVfVHS6o.js.map} +1 -1
  14. package/dist/{auth-users-columns-CgyPWQ18.js → ensure-collection-tables-jYsvOLZF.js} +1443 -11
  15. package/dist/ensure-collection-tables-jYsvOLZF.js.map +1 -0
  16. package/dist/index.d.ts +16 -16
  17. package/dist/index.es.js +2169 -1803
  18. package/dist/index.es.js.map +1 -1
  19. package/dist/{rls-enforcement-Ch0T6OwW.js → rls-enforcement-CsD7nZDn.js} +2 -2
  20. package/dist/{rls-enforcement-Ch0T6OwW.js.map → rls-enforcement-CsD7nZDn.js.map} +1 -1
  21. package/dist/schema/classify-change.d.ts +82 -0
  22. package/dist/schema/dynamic-tables.d.ts +1 -1
  23. package/dist/schema/ensure-collection-policies.d.ts +1 -1
  24. package/dist/schema/ensure-collection-tables.d.ts +93 -2
  25. package/dist/schema/generate-schema-commit.d.ts +136 -0
  26. package/dist/schema/introspect-db-constraints.d.ts +1 -1
  27. package/dist/schema/introspect-db-logic.d.ts +3 -3
  28. package/dist/schema/introspect-db-project.d.ts +1 -1
  29. package/dist/schema/introspect-db-queries.d.ts +1 -1
  30. package/dist/schema/introspect-db-structure.d.ts +2 -2
  31. package/dist/schema/introspect-runtime.d.ts +1 -1
  32. package/dist/schema/vector-index.d.ts +88 -0
  33. package/dist/services/BranchService.d.ts +2 -2
  34. package/dist/services/FetchService.d.ts +4 -4
  35. package/dist/services/PersistService.d.ts +5 -5
  36. package/dist/services/RelationService.d.ts +3 -3
  37. package/dist/services/RelationWriteService.d.ts +3 -3
  38. package/dist/services/cdc/junction-tables.d.ts +1 -1
  39. package/dist/services/cdc/trigger-cdc.d.ts +1 -1
  40. package/dist/services/channel-bus/PostgresChannelBus.d.ts +1 -1
  41. package/dist/services/channel-bus/index.d.ts +2 -2
  42. package/dist/services/collection-helpers.d.ts +1 -1
  43. package/dist/services/dataService.d.ts +10 -10
  44. package/dist/services/index.d.ts +4 -4
  45. package/dist/services/junction-writes.d.ts +2 -2
  46. package/dist/services/nested-path.d.ts +1 -1
  47. package/dist/services/realtimeService.d.ts +3 -3
  48. package/dist/services/row-pipeline.d.ts +1 -1
  49. package/dist/services/write-denial.d.ts +1 -1
  50. package/dist/utils/drizzle-conditions.d.ts +2 -2
  51. package/dist/websocket-BVgDVO-V.js.map +1 -1
  52. package/dist/websocket.d.ts +2 -2
  53. package/package.json +7 -7
  54. package/src/PostgresBackendDriver.ts +40 -0
  55. package/src/schema/classify-change.ts +436 -0
  56. package/src/schema/ensure-collection-tables.test.ts +168 -1
  57. package/src/schema/ensure-collection-tables.ts +344 -14
  58. package/src/schema/generate-postgres-ddl-logic.ts +15 -0
  59. package/src/schema/generate-schema-commit.ts +242 -0
  60. package/src/schema/vector-index.ts +278 -0
  61. package/dist/auth-users-columns-CgyPWQ18.js.map +0 -1
  62. package/dist/ensure-collection-tables-BY1pHRD_.js +0 -840
  63. package/dist/ensure-collection-tables-BY1pHRD_.js.map +0 -1
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The one place a `{ type: "vector" }` property becomes an ANN index.
3
+ *
4
+ * Without an index, pgvector answers `ORDER BY embedding <=> $1` by computing
5
+ * the distance to every row and sorting — exact, and linear. That is the right
6
+ * answer at ten thousand rows and the wrong one at a million, which is why the
7
+ * default here is to build an index rather than to leave the column bare.
8
+ *
9
+ * ## The operator class is not a detail
10
+ *
11
+ * An index is built for exactly one operator class, and the planner uses it
12
+ * only for the operator that class implements. `vector_cosine_ops` answers
13
+ * `<=>` and nothing else; a query asking for `<->` against a cosine index gets
14
+ * a sequential scan and no error. So the default indexed distance here is
15
+ * `cosine`, because `cosine` is what `vectorSearch` measures with when the
16
+ * caller does not say — see `DrizzleConditionBuilder.buildVectorSearch`. The
17
+ * two defaults have to agree, and this comment is the reason they do.
18
+ *
19
+ * ## Why 2000 dimensions is a ceiling and not an error
20
+ *
21
+ * pgvector cannot index a `vector` wider than 2000 dimensions with either
22
+ * method. A 3072-dimension embedding (`text-embedding-3-large`) is therefore
23
+ * storable and searchable but not indexable. Refusing the boot over that would
24
+ * make a working configuration unbootable; silently indexing it is impossible.
25
+ * So the column is created, the index is skipped, and the reason is reported.
26
+ *
27
+ * Like `search-column.ts`, this module exists so that the DDL generator and the
28
+ * boot-time ensure render the *same* specification rather than describing the
29
+ * same index twice, differently. `contracts/derived-names.txt` records the
30
+ * names both produce, and CI fails if they diverge.
31
+ */
32
+ import type { CollectionConfig, Property, VectorDistance } from "@rebasepro/types";
33
+ /**
34
+ * The widest `vector` pgvector will build an HNSW or IVFFlat index over.
35
+ * Storage and exact search are unaffected by this limit.
36
+ */
37
+ export declare const MAX_INDEXABLE_VECTOR_DIMENSIONS = 2000;
38
+ /** The distance indexed when a property does not name one. */
39
+ export declare const DEFAULT_VECTOR_DISTANCE: VectorDistance;
40
+ /** The index method used when a property does not name one. */
41
+ export declare const DEFAULT_VECTOR_INDEX_METHOD: "hnsw";
42
+ export interface VectorIndexSpec {
43
+ schema: string;
44
+ table: string;
45
+ column: string;
46
+ indexName: string;
47
+ method: "hnsw" | "ivfflat";
48
+ distance: VectorDistance;
49
+ operatorClass: string;
50
+ /** Rendered into `WITH (...)`; empty when every parameter is defaulted. */
51
+ parameters: Array<[string, number]>;
52
+ }
53
+ /** A vector column that will not be indexed, and why. */
54
+ export interface SkippedVectorIndex {
55
+ schema: string;
56
+ table: string;
57
+ column: string;
58
+ dimensions: number;
59
+ reason: string;
60
+ }
61
+ export interface VectorIndexPlan {
62
+ specs: VectorIndexSpec[];
63
+ skipped: SkippedVectorIndex[];
64
+ }
65
+ export declare class VectorIndexConfigError extends Error {
66
+ constructor(message: string);
67
+ }
68
+ /**
69
+ * Every ANN index a collection's vector properties call for.
70
+ *
71
+ * `resolveColumn` is passed in rather than imported so that this module stays
72
+ * free of the DDL generator, which imports *it*. Both callers hand it the same
73
+ * `resolveColumnName`, and a contract test asserts the names agree.
74
+ */
75
+ export declare const buildVectorIndexPlan: (collection: CollectionConfig, resolveColumn: (propName: string, prop?: Property | null) => string) => VectorIndexPlan;
76
+ /**
77
+ * The `CREATE INDEX` for one spec.
78
+ *
79
+ * `CONCURRENTLY` is deliberately absent, for the same reason it is absent from
80
+ * `searchIndexStatements`: this form is replayed as part of a migration, where
81
+ * a concurrent build is not allowed. The boot-time ensure rewrites it — see
82
+ * `ensureCollectionTables`.
83
+ */
84
+ export declare const vectorIndexStatement: (spec: VectorIndexSpec) => string;
85
+ /** Every statement for a plan, in a stable order. */
86
+ export declare const vectorIndexStatements: (plan: VectorIndexPlan) => string[];
87
+ /** The index names a plan creates — what the derived-names contract records. */
88
+ export declare const vectorIndexNames: (plan: VectorIndexPlan) => string[];
@@ -7,8 +7,8 @@
7
7
  * same `rebase` schema convention used by entity_history, auth, etc.
8
8
  */
9
9
  import { BranchInfo } from "@rebasepro/types";
10
- import { DrizzleClient } from "../interfaces";
11
- import { DatabasePoolManager } from "../databasePoolManager";
10
+ import { DrizzleClient } from "../interfaces.js";
11
+ import { DatabasePoolManager } from "../databasePoolManager.js";
12
12
  export declare class BranchService {
13
13
  private db;
14
14
  private poolManager;
@@ -2,10 +2,10 @@ import { SQL } from "drizzle-orm";
2
2
  import { PgTable } from "drizzle-orm/pg-core";
3
3
  import { FilterValues, OrderByTuple, LogicalCondition } from "@rebasepro/types";
4
4
  import type { VectorSearchParams } from "@rebasepro/types";
5
- import { RelationService } from "./RelationService";
6
- import { DrizzleClient } from "../interfaces";
7
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
8
- import { type NestedPathHop } from "./nested-path";
5
+ import { RelationService } from "./RelationService.js";
6
+ import { DrizzleClient } from "../interfaces.js";
7
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
8
+ import { type NestedPathHop } from "./nested-path.js";
9
9
  /**
10
10
  * Service for handling all row read operations.
11
11
  * Handles fetching, searching, counting, and filtering rows.
@@ -1,8 +1,8 @@
1
- import { RelationService } from "./RelationService";
2
- import { RelationWriteService } from "./RelationWriteService";
3
- import { FetchService } from "./FetchService";
4
- import { DrizzleClient } from "../interfaces";
5
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
1
+ import { RelationService } from "./RelationService.js";
2
+ import { RelationWriteService } from "./RelationWriteService.js";
3
+ import { FetchService } from "./FetchService.js";
4
+ import { DrizzleClient } from "../interfaces.js";
5
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
6
6
  /**
7
7
  * Service for handling all row write operations.
8
8
  * Handles saving, deleting, and updating rows.
@@ -1,7 +1,7 @@
1
- import { DrizzleClient } from "../interfaces";
1
+ import { DrizzleClient } from "../interfaces.js";
2
2
  import { CollectionConfig, FilterValues, OrderByTuple, ResolvedRelation, ResolvedHasMany, ResolvedHasOne } from "@rebasepro/types";
3
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
4
- import type { NestedPathHop } from "./nested-path";
3
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
4
+ import type { NestedPathHop } from "./nested-path.js";
5
5
  /**
6
6
  * Service for handling all relation-related operations.
7
7
  * Handles fetching, updating, and managing row relations.
@@ -1,7 +1,7 @@
1
1
  import { CollectionConfig, ResolvedManyToMany, ResolvedRelation, ResolvedVia } from "@rebasepro/types";
2
- import { DrizzleClient } from "../interfaces";
3
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
4
- import type { NestedPathHop } from "./nested-path";
2
+ import { DrizzleClient } from "../interfaces.js";
3
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
4
+ import type { NestedPathHop } from "./nested-path.js";
5
5
  /**
6
6
  * Writing relations: junction membership, foreign-key stamping, and the links a
7
7
  * nested path creates or removes.
@@ -1,5 +1,5 @@
1
1
  import { CollectionConfig } from "@rebasepro/types";
2
- import { PostgresCollectionRegistry } from "../../collections/PostgresCollectionRegistry";
2
+ import { PostgresCollectionRegistry } from "../../collections/PostgresCollectionRegistry.js";
3
3
  /**
4
4
  * One end of a many-to-many, as seen from the junction table.
5
5
  *
@@ -1,4 +1,4 @@
1
- import type { RawSqlRunner } from "../../security/rls-enforcement";
1
+ import type { RawSqlRunner } from "../../security/rls-enforcement.js";
2
2
  /**
3
3
  * Trigger-based Change Data Capture (CDC).
4
4
  *
@@ -26,7 +26,7 @@
26
26
  * than correctness. That is what makes coalescing safe.
27
27
  */
28
28
  import { NodePgDatabase } from "drizzle-orm/node-postgres";
29
- import { ChannelBus, ChannelBusFrame, ChannelBusHandler } from "./ChannelBus";
29
+ import { ChannelBus, ChannelBusFrame, ChannelBusHandler } from "./ChannelBus.js";
30
30
  /** NOTIFY channel carrying channel-bus frames. */
31
31
  export declare const CHANNEL_BUS_NOTIFY_CHANNEL = "rebase_channel_bus";
32
32
  /**
@@ -16,8 +16,8 @@
16
16
  */
17
17
  import { NodePgDatabase } from "drizzle-orm/node-postgres";
18
18
  import { type ChannelBus, type ChannelBusSetting } from "@rebasepro/types";
19
- export * from "./ChannelBus";
20
- export { PostgresChannelBus, CHANNEL_BUS_NOTIFY_CHANNEL, PG_NOTIFY_MAX_PAYLOAD_BYTES, DEFAULT_BATCH_WINDOW_MS, parseChannelBusFrame, parseChannelBusPayload } from "./PostgresChannelBus";
19
+ export * from "./ChannelBus.js";
20
+ export { PostgresChannelBus, CHANNEL_BUS_NOTIFY_CHANNEL, PG_NOTIFY_MAX_PAYLOAD_BYTES, DEFAULT_BATCH_WINDOW_MS, parseChannelBusFrame, parseChannelBusPayload } from "./PostgresChannelBus.js";
21
21
  export interface ChannelBusDeps {
22
22
  db: NodePgDatabase<Record<string, unknown>>;
23
23
  /**
@@ -1,6 +1,6 @@
1
1
  import { PgTable, AnyPgColumn } from "drizzle-orm/pg-core";
2
2
  import { CollectionConfig, ResolvedHasMany, ResolvedHasOne } from "@rebasepro/types";
3
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
3
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
4
4
  import { ApiError } from "@rebasepro/server";
5
5
  export { buildCompositeId, parseIdValues, isAddressableId, COMPOSITE_ID_SEPARATOR } from "@rebasepro/common";
6
6
  export type { PrimaryKeyInfo } from "@rebasepro/common";
@@ -1,15 +1,15 @@
1
1
  import { FilterValues, LogicalCondition, OrderByTuple } from "@rebasepro/types";
2
2
  import type { VectorSearchParams } from "@rebasepro/types";
3
- import { FetchService } from "./FetchService";
4
- import { PersistService } from "./PersistService";
5
- import { RelationService } from "./RelationService";
6
- import { DataRepository, DrizzleClient } from "../interfaces";
7
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
8
- export { sanitizeAndConvertDates, serializeDataToServer, parseDataFromServer } from "../data-transformer";
9
- export { FetchService } from "./FetchService";
10
- export { PersistService } from "./PersistService";
11
- export { RelationService } from "./RelationService";
12
- export * from "../interfaces";
3
+ import { FetchService } from "./FetchService.js";
4
+ import { PersistService } from "./PersistService.js";
5
+ import { RelationService } from "./RelationService.js";
6
+ import { DataRepository, DrizzleClient } from "../interfaces.js";
7
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
8
+ export { sanitizeAndConvertDates, serializeDataToServer, parseDataFromServer } from "../data-transformer.js";
9
+ export { FetchService } from "./FetchService.js";
10
+ export { PersistService } from "./PersistService.js";
11
+ export { RelationService } from "./RelationService.js";
12
+ export * from "../interfaces.js";
13
13
  /**
14
14
  * DataService - Facade for row operations.
15
15
  *
@@ -1,4 +1,4 @@
1
- export { FetchService } from "./FetchService";
2
- export { PersistService } from "./PersistService";
3
- export { RelationService } from "./RelationService";
4
- export { getCollectionByPath, getTableForCollection, getPrimaryKeys, deriveRowAddress, parseIdValues, buildCompositeId } from "./collection-helpers";
1
+ export { FetchService } from "./FetchService.js";
2
+ export { PersistService } from "./PersistService.js";
3
+ export { RelationService } from "./RelationService.js";
4
+ export { getCollectionByPath, getTableForCollection, getPrimaryKeys, deriveRowAddress, parseIdValues, buildCompositeId } from "./collection-helpers.js";
@@ -1,7 +1,7 @@
1
1
  import { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
2
2
  import type { ResolvedVia } from "@rebasepro/types";
3
- import { DrizzleClient } from "../interfaces";
4
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
3
+ import { DrizzleClient } from "../interfaces.js";
4
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
5
5
  /**
6
6
  * Writing a many-to-many means writing rows in a junction table, and doing that
7
7
  * needs three things: the table, the column naming the row being written from,
@@ -1,5 +1,5 @@
1
1
  import { CollectionConfig, ResolvedRelation } from "@rebasepro/types";
2
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
2
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
3
3
  /**
4
4
  * The last hop of a nested collection path, e.g. `authors/1/posts`.
5
5
  *
@@ -2,9 +2,9 @@ import { WebSocket } from "ws";
2
2
  import { EventEmitter } from "events";
3
3
  import { DataDriver, WebSocketMessage, LogicalCondition, OrderByTuple } from "@rebasepro/types";
4
4
  import { NodePgDatabase } from "drizzle-orm/node-postgres";
5
- import { RealtimeProvider, CollectionSubscriptionConfig, SingleSubscriptionConfig } from "../interfaces";
6
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
7
- import { ChannelBus } from "./channel-bus";
5
+ import { RealtimeProvider, CollectionSubscriptionConfig, SingleSubscriptionConfig } from "../interfaces.js";
6
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
7
+ import { ChannelBus } from "./channel-bus/index.js";
8
8
  import type { ChannelRetentionRule } from "@rebasepro/types";
9
9
  /**
10
10
  * Auth context stored per-subscription so real-time refetches respect RLS.
@@ -1,5 +1,5 @@
1
1
  import { CollectionConfig, ResolvedRelation } from "@rebasepro/types";
2
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
2
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
3
3
  /**
4
4
  * Turning a drizzle result into a row we serve.
5
5
  *
@@ -1,7 +1,7 @@
1
1
  import { SQL } from "drizzle-orm";
2
2
  import { PgTable } from "drizzle-orm/pg-core";
3
3
  import { ApiError } from "@rebasepro/server";
4
- import { DrizzleClient } from "../interfaces";
4
+ import { DrizzleClient } from "../interfaces.js";
5
5
  /**
6
6
  * Explain a write that matched no rows.
7
7
  *
@@ -1,8 +1,8 @@
1
1
  import { SQL } from "drizzle-orm";
2
2
  import { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
3
3
  import { CollectionConfig, FilterValues, WhereFilterOp, LogicalCondition, FilterCondition, ResolvedRelation, ResolvedBelongsTo, ResolvedForeignKeyOnTarget, ResolvedManyToMany, type RelationAggregateSort } from "@rebasepro/types";
4
- import { type SearchColumnSpec } from "../schema/search-column";
5
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
4
+ import { type SearchColumnSpec } from "../schema/search-column.js";
5
+ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
6
6
  /**
7
7
  * What to do with a filter field that resolves to no column at all.
8
8
  *