@deterministic-code/datasources 0.0.0-stage → 0.1.1
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/dist/ArrayReader.d.ts +12 -0
- package/dist/BatchCommandIBulkWriteStrategy.d.ts +33 -0
- package/dist/BuiltRepository.d.ts +16 -0
- package/dist/BulkCRUDRepository.d.ts +17 -0
- package/dist/BulkCommand.d.ts +5 -0
- package/dist/BulkWriteEnrichment.d.ts +4 -0
- package/dist/CRUDRepository.d.ts +40 -0
- package/dist/CRUDRepositoryBuilder.d.ts +19 -0
- package/dist/CRUDRepositoryOptions.d.ts +7 -0
- package/dist/CRUDRepositoryStatements.d.ts +17 -0
- package/dist/CascadeDeleteEnrichmentStrategy.d.ts +7 -0
- package/dist/CascadeDeleteUpdateEnrichmentStrategy.d.ts +8 -0
- package/dist/CommandMiddlewareHost.d.ts +22 -0
- package/dist/ConsoleCommandMiddleware.d.ts +14 -0
- package/dist/CreateEnrichmentStrategy.d.ts +14 -0
- package/dist/Datasource.d.ts +30 -0
- package/dist/DatasourceError.d.ts +3 -0
- package/dist/DatasourceFactory.d.ts +12 -0
- package/dist/DatasourceOptions.d.ts +1 -0
- package/dist/DatasourceUrl.d.ts +12 -0
- package/dist/DatasourceUrlParser.d.ts +4 -0
- package/dist/DefaultCreateEnrichmentStrategy.d.ts +7 -0
- package/dist/DefaultReadonlyEnrichmentStrategy.d.ts +19 -0
- package/dist/DefaultUpdateEnrichmentStrategy.d.ts +7 -0
- package/dist/DefaultWriteEnrichmentStrategy.d.ts +21 -0
- package/dist/DeleteEnrichmentStrategy.d.ts +11 -0
- package/dist/DriverLoader.d.ts +5 -0
- package/dist/Enrichment.d.ts +13 -0
- package/dist/EnrichmentPropertyType.d.ts +7 -0
- package/dist/ExpectConsoleMiddleware.d.ts +15 -0
- package/dist/FirstResultReader.d.ts +19 -0
- package/dist/HashsetOptimizedReadonlyEnrichmentStrategy.d.ts +9 -0
- package/dist/IBulkWriteStrategy.d.ts +12 -0
- package/dist/ICRUDRepository.d.ts +12 -0
- package/dist/ICRUDRepositoryFactory.d.ts +7 -0
- package/dist/ICommand.d.ts +20 -0
- package/dist/ICommandMiddleware.d.ts +12 -0
- package/dist/IConnection.d.ts +12 -0
- package/dist/IDatasource.d.ts +18 -0
- package/dist/IDatasourceFactory.d.ts +5 -0
- package/dist/IDriver.d.ts +19 -0
- package/dist/IEnriched.d.ts +6 -0
- package/dist/IReader.d.ts +8 -0
- package/dist/IReadonlyEnrichmentStrategy.d.ts +7 -0
- package/dist/IReadonlyRepository.d.ts +11 -0
- package/dist/IRepository.d.ts +4 -0
- package/dist/IRepositoryFactory.d.ts +7 -0
- package/dist/IRepositoryTree.d.ts +4 -0
- package/dist/IRepositoryTreeNode.d.ts +7 -0
- package/dist/ITransaction.d.ts +8 -0
- package/dist/IUnitOfWork.d.ts +5 -0
- package/dist/IWriteEnrichmentStrategy.d.ts +7 -0
- package/dist/Information.d.ts +5 -0
- package/dist/IsolationLevel.d.ts +7 -0
- package/dist/LazyWriteEnrichmentStrategy.d.ts +4 -0
- package/dist/NestedToObjectEnrichmentStrategy.d.ts +10 -0
- package/dist/Parameter.d.ts +7 -0
- package/dist/ParameterDirection.d.ts +7 -0
- package/dist/ProviderCatalog.d.ts +7 -0
- package/dist/ProviderNotImplementedError.d.ts +4 -0
- package/dist/ProviderNotInstalledError.d.ts +4 -0
- package/dist/ReadonlyRepository.d.ts +59 -0
- package/dist/ReadonlyRepositoryBuilder.d.ts +12 -0
- package/dist/ReadonlyRepositoryMappingOptions.d.ts +14 -0
- package/dist/ReadonlyRepositoryStatements.d.ts +8 -0
- package/dist/RepositoryAccess.d.ts +11 -0
- package/dist/RepositoryFactory.d.ts +23 -0
- package/dist/RepositoryNotRegisteredError.d.ts +4 -0
- package/dist/RepositoryTree.d.ts +6 -0
- package/dist/RepositoryTreeNode.d.ts +9 -0
- package/dist/Response.d.ts +7 -0
- package/dist/Row.d.ts +2 -0
- package/dist/SingleCommandIBulkWriteStrategy.d.ts +11 -0
- package/dist/StatementMappers.d.ts +16 -0
- package/dist/StoredEnrichment.d.ts +11 -0
- package/dist/StoredProcedureBulkWriteStrategy.d.ts +27 -0
- package/dist/StreamingReader.d.ts +16 -0
- package/dist/UnitOfWorkTransaction.d.ts +12 -0
- package/dist/UpdateEnrichmentStrategy.d.ts +18 -0
- package/dist/WriteMode.d.ts +1 -0
- package/dist/builders/Field.d.ts +5 -0
- package/dist/builders/Scalar.d.ts +1 -0
- package/dist/builders/index.d.ts +2 -0
- package/dist/collectAsync.d.ts +1 -0
- package/dist/converters/Cell.d.ts +2 -0
- package/dist/converters/ChangeCasingConverter.d.ts +7 -0
- package/dist/converters/Constructable.d.ts +1 -0
- package/dist/converters/MetaDataRowTypeConverter.d.ts +14 -0
- package/dist/converters/PluralizerConverter.d.ts +4 -0
- package/dist/converters/RegexConverter.d.ts +7 -0
- package/dist/converters/ReplaceConverter.d.ts +7 -0
- package/dist/converters/RowTypeConverter.d.ts +10 -0
- package/dist/converters/ToLowerCaseConverter.d.ts +4 -0
- package/dist/converters/ToUpperCaseConverter.d.ts +4 -0
- package/dist/converters/TypeConverter.d.ts +5 -0
- package/dist/createCRUDRepositoryOptions.d.ts +7 -0
- package/dist/createReadonlyRepositoryMappingOptions.d.ts +6 -0
- package/dist/dotEnv.d.ts +5 -0
- package/dist/index.d.ts +119 -0
- package/dist/mappers/ChangeCasingMapper.d.ts +9 -0
- package/dist/mappers/DictionaryMapper.d.ts +8 -0
- package/dist/mappers/FlatToNestedMapper.d.ts +20 -0
- package/dist/mappers/IFlatToNestedMapper.d.ts +6 -0
- package/dist/mappers/IMapper.d.ts +4 -0
- package/dist/mappers/IdentityMapper.d.ts +5 -0
- package/dist/mappers/PluralizerMapper.d.ts +6 -0
- package/dist/mappers/RowTypeMapper.d.ts +6 -0
- package/dist/mappers/TransformConverterMapper.d.ts +5 -0
- package/dist/mappers/TransformMapper.d.ts +6 -0
- package/dist/mappers/TypeMap.d.ts +8 -0
- package/dist/mappers/TypeMapGroup.d.ts +5 -0
- package/dist/mocks/index.d.ts +9 -0
- package/dist/mocks/mock-command.d.ts +28 -0
- package/dist/mocks/mock-connection.d.ts +22 -0
- package/dist/mocks/mock-datasource.d.ts +24 -0
- package/dist/mocks/mock-driver.d.ts +15 -0
- package/dist/mocks/mock-reader.d.ts +14 -0
- package/dist/mocks/mock-repository.d.ts +42 -0
- package/dist/mocks/mock-select-statement.d.ts +10 -0
- package/dist/mocks/mock-transaction.d.ts +16 -0
- package/dist/mocks/mock-where.d.ts +8 -0
- package/dist/parametersToRecord.d.ts +2 -0
- package/dist/readerToAsyncIterable.d.ts +2 -0
- package/dist/splitStatements.d.ts +1 -0
- package/dist/statementParameters.d.ts +1 -0
- package/dist/statementUsesParameter.d.ts +1 -0
- package/dist/statements/Aggregate.d.ts +6 -0
- package/dist/statements/ArrayExpression.d.ts +5 -0
- package/dist/statements/BulkDeleteStatement.d.ts +11 -0
- package/dist/statements/BulkDeleteStatementTextRenderer.d.ts +4 -0
- package/dist/statements/BulkInsertStatement.d.ts +12 -0
- package/dist/statements/BulkInsertStatementTextRenderer.d.ts +4 -0
- package/dist/statements/BulkUpdateStatement.d.ts +16 -0
- package/dist/statements/BulkUpdateStatementTextRenderer.d.ts +8 -0
- package/dist/statements/CheckConstraint.d.ts +7 -0
- package/dist/statements/Cmp.d.ts +9 -0
- package/dist/statements/Column.d.ts +9 -0
- package/dist/statements/ColumnDefault.d.ts +5 -0
- package/dist/statements/Condition.d.ts +3 -0
- package/dist/statements/ConditionRenderer.d.ts +12 -0
- package/dist/statements/CreateIndexStatement.d.ts +10 -0
- package/dist/statements/CreateIndexStatementTextRenderer.d.ts +5 -0
- package/dist/statements/CreateTableStatement.d.ts +11 -0
- package/dist/statements/CreateTableStatementTextRenderer.d.ts +18 -0
- package/dist/statements/DefaultStatementTextRenderer.d.ts +5 -0
- package/dist/statements/DeleteStatement.d.ts +9 -0
- package/dist/statements/DeleteStatementTextRenderer.d.ts +7 -0
- package/dist/statements/ExecuteStoredProcedureStatement.d.ts +9 -0
- package/dist/statements/ExecuteStoredProcedureStatementTextRenderer.d.ts +4 -0
- package/dist/statements/ExpressionEvaluator.d.ts +5 -0
- package/dist/statements/ExpressionRenderer.d.ts +8 -0
- package/dist/statements/ForeignKey.d.ts +19 -0
- package/dist/statements/IBulkDeleteStatement.d.ts +3 -0
- package/dist/statements/IBulkInsertStatement.d.ts +3 -0
- package/dist/statements/IBulkUpdateStatement.d.ts +3 -0
- package/dist/statements/ICondition.d.ts +4 -0
- package/dist/statements/IConditionVisitor.d.ts +6 -0
- package/dist/statements/ICreateIndexStatement.d.ts +3 -0
- package/dist/statements/ICreateTableStatement.d.ts +3 -0
- package/dist/statements/IDeleteStatement.d.ts +5 -0
- package/dist/statements/IExecuteStoredProcedureStatement.d.ts +3 -0
- package/dist/statements/IExpression.d.ts +2 -0
- package/dist/statements/IInsertStatement.d.ts +3 -0
- package/dist/statements/IReturnStatement.d.ts +3 -0
- package/dist/statements/ISelectStatement.d.ts +5 -0
- package/dist/statements/IStatement.d.ts +4 -0
- package/dist/statements/IStatementVisitor.d.ts +26 -0
- package/dist/statements/ITableConstraint.d.ts +5 -0
- package/dist/statements/IUpdateStatement.d.ts +5 -0
- package/dist/statements/IWhere.d.ts +6 -0
- package/dist/statements/Identifier.d.ts +5 -0
- package/dist/statements/InsertStatement.d.ts +9 -0
- package/dist/statements/InsertStatementTextRenderer.d.ts +4 -0
- package/dist/statements/Join.d.ts +14 -0
- package/dist/statements/Literal.d.ts +6 -0
- package/dist/statements/Native.d.ts +5 -0
- package/dist/statements/NotNull.d.ts +4 -0
- package/dist/statements/Operator.d.ts +107 -0
- package/dist/statements/OrderBy.d.ts +10 -0
- package/dist/statements/PrimaryKey.d.ts +7 -0
- package/dist/statements/ReturnStatement.d.ts +9 -0
- package/dist/statements/ReturnStatementTextRenderer.d.ts +4 -0
- package/dist/statements/SelectInsertedIdStatement.d.ts +8 -0
- package/dist/statements/SelectInsertedIdStatementTextRenderer.d.ts +4 -0
- package/dist/statements/SelectStatement.d.ts +20 -0
- package/dist/statements/SelectStatementOptions.d.ts +15 -0
- package/dist/statements/SelectStatementTextRenderer.d.ts +19 -0
- package/dist/statements/StatementEvaluator.d.ts +4 -0
- package/dist/statements/StatementParser.d.ts +4 -0
- package/dist/statements/StatementRenderer.d.ts +42 -0
- package/dist/statements/StatementTextRenderer.d.ts +14 -0
- package/dist/statements/Subquery.d.ts +6 -0
- package/dist/statements/UniqueConstraint.d.ts +7 -0
- package/dist/statements/UpdateStatement.d.ts +14 -0
- package/dist/statements/UpdateStatementTextRenderer.d.ts +14 -0
- package/dist/statements/Where.d.ts +16 -0
- package/dist/statements/WhereText.d.ts +8 -0
- package/dist/statements/index.d.ts +75 -0
- package/dist/stubs/StubCommand.d.ts +15 -0
- package/dist/stubs/StubConnection.d.ts +13 -0
- package/dist/stubs/StubDatasource.d.ts +20 -0
- package/dist/stubs/StubReader.d.ts +11 -0
- package/dist/stubs/StubRepository.d.ts +22 -0
- package/dist/stubs/StubTransaction.d.ts +10 -0
- package/dist/stubs/createStubDatasource.d.ts +2 -0
- package/dist/stubs/index.d.ts +7 -0
- package/dist/stubs/notImplemented.d.ts +1 -0
- package/package.json +24 -4
- package/src/ArrayReader.test.ts +23 -0
- package/src/ArrayReader.ts +32 -0
- package/src/BatchCommandIBulkWriteStrategy.ts +228 -0
- package/src/BuiltRepository.ts +17 -0
- package/src/BulkCRUDRepository.test.ts +183 -0
- package/src/BulkCRUDRepository.ts +84 -0
- package/src/BulkCommand.ts +6 -0
- package/src/BulkWriteEnrichment.ts +19 -0
- package/src/BulkWriteStrategy.test.ts +293 -0
- package/src/CRUDRepository.test.ts +420 -0
- package/src/CRUDRepository.ts +264 -0
- package/src/CRUDRepositoryBuilder.ts +53 -0
- package/src/CRUDRepositoryOptions.test.ts +76 -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/Command.test.ts +105 -0
- package/src/CommandMiddlewareHost.test.ts +98 -0
- package/src/CommandMiddlewareHost.ts +113 -0
- package/src/Connection.test.ts +34 -0
- package/src/ConsoleCommandMiddleware.test.ts +149 -0
- package/src/ConsoleCommandMiddleware.ts +64 -0
- package/src/CreateEnrichmentStrategy.ts +82 -0
- package/src/Datasource.test.ts +63 -0
- package/src/Datasource.ts +152 -0
- package/src/DatasourceError.test.ts +10 -0
- package/src/DatasourceError.ts +6 -0
- package/src/DatasourceFactory.test.ts +159 -0
- package/src/DatasourceFactory.ts +86 -0
- package/src/DatasourceOptions.ts +1 -0
- package/src/DatasourceUrl.ts +37 -0
- package/src/DatasourceUrlParser.test.ts +173 -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.test.ts +79 -0
- package/src/ExpectConsoleMiddleware.ts +47 -0
- package/src/FirstResultReader.test.ts +43 -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.test.ts +13 -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.test.ts +110 -0
- package/src/ProviderCatalog.ts +21 -0
- package/src/ProviderNotImplementedError.test.ts +11 -0
- package/src/ProviderNotImplementedError.ts +9 -0
- package/src/ProviderNotInstalledError.test.ts +11 -0
- package/src/ProviderNotInstalledError.ts +9 -0
- package/src/ReadonlyRepository.test.ts +406 -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.test.ts +94 -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.test.ts +221 -0
- package/src/StatementMappers.ts +110 -0
- package/src/StoredEnrichment.ts +25 -0
- package/src/StoredProcedureBulkWriteStrategy.ts +164 -0
- package/src/StreamingReader.test.ts +126 -0
- package/src/StreamingReader.ts +64 -0
- package/src/Transaction.test.ts +37 -0
- package/src/UnitOfWorkTransaction.test.ts +43 -0
- package/src/UnitOfWorkTransaction.ts +50 -0
- package/src/UpdateEnrichmentStrategy.ts +97 -0
- package/src/UserViewCRUDRepository.test.ts +323 -0
- package/src/WriteMode.ts +1 -0
- package/src/builders/Field.ts +6 -0
- package/src/builders/Scalar.ts +1 -0
- package/src/builders/builders.test.ts +404 -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.test.ts +34 -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.test.ts +43 -0
- package/src/converters/PluralizerConverter.ts +67 -0
- package/src/converters/RegexConverter.test.ts +11 -0
- package/src/converters/RegexConverter.ts +14 -0
- package/src/converters/ReplaceConverter.test.ts +9 -0
- package/src/converters/ReplaceConverter.ts +6 -0
- package/src/converters/RowTypeConverter.test.ts +79 -0
- package/src/converters/RowTypeConverter.ts +33 -0
- package/src/converters/ToLowerCaseConverter.test.ts +9 -0
- package/src/converters/ToLowerCaseConverter.ts +4 -0
- package/src/converters/ToUpperCaseConverter.test.ts +9 -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.test.ts +21 -0
- package/src/dotEnv.ts +16 -0
- package/src/edgeCases.test.ts +485 -0
- package/src/index.ts +222 -0
- package/src/mappers/ChangeCasingMapper.test.ts +32 -0
- package/src/mappers/ChangeCasingMapper.ts +15 -0
- package/src/mappers/DictionaryMapper.test.ts +69 -0
- package/src/mappers/DictionaryMapper.ts +16 -0
- package/src/mappers/FlatToNestedMapper.test.ts +269 -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.test.ts +12 -0
- package/src/mappers/IdentityMapper.ts +6 -0
- package/src/mappers/PluralizerMapper.test.ts +40 -0
- package/src/mappers/PluralizerMapper.ts +9 -0
- package/src/mappers/RowTypeMapper.test.ts +12 -0
- package/src/mappers/RowTypeMapper.ts +13 -0
- package/src/mappers/TransformConverterMapper.test.ts +181 -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/mappers/transformMapper.test.ts +66 -0
- package/src/mocks/MockCommand.test.ts +75 -0
- package/src/mocks/MockConnection.test.ts +34 -0
- package/src/mocks/MockDatasource.test.ts +40 -0
- package/src/mocks/MockReader.test.ts +17 -0
- package/src/mocks/MockRepository.test.ts +32 -0
- package/src/mocks/MockSelectStatement.test.ts +11 -0
- package/src/mocks/MockTransaction.test.ts +17 -0
- package/src/mocks/MockWhere.test.ts +11 -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.test.ts +19 -0
- package/src/parametersToRecord.ts +11 -0
- package/src/public-surface.test.ts +23 -0
- package/src/readWithWhereClauseAndCustomFlatToNestedObjectMappingOptions.test.ts +126 -0
- package/src/readerToAsyncIterable.test.ts +39 -0
- package/src/readerToAsyncIterable.ts +11 -0
- package/src/repository.test.ts +410 -0
- package/src/repository.type.test.ts +29 -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.test.ts +11 -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/StatementCompile.test.ts +231 -0
- package/src/statements/StatementEvaluator.ts +5 -0
- package/src/statements/StatementParser.test.ts +304 -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.test.ts +99 -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/src/tests/contact/Address.ts +14 -0
- package/src/tests/contact/AddressType.ts +6 -0
- package/src/tests/contact/Base.ts +7 -0
- package/src/tests/contact/Contact.ts +12 -0
- package/src/tests/contact/ContactBase.ts +8 -0
- package/src/tests/contact/ContactChangeLog.ts +8 -0
- package/src/tests/contact/ContactGroup.ts +6 -0
- package/src/tests/contact/ContactGroupBase.ts +6 -0
- package/src/tests/contact/ContactGroupMember.ts +6 -0
- package/src/tests/contact/ContactSource.ts +6 -0
- package/src/tests/contact/ContactType.ts +6 -0
- package/src/tests/contact/ContactsService.test.ts +118 -0
- package/src/tests/contact/ContactsService.ts +32 -0
- package/src/tests/contact/ImportContactRequest.ts +4 -0
- package/src/tests/contact/ImportContactResult.ts +5 -0
- package/src/tests/contact/LegacyContact.ts +7 -0
- package/src/tests/contact/LegacyMigrationResult.ts +5 -0
- package/src/tests/contact/Phone.ts +9 -0
- package/src/tests/contact/PhoneType.ts +6 -0
- package/src/tests/contact/asContactsView.ts +63 -0
- package/src/tests/contact/contactColumns.ts +40 -0
- package/src/tests/contact/contactLookupIds.ts +32 -0
- package/src/tests/contact/contactLookups.ts +6 -0
- package/src/tests/contact/contactsParity.ts +63 -0
- package/src/tests/contact/contactsServiceOf.ts +38 -0
- package/src/tests/contact/contactsView.ts +31 -0
- package/src/tests/contact/expectContactsView.ts +23 -0
- package/src/tests/contact/extraContact.ts +61 -0
- package/src/tests/contact/logMapped.ts +5 -0
- package/src/tests/contact/seedContacts.ts +31 -0
- package/README.md +0 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
MockCommand,
|
|
4
|
+
MockConnection,
|
|
5
|
+
MockDatasource,
|
|
6
|
+
MockRepository,
|
|
7
|
+
Native,
|
|
8
|
+
untyped,
|
|
9
|
+
} from "../index.ts";
|
|
10
|
+
|
|
11
|
+
describe("MockDatasource", () => {
|
|
12
|
+
it("builds commands and repositories from a mock datasource", async () => {
|
|
13
|
+
const ds = new MockDatasource();
|
|
14
|
+
expect(ds.provider).toBe("mock");
|
|
15
|
+
expect(await ds.createConnection()).toBe(ds.connection);
|
|
16
|
+
const mockCommand = await ds.createCommand();
|
|
17
|
+
expect(mockCommand).toBeInstanceOf(MockCommand);
|
|
18
|
+
await mockCommand.executeNative(new Native(""));
|
|
19
|
+
await mockCommand.executeReaderNative(new Native(""));
|
|
20
|
+
const provided = new MockConnection();
|
|
21
|
+
expect((await ds.createCommand(provided)).connection).toBe(provided);
|
|
22
|
+
expect(ds.createRepository(untyped(), provided)).toBeInstanceOf(MockRepository);
|
|
23
|
+
expect(ds.createRepository(untyped())).toBeInstanceOf(MockRepository);
|
|
24
|
+
|
|
25
|
+
await ds.connection.close();
|
|
26
|
+
ds.command = new MockCommand(ds.connection);
|
|
27
|
+
ds.repository = new MockRepository(ds.connection);
|
|
28
|
+
expect(await ds.createCommand()).toBe(ds.command);
|
|
29
|
+
await expect(ds.createCommand()).rejects.toThrow("Connection is already open");
|
|
30
|
+
expect(ds.createRepository(untyped())).toBe(ds.repository);
|
|
31
|
+
expect(ds.createReadonlyRepository(untyped())).toBe(ds.repository);
|
|
32
|
+
|
|
33
|
+
const named = new MockDatasource("custom");
|
|
34
|
+
expect(named.provider).toBe("custom");
|
|
35
|
+
const customRepo = new MockRepository(named.connection);
|
|
36
|
+
named.repositories.register("Item", "items", () => customRepo, () => customRepo);
|
|
37
|
+
expect(named.createRepository("items")).toBe(customRepo);
|
|
38
|
+
expect(named.createReadonlyRepository("Item")).toBe(customRepo);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { MockReader } from "../index.ts";
|
|
3
|
+
|
|
4
|
+
describe("MockReader", () => {
|
|
5
|
+
it("walks mock reader rows and errors", async () => {
|
|
6
|
+
const reader = new MockReader(["x"]);
|
|
7
|
+
expect(await reader.next()).toBe(true);
|
|
8
|
+
expect(reader.current).toBe("x");
|
|
9
|
+
expect(await reader.next()).toBe(false);
|
|
10
|
+
expect(await reader.nextResult()).toBe(false);
|
|
11
|
+
expect(await Array.fromAsync(new MockReader(["x"]).read())).toEqual(["x"]);
|
|
12
|
+
await reader.dispose();
|
|
13
|
+
await reader[Symbol.asyncDispose]();
|
|
14
|
+
reader.nextError = new Error("next");
|
|
15
|
+
await expect(reader.next()).rejects.toThrow("next");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { collectAsync, MockConnection, MockSelectStatement, MockRepository, MockWhere } from "../index.ts";
|
|
3
|
+
|
|
4
|
+
describe("MockRepository", () => {
|
|
5
|
+
it("records repository CRUD and errors", async () => {
|
|
6
|
+
const repo = new MockRepository<{ id: number }>(new MockConnection());
|
|
7
|
+
expect(await repo.readSingle()).toBeUndefined();
|
|
8
|
+
repo.items = [{ id: 1 }, { id: 2 }];
|
|
9
|
+
expect(await repo.readSingle(new MockSelectStatement("id=1"))).toEqual({ id: 1 });
|
|
10
|
+
expect(await collectAsync(repo.read())).toEqual([{ id: 1 }, { id: 2 }]);
|
|
11
|
+
expect(await collectAsync(repo.read(new MockSelectStatement("all")))).toHaveLength(2);
|
|
12
|
+
expect(await repo.readSingle(new MockWhere("id=1"))).toEqual({ id: 1 });
|
|
13
|
+
expect(await collectAsync(repo.read(new MockWhere("all")))).toHaveLength(2);
|
|
14
|
+
expect(await repo.readSingleById(1)).toEqual({ id: 1 });
|
|
15
|
+
expect(await repo.create({ id: 3 })).toEqual({ id: 3 });
|
|
16
|
+
expect(
|
|
17
|
+
(await repo.update({ id: 3 }, new MockWhere("id=3"))).rowsAffected,
|
|
18
|
+
).toBe(1);
|
|
19
|
+
expect((await repo.delete({ id: 3 })).rowsAffected).toBe(1);
|
|
20
|
+
|
|
21
|
+
repo.readSingleError = new Error("gs");
|
|
22
|
+
await expect(repo.readSingle()).rejects.toThrow("gs");
|
|
23
|
+
repo.readError = new Error("g");
|
|
24
|
+
await expect(collectAsync(repo.read())).rejects.toThrow("g");
|
|
25
|
+
repo.addError = new Error("ad");
|
|
26
|
+
await expect(repo.create({ id: 0 })).rejects.toThrow("ad");
|
|
27
|
+
repo.updateError = new Error("up");
|
|
28
|
+
await expect(repo.update({ id: 0 })).rejects.toThrow("up");
|
|
29
|
+
repo.deleteError = new Error("del");
|
|
30
|
+
await expect(repo.delete({ id: 0 })).rejects.toThrow("del");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { DefaultStatementTextRenderer, MockSelectStatement } from "../index.ts";
|
|
3
|
+
|
|
4
|
+
describe("MockSelectStatement", () => {
|
|
5
|
+
it("tracks accept calls", () => {
|
|
6
|
+
const query = new MockSelectStatement("q");
|
|
7
|
+
expect(query.accept({ visit: () => "" })).toBe("q");
|
|
8
|
+
expect(query.acceptCalls).toBe(1);
|
|
9
|
+
expect(DefaultStatementTextRenderer.instance.render(query)).toBe("q");
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { MockConnection, MockTransaction } from "../index.ts";
|
|
3
|
+
|
|
4
|
+
describe("MockTransaction", () => {
|
|
5
|
+
it("records transaction commit and abort", async () => {
|
|
6
|
+
const connection = new MockConnection();
|
|
7
|
+
const txn = new MockTransaction(connection);
|
|
8
|
+
await txn.commit();
|
|
9
|
+
expect(txn.committed).toBe(true);
|
|
10
|
+
await txn.abort();
|
|
11
|
+
expect(txn.aborted).toBe(true);
|
|
12
|
+
txn.commitError = new Error("c");
|
|
13
|
+
await expect(txn.commit()).rejects.toThrow("c");
|
|
14
|
+
txn.abortError = new Error("a");
|
|
15
|
+
await expect(txn.abort()).rejects.toThrow("a");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { DefaultStatementTextRenderer, MockWhere } from "../index.ts";
|
|
3
|
+
|
|
4
|
+
describe("MockWhere", () => {
|
|
5
|
+
it("tracks accept calls", () => {
|
|
6
|
+
const where = new MockWhere("w");
|
|
7
|
+
expect(where.accept({ visit: () => "" })).toBe("w");
|
|
8
|
+
expect(where.acceptCalls).toBe(1);
|
|
9
|
+
expect(DefaultStatementTextRenderer.instance.render(where)).toBe("w");
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { columnType as identityColumnType } from "../IDriver.ts";
|
|
2
|
+
import type { DatasourceOptions } from "../DatasourceOptions.ts";
|
|
3
|
+
import type { ICommand } from "../ICommand.ts";
|
|
4
|
+
import type { IConnection } from "../IConnection.ts";
|
|
5
|
+
import type { IDriver } from "../IDriver.ts";
|
|
6
|
+
import type { ITransaction } from "../ITransaction.ts";
|
|
7
|
+
import type { IsolationLevel } from "../IsolationLevel.ts";
|
|
8
|
+
import type { Cell } from "../converters/Cell.ts";
|
|
9
|
+
import type { TypeConverter } from "../converters/TypeConverter.ts";
|
|
10
|
+
import { MockCommand } from "./mock-command.ts";
|
|
11
|
+
import { MockConnection } from "./mock-connection.ts";
|
|
12
|
+
import { MockTransaction } from "./mock-transaction.ts";
|
|
13
|
+
|
|
14
|
+
export class MockDriver implements IDriver {
|
|
15
|
+
rowTypeConverters: Record<string, TypeConverter<Cell, Cell>> = {};
|
|
16
|
+
columnType = identityColumnType;
|
|
17
|
+
connection = (_options?: DatasourceOptions): IConnection => new MockConnection();
|
|
18
|
+
command = (connection: IConnection): ICommand => new MockCommand(connection);
|
|
19
|
+
transaction = (
|
|
20
|
+
connection: IConnection,
|
|
21
|
+
isolation: IsolationLevel = "readCommitted",
|
|
22
|
+
): ITransaction => {
|
|
23
|
+
const txn = new MockTransaction(connection);
|
|
24
|
+
txn.isolation = isolation;
|
|
25
|
+
return txn;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { IReader } from "../IReader.ts";
|
|
2
|
+
import { readerToAsyncIterable } from "../readerToAsyncIterable.ts";
|
|
3
|
+
|
|
4
|
+
export class MockReader<T = unknown> implements IReader<T> {
|
|
5
|
+
current: T | undefined = undefined;
|
|
6
|
+
nextCalls = 0;
|
|
7
|
+
nextError?: unknown;
|
|
8
|
+
private index = -1;
|
|
9
|
+
|
|
10
|
+
constructor(public rows: readonly T[] = []) {}
|
|
11
|
+
|
|
12
|
+
async next(): Promise<boolean> {
|
|
13
|
+
this.nextCalls += 1;
|
|
14
|
+
if (this.nextError) {
|
|
15
|
+
throw this.nextError;
|
|
16
|
+
}
|
|
17
|
+
this.index += 1;
|
|
18
|
+
if (this.index < this.rows.length) {
|
|
19
|
+
this.current = this.rows[this.index];
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
this.current = undefined;
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
read(): AsyncIterable<T> {
|
|
27
|
+
return readerToAsyncIterable(this);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async nextResult(): Promise<boolean> {
|
|
31
|
+
this.current = undefined;
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async dispose(): Promise<void> {}
|
|
36
|
+
|
|
37
|
+
[Symbol.asyncDispose] = (): Promise<void> => this.dispose();
|
|
38
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Scalar } from "../builders/Scalar.ts";
|
|
2
|
+
import type { Cells } from "../converters/Cell.ts";
|
|
3
|
+
import type { Constructable } from "../converters/Constructable.ts";
|
|
4
|
+
import type { IConnection } from "../IConnection.ts";
|
|
5
|
+
import type { Parameter } from "../Parameter.ts";
|
|
6
|
+
import type { IExecuteStoredProcedureStatement } from "../statements/IExecuteStoredProcedureStatement.ts";
|
|
7
|
+
import type { ISelectStatement } from "../statements/ISelectStatement.ts";
|
|
8
|
+
import type { ICRUDRepository } from "../ICRUDRepository.ts";
|
|
9
|
+
import { ReadonlyRepository, untyped } from "../ReadonlyRepository.ts";
|
|
10
|
+
import type { ReadonlyRepositoryMappingOptions } from "../ReadonlyRepositoryMappingOptions.ts";
|
|
11
|
+
import type { Response } from "../Response.ts";
|
|
12
|
+
import type { IWhere } from "../statements/IWhere.ts";
|
|
13
|
+
|
|
14
|
+
export class MockRepository<T = unknown> extends ReadonlyRepository<T> implements ICRUDRepository<T> {
|
|
15
|
+
readonly ids: readonly string[] = [];
|
|
16
|
+
items: T[] = [];
|
|
17
|
+
readSingleCalls: Array<ISelectStatement | IWhere | IExecuteStoredProcedureStatement | undefined> = [];
|
|
18
|
+
readCalls: Array<ISelectStatement | IWhere | IExecuteStoredProcedureStatement | undefined> = [];
|
|
19
|
+
addCalls: T[] = [];
|
|
20
|
+
updateCalls: Array<{ item: T; byWhere?: IWhere }> = [];
|
|
21
|
+
deleteCalls: Array<{ item: T; byWhere?: IWhere }> = [];
|
|
22
|
+
readSingleError?: unknown;
|
|
23
|
+
readError?: unknown;
|
|
24
|
+
addError?: unknown;
|
|
25
|
+
updateError?: unknown;
|
|
26
|
+
deleteError?: unknown;
|
|
27
|
+
addResponse: Response = { result: undefined, rowsAffected: 1 };
|
|
28
|
+
updateResponse: Response = { result: undefined, rowsAffected: 1 };
|
|
29
|
+
deleteResponse: Response = { result: undefined, rowsAffected: 1 };
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
_connection: IConnection,
|
|
33
|
+
type: Constructable<T> = untyped<T>(),
|
|
34
|
+
) {
|
|
35
|
+
super(type);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async readSingle(
|
|
39
|
+
query?: ISelectStatement | IWhere | IExecuteStoredProcedureStatement,
|
|
40
|
+
_parameters?: Parameter[],
|
|
41
|
+
_options?: ReadonlyRepositoryMappingOptions<T>,
|
|
42
|
+
): Promise<T | undefined> {
|
|
43
|
+
this.readSingleCalls.push(query);
|
|
44
|
+
if (this.readSingleError) {
|
|
45
|
+
throw this.readSingleError;
|
|
46
|
+
}
|
|
47
|
+
return this.items[0];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async *read(
|
|
51
|
+
query?: ISelectStatement | IWhere | IExecuteStoredProcedureStatement,
|
|
52
|
+
_parameters?: Parameter[],
|
|
53
|
+
_options?: ReadonlyRepositoryMappingOptions<T>,
|
|
54
|
+
): AsyncIterable<T> {
|
|
55
|
+
this.readCalls.push(query);
|
|
56
|
+
if (this.readError) {
|
|
57
|
+
throw this.readError;
|
|
58
|
+
}
|
|
59
|
+
for (const item of this.items) {
|
|
60
|
+
yield item;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async create(item: T): Promise<T> {
|
|
65
|
+
this.addCalls.push(item);
|
|
66
|
+
if (this.addError) {
|
|
67
|
+
throw this.addError;
|
|
68
|
+
}
|
|
69
|
+
this.items.push(item);
|
|
70
|
+
this.addResponse = { result: item, rowsAffected: 1 };
|
|
71
|
+
return item;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async update(item: T, byWhere?: IWhere): Promise<Response> {
|
|
75
|
+
this.updateCalls.push({ item, byWhere });
|
|
76
|
+
if (this.updateError) {
|
|
77
|
+
throw this.updateError;
|
|
78
|
+
}
|
|
79
|
+
return this.updateResponse;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async delete(item: T, byWhere?: IWhere): Promise<Response> {
|
|
83
|
+
this.deleteCalls.push({ item, byWhere });
|
|
84
|
+
if (this.deleteError) {
|
|
85
|
+
throw this.deleteError;
|
|
86
|
+
}
|
|
87
|
+
return this.deleteResponse;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
readSingleById = (_id: Scalar | Cells): Promise<T | undefined> => this.readSingle();
|
|
91
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ISelectStatement } from "../statements/ISelectStatement.ts";
|
|
2
|
+
import type { IStatementVisitor } from "../statements/IStatementVisitor.ts";
|
|
3
|
+
import type { IWhere } from "../statements/IWhere.ts";
|
|
4
|
+
|
|
5
|
+
export class MockSelectStatement implements ISelectStatement {
|
|
6
|
+
acceptCalls = 0;
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
public text: string,
|
|
10
|
+
public where?: IWhere,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
accept(_visitor: IStatementVisitor): string {
|
|
14
|
+
this.acceptCalls += 1;
|
|
15
|
+
return this.text;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IConnection } from "../IConnection.ts";
|
|
2
|
+
import type { ITransaction } from "../ITransaction.ts";
|
|
3
|
+
import { IsolationLevel } from "../IsolationLevel.ts";
|
|
4
|
+
|
|
5
|
+
export class MockTransaction implements ITransaction {
|
|
6
|
+
commitCalls = 0;
|
|
7
|
+
abortCalls = 0;
|
|
8
|
+
commitError?: unknown;
|
|
9
|
+
abortError?: unknown;
|
|
10
|
+
committed = false;
|
|
11
|
+
aborted = false;
|
|
12
|
+
isolation: IsolationLevel = IsolationLevel.ReadCommitted;
|
|
13
|
+
|
|
14
|
+
constructor(readonly connection: IConnection) {}
|
|
15
|
+
|
|
16
|
+
async commit(): Promise<void> {
|
|
17
|
+
this.commitCalls += 1;
|
|
18
|
+
if (this.commitError) {
|
|
19
|
+
throw this.commitError;
|
|
20
|
+
}
|
|
21
|
+
this.committed = true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async abort(): Promise<void> {
|
|
25
|
+
this.abortCalls += 1;
|
|
26
|
+
if (this.abortError) {
|
|
27
|
+
throw this.abortError;
|
|
28
|
+
}
|
|
29
|
+
this.aborted = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IConditionVisitor } from "../statements/IConditionVisitor.ts";
|
|
2
|
+
import type { IWhere } from "../statements/IWhere.ts";
|
|
3
|
+
|
|
4
|
+
export class MockWhere implements IWhere {
|
|
5
|
+
acceptCalls = 0;
|
|
6
|
+
|
|
7
|
+
constructor(public text: string) {}
|
|
8
|
+
|
|
9
|
+
accept(_visitor: IConditionVisitor): string {
|
|
10
|
+
this.acceptCalls += 1;
|
|
11
|
+
return this.text;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { parametersToRecord } from "./index.ts";
|
|
3
|
+
|
|
4
|
+
describe("parametersToRecord", () => {
|
|
5
|
+
it("returns an empty record when parameters are omitted", () => {
|
|
6
|
+
expect(parametersToRecord()).toEqual({});
|
|
7
|
+
expect(parametersToRecord(null)).toEqual({});
|
|
8
|
+
expect(parametersToRecord(undefined)).toEqual({});
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("maps names to values", () => {
|
|
12
|
+
expect(
|
|
13
|
+
parametersToRecord([
|
|
14
|
+
{ name: "id", value: 1 },
|
|
15
|
+
{ name: "label", value: "a" },
|
|
16
|
+
]),
|
|
17
|
+
).toEqual({ id: 1, label: "a" });
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Parameter } from "./Parameter.ts";
|
|
2
|
+
|
|
3
|
+
export function parametersToRecord<T>(
|
|
4
|
+
parameters?: Parameter<T>[] | null,
|
|
5
|
+
): Record<string, T> {
|
|
6
|
+
if (!parameters) return {};
|
|
7
|
+
const record: Record<string, T> = {};
|
|
8
|
+
for (const parameter of parameters)
|
|
9
|
+
if (parameter.value !== undefined) record[parameter.name] = parameter.value;
|
|
10
|
+
return record;
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
const providers = join(dirname(fileURLToPath(import.meta.url)), "../../providers");
|
|
7
|
+
|
|
8
|
+
describe("provider public surface", () => {
|
|
9
|
+
it("exports only the provider", () => {
|
|
10
|
+
const names = readdirSync(providers, { withFileTypes: true })
|
|
11
|
+
.filter((entry) => entry.isDirectory() && entry.name !== "node_modules")
|
|
12
|
+
.map((entry) => entry.name);
|
|
13
|
+
expect(names.length).toBeGreaterThanOrEqual(11);
|
|
14
|
+
for (const name of names) {
|
|
15
|
+
const source = readFileSync(join(providers, name, "src/index.ts"), "utf8");
|
|
16
|
+
const match = source.match(
|
|
17
|
+
/^export \{ ([A-Za-z0-9]+) \} from "\.\/\1\.ts";\n$/,
|
|
18
|
+
);
|
|
19
|
+
expect(match, name).not.toBeNull();
|
|
20
|
+
expect(match?.[1]?.endsWith("Driver"), name).toBe(true);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|