@vibeorm/schema 5.1.0 → 5.3.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.
@@ -76,6 +76,8 @@ export type DialectCapabilities = {
76
76
  readonly nativeRowLevelSecurity: boolean;
77
77
  /** INSERT/UPDATE/DELETE ... RETURNING. False ⇒ insertId + re-select fallback. */
78
78
  readonly returning: boolean;
79
+ /** Count-only writes can assert their exact direct row count inside the same SQL statement. */
80
+ readonly exactRowCount: boolean;
79
81
  /** Native scalar array columns (String[], Int[], ...). */
80
82
  readonly scalarArrays: boolean;
81
83
  /** Native enum column types (CREATE TYPE / inline ENUM). */
package/dist/errors.d.ts CHANGED
@@ -9,6 +9,8 @@
9
9
  export declare const VIBE_ERROR_CODES: readonly [
10
10
  /** findUniqueOrThrow / findFirstOrThrow / update / delete target missing. */
11
11
  "VIBE_NOT_FOUND",
12
+ /** A count-only write's exact affected-row expectation did not match. */
13
+ "VIBE_ROW_COUNT_MISMATCH",
12
14
  /** Unique constraint violation (driver-mapped). */
13
15
  "VIBE_UNIQUE_VIOLATION",
14
16
  /** Exclusion constraint violation (PostgreSQL SQLSTATE 23P01). */
@@ -185,6 +185,8 @@ export type ExtensionClientContribution = {
185
185
  * type or at runtime.
186
186
  */
187
187
  readonly readOnly?: true | readonly string[];
188
+ /** Opt this surface into explicit lazy operation capture and transaction batching. */
189
+ readonly lazy?: true;
188
190
  readonly runtimeGlue: string;
189
191
  readonly dts: readonly string[];
190
192
  readonly dtsTypes?: readonly string[];
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // packages/schema/src/errors.ts
3
3
  var VIBE_ERROR_CODES = [
4
4
  "VIBE_NOT_FOUND",
5
+ "VIBE_ROW_COUNT_MISMATCH",
5
6
  "VIBE_UNIQUE_VIOLATION",
6
7
  "VIBE_EXCLUSION_VIOLATION",
7
8
  "VIBE_FK_VIOLATION",
@@ -228,6 +229,10 @@ var RESERVED_CLIENT_NAMES = [
228
229
  "$querySqlResult",
229
230
  "$executeSql",
230
231
  "$queryRaw",
232
+ "$queueRaw",
233
+ "$lazy",
234
+ "$queryRawLazy",
235
+ "$executeRawLazy",
231
236
  "$queryRawUnsafe",
232
237
  "$executeRaw",
233
238
  "$executeRawUnsafe",
@@ -242,6 +247,7 @@ var RESERVED_CLIENT_NAMES = [
242
247
  "$models",
243
248
  "$withContext",
244
249
  "$advisoryLock",
250
+ "$advisoryLocks",
245
251
  "$tryAdvisoryLock"
246
252
  ];
247
253
  var RESERVED_COLUMN_PREFIX = "__vibe_";
@@ -441,6 +447,7 @@ var POSTGRES_CAPABILITIES = Object.freeze({
441
447
  predicateArithmeticTypes: Object.freeze(["Int", "BigInt", "Float", "Decimal"]),
442
448
  nativeRowLevelSecurity: true,
443
449
  returning: true,
450
+ exactRowCount: true,
444
451
  scalarArrays: true,
445
452
  nativeEnums: true,
446
453
  ilike: true,
@@ -481,6 +488,7 @@ var SQLITE_CAPABILITIES = Object.freeze({
481
488
  predicateArithmeticTypes: Object.freeze(["Int", "BigInt", "Float"]),
482
489
  nativeRowLevelSecurity: false,
483
490
  returning: true,
491
+ exactRowCount: false,
484
492
  scalarArrays: false,
485
493
  nativeEnums: false,
486
494
  ilike: false,
@@ -521,6 +529,7 @@ var MYSQL_CAPABILITIES = Object.freeze({
521
529
  predicateArithmeticTypes: Object.freeze(["Int", "BigInt", "Float", "Decimal"]),
522
530
  nativeRowLevelSecurity: false,
523
531
  returning: false,
532
+ exactRowCount: false,
524
533
  scalarArrays: false,
525
534
  nativeEnums: true,
526
535
  ilike: false,
@@ -1943,6 +1952,11 @@ function validateRowRules(params) {
1943
1952
  function wellFormedName(params) {
1944
1953
  return [...params.name].every((character) => character.length !== 1 || character.charCodeAt(0) < 55296 || character.charCodeAt(0) > 57343);
1945
1954
  }
1955
+ var REPEATED_RULE_ADVICE = Object.freeze({
1956
+ appendOnly: "Keep one: it already refuses every UPDATE and DELETE.",
1957
+ rowFixed: "Merge them into one rule whose except list holds only the fields both leave mutable.",
1958
+ frozen: "Merge them into one rule, or protect the fields of a later stage with a fixed rule gated by onceSet."
1959
+ });
1946
1960
  function validateRowRulesWithLookup(params) {
1947
1961
  const { model, dialect } = params;
1948
1962
  const rules = model.rowRules;
@@ -1954,7 +1968,7 @@ function validateRowRulesWithLookup(params) {
1954
1968
  const add = (params) => {
1955
1969
  issues.push({ rule: params.rule ?? "row-rule-invalid", model: model.name, ...params });
1956
1970
  };
1957
- const seenKinds = new Set;
1971
+ const firstOfKind = new Map;
1958
1972
  const seenDefinitions = new Set;
1959
1973
  const seenNames = new Set;
1960
1974
  for (const value of rules) {
@@ -1965,18 +1979,22 @@ function validateRowRulesWithLookup(params) {
1965
1979
  }
1966
1980
  const rule = value;
1967
1981
  const generated = rule.kind === "appendOnly" ? new Set : params.generatedFields({ model });
1968
- if (seenNames.has(rule.name))
1982
+ const first = rule.kind === "fixed" ? undefined : firstOfKind.get(rule.kind);
1983
+ if (first !== undefined && rule.kind !== "fixed")
1984
+ 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]}` });
1985
+ else if (seenNames.has(rule.name))
1969
1986
  add({ rule: "row-rule-name-collision", message: `Row rules share the physical stem ${rule.name}; supply an explicit, distinct name stem` });
1970
1987
  seenNames.add(rule.name);
1971
1988
  if (model.isView)
1972
1989
  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);
1990
+ if (rule.kind !== "fixed" && first === undefined)
1991
+ firstOfKind.set(rule.kind, rule.name);
1992
+ if (rule.kind === "fixed") {
1993
+ const definition = JSON.stringify([rule.kind, [...rule.columns].sort(), rule.when]);
1994
+ if (seenDefinitions.has(definition))
1995
+ add({ message: "Duplicate fixed row-rule declaration" });
1996
+ seenDefinitions.add(definition);
1997
+ }
1980
1998
  const pair = rowRuleObjectNames({ rule });
1981
1999
  const names = dialect === "postgres" ? [pair.functionName, pair.triggerName] : (rule.kind === "appendOnly" ? ["update", "delete"] : ["update"]).map((event) => rowRuleTriggerName({ rule, event }));
1982
2000
  for (const name of names) {
@@ -2011,7 +2029,7 @@ function validateRowRulesWithLookup(params) {
2011
2029
  if (rule.kind !== "appendOnly" && (rule.kind === "fixed" && rule.columns.length === 0 || protectedFieldsWithGenerated({ model, rule, generated }).length === 0))
2012
2030
  add({ message: `${rule.kind} requires at least one protected stored field` });
2013
2031
  }
2014
- if (seenKinds.has("appendOnly") && rules.length > 1)
2032
+ if (firstOfKind.has("appendOnly") && rules.length > 1)
2015
2033
  add({ message: "appendOnly cannot combine with other row rules; it already refuses every UPDATE and DELETE" });
2016
2034
  return issues;
2017
2035
  }
@@ -2837,7 +2855,11 @@ var RESERVED_ENUM_NAMES = [
2837
2855
  "TransactionOptions",
2838
2856
  "CallbackTransactionOptions",
2839
2857
  "RawStatement",
2858
+ "LazyRawExecuteOptions",
2859
+ "LazyRawQueryOptions",
2860
+ "QueueRawOptions",
2840
2861
  "AdvisoryLockOptions",
2862
+ "AdvisoryLocksOptions",
2841
2863
  "StatementDiagnosticsOptions",
2842
2864
  "SchemaIR",
2843
2865
  "VibeExtension",
@@ -2876,6 +2898,11 @@ var GENERATED_TYPE_NAMES = {
2876
2898
  "ScalarOrderByInput",
2877
2899
  "RelationOrderByInput",
2878
2900
  "RelationFindManyArgs",
2901
+ "RelationAggregateOrderByInput",
2902
+ "RelationAvgOrderByInput",
2903
+ "RelationSumOrderByInput",
2904
+ "RelationMinOrderByInput",
2905
+ "RelationMaxOrderByInput",
2879
2906
  "CreateInput",
2880
2907
  "UncheckedCreateInput",
2881
2908
  "CreateManyInput",
@@ -4535,4 +4562,4 @@ export {
4535
4562
  validatorRefIssue
4536
4563
  };
4537
4564
 
4538
- //# debugId=92D7E56C6E6AF7A964756E2164756E21
4565
+ //# debugId=B8429E15DEC34CA164756E2164756E21