@rebasepro/server-postgres 0.12.1-canary.gf4240e3 → 0.13.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.
@@ -1,7 +1,7 @@
1
1
  import { PgTable, AnyPgColumn } from "drizzle-orm/pg-core";
2
2
  import { CollectionConfig, ResolvedHasMany, ResolvedHasOne } from "@rebasepro/types";
3
3
  import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
4
- export { buildCompositeId, parseIdValues, COMPOSITE_ID_SEPARATOR } from "@rebasepro/common";
4
+ export { buildCompositeId, parseIdValues, isAddressableId, COMPOSITE_ID_SEPARATOR } from "@rebasepro/common";
5
5
  export type { PrimaryKeyInfo } from "@rebasepro/common";
6
6
  import type { PrimaryKeyInfo } from "@rebasepro/common";
7
7
  /**
@@ -22,6 +22,17 @@ export interface DrizzleColumnMeta {
22
22
  }
23
23
  /** Safely extract Drizzle column metadata from a column object. */
24
24
  export declare function getColumnMeta(col: AnyPgColumn): DrizzleColumnMeta;
25
+ /**
26
+ * Whether an address could name a row in this table, judged by the columns.
27
+ *
28
+ * {@link getPrimaryKeys} lets a config's `isId: "uuid"` win over the schema, so
29
+ * its `isUUID` is a claim rather than a fact — right for deriving addresses,
30
+ * wrong for refusing a query. Here the Drizzle column type decides, because it
31
+ * is what Postgres will enforce: a `uuid` column meets `/c/products/new` with
32
+ * `22P02`, which aborts the surrounding transaction and turns every later
33
+ * statement into an unrelated-looking `25P02`.
34
+ */
35
+ export declare function idCanAddressTable(id: string | number, table: PgTable, idInfoArray: PrimaryKeyInfo[]): boolean;
25
36
  export declare function getCollectionByPath(collectionPath: string, registry: PostgresCollectionRegistry): CollectionConfig;
26
37
  export declare function getTableForCollection(collection: CollectionConfig, registry: PostgresCollectionRegistry): PgTable<any>;
27
38
  /**
@@ -1458,6 +1458,34 @@ function createRelationRefWithData(id, path, data) {
1458
1458
  data
1459
1459
  };
1460
1460
  }
1461
+ /** The eight-four-four-four-twelve shape of a UUID, any version. */
1462
+ var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1463
+ /** Whether one address part can be a value of the column it addresses. */
1464
+ function partIsAddressable(part, pk) {
1465
+ if (pk.isUUID) return UUID_PATTERN.test(String(part));
1466
+ if (pk.type === "number") return typeof part === "number" ? Number.isFinite(part) : !isNaN(parseInt(String(part), 10));
1467
+ return true;
1468
+ }
1469
+ /**
1470
+ * Whether an address could name a row at all, before asking the database.
1471
+ *
1472
+ * A `uuid` column cannot hold `"new"`, and an `integer` column cannot hold
1473
+ * `"abc"` — so the answer to "which row is this" is "none", and that is a 404,
1474
+ * not a failure. Postgres cannot say so politely: the comparison never runs, it
1475
+ * raises `22P02` and aborts the enclosing transaction, after which every
1476
+ * further statement returns the far less helpful `25P02`.
1477
+ *
1478
+ * `isUUID` must come from the column, not from `isId: "uuid"` in a config: the
1479
+ * config is a claim about a key, and a `text` column that holds ids of some
1480
+ * other shape is a working app this must not start rejecting.
1481
+ */
1482
+ function isAddressableId(idValue, primaryKeys) {
1483
+ if (primaryKeys.length === 0) return false;
1484
+ if (primaryKeys.length === 1) return partIsAddressable(idValue, primaryKeys[0]);
1485
+ const parts = String(idValue).split(":::");
1486
+ if (parts.length !== primaryKeys.length) return false;
1487
+ return parts.every((part, i) => partIsAddressable(part, primaryKeys[i]));
1488
+ }
1461
1489
  /**
1462
1490
  * Derive a row's address from its key columns.
1463
1491
  *
@@ -4266,6 +4294,6 @@ function buildSdkData(driver) {
4266
4294
  return wrapAsSdkData(buildRebaseData(driver));
4267
4295
  }
4268
4296
  //#endregion
4269
- export { DEFAULT_ONE_OF_TYPE as A, updateDateAutoValues as C, mergeDeep as D, getPolicyNamesForRule as E, hasForeignKeyOnTarget as M, isManyToMany as N, camelCase as O, Vector as P, normalizeToEntityRelation as S, legacyForeignKeyName as T, buildCompositeId as _, getJunctionSecurityRules as a, createRelationRef as b, policyToPostgres as c, findRelation as d, getColumnName as f, resolveCollectionRelations as g, getTableVarName as h, getJunctionCollectionConfig as i, DEFAULT_ONE_OF_VALUE as j, toSnakeCase as k, securityRuleToConditions as l, getTableName as m, CollectionRegistry as n, resolveJunctionSpecs as o, getEnumVarName as p, resolveStringColumnLength as r, getEffectiveSecurityRules as s, buildSdkData as t, findAnonymousGrants as u, getDeclaredPrimaryKeys as v, generateForeignKeyName as w, createRelationRefWithData as x, parseIdValues as y };
4297
+ export { toSnakeCase as A, normalizeToEntityRelation as C, getPolicyNamesForRule as D, legacyForeignKeyName as E, Vector as F, DEFAULT_ONE_OF_VALUE as M, hasForeignKeyOnTarget as N, mergeDeep as O, isManyToMany as P, createRelationRefWithData as S, generateForeignKeyName as T, buildCompositeId as _, getJunctionSecurityRules as a, parseIdValues as b, policyToPostgres as c, findRelation as d, getColumnName as f, resolveCollectionRelations as g, getTableVarName as h, getJunctionCollectionConfig as i, DEFAULT_ONE_OF_TYPE as j, camelCase as k, securityRuleToConditions as l, getTableName as m, CollectionRegistry as n, resolveJunctionSpecs as o, getEnumVarName as p, resolveStringColumnLength as r, getEffectiveSecurityRules as s, buildSdkData as t, findAnonymousGrants as u, getDeclaredPrimaryKeys as v, updateDateAutoValues as w, createRelationRef as x, isAddressableId as y };
4270
4298
 
4271
- //# sourceMappingURL=src-CzbghKwf.js.map
4299
+ //# sourceMappingURL=src-DlPBctw_.js.map