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,98 @@
|
|
|
1
|
+
import { AttributeDefinition } from '../model/model-definition.ts';
|
|
2
|
+
import { AnyModel, ModelStatic, Values } from '../model/options.ts';
|
|
3
|
+
import { ReferenceDefaults, ReferenceSpec } from './association-key-types.ts';
|
|
4
|
+
import { AssociationName, AssociationOptions, ForeignKeyOptions } from './types.ts';
|
|
5
|
+
type Model = ModelStatic<AnyModel>;
|
|
6
|
+
export type { AssociationKeyFields, ReferenceDefaults, ReferenceSpec, TargetKeys, } from './association-key-types.ts';
|
|
7
|
+
/** Naming and foreign key attribute rules shared by the association classes (Sequelize v6 defaults). */
|
|
8
|
+
export declare class AssociationKeys {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Converts `snake_case` / `kebab-case` / spaced names to camelCase.
|
|
12
|
+
*
|
|
13
|
+
* @param value - Name to convert.
|
|
14
|
+
* @returns camelCase name.
|
|
15
|
+
*/
|
|
16
|
+
camelize(value: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Singular and plural forms of a model name.
|
|
19
|
+
*
|
|
20
|
+
* @param model - Model class.
|
|
21
|
+
* @returns Name forms.
|
|
22
|
+
*/
|
|
23
|
+
modelName(model: Model): AssociationName;
|
|
24
|
+
/**
|
|
25
|
+
* First primary key attribute of a model.
|
|
26
|
+
*
|
|
27
|
+
* @param model - Model class.
|
|
28
|
+
* @returns Attribute name (`id` when the model has none).
|
|
29
|
+
*/
|
|
30
|
+
primaryKey(model: Model): string;
|
|
31
|
+
/**
|
|
32
|
+
* Attribute definition by name.
|
|
33
|
+
*
|
|
34
|
+
* @param model - Model class.
|
|
35
|
+
* @param name - Attribute name.
|
|
36
|
+
* @returns Definition, if the attribute exists.
|
|
37
|
+
*/
|
|
38
|
+
attributeOf(model: Model, name: string): AttributeDefinition | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Column of an attribute.
|
|
41
|
+
*
|
|
42
|
+
* @param model - Model class.
|
|
43
|
+
* @param name - Attribute name.
|
|
44
|
+
* @returns Column name (the attribute name when not defined).
|
|
45
|
+
*/
|
|
46
|
+
fieldOf(model: Model, name: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Attribute name of a `foreignKey` / `otherKey` option.
|
|
49
|
+
*
|
|
50
|
+
* @param option - Option value.
|
|
51
|
+
* @returns Attribute name, if given.
|
|
52
|
+
*/
|
|
53
|
+
foreignKeyName(option: string | ForeignKeyOptions | undefined): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Object form of a `foreignKey` / `otherKey` option.
|
|
56
|
+
*
|
|
57
|
+
* @param option - Option value.
|
|
58
|
+
* @returns Foreign key options (empty for a string).
|
|
59
|
+
*/
|
|
60
|
+
foreignKeyExtras(option: string | ForeignKeyOptions | undefined): ForeignKeyOptions;
|
|
61
|
+
/**
|
|
62
|
+
* Singular and plural alias forms.
|
|
63
|
+
*
|
|
64
|
+
* @param as - `as` option.
|
|
65
|
+
* @param fallback - Forms used without `as`.
|
|
66
|
+
* @param multi - Whether a string alias is the plural form.
|
|
67
|
+
* @returns Alias forms.
|
|
68
|
+
*/
|
|
69
|
+
aliasNames(as: string | AssociationName | undefined, fallback: AssociationName, multi: boolean): AssociationName;
|
|
70
|
+
/**
|
|
71
|
+
* `references` / `onDelete` / `onUpdate` attribute options of a foreign key.
|
|
72
|
+
*
|
|
73
|
+
* @param spec - Referenced model and key, with the actions from the options.
|
|
74
|
+
* @param allowNull - Whether the key may be `NULL` (for the `auto` delete action).
|
|
75
|
+
* @param defaults - Actions used when the options give none.
|
|
76
|
+
* @returns Attribute options (empty with `constraints: false`).
|
|
77
|
+
*/
|
|
78
|
+
reference(spec: ReferenceSpec, allowNull: boolean, defaults: ReferenceDefaults): Values;
|
|
79
|
+
/**
|
|
80
|
+
* Attribute options of a foreign key.
|
|
81
|
+
*
|
|
82
|
+
* @param type - Referenced attribute (its data type is reused).
|
|
83
|
+
* @param extras - Object form of the foreign key option.
|
|
84
|
+
* @param base - Further attribute options.
|
|
85
|
+
* @returns Attribute options.
|
|
86
|
+
*/
|
|
87
|
+
keyAttribute(type: AttributeDefinition | undefined, extras: ForeignKeyOptions, base?: Values): Values;
|
|
88
|
+
/**
|
|
89
|
+
* Adds the foreign key attribute (with its reference) to the model that holds the key.
|
|
90
|
+
*
|
|
91
|
+
* @param owner - Model that holds the foreign key.
|
|
92
|
+
* @param referenced - Model the key references.
|
|
93
|
+
* @param referencedKey - Referenced attribute.
|
|
94
|
+
* @param foreignKey - Foreign key attribute name.
|
|
95
|
+
* @param options - Association options.
|
|
96
|
+
*/
|
|
97
|
+
addForeignKey(owner: Model, referenced: Model, referencedKey: string, foreignKey: string, options: AssociationOptions): void;
|
|
98
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic } from '../model/options.ts';
|
|
2
|
+
import { IncludeOptions } from './include.ts';
|
|
3
|
+
import { Association } from './types.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
/** Finds the association an include entry refers to, by object, alias or target model. */
|
|
6
|
+
export declare class AssociationLookup {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Replaces `{ all: true }` entries with one entry per association of `source`.
|
|
10
|
+
*
|
|
11
|
+
* @param source - Model the includes are resolved on.
|
|
12
|
+
* @param items - Include entries.
|
|
13
|
+
* @returns Include entries without `all`.
|
|
14
|
+
*/
|
|
15
|
+
expandAll(source: Model, items: readonly IncludeOptions[]): readonly IncludeOptions[];
|
|
16
|
+
/**
|
|
17
|
+
* Association an include entry refers to.
|
|
18
|
+
*
|
|
19
|
+
* @param source - Model the include is resolved on.
|
|
20
|
+
* @param item - Include entry.
|
|
21
|
+
* @returns The association.
|
|
22
|
+
* @throws EagerLoadingError when the target model is not associated to `source`.
|
|
23
|
+
*/
|
|
24
|
+
resolve(source: Model, item: IncludeOptions): Association;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic } from '../model/options.ts';
|
|
2
|
+
import { AssociationKeyFields } from './association-key-types.ts';
|
|
3
|
+
import { Association as AssociationFields, AssociationName, AssociationOptions, AssociationType } from './types.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
/** Everything an association is built from. */
|
|
6
|
+
export type AssociationInit = Readonly<{
|
|
7
|
+
type: AssociationType;
|
|
8
|
+
source: Model;
|
|
9
|
+
target: Model;
|
|
10
|
+
options: AssociationOptions;
|
|
11
|
+
name: AssociationName;
|
|
12
|
+
keys: AssociationKeyFields;
|
|
13
|
+
}>;
|
|
14
|
+
/** Computes the public fields of an association from its definition. */
|
|
15
|
+
export declare class AssociationShape {
|
|
16
|
+
#private;
|
|
17
|
+
/**
|
|
18
|
+
* Public fields of an association.
|
|
19
|
+
*
|
|
20
|
+
* @param init - Kind, models, options, alias forms and resolved keys.
|
|
21
|
+
* @returns Field values.
|
|
22
|
+
*/
|
|
23
|
+
fields(init: AssociationInit): AssociationFields;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic, Values } from '../model/options.ts';
|
|
2
|
+
import { AssociationKeyFields } from './association-key-types.ts';
|
|
3
|
+
import { Association as AssociationFields, AssociationName, AssociationOptions, AssociationThrough, AssociationType } from './types.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
/** Query options accepted by the accessor methods (`getPosts(options)`, ...). */
|
|
6
|
+
export type AccessorOptions = Values & Readonly<{
|
|
7
|
+
where?: unknown;
|
|
8
|
+
transaction?: unknown;
|
|
9
|
+
logging?: unknown;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Association between two models (Sequelize v6 `Association`). Subclasses resolve the keys,
|
|
13
|
+
* add the foreign key attributes and implement the accessor methods that are installed on the
|
|
14
|
+
* source prototype (`getX`, `setX`, `createX`, ...).
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class Association implements AssociationFields {
|
|
17
|
+
/** Kind of association. */
|
|
18
|
+
readonly associationType: AssociationType;
|
|
19
|
+
/** Model the association is defined on. */
|
|
20
|
+
readonly source: Model;
|
|
21
|
+
/** Associated model. */
|
|
22
|
+
readonly target: Model;
|
|
23
|
+
/** Alias used in `include` and as the instance property. */
|
|
24
|
+
readonly as: string;
|
|
25
|
+
/** Singular and plural alias forms. */
|
|
26
|
+
readonly name: AssociationName;
|
|
27
|
+
/** Whether `as` was given explicitly. */
|
|
28
|
+
readonly isAliased: boolean;
|
|
29
|
+
/** Association scope. */
|
|
30
|
+
readonly scope: Readonly<Record<string, unknown>> | undefined;
|
|
31
|
+
/** True for belongsTo / hasOne. */
|
|
32
|
+
readonly isSingleAssociation: boolean;
|
|
33
|
+
/** True for hasMany / belongsToMany. */
|
|
34
|
+
readonly isMultiAssociation: boolean;
|
|
35
|
+
/** Names of the instance methods added to the source model. */
|
|
36
|
+
readonly accessors: Readonly<Record<string, string>>;
|
|
37
|
+
/** Foreign key attribute (on the source for belongsTo, on the target for hasOne/hasMany, on the junction for belongsToMany). */
|
|
38
|
+
readonly foreignKey: string;
|
|
39
|
+
/** Column of the foreign key. */
|
|
40
|
+
readonly identifierField: string;
|
|
41
|
+
/** Source attribute referenced by the foreign key. */
|
|
42
|
+
readonly sourceKey: string;
|
|
43
|
+
/** Target attribute referenced by the foreign key (belongsTo) or by `otherKey` (belongsToMany). */
|
|
44
|
+
readonly targetKey: string;
|
|
45
|
+
/** Junction foreign key pointing at the target (belongsToMany). */
|
|
46
|
+
readonly otherKey: string | undefined;
|
|
47
|
+
/** Junction model (belongsToMany). */
|
|
48
|
+
readonly through: AssociationThrough | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* @param type - Kind of association.
|
|
51
|
+
* @param source - Model the association is defined on.
|
|
52
|
+
* @param target - Associated model.
|
|
53
|
+
* @param options - Association options.
|
|
54
|
+
* @param name - Singular and plural alias forms.
|
|
55
|
+
* @param keys - Resolved keys.
|
|
56
|
+
*/
|
|
57
|
+
protected constructor(type: AssociationType, source: Model, target: Model, options: AssociationOptions, name: AssociationName, keys: AssociationKeyFields);
|
|
58
|
+
/**
|
|
59
|
+
* Registers the association on the source model, installs the accessor methods and the
|
|
60
|
+
* instance properties of the alias (and of the junction model on the target).
|
|
61
|
+
*
|
|
62
|
+
* @throws AssociationError when the alias is already used on the source.
|
|
63
|
+
*/
|
|
64
|
+
protected install(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Values of an array-or-single argument as a list.
|
|
67
|
+
*
|
|
68
|
+
* @param value - One value, a list, `null` or `undefined`.
|
|
69
|
+
* @returns List of values.
|
|
70
|
+
*/
|
|
71
|
+
protected toArray<T>(value: T | readonly T[] | null | undefined): readonly T[];
|
|
72
|
+
/**
|
|
73
|
+
* Attribute of an instance, or the value itself for a key given directly.
|
|
74
|
+
*
|
|
75
|
+
* @param item - Instance or key value.
|
|
76
|
+
* @param key - Attribute name.
|
|
77
|
+
* @returns Key value.
|
|
78
|
+
*/
|
|
79
|
+
protected keyOf(item: unknown, key: string): unknown;
|
|
80
|
+
/**
|
|
81
|
+
* `Op.and` of the given conditions, skipping missing ones.
|
|
82
|
+
*
|
|
83
|
+
* @param parts - Conditions.
|
|
84
|
+
* @returns Where condition.
|
|
85
|
+
*/
|
|
86
|
+
protected andWhere(...parts: readonly unknown[]): Values;
|
|
87
|
+
/**
|
|
88
|
+
* Query options passed on to the queries an accessor runs.
|
|
89
|
+
*
|
|
90
|
+
* @param options - Accessor options.
|
|
91
|
+
* @returns `transaction`, `logging` and `benchmark`.
|
|
92
|
+
*/
|
|
93
|
+
protected passThrough(options: AccessorOptions): Values;
|
|
94
|
+
}
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic, Values } from '../model/options.ts';
|
|
2
|
+
import { Association, AccessorOptions } from './association.ts';
|
|
3
|
+
import { BelongsToManyOptions } from './types.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
type Instance = AnyModel;
|
|
6
|
+
type LinkOptions = AccessorOptions & Readonly<{
|
|
7
|
+
through?: Values;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* `source.belongsToMany(target, { through })` (Sequelize v6 `BelongsToMany`): both foreign keys
|
|
11
|
+
* live on a junction model, which is created when given by name.
|
|
12
|
+
*/
|
|
13
|
+
export declare class BelongsToMany extends Association {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Adds the foreign key attributes to the junction model and registers the association.
|
|
17
|
+
*
|
|
18
|
+
* @param source - Model the association is defined on.
|
|
19
|
+
* @param target - Associated model.
|
|
20
|
+
* @param options - Association options with `through`.
|
|
21
|
+
*/
|
|
22
|
+
constructor(source: Model, target: Model, options: BelongsToManyOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Loads the associated instances, each with its junction row under the junction model name
|
|
25
|
+
* (`getXs`).
|
|
26
|
+
*
|
|
27
|
+
* @param instance - Source instance.
|
|
28
|
+
* @param options - Find options.
|
|
29
|
+
* @returns Associated instances.
|
|
30
|
+
*/
|
|
31
|
+
get(instance: Instance, options?: AccessorOptions): Promise<Instance[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Counts the associated instances (`countXs`).
|
|
34
|
+
*
|
|
35
|
+
* @param instance - Source instance.
|
|
36
|
+
* @param options - Count options.
|
|
37
|
+
* @returns Number of associated rows.
|
|
38
|
+
*/
|
|
39
|
+
count(instance: Instance, options?: AccessorOptions): Promise<number>;
|
|
40
|
+
/**
|
|
41
|
+
* Checks whether all given instances are associated (`hasX` / `hasXs`).
|
|
42
|
+
*
|
|
43
|
+
* @param instance - Source instance.
|
|
44
|
+
* @param items - Instance(s) or target key value(s).
|
|
45
|
+
* @param options - Query options.
|
|
46
|
+
* @returns True when every item is associated.
|
|
47
|
+
*/
|
|
48
|
+
has(instance: Instance, items: unknown, options?: AccessorOptions): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Creates the missing junction rows (`addX` / `addXs`).
|
|
51
|
+
*
|
|
52
|
+
* @param instance - Source instance.
|
|
53
|
+
* @param items - Instance(s) or target key value(s).
|
|
54
|
+
* @param options - Query options; `through` gives junction values.
|
|
55
|
+
* @returns The source instance.
|
|
56
|
+
*/
|
|
57
|
+
add(instance: Instance, items: unknown, options?: LinkOptions): Promise<Instance>;
|
|
58
|
+
/**
|
|
59
|
+
* Deletes the junction rows (`removeX` / `removeXs`).
|
|
60
|
+
*
|
|
61
|
+
* @param instance - Source instance.
|
|
62
|
+
* @param items - Instance(s) or target key value(s).
|
|
63
|
+
* @param options - Query options.
|
|
64
|
+
* @returns The source instance.
|
|
65
|
+
*/
|
|
66
|
+
remove(instance: Instance, items: unknown, options?: AccessorOptions): Promise<Instance>;
|
|
67
|
+
/**
|
|
68
|
+
* Replaces the associated instances: deletes stale junction rows, adds missing ones (`setXs`).
|
|
69
|
+
*
|
|
70
|
+
* @param instance - Source instance.
|
|
71
|
+
* @param items - Instance(s) or target key value(s).
|
|
72
|
+
* @param options - Query options; `through` gives junction values.
|
|
73
|
+
* @returns The source instance.
|
|
74
|
+
*/
|
|
75
|
+
set(instance: Instance, items: unknown, options?: LinkOptions): Promise<Instance>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates an associated instance and its junction row (`createX`).
|
|
78
|
+
*
|
|
79
|
+
* @param instance - Source instance.
|
|
80
|
+
* @param values - Values of the new instance.
|
|
81
|
+
* @param options - Query options; `through` gives junction values.
|
|
82
|
+
* @returns The created instance.
|
|
83
|
+
*/
|
|
84
|
+
create(instance: Instance, values?: Values, options?: LinkOptions): Promise<Instance>;
|
|
85
|
+
}
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic, Values } from '../model/options.ts';
|
|
2
|
+
import { Association, AccessorOptions } from './association.ts';
|
|
3
|
+
import { AssociationOptions } from './types.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
type Instance = AnyModel;
|
|
6
|
+
/** `source.belongsTo(target)` (Sequelize v6 `BelongsTo`): the foreign key lives on the source. */
|
|
7
|
+
export declare class BelongsTo extends Association {
|
|
8
|
+
/**
|
|
9
|
+
* Adds the foreign key attribute to the source and registers the association.
|
|
10
|
+
*
|
|
11
|
+
* @param source - Model the association is defined on.
|
|
12
|
+
* @param target - Associated model.
|
|
13
|
+
* @param options - Association options.
|
|
14
|
+
*/
|
|
15
|
+
constructor(source: Model, target: Model, options?: AssociationOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Loads the associated instance (`getX`).
|
|
18
|
+
*
|
|
19
|
+
* @param instance - Source instance.
|
|
20
|
+
* @param options - Find options.
|
|
21
|
+
* @returns Associated instance, or `null`.
|
|
22
|
+
*/
|
|
23
|
+
get(instance: Instance, options?: AccessorOptions): Promise<Instance | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Points the foreign key at `associated` and saves the source (`setX`).
|
|
26
|
+
*
|
|
27
|
+
* @param instance - Source instance.
|
|
28
|
+
* @param associated - Instance, key value or `null`.
|
|
29
|
+
* @param options - Query options; `save: false` skips saving.
|
|
30
|
+
* @returns The saved source instance, or `undefined` with `save: false` (like v6).
|
|
31
|
+
*/
|
|
32
|
+
set(instance: Instance, associated: unknown, options?: AccessorOptions & Readonly<{
|
|
33
|
+
save?: boolean;
|
|
34
|
+
}>): Promise<Instance | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates the associated instance and points the foreign key at it (`createX`).
|
|
37
|
+
*
|
|
38
|
+
* @param instance - Source instance.
|
|
39
|
+
* @param values - Values of the new instance.
|
|
40
|
+
* @param options - Query options.
|
|
41
|
+
* @returns The created instance.
|
|
42
|
+
*/
|
|
43
|
+
create(instance: Instance, values?: Values, options?: AccessorOptions): Promise<Instance>;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic, Values } from '../model/options.ts';
|
|
2
|
+
import { Association, AccessorOptions } from './association.ts';
|
|
3
|
+
import { AssociationOptions } from './types.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
type Instance = AnyModel;
|
|
6
|
+
/** `source.hasMany(target)` (Sequelize v6 `HasMany`): the foreign key lives on the target. */
|
|
7
|
+
export declare class HasMany extends Association {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Adds the foreign key attribute to the target and registers the association.
|
|
11
|
+
*
|
|
12
|
+
* @param source - Model the association is defined on.
|
|
13
|
+
* @param target - Associated model.
|
|
14
|
+
* @param options - Association options.
|
|
15
|
+
*/
|
|
16
|
+
constructor(source: Model, target: Model, options?: AssociationOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Loads the associated instances (`getXs`).
|
|
19
|
+
*
|
|
20
|
+
* @param instance - Source instance.
|
|
21
|
+
* @param options - Find options.
|
|
22
|
+
* @returns Associated instances.
|
|
23
|
+
*/
|
|
24
|
+
get(instance: Instance, options?: AccessorOptions): Promise<Instance[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Counts the associated instances (`countXs`).
|
|
27
|
+
*
|
|
28
|
+
* @param instance - Source instance.
|
|
29
|
+
* @param options - Count options.
|
|
30
|
+
* @returns Number of associated rows.
|
|
31
|
+
*/
|
|
32
|
+
count(instance: Instance, options?: AccessorOptions): Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Checks whether all given instances are associated (`hasX` / `hasXs`).
|
|
35
|
+
*
|
|
36
|
+
* @param instance - Source instance.
|
|
37
|
+
* @param item - Instance(s) or primary key value(s).
|
|
38
|
+
* @param options - Query options.
|
|
39
|
+
* @returns True when every item is associated.
|
|
40
|
+
*/
|
|
41
|
+
has(instance: Instance, item: unknown, options?: AccessorOptions): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Links the given instances to the source (`addX` / `addXs`).
|
|
44
|
+
*
|
|
45
|
+
* @param instance - Source instance.
|
|
46
|
+
* @param items - Instance(s) or primary key value(s).
|
|
47
|
+
* @param options - Query options.
|
|
48
|
+
* @returns The source instance.
|
|
49
|
+
*/
|
|
50
|
+
add(instance: Instance, items: unknown, options?: AccessorOptions): Promise<Instance>;
|
|
51
|
+
/**
|
|
52
|
+
* Unlinks the given instances (`removeX` / `removeXs`).
|
|
53
|
+
*
|
|
54
|
+
* @param instance - Source instance.
|
|
55
|
+
* @param items - Instance(s) or primary key value(s).
|
|
56
|
+
* @param options - Query options.
|
|
57
|
+
* @returns The source instance.
|
|
58
|
+
*/
|
|
59
|
+
remove(instance: Instance, items: unknown, options?: AccessorOptions): Promise<Instance>;
|
|
60
|
+
/**
|
|
61
|
+
* Replaces the associated instances (`setXs`).
|
|
62
|
+
*
|
|
63
|
+
* @param instance - Source instance.
|
|
64
|
+
* @param items - Instance(s) or primary key value(s).
|
|
65
|
+
* @param options - Query options.
|
|
66
|
+
* @returns The source instance.
|
|
67
|
+
*/
|
|
68
|
+
set(instance: Instance, items: unknown, options?: AccessorOptions): Promise<Instance>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates an associated instance linked to the source (`createX`).
|
|
71
|
+
*
|
|
72
|
+
* @param instance - Source instance.
|
|
73
|
+
* @param values - Values of the new instance.
|
|
74
|
+
* @param options - Query options.
|
|
75
|
+
* @returns The created instance.
|
|
76
|
+
*/
|
|
77
|
+
create(instance: Instance, values?: Values, options?: AccessorOptions): Promise<Instance>;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic, Values } from '../model/options.ts';
|
|
2
|
+
import { Association, AccessorOptions } from './association.ts';
|
|
3
|
+
import { AssociationOptions } from './types.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
type Instance = AnyModel;
|
|
6
|
+
/** `source.hasOne(target)` (Sequelize v6 `HasOne`): the foreign key lives on the target. */
|
|
7
|
+
export declare class HasOne extends Association {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Adds the foreign key attribute to the target and registers the association.
|
|
11
|
+
*
|
|
12
|
+
* @param source - Model the association is defined on.
|
|
13
|
+
* @param target - Associated model.
|
|
14
|
+
* @param options - Association options.
|
|
15
|
+
*/
|
|
16
|
+
constructor(source: Model, target: Model, options?: AssociationOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Loads the associated instance (`getX`).
|
|
19
|
+
*
|
|
20
|
+
* @param instance - Source instance.
|
|
21
|
+
* @param options - Find options.
|
|
22
|
+
* @returns Associated instance, or `null`.
|
|
23
|
+
*/
|
|
24
|
+
get(instance: Instance, options?: AccessorOptions): Promise<Instance | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Makes `associated` the associated instance, unlinking the current one (`setX`).
|
|
27
|
+
*
|
|
28
|
+
* @param instance - Source instance.
|
|
29
|
+
* @param associated - Instance, primary key value or `null`.
|
|
30
|
+
* @param options - Query options.
|
|
31
|
+
* @returns The new associated instance, or `null`.
|
|
32
|
+
*/
|
|
33
|
+
set(instance: Instance, associated: unknown, options?: AccessorOptions): Promise<Instance | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Creates the associated instance linked to the source (`createX`).
|
|
36
|
+
*
|
|
37
|
+
* @param instance - Source instance.
|
|
38
|
+
* @param values - Values of the new instance.
|
|
39
|
+
* @param options - Query options.
|
|
40
|
+
* @returns The created instance.
|
|
41
|
+
*/
|
|
42
|
+
create(instance: Instance, values?: Values, options?: AccessorOptions): Promise<Instance>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic } from '../model/options.ts';
|
|
2
|
+
import { IncludeNode } from './include.ts';
|
|
3
|
+
import { IncludeRow, InstanceBuilder } from './include-rows.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
type Instance = AnyModel;
|
|
6
|
+
/** Groups joined result rows into instance trees (Sequelize v6 de-duplication by primary key). */
|
|
7
|
+
export declare class IncludeAssembler {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Groups joined rows into instance trees.
|
|
11
|
+
*
|
|
12
|
+
* @param model - Main model.
|
|
13
|
+
* @param includes - Include tree.
|
|
14
|
+
* @param rows - Joined rows.
|
|
15
|
+
* @param parseMain - Parses a row with the main model's data types.
|
|
16
|
+
* @param build - Builds an instance from loaded values.
|
|
17
|
+
* @returns Main instances with the included instances attached.
|
|
18
|
+
*/
|
|
19
|
+
assemble(model: Model, includes: readonly IncludeNode[], rows: readonly IncludeRow[], parseMain: (row: IncludeRow) => Readonly<Record<string, unknown>>, build: InstanceBuilder): readonly Instance[];
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ModelDefinition } from '../model/model-definition.ts';
|
|
2
|
+
import { ExprNode } from '../sql/ast.ts';
|
|
3
|
+
import { IncludeNode } from './include.ts';
|
|
4
|
+
/** Columns an include adds to the SELECT, aliased by result path (`Posts.title`). */
|
|
5
|
+
export declare class IncludeColumns {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Prefixed columns of an include, its junction and its nested includes.
|
|
9
|
+
*
|
|
10
|
+
* @param node - Include node.
|
|
11
|
+
* @returns Aliased column expressions.
|
|
12
|
+
*/
|
|
13
|
+
columns(node: IncludeNode): readonly ExprNode[];
|
|
14
|
+
/**
|
|
15
|
+
* Join keys of the main table that the subquery must expose for the outer joins.
|
|
16
|
+
*
|
|
17
|
+
* @param definition - Main model definition.
|
|
18
|
+
* @param alias - Main table alias.
|
|
19
|
+
* @param columns - Columns already selected.
|
|
20
|
+
* @param joined - Joined includes.
|
|
21
|
+
* @returns Missing key columns.
|
|
22
|
+
*/
|
|
23
|
+
missingKeys(definition: ModelDefinition, alias: string, columns: readonly ExprNode[], joined: readonly IncludeNode[]): readonly ExprNode[];
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModelDefinition } from '../model/model-definition.ts';
|
|
2
|
+
import { JoinNode } from '../sql/ast.ts';
|
|
3
|
+
import { IncludeNode } from './include.ts';
|
|
4
|
+
/** Builds the JOIN nodes of an include and its nested includes. */
|
|
5
|
+
export declare class IncludeJoins {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Joins of an include: the target table, or junction then target for belongsToMany, followed by
|
|
9
|
+
* the joins of the nested (non-separate) includes.
|
|
10
|
+
*
|
|
11
|
+
* @param parent - Definition of the parent model.
|
|
12
|
+
* @param parentAlias - Table alias of the parent.
|
|
13
|
+
* @param node - Include node.
|
|
14
|
+
* @returns Join nodes.
|
|
15
|
+
*/
|
|
16
|
+
joins(parent: ModelDefinition, parentAlias: string, node: IncludeNode): readonly JoinNode[];
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic } from '../model/options.ts';
|
|
2
|
+
import { IncludeNode } from './include.ts';
|
|
3
|
+
import { IncludeResolver } from './include-resolver.ts';
|
|
4
|
+
import { IncludeRow, InstanceBuilder } from './include-rows.ts';
|
|
5
|
+
export type { IncludeRow, InstanceBuilder } from './include-rows.ts';
|
|
6
|
+
type Model = ModelStatic<AnyModel>;
|
|
7
|
+
type Instance = AnyModel;
|
|
8
|
+
/**
|
|
9
|
+
* Turns joined result rows into instance trees (Sequelize v6 de-duplication by primary key),
|
|
10
|
+
* parses raw joined rows, and loads `separate: true` includes with one extra query each.
|
|
11
|
+
*/
|
|
12
|
+
export declare class IncludeLoader {
|
|
13
|
+
#private;
|
|
14
|
+
/**
|
|
15
|
+
* @param resolver - Converts include nodes back to options for the separate queries.
|
|
16
|
+
*/
|
|
17
|
+
constructor(resolver: IncludeResolver);
|
|
18
|
+
/**
|
|
19
|
+
* Groups joined rows into instance trees.
|
|
20
|
+
*
|
|
21
|
+
* @param model - Main model.
|
|
22
|
+
* @param includes - Include tree.
|
|
23
|
+
* @param rows - Joined rows.
|
|
24
|
+
* @param parseMain - Parses a row with the main model's data types.
|
|
25
|
+
* @param build - Builds an instance from loaded values.
|
|
26
|
+
* @returns Main instances with the included instances attached.
|
|
27
|
+
*/
|
|
28
|
+
assemble(model: Model, includes: readonly IncludeNode[], rows: readonly IncludeRow[], parseMain: (row: IncludeRow) => Readonly<Record<string, unknown>>, build: InstanceBuilder): readonly Instance[];
|
|
29
|
+
/**
|
|
30
|
+
* Parses a joined raw row: included keys are parsed with the included model's data types.
|
|
31
|
+
*
|
|
32
|
+
* @param includes - Include tree.
|
|
33
|
+
* @param row - Joined row.
|
|
34
|
+
* @param parseMain - Parses a row with the main model's data types.
|
|
35
|
+
* @returns Parsed row.
|
|
36
|
+
*/
|
|
37
|
+
parseRawRow(includes: readonly IncludeNode[], row: IncludeRow, parseMain: (row: IncludeRow) => Readonly<Record<string, unknown>>): Record<string, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Loads `separate: true` includes with one extra query each and attaches them, keeping at most
|
|
40
|
+
* `limit` rows per parent.
|
|
41
|
+
*
|
|
42
|
+
* @param parents - Instances the includes belong to.
|
|
43
|
+
* @param includes - Include tree.
|
|
44
|
+
* @param options - Find options (`transaction` is passed on).
|
|
45
|
+
* @returns Resolves when all separate includes are attached.
|
|
46
|
+
*/
|
|
47
|
+
loadSeparate(parents: readonly Instance[], includes: readonly IncludeNode[], options: Readonly<Record<string, unknown>>): Promise<void>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ModelDefinition } from '../model/model-definition.ts';
|
|
2
|
+
import { OrderNode } from '../sql/ast.ts';
|
|
3
|
+
import { IncludeNode } from './include.ts';
|
|
4
|
+
/** ORDER BY nodes: all of them, and those that belong inside the main-table subquery. */
|
|
5
|
+
export type OrderNodes = Readonly<{
|
|
6
|
+
all: readonly OrderNode[];
|
|
7
|
+
main: readonly OrderNode[];
|
|
8
|
+
}>;
|
|
9
|
+
/** Resolves `order` items that reference an include (`[Include, 'attr', 'DESC']`). */
|
|
10
|
+
export declare class IncludeOrder {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* Order nodes of a find, resolving items that go through includes.
|
|
14
|
+
*
|
|
15
|
+
* @param definition - Main model definition.
|
|
16
|
+
* @param includes - Joined includes.
|
|
17
|
+
* @param order - `order` option.
|
|
18
|
+
* @param mainAlias - Main table alias.
|
|
19
|
+
* @returns All order nodes and the ones for the subquery.
|
|
20
|
+
*/
|
|
21
|
+
nodes(definition: ModelDefinition, includes: readonly IncludeNode[], order: unknown, mainAlias: string): OrderNodes;
|
|
22
|
+
}
|