@deterministic-code/datasources 0.0.0-stage → 0.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/package.json +16 -4
- package/src/ArrayReader.ts +32 -0
- package/src/BatchCommandIBulkWriteStrategy.ts +228 -0
- package/src/BuiltRepository.ts +17 -0
- package/src/BulkCRUDRepository.ts +84 -0
- package/src/BulkCommand.ts +6 -0
- package/src/BulkWriteEnrichment.ts +19 -0
- package/src/CRUDRepository.ts +264 -0
- package/src/CRUDRepositoryBuilder.ts +53 -0
- package/src/CRUDRepositoryOptions.ts +8 -0
- package/src/CRUDRepositoryStatements.ts +43 -0
- package/src/CascadeDeleteEnrichmentStrategy.ts +51 -0
- package/src/CascadeDeleteUpdateEnrichmentStrategy.ts +28 -0
- package/src/CommandMiddlewareHost.ts +113 -0
- package/src/ConsoleCommandMiddleware.ts +64 -0
- package/src/CreateEnrichmentStrategy.ts +82 -0
- package/src/Datasource.ts +152 -0
- package/src/DatasourceError.ts +6 -0
- package/src/DatasourceFactory.ts +86 -0
- package/src/DatasourceOptions.ts +1 -0
- package/src/DatasourceUrl.ts +37 -0
- package/src/DatasourceUrlParser.ts +188 -0
- package/src/DefaultCreateEnrichmentStrategy.ts +21 -0
- package/src/DefaultReadonlyEnrichmentStrategy.ts +164 -0
- package/src/DefaultUpdateEnrichmentStrategy.ts +40 -0
- package/src/DefaultWriteEnrichmentStrategy.ts +151 -0
- package/src/DeleteEnrichmentStrategy.ts +56 -0
- package/src/DriverLoader.ts +97 -0
- package/src/Enrichment.ts +15 -0
- package/src/EnrichmentPropertyType.ts +9 -0
- package/src/ExpectConsoleMiddleware.ts +47 -0
- package/src/FirstResultReader.ts +49 -0
- package/src/HashsetOptimizedReadonlyEnrichmentStrategy.ts +80 -0
- package/src/IBulkWriteStrategy.ts +13 -0
- package/src/ICRUDRepository.ts +13 -0
- package/src/ICRUDRepositoryFactory.ts +8 -0
- package/src/ICommand.ts +45 -0
- package/src/ICommandMiddleware.ts +20 -0
- package/src/IConnection.ts +13 -0
- package/src/IDatasource.ts +27 -0
- package/src/IDatasourceFactory.ts +6 -0
- package/src/IDriver.ts +24 -0
- package/src/IEnriched.ts +11 -0
- package/src/IReader.ts +8 -0
- package/src/IReadonlyEnrichmentStrategy.ts +19 -0
- package/src/IReadonlyRepository.ts +21 -0
- package/src/IRepository.ts +5 -0
- package/src/IRepositoryFactory.ts +8 -0
- package/src/IRepositoryTree.ts +5 -0
- package/src/IRepositoryTreeNode.ts +8 -0
- package/src/ITransaction.ts +9 -0
- package/src/IUnitOfWork.ts +5 -0
- package/src/IWriteEnrichmentStrategy.ts +8 -0
- package/src/Information.ts +5 -0
- package/src/IsolationLevel.ts +8 -0
- package/src/LazyWriteEnrichmentStrategy.ts +5 -0
- package/src/NestedToObjectEnrichmentStrategy.ts +33 -0
- package/src/Parameter.ts +8 -0
- package/src/ParameterDirection.ts +9 -0
- package/src/ProviderCatalog.ts +21 -0
- package/src/ProviderNotImplementedError.ts +9 -0
- package/src/ProviderNotInstalledError.ts +9 -0
- package/src/ReadonlyRepository.ts +276 -0
- package/src/ReadonlyRepositoryBuilder.ts +53 -0
- package/src/ReadonlyRepositoryMappingOptions.ts +15 -0
- package/src/ReadonlyRepositoryStatements.ts +13 -0
- package/src/RepositoryAccess.ts +14 -0
- package/src/RepositoryFactory.ts +115 -0
- package/src/RepositoryNotRegisteredError.ts +9 -0
- package/src/RepositoryTree.ts +6 -0
- package/src/RepositoryTreeNode.ts +11 -0
- package/src/Response.ts +15 -0
- package/src/Row.ts +3 -0
- package/src/SingleCommandIBulkWriteStrategy.ts +35 -0
- package/src/StatementMappers.ts +110 -0
- package/src/StoredEnrichment.ts +25 -0
- package/src/StoredProcedureBulkWriteStrategy.ts +164 -0
- package/src/StreamingReader.ts +64 -0
- package/src/UnitOfWorkTransaction.ts +50 -0
- package/src/UpdateEnrichmentStrategy.ts +97 -0
- package/src/WriteMode.ts +1 -0
- package/src/builders/Field.ts +6 -0
- package/src/builders/Scalar.ts +1 -0
- package/src/builders/index.ts +2 -0
- package/src/collectAsync.ts +7 -0
- package/src/converters/Cell.ts +10 -0
- package/src/converters/ChangeCasingConverter.ts +59 -0
- package/src/converters/Constructable.ts +1 -0
- package/src/converters/MetaDataRowTypeConverter.ts +80 -0
- package/src/converters/PluralizerConverter.ts +67 -0
- package/src/converters/RegexConverter.ts +14 -0
- package/src/converters/ReplaceConverter.ts +6 -0
- package/src/converters/RowTypeConverter.ts +33 -0
- package/src/converters/ToLowerCaseConverter.ts +4 -0
- package/src/converters/ToUpperCaseConverter.ts +4 -0
- package/src/converters/TypeConverter.ts +6 -0
- package/src/createCRUDRepositoryOptions.ts +21 -0
- package/src/createReadonlyRepositoryMappingOptions.ts +26 -0
- package/src/dotEnv.ts +16 -0
- package/src/index.ts +222 -0
- package/src/mappers/ChangeCasingMapper.ts +15 -0
- package/src/mappers/DictionaryMapper.ts +16 -0
- package/src/mappers/FlatToNestedMapper.ts +127 -0
- package/src/mappers/IFlatToNestedMapper.ts +7 -0
- package/src/mappers/IMapper.ts +4 -0
- package/src/mappers/IdentityMapper.ts +6 -0
- package/src/mappers/PluralizerMapper.ts +9 -0
- package/src/mappers/RowTypeMapper.ts +13 -0
- package/src/mappers/TransformConverterMapper.ts +11 -0
- package/src/mappers/TransformMapper.ts +8 -0
- package/src/mappers/TypeMap.ts +10 -0
- package/src/mappers/TypeMapGroup.ts +6 -0
- package/src/mocks/index.ts +9 -0
- package/src/mocks/mock-command.ts +66 -0
- package/src/mocks/mock-connection.ts +57 -0
- package/src/mocks/mock-datasource.ts +65 -0
- package/src/mocks/mock-driver.ts +27 -0
- package/src/mocks/mock-reader.ts +38 -0
- package/src/mocks/mock-repository.ts +91 -0
- package/src/mocks/mock-select-statement.ts +17 -0
- package/src/mocks/mock-transaction.ts +31 -0
- package/src/mocks/mock-where.ts +13 -0
- package/src/parametersToRecord.ts +11 -0
- package/src/readerToAsyncIterable.ts +11 -0
- package/src/splitStatements.ts +99 -0
- package/src/statementParameters.ts +22 -0
- package/src/statementUsesParameter.ts +4 -0
- package/src/statements/Aggregate.ts +9 -0
- package/src/statements/ArrayExpression.ts +5 -0
- package/src/statements/BulkDeleteStatement.ts +18 -0
- package/src/statements/BulkDeleteStatementTextRenderer.ts +16 -0
- package/src/statements/BulkInsertStatement.ts +37 -0
- package/src/statements/BulkInsertStatementTextRenderer.ts +10 -0
- package/src/statements/BulkUpdateStatement.ts +24 -0
- package/src/statements/BulkUpdateStatementTextRenderer.ts +29 -0
- package/src/statements/CheckConstraint.ts +9 -0
- package/src/statements/Cmp.ts +12 -0
- package/src/statements/Column.ts +10 -0
- package/src/statements/ColumnDefault.ts +6 -0
- package/src/statements/Condition.ts +3 -0
- package/src/statements/ConditionRenderer.ts +17 -0
- package/src/statements/CreateIndexStatement.ts +18 -0
- package/src/statements/CreateIndexStatementTextRenderer.ts +11 -0
- package/src/statements/CreateTableStatement.ts +18 -0
- package/src/statements/CreateTableStatementTextRenderer.ts +92 -0
- package/src/statements/DefaultStatementTextRenderer.ts +9 -0
- package/src/statements/DeleteStatement.ts +15 -0
- package/src/statements/DeleteStatementTextRenderer.ts +12 -0
- package/src/statements/ExecuteStoredProcedureStatement.ts +15 -0
- package/src/statements/ExecuteStoredProcedureStatementTextRenderer.ts +15 -0
- package/src/statements/ExpressionEvaluator.ts +166 -0
- package/src/statements/ExpressionRenderer.ts +161 -0
- package/src/statements/ForeignKey.ts +23 -0
- package/src/statements/IBulkDeleteStatement.ts +3 -0
- package/src/statements/IBulkInsertStatement.ts +3 -0
- package/src/statements/IBulkUpdateStatement.ts +3 -0
- package/src/statements/ICondition.ts +5 -0
- package/src/statements/IConditionVisitor.ts +7 -0
- package/src/statements/ICreateIndexStatement.ts +3 -0
- package/src/statements/ICreateTableStatement.ts +3 -0
- package/src/statements/IDeleteStatement.ts +6 -0
- package/src/statements/IExecuteStoredProcedureStatement.ts +3 -0
- package/src/statements/IExpression.ts +1 -0
- package/src/statements/IInsertStatement.ts +3 -0
- package/src/statements/IReturnStatement.ts +3 -0
- package/src/statements/ISelectStatement.ts +6 -0
- package/src/statements/IStatement.ts +5 -0
- package/src/statements/IStatementVisitor.ts +27 -0
- package/src/statements/ITableConstraint.ts +6 -0
- package/src/statements/IUpdateStatement.ts +6 -0
- package/src/statements/IWhere.ts +7 -0
- package/src/statements/Identifier.ts +5 -0
- package/src/statements/InsertStatement.ts +15 -0
- package/src/statements/InsertStatementTextRenderer.ts +7 -0
- package/src/statements/Join.ts +26 -0
- package/src/statements/Literal.ts +6 -0
- package/src/statements/Native.ts +5 -0
- package/src/statements/NotNull.ts +3 -0
- package/src/statements/Operator.ts +234 -0
- package/src/statements/OrderBy.ts +19 -0
- package/src/statements/PrimaryKey.ts +9 -0
- package/src/statements/ReturnStatement.ts +15 -0
- package/src/statements/ReturnStatementTextRenderer.ts +15 -0
- package/src/statements/SelectInsertedIdStatement.ts +11 -0
- package/src/statements/SelectInsertedIdStatementTextRenderer.ts +7 -0
- package/src/statements/SelectStatement.ts +34 -0
- package/src/statements/SelectStatementOptions.ts +16 -0
- package/src/statements/SelectStatementTextRenderer.ts +71 -0
- package/src/statements/StatementEvaluator.ts +5 -0
- package/src/statements/StatementParser.ts +461 -0
- package/src/statements/StatementRenderer.ts +120 -0
- package/src/statements/StatementTextRenderer.ts +60 -0
- package/src/statements/Subquery.ts +6 -0
- package/src/statements/UniqueConstraint.ts +9 -0
- package/src/statements/UpdateStatement.ts +34 -0
- package/src/statements/UpdateStatementTextRenderer.ts +63 -0
- package/src/statements/Where.ts +250 -0
- package/src/statements/WhereText.ts +10 -0
- package/src/statements/index.ts +75 -0
- package/src/stubs/StubCommand.ts +30 -0
- package/src/stubs/StubConnection.ts +21 -0
- package/src/stubs/StubDatasource.ts +60 -0
- package/src/stubs/StubReader.ts +25 -0
- package/src/stubs/StubRepository.ts +42 -0
- package/src/stubs/StubTransaction.ts +17 -0
- package/src/stubs/createStubDatasource.ts +4 -0
- package/src/stubs/index.ts +7 -0
- package/src/stubs/notImplemented.ts +5 -0
- package/README.md +0 -3
package/src/index.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
export type { ICommand } from "./ICommand.ts";
|
|
2
|
+
export { execute, executeReader } from "./ICommand.ts";
|
|
3
|
+
export type { ICommandMiddleware } from "./ICommandMiddleware.ts";
|
|
4
|
+
export type { IConnection } from "./IConnection.ts";
|
|
5
|
+
export type { IDatasource } from "./IDatasource.ts";
|
|
6
|
+
export type { IDriver } from "./IDriver.ts";
|
|
7
|
+
export { columnType } from "./IDriver.ts";
|
|
8
|
+
export type { Information } from "./Information.ts";
|
|
9
|
+
export type { DatasourceOptions } from "./DatasourceOptions.ts";
|
|
10
|
+
export { DatasourceFactory } from "./DatasourceFactory.ts";
|
|
11
|
+
export { ProviderCatalog } from "./ProviderCatalog.ts";
|
|
12
|
+
export type {
|
|
13
|
+
ICreateTableStatement,
|
|
14
|
+
ICreateIndexStatement,
|
|
15
|
+
IDeleteStatement,
|
|
16
|
+
IExpression,
|
|
17
|
+
IBulkDeleteStatement,
|
|
18
|
+
IBulkInsertStatement,
|
|
19
|
+
IBulkUpdateStatement,
|
|
20
|
+
IInsertStatement,
|
|
21
|
+
ISelectStatement,
|
|
22
|
+
IStatement,
|
|
23
|
+
IStatementVisitor,
|
|
24
|
+
ICondition,
|
|
25
|
+
IConditionVisitor,
|
|
26
|
+
IExecuteStoredProcedureStatement,
|
|
27
|
+
IReturnStatement,
|
|
28
|
+
ITableConstraint,
|
|
29
|
+
TableConstraintKind,
|
|
30
|
+
IUpdateStatement,
|
|
31
|
+
IWhere,
|
|
32
|
+
} from "./statements/index.ts";
|
|
33
|
+
export type { IReader } from "./IReader.ts";
|
|
34
|
+
export type { IRepository } from "./IRepository.ts";
|
|
35
|
+
export type { IReadonlyRepository } from "./IReadonlyRepository.ts";
|
|
36
|
+
export type { ICRUDRepository } from "./ICRUDRepository.ts";
|
|
37
|
+
export { ReadonlyRepository, untyped } from "./ReadonlyRepository.ts";
|
|
38
|
+
export type { IRepositoryFactory } from "./IRepositoryFactory.ts";
|
|
39
|
+
export type { ICRUDRepositoryFactory } from "./ICRUDRepositoryFactory.ts";
|
|
40
|
+
export { RepositoryFactory } from "./RepositoryFactory.ts";
|
|
41
|
+
export { RepositoryAccess } from "./RepositoryAccess.ts";
|
|
42
|
+
export { RepositoryNotRegisteredError } from "./RepositoryNotRegisteredError.ts";
|
|
43
|
+
export type { IEnriched } from "./IEnriched.ts";
|
|
44
|
+
export type { IRepositoryTree } from "./IRepositoryTree.ts";
|
|
45
|
+
export type { IRepositoryTreeNode } from "./IRepositoryTreeNode.ts";
|
|
46
|
+
export type { Association, Enrichment } from "./Enrichment.ts";
|
|
47
|
+
export { EnrichmentPropertyType } from "./EnrichmentPropertyType.ts";
|
|
48
|
+
export type { IReadonlyEnrichmentStrategy } from "./IReadonlyEnrichmentStrategy.ts";
|
|
49
|
+
export type { IWriteEnrichmentStrategy } from "./IWriteEnrichmentStrategy.ts";
|
|
50
|
+
export type { WriteMode } from "./WriteMode.ts";
|
|
51
|
+
export { DefaultReadonlyEnrichmentStrategy } from "./DefaultReadonlyEnrichmentStrategy.ts";
|
|
52
|
+
export { DefaultWriteEnrichmentStrategy } from "./DefaultWriteEnrichmentStrategy.ts";
|
|
53
|
+
export { DeleteEnrichmentStrategy } from "./DeleteEnrichmentStrategy.ts";
|
|
54
|
+
export { CascadeDeleteEnrichmentStrategy } from "./CascadeDeleteEnrichmentStrategy.ts";
|
|
55
|
+
export { UpdateEnrichmentStrategy } from "./UpdateEnrichmentStrategy.ts";
|
|
56
|
+
export { DefaultUpdateEnrichmentStrategy } from "./DefaultUpdateEnrichmentStrategy.ts";
|
|
57
|
+
export { CreateEnrichmentStrategy } from "./CreateEnrichmentStrategy.ts";
|
|
58
|
+
export { DefaultCreateEnrichmentStrategy } from "./DefaultCreateEnrichmentStrategy.ts";
|
|
59
|
+
export { CascadeDeleteUpdateEnrichmentStrategy } from "./CascadeDeleteUpdateEnrichmentStrategy.ts";
|
|
60
|
+
export { LazyWriteEnrichmentStrategy } from "./LazyWriteEnrichmentStrategy.ts";
|
|
61
|
+
export { HashsetOptimizedReadonlyEnrichmentStrategy } from "./HashsetOptimizedReadonlyEnrichmentStrategy.ts";
|
|
62
|
+
export { NestedToObjectEnrichmentStrategy } from "./NestedToObjectEnrichmentStrategy.ts";
|
|
63
|
+
export { BulkCRUDRepository } from "./BulkCRUDRepository.ts";
|
|
64
|
+
export type { IBulkWriteStrategy } from "./IBulkWriteStrategy.ts";
|
|
65
|
+
export type { BulkCommand } from "./BulkCommand.ts";
|
|
66
|
+
export { SingleCommandIBulkWriteStrategy } from "./SingleCommandIBulkWriteStrategy.ts";
|
|
67
|
+
export { BatchCommandIBulkWriteStrategy } from "./BatchCommandIBulkWriteStrategy.ts";
|
|
68
|
+
export { StoredProcedureBulkWriteStrategy } from "./StoredProcedureBulkWriteStrategy.ts";
|
|
69
|
+
export { RepositoryTree } from "./RepositoryTree.ts";
|
|
70
|
+
export { RepositoryTreeNode } from "./RepositoryTreeNode.ts";
|
|
71
|
+
export { CRUDRepository } from "./CRUDRepository.ts";
|
|
72
|
+
export { ReadonlyRepositoryBuilder } from "./ReadonlyRepositoryBuilder.ts";
|
|
73
|
+
export { CRUDRepositoryBuilder } from "./CRUDRepositoryBuilder.ts";
|
|
74
|
+
export { StatementMappers } from "./StatementMappers.ts";
|
|
75
|
+
export { ReadonlyRepositoryStatements } from "./ReadonlyRepositoryStatements.ts";
|
|
76
|
+
export { CRUDRepositoryStatements } from "./CRUDRepositoryStatements.ts";
|
|
77
|
+
export type { BuiltRepository } from "./BuiltRepository.ts";
|
|
78
|
+
export { createCRUDRepositoryOptions } from "./createCRUDRepositoryOptions.ts";
|
|
79
|
+
export { createReadonlyRepositoryMappingOptions } from "./createReadonlyRepositoryMappingOptions.ts";
|
|
80
|
+
export type { ReadonlyRepositoryMappingOptions } from "./ReadonlyRepositoryMappingOptions.ts";
|
|
81
|
+
export type { CRUDRepositoryOptions } from "./CRUDRepositoryOptions.ts";
|
|
82
|
+
export { Response } from "./Response.ts";
|
|
83
|
+
export type { ITransaction } from "./ITransaction.ts";
|
|
84
|
+
export type { IUnitOfWork } from "./IUnitOfWork.ts";
|
|
85
|
+
export { UnitOfWorkTransaction } from "./UnitOfWorkTransaction.ts";
|
|
86
|
+
export { IsolationLevel } from "./IsolationLevel.ts";
|
|
87
|
+
export type { IsolationLevel as IsolationLevelName } from "./IsolationLevel.ts";
|
|
88
|
+
export type { Comparison } from "./statements/index.ts";
|
|
89
|
+
export {
|
|
90
|
+
ArrayExpression,
|
|
91
|
+
CheckConstraint,
|
|
92
|
+
ColumnDefault,
|
|
93
|
+
Condition,
|
|
94
|
+
ConditionRenderer,
|
|
95
|
+
ExpressionRenderer,
|
|
96
|
+
CreateIndexStatement,
|
|
97
|
+
CreateTableStatement,
|
|
98
|
+
CreateTableStatementTextRenderer,
|
|
99
|
+
CreateIndexStatementTextRenderer,
|
|
100
|
+
SelectStatementTextRenderer,
|
|
101
|
+
InsertStatementTextRenderer,
|
|
102
|
+
UpdateStatementTextRenderer,
|
|
103
|
+
DeleteStatementTextRenderer,
|
|
104
|
+
BulkInsertStatementTextRenderer,
|
|
105
|
+
BulkUpdateStatementTextRenderer,
|
|
106
|
+
BulkDeleteStatementTextRenderer,
|
|
107
|
+
ExecuteStoredProcedureStatementTextRenderer,
|
|
108
|
+
ReturnStatementTextRenderer,
|
|
109
|
+
SelectInsertedIdStatementTextRenderer,
|
|
110
|
+
DefaultStatementTextRenderer,
|
|
111
|
+
DeleteStatement,
|
|
112
|
+
ForeignKey,
|
|
113
|
+
Identifier,
|
|
114
|
+
InsertStatement,
|
|
115
|
+
BulkInsertStatement,
|
|
116
|
+
BulkUpdateStatement,
|
|
117
|
+
BulkDeleteStatement,
|
|
118
|
+
Literal,
|
|
119
|
+
NotNull,
|
|
120
|
+
Operator,
|
|
121
|
+
eq,
|
|
122
|
+
ne,
|
|
123
|
+
gt,
|
|
124
|
+
lt,
|
|
125
|
+
ge,
|
|
126
|
+
le,
|
|
127
|
+
PrimaryKey,
|
|
128
|
+
Aggregate,
|
|
129
|
+
OrderBy,
|
|
130
|
+
SelectStatement,
|
|
131
|
+
StatementParser,
|
|
132
|
+
StatementRenderer,
|
|
133
|
+
StatementTextRenderer,
|
|
134
|
+
Native,
|
|
135
|
+
n,
|
|
136
|
+
Subquery,
|
|
137
|
+
ReferentialAction,
|
|
138
|
+
ExpressionEvaluator,
|
|
139
|
+
StatementEvaluator,
|
|
140
|
+
ExecuteStoredProcedureStatement,
|
|
141
|
+
SelectInsertedIdStatement,
|
|
142
|
+
ReturnStatement,
|
|
143
|
+
UniqueConstraint,
|
|
144
|
+
UpdateStatement,
|
|
145
|
+
WhereText,
|
|
146
|
+
Where,
|
|
147
|
+
Join,
|
|
148
|
+
} from "./statements/index.ts";
|
|
149
|
+
export type { IDatasourceFactory } from "./IDatasourceFactory.ts";
|
|
150
|
+
export type { Parameter } from "./Parameter.ts";
|
|
151
|
+
export { ParameterDirection } from "./ParameterDirection.ts";
|
|
152
|
+
export type { ParameterDirection as ParameterDirectionName } from "./ParameterDirection.ts";
|
|
153
|
+
export type { Row } from "./Row.ts";
|
|
154
|
+
export { ArrayReader } from "./ArrayReader.ts";
|
|
155
|
+
export { FirstResultReader } from "./FirstResultReader.ts";
|
|
156
|
+
export { StreamingReader, statementReader } from "./StreamingReader.ts";
|
|
157
|
+
export { splitStatements } from "./splitStatements.ts";
|
|
158
|
+
export { statementParameters } from "./statementParameters.ts";
|
|
159
|
+
export { statementUsesParameter } from "./statementUsesParameter.ts";
|
|
160
|
+
export { collectAsync } from "./collectAsync.ts";
|
|
161
|
+
export { CommandMiddlewareHost } from "./CommandMiddlewareHost.ts";
|
|
162
|
+
export {
|
|
163
|
+
ConsoleCommandMiddleware,
|
|
164
|
+
formatElapsed,
|
|
165
|
+
} from "./ConsoleCommandMiddleware.ts";
|
|
166
|
+
export { ExpectConsoleMiddleware } from "./ExpectConsoleMiddleware.ts";
|
|
167
|
+
export { Datasource } from "./Datasource.ts";
|
|
168
|
+
export { DatasourceUrl } from "./DatasourceUrl.ts";
|
|
169
|
+
export { DatasourceUrlParser } from "./DatasourceUrlParser.ts";
|
|
170
|
+
import { Datasource } from "./Datasource.ts";
|
|
171
|
+
import { DatasourceFactory } from "./DatasourceFactory.ts";
|
|
172
|
+
Datasource.create = (options) => DatasourceFactory.create(options) as Datasource;
|
|
173
|
+
export { DatasourceError } from "./DatasourceError.ts";
|
|
174
|
+
export type { Cell, Cells } from "./converters/Cell.ts";
|
|
175
|
+
export type { Constructable } from "./converters/Constructable.ts";
|
|
176
|
+
export { TypeConverter } from "./converters/TypeConverter.ts";
|
|
177
|
+
export { MetaDataRowTypeConverter } from "./converters/MetaDataRowTypeConverter.ts";
|
|
178
|
+
export { RowTypeConverter } from "./converters/RowTypeConverter.ts";
|
|
179
|
+
export { ToLowerCaseConverter } from "./converters/ToLowerCaseConverter.ts";
|
|
180
|
+
export { ToUpperCaseConverter } from "./converters/ToUpperCaseConverter.ts";
|
|
181
|
+
export { ChangeCasingConverter, type Casing } from "./converters/ChangeCasingConverter.ts";
|
|
182
|
+
export { PluralizerConverter } from "./converters/PluralizerConverter.ts";
|
|
183
|
+
export { RegexConverter } from "./converters/RegexConverter.ts";
|
|
184
|
+
export { ReplaceConverter } from "./converters/ReplaceConverter.ts";
|
|
185
|
+
export type { IMapper } from "./mappers/IMapper.ts";
|
|
186
|
+
export type { IFlatToNestedMapper } from "./mappers/IFlatToNestedMapper.ts";
|
|
187
|
+
export type { TypeMap, TypeMapFields } from "./mappers/TypeMap.ts";
|
|
188
|
+
export type { TypeMapGroup } from "./mappers/TypeMapGroup.ts";
|
|
189
|
+
export { FlatToNestedMapper } from "./mappers/FlatToNestedMapper.ts";
|
|
190
|
+
export { ChangeCasingMapper } from "./mappers/ChangeCasingMapper.ts";
|
|
191
|
+
export { DictionaryMapper } from "./mappers/DictionaryMapper.ts";
|
|
192
|
+
export { IdentityMapper } from "./mappers/IdentityMapper.ts";
|
|
193
|
+
export { PluralizerMapper } from "./mappers/PluralizerMapper.ts";
|
|
194
|
+
export { TransformMapper } from "./mappers/TransformMapper.ts";
|
|
195
|
+
export { TransformConverterMapper } from "./mappers/TransformConverterMapper.ts";
|
|
196
|
+
export { RowTypeMapper } from "./mappers/RowTypeMapper.ts";
|
|
197
|
+
export { parametersToRecord } from "./parametersToRecord.ts";
|
|
198
|
+
export { ProviderNotImplementedError } from "./ProviderNotImplementedError.ts";
|
|
199
|
+
export { ProviderNotInstalledError } from "./ProviderNotInstalledError.ts";
|
|
200
|
+
export type { Column, JoinKind, SelectStatementOptions, ReferentialAction as ReferentialActionName, SortDirection } from "./statements/index.ts";
|
|
201
|
+
export type { Field, Scalar } from "./builders/index.ts";
|
|
202
|
+
export { readerToAsyncIterable } from "./readerToAsyncIterable.ts";
|
|
203
|
+
export {
|
|
204
|
+
StubCommand,
|
|
205
|
+
StubConnection,
|
|
206
|
+
StubDatasource,
|
|
207
|
+
StubReader,
|
|
208
|
+
StubRepository,
|
|
209
|
+
StubTransaction,
|
|
210
|
+
createStubDatasource,
|
|
211
|
+
} from "./stubs/index.ts";
|
|
212
|
+
export {
|
|
213
|
+
MockCommand,
|
|
214
|
+
MockConnection,
|
|
215
|
+
MockDatasource,
|
|
216
|
+
MockDriver,
|
|
217
|
+
MockSelectStatement,
|
|
218
|
+
MockReader,
|
|
219
|
+
MockRepository,
|
|
220
|
+
MockTransaction,
|
|
221
|
+
MockWhere,
|
|
222
|
+
} from "./mocks/index.ts";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChangeCasingConverter, type Casing } from "../converters/ChangeCasingConverter.ts";
|
|
2
|
+
import type { IMapper } from "./IMapper.ts";
|
|
3
|
+
|
|
4
|
+
export class ChangeCasingMapper implements IMapper<string, string> {
|
|
5
|
+
private readonly forward: ChangeCasingConverter;
|
|
6
|
+
private readonly reverse: ChangeCasingConverter;
|
|
7
|
+
|
|
8
|
+
constructor(from: Casing, to: Casing) {
|
|
9
|
+
this.forward = new ChangeCasingConverter(to);
|
|
10
|
+
this.reverse = new ChangeCasingConverter(from);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
map = (value: string): string => this.forward.convert(value);
|
|
14
|
+
reverseMap = (value: string): string => this.reverse.convert(value);
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IMapper } from "./IMapper.ts";
|
|
2
|
+
|
|
3
|
+
export class DictionaryMapper<T extends string | number> implements IMapper<T, T> {
|
|
4
|
+
private readonly forward = new Map<T, T>();
|
|
5
|
+
private readonly reverse = new Map<T, T>();
|
|
6
|
+
|
|
7
|
+
constructor(map: readonly (readonly [T, T])[]) {
|
|
8
|
+
for (const [from, to] of map) {
|
|
9
|
+
this.forward.set(from, to);
|
|
10
|
+
if (!this.reverse.has(to)) this.reverse.set(to, from);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
map = (value: T): T => this.forward.get(value) ?? value;
|
|
15
|
+
reverseMap = (value: T): T => this.reverse.get(value) ?? value;
|
|
16
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { Cell, Cells } from "../converters/Cell.ts";
|
|
2
|
+
import type { IFlatToNestedMapper } from "./IFlatToNestedMapper.ts";
|
|
3
|
+
import type { TypeMap, TypeMapFields } from "./TypeMap.ts";
|
|
4
|
+
import type { TypeMapGroup } from "./TypeMapGroup.ts";
|
|
5
|
+
|
|
6
|
+
type GroupPlan = { key: string; fields: Record<string, string>; destKey: string };
|
|
7
|
+
|
|
8
|
+
const stringFields = (fields: TypeMapFields<object>): Record<string, string> =>
|
|
9
|
+
Object.fromEntries(
|
|
10
|
+
Object.entries(fields).filter((entry): entry is [string, string] => typeof entry[1] === "string"),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const destOf = (fields: Record<string, string>, column: string) =>
|
|
14
|
+
Object.entries(fields).find(([, source]) => source === column)?.[0] ?? column;
|
|
15
|
+
|
|
16
|
+
const cellKey = (value: Cell | undefined) => (value == null ? null : String(value));
|
|
17
|
+
|
|
18
|
+
export class FlatToNestedMapper<T> implements IFlatToNestedMapper<T> {
|
|
19
|
+
readonly spec: TypeMap<T>;
|
|
20
|
+
private readonly scalars: Record<string, string>;
|
|
21
|
+
private readonly groups: Record<string, GroupPlan>;
|
|
22
|
+
private readonly parentDest: string;
|
|
23
|
+
|
|
24
|
+
constructor(spec: TypeMap<T>) {
|
|
25
|
+
this.spec = spec;
|
|
26
|
+
this.scalars = {};
|
|
27
|
+
this.groups = {};
|
|
28
|
+
for (const [name, value] of Object.entries(spec.fields) as [string, string | TypeMapGroup<object>][]) {
|
|
29
|
+
if (typeof value === "string") this.scalars[name] = value;
|
|
30
|
+
else {
|
|
31
|
+
const fields = stringFields(value.fields);
|
|
32
|
+
this.groups[name] = { key: value.key, fields, destKey: destOf(fields, value.key) };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
this.parentDest = destOf(this.scalars, spec.key);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
map = (rows: Iterable<T | Cells>): T[] => this._collapse(rows);
|
|
39
|
+
|
|
40
|
+
reverseMap = (values: T[]): Cells[] => [...values].flatMap((value) => this.explode(value));
|
|
41
|
+
|
|
42
|
+
private _map = (row: Cells): T => {
|
|
43
|
+
const dest = {} as Record<string, Cell | Cells[]>;
|
|
44
|
+
for (const [name, column] of Object.entries(this.scalars)) dest[name] = row[column] ?? null;
|
|
45
|
+
for (const [name, group] of Object.entries(this.groups)) {
|
|
46
|
+
const key = row[group.key];
|
|
47
|
+
dest[name] =
|
|
48
|
+
key == null
|
|
49
|
+
? []
|
|
50
|
+
: [
|
|
51
|
+
Object.fromEntries(
|
|
52
|
+
Object.entries(group.fields).map(([field, column]) => [field, row[column] ?? null]),
|
|
53
|
+
),
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
return dest as T;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
private _collapse = (rows: Iterable<T | Cells>): T[] => {
|
|
60
|
+
const byParent = new Map<string, T>();
|
|
61
|
+
const seen = new Set<string>();
|
|
62
|
+
for (const raw of rows) {
|
|
63
|
+
const item = this.mapped(raw) ? raw : this._map(raw);
|
|
64
|
+
const parent = cellKey((item as Record<string, Cell>)[this.parentDest]);
|
|
65
|
+
if (parent == null) continue;
|
|
66
|
+
const existing = byParent.get(parent);
|
|
67
|
+
if (!existing) {
|
|
68
|
+
byParent.set(parent, item);
|
|
69
|
+
this.mark(seen, parent, item);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
this.merge(existing, item, parent, seen);
|
|
73
|
+
}
|
|
74
|
+
return [...byParent.values()];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
private explode = (value: T): Cells[] => {
|
|
78
|
+
const record = value as Record<string, Cell | Cells[]>;
|
|
79
|
+
let rows: Cells[] = [this.scalarsOf(record)];
|
|
80
|
+
for (const [name, group] of Object.entries(this.groups)) {
|
|
81
|
+
const children = (record[name] as Cells[] | undefined)?.length
|
|
82
|
+
? (record[name] as Cells[])
|
|
83
|
+
: [undefined];
|
|
84
|
+
rows = rows.flatMap((row) => children.map((child) => this.withChild(row, group, child)));
|
|
85
|
+
}
|
|
86
|
+
return rows;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
private scalarsOf = (record: Record<string, Cell | Cells[]>): Cells => {
|
|
90
|
+
const row: Cells = {};
|
|
91
|
+
for (const [name, column] of Object.entries(this.scalars))
|
|
92
|
+
row[column] = (record[name] as Cell | undefined) ?? null;
|
|
93
|
+
return row;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
private withChild = (row: Cells, group: GroupPlan, child: Cells | undefined): Cells => {
|
|
97
|
+
const next = { ...row };
|
|
98
|
+
for (const [field, column] of Object.entries(group.fields)) next[column] = child?.[field] ?? null;
|
|
99
|
+
return next;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
private mapped = (row: T | Cells): row is T =>
|
|
103
|
+
Object.keys(this.groups).every((name) => Array.isArray((row as Record<string, unknown>)[name]));
|
|
104
|
+
|
|
105
|
+
private mark = (seen: Set<string>, parent: string, item: T) => {
|
|
106
|
+
const record = item as Record<string, Cells[]>;
|
|
107
|
+
for (const [name, group] of Object.entries(this.groups))
|
|
108
|
+
for (const child of record[name]) {
|
|
109
|
+
const key = cellKey(child[group.destKey]);
|
|
110
|
+
if (key != null) seen.add(`${parent}:${name}:${key}`);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
private merge = (into: T, from: T, parent: string, seen: Set<string>) => {
|
|
115
|
+
const dest = into as Record<string, Cells[]>;
|
|
116
|
+
const source = from as Record<string, Cells[]>;
|
|
117
|
+
for (const [name, group] of Object.entries(this.groups)) {
|
|
118
|
+
const children = dest[name];
|
|
119
|
+
for (const child of source[name]) {
|
|
120
|
+
const key = cellKey(child[group.destKey]);
|
|
121
|
+
if (key == null || seen.has(`${parent}:${name}:${key}`)) continue;
|
|
122
|
+
seen.add(`${parent}:${name}:${key}`);
|
|
123
|
+
children.push(child);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PluralizerConverter } from "../converters/PluralizerConverter.ts";
|
|
2
|
+
import type { IMapper } from "./IMapper.ts";
|
|
3
|
+
|
|
4
|
+
export class PluralizerMapper implements IMapper<string, string> {
|
|
5
|
+
private readonly pluralizer = new PluralizerConverter();
|
|
6
|
+
|
|
7
|
+
map = (value: string): string => this.pluralizer.convert(value);
|
|
8
|
+
reverseMap = (value: string): string => this.pluralizer.reverseConvert(value);
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Cells } from "../converters/Cell.ts";
|
|
2
|
+
import { MetaDataRowTypeConverter as RowTypeConverter } from "../converters/MetaDataRowTypeConverter.ts";
|
|
3
|
+
import type { TypeConverter } from "../converters/TypeConverter.ts";
|
|
4
|
+
import { TransformMapper } from "./TransformMapper.ts";
|
|
5
|
+
|
|
6
|
+
export class RowTypeMapper<T> extends TransformMapper<Cells, T> {
|
|
7
|
+
constructor(converter: TypeConverter<T, Cells> = new RowTypeConverter()) {
|
|
8
|
+
super(
|
|
9
|
+
(row) => converter.convert(row),
|
|
10
|
+
(item) => converter.reverseConvert(item),
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TypeConverter } from "../converters/TypeConverter.ts";
|
|
2
|
+
import { TransformMapper } from "./TransformMapper.ts";
|
|
3
|
+
|
|
4
|
+
export class TransformConverterMapper<T> extends TransformMapper<T, T> {
|
|
5
|
+
constructor(converter: TypeConverter<T, T>, filter?: (value: T) => boolean) {
|
|
6
|
+
super(
|
|
7
|
+
(value) => (filter?.(value) !== false ? converter.convert(value) : value),
|
|
8
|
+
(value) => (filter?.(value) !== false ? converter.reverseConvert(value) : value),
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { MockCommand } from "./mock-command.ts";
|
|
2
|
+
export { MockConnection } from "./mock-connection.ts";
|
|
3
|
+
export { MockDatasource } from "./mock-datasource.ts";
|
|
4
|
+
export { MockDriver } from "./mock-driver.ts";
|
|
5
|
+
export { MockSelectStatement } from "./mock-select-statement.ts";
|
|
6
|
+
export { MockReader } from "./mock-reader.ts";
|
|
7
|
+
export { MockRepository } from "./mock-repository.ts";
|
|
8
|
+
export { MockTransaction } from "./mock-transaction.ts";
|
|
9
|
+
export { MockWhere } from "./mock-where.ts";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ICommand } from "../ICommand.ts";
|
|
2
|
+
import type { IConnection } from "../IConnection.ts";
|
|
3
|
+
import type { Cells } from "../converters/Cell.ts";
|
|
4
|
+
import type { IReader } from "../IReader.ts";
|
|
5
|
+
import type { Response } from "../Response.ts";
|
|
6
|
+
import { CommandMiddlewareHost } from "../CommandMiddlewareHost.ts";
|
|
7
|
+
import type { Parameter } from "../Parameter.ts";
|
|
8
|
+
import type { Row } from "../Row.ts";
|
|
9
|
+
import type { IStatement } from "../statements/IStatement.ts";
|
|
10
|
+
import { DefaultStatementTextRenderer } from "../statements/DefaultStatementTextRenderer.ts";
|
|
11
|
+
import { Native } from "../statements/Native.ts";
|
|
12
|
+
import { SelectInsertedIdStatement } from "../statements/SelectInsertedIdStatement.ts";
|
|
13
|
+
import { MockReader } from "./mock-reader.ts";
|
|
14
|
+
|
|
15
|
+
export class MockCommand extends CommandMiddlewareHost implements ICommand {
|
|
16
|
+
executeCalls: { text: string; parameters?: Parameter[] }[] = [];
|
|
17
|
+
executeReaderCalls: { text: string; parameters?: Parameter[] }[] = [];
|
|
18
|
+
executeError?: unknown;
|
|
19
|
+
executeReaderError?: unknown;
|
|
20
|
+
response: Response = { result: undefined, rowsAffected: 0 };
|
|
21
|
+
reader: IReader<Cells> = new MockReader();
|
|
22
|
+
|
|
23
|
+
constructor(readonly connection: IConnection) {
|
|
24
|
+
super();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
executeReaderStatement = (
|
|
28
|
+
statement: IStatement,
|
|
29
|
+
parameters?: Parameter[],
|
|
30
|
+
): Promise<IReader<Cells>> =>
|
|
31
|
+
this.executeReaderNative(
|
|
32
|
+
new Native(
|
|
33
|
+
statement instanceof SelectInsertedIdStatement
|
|
34
|
+
? `${statement.table}.${statement.column}`
|
|
35
|
+
: DefaultStatementTextRenderer.instance.render(statement),
|
|
36
|
+
),
|
|
37
|
+
parameters,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
async executeReaderNative(
|
|
41
|
+
text: Native,
|
|
42
|
+
parameters?: Parameter[],
|
|
43
|
+
): Promise<IReader<Cells>> {
|
|
44
|
+
return this.run(text.text, parameters, async (query, params) => {
|
|
45
|
+
this.executeReaderCalls.push({ text: query, parameters: params });
|
|
46
|
+
if (this.executeReaderError) {
|
|
47
|
+
throw this.executeReaderError;
|
|
48
|
+
}
|
|
49
|
+
const rows =
|
|
50
|
+
this.reader instanceof MockReader
|
|
51
|
+
? (this.reader.rows as readonly Row[])
|
|
52
|
+
: [];
|
|
53
|
+
return { value: this.reader, rows };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async executeNative(text: Native, parameters?: Parameter[]): Promise<Response> {
|
|
58
|
+
return this.run(text.text, parameters, async (query, params) => {
|
|
59
|
+
this.executeCalls.push({ text: query, parameters: params });
|
|
60
|
+
if (this.executeError) {
|
|
61
|
+
throw this.executeError;
|
|
62
|
+
}
|
|
63
|
+
return { value: this.response, rows: [] };
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DatasourceError } from "../DatasourceError.ts";
|
|
2
|
+
import type { ICommand } from "../ICommand.ts";
|
|
3
|
+
import type { IConnection } from "../IConnection.ts";
|
|
4
|
+
import type { ITransaction } from "../ITransaction.ts";
|
|
5
|
+
import { IsolationLevel, type IsolationLevel as Isolation } from "../IsolationLevel.ts";
|
|
6
|
+
import { MockCommand } from "./mock-command.ts";
|
|
7
|
+
import { MockTransaction } from "./mock-transaction.ts";
|
|
8
|
+
|
|
9
|
+
export class MockConnection implements IConnection {
|
|
10
|
+
readonly provider: string;
|
|
11
|
+
openCalls = 0;
|
|
12
|
+
closeCalls = 0;
|
|
13
|
+
startTransactionCalls = 0;
|
|
14
|
+
openError?: unknown;
|
|
15
|
+
closeError?: unknown;
|
|
16
|
+
startTransactionError?: unknown;
|
|
17
|
+
transaction: ITransaction;
|
|
18
|
+
command?: ICommand;
|
|
19
|
+
isOpen = false;
|
|
20
|
+
|
|
21
|
+
constructor(transaction?: ITransaction, provider = "mock") {
|
|
22
|
+
this.provider = provider;
|
|
23
|
+
this.transaction = transaction ?? new MockTransaction(this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
createCommand = (): ICommand => this.command ?? new MockCommand(this);
|
|
27
|
+
|
|
28
|
+
async open(): Promise<void> {
|
|
29
|
+
if (this.isOpen) throw new DatasourceError("Connection is already open");
|
|
30
|
+
this.openCalls += 1;
|
|
31
|
+
if (this.openError) {
|
|
32
|
+
throw this.openError;
|
|
33
|
+
}
|
|
34
|
+
this.isOpen = true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async close(): Promise<void> {
|
|
38
|
+
this.closeCalls += 1;
|
|
39
|
+
if (this.closeError) {
|
|
40
|
+
throw this.closeError;
|
|
41
|
+
}
|
|
42
|
+
this.isOpen = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
[Symbol.asyncDispose] = (): Promise<void> => this.close();
|
|
46
|
+
|
|
47
|
+
async startTransaction(isolation: Isolation = IsolationLevel.ReadCommitted): Promise<ITransaction> {
|
|
48
|
+
this.startTransactionCalls += 1;
|
|
49
|
+
if (this.startTransactionError) {
|
|
50
|
+
throw this.startTransactionError;
|
|
51
|
+
}
|
|
52
|
+
if (this.transaction instanceof MockTransaction) {
|
|
53
|
+
this.transaction.isolation = isolation;
|
|
54
|
+
}
|
|
55
|
+
return this.transaction;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Constructable } from "../converters/Constructable.ts";
|
|
2
|
+
import type { ICommand } from "../ICommand.ts";
|
|
3
|
+
import type { IConnection } from "../IConnection.ts";
|
|
4
|
+
import type { IDatasource } from "../IDatasource.ts";
|
|
5
|
+
import type { IReadonlyRepository } from "../IReadonlyRepository.ts";
|
|
6
|
+
import type { ICRUDRepository } from "../ICRUDRepository.ts";
|
|
7
|
+
import { DatasourceError } from "../DatasourceError.ts";
|
|
8
|
+
import { RepositoryFactory } from "../RepositoryFactory.ts";
|
|
9
|
+
import { MockCommand } from "./mock-command.ts";
|
|
10
|
+
import { MockConnection } from "./mock-connection.ts";
|
|
11
|
+
import { MockRepository } from "./mock-repository.ts";
|
|
12
|
+
export class MockDatasource implements IDatasource {
|
|
13
|
+
createConnectionCalls = 0;
|
|
14
|
+
createCommandCalls: Array<IConnection | undefined> = [];
|
|
15
|
+
createRepositoryCalls: Array<IConnection | undefined> = [];
|
|
16
|
+
connection: IConnection;
|
|
17
|
+
command?: ICommand;
|
|
18
|
+
repository?: ICRUDRepository;
|
|
19
|
+
readonly repositories = new RepositoryFactory();
|
|
20
|
+
|
|
21
|
+
constructor(readonly provider = "mock") {
|
|
22
|
+
this.connection = new MockConnection();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
createConnection(): Promise<IConnection> {
|
|
26
|
+
this.createConnectionCalls += 1;
|
|
27
|
+
return Promise.resolve(this.connection);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async createCommand(connection?: IConnection): Promise<ICommand> {
|
|
31
|
+
this.createCommandCalls.push(connection);
|
|
32
|
+
if (connection === undefined) {
|
|
33
|
+
if (this.connection.isOpen) throw new DatasourceError("Connection is already open");
|
|
34
|
+
await this.connection.open();
|
|
35
|
+
}
|
|
36
|
+
return this.command ?? new MockCommand(connection ?? this.connection);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
createRepository<T>(type: Constructable<T>, connection?: IConnection): ICRUDRepository<T>;
|
|
40
|
+
createRepository(typeName: string, connection?: IConnection): ICRUDRepository;
|
|
41
|
+
createRepository<T>(
|
|
42
|
+
typeOrName: Constructable<T> | string,
|
|
43
|
+
connection?: IConnection,
|
|
44
|
+
): ICRUDRepository<T> {
|
|
45
|
+
this.createRepositoryCalls.push(connection);
|
|
46
|
+
if (typeof typeOrName === "string")
|
|
47
|
+
return this.repositories.create(typeOrName, connection ?? this.connection) as ICRUDRepository<T>;
|
|
48
|
+
return (this.repository as ICRUDRepository<T> | undefined) ??
|
|
49
|
+
new MockRepository<T>(connection ?? this.connection, typeOrName);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
createReadonlyRepository<T>(
|
|
53
|
+
type: Constructable<T>,
|
|
54
|
+
connection?: IConnection,
|
|
55
|
+
): IReadonlyRepository<T>;
|
|
56
|
+
createReadonlyRepository(typeName: string, connection?: IConnection): IReadonlyRepository;
|
|
57
|
+
createReadonlyRepository<T>(
|
|
58
|
+
typeOrName: Constructable<T> | string,
|
|
59
|
+
connection?: IConnection,
|
|
60
|
+
): IReadonlyRepository<T> {
|
|
61
|
+
if (typeof typeOrName === "string")
|
|
62
|
+
return this.repositories.createReadonly(typeOrName, connection ?? this.connection) as IReadonlyRepository<T>;
|
|
63
|
+
return this.createRepository(typeOrName, connection);
|
|
64
|
+
}
|
|
65
|
+
}
|