@vibeorm/schema 5.1.0 → 5.2.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.
package/dist/index.js CHANGED
@@ -1943,6 +1943,11 @@ function validateRowRules(params) {
1943
1943
  function wellFormedName(params) {
1944
1944
  return [...params.name].every((character) => character.length !== 1 || character.charCodeAt(0) < 55296 || character.charCodeAt(0) > 57343);
1945
1945
  }
1946
+ var REPEATED_RULE_ADVICE = Object.freeze({
1947
+ appendOnly: "Keep one: it already refuses every UPDATE and DELETE.",
1948
+ rowFixed: "Merge them into one rule whose except list holds only the fields both leave mutable.",
1949
+ frozen: "Merge them into one rule, or protect the fields of a later stage with a fixed rule gated by onceSet."
1950
+ });
1946
1951
  function validateRowRulesWithLookup(params) {
1947
1952
  const { model, dialect } = params;
1948
1953
  const rules = model.rowRules;
@@ -1954,7 +1959,7 @@ function validateRowRulesWithLookup(params) {
1954
1959
  const add = (params) => {
1955
1960
  issues.push({ rule: params.rule ?? "row-rule-invalid", model: model.name, ...params });
1956
1961
  };
1957
- const seenKinds = new Set;
1962
+ const firstOfKind = new Map;
1958
1963
  const seenDefinitions = new Set;
1959
1964
  const seenNames = new Set;
1960
1965
  for (const value of rules) {
@@ -1965,18 +1970,22 @@ function validateRowRulesWithLookup(params) {
1965
1970
  }
1966
1971
  const rule = value;
1967
1972
  const generated = rule.kind === "appendOnly" ? new Set : params.generatedFields({ model });
1968
- if (seenNames.has(rule.name))
1973
+ const first = rule.kind === "fixed" ? undefined : firstOfKind.get(rule.kind);
1974
+ if (first !== undefined && rule.kind !== "fixed")
1975
+ add({ message: `Model "${model.name}" declares more than one ${rule.kind} row rule (${first}, ${rule.name}). A model takes at most one ${rule.kind} rule; only fixed rules may repeat. ${REPEATED_RULE_ADVICE[rule.kind]}` });
1976
+ else if (seenNames.has(rule.name))
1969
1977
  add({ rule: "row-rule-name-collision", message: `Row rules share the physical stem ${rule.name}; supply an explicit, distinct name stem` });
1970
1978
  seenNames.add(rule.name);
1971
1979
  if (model.isView)
1972
1980
  add({ message: "Row rules require a stored table, not a view" });
1973
- if (rule.kind !== "fixed" && seenKinds.has(rule.kind))
1974
- add({ message: `Only one ${rule.kind} row rule is allowed per model` });
1975
- seenKinds.add(rule.kind);
1976
- const definition = rule.kind === "fixed" ? JSON.stringify([rule.kind, [...rule.columns].sort(), rule.when]) : rule.kind;
1977
- if (seenDefinitions.has(definition))
1978
- add({ message: `Duplicate ${rule.kind} row-rule declaration` });
1979
- seenDefinitions.add(definition);
1981
+ if (rule.kind !== "fixed" && first === undefined)
1982
+ firstOfKind.set(rule.kind, rule.name);
1983
+ if (rule.kind === "fixed") {
1984
+ const definition = JSON.stringify([rule.kind, [...rule.columns].sort(), rule.when]);
1985
+ if (seenDefinitions.has(definition))
1986
+ add({ message: "Duplicate fixed row-rule declaration" });
1987
+ seenDefinitions.add(definition);
1988
+ }
1980
1989
  const pair = rowRuleObjectNames({ rule });
1981
1990
  const names = dialect === "postgres" ? [pair.functionName, pair.triggerName] : (rule.kind === "appendOnly" ? ["update", "delete"] : ["update"]).map((event) => rowRuleTriggerName({ rule, event }));
1982
1991
  for (const name of names) {
@@ -2011,7 +2020,7 @@ function validateRowRulesWithLookup(params) {
2011
2020
  if (rule.kind !== "appendOnly" && (rule.kind === "fixed" && rule.columns.length === 0 || protectedFieldsWithGenerated({ model, rule, generated }).length === 0))
2012
2021
  add({ message: `${rule.kind} requires at least one protected stored field` });
2013
2022
  }
2014
- if (seenKinds.has("appendOnly") && rules.length > 1)
2023
+ if (firstOfKind.has("appendOnly") && rules.length > 1)
2015
2024
  add({ message: "appendOnly cannot combine with other row rules; it already refuses every UPDATE and DELETE" });
2016
2025
  return issues;
2017
2026
  }
@@ -2876,6 +2885,11 @@ var GENERATED_TYPE_NAMES = {
2876
2885
  "ScalarOrderByInput",
2877
2886
  "RelationOrderByInput",
2878
2887
  "RelationFindManyArgs",
2888
+ "RelationAggregateOrderByInput",
2889
+ "RelationAvgOrderByInput",
2890
+ "RelationSumOrderByInput",
2891
+ "RelationMinOrderByInput",
2892
+ "RelationMaxOrderByInput",
2879
2893
  "CreateInput",
2880
2894
  "UncheckedCreateInput",
2881
2895
  "CreateManyInput",
@@ -4535,4 +4549,4 @@ export {
4535
4549
  validatorRefIssue
4536
4550
  };
4537
4551
 
4538
- //# debugId=92D7E56C6E6AF7A964756E2164756E21
4552
+ //# debugId=6A81F5FFEA4B498F64756E2164756E21