@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,42 @@
|
|
|
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
|
+
import { notImplemented } from "./notImplemented.ts";
|
|
14
|
+
|
|
15
|
+
export class StubRepository<T = unknown> extends ReadonlyRepository<T> implements ICRUDRepository<T> {
|
|
16
|
+
readonly ids: readonly string[] = [];
|
|
17
|
+
constructor(
|
|
18
|
+
readonly provider: string,
|
|
19
|
+
_connection: IConnection,
|
|
20
|
+
type: Constructable<T> = untyped<T>(),
|
|
21
|
+
) {
|
|
22
|
+
super(type);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async *read(
|
|
26
|
+
_query?: ISelectStatement | IWhere | IExecuteStoredProcedureStatement,
|
|
27
|
+
_parameters?: Parameter[],
|
|
28
|
+
_options?: ReadonlyRepositoryMappingOptions<T>,
|
|
29
|
+
): AsyncIterable<T> {
|
|
30
|
+
notImplemented(this.provider);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
create = async (_item: T): Promise<T> => notImplemented(this.provider);
|
|
34
|
+
|
|
35
|
+
update = async (_item: T, _byWhere?: IWhere): Promise<Response> =>
|
|
36
|
+
notImplemented(this.provider);
|
|
37
|
+
|
|
38
|
+
delete = async (_item: T, _byWhere?: IWhere): Promise<Response> =>
|
|
39
|
+
notImplemented(this.provider);
|
|
40
|
+
|
|
41
|
+
readSingleById = (_id: Scalar | Cells): Promise<T | undefined> => notImplemented(this.provider);
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IConnection } from "../IConnection.ts";
|
|
2
|
+
import type { ITransaction } from "../ITransaction.ts";
|
|
3
|
+
import { IsolationLevel } from "../IsolationLevel.ts";
|
|
4
|
+
import { notImplemented } from "./notImplemented.ts";
|
|
5
|
+
|
|
6
|
+
export class StubTransaction implements ITransaction {
|
|
7
|
+
readonly isolation = IsolationLevel.ReadCommitted;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
readonly provider: string,
|
|
11
|
+
readonly connection: IConnection,
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
commit = async (): Promise<void> => notImplemented(this.provider);
|
|
15
|
+
|
|
16
|
+
abort = async (): Promise<void> => notImplemented(this.provider);
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createStubDatasource } from "./createStubDatasource.ts";
|
|
2
|
+
export { StubCommand } from "./StubCommand.ts";
|
|
3
|
+
export { StubConnection } from "./StubConnection.ts";
|
|
4
|
+
export { StubDatasource } from "./StubDatasource.ts";
|
|
5
|
+
export { StubReader } from "./StubReader.ts";
|
|
6
|
+
export { StubRepository } from "./StubRepository.ts";
|
|
7
|
+
export { StubTransaction } from "./StubTransaction.ts";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AddressType } from "./AddressType.ts";
|
|
2
|
+
import { Base } from "./Base.ts";
|
|
3
|
+
import { Contact } from "./Contact.ts";
|
|
4
|
+
|
|
5
|
+
export class Address extends Base {
|
|
6
|
+
Contact = new Contact();
|
|
7
|
+
AddressType = new AddressType();
|
|
8
|
+
Line1 = "";
|
|
9
|
+
Line2: string | null = null;
|
|
10
|
+
City = "";
|
|
11
|
+
Region: string | null = null;
|
|
12
|
+
PostalCode: string | null = null;
|
|
13
|
+
Country: string | null = null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Address } from "./Address.ts";
|
|
2
|
+
import { ContactBase } from "./ContactBase.ts";
|
|
3
|
+
import { ContactSource } from "./ContactSource.ts";
|
|
4
|
+
import { ContactType } from "./ContactType.ts";
|
|
5
|
+
import { Phone } from "./Phone.ts";
|
|
6
|
+
|
|
7
|
+
export class Contact extends ContactBase {
|
|
8
|
+
ContactSource = new ContactSource();
|
|
9
|
+
ContactType = new ContactType();
|
|
10
|
+
Addresses: Address[] = [];
|
|
11
|
+
Phones: Phone[] = [];
|
|
12
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { MemoryDriver } from "@datasources/memory";
|
|
3
|
+
import { collectAsync } from "../../collectAsync.ts";
|
|
4
|
+
import { CRUDRepository } from "../../CRUDRepository.ts";
|
|
5
|
+
import { ReadonlyRepository } from "../../ReadonlyRepository.ts";
|
|
6
|
+
import type { Constructable } from "../../converters/Constructable.ts";
|
|
7
|
+
import type { IConnection } from "../../IConnection.ts";
|
|
8
|
+
import type { Scalar } from "../../builders/Scalar.ts";
|
|
9
|
+
import { Address } from "./Address.ts";
|
|
10
|
+
import { AddressType } from "./AddressType.ts";
|
|
11
|
+
import { columns, contactEntity, snake } from "./contactColumns.ts";
|
|
12
|
+
import { Contact } from "./Contact.ts";
|
|
13
|
+
import { ContactSource } from "./ContactSource.ts";
|
|
14
|
+
import { ContactType } from "./ContactType.ts";
|
|
15
|
+
import { ContactsService } from "./ContactsService.ts";
|
|
16
|
+
import { Phone } from "./Phone.ts";
|
|
17
|
+
import { PhoneType } from "./PhoneType.ts";
|
|
18
|
+
|
|
19
|
+
describe("ContactsService", () => {
|
|
20
|
+
it("fills names and child lists", async () => {
|
|
21
|
+
const person: Record<string, Scalar> = { name: "person" };
|
|
22
|
+
const types = await setup([person]);
|
|
23
|
+
const typesRepo = createLookupRepo(ContactType, types);
|
|
24
|
+
const source: Record<string, Scalar> = { name: "import" };
|
|
25
|
+
const sources = await setup([source]);
|
|
26
|
+
const sourcesRepo = createLookupRepo(ContactSource, sources);
|
|
27
|
+
const home: Record<string, Scalar> = { name: "Home" };
|
|
28
|
+
const addressTypes = await setup([home]);
|
|
29
|
+
const addressTypesRepo = createLookupRepo(AddressType, addressTypes);
|
|
30
|
+
const work: Record<string, Scalar> = { name: "Work" };
|
|
31
|
+
const phoneTypes = await setup([work]);
|
|
32
|
+
const phoneTypesRepo = createLookupRepo(PhoneType, phoneTypes);
|
|
33
|
+
const connection = await setup();
|
|
34
|
+
const contactsRepo = new CRUDRepository(connection, {
|
|
35
|
+
type: Contact,
|
|
36
|
+
entityMapper: contactEntity,
|
|
37
|
+
propertyMappings: columns,
|
|
38
|
+
ids: ["Id"],
|
|
39
|
+
});
|
|
40
|
+
const addressesRepo = new CRUDRepository(connection, {
|
|
41
|
+
type: Address,
|
|
42
|
+
entityMapper: snake,
|
|
43
|
+
propertyMappings: columns,
|
|
44
|
+
ids: ["Id"],
|
|
45
|
+
});
|
|
46
|
+
const phonesRepo = new CRUDRepository(connection, {
|
|
47
|
+
type: Phone,
|
|
48
|
+
entityMapper: snake,
|
|
49
|
+
propertyMappings: columns,
|
|
50
|
+
ids: ["Id"],
|
|
51
|
+
});
|
|
52
|
+
const service = ContactsService.open(
|
|
53
|
+
contactsRepo,
|
|
54
|
+
typesRepo,
|
|
55
|
+
sourcesRepo,
|
|
56
|
+
addressTypesRepo,
|
|
57
|
+
phoneTypesRepo,
|
|
58
|
+
addressesRepo,
|
|
59
|
+
phonesRepo,
|
|
60
|
+
);
|
|
61
|
+
const other = await service.create(Object.assign(new Contact(), {
|
|
62
|
+
FirstName: "Other",
|
|
63
|
+
ContactType: Object.assign(new ContactType(), { Id: person.id }),
|
|
64
|
+
ContactSource: Object.assign(new ContactSource(), { Id: source.id }),
|
|
65
|
+
}));
|
|
66
|
+
expect(other.Id).toBeGreaterThan(0);
|
|
67
|
+
const stray = await addressesRepo.create(Object.assign(new Address(), {
|
|
68
|
+
Contact: Object.assign(new Contact(), { Id: other.Id }),
|
|
69
|
+
Line1: "other",
|
|
70
|
+
City: "x",
|
|
71
|
+
AddressType: Object.assign(new AddressType(), { Id: home.id }),
|
|
72
|
+
}));
|
|
73
|
+
expect(stray.Id).toBeGreaterThan(0);
|
|
74
|
+
const created = await service.create(Object.assign(new Contact(), {
|
|
75
|
+
ContactType: Object.assign(new ContactType(), { Id: person.id }),
|
|
76
|
+
ContactSource: Object.assign(new ContactSource(), { Id: source.id }),
|
|
77
|
+
FirstName: "Ada",
|
|
78
|
+
Addresses: [Object.assign(new Address(), {
|
|
79
|
+
Line1: "1 Main",
|
|
80
|
+
City: "Paris",
|
|
81
|
+
AddressType: Object.assign(new AddressType(), { Id: home.id }),
|
|
82
|
+
})],
|
|
83
|
+
Phones: [Object.assign(new Phone(), {
|
|
84
|
+
Number: "555",
|
|
85
|
+
PhoneType: Object.assign(new PhoneType(), { Id: work.id }),
|
|
86
|
+
})],
|
|
87
|
+
}));
|
|
88
|
+
expect(created.Id).toBeGreaterThan(0);
|
|
89
|
+
const contact = (await collectAsync(service.read())).find((item) => item.FirstName === "Ada");
|
|
90
|
+
expect(contact?.Id).toBe(created.Id);
|
|
91
|
+
expect(contact?.Id).not.toBe(other.Id);
|
|
92
|
+
expect(contact?.ContactType.Name).toBe("person");
|
|
93
|
+
expect(contact?.ContactSource.Name).toBe("import");
|
|
94
|
+
expect(contact?.Addresses).toHaveLength(1);
|
|
95
|
+
expect(contact?.Addresses[0]?.Id).toBeGreaterThan(0);
|
|
96
|
+
expect(contact?.Addresses[0]?.Line1).toBe("1 Main");
|
|
97
|
+
expect(contact?.Addresses[0]?.AddressType.Name).toBe("Home");
|
|
98
|
+
expect(contact?.Phones[0]?.Id).toBeGreaterThan(0);
|
|
99
|
+
expect(contact?.Phones[0]?.Number).toBe("555");
|
|
100
|
+
expect(contact?.Phones[0]?.PhoneType.Name).toBe("Work");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const createLookupRepo = <T extends object>(type: Constructable<T>, connection: IConnection) =>
|
|
105
|
+
new ReadonlyRepository(connection, { type, entityMapper: snake, propertyMappings: columns });
|
|
106
|
+
|
|
107
|
+
const setup = async (rows: Record<string, Scalar>[] = []): Promise<IConnection> => {
|
|
108
|
+
const connection = new MemoryDriver().connection();
|
|
109
|
+
await connection.open();
|
|
110
|
+
for (const row of rows) {
|
|
111
|
+
const response = await connection.createCommand().execute(
|
|
112
|
+
"insert",
|
|
113
|
+
Object.entries(row).map(([name, value]) => ({ name, value })),
|
|
114
|
+
);
|
|
115
|
+
row.id = response.result as number;
|
|
116
|
+
}
|
|
117
|
+
return connection;
|
|
118
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ICRUDRepository } from "../../ICRUDRepository.ts";
|
|
2
|
+
import type { IEnriched } from "../../IEnriched.ts";
|
|
3
|
+
import type { IReadonlyRepository } from "../../IReadonlyRepository.ts";
|
|
4
|
+
import type { Address } from "./Address.ts";
|
|
5
|
+
import type { AddressType } from "./AddressType.ts";
|
|
6
|
+
import type { Contact } from "./Contact.ts";
|
|
7
|
+
import type { ContactSource } from "./ContactSource.ts";
|
|
8
|
+
import type { ContactType } from "./ContactType.ts";
|
|
9
|
+
import type { Phone } from "./Phone.ts";
|
|
10
|
+
import type { PhoneType } from "./PhoneType.ts";
|
|
11
|
+
|
|
12
|
+
type EnrichedCRUD<T> = ICRUDRepository<T> & IEnriched<T>;
|
|
13
|
+
|
|
14
|
+
export const ContactsService = {
|
|
15
|
+
open(
|
|
16
|
+
contacts: EnrichedCRUD<Contact>,
|
|
17
|
+
types: IReadonlyRepository<ContactType>,
|
|
18
|
+
sources: IReadonlyRepository<ContactSource>,
|
|
19
|
+
addressTypes: IReadonlyRepository<AddressType>,
|
|
20
|
+
phoneTypes: IReadonlyRepository<PhoneType>,
|
|
21
|
+
addresses: EnrichedCRUD<Address>,
|
|
22
|
+
phones: EnrichedCRUD<Phone>,
|
|
23
|
+
): EnrichedCRUD<Contact> {
|
|
24
|
+
addresses.addEnriched({ destinationProperty: "AddressType", sourceProperty: "AddressType", relatedKey: "Id" }, addressTypes);
|
|
25
|
+
phones.addEnriched({ destinationProperty: "PhoneType", sourceProperty: "PhoneType", relatedKey: "Id" }, phoneTypes);
|
|
26
|
+
contacts.addEnriched({ destinationProperty: "ContactType", sourceProperty: "ContactType", relatedKey: "Id" }, types);
|
|
27
|
+
contacts.addEnriched({ destinationProperty: "ContactSource", sourceProperty: "ContactSource", relatedKey: "Id" }, sources);
|
|
28
|
+
contacts.addEnriched({ destinationProperty: "Addresses", sourceProperty: "Id", relatedKey: "Contact", type: "list" }, addresses);
|
|
29
|
+
contacts.addEnriched({ destinationProperty: "Phones", sourceProperty: "Id", relatedKey: "Contact", type: "list" }, phones);
|
|
30
|
+
return contacts;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Contact } from "./Contact.ts";
|
|
2
|
+
|
|
3
|
+
type AddressView = { id: number; line1: string; city: string; address_type_name: string };
|
|
4
|
+
type PhoneView = { id: number; number: string; phone_type_name: string };
|
|
5
|
+
|
|
6
|
+
export type ContactsView = {
|
|
7
|
+
id: number;
|
|
8
|
+
first_name: string;
|
|
9
|
+
last_name: string;
|
|
10
|
+
email: string | null;
|
|
11
|
+
contact_source_name: string;
|
|
12
|
+
contact_type_name: string;
|
|
13
|
+
addresses: AddressView[];
|
|
14
|
+
phones: PhoneView[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const byId = (left: { id: number }, right: { id: number }) => left.id - right.id;
|
|
18
|
+
|
|
19
|
+
export const fromContacts = (contacts: Contact[]): ContactsView[] =>
|
|
20
|
+
contacts
|
|
21
|
+
.map((contact) => ({
|
|
22
|
+
id: contact.Id,
|
|
23
|
+
first_name: contact.FirstName,
|
|
24
|
+
last_name: contact.LastName,
|
|
25
|
+
email: contact.Email,
|
|
26
|
+
contact_source_name: contact.ContactSource.Name,
|
|
27
|
+
contact_type_name: contact.ContactType.Name,
|
|
28
|
+
addresses: contact.Addresses.map((address) => ({
|
|
29
|
+
id: address.Id,
|
|
30
|
+
line1: address.Line1,
|
|
31
|
+
city: address.City,
|
|
32
|
+
address_type_name: address.AddressType.Name,
|
|
33
|
+
})).sort(byId),
|
|
34
|
+
phones: contact.Phones.map((phone) => ({
|
|
35
|
+
id: phone.Id,
|
|
36
|
+
number: phone.Number,
|
|
37
|
+
phone_type_name: phone.PhoneType.Name,
|
|
38
|
+
})).sort(byId),
|
|
39
|
+
}))
|
|
40
|
+
.sort(byId);
|
|
41
|
+
|
|
42
|
+
export const asContactsView = (contacts: ContactsView[]): ContactsView[] =>
|
|
43
|
+
[...contacts]
|
|
44
|
+
.sort(byId)
|
|
45
|
+
.map((contact) => ({
|
|
46
|
+
id: contact.id,
|
|
47
|
+
first_name: contact.first_name,
|
|
48
|
+
last_name: contact.last_name,
|
|
49
|
+
email: contact.email,
|
|
50
|
+
contact_source_name: contact.contact_source_name,
|
|
51
|
+
contact_type_name: contact.contact_type_name,
|
|
52
|
+
addresses: [...contact.addresses]
|
|
53
|
+
.map(({ id, line1, city, address_type_name }) => ({
|
|
54
|
+
id,
|
|
55
|
+
line1,
|
|
56
|
+
city,
|
|
57
|
+
address_type_name,
|
|
58
|
+
}))
|
|
59
|
+
.sort(byId),
|
|
60
|
+
phones: [...contact.phones]
|
|
61
|
+
.map(({ id, number, phone_type_name }) => ({ id, number, phone_type_name }))
|
|
62
|
+
.sort(byId),
|
|
63
|
+
}));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ChangeCasingMapper } from "../../mappers/ChangeCasingMapper.ts";
|
|
2
|
+
import { DictionaryMapper } from "../../mappers/DictionaryMapper.ts";
|
|
3
|
+
import type { IMapper } from "../../mappers/IMapper.ts";
|
|
4
|
+
import { TransformMapper } from "../../mappers/TransformMapper.ts";
|
|
5
|
+
|
|
6
|
+
export const snake = new ChangeCasingMapper("pascalCase", "snakeCase");
|
|
7
|
+
|
|
8
|
+
const references = new DictionaryMapper<string>([
|
|
9
|
+
["Contact", "contact_id"],
|
|
10
|
+
["AddressType", "address_type_id"],
|
|
11
|
+
["ContactType", "contact_type_id"],
|
|
12
|
+
["ContactSource", "contact_source_id"],
|
|
13
|
+
["PhoneType", "phone_type_id"],
|
|
14
|
+
["Line1", "line1"],
|
|
15
|
+
["Line2", "line2"],
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
export const columns: IMapper<string, string> = new TransformMapper(
|
|
19
|
+
(name) => {
|
|
20
|
+
const mapped = references.map(name);
|
|
21
|
+
return mapped !== name ? mapped : snake.map(name);
|
|
22
|
+
},
|
|
23
|
+
(name) => {
|
|
24
|
+
const from = references.reverseMap(name);
|
|
25
|
+
return from !== name ? from : snake.reverseMap(name);
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const contactEntity = new DictionaryMapper<string>([["Contact", "contacts_base"]]);
|
|
30
|
+
|
|
31
|
+
export const joinEntity: IMapper<string, string> = new TransformMapper(
|
|
32
|
+
(name) => {
|
|
33
|
+
const mapped = contactEntity.map(name);
|
|
34
|
+
return mapped !== name ? mapped : snake.map(name);
|
|
35
|
+
},
|
|
36
|
+
(name) => {
|
|
37
|
+
const from = contactEntity.reverseMap(name);
|
|
38
|
+
return from !== name ? from : snake.reverseMap(name);
|
|
39
|
+
},
|
|
40
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Operator, Where } from "../../statements/index.ts";
|
|
2
|
+
import type { IConnection } from "../../IConnection.ts";
|
|
3
|
+
import { CRUDRepository } from "../../CRUDRepository.ts";
|
|
4
|
+
import type { Constructable } from "../../converters/Constructable.ts";
|
|
5
|
+
import { AddressType } from "./AddressType.ts";
|
|
6
|
+
import { columns, snake } from "./contactColumns.ts";
|
|
7
|
+
import type { ContactLookups } from "./contactLookups.ts";
|
|
8
|
+
import { ContactSource } from "./ContactSource.ts";
|
|
9
|
+
import { ContactType } from "./ContactType.ts";
|
|
10
|
+
import { PhoneType } from "./PhoneType.ts";
|
|
11
|
+
|
|
12
|
+
const of = async <T extends { Id: number }>(
|
|
13
|
+
connection: IConnection,
|
|
14
|
+
type: Constructable<T>,
|
|
15
|
+
name: string,
|
|
16
|
+
): Promise<number> => {
|
|
17
|
+
const row = await new CRUDRepository(connection, {
|
|
18
|
+
type,
|
|
19
|
+
entityMapper: snake,
|
|
20
|
+
propertyMappings: columns,
|
|
21
|
+
ids: ["Id"],
|
|
22
|
+
}).readSingle(new Where(new Operator.Equals("Name", name)));
|
|
23
|
+
if (!row) throw new Error(`${type.name} '${name}' missing`);
|
|
24
|
+
return row.Id;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const contactLookupIds = async (connection: IConnection): Promise<ContactLookups> => ({
|
|
28
|
+
ContactSourceId: await of(connection, ContactSource, "Web"),
|
|
29
|
+
ContactTypeId: await of(connection, ContactType, "Person"),
|
|
30
|
+
AddressTypeId: await of(connection, AddressType, "Home"),
|
|
31
|
+
PhoneTypeId: await of(connection, PhoneType, "Mobile"),
|
|
32
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { collectAsync } from "../../collectAsync.ts";
|
|
2
|
+
import { ConsoleCommandMiddleware } from "../../ConsoleCommandMiddleware.ts";
|
|
3
|
+
import type { Cells } from "../../converters/Cell.ts";
|
|
4
|
+
import { FlatToNestedMapper } from "../../mappers/FlatToNestedMapper.ts";
|
|
5
|
+
import type { IConnection } from "../../IConnection.ts";
|
|
6
|
+
import { CRUDRepository } from "../../CRUDRepository.ts";
|
|
7
|
+
import { Join, SelectStatement, type ISelectStatement, type IWhere } from "../../index.ts";
|
|
8
|
+
import { fromContacts, type ContactsView } from "./asContactsView.ts";
|
|
9
|
+
import { columns, joinEntity } from "./contactColumns.ts";
|
|
10
|
+
import { contactsServiceOf } from "./contactsServiceOf.ts";
|
|
11
|
+
import { contactsView } from "./contactsView.ts";
|
|
12
|
+
|
|
13
|
+
export const contactsJoinSelect = (where?: IWhere): ISelectStatement =>
|
|
14
|
+
new SelectStatement({
|
|
15
|
+
table: "Contact",
|
|
16
|
+
fields: [
|
|
17
|
+
"Contact.Id AS Id",
|
|
18
|
+
"Contact.FirstName AS FirstName",
|
|
19
|
+
"Contact.LastName AS LastName",
|
|
20
|
+
"Contact.Email AS Email",
|
|
21
|
+
"ContactSource.Name AS ContactSourceName",
|
|
22
|
+
"ContactType.Name AS ContactTypeName",
|
|
23
|
+
"Address.Id AS AddressId",
|
|
24
|
+
"Address.Line1 AS Line1",
|
|
25
|
+
"Address.City AS City",
|
|
26
|
+
"AddressType.Name AS AddressTypeName",
|
|
27
|
+
"Phone.Id AS PhoneId",
|
|
28
|
+
"Phone.Number AS Number",
|
|
29
|
+
"PhoneType.Name AS PhoneTypeName",
|
|
30
|
+
],
|
|
31
|
+
joins: [
|
|
32
|
+
Join.inner("ContactSource", "Contact.ContactSourceId", "ContactSource.Id"),
|
|
33
|
+
Join.inner("ContactType", "Contact.ContactTypeId", "ContactType.Id"),
|
|
34
|
+
Join.left("Address", "Contact.Id", "Address.ContactId"),
|
|
35
|
+
Join.left("AddressType", "Address.AddressTypeId", "AddressType.Id"),
|
|
36
|
+
Join.left("Phone", "Contact.Id", "Phone.ContactId"),
|
|
37
|
+
Join.left("PhoneType", "Phone.PhoneTypeId", "PhoneType.Id"),
|
|
38
|
+
],
|
|
39
|
+
where,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const contactsParity = async (
|
|
43
|
+
connection: IConnection,
|
|
44
|
+
verbose: boolean,
|
|
45
|
+
): Promise<{ eager: ContactsView[]; enriched: ContactsView[] }> => {
|
|
46
|
+
const middleware = new ConsoleCommandMiddleware(undefined, undefined, {
|
|
47
|
+
isVerbose: verbose ? "true" : "false",
|
|
48
|
+
});
|
|
49
|
+
const eager = new FlatToNestedMapper(contactsView).map(
|
|
50
|
+
await collectAsync(
|
|
51
|
+
new CRUDRepository<Cells>(connection, {
|
|
52
|
+
entityMapper: joinEntity,
|
|
53
|
+
propertyMappings: columns,
|
|
54
|
+
})
|
|
55
|
+
.addMiddleware(middleware)
|
|
56
|
+
.read(contactsJoinSelect()),
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
const enriched = fromContacts(
|
|
60
|
+
await collectAsync(contactsServiceOf(connection, verbose ? middleware : undefined).read()),
|
|
61
|
+
);
|
|
62
|
+
return { eager, enriched };
|
|
63
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ICommandMiddleware } from "../../ICommandMiddleware.ts";
|
|
2
|
+
import type { IConnection } from "../../IConnection.ts";
|
|
3
|
+
import { CRUDRepository } from "../../CRUDRepository.ts";
|
|
4
|
+
import type { Constructable } from "../../converters/Constructable.ts";
|
|
5
|
+
import type { IMapper } from "../../mappers/IMapper.ts";
|
|
6
|
+
import { Address } from "./Address.ts";
|
|
7
|
+
import { AddressType } from "./AddressType.ts";
|
|
8
|
+
import { columns, contactEntity, snake } from "./contactColumns.ts";
|
|
9
|
+
import { Contact } from "./Contact.ts";
|
|
10
|
+
import { ContactSource } from "./ContactSource.ts";
|
|
11
|
+
import { ContactType } from "./ContactType.ts";
|
|
12
|
+
import { ContactsService } from "./ContactsService.ts";
|
|
13
|
+
import { Phone } from "./Phone.ts";
|
|
14
|
+
import { PhoneType } from "./PhoneType.ts";
|
|
15
|
+
|
|
16
|
+
export const contactsServiceOf = (
|
|
17
|
+
connection: IConnection,
|
|
18
|
+
middleware?: ICommandMiddleware,
|
|
19
|
+
) => {
|
|
20
|
+
const of = <T>(type: Constructable<T>, entity?: IMapper<string, string>) => {
|
|
21
|
+
const repo = new CRUDRepository(connection, {
|
|
22
|
+
type,
|
|
23
|
+
entityMapper: entity ?? snake,
|
|
24
|
+
propertyMappings: columns,
|
|
25
|
+
ids: ["Id"],
|
|
26
|
+
});
|
|
27
|
+
return middleware ? repo.addMiddleware(middleware) : repo;
|
|
28
|
+
};
|
|
29
|
+
return ContactsService.open(
|
|
30
|
+
of(Contact, contactEntity),
|
|
31
|
+
of(ContactType),
|
|
32
|
+
of(ContactSource),
|
|
33
|
+
of(AddressType),
|
|
34
|
+
of(PhoneType),
|
|
35
|
+
of(Address),
|
|
36
|
+
of(Phone),
|
|
37
|
+
);
|
|
38
|
+
};
|