@vibeorm/schema 5.9.0 → 5.10.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.
@@ -189,6 +189,17 @@ export type DialectCapabilities = {
189
189
  * can) and then writes it, inside the call's transaction.
190
190
  */
191
191
  readonly returningReadsJoinedSource: boolean;
192
+ /**
193
+ * `skipUnchanged: true` on `upsert` / `upsertMany`: a conflicting row whose
194
+ * every written column already holds the incoming value is not rewritten and
195
+ * keeps its `@updatedAt` stamp. PostgreSQL and SQLite put the comparison on
196
+ * the conflict arm's `WHERE`; MySQL's ON DUPLICATE KEY UPDATE has none, so
197
+ * the stamp's assignment goes first and keeps the stored stamp when the
198
+ * stored row equals the incoming one byte for byte (`IF(… <=> …, stamp, ?)`,
199
+ * assignments run left to right), and MySQL itself skips a row whose
200
+ * assignments change nothing. Without it `skipUnchanged` is refused.
201
+ */
202
+ readonly upsertSkipUnchanged: boolean;
192
203
  };
193
204
  export declare const POSTGRES_CAPABILITIES: DialectCapabilities;
194
205
  export declare const SQLITE_CAPABILITIES: DialectCapabilities;
@@ -37,4 +37,12 @@ export type ExclusionIR = {
37
37
  readonly normalizationSource?: string;
38
38
  readonly catalogDefinition?: true;
39
39
  };
40
+ /**
41
+ * The model fields an exclusion constraint compares, in declaration order: its
42
+ * keys' fields, then its range endpoints'. `undefined` when the constraint has
43
+ * no structured source (a definition read back from the catalog).
44
+ */
45
+ export declare function exclusionFields(params: {
46
+ readonly exclusion: ExclusionIR;
47
+ }): readonly string[] | undefined;
40
48
  //# sourceMappingURL=exclusion.d.ts.map
@@ -326,11 +326,6 @@ export declare function buildExtensionRegistry(params: {
326
326
  }): ExtensionRegistry;
327
327
  /** An empty registry — the default when no extensions are configured. */
328
328
  export declare const EMPTY_EXTENSION_REGISTRY: ExtensionRegistry;
329
- /** Whether built-in declarations establish public-only physical ownership for this model. */
330
- export declare function hasPublicExtensionDeclaration(params: {
331
- schema: SchemaIR;
332
- model: string;
333
- }): boolean;
334
329
  /** Refuse placement that built-in extension SQL and ownership cannot preserve. */
335
330
  export declare function assertExtensionModelPlacement(params: {
336
331
  namespace?: string;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * What kind of failure an error is, read from its `code` and `meta` alone:
3
+ * the answer a retry policy or an error report needs, without matching
4
+ * message text.
5
+ */
6
+ /**
7
+ * The closed set of `meta.reason` values a `VIBE_ADAPTER` error carries when
8
+ * the database could not be reached, the link died, the server is going away
9
+ * or no connection was free. Each such error also carries
10
+ * `meta.mayHaveReachedServer`: `false` only when the driver proves the
11
+ * statement was never sent, `true` otherwise.
12
+ */
13
+ export declare const CONNECTION_FAILURE_REASONS: readonly [
14
+ "connection-refused",
15
+ "connection-timeout",
16
+ "connection-lost",
17
+ "connection-not-writable",
18
+ "acquire-timeout",
19
+ "pool-exhausted",
20
+ "pool-closed",
21
+ "too-many-connections",
22
+ "server-shutdown"
23
+ ];
24
+ /** One member of {@link CONNECTION_FAILURE_REASONS}. */
25
+ export type ConnectionFailureReason = (typeof CONNECTION_FAILURE_REASONS)[number];
26
+ /** Whether `value` is one of {@link CONNECTION_FAILURE_REASONS}. */
27
+ export declare function isConnectionFailureReason(params: {
28
+ value: unknown;
29
+ }): boolean;
30
+ /**
31
+ * The kinds {@link failureKindOf} answers:
32
+ *
33
+ * - `"connection"`: the database could not be reached, the link died, the
34
+ * server is going away or no connection was free. `meta.reason` says which
35
+ * and `meta.mayHaveReachedServer` whether the statement can have run.
36
+ * - `"conflict"`: the engine rolled the transaction back to resolve a
37
+ * conflict with another one (deadlock, serialization failure, SQLite's busy
38
+ * database file). Running the whole transaction again is the remedy.
39
+ * - `"timeout"`: a statement or transaction deadline ran out and the work was
40
+ * cancelled before it committed.
41
+ * - `"constraint"`: the database refused the data: a unique, foreign-key,
42
+ * exclusion, CHECK or NOT NULL constraint, or a declared row rule. Retrying
43
+ * the same data fails the same way.
44
+ */
45
+ export declare const FAILURE_KINDS: readonly ["connection", "conflict", "timeout", "constraint"];
46
+ /** One member of {@link FAILURE_KINDS}. */
47
+ export type FailureKind = (typeof FAILURE_KINDS)[number];
48
+ /**
49
+ * The kind of failure `error` is, or `undefined` when it is none of
50
+ * {@link FAILURE_KINDS} (a bug, bad input caught before the database, a
51
+ * refusal by a restricted handle, a lock that was not available, a commit whose
52
+ * outcome is unknown). Read from the error's `code` and `meta` only, never from
53
+ * its message or its `cause`; an error that wraps a VibeORM error is not
54
+ * unwrapped. Any object with a VibeORM `code` and a `meta` object is read, so a
55
+ * second installed copy of `@vibeorm/schema` answers the same.
56
+ *
57
+ * It agrees with `transactionOutcomeOf`: `"conflict"` and `"timeout"` are
58
+ * failures that ended a transaction before it committed, and a `COMMIT` whose
59
+ * reply was lost is `VIBE_TRANSACTION` with `meta.reason:
60
+ * "transaction-outcome-unknown"`, which answers `undefined`. Decide a retry
61
+ * of a whole transaction from `transactionOutcomeOf`, of one statement from
62
+ * `meta.mayHaveReachedServer`.
63
+ *
64
+ * @example
65
+ * const kind = failureKindOf({ error });
66
+ * if (kind === "conflict") return runAgain();
67
+ * if (kind === "connection" && (error as VibeError).meta.mayHaveReachedServer === false) return retryLater();
68
+ */
69
+ export declare function failureKindOf(params: {
70
+ error: unknown;
71
+ }): FailureKind | undefined;
72
+ //# sourceMappingURL=failure-kind.d.ts.map
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export { assertGeneratedColumn, assertGeneratedColumns, generatedColumnFromSql,
18
18
  export type { DatabaseModuleOptions, DatabaseModuleManifest, DatabaseModuleArtifact } from "./database-module.ts";
19
19
  export { prepareDatabaseModuleSchema } from "./module-schema.ts";
20
20
  export type { ExclusionIR, ExclusionSpec, ExclusionKey, ExclusionEndpoint } from "./exclusion.ts";
21
+ export { exclusionFields } from "./exclusion.ts";
21
22
  export { DIALECTS, ENUM_STORAGES, enumStorageOf, fieldTypeIdentity, isEnumType, providerToDialect } from "./ir.ts";
22
23
  export type { CascadeAction, DatasourceIR, DefaultValueIR, Dialect, EnumIR, EnumStorage, ExtensionDeclIR, FieldIR, FieldType, JsonSchemaRefIR, ValidatorRefIR, IndexFieldIR, IndexKeyTermIR, CheckIR, IndexIR, IndexKind, ModelIR, Provider, RelationIR, RelationType, ScalarType, SchemaIR, TableStorageParameters, TableStorageValue, VacuumStorageParameters, } from "./ir.ts";
23
24
  export { PREDICATE_COMPARISON_OPS, assertPredicateCapabilities, inspectPredicate, inspectPredicateExpression, isPredicateFieldRef, predicateCapabilityIssue, predicateFieldNames, predicateKey } from "./predicate.ts";
@@ -35,6 +36,9 @@ export { isLocalDateField, isCanonicalLocalDate, localDateCheckName } from "./lo
35
36
  export { dialectCollation, isMysqlCollationName } from "./collation.ts";
36
37
  export { READ_ONLY_REFUSAL_REASONS, ReadOnlyClientError, SCOPED_REFUSAL_REASONS, ScopedQueryError, VIBE_ERROR_CODES, VibeError, internalError, invalidStoredData, unsupportedCapability, } from "./errors.ts";
37
38
  export type { ReadOnlyRefusalReason, ScopedRefusalReason, VibeErrorCode } from "./errors.ts";
39
+ export { CONNECTION_FAILURE_REASONS, FAILURE_KINDS, failureKindOf, isConnectionFailureReason } from "./failure-kind.ts";
40
+ export type { ConnectionFailureReason, FailureKind } from "./failure-kind.ts";
41
+ export { didYouMean, editDistance, isUnknownNameRefusal, suggestName, withSuggestion } from "./suggest.ts";
38
42
  export { decodePrismaString, encodePrismaString, exactDecimalLiteral, exactIntegerLiteral } from "./prisma-literal.ts";
39
43
  export { RESERVED_CLIENT_NAMES, RESERVED_DELEGATE_NAMES, isReservedClientName, isReservedDelegateName, } from "./reserved.ts";
40
44
  export { assertExtensionModelPlacement, assertExtensionPlacement, EMPTY_EXTENSION_REGISTRY, buildExtensionRegistry, defineExtension, extensionDeclarations, extensionManifestEntry, extensionOptionsHash, mergeExtensionDeclarations, } from "./extension.ts";
@@ -43,10 +47,14 @@ export { buildComputedManifest, validateComputedConfig } from "./computed.ts";
43
47
  export type { ComputedConfig, ComputedFieldSpec, ComputedManifestEntry } from "./computed.ts";
44
48
  export { RESERVED_ENUM_NAMES, assertValidSchemaIR, generatedTypeNames, validateSchemaIR } from "./validate.ts";
45
49
  export type { DisambiguatedTypeSuffix, GeneratedTypeNames, ValidationIssue } from "./validate.ts";
50
+ export { sealSchemaIR } from "./sealed.ts";
46
51
  export { implicitJoinTable } from "./m2m.ts";
47
52
  export type { ImplicitJoinTable } from "./m2m.ts";
48
53
  export { IDENTIFIER_LIMITS, assertIdentifierFits, defaultForeignKeyName, defaultIndexName, defaultExpressionIndexName, defaultPrimaryKeyName, fitDefaultName, identifierLength, implicitJoinTableObjectNames, postgresGeneratedObjectName, } from "./physical-names.ts";
49
54
  export type { IdentifierLimit, ImplicitJoinTableObjectNames } from "./physical-names.ts";
55
+ export { modelUniqueKeys } from "./unique-keys.ts";
56
+ export { normalizeWhere } from "./partial-predicate.ts";
57
+ export type { UniqueKeyIR } from "./unique-keys.ts";
50
58
  export type { NativeRlsIR, RlsContextFieldIR, RlsContextIR, RlsContextRefIR, RlsContextScalar, RlsPolicyIR } from "./ir.ts";
51
59
  export { DIALECT_CAPABILITIES, MYSQL_CAPABILITIES, POSTGRES_CAPABILITIES, SQLITE_CAPABILITIES } from "./capabilities.ts";
52
60
  export { RLS_CONTEXT_REASONS, RlsContextError } from "./errors.ts";