@rebasepro/common 0.12.0 → 0.12.1-canary.gdfba2a1

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/dist/index.es.js CHANGED
@@ -1952,7 +1952,7 @@ function buildConditionContext(params) {
1952
1952
  * Maps a PostgreSQL column data type to a Rebase property type.
1953
1953
  */
1954
1954
  function pgTypeToRebaseProperty(column) {
1955
- const { column_name, data_type, udt_name, is_nullable, column_default, enum_values } = column;
1955
+ const { column_name, data_type, udt_name, is_nullable, column_default, character_maximum_length, enum_values } = column;
1956
1956
  const required = is_nullable === "NO";
1957
1957
  const prettifiedName = prettifyIdentifier(column_name);
1958
1958
  const isAutoId = column_default != null && (column_default.includes("nextval") || column_default.includes("gen_random_uuid") || column_default.includes("uuid_generate") || column_default.includes("identity"));
@@ -1976,11 +1976,15 @@ function pgTypeToRebaseProperty(column) {
1976
1976
  let colType = "varchar";
1977
1977
  if (dt === "text" || dt === "citext") colType = "text";
1978
1978
  if (dt === "char" || dt === "character") colType = "char";
1979
+ const declaredLength = colType === "text" ? null : character_maximum_length;
1979
1980
  const prop = {
1980
1981
  type: "string",
1981
1982
  name: prettifiedName,
1982
1983
  columnType: colType,
1983
- validation: required ? { required: true } : void 0
1984
+ validation: required || declaredLength ? {
1985
+ ...required ? { required: true } : {},
1986
+ ...declaredLength ? { max: declaredLength } : {}
1987
+ } : void 0
1984
1988
  };
1985
1989
  if (isAutoId) prop.isId = "manual";
1986
1990
  return prop;
@@ -2184,6 +2188,34 @@ function buildCollectionFromTableMetadata(tableName, metadata) {
2184
2188
  };
2185
2189
  }
2186
2190
  //#endregion
2191
+ //#region src/util/string-column-length.ts
2192
+ /**
2193
+ * The length a bounded string column is declared with when the property does
2194
+ * not say. Historical: it is what the DDL generator hardcoded, kept so that
2195
+ * regenerating an existing schema does not silently redefine its columns.
2196
+ */
2197
+ var DEFAULT_STRING_COLUMN_LENGTH = 255;
2198
+ /**
2199
+ * How wide a `varchar`/`char` column should be for a given property.
2200
+ *
2201
+ * One definition, three call sites, because they used to disagree. For the same
2202
+ * `columnType: "varchar"` property the DDL generator emitted `VARCHAR(255)`
2203
+ * while the Drizzle generator emitted a bare `varchar("col")` — which Postgres
2204
+ * reads as *unbounded* — so which of the two you ran decided whether the column
2205
+ * had a limit at all. Introspection then dropped the length entirely, so reading
2206
+ * an existing `character varying(500)` column back and regenerating it produced
2207
+ * a `VARCHAR(255)`: a silent narrowing of a column with data already in it.
2208
+ *
2209
+ * `validation.max` is the property's own statement about how long the value may
2210
+ * be, so it is the only sensible source for the column's width — and it keeps
2211
+ * the constraint the database enforces in step with the one the app enforces,
2212
+ * rather than inventing a second, different limit underneath it.
2213
+ */
2214
+ function resolveStringColumnLength(prop) {
2215
+ const max = prop.validation?.max;
2216
+ return typeof max === "number" && Number.isInteger(max) && max > 0 ? max : 255;
2217
+ }
2218
+ //#endregion
2187
2219
  //#region src/data/resolveDataSource.ts
2188
2220
  /**
2189
2221
  * Build a keyed registry from a list of {@link DataSourceDefinition}s.
@@ -3773,6 +3805,6 @@ async function detectJunctionTables(executeSql) {
3773
3805
  return junctionTables;
3774
3806
  }
3775
3807
  //#endregion
3776
- export { COLLECTION_PATH_SEPARATOR, COMPOSITE_ID_SEPARATOR, CollectionRegistry, DEFAULT_FIND_ALL_MAX_ROWS, DEFAULT_MAX_PAGES, DEFAULT_ONE_OF_TYPE, DEFAULT_ONE_OF_VALUE, DEFAULT_PAGE_SIZE, JUNCTION_TABLES_SQL, QueryBuilder, REBASE_INTERNAL_PREFIXES, REBASE_INTERNAL_SCHEMAS, RebasePaginationError, and, buildCollection, buildCollectionFromTableMetadata, buildCompositeId, buildConditionContext, buildProperty, buildPropertyCallbacks, buildRebaseData, buildRoutedRebaseData, buildSdkData, canCreateEntity, canDeleteEntity, canEditEntity, canReadCollection, checkOperation, classifyTable, collectAllPages, cond, createDataSourceRegistry, createPaginationHelpers, createRelationRef, createRelationRefWithData, defaultUsersCollection, defineCollection, deserializeFilter, deserializeLogicalCondition, deserializeOrderBy, detectJunctionTables, embedParentExpression, enumToObjectEntries, evaluateCondition, evaluatePolicy, findAnonymousGrants, findRelation, fullPathToCollectionSegments, getArrayResolvedProperties, getColumnName, getDeclaredPrimaryKeys, getDefaultValueFor, getDefaultValueFortype, getDefaultValuesFor, getEffectiveSecurityRules, getEntityChildViews, getEnumVarName, getInjectedSecurityRules, getJunctionCollectionConfig, getJunctionSecurityRules, getLabelOrConfigFrom, getPrimaryKeys, getReferenceFrom, getRelationFrom, getSubcollections, getTableName, getTableVarName, isJunctionBackedRelation, isPropertyBuilder, isRebaseInternalTable, normalizeToEntityRelation, or, paginateFind, parseIdValues, policyToPostgres, registerConditionOperations, resolveArrayProperties, resolveCollectionRelations, resolveDataSource, resolveEnumValues, resolveJunctionSpecs, resolvePrimaryKeys, resolveProperties, resolveProperty, resolvePropertyEnum, resolveRelation, resolveRelationProperty, resolveStorageFilenameString, resolveStoragePathString, resolveStorageSource, sanitizeData, securityRuleToConditions, segmentsToStrippedPath, serializeFilter, serializeLogicalCondition, serializeOrderBy, sortProperties, sqlToPolicy, stripCollectionPath, traverseValueProperty, traverseValuesProperties, updateDateAutoValues, wrapAsEntityData, wrapAsSdkData };
3808
+ export { COLLECTION_PATH_SEPARATOR, COMPOSITE_ID_SEPARATOR, CollectionRegistry, DEFAULT_FIND_ALL_MAX_ROWS, DEFAULT_MAX_PAGES, DEFAULT_ONE_OF_TYPE, DEFAULT_ONE_OF_VALUE, DEFAULT_PAGE_SIZE, DEFAULT_STRING_COLUMN_LENGTH, JUNCTION_TABLES_SQL, QueryBuilder, REBASE_INTERNAL_PREFIXES, REBASE_INTERNAL_SCHEMAS, RebasePaginationError, and, buildCollection, buildCollectionFromTableMetadata, buildCompositeId, buildConditionContext, buildProperty, buildPropertyCallbacks, buildRebaseData, buildRoutedRebaseData, buildSdkData, canCreateEntity, canDeleteEntity, canEditEntity, canReadCollection, checkOperation, classifyTable, collectAllPages, cond, createDataSourceRegistry, createPaginationHelpers, createRelationRef, createRelationRefWithData, defaultUsersCollection, defineCollection, deserializeFilter, deserializeLogicalCondition, deserializeOrderBy, detectJunctionTables, embedParentExpression, enumToObjectEntries, evaluateCondition, evaluatePolicy, findAnonymousGrants, findRelation, fullPathToCollectionSegments, getArrayResolvedProperties, getColumnName, getDeclaredPrimaryKeys, getDefaultValueFor, getDefaultValueFortype, getDefaultValuesFor, getEffectiveSecurityRules, getEntityChildViews, getEnumVarName, getInjectedSecurityRules, getJunctionCollectionConfig, getJunctionSecurityRules, getLabelOrConfigFrom, getPrimaryKeys, getReferenceFrom, getRelationFrom, getSubcollections, getTableName, getTableVarName, isJunctionBackedRelation, isPropertyBuilder, isRebaseInternalTable, normalizeToEntityRelation, or, paginateFind, parseIdValues, policyToPostgres, registerConditionOperations, resolveArrayProperties, resolveCollectionRelations, resolveDataSource, resolveEnumValues, resolveJunctionSpecs, resolvePrimaryKeys, resolveProperties, resolveProperty, resolvePropertyEnum, resolveRelation, resolveRelationProperty, resolveStorageFilenameString, resolveStoragePathString, resolveStorageSource, resolveStringColumnLength, sanitizeData, securityRuleToConditions, segmentsToStrippedPath, serializeFilter, serializeLogicalCondition, serializeOrderBy, sortProperties, sqlToPolicy, stripCollectionPath, traverseValueProperty, traverseValuesProperties, updateDateAutoValues, wrapAsEntityData, wrapAsSdkData };
3777
3809
 
3778
3810
  //# sourceMappingURL=index.es.js.map