postgrelize 0.0.0-stage → 1.1.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/CHANGELOG.md +289 -0
- package/LICENSE +21 -0
- package/README.md +131 -2
- package/dist/associations/alias-minifier.d.ts +43 -0
- package/dist/associations/association-accessors.d.ts +21 -0
- package/dist/associations/association-key-types.d.ts +44 -0
- package/dist/associations/association-keys.d.ts +98 -0
- package/dist/associations/association-lookup.d.ts +26 -0
- package/dist/associations/association-shape.d.ts +25 -0
- package/dist/associations/association.d.ts +95 -0
- package/dist/associations/belongs-to-many.d.ts +86 -0
- package/dist/associations/belongs-to.d.ts +45 -0
- package/dist/associations/has-many.d.ts +79 -0
- package/dist/associations/has-one.d.ts +44 -0
- package/dist/associations/include-assembler.d.ts +21 -0
- package/dist/associations/include-columns.d.ts +24 -0
- package/dist/associations/include-joins.d.ts +17 -0
- package/dist/associations/include-loader.d.ts +48 -0
- package/dist/associations/include-order.d.ts +22 -0
- package/dist/associations/include-query-builder.d.ts +54 -0
- package/dist/associations/include-resolver.d.ts +29 -0
- package/dist/associations/include-rows.d.ts +47 -0
- package/dist/associations/include-sub-query.d.ts +35 -0
- package/dist/associations/include.d.ts +112 -0
- package/dist/associations/junction-keys.d.ts +23 -0
- package/dist/associations/nested-creator.d.ts +44 -0
- package/dist/associations/nested-saver.d.ts +30 -0
- package/dist/associations/owner-keys.d.ts +34 -0
- package/dist/associations/separate-include-loader.d.ts +24 -0
- package/dist/associations/types.d.ts +139 -0
- package/dist/connection/after-connect-hook.d.ts +24 -0
- package/dist/connection/connect-hooks.d.ts +26 -0
- package/dist/connection/connection-config.d.ts +33 -0
- package/dist/connection/connection-manager.d.ts +65 -0
- package/dist/connection/connection-types.d.ts +21 -0
- package/dist/connection/copy-from-stdin.d.ts +52 -0
- package/dist/connection/copy-runner.d.ts +30 -0
- package/dist/connection/copy-to-stdout.d.ts +49 -0
- package/dist/connection/copy.d.ts +22 -0
- package/dist/connection/notifications.d.ts +28 -0
- package/dist/connection/options.d.ts +165 -0
- package/dist/connection/query-logger.d.ts +41 -0
- package/dist/connection/replica-router.d.ts +20 -0
- package/dist/connection/statement-cache.d.ts +36 -0
- package/dist/connection/statement-timeout.d.ts +22 -0
- package/dist/data-types/abstract-data-type.d.ts +58 -0
- package/dist/data-types/array-literal-parser.d.ts +17 -0
- package/dist/data-types/array-type.d.ts +18 -0
- package/dist/data-types/bit-type.d.ts +14 -0
- package/dist/data-types/blob-type.d.ts +12 -0
- package/dist/data-types/char-type.d.ts +12 -0
- package/dist/data-types/composite-fields.d.ts +26 -0
- package/dist/data-types/composite-type.d.ts +32 -0
- package/dist/data-types/data-types.d.ts +176 -0
- package/dist/data-types/date-type.d.ts +14 -0
- package/dist/data-types/decimal-type.d.ts +13 -0
- package/dist/data-types/default-value-generator.d.ts +15 -0
- package/dist/data-types/enum-type.d.ts +19 -0
- package/dist/data-types/ewkb-reader.d.ts +18 -0
- package/dist/data-types/ewkb-writer.d.ts +17 -0
- package/dist/data-types/float-type.d.ts +12 -0
- package/dist/data-types/geometric-text.d.ts +65 -0
- package/dist/data-types/geometric-type.d.ts +46 -0
- package/dist/data-types/hstore-type.d.ts +16 -0
- package/dist/data-types/integer-type.d.ts +24 -0
- package/dist/data-types/json-type.d.ts +16 -0
- package/dist/data-types/multirange-type.d.ts +19 -0
- package/dist/data-types/range-type.d.ts +28 -0
- package/dist/data-types/record-text.d.ts +29 -0
- package/dist/data-types/scalar-type.d.ts +13 -0
- package/dist/data-types/spatial-type.d.ts +20 -0
- package/dist/data-types/string-type.d.ts +12 -0
- package/dist/data-types/text-type.d.ts +12 -0
- package/dist/data-types/timestamp-type.d.ts +15 -0
- package/dist/data-types/virtual-type.d.ts +15 -0
- package/dist/data-types/wall-clock.d.ts +14 -0
- package/dist/ddl/column-ddl.d.ts +73 -0
- package/dist/ddl/constraint-ddl.d.ts +30 -0
- package/dist/ddl/ddl-generator.d.ts +181 -0
- package/dist/ddl/ddl-guards.d.ts +60 -0
- package/dist/ddl/ddl-types.d.ts +204 -0
- package/dist/ddl/enum-ddl.d.ts +42 -0
- package/dist/ddl/extension-ddl.d.ts +57 -0
- package/dist/ddl/function-ddl.d.ts +98 -0
- package/dist/ddl/index-ddl.d.ts +29 -0
- package/dist/ddl/index-element-ddl.d.ts +19 -0
- package/dist/ddl/partition-ddl.d.ts +88 -0
- package/dist/ddl/partition-types.d.ts +94 -0
- package/dist/ddl/policy-ddl.d.ts +137 -0
- package/dist/ddl/routine-guards.d.ts +63 -0
- package/dist/ddl/sequence-ddl.d.ts +103 -0
- package/dist/ddl/sql-literal.d.ts +61 -0
- package/dist/ddl/table-ddl.d.ts +35 -0
- package/dist/ddl/trigger-ddl.d.ts +81 -0
- package/dist/ddl/view-ddl.d.ts +122 -0
- package/dist/decorators/association-applier.d.ts +18 -0
- package/dist/decorators/association-decorators.d.ts +72 -0
- package/dist/decorators/column-decorators.d.ts +147 -0
- package/dist/decorators/decorator-factory.d.ts +45 -0
- package/dist/decorators/decorator-signature.d.ts +26 -0
- package/dist/decorators/decorator-types.d.ts +24 -0
- package/dist/decorators/foreign-key-decorator.d.ts +21 -0
- package/dist/decorators/hook-decorators.d.ts +393 -0
- package/dist/decorators/init-arguments.d.ts +29 -0
- package/dist/decorators/model-decorators.d.ts +18 -0
- package/dist/decorators/model-metadata.d.ts +70 -0
- package/dist/decorators/table-decorators.d.ts +43 -0
- package/dist/decorators/timestamp-decorators.d.ts +38 -0
- package/dist/errors/base-error.d.ts +40 -0
- package/dist/errors/connection-errors.d.ts +152 -0
- package/dist/errors/database-errors.d.ts +186 -0
- package/dist/errors/errors.d.ts +5 -0
- package/dist/errors/map-pg-error.d.ts +27 -0
- package/dist/errors/misc-errors.d.ts +232 -0
- package/dist/errors/validation-errors.d.ts +141 -0
- package/dist/exports-associations.d.ts +6 -0
- package/dist/exports-core.d.ts +95 -0
- package/dist/exports-decorators.d.ts +8 -0
- package/dist/exports-errors.d.ts +2 -0
- package/dist/exports-model.d.ts +21 -0
- package/dist/exports-schema.d.ts +19 -0
- package/dist/expressions/call-expressions.d.ts +54 -0
- package/dist/expressions/condition-expressions.d.ts +51 -0
- package/dist/expressions/expression.d.ts +52 -0
- package/dist/expressions/jsonpath-helpers.d.ts +37 -0
- package/dist/expressions/logic.d.ts +25 -0
- package/dist/expressions/methods.d.ts +188 -0
- package/dist/expressions/op.d.ts +182 -0
- package/dist/expressions/query-expressions.d.ts +110 -0
- package/dist/expressions/row-expressions.d.ts +35 -0
- package/dist/expressions/search-helpers.d.ts +138 -0
- package/dist/expressions/trigram-helpers.d.ts +40 -0
- package/dist/hooks/hooks.d.ts +125 -0
- package/dist/index.cjs +21864 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +21688 -0
- package/dist/index.js.map +1 -0
- package/dist/model/attribute-columns.d.ts +85 -0
- package/dist/model/attribute-normalizer.d.ts +42 -0
- package/dist/model/attribute-options.d.ts +121 -0
- package/dist/model/bulk-insert-builder.d.ts +24 -0
- package/dist/model/bulk-options.d.ts +173 -0
- package/dist/model/copy-options.d.ts +51 -0
- package/dist/model/cte-builder.d.ts +134 -0
- package/dist/model/definition-normalizer.d.ts +26 -0
- package/dist/model/delete-query-builder.d.ts +42 -0
- package/dist/model/find-options.d.ts +144 -0
- package/dist/model/find-query-builder.d.ts +38 -0
- package/dist/model/inflector.d.ts +28 -0
- package/dist/model/insert-query-builder.d.ts +41 -0
- package/dist/model/instance-destroyer.d.ts +44 -0
- package/dist/model/instance-lifecycle-services.d.ts +61 -0
- package/dist/model/instance-lifecycle.d.ts +128 -0
- package/dist/model/instance-saver.d.ts +25 -0
- package/dist/model/instance-state.d.ts +48 -0
- package/dist/model/instance-validation.d.ts +35 -0
- package/dist/model/instance-values.d.ts +88 -0
- package/dist/model/instance-writer.d.ts +59 -0
- package/dist/model/join-source-builder.d.ts +25 -0
- package/dist/model/lateral-keys-builder.d.ts +25 -0
- package/dist/model/merge-action-builder.d.ts +31 -0
- package/dist/model/merge-options.d.ts +72 -0
- package/dist/model/merge-query-builder.d.ts +29 -0
- package/dist/model/merge-source-builder.d.ts +22 -0
- package/dist/model/mixins/model-aggregates.d.ts +69 -0
- package/dist/model/mixins/model-associations.d.ts +113 -0
- package/dist/model/mixins/model-constructor.d.ts +7 -0
- package/dist/model/mixins/model-finders.d.ts +140 -0
- package/dist/model/mixins/model-hooks.d.ts +142 -0
- package/dist/model/mixins/model-postgres.d.ts +198 -0
- package/dist/model/mixins/model-schema-binding.d.ts +36 -0
- package/dist/model/mixins/model-schema.d.ts +100 -0
- package/dist/model/mixins/model-scopes.d.ts +57 -0
- package/dist/model/mixins/model-writers.d.ts +175 -0
- package/dist/model/mixins/named-hooks.d.ts +28 -0
- package/dist/model/model-accessors.d.ts +22 -0
- package/dist/model/model-base.d.ts +83 -0
- package/dist/model/model-definition.d.ts +130 -0
- package/dist/model/model-instance-persistence.d.ts +132 -0
- package/dist/model/model-instance-values.d.ts +197 -0
- package/dist/model/model-operations.d.ts +22 -0
- package/dist/model/model-registry.d.ts +152 -0
- package/dist/model/model-services.d.ts +46 -0
- package/dist/model/model-state.d.ts +68 -0
- package/dist/model/model-values.d.ts +86 -0
- package/dist/model/model.d.ts +629 -0
- package/dist/model/on-conflict-builder.d.ts +111 -0
- package/dist/model/operations/bulk-create-operation.d.ts +40 -0
- package/dist/model/operations/copy-from-source.d.ts +51 -0
- package/dist/model/operations/copy-operation.d.ts +54 -0
- package/dist/model/operations/count-operation.d.ts +52 -0
- package/dist/model/operations/create-operation.d.ts +31 -0
- package/dist/model/operations/destroy-operation.d.ts +65 -0
- package/dist/model/operations/find-cursor.d.ts +23 -0
- package/dist/model/operations/find-lookups.d.ts +99 -0
- package/dist/model/operations/find-operation.d.ts +47 -0
- package/dist/model/operations/increment-operation.d.ts +40 -0
- package/dist/model/operations/insert-operation.d.ts +71 -0
- package/dist/model/operations/merge-operation.d.ts +56 -0
- package/dist/model/operations/model-operation.d.ts +33 -0
- package/dist/model/operations/update-operation.d.ts +45 -0
- package/dist/model/operations/upsert-operation.d.ts +39 -0
- package/dist/model/options.d.ts +103 -0
- package/dist/model/returning-old.d.ts +52 -0
- package/dist/model/row-mapper.d.ts +78 -0
- package/dist/model/row-plan.d.ts +31 -0
- package/dist/model/runtime.d.ts +56 -0
- package/dist/model/scope-registry.d.ts +81 -0
- package/dist/model/select-aggregates.d.ts +37 -0
- package/dist/model/select-lock.d.ts +13 -0
- package/dist/model/select-options.d.ts +92 -0
- package/dist/model/select-query-builder.d.ts +73 -0
- package/dist/model/select-targets.d.ts +77 -0
- package/dist/model/source-option-builder.d.ts +23 -0
- package/dist/model/source-options.d.ts +108 -0
- package/dist/model/statement-builder.d.ts +77 -0
- package/dist/model/statement-services.d.ts +2 -0
- package/dist/model/sync-hooks.d.ts +18 -0
- package/dist/model/table-sample-builder.d.ts +13 -0
- package/dist/model/types.d.ts +85 -0
- package/dist/model/unnest-insert-builder.d.ts +24 -0
- package/dist/model/update-query-builder.d.ts +39 -0
- package/dist/model/v6-conflict-builder.d.ts +37 -0
- package/dist/model/value-cloner.d.ts +17 -0
- package/dist/model/values-writer.d.ts +12 -0
- package/dist/model/where-options.d.ts +164 -0
- package/dist/model/write-options.d.ts +160 -0
- package/dist/model/written-rows.d.ts +56 -0
- package/dist/package-version.d.ts +8 -0
- package/dist/query/query-result-shaper.d.ts +93 -0
- package/dist/query/raw-query.d.ts +27 -0
- package/dist/query-interface/alter-planner.d.ts +40 -0
- package/dist/query-interface/bulk-data.d.ts +44 -0
- package/dist/query-interface/column-commands.d.ts +52 -0
- package/dist/query-interface/column-describer.d.ts +17 -0
- package/dist/query-interface/enum-commands.d.ts +36 -0
- package/dist/query-interface/index-commands.d.ts +57 -0
- package/dist/query-interface/model-tables.d.ts +58 -0
- package/dist/query-interface/object-commands.d.ts +71 -0
- package/dist/query-interface/partition-commands.d.ts +43 -0
- package/dist/query-interface/policy-commands.d.ts +54 -0
- package/dist/query-interface/query-interface-catalog.d.ts +180 -0
- package/dist/query-interface/query-interface-objects.d.ts +108 -0
- package/dist/query-interface/query-interface-partitions.d.ts +66 -0
- package/dist/query-interface/query-interface-policies.d.ts +86 -0
- package/dist/query-interface/query-interface-routines.d.ts +120 -0
- package/dist/query-interface/query-interface-tables.d.ts +179 -0
- package/dist/query-interface/query-interface-types.d.ts +62 -0
- package/dist/query-interface/query-interface-views.d.ts +84 -0
- package/dist/query-interface/query-interface.d.ts +256 -0
- package/dist/query-interface/routine-commands.d.ts +71 -0
- package/dist/query-interface/schema-synchronizer.d.ts +110 -0
- package/dist/query-interface/statement-runner.d.ts +40 -0
- package/dist/query-interface/sync-planner.d.ts +26 -0
- package/dist/query-interface/table-commands.d.ts +63 -0
- package/dist/query-interface/table-introspector.d.ts +58 -0
- package/dist/query-interface/view-commands.d.ts +47 -0
- package/dist/sequelize/instance-hook-adders.d.ts +72 -0
- package/dist/sequelize/sequelize-base.d.ts +196 -0
- package/dist/sequelize/sequelize-constructor.d.ts +7 -0
- package/dist/sequelize/sequelize-helpers.d.ts +133 -0
- package/dist/sequelize/sequelize-hooks.d.ts +99 -0
- package/dist/sequelize/sequelize-internals.d.ts +87 -0
- package/dist/sequelize/sequelize-notifications.d.ts +66 -0
- package/dist/sequelize/sequelize-schema.d.ts +125 -0
- package/dist/sequelize/sequelize-transactions.d.ts +96 -0
- package/dist/sequelize.d.ts +1175 -0
- package/dist/sql/ast-clauses.d.ts +137 -0
- package/dist/sql/ast-expressions.d.ts +88 -0
- package/dist/sql/ast-statements.d.ts +80 -0
- package/dist/sql/ast.d.ts +21 -0
- package/dist/sql/compile.d.ts +21 -0
- package/dist/sql/dml-compiler.d.ts +54 -0
- package/dist/sql/expression-compiler.d.ts +56 -0
- package/dist/sql/from-compiler.d.ts +39 -0
- package/dist/sql/identifier-quoter.d.ts +15 -0
- package/dist/sql/merge-compiler.d.ts +20 -0
- package/dist/sql/order.d.ts +15 -0
- package/dist/sql/query-compiler.d.ts +45 -0
- package/dist/sql/sql-chunks.d.ts +50 -0
- package/dist/sql/with-compiler.d.ts +19 -0
- package/dist/transaction/advisory-locks.d.ts +28 -0
- package/dist/transaction/cls-namespace.d.ts +44 -0
- package/dist/transaction/transaction-constants.d.ts +35 -0
- package/dist/transaction/transaction-runner.d.ts +78 -0
- package/dist/transaction/transaction-starter.d.ts +25 -0
- package/dist/transaction/transaction-statements.d.ts +29 -0
- package/dist/transaction/transaction.d.ts +201 -0
- package/dist/validation/attribute-validators.d.ts +23 -0
- package/dist/validation/builtin-attribute-validator.d.ts +19 -0
- package/dist/validation/builtin-validators.d.ts +16 -0
- package/dist/validation/core-validator.d.ts +16 -0
- package/dist/validation/custom-validators.d.ts +13 -0
- package/dist/validation/instance-validator.d.ts +25 -0
- package/dist/validation/schema-items.d.ts +22 -0
- package/dist/validation/standard-schema-validator.d.ts +30 -0
- package/dist/validation/standard-schema.d.ts +39 -0
- package/dist/validation/types.d.ts +36 -0
- package/dist/validation/validation-target.d.ts +13 -0
- package/dist/where/comparison-compiler.d.ts +27 -0
- package/dist/where/condition-compiler.d.ts +18 -0
- package/dist/where/operand-resolver.d.ts +10 -0
- package/dist/where/operator-allowlist.d.ts +14 -0
- package/dist/where/where-support.d.ts +52 -0
- package/dist/where/where.d.ts +46 -0
- package/dist/where/window-compiler.d.ts +14 -0
- package/llm/USAGE.md +423 -0
- package/package.json +103 -4
- package/skills/postgrelize/SKILL.md +57 -0
- package/skills/postgrelize/reference/associations.md +108 -0
- package/skills/postgrelize/reference/errors.md +37 -0
- package/skills/postgrelize/reference/migrating-from-sequelize.md +15 -0
- package/skills/postgrelize/reference/postgresql-features.md +157 -0
- package/skills/postgrelize/reference/querying.md +111 -0
- package/skills/postgrelize/reference/schema.md +135 -0
- package/skills/postgrelize/reference/security.md +34 -0
- package/skills/postgrelize/reference/transactions-and-sessions.md +122 -0
- package/skills/postgrelize/reference/writing.md +198 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ConnectionManager, ExecuteOptions } from '../connection/connection-manager.ts';
|
|
2
|
+
/** Advisory lock key: a 64-bit integer, or a string hashed by PostgreSQL. */
|
|
3
|
+
export type AdvisoryLockKey = number | bigint | string;
|
|
4
|
+
/** Transaction-level advisory locks taken on the connection of one transaction. */
|
|
5
|
+
export declare class AdvisoryLocks {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* @param connections - Connection manager running the lock statements.
|
|
9
|
+
* @param executeOptions - Execute options bound to the owning transaction.
|
|
10
|
+
*/
|
|
11
|
+
constructor(connections: ConnectionManager, executeOptions: () => ExecuteOptions);
|
|
12
|
+
/**
|
|
13
|
+
* Waits for and takes the lock.
|
|
14
|
+
*
|
|
15
|
+
* @param key - Lock key.
|
|
16
|
+
* @param shared - Take a shared lock.
|
|
17
|
+
* @returns Resolves when the lock is held.
|
|
18
|
+
*/
|
|
19
|
+
lock(key: AdvisoryLockKey, shared: boolean): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Tries to take the lock without waiting.
|
|
22
|
+
*
|
|
23
|
+
* @param key - Lock key.
|
|
24
|
+
* @param shared - Take a shared lock.
|
|
25
|
+
* @returns True when the lock was acquired.
|
|
26
|
+
*/
|
|
27
|
+
tryLock(key: AdvisoryLockKey, shared: boolean): Promise<boolean>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Transaction } from './transaction.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Continuation-local namespace in the shape of `cls-hooked` / `continuation-local-storage`
|
|
4
|
+
* (the namespace passed to Sequelize v6 `useCLS`). Only these members are used.
|
|
5
|
+
*/
|
|
6
|
+
export type ClsNamespace = Readonly<{
|
|
7
|
+
bind: (...args: never[]) => unknown;
|
|
8
|
+
run: (callback: (context?: unknown) => unknown) => unknown;
|
|
9
|
+
get: (key: string) => unknown;
|
|
10
|
+
set: (key: string, value: unknown) => unknown;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Keeps the current transaction under the `transaction` key of a CLS namespace, as Sequelize v6 does:
|
|
14
|
+
* managed transactions run in `namespace.run` and set the key, queries without a `transaction` option
|
|
15
|
+
* read it, and finishing a transaction clears it. Project code can also place a transaction there.
|
|
16
|
+
*/
|
|
17
|
+
export declare class NamespaceContext {
|
|
18
|
+
#private;
|
|
19
|
+
/**
|
|
20
|
+
* @param namespace - Namespace given to `Sequelize.useCLS`.
|
|
21
|
+
* @throws Error when it is not a CLS namespace (has no `bind` and `run`), like v6.
|
|
22
|
+
*/
|
|
23
|
+
constructor(namespace: unknown);
|
|
24
|
+
/**
|
|
25
|
+
* Transaction stored in the namespace of the current context.
|
|
26
|
+
*
|
|
27
|
+
* @returns The transaction, or `undefined` when none is stored (or it was cleared).
|
|
28
|
+
*/
|
|
29
|
+
current(): Transaction | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Runs `run` in a new namespace context with `transaction` stored in it.
|
|
32
|
+
*
|
|
33
|
+
* @param transaction - Transaction to store.
|
|
34
|
+
* @param run - Callback.
|
|
35
|
+
* @returns Result of `run`.
|
|
36
|
+
*/
|
|
37
|
+
run<T>(transaction: Transaction, run: () => Promise<T>): Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Clears the stored transaction when it is the one that finished (not for savepoints, as in v6).
|
|
40
|
+
*
|
|
41
|
+
* @param transaction - Finished transaction.
|
|
42
|
+
*/
|
|
43
|
+
release(transaction: Transaction): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Transaction isolation levels (Sequelize v6 `Transaction.ISOLATION_LEVELS`). */
|
|
2
|
+
export declare const ISOLATION_LEVELS: {
|
|
3
|
+
/** `READ UNCOMMITTED` (behaves as `READ COMMITTED` in PostgreSQL). */
|
|
4
|
+
readonly READ_UNCOMMITTED: "READ UNCOMMITTED";
|
|
5
|
+
/** `READ COMMITTED` (PostgreSQL default). */
|
|
6
|
+
readonly READ_COMMITTED: "READ COMMITTED";
|
|
7
|
+
/** `REPEATABLE READ`. */
|
|
8
|
+
readonly REPEATABLE_READ: "REPEATABLE READ";
|
|
9
|
+
/** `SERIALIZABLE`. */
|
|
10
|
+
readonly SERIALIZABLE: "SERIALIZABLE";
|
|
11
|
+
};
|
|
12
|
+
/** One of {@link ISOLATION_LEVELS}. */
|
|
13
|
+
export type IsolationLevel = (typeof ISOLATION_LEVELS)[keyof typeof ISOLATION_LEVELS];
|
|
14
|
+
/** Row lock strengths for `findAll({ lock })` (Sequelize v6 `Transaction.LOCK`). */
|
|
15
|
+
export declare const LOCK: {
|
|
16
|
+
/** `FOR UPDATE`. */
|
|
17
|
+
readonly UPDATE: "UPDATE";
|
|
18
|
+
/** `FOR SHARE`. */
|
|
19
|
+
readonly SHARE: "SHARE";
|
|
20
|
+
/** `FOR KEY SHARE`. */
|
|
21
|
+
readonly KEY_SHARE: "KEY SHARE";
|
|
22
|
+
/** `FOR NO KEY UPDATE`. */
|
|
23
|
+
readonly NO_KEY_UPDATE: "NO KEY UPDATE";
|
|
24
|
+
};
|
|
25
|
+
/** One of {@link LOCK}. */
|
|
26
|
+
export type LockStrength = (typeof LOCK)[keyof typeof LOCK];
|
|
27
|
+
/** Transaction types; accepted for Sequelize v6 compatibility and ignored by PostgreSQL. */
|
|
28
|
+
export declare const TRANSACTION_TYPES: {
|
|
29
|
+
/** SQLite-only, ignored. */
|
|
30
|
+
readonly DEFERRED: "DEFERRED";
|
|
31
|
+
/** SQLite-only, ignored. */
|
|
32
|
+
readonly IMMEDIATE: "IMMEDIATE";
|
|
33
|
+
/** SQLite-only, ignored. */
|
|
34
|
+
readonly EXCLUSIVE: "EXCLUSIVE";
|
|
35
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Transaction } from './transaction.ts';
|
|
2
|
+
/** Continuation-local storage of the current transaction (`AsyncLocalStorage`, used by `Sequelize.useCLS`). */
|
|
3
|
+
export declare class TransactionContext {
|
|
4
|
+
#private;
|
|
5
|
+
/**
|
|
6
|
+
* Transaction of the current async context.
|
|
7
|
+
*
|
|
8
|
+
* @returns The transaction, or `undefined` outside `run`.
|
|
9
|
+
*/
|
|
10
|
+
current(): Transaction | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Runs `run` with `transaction` as the current transaction.
|
|
13
|
+
*
|
|
14
|
+
* @param transaction - Transaction to make current.
|
|
15
|
+
* @param run - Callback.
|
|
16
|
+
* @returns Result of `run`.
|
|
17
|
+
*/
|
|
18
|
+
run<T>(transaction: Transaction, run: () => Promise<T>): Promise<T>;
|
|
19
|
+
}
|
|
20
|
+
/** Runs managed transactions: begins, runs the callback, commits on success and rolls back on error. */
|
|
21
|
+
export declare class TransactionRunner {
|
|
22
|
+
#private;
|
|
23
|
+
/**
|
|
24
|
+
* @param context - Context the transaction is made current in while the callback runs.
|
|
25
|
+
*/
|
|
26
|
+
constructor(context: Pick<TransactionContext, 'run'>);
|
|
27
|
+
/**
|
|
28
|
+
* Runs `run` inside `transaction`.
|
|
29
|
+
*
|
|
30
|
+
* @param transaction - Transaction, not started yet.
|
|
31
|
+
* @param run - Callback receiving the transaction.
|
|
32
|
+
* @returns Result of `run`.
|
|
33
|
+
*/
|
|
34
|
+
run<T>(transaction: Transaction, run: (transaction: Transaction) => Promise<T>): Promise<T>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Transaction scope shared by every `Sequelize` instance: the `useCLS` switch, the current
|
|
38
|
+
* transaction of the async context and the managed-transaction runner.
|
|
39
|
+
*/
|
|
40
|
+
export declare class TransactionScope {
|
|
41
|
+
#private;
|
|
42
|
+
/**
|
|
43
|
+
* Enables continuation-local transactions.
|
|
44
|
+
*
|
|
45
|
+
* @param namespace - CLS namespace (v6 style); `AsyncLocalStorage` is used without one.
|
|
46
|
+
* @throws Error when `namespace` is given but is not a CLS namespace.
|
|
47
|
+
*/
|
|
48
|
+
enableCls(namespace?: unknown): void;
|
|
49
|
+
/**
|
|
50
|
+
* Transaction that queries without a `transaction` option use.
|
|
51
|
+
*
|
|
52
|
+
* @returns The transaction, or `undefined` when CLS is off or outside a managed transaction.
|
|
53
|
+
*/
|
|
54
|
+
active(): Transaction | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Parent of a new transaction started without `transaction`: with `AsyncLocalStorage` CLS the
|
|
57
|
+
* enclosing managed transaction (savepoint); with a v6 namespace none, as in v6.
|
|
58
|
+
*
|
|
59
|
+
* @returns The enclosing transaction, if any.
|
|
60
|
+
*/
|
|
61
|
+
implicitParent(): Transaction | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Called when a transaction releases its connection.
|
|
64
|
+
*
|
|
65
|
+
* @param transaction - Finished transaction.
|
|
66
|
+
*/
|
|
67
|
+
release(transaction: Transaction): void;
|
|
68
|
+
/**
|
|
69
|
+
* Runs `run` inside `transaction`, committing or rolling back.
|
|
70
|
+
*
|
|
71
|
+
* @param transaction - Transaction, not started yet.
|
|
72
|
+
* @param run - Callback receiving the transaction.
|
|
73
|
+
* @returns Result of `run`.
|
|
74
|
+
*/
|
|
75
|
+
run<T>(transaction: Transaction, run: (transaction: Transaction) => Promise<T>): Promise<T>;
|
|
76
|
+
}
|
|
77
|
+
/** The scope used by all `Sequelize` instances. */
|
|
78
|
+
export declare const transactionScope: TransactionScope;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ConnectionManager } from '../connection/connection-manager.ts';
|
|
2
|
+
import { Transaction, TransactionOptions } from './transaction.ts';
|
|
3
|
+
/** Creates transactions on a connection manager, nesting them in the CLS transaction when enabled. */
|
|
4
|
+
export declare class TransactionStarter {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* @param connections - Connection manager of the owning `Sequelize` instance.
|
|
8
|
+
*/
|
|
9
|
+
constructor(connections: ConnectionManager);
|
|
10
|
+
/**
|
|
11
|
+
* Starts an unmanaged transaction.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Transaction options.
|
|
14
|
+
* @returns Started transaction.
|
|
15
|
+
*/
|
|
16
|
+
begin(options: TransactionOptions): Promise<Transaction>;
|
|
17
|
+
/**
|
|
18
|
+
* Runs `run` in a managed transaction: committed on success, rolled back on error.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Transaction options.
|
|
21
|
+
* @param run - Callback receiving the transaction.
|
|
22
|
+
* @returns Result of `run`.
|
|
23
|
+
*/
|
|
24
|
+
managed<T>(options: TransactionOptions, run: (transaction: Transaction) => Promise<T>): Promise<T>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DeferrableValue } from '../ddl/ddl-types.ts';
|
|
2
|
+
import { IsolationLevel } from './transaction-constants.ts';
|
|
3
|
+
/** SQL statements that start and finish a transaction, or a savepoint when it is nested. */
|
|
4
|
+
export declare class TransactionStatements {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* @param id - Transaction id, quoted as the savepoint name.
|
|
8
|
+
* @param nested - Whether the transaction is a savepoint inside a parent transaction.
|
|
9
|
+
*/
|
|
10
|
+
constructor(id: string, nested: boolean);
|
|
11
|
+
/**
|
|
12
|
+
* @param options - Isolation level, access mode and deferrable mode of a top-level transaction.
|
|
13
|
+
* @returns `START TRANSACTION …`, or `SAVEPOINT …` when nested.
|
|
14
|
+
* @throws Error for an isolation level outside the allowlist or a non-boolean `deferrable`.
|
|
15
|
+
*/
|
|
16
|
+
begin(options: Readonly<{
|
|
17
|
+
isolationLevel?: IsolationLevel;
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
deferrable?: boolean | DeferrableValue;
|
|
20
|
+
}>): string;
|
|
21
|
+
/**
|
|
22
|
+
* @returns `COMMIT`, or `RELEASE SAVEPOINT …` when nested.
|
|
23
|
+
*/
|
|
24
|
+
commit(): string;
|
|
25
|
+
/**
|
|
26
|
+
* @returns `ROLLBACK`, or `ROLLBACK TO SAVEPOINT …` when nested.
|
|
27
|
+
*/
|
|
28
|
+
rollback(): string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Client, ConnectionManager, ExecuteOptions } from '../connection/connection-manager.ts';
|
|
2
|
+
import { LoggingFunction } from '../connection/options.ts';
|
|
3
|
+
import { DeferrableValue } from '../ddl/ddl-types.ts';
|
|
4
|
+
import { AdvisoryLockKey } from './advisory-locks.ts';
|
|
5
|
+
import { LOCK, TRANSACTION_TYPES, IsolationLevel } from './transaction-constants.ts';
|
|
6
|
+
export { ISOLATION_LEVELS, LOCK, TRANSACTION_TYPES } from './transaction-constants.ts';
|
|
7
|
+
export type { AdvisoryLockKey } from './advisory-locks.ts';
|
|
8
|
+
export type { IsolationLevel, LockStrength } from './transaction-constants.ts';
|
|
9
|
+
/**
|
|
10
|
+
* Options of `sequelize.transaction()`.
|
|
11
|
+
*
|
|
12
|
+
* All fields are optional.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const options: TransactionOptions = {
|
|
17
|
+
* isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE,
|
|
18
|
+
* readOnly: true,
|
|
19
|
+
* deferrable: true,
|
|
20
|
+
* settings: { 'app.user_id': '42', statement_timeout: '5s' },
|
|
21
|
+
* };
|
|
22
|
+
* const t = await sequelize.transaction(options);
|
|
23
|
+
* await t.commit();
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type TransactionOptions = Readonly<{
|
|
27
|
+
/** Isolation level of a new transaction. */
|
|
28
|
+
isolationLevel?: IsolationLevel;
|
|
29
|
+
/** Accepted for compatibility, ignored. */
|
|
30
|
+
type?: (typeof TRANSACTION_TYPES)[keyof typeof TRANSACTION_TYPES];
|
|
31
|
+
/** Start `READ ONLY`. PostgreSQL extension. */
|
|
32
|
+
readOnly?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* `true` / `false`: start `DEFERRABLE` / `NOT DEFERRABLE`. PostgreSQL honours it only for
|
|
35
|
+
* `SERIALIZABLE READ ONLY` transactions: a deferrable one waits for a safe snapshot and then runs
|
|
36
|
+
* without serialization failures; ignored for savepoints (PostgreSQL extension).
|
|
37
|
+
* `Deferrable.SET_DEFERRED` / `Deferrable.SET_IMMEDIATE` (Sequelize v6): run `SET CONSTRAINTS ... DEFERRED` /
|
|
38
|
+
* `IMMEDIATE` right after the transaction starts, for all constraints or the names given.
|
|
39
|
+
*/
|
|
40
|
+
deferrable?: boolean | DeferrableValue;
|
|
41
|
+
/** Parent transaction: the new transaction becomes a savepoint inside it. */
|
|
42
|
+
transaction?: Transaction | null;
|
|
43
|
+
/**
|
|
44
|
+
* Session settings applied with `SET LOCAL` semantics (`set_config(name, value, true)`), e.g.
|
|
45
|
+
* `{ 'app.user_id': '42', statement_timeout: '5s' }` for row-level security. PostgreSQL extension.
|
|
46
|
+
*/
|
|
47
|
+
settings?: Readonly<Record<string, string | number | boolean>>;
|
|
48
|
+
/** SQL logger for transaction statements. */
|
|
49
|
+
logging?: LoggingFunction | false;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Handle of an open database transaction or savepoint (Sequelize v6 `Transaction`).
|
|
53
|
+
*
|
|
54
|
+
* Obtain one from `sequelize.transaction()` and pass it to queries with the `transaction` option.
|
|
55
|
+
* Unmanaged transactions must be finished with {@link Transaction.commit} or
|
|
56
|
+
* {@link Transaction.rollback}; the connection is released to the pool when that happens.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const t = await sequelize.transaction();
|
|
61
|
+
* try {
|
|
62
|
+
* const created = await User.create({ name: 'Ann' }, { transaction: t });
|
|
63
|
+
* await Post.create({ title: 'Hi', userId: created.id }, { transaction: t });
|
|
64
|
+
* await t.commit();
|
|
65
|
+
* } catch (e) {
|
|
66
|
+
* await t.rollback();
|
|
67
|
+
* throw e;
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare class Transaction {
|
|
72
|
+
#private;
|
|
73
|
+
/** Values for the `isolationLevel` option, e.g. `SERIALIZABLE` or `READ_COMMITTED`. */
|
|
74
|
+
static readonly ISOLATION_LEVELS: {
|
|
75
|
+
readonly READ_UNCOMMITTED: "READ UNCOMMITTED";
|
|
76
|
+
readonly READ_COMMITTED: "READ COMMITTED";
|
|
77
|
+
readonly REPEATABLE_READ: "REPEATABLE READ";
|
|
78
|
+
readonly SERIALIZABLE: "SERIALIZABLE";
|
|
79
|
+
};
|
|
80
|
+
/** Row lock strengths. */
|
|
81
|
+
static readonly LOCK: {
|
|
82
|
+
readonly UPDATE: "UPDATE";
|
|
83
|
+
readonly SHARE: "SHARE";
|
|
84
|
+
readonly KEY_SHARE: "KEY SHARE";
|
|
85
|
+
readonly NO_KEY_UPDATE: "NO KEY UPDATE";
|
|
86
|
+
};
|
|
87
|
+
/** Transaction types (ignored by PostgreSQL). */
|
|
88
|
+
static readonly TYPES: {
|
|
89
|
+
readonly DEFERRED: "DEFERRED";
|
|
90
|
+
readonly IMMEDIATE: "IMMEDIATE";
|
|
91
|
+
readonly EXCLUSIVE: "EXCLUSIVE";
|
|
92
|
+
};
|
|
93
|
+
/** Unique id, used in SQL logs and as savepoint name. */
|
|
94
|
+
readonly id: string;
|
|
95
|
+
/** Options the transaction was started with. */
|
|
96
|
+
readonly options: TransactionOptions;
|
|
97
|
+
/** Parent transaction when this one is a savepoint. */
|
|
98
|
+
readonly parent: Transaction | undefined;
|
|
99
|
+
/** `'commit'` or `'rollback'` once the transaction is finished. */
|
|
100
|
+
finished: 'commit' | 'rollback' | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Creates an unstarted transaction; use `sequelize.transaction()` instead of calling this directly.
|
|
103
|
+
*
|
|
104
|
+
* @param connections - Connection manager of the owning `Sequelize` instance.
|
|
105
|
+
* @param options - Transaction options.
|
|
106
|
+
*/
|
|
107
|
+
constructor(connections: ConnectionManager, options?: TransactionOptions);
|
|
108
|
+
/** Row lock strengths (instance alias of {@link Transaction.LOCK}). */
|
|
109
|
+
get LOCK(): typeof LOCK;
|
|
110
|
+
/** @internal */
|
|
111
|
+
get client(): Client;
|
|
112
|
+
/** @internal */
|
|
113
|
+
executeOptions(): ExecuteOptions;
|
|
114
|
+
/** @internal */
|
|
115
|
+
begin(): Promise<this>;
|
|
116
|
+
/**
|
|
117
|
+
* Commits the transaction (or releases the savepoint) and runs `afterCommit` hooks.
|
|
118
|
+
*
|
|
119
|
+
* @returns Resolves when committed and all `afterCommit` hooks have run.
|
|
120
|
+
* @throws Error when the transaction is already finished.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const t = await sequelize.transaction();
|
|
125
|
+
* await User.create({ name: 'Ann' }, { transaction: t });
|
|
126
|
+
* await t.commit();
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
commit(): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Rolls the transaction back (or rolls back to the savepoint).
|
|
132
|
+
*
|
|
133
|
+
* @returns Resolves when rolled back.
|
|
134
|
+
* @throws Error when the transaction is already finished.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const t = await sequelize.transaction();
|
|
139
|
+
* try {
|
|
140
|
+
* await User.create({ name: 'Ann' }, { transaction: t });
|
|
141
|
+
* await t.commit();
|
|
142
|
+
* } catch (e) {
|
|
143
|
+
* await t.rollback();
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
rollback(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Takes a transaction-level advisory lock (`pg_advisory_xact_lock`), waiting until it is free.
|
|
150
|
+
* The lock is released on commit or rollback. PostgreSQL extension.
|
|
151
|
+
*
|
|
152
|
+
* @param key - Integer key, or a string hashed with `hashtextextended`.
|
|
153
|
+
* @param options - `shared: true` for a shared lock.
|
|
154
|
+
* @returns Resolves when the lock is held.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* await sequelize.transaction(async (t) => {
|
|
159
|
+
* await t.advisoryLock('invoice-42');
|
|
160
|
+
* await Invoice.update({ status: 'sent' }, { where: { id: 42 }, transaction: t });
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
advisoryLock(key: AdvisoryLockKey, options?: Readonly<{
|
|
165
|
+
shared?: boolean;
|
|
166
|
+
}>): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Tries to take a transaction-level advisory lock without waiting. PostgreSQL extension.
|
|
169
|
+
*
|
|
170
|
+
* @param key - Integer key, or a string hashed with `hashtextextended`.
|
|
171
|
+
* @param options - `shared: true` for a shared lock.
|
|
172
|
+
* @returns True when the lock was acquired.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* await sequelize.transaction(async (t) => {
|
|
177
|
+
* if (await t.tryAdvisoryLock(42, { shared: true })) {
|
|
178
|
+
* await Task.findAll({ transaction: t });
|
|
179
|
+
* }
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
tryAdvisoryLock(key: AdvisoryLockKey, options?: Readonly<{
|
|
184
|
+
shared?: boolean;
|
|
185
|
+
}>): Promise<boolean>;
|
|
186
|
+
/**
|
|
187
|
+
* Registers a callback run after a successful commit.
|
|
188
|
+
*
|
|
189
|
+
* @param hook - Callback receiving this transaction; hooks run in registration order after the
|
|
190
|
+
* transaction is committed and are awaited by `commit()`. They never run after a rollback.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* await sequelize.transaction(async (t) => {
|
|
195
|
+
* t.afterCommit(() => console.log('committed, safe to notify'));
|
|
196
|
+
* await User.create({ name: 'Ann' }, { transaction: t });
|
|
197
|
+
* });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
afterCommit(hook: (transaction: Transaction) => unknown): void;
|
|
201
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ValidationErrorItem } from '../errors/errors.ts';
|
|
2
|
+
import { AttributeDefinition } from '../model/model-definition.ts';
|
|
3
|
+
import { ValidationTarget } from './validation-target.ts';
|
|
4
|
+
/** Runs the `validate` options of one attribute: built-in, custom and Standard Schema validators. */
|
|
5
|
+
export declare class AttributeValidators {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Validates one attribute value (`notNull` is checked elsewhere).
|
|
9
|
+
*
|
|
10
|
+
* @param target - Instance being validated.
|
|
11
|
+
* @param attribute - Attribute definition.
|
|
12
|
+
* @param value - Current value of the attribute.
|
|
13
|
+
* @returns Failures of all validators of the attribute.
|
|
14
|
+
*/
|
|
15
|
+
items(target: ValidationTarget, attribute: AttributeDefinition, value: unknown): Promise<readonly ValidationErrorItem[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the attribute has validators to run (everything in `validate` except `notNull`).
|
|
18
|
+
*
|
|
19
|
+
* @param attribute - Attribute definition.
|
|
20
|
+
* @returns True when {@link AttributeValidators.items} can report failures.
|
|
21
|
+
*/
|
|
22
|
+
hasValidators(attribute: AttributeDefinition): boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ValidationErrorItem } from '../errors/errors.ts';
|
|
2
|
+
import { AttributeDefinition } from '../model/model-definition.ts';
|
|
3
|
+
import { ValidationTarget } from './validation-target.ts';
|
|
4
|
+
/** Runs one built-in (validator.js) validator option of an attribute. */
|
|
5
|
+
export declare class BuiltinAttributeValidator {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Validates a non-null attribute value.
|
|
9
|
+
*
|
|
10
|
+
* @param target - Instance being validated.
|
|
11
|
+
* @param attribute - Attribute definition.
|
|
12
|
+
* @param name - Validator name, e.g. `isEmail`.
|
|
13
|
+
* @param test - Validator option: `false`, arguments, or `{ args, msg }`.
|
|
14
|
+
* @param value - Current value of the attribute.
|
|
15
|
+
* @returns The failure, or `undefined` when the value passed or the validator is disabled.
|
|
16
|
+
* @remarks An unknown validator name fails with `Invalid validator function: <name>`, like v6.
|
|
17
|
+
*/
|
|
18
|
+
run(target: ValidationTarget, attribute: AttributeDefinition, name: string, test: unknown, value: unknown): ValidationErrorItem | undefined;
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Built-in validator: value as a string, then the validator arguments. */
|
|
2
|
+
export type ValidatorFunction = (value: string, ...args: readonly unknown[]) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Sequelize v6 built-in attribute validators: validator.js functions plus the v6 additions.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class BuiltinValidators {
|
|
9
|
+
/**
|
|
10
|
+
* Finds a built-in validator by its Sequelize v6 name.
|
|
11
|
+
*
|
|
12
|
+
* @param name - Validator name, e.g. `'isEmail'` or `'len'`.
|
|
13
|
+
* @returns The validator (called with the value as a string and the arguments), or `undefined`.
|
|
14
|
+
*/
|
|
15
|
+
find(name: string): ValidatorFunction | undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ValidationErrorItem } from '../errors/errors.ts';
|
|
2
|
+
import { AttributeDefinition } from '../model/model-definition.ts';
|
|
3
|
+
import { ValidationTarget } from './validation-target.ts';
|
|
4
|
+
/** Checks the checks Sequelize v6 always runs: `allowNull` and string attributes holding objects. */
|
|
5
|
+
export declare class CoreValidator {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Validates one attribute value.
|
|
9
|
+
*
|
|
10
|
+
* @param target - Instance being validated.
|
|
11
|
+
* @param attribute - Attribute definition.
|
|
12
|
+
* @param value - Current value of the attribute.
|
|
13
|
+
* @returns Failures; empty for auto-generated attributes and valid values.
|
|
14
|
+
*/
|
|
15
|
+
items(target: ValidationTarget, attribute: AttributeDefinition, value: unknown): readonly ValidationErrorItem[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Runs user-supplied validator functions (sync, async or callback style). */
|
|
2
|
+
export declare class CustomValidators {
|
|
3
|
+
#private;
|
|
4
|
+
/**
|
|
5
|
+
* Calls a validator with the instance as `this`.
|
|
6
|
+
*
|
|
7
|
+
* @param instance - Instance being validated.
|
|
8
|
+
* @param fn - Validator function; with one parameter more than `args` it is callback style.
|
|
9
|
+
* @param args - Arguments passed before the callback.
|
|
10
|
+
* @returns The failure message, or `undefined` when the validator passed.
|
|
11
|
+
*/
|
|
12
|
+
failure(instance: object, fn: unknown, args: readonly unknown[]): Promise<string | undefined>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ValidationErrorItem } from '../errors/errors.ts';
|
|
2
|
+
import { StandardSchemaV1 } from './standard-schema.ts';
|
|
3
|
+
import { ModelValidatorFunction } from './types.ts';
|
|
4
|
+
import { ValidationScope, ValidationTarget } from './validation-target.ts';
|
|
5
|
+
export type { ValidationScope, ValidationTarget } from './validation-target.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Validates instances like Sequelize v6 `InstanceValidator` (without hooks): `notNull`, string
|
|
8
|
+
* values, built-in (validator.js) and custom attribute validators, Standard Schemas and model
|
|
9
|
+
* validators. Expressions (`literal`, `fn`, ...) are not validated.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare class InstanceValidator {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Validates an instance and returns all failures.
|
|
17
|
+
*
|
|
18
|
+
* @param target - Instance, its definition and values.
|
|
19
|
+
* @param scope - Attributes and model validators to skip.
|
|
20
|
+
* @param modelValidators - Model-level validators (`validate` model option).
|
|
21
|
+
* @param modelSchema - Standard Schema of the whole model (`schema` model option).
|
|
22
|
+
* @returns Failures; empty when the instance is valid.
|
|
23
|
+
*/
|
|
24
|
+
validate(target: ValidationTarget, scope: ValidationScope, modelValidators?: Readonly<Record<string, ModelValidatorFunction>>, modelSchema?: StandardSchemaV1): Promise<readonly ValidationErrorItem[]>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ValidationErrorItem } from '../errors/errors.ts';
|
|
2
|
+
import { StandardSchemaV1 } from './standard-schema.ts';
|
|
3
|
+
import { ValidationTarget } from './validation-target.ts';
|
|
4
|
+
/** Turns the issues of a Standard Schema into validation error items. */
|
|
5
|
+
export declare class SchemaItems {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* @param test - Value to check.
|
|
9
|
+
* @returns Whether `test` is a Standard Schema.
|
|
10
|
+
*/
|
|
11
|
+
isSchema(test: unknown): test is StandardSchemaV1;
|
|
12
|
+
/**
|
|
13
|
+
* Validates a value against a schema.
|
|
14
|
+
*
|
|
15
|
+
* @param target - Instance being validated.
|
|
16
|
+
* @param schema - Standard Schema.
|
|
17
|
+
* @param value - Value to validate.
|
|
18
|
+
* @param path - Attribute the schema belongs to; `undefined` for a model schema.
|
|
19
|
+
* @returns One item per schema issue.
|
|
20
|
+
*/
|
|
21
|
+
items(target: ValidationTarget, schema: StandardSchemaV1, value: unknown, path: string | undefined): Promise<readonly ValidationErrorItem[]>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from './standard-schema.ts';
|
|
2
|
+
/** Problem found by a Standard Schema, with a dotted path. */
|
|
3
|
+
export type StandardSchemaFailure = Readonly<{
|
|
4
|
+
message: string;
|
|
5
|
+
path: string | undefined;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* Validates values with [Standard Schema v1](https://standardschema.dev) schemas (zod, valibot,
|
|
9
|
+
* arktype, ...).
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare class StandardSchemaValidator {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Checks whether a value is a Standard Schema.
|
|
17
|
+
*
|
|
18
|
+
* @param value - Value to test.
|
|
19
|
+
* @returns True when `value` has a `~standard.validate` function.
|
|
20
|
+
*/
|
|
21
|
+
isSchema(value: unknown): value is StandardSchemaV1;
|
|
22
|
+
/**
|
|
23
|
+
* Validates a value.
|
|
24
|
+
*
|
|
25
|
+
* @param schema - Schema to validate against.
|
|
26
|
+
* @param value - Value to validate.
|
|
27
|
+
* @returns Issues with dotted paths (empty when valid).
|
|
28
|
+
*/
|
|
29
|
+
issues(schema: StandardSchemaV1, value: unknown): Promise<readonly StandardSchemaFailure[]>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** A path segment of a Standard Schema issue. */
|
|
2
|
+
export type StandardSchemaPathSegment = Readonly<{
|
|
3
|
+
/** Key of the segment. */
|
|
4
|
+
key: PropertyKey;
|
|
5
|
+
}>;
|
|
6
|
+
/** One problem reported by a Standard Schema validator. */
|
|
7
|
+
export type StandardSchemaIssue = Readonly<{
|
|
8
|
+
/** Error message. */
|
|
9
|
+
message: string;
|
|
10
|
+
/** Location of the problem inside the validated value. */
|
|
11
|
+
path?: readonly (PropertyKey | StandardSchemaPathSegment)[];
|
|
12
|
+
}>;
|
|
13
|
+
/** Result of Standard Schema validation. */
|
|
14
|
+
export type StandardSchemaResult = Readonly<{
|
|
15
|
+
/** Validated (possibly transformed) value. */
|
|
16
|
+
value: unknown;
|
|
17
|
+
/** Absent on success. */
|
|
18
|
+
issues?: undefined;
|
|
19
|
+
}> | Readonly<{
|
|
20
|
+
/** Problems found. */
|
|
21
|
+
issues: readonly StandardSchemaIssue[];
|
|
22
|
+
}>;
|
|
23
|
+
/** The `~standard` property of a Standard Schema v1 object. */
|
|
24
|
+
export type StandardSchemaProps = Readonly<{
|
|
25
|
+
/** Standard Schema version. */
|
|
26
|
+
version: 1;
|
|
27
|
+
/** Library name, e.g. `'zod'`. */
|
|
28
|
+
vendor: string;
|
|
29
|
+
/** Validates a value. */
|
|
30
|
+
validate: (value: unknown) => StandardSchemaResult | Promise<StandardSchemaResult>;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Any schema implementing [Standard Schema v1](https://standardschema.dev) — zod, valibot, arktype
|
|
34
|
+
* and others. Used by `validate: { schema }` on attributes and `schema` on models.
|
|
35
|
+
*/
|
|
36
|
+
export type StandardSchemaV1 = Readonly<{
|
|
37
|
+
/** Standard Schema interface. */
|
|
38
|
+
'~standard': StandardSchemaProps;
|
|
39
|
+
}>;
|