@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,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,12 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { IdentityMapper } from "./IdentityMapper.ts";
|
|
3
|
+
|
|
4
|
+
describe("IdentityMapper", () => {
|
|
5
|
+
it("maps and reverses the same value", () => {
|
|
6
|
+
const mapper = new IdentityMapper<string>();
|
|
7
|
+
const mapped = mapper.map("contact");
|
|
8
|
+
const reversed = mapper.reverseMap("contact");
|
|
9
|
+
expect(mapped).toBe("contact");
|
|
10
|
+
expect(reversed).toBe("contact");
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { ChangeCasingMapper } from "./ChangeCasingMapper.ts";
|
|
3
|
+
import { PluralizerMapper } from "./PluralizerMapper.ts";
|
|
4
|
+
|
|
5
|
+
describe("PluralizerMapper", () => {
|
|
6
|
+
it("pluralizes and lowercases the table name", () => {
|
|
7
|
+
const mapper = new PluralizerMapper();
|
|
8
|
+
expect(mapper.map("User")).toBe("Users");
|
|
9
|
+
expect(mapper.reverseMap("Users")).toBe("User");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("maps contacts", () => {
|
|
13
|
+
const mapper = new PluralizerMapper();
|
|
14
|
+
const contact = mapper.map("Contact");
|
|
15
|
+
const address = mapper.map("Address");
|
|
16
|
+
expect(contact).toBe("Contacts");
|
|
17
|
+
expect(address).toBe("Addresses");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("reverse maps contacts", () => {
|
|
21
|
+
const mapper = new PluralizerMapper();
|
|
22
|
+
const contact = mapper.reverseMap("Contacts");
|
|
23
|
+
const address = mapper.reverseMap("Addresses");
|
|
24
|
+
expect(contact).toBe("Contact");
|
|
25
|
+
expect(address).toBe("Address");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("lowercases then pluralizes", () => {
|
|
29
|
+
const casing = new ChangeCasingMapper("pascalCase", "snakeCase");
|
|
30
|
+
const pluralizer = new PluralizerMapper();
|
|
31
|
+
const contact = pluralizer.map(casing.map("Contact"));
|
|
32
|
+
const address = pluralizer.map(casing.map("Address"));
|
|
33
|
+
const contactName = casing.reverseMap(pluralizer.reverseMap(contact));
|
|
34
|
+
const addressName = casing.reverseMap(pluralizer.reverseMap(address));
|
|
35
|
+
expect(contact).toBe("contacts");
|
|
36
|
+
expect(address).toBe("addresses");
|
|
37
|
+
expect(contactName).toBe("Contact");
|
|
38
|
+
expect(addressName).toBe("Address");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -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,12 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { MetaDataRowTypeConverter } from "../converters/MetaDataRowTypeConverter.ts";
|
|
3
|
+
import { RowTypeMapper } from "./RowTypeMapper.ts";
|
|
4
|
+
|
|
5
|
+
describe("RowTypeMapper", () => {
|
|
6
|
+
it("maps a flat row to T and back", () => {
|
|
7
|
+
const mapper = new RowTypeMapper<{ id: number; name: string }>(new MetaDataRowTypeConverter());
|
|
8
|
+
const row = { id: 1, name: "ada" };
|
|
9
|
+
expect(mapper.map(row)).toEqual(row);
|
|
10
|
+
expect(mapper.reverseMap(row)).toEqual(row);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -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,181 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { TypeConverter } from "../converters/TypeConverter.ts";
|
|
3
|
+
import { TransformConverterMapper } from "./TransformConverterMapper.ts";
|
|
4
|
+
|
|
5
|
+
class Wrap extends TypeConverter<string, string> {
|
|
6
|
+
convert = (from: string) => `[${from}]`;
|
|
7
|
+
reverseConvert = (to: string) => to.replace(/^\[|\]$/g, "");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe("TransformConverterMapper", () => {
|
|
11
|
+
it("converts both ways without a filter", () => {
|
|
12
|
+
const mapper = new TransformConverterMapper(new Wrap());
|
|
13
|
+
expect(mapper.map("ab")).toBe("[ab]");
|
|
14
|
+
expect(mapper.reverseMap("[ab]")).toBe("ab");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("converts when the filter is true", () => {
|
|
18
|
+
const mapper = new TransformConverterMapper(new Wrap(), (s) => s.includes("ab"));
|
|
19
|
+
expect(mapper.map("ab")).toBe("[ab]");
|
|
20
|
+
expect(mapper.reverseMap("[ab]")).toBe("ab");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("is identity when the filter is false", () => {
|
|
24
|
+
const mapper = new TransformConverterMapper(new Wrap(), (s) => s.includes("ab"));
|
|
25
|
+
expect(mapper.map("a")).toBe("a");
|
|
26
|
+
expect(mapper.reverseMap("[a]")).toBe("[a]");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
type Address = { street: string; city: string; country: string };
|
|
30
|
+
type Contact = { email: string; phone: string; address: Address };
|
|
31
|
+
type User = { username: string; displayName: string; contact: Contact };
|
|
32
|
+
type Payload = string[] | User;
|
|
33
|
+
|
|
34
|
+
class UserFromCells extends TypeConverter<Payload, Payload> {
|
|
35
|
+
convert = (from: Payload): Payload => {
|
|
36
|
+
if (!Array.isArray(from)) return from;
|
|
37
|
+
const [username, displayName, email, phone, street, city, country] = from;
|
|
38
|
+
if (from.length !== 7) throw new Error("expected 7 cells");
|
|
39
|
+
return {
|
|
40
|
+
username,
|
|
41
|
+
displayName,
|
|
42
|
+
contact: { email, phone, address: { street, city, country } },
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
reverseConvert = (to: Payload): Payload =>
|
|
46
|
+
Array.isArray(to)
|
|
47
|
+
? to
|
|
48
|
+
: [
|
|
49
|
+
to.username,
|
|
50
|
+
to.displayName,
|
|
51
|
+
to.contact.email,
|
|
52
|
+
to.contact.phone,
|
|
53
|
+
to.contact.address.street,
|
|
54
|
+
to.contact.address.city,
|
|
55
|
+
to.contact.address.country,
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
it("expands flat cells into a nested user", () => {
|
|
60
|
+
const cells = [
|
|
61
|
+
"ada",
|
|
62
|
+
"Ada Lovelace",
|
|
63
|
+
"ada@example.com",
|
|
64
|
+
"+44 20 7946 0958",
|
|
65
|
+
"10 Downing St",
|
|
66
|
+
"London",
|
|
67
|
+
"UK",
|
|
68
|
+
];
|
|
69
|
+
const expected: User = {
|
|
70
|
+
username: "ada",
|
|
71
|
+
displayName: "Ada Lovelace",
|
|
72
|
+
contact: {
|
|
73
|
+
email: "ada@example.com",
|
|
74
|
+
phone: "+44 20 7946 0958",
|
|
75
|
+
address: { street: "10 Downing St", city: "London", country: "UK" },
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const mapper = new TransformConverterMapper(new UserFromCells());
|
|
79
|
+
expect(mapper.map(cells)).toEqual(expected);
|
|
80
|
+
expect(mapper.reverseMap(expected)).toEqual(cells);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
type Account = {
|
|
84
|
+
id: number;
|
|
85
|
+
username: string;
|
|
86
|
+
displayName: string;
|
|
87
|
+
isEnabled: boolean;
|
|
88
|
+
created: Date;
|
|
89
|
+
contact: Contact;
|
|
90
|
+
};
|
|
91
|
+
type AccountPayload = string[] | Account;
|
|
92
|
+
|
|
93
|
+
class AccountFromCells extends TypeConverter<AccountPayload, AccountPayload> {
|
|
94
|
+
convert = (from: AccountPayload): AccountPayload => {
|
|
95
|
+
if (!Array.isArray(from)) return from;
|
|
96
|
+
const [id, username, displayName, enabled, created, email, phone, street, city] = from;
|
|
97
|
+
if (from.length !== 10) throw new Error("expected 10 cells");
|
|
98
|
+
return {
|
|
99
|
+
id: Number(id),
|
|
100
|
+
username,
|
|
101
|
+
displayName,
|
|
102
|
+
isEnabled: enabled === "1",
|
|
103
|
+
created: new Date(created),
|
|
104
|
+
contact: { email, phone, address: { street, city, country: "" } },
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
reverseConvert = (to: AccountPayload): AccountPayload =>
|
|
108
|
+
Array.isArray(to)
|
|
109
|
+
? to
|
|
110
|
+
: [
|
|
111
|
+
String(to.id),
|
|
112
|
+
to.username,
|
|
113
|
+
to.displayName,
|
|
114
|
+
to.isEnabled ? "1" : "0",
|
|
115
|
+
to.created.toISOString(),
|
|
116
|
+
to.contact.email,
|
|
117
|
+
to.contact.phone,
|
|
118
|
+
to.contact.address.street,
|
|
119
|
+
to.contact.address.city,
|
|
120
|
+
"",
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const isEnabled = (payload: AccountPayload) =>
|
|
125
|
+
Array.isArray(payload) ? payload[3] === "1" : payload.isEnabled;
|
|
126
|
+
|
|
127
|
+
it("converts types and filters rows", () => {
|
|
128
|
+
const ada = [
|
|
129
|
+
"7",
|
|
130
|
+
"ada",
|
|
131
|
+
"Ada Lovelace",
|
|
132
|
+
"1",
|
|
133
|
+
"2020-01-02T03:04:05.000Z",
|
|
134
|
+
"ada@example.com",
|
|
135
|
+
"+44",
|
|
136
|
+
"10 Downing St",
|
|
137
|
+
"London",
|
|
138
|
+
"secret-note",
|
|
139
|
+
];
|
|
140
|
+
const guest = [
|
|
141
|
+
"0",
|
|
142
|
+
"guest",
|
|
143
|
+
"Guest",
|
|
144
|
+
"0",
|
|
145
|
+
"2020-01-01T00:00:00.000Z",
|
|
146
|
+
"guest@example.com",
|
|
147
|
+
"",
|
|
148
|
+
"1 Road",
|
|
149
|
+
"Paris",
|
|
150
|
+
"ignore-me",
|
|
151
|
+
];
|
|
152
|
+
const expected: Account = {
|
|
153
|
+
id: 7,
|
|
154
|
+
username: "ada",
|
|
155
|
+
displayName: "Ada Lovelace",
|
|
156
|
+
isEnabled: true,
|
|
157
|
+
created: new Date("2020-01-02T03:04:05.000Z"),
|
|
158
|
+
contact: {
|
|
159
|
+
email: "ada@example.com",
|
|
160
|
+
phone: "+44",
|
|
161
|
+
address: { street: "10 Downing St", city: "London", country: "" },
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
const mapper = new TransformConverterMapper(new AccountFromCells(), isEnabled);
|
|
165
|
+
expect(mapper.map(ada)).toEqual(expected);
|
|
166
|
+
expect(mapper.reverseMap(expected)).toEqual([
|
|
167
|
+
"7",
|
|
168
|
+
"ada",
|
|
169
|
+
"Ada Lovelace",
|
|
170
|
+
"1",
|
|
171
|
+
"2020-01-02T03:04:05.000Z",
|
|
172
|
+
"ada@example.com",
|
|
173
|
+
"+44",
|
|
174
|
+
"10 Downing St",
|
|
175
|
+
"London",
|
|
176
|
+
"",
|
|
177
|
+
]);
|
|
178
|
+
expect(mapper.map(guest)).toBe(guest);
|
|
179
|
+
expect(mapper.reverseMap(guest)).toBe(guest);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -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,66 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { TransformMapper } from "./TransformMapper.ts";
|
|
3
|
+
|
|
4
|
+
type User = { id: number; name: string };
|
|
5
|
+
type Contacts = { email: string; phone: string };
|
|
6
|
+
type Nested = { user: User; contacts: Contacts };
|
|
7
|
+
type Flat = {
|
|
8
|
+
userId: number;
|
|
9
|
+
userName: string;
|
|
10
|
+
contactEmail: string;
|
|
11
|
+
contactPhone: string;
|
|
12
|
+
};
|
|
13
|
+
type Contact = { name: string; email: string };
|
|
14
|
+
type ContactRow = { contactName: string; contactEmail: string };
|
|
15
|
+
|
|
16
|
+
describe("TransformMapper", () => {
|
|
17
|
+
it("flattens and unflattens user and contacts", () => {
|
|
18
|
+
const nested: Nested = {
|
|
19
|
+
user: { id: 1, name: "Ada" },
|
|
20
|
+
contacts: { email: "ada@x.dev", phone: "555" },
|
|
21
|
+
};
|
|
22
|
+
const mapper = new TransformMapper<Nested, Flat>(
|
|
23
|
+
(n) => ({
|
|
24
|
+
userId: n.user.id,
|
|
25
|
+
userName: n.user.name,
|
|
26
|
+
contactEmail: n.contacts.email,
|
|
27
|
+
contactPhone: n.contacts.phone,
|
|
28
|
+
}),
|
|
29
|
+
(f) => ({
|
|
30
|
+
user: { id: f.userId, name: f.userName },
|
|
31
|
+
contacts: { email: f.contactEmail, phone: f.contactPhone },
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
const flat = mapper.map(nested);
|
|
35
|
+
expect(flat).toEqual({
|
|
36
|
+
userId: 1,
|
|
37
|
+
userName: "Ada",
|
|
38
|
+
contactEmail: "ada@x.dev",
|
|
39
|
+
contactPhone: "555",
|
|
40
|
+
});
|
|
41
|
+
expect(mapper.reverseMap(flat)).toEqual(nested);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("prefixes a contact field", () => {
|
|
45
|
+
const mapper = new TransformMapper<string, string>(
|
|
46
|
+
(name) => `contact_${name}`,
|
|
47
|
+
(name) => name.slice("contact_".length),
|
|
48
|
+
);
|
|
49
|
+
const mapped = mapper.map("email");
|
|
50
|
+
const reversed = mapper.reverseMap(mapped);
|
|
51
|
+
expect(mapped).toBe("contact_email");
|
|
52
|
+
expect(reversed).toBe("email");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("maps a contact name and email", () => {
|
|
56
|
+
const contact: Contact = { name: "Ada", email: "ada@x.dev" };
|
|
57
|
+
const mapper = new TransformMapper<Contact, ContactRow>(
|
|
58
|
+
(item) => ({ contactName: item.name, contactEmail: item.email }),
|
|
59
|
+
(row) => ({ name: row.contactName, email: row.contactEmail }),
|
|
60
|
+
);
|
|
61
|
+
const mapped = mapper.map(contact);
|
|
62
|
+
const reversed = mapper.reverseMap(mapped);
|
|
63
|
+
expect(mapped).toEqual({ contactName: "Ada", contactEmail: "ada@x.dev" });
|
|
64
|
+
expect(reversed).toEqual(contact);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
execute,
|
|
4
|
+
executeReader,
|
|
5
|
+
ExecuteStoredProcedureStatement,
|
|
6
|
+
Native,
|
|
7
|
+
MockCommand,
|
|
8
|
+
MockConnection,
|
|
9
|
+
MockReader,
|
|
10
|
+
} from "../index.ts";
|
|
11
|
+
|
|
12
|
+
describe("MockCommand", () => {
|
|
13
|
+
it("records command execute paths", async () => {
|
|
14
|
+
const connection = new MockConnection();
|
|
15
|
+
const command = new MockCommand(connection);
|
|
16
|
+
command.response = { result: 1, rowsAffected: 2 };
|
|
17
|
+
command.reader = new MockReader([{ id: 1 }]);
|
|
18
|
+
expect(await command.executeNative(new Native("insert"), [{ name: "id", value: 1 }])).toEqual({
|
|
19
|
+
result: 1,
|
|
20
|
+
rowsAffected: 2,
|
|
21
|
+
});
|
|
22
|
+
expect(command.executeCalls).toHaveLength(1);
|
|
23
|
+
const reader = await command.executeReaderNative(new Native(""));
|
|
24
|
+
expect(reader).toBe(command.reader);
|
|
25
|
+
|
|
26
|
+
command.reader = {
|
|
27
|
+
current: undefined,
|
|
28
|
+
next: async () => false,
|
|
29
|
+
nextResult: async () => false,
|
|
30
|
+
async *read() {
|
|
31
|
+
while (await this.next()) {
|
|
32
|
+
if (this.current !== undefined) yield this.current;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
dispose: async () => {},
|
|
36
|
+
};
|
|
37
|
+
expect(await command.executeReaderNative(new Native("plain"))).toBe(command.reader);
|
|
38
|
+
|
|
39
|
+
command.executeError = new Error("exec");
|
|
40
|
+
await expect(command.executeNative(new Native(""))).rejects.toThrow("exec");
|
|
41
|
+
command.executeReaderError = new Error("read");
|
|
42
|
+
await expect(command.executeReaderNative(new Native("x"))).rejects.toThrow("read");
|
|
43
|
+
|
|
44
|
+
command.executeError = undefined;
|
|
45
|
+
command.executeReaderError = undefined;
|
|
46
|
+
const fields = [{ name: "id", value: 1 }];
|
|
47
|
+
const statement = new ExecuteStoredProcedureStatement("save", fields);
|
|
48
|
+
await execute(command, statement, fields);
|
|
49
|
+
expect(command.executeCalls.at(-1)).toEqual({
|
|
50
|
+
text: "CALL save($id)",
|
|
51
|
+
parameters: fields,
|
|
52
|
+
});
|
|
53
|
+
await executeReader(command, statement, fields);
|
|
54
|
+
expect(command.executeReaderCalls.at(-1)).toEqual({
|
|
55
|
+
text: "CALL save($id)",
|
|
56
|
+
parameters: fields,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("runs command middleware on mock commands", async () => {
|
|
61
|
+
const connection = new MockConnection();
|
|
62
|
+
const command = new MockCommand(connection);
|
|
63
|
+
const seen: string[] = [];
|
|
64
|
+
command.addMiddleware({
|
|
65
|
+
beforeCommand: (text) => {
|
|
66
|
+
seen.push(`before:${text}`);
|
|
67
|
+
},
|
|
68
|
+
afterCommand: (text) => {
|
|
69
|
+
seen.push(`after:${text}`);
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
await command.executeNative(new Native("insert"));
|
|
73
|
+
expect(seen).toEqual(["before:insert", "after:insert"]);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { IsolationLevel, MockCommand, MockConnection, MockTransaction } from "../index.ts";
|
|
3
|
+
|
|
4
|
+
describe("MockConnection", () => {
|
|
5
|
+
it("records connection operations and errors", async () => {
|
|
6
|
+
const connection = new MockConnection();
|
|
7
|
+
await connection.open();
|
|
8
|
+
expect(connection.openCalls).toBe(1);
|
|
9
|
+
expect(connection.isOpen).toBe(true);
|
|
10
|
+
const txn = await connection.startTransaction(IsolationLevel.ReadUncommitted);
|
|
11
|
+
expect(txn).toBe(connection.transaction);
|
|
12
|
+
expect(txn.isolation).toBe(IsolationLevel.ReadUncommitted);
|
|
13
|
+
await connection.close();
|
|
14
|
+
expect(connection.isOpen).toBe(false);
|
|
15
|
+
|
|
16
|
+
connection.openError = new Error("open-fail");
|
|
17
|
+
await expect(connection.open()).rejects.toThrow("open-fail");
|
|
18
|
+
connection.closeError = new Error("close-fail");
|
|
19
|
+
await expect(connection.close()).rejects.toThrow("close-fail");
|
|
20
|
+
connection.startTransactionError = new Error("tx-fail");
|
|
21
|
+
await expect(connection.startTransaction()).rejects.toThrow("tx-fail");
|
|
22
|
+
|
|
23
|
+
const customTxn = new MockTransaction(connection);
|
|
24
|
+
const withTxn = new MockConnection(customTxn);
|
|
25
|
+
expect(withTxn.transaction).toBe(customTxn);
|
|
26
|
+
const opened = new MockConnection();
|
|
27
|
+
await opened.open();
|
|
28
|
+
await expect(opened.open()).rejects.toThrow("already open");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("creates a command when none is assigned", () => {
|
|
32
|
+
expect(new MockConnection().createCommand()).toBeInstanceOf(MockCommand);
|
|
33
|
+
});
|
|
34
|
+
});
|