@uql/core 1.0.12 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +254 -0
- package/LICENSE.md +2 -2
- package/dist/browser/http/bus.d.ts +3 -0
- package/dist/browser/http/bus.js +14 -0
- package/dist/browser/http/http.d.ts +6 -0
- package/dist/browser/http/http.js +45 -0
- package/dist/browser/http/index.d.ts +2 -0
- package/dist/browser/http/index.js +3 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.js +5 -0
- package/dist/browser/options.d.ts +4 -0
- package/dist/browser/options.js +14 -0
- package/dist/browser/querier/genericClientRepository.d.ts +17 -0
- package/dist/browser/querier/genericClientRepository.js +39 -0
- package/dist/browser/querier/httpQuerier.d.ts +20 -0
- package/dist/browser/querier/httpQuerier.js +71 -0
- package/dist/browser/querier/index.d.ts +3 -0
- package/dist/browser/querier/index.js +4 -0
- package/dist/browser/querier/querier.util.d.ts +2 -0
- package/dist/browser/querier/querier.util.js +17 -0
- package/dist/browser/type/clientQuerier.d.ts +16 -0
- package/dist/browser/type/clientQuerier.js +2 -0
- package/dist/browser/type/clientQuerierPool.d.ts +4 -0
- package/dist/browser/type/clientQuerierPool.js +2 -0
- package/dist/browser/type/clientRepository.d.ts +13 -0
- package/dist/browser/type/clientRepository.js +2 -0
- package/dist/browser/type/index.d.ts +4 -0
- package/dist/browser/type/index.js +5 -0
- package/dist/browser/type/request.d.ts +28 -0
- package/dist/browser/type/request.js +2 -0
- package/dist/browser/uql-browser.min.js +2150 -0
- package/dist/browser/uql-browser.min.js.map +1 -0
- package/dist/dialect/abstractDialect.d.ts +16 -0
- package/dist/dialect/abstractDialect.js +28 -0
- package/dist/dialect/abstractSqlDialect.d.ts +47 -0
- package/dist/dialect/abstractSqlDialect.js +650 -0
- package/dist/dialect/index.d.ts +3 -0
- package/dist/dialect/index.js +4 -0
- package/dist/dialect/queryContext.d.ts +48 -0
- package/dist/dialect/queryContext.js +65 -0
- package/{entity → dist/entity}/decorator/definition.d.ts +3 -3
- package/dist/entity/decorator/definition.js +214 -0
- package/{entity → dist/entity}/decorator/entity.d.ts +1 -1
- package/dist/entity/decorator/entity.js +7 -0
- package/{entity → dist/entity}/decorator/field.d.ts +1 -1
- package/dist/entity/decorator/field.js +8 -0
- package/{entity → dist/entity}/decorator/id.d.ts +1 -1
- package/dist/entity/decorator/id.js +8 -0
- package/dist/entity/decorator/index.d.ts +5 -0
- package/dist/entity/decorator/index.js +6 -0
- package/{entity → dist/entity}/decorator/relation.d.ts +1 -1
- package/dist/entity/decorator/relation.js +20 -0
- package/dist/entity/index.d.ts +1 -0
- package/dist/entity/index.js +2 -0
- package/dist/express/index.d.ts +2 -0
- package/dist/express/index.js +3 -0
- package/dist/express/querierMiddleware.d.ts +26 -0
- package/dist/express/querierMiddleware.js +190 -0
- package/dist/express/query.util.d.ts +2 -0
- package/dist/express/query.util.js +19 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -0
- package/dist/maria/index.d.ts +3 -0
- package/dist/maria/index.js +4 -0
- package/dist/maria/mariaDialect.d.ts +8 -0
- package/dist/maria/mariaDialect.js +38 -0
- package/dist/maria/mariaQuerierPool.test.d.ts +5 -0
- package/dist/maria/mariaQuerierPool.test.js +19 -0
- package/dist/maria/mariadbQuerier.d.ts +17 -0
- package/dist/maria/mariadbQuerier.js +39 -0
- package/dist/maria/mariadbQuerier.test.d.ts +4 -0
- package/dist/maria/mariadbQuerier.test.js +19 -0
- package/dist/maria/mariadbQuerierPool.d.ts +10 -0
- package/dist/maria/mariadbQuerierPool.js +17 -0
- package/dist/migrate/cli.d.ts +2 -0
- package/dist/migrate/cli.js +254 -0
- package/dist/migrate/generator/index.d.ts +4 -0
- package/dist/migrate/generator/index.js +5 -0
- package/dist/migrate/generator/mongoSchemaGenerator.d.ts +12 -0
- package/dist/migrate/generator/mongoSchemaGenerator.js +100 -0
- package/dist/migrate/generator/mysqlSchemaGenerator.d.ts +14 -0
- package/dist/migrate/generator/mysqlSchemaGenerator.js +81 -0
- package/dist/migrate/generator/postgresSchemaGenerator.d.ts +18 -0
- package/dist/migrate/generator/postgresSchemaGenerator.js +111 -0
- package/dist/migrate/generator/sqliteSchemaGenerator.d.ts +14 -0
- package/dist/migrate/generator/sqliteSchemaGenerator.js +68 -0
- package/dist/migrate/index.d.ts +12 -0
- package/dist/migrate/index.js +17 -0
- package/dist/migrate/introspection/index.d.ts +4 -0
- package/dist/migrate/introspection/index.js +5 -0
- package/dist/migrate/introspection/mongoIntrospector.d.ts +8 -0
- package/dist/migrate/introspection/mongoIntrospector.js +46 -0
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +25 -0
- package/dist/migrate/introspection/mysqlIntrospector.js +220 -0
- package/dist/migrate/introspection/postgresIntrospector.d.ts +21 -0
- package/dist/migrate/introspection/postgresIntrospector.js +269 -0
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +23 -0
- package/dist/migrate/introspection/sqliteIntrospector.js +212 -0
- package/dist/migrate/migrator-mongo.test.d.ts +1 -0
- package/dist/migrate/migrator-mongo.test.js +54 -0
- package/dist/migrate/migrator.d.ts +133 -0
- package/dist/migrate/migrator.js +600 -0
- package/dist/migrate/migrator.test.d.ts +1 -0
- package/dist/migrate/migrator.test.js +106 -0
- package/dist/migrate/schemaGenerator.d.ts +78 -0
- package/dist/migrate/schemaGenerator.js +363 -0
- package/dist/migrate/storage/databaseStorage.d.ts +24 -0
- package/dist/migrate/storage/databaseStorage.js +77 -0
- package/dist/migrate/storage/index.d.ts +2 -0
- package/dist/migrate/storage/index.js +3 -0
- package/dist/migrate/storage/jsonStorage.d.ts +15 -0
- package/dist/migrate/storage/jsonStorage.js +51 -0
- package/dist/migrate/type.d.ts +1 -0
- package/dist/migrate/type.js +2 -0
- package/dist/mongo/index.d.ts +3 -0
- package/dist/mongo/index.js +4 -0
- package/dist/mongo/mongoDialect.d.ts +34 -0
- package/dist/mongo/mongoDialect.js +163 -0
- package/dist/mongo/mongodbQuerier.d.ts +28 -0
- package/dist/mongo/mongodbQuerier.js +204 -0
- package/dist/mongo/mongodbQuerier.test.d.ts +1 -0
- package/dist/mongo/mongodbQuerier.test.js +36 -0
- package/dist/mongo/mongodbQuerierPool.d.ts +10 -0
- package/dist/mongo/mongodbQuerierPool.js +20 -0
- package/dist/mongo/mongodbQuerierPool.test.d.ts +1 -0
- package/dist/mongo/mongodbQuerierPool.test.js +21 -0
- package/dist/mysql/index.d.ts +3 -0
- package/dist/mysql/index.js +4 -0
- package/dist/mysql/mysql2Querier.d.ts +17 -0
- package/dist/mysql/mysql2Querier.js +43 -0
- package/dist/mysql/mysql2Querier.test.d.ts +4 -0
- package/dist/mysql/mysql2Querier.test.js +16 -0
- package/dist/mysql/mysql2QuerierPool.d.ts +10 -0
- package/dist/mysql/mysql2QuerierPool.js +17 -0
- package/dist/mysql/mysql2QuerierPool.test.d.ts +5 -0
- package/dist/mysql/mysql2QuerierPool.test.js +16 -0
- package/dist/mysql/mysqlDialect.d.ts +5 -0
- package/dist/mysql/mysqlDialect.js +15 -0
- package/dist/namingStrategy/defaultNamingStrategy.d.ts +9 -0
- package/dist/namingStrategy/defaultNamingStrategy.js +15 -0
- package/dist/namingStrategy/index.d.ts +2 -0
- package/dist/namingStrategy/index.js +3 -0
- package/dist/namingStrategy/snakeCaseNamingStrategy.d.ts +8 -0
- package/dist/namingStrategy/snakeCaseNamingStrategy.js +14 -0
- package/{options.d.ts → dist/options.d.ts} +1 -1
- package/dist/options.js +14 -0
- package/dist/package.json +131 -0
- package/dist/postgres/index.d.ts +3 -0
- package/dist/postgres/index.js +4 -0
- package/dist/postgres/pgQuerier.d.ts +17 -0
- package/dist/postgres/pgQuerier.js +39 -0
- package/dist/postgres/pgQuerier.test.d.ts +4 -0
- package/dist/postgres/pgQuerier.test.js +20 -0
- package/dist/postgres/pgQuerierPool.d.ts +10 -0
- package/dist/postgres/pgQuerierPool.js +17 -0
- package/dist/postgres/pgQuerierPool.test.d.ts +5 -0
- package/dist/postgres/pgQuerierPool.test.js +23 -0
- package/dist/postgres/postgresDialect.d.ts +13 -0
- package/dist/postgres/postgresDialect.js +110 -0
- package/dist/querier/abstractQuerier-test.d.ts +45 -0
- package/dist/querier/abstractQuerier-test.js +461 -0
- package/dist/querier/abstractQuerier.d.ts +50 -0
- package/dist/querier/abstractQuerier.js +278 -0
- package/dist/querier/abstractQuerierPool-test.d.ts +9 -0
- package/dist/querier/abstractQuerierPool-test.js +18 -0
- package/dist/querier/abstractQuerierPool.d.ts +14 -0
- package/dist/querier/abstractQuerierPool.js +9 -0
- package/dist/querier/abstractSqlQuerier-test.d.ts +9 -0
- package/dist/querier/abstractSqlQuerier-test.js +16 -0
- package/dist/querier/abstractSqlQuerier.d.ts +28 -0
- package/dist/querier/abstractSqlQuerier.js +133 -0
- package/dist/querier/decorator/index.d.ts +3 -0
- package/dist/querier/decorator/index.js +4 -0
- package/dist/querier/decorator/injectQuerier.d.ts +3 -0
- package/dist/querier/decorator/injectQuerier.js +33 -0
- package/dist/querier/decorator/serialized.d.ts +6 -0
- package/dist/querier/decorator/serialized.js +14 -0
- package/{querier → dist/querier}/decorator/transactional.d.ts +1 -1
- package/dist/querier/decorator/transactional.js +48 -0
- package/dist/querier/index.d.ts +4 -0
- package/dist/querier/index.js +5 -0
- package/dist/repository/genericRepository.d.ts +20 -0
- package/dist/repository/genericRepository.js +51 -0
- package/dist/repository/index.d.ts +1 -0
- package/dist/repository/index.js +2 -0
- package/dist/sqlite/index.d.ts +3 -0
- package/dist/sqlite/index.js +4 -0
- package/dist/sqlite/sqliteDialect.d.ts +10 -0
- package/dist/sqlite/sqliteDialect.js +48 -0
- package/dist/sqlite/sqliteQuerier.d.ts +15 -0
- package/dist/sqlite/sqliteQuerier.js +33 -0
- package/dist/sqlite/sqliteQuerier.test.d.ts +5 -0
- package/dist/sqlite/sqliteQuerier.test.js +19 -0
- package/dist/sqlite/sqliteQuerierPool.d.ts +14 -0
- package/dist/sqlite/sqliteQuerierPool.js +34 -0
- package/dist/sqlite/sqliteQuerierPool.test.d.ts +5 -0
- package/dist/sqlite/sqliteQuerierPool.test.js +10 -0
- package/dist/test/entityMock.d.ts +164 -0
- package/dist/test/entityMock.js +554 -0
- package/dist/test/index.d.ts +3 -0
- package/dist/test/index.js +4 -0
- package/dist/test/it.util.d.ts +4 -0
- package/dist/test/it.util.js +55 -0
- package/dist/test/spec.util.d.ts +14 -0
- package/dist/test/spec.util.js +50 -0
- package/{type → dist/type}/entity.d.ts +97 -4
- package/dist/type/entity.js +5 -0
- package/dist/type/index.d.ts +9 -0
- package/dist/type/index.js +10 -0
- package/dist/type/migration.d.ts +213 -0
- package/dist/type/migration.js +2 -0
- package/dist/type/namingStrategy.d.ts +17 -0
- package/dist/type/namingStrategy.js +2 -0
- package/dist/type/querier.d.ts +96 -0
- package/dist/type/querier.js +11 -0
- package/{type → dist/type}/querierPool.d.ts +7 -3
- package/dist/type/querierPool.js +2 -0
- package/{type → dist/type}/query.d.ts +170 -108
- package/dist/type/query.js +9 -0
- package/{type → dist/type}/repository.d.ts +42 -35
- package/dist/type/repository.js +2 -0
- package/{type → dist/type}/universalQuerier.d.ts +50 -28
- package/dist/type/universalQuerier.js +2 -0
- package/dist/type/utility.d.ts +13 -0
- package/dist/type/utility.js +2 -0
- package/dist/util/dialect.util.d.ts +12 -0
- package/dist/util/dialect.util.js +93 -0
- package/dist/util/index.d.ts +5 -0
- package/dist/util/index.js +6 -0
- package/dist/util/object.util.d.ts +7 -0
- package/dist/util/object.util.js +19 -0
- package/dist/util/raw.d.ts +8 -0
- package/dist/util/raw.js +11 -0
- package/dist/util/sql.util.d.ts +13 -0
- package/dist/util/sql.util.js +78 -0
- package/{util → dist/util}/string.util.d.ts +1 -0
- package/dist/util/string.util.js +34 -0
- package/package.json +85 -17
- package/src/@types/index.d.ts +1 -0
- package/src/@types/jest.d.ts +6 -0
- package/src/browser/http/bus.spec.ts +22 -0
- package/src/browser/http/bus.ts +17 -0
- package/src/browser/http/http.spec.ts +70 -0
- package/src/browser/http/http.ts +55 -0
- package/src/browser/http/index.ts +2 -0
- package/src/browser/index.ts +4 -0
- package/src/browser/options.spec.ts +37 -0
- package/src/browser/options.ts +18 -0
- package/src/browser/querier/genericClientRepository.spec.ts +105 -0
- package/src/browser/querier/genericClientRepository.ts +49 -0
- package/src/browser/querier/httpQuerier.ts +82 -0
- package/src/browser/querier/index.ts +3 -0
- package/src/browser/querier/querier.util.spec.ts +35 -0
- package/src/browser/querier/querier.util.ts +18 -0
- package/src/browser/type/clientQuerier.ts +45 -0
- package/src/browser/type/clientQuerierPool.ts +5 -0
- package/src/browser/type/clientRepository.ts +22 -0
- package/src/browser/type/index.ts +4 -0
- package/src/browser/type/request.ts +25 -0
- package/src/dialect/abstractDialect.ts +28 -0
- package/src/dialect/abstractSqlDialect-spec.ts +1309 -0
- package/src/dialect/abstractSqlDialect.ts +805 -0
- package/src/dialect/index.ts +3 -0
- package/src/dialect/namingStrategy.spec.ts +52 -0
- package/src/dialect/queryContext.ts +69 -0
- package/src/entity/decorator/definition.spec.ts +736 -0
- package/src/entity/decorator/definition.ts +265 -0
- package/src/entity/decorator/entity.ts +8 -0
- package/src/entity/decorator/field.ts +9 -0
- package/src/entity/decorator/id.ts +9 -0
- package/src/entity/decorator/index.ts +5 -0
- package/src/entity/decorator/relation.spec.ts +41 -0
- package/src/entity/decorator/relation.ts +34 -0
- package/src/entity/index.ts +1 -0
- package/src/express/@types/express.d.ts +8 -0
- package/src/express/@types/index.d.ts +1 -0
- package/src/express/index.ts +2 -0
- package/src/express/querierMiddleware.ts +217 -0
- package/src/express/query.util.spec.ts +40 -0
- package/src/express/query.util.ts +21 -0
- package/src/index.ts +9 -0
- package/src/maria/index.ts +3 -0
- package/src/maria/mariaDialect.spec.ts +207 -0
- package/src/maria/mariaDialect.ts +42 -0
- package/src/maria/mariaQuerierPool.test.ts +23 -0
- package/src/maria/mariadbQuerier.test.ts +23 -0
- package/src/maria/mariadbQuerier.ts +45 -0
- package/src/maria/mariadbQuerierPool.ts +21 -0
- package/src/migrate/cli.ts +301 -0
- package/src/migrate/generator/index.ts +4 -0
- package/src/migrate/generator/mongoSchemaGenerator.spec.ts +112 -0
- package/src/migrate/generator/mongoSchemaGenerator.ts +115 -0
- package/src/migrate/generator/mysqlSchemaGenerator.spec.ts +34 -0
- package/src/migrate/generator/mysqlSchemaGenerator.ts +92 -0
- package/src/migrate/generator/postgresSchemaGenerator.spec.ts +44 -0
- package/src/migrate/generator/postgresSchemaGenerator.ts +127 -0
- package/src/migrate/generator/sqliteSchemaGenerator.spec.ts +33 -0
- package/src/migrate/generator/sqliteSchemaGenerator.ts +81 -0
- package/src/migrate/index.ts +41 -0
- package/src/migrate/introspection/index.ts +4 -0
- package/src/migrate/introspection/mongoIntrospector.spec.ts +75 -0
- package/src/migrate/introspection/mongoIntrospector.ts +47 -0
- package/src/migrate/introspection/mysqlIntrospector.spec.ts +113 -0
- package/src/migrate/introspection/mysqlIntrospector.ts +278 -0
- package/src/migrate/introspection/postgresIntrospector.spec.ts +112 -0
- package/src/migrate/introspection/postgresIntrospector.ts +329 -0
- package/src/migrate/introspection/sqliteIntrospector.spec.ts +112 -0
- package/src/migrate/introspection/sqliteIntrospector.ts +296 -0
- package/src/migrate/migrator-mongo.test.ts +54 -0
- package/src/migrate/migrator.spec.ts +255 -0
- package/src/migrate/migrator.test.ts +94 -0
- package/src/migrate/migrator.ts +719 -0
- package/src/migrate/namingStrategy.spec.ts +22 -0
- package/src/migrate/schemaGenerator-advanced.spec.ts +138 -0
- package/src/migrate/schemaGenerator.spec.ts +190 -0
- package/src/migrate/schemaGenerator.ts +478 -0
- package/src/migrate/storage/databaseStorage.spec.ts +69 -0
- package/src/migrate/storage/databaseStorage.ts +100 -0
- package/src/migrate/storage/index.ts +2 -0
- package/src/migrate/storage/jsonStorage.ts +58 -0
- package/src/migrate/type.ts +1 -0
- package/src/mongo/index.ts +3 -0
- package/src/mongo/mongoDialect.spec.ts +251 -0
- package/src/mongo/mongoDialect.ts +238 -0
- package/src/mongo/mongodbQuerier.test.ts +45 -0
- package/src/mongo/mongodbQuerier.ts +256 -0
- package/src/mongo/mongodbQuerierPool.test.ts +25 -0
- package/src/mongo/mongodbQuerierPool.ts +24 -0
- package/src/mysql/index.ts +3 -0
- package/src/mysql/mysql2Querier.test.ts +20 -0
- package/src/mysql/mysql2Querier.ts +49 -0
- package/src/mysql/mysql2QuerierPool.test.ts +20 -0
- package/src/mysql/mysql2QuerierPool.ts +21 -0
- package/src/mysql/mysqlDialect.spec.ts +20 -0
- package/src/mysql/mysqlDialect.ts +16 -0
- package/src/namingStrategy/defaultNamingStrategy.ts +18 -0
- package/src/namingStrategy/index.spec.ts +36 -0
- package/src/namingStrategy/index.ts +2 -0
- package/src/namingStrategy/snakeCaseNamingStrategy.ts +15 -0
- package/src/options.spec.ts +41 -0
- package/src/options.ts +18 -0
- package/src/postgres/index.ts +3 -0
- package/src/postgres/manual-types.d.ts +4 -0
- package/src/postgres/pgQuerier.test.ts +25 -0
- package/src/postgres/pgQuerier.ts +45 -0
- package/src/postgres/pgQuerierPool.test.ts +28 -0
- package/src/postgres/pgQuerierPool.ts +21 -0
- package/src/postgres/postgresDialect.spec.ts +428 -0
- package/src/postgres/postgresDialect.ts +144 -0
- package/src/querier/abstractQuerier-test.ts +584 -0
- package/src/querier/abstractQuerier.ts +353 -0
- package/src/querier/abstractQuerierPool-test.ts +20 -0
- package/src/querier/abstractQuerierPool.ts +18 -0
- package/src/querier/abstractSqlQuerier-spec.ts +979 -0
- package/src/querier/abstractSqlQuerier-test.ts +21 -0
- package/src/querier/abstractSqlQuerier.ts +138 -0
- package/src/querier/decorator/index.ts +3 -0
- package/src/querier/decorator/injectQuerier.spec.ts +74 -0
- package/src/querier/decorator/injectQuerier.ts +45 -0
- package/src/querier/decorator/serialized.spec.ts +98 -0
- package/src/querier/decorator/serialized.ts +13 -0
- package/src/querier/decorator/transactional.spec.ts +240 -0
- package/src/querier/decorator/transactional.ts +56 -0
- package/src/querier/index.ts +4 -0
- package/src/repository/genericRepository.spec.ts +111 -0
- package/src/repository/genericRepository.ts +74 -0
- package/src/repository/index.ts +1 -0
- package/src/sqlite/index.ts +3 -0
- package/src/sqlite/manual-types.d.ts +4 -0
- package/src/sqlite/sqliteDialect.spec.ts +155 -0
- package/src/sqlite/sqliteDialect.ts +76 -0
- package/src/sqlite/sqliteQuerier.spec.ts +36 -0
- package/src/sqlite/sqliteQuerier.test.ts +21 -0
- package/src/sqlite/sqliteQuerier.ts +37 -0
- package/src/sqlite/sqliteQuerierPool.test.ts +12 -0
- package/src/sqlite/sqliteQuerierPool.ts +38 -0
- package/src/test/entityMock.ts +375 -0
- package/src/test/index.ts +3 -0
- package/src/test/it.util.ts +69 -0
- package/src/test/spec.util.ts +57 -0
- package/src/type/entity.ts +218 -0
- package/src/type/index.ts +9 -0
- package/src/type/migration.ts +241 -0
- package/src/type/namingStrategy.ts +17 -0
- package/src/type/querier.ts +143 -0
- package/src/type/querierPool.ts +26 -0
- package/src/type/query.ts +506 -0
- package/src/type/repository.ts +142 -0
- package/src/type/universalQuerier.ts +133 -0
- package/src/type/utility.ts +21 -0
- package/src/util/dialect.util-extra.spec.ts +96 -0
- package/src/util/dialect.util.spec.ts +23 -0
- package/src/util/dialect.util.ts +134 -0
- package/src/util/index.ts +5 -0
- package/src/util/object.util.spec.ts +29 -0
- package/src/util/object.util.ts +27 -0
- package/src/util/raw.ts +11 -0
- package/src/util/sql.util-extra.spec.ts +17 -0
- package/src/util/sql.util.spec.ts +208 -0
- package/src/util/sql.util.ts +104 -0
- package/src/util/string.util.spec.ts +46 -0
- package/src/util/string.util.ts +35 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +8 -0
- package/README.md +0 -177
- package/dialect/abstractSqlDialect.d.ts +0 -30
- package/dialect/abstractSqlDialect.js +0 -365
- package/dialect/index.d.ts +0 -4
- package/dialect/index.js +0 -8
- package/dialect/mysqlDialect.d.ts +0 -6
- package/dialect/mysqlDialect.js +0 -21
- package/dialect/postgresDialect.d.ts +0 -8
- package/dialect/postgresDialect.js +0 -44
- package/dialect/sqliteDialect.d.ts +0 -4
- package/dialect/sqliteDialect.js +0 -11
- package/entity/decorator/definition.js +0 -223
- package/entity/decorator/entity.js +0 -11
- package/entity/decorator/field.js +0 -12
- package/entity/decorator/id.js +0 -12
- package/entity/decorator/index.d.ts +0 -5
- package/entity/decorator/index.js +0 -12
- package/entity/decorator/relation.js +0 -27
- package/entity/index.d.ts +0 -1
- package/entity/index.js +0 -5
- package/index.d.ts +0 -1
- package/index.js +0 -5
- package/options.js +0 -20
- package/querier/abstractQuerier.d.ts +0 -30
- package/querier/abstractQuerier.js +0 -230
- package/querier/abstractSqlQuerier.d.ts +0 -27
- package/querier/abstractSqlQuerier.js +0 -88
- package/querier/decorator/index.d.ts +0 -2
- package/querier/decorator/index.js +0 -6
- package/querier/decorator/injectQuerier.d.ts +0 -3
- package/querier/decorator/injectQuerier.js +0 -39
- package/querier/decorator/transactional.js +0 -52
- package/querier/index.d.ts +0 -3
- package/querier/index.js +0 -7
- package/repository/genericRepository.d.ts +0 -19
- package/repository/genericRepository.js +0 -52
- package/repository/index.d.ts +0 -1
- package/repository/index.js +0 -5
- package/type/entity.js +0 -5
- package/type/index.d.ts +0 -7
- package/type/index.js +0 -11
- package/type/querier.d.ts +0 -53
- package/type/querier.js +0 -3
- package/type/querierPool.js +0 -3
- package/type/query.js +0 -13
- package/type/repository.js +0 -3
- package/type/universalQuerier.js +0 -3
- package/type/utility.d.ts +0 -12
- package/type/utility.js +0 -3
- package/util/dialect.util.d.ts +0 -17
- package/util/dialect.util.js +0 -114
- package/util/index.d.ts +0 -5
- package/util/index.js +0 -9
- package/util/object.util.d.ts +0 -3
- package/util/object.util.js +0 -22
- package/util/raw.d.ts +0 -2
- package/util/raw.js +0 -9
- package/util/sql.util.d.ts +0 -2
- package/util/sql.util.js +0 -55
- package/util/string.util.js +0 -20
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getKeys, hasKeys } from './object.util.js';
|
|
2
|
+
export function flatObject(obj, pre) {
|
|
3
|
+
return getKeys(obj).reduce((acc, key) => flatObjectEntry(acc, key, obj[key], typeof obj[key] === 'object' ? '' : pre), {});
|
|
4
|
+
}
|
|
5
|
+
function flatObjectEntry(map, key, val, pre) {
|
|
6
|
+
const prefix = pre ? `${pre}.${key}` : key;
|
|
7
|
+
return typeof val === 'object'
|
|
8
|
+
? getKeys(val).reduce((acc, prop) => flatObjectEntry(acc, prop, val[prop], prefix), map)
|
|
9
|
+
: { ...map, [prefix]: val };
|
|
10
|
+
}
|
|
11
|
+
export function unflatObjects(objects) {
|
|
12
|
+
if (!Array.isArray(objects) || !objects.length) {
|
|
13
|
+
return objects;
|
|
14
|
+
}
|
|
15
|
+
const attrsPaths = obtainAttrsPaths(objects[0]);
|
|
16
|
+
if (!hasKeys(attrsPaths)) {
|
|
17
|
+
return objects;
|
|
18
|
+
}
|
|
19
|
+
return objects.map((row) => {
|
|
20
|
+
const dto = {};
|
|
21
|
+
for (const col in row) {
|
|
22
|
+
if (row[col] === null) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const attrPath = attrsPaths[col];
|
|
26
|
+
if (attrPath) {
|
|
27
|
+
const target = attrPath.slice(0, -1).reduce((acc, key) => {
|
|
28
|
+
if (typeof acc[key] !== 'object') {
|
|
29
|
+
acc[key] = {};
|
|
30
|
+
}
|
|
31
|
+
return acc[key];
|
|
32
|
+
}, dto);
|
|
33
|
+
target[attrPath[attrPath.length - 1]] = row[col];
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
dto[col] = row[col];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return dto;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export function obtainAttrsPaths(row) {
|
|
43
|
+
return getKeys(row).reduce((acc, col) => {
|
|
44
|
+
// Support both dot notation (legacy) and underscore notation (new)
|
|
45
|
+
if (col.includes('.')) {
|
|
46
|
+
acc[col] = col.split('.');
|
|
47
|
+
}
|
|
48
|
+
else if (col.includes('_') && col !== col.toUpperCase()) {
|
|
49
|
+
// Convert underscore to dot notation for nested paths
|
|
50
|
+
// Skip all-uppercase (like UPPER_CASE constants)
|
|
51
|
+
acc[col] = col.split('_');
|
|
52
|
+
}
|
|
53
|
+
return acc;
|
|
54
|
+
}, {});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Escape a SQL identifier (table name, column name, etc.)
|
|
58
|
+
* @param val the identifier to escape
|
|
59
|
+
* @param escapeIdChar the escape character to use (e.g. ` or ")
|
|
60
|
+
* @param forbidQualified whether to forbid qualified identifiers (containing dots)
|
|
61
|
+
* @param addDot whether to add a dot suffix
|
|
62
|
+
*/
|
|
63
|
+
export function escapeSqlId(val, escapeIdChar = '`', forbidQualified, addDot) {
|
|
64
|
+
if (!val) {
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
if (!forbidQualified && val.includes('.')) {
|
|
68
|
+
const result = val
|
|
69
|
+
.split('.')
|
|
70
|
+
.map((it) => escapeSqlId(it, escapeIdChar, true))
|
|
71
|
+
.join('.');
|
|
72
|
+
return addDot ? result + '.' : result;
|
|
73
|
+
}
|
|
74
|
+
const escaped = escapeIdChar + val.replace(new RegExp(escapeIdChar, 'g'), escapeIdChar + escapeIdChar) + escapeIdChar;
|
|
75
|
+
const suffix = addDot ? '.' : '';
|
|
76
|
+
return escaped + suffix;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3FsLnV0aWwuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbC9zcWwudXRpbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRXBELE1BQU0sVUFBVSxVQU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hcyBUO1xuXG4gICAgZm9yIChjb25zdCBjb2wgaW4gcm93KSB7XG4gICAgICBpZiAocm93W2NvbF0gPT09IG51bGwpIHtcbiAgICAgICAgY29udGludWU7XG4gICAgICB9XG4gICAgICBjb25zdCBhdHRyUGF0aCA9IGF0dHJzUGF0aHNbY29sXTtcbiAgICAgIGlmIChhdHRyUGF0aCkge1xuICAgICAgICBjb25zdCB0YXJnZXQgPSBhdHRyUGF0aC5zbGljZSgwLCAtMSkucmVkdWNlKFxuICAgICAgICAgIChhY2MsIGtleSkgPT4ge1xuICAgICAgICAgICAgaWYgKHR5cGVvZiBhY2Nba2V5IGFzIEtleTxUPl0gIT09ICdvYmplY3QnKSB7XG4gICAgICAgICAgICAgIGFjY1trZXkgYXMgS2V5PFQ+XSA9IHt9IGFzIEZpZWxkVmFsdWU8VD47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gYWNjW2tleSBhcyBLZXk8VD5dO1xuICAgICAgICAgIH0sXG4gICAgICAgICAgZHRvIGFzIFJlY29yZDxzdHJpbmcsIGFueT4sXG4gICAgICAgICk7XG4gICAgICAgIHRhcmdldFthdHRyUGF0aFthdHRyUGF0aC5sZW5ndGggLSAxXV0gPSByb3dbY29sXTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGR0b1tjb2xdID0gcm93W2NvbF07XG4gICAgICB9XG4gICAgfVxuXG4gICAgcmV0dXJuIGR0bztcbiAgfSk7XG59XG5cbmV4cG9ydCBmdW5jdGlvbiBvYnRhaW5BdHRyc1BhdGhzPFQ+KHJvdzogVCkge1xuICByZXR1cm4gZ2V0S2V5cyhyb3cpLnJlZHVjZShcbiAgICAoYWNjLCBjb2wpID0+IHtcbiAgICAgIC8vIFN1cHBvcnQgYm90aCBkb3Qgbm90YXRpb24gKGxlZ2FjeSkgYW5kIHVuZGVyc2NvcmUgbm90YXRpb24gKG5ldylcbiAgICAgIGlmIChjb2wuaW5jbHVkZXMoJy4nKSkge1xuICAgICAgICBh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iAgfVxuXG4gIGlmICghZm9yYmlkUXVhbGlmaWVkICYmIHZhbC5pbmNsdWRlcygnLicpKSB7XG4gICAgY29uc3QgcmVzdWx0ID0gdmFsXG4gICAgICAuc3BsaXQoJy4nKVxuICAgICAgLm1hcCgoaXQpID0+IGVzY2FwZVNxbElkKGl0LCBlc2NhcGVJZENoYXIsIHRydWUpKVxuICAgICAgLmpvaW4oJy4nKTtcbiAgICByZXR1cm4gYWRkRG90ID8gcmVzdWx0ICsgJy4nIDogcmVzdWx0O1xuICB9XG5cbiAgY29uc3QgZXNjYXBlZCA9IGVzY2FwZUlkQ2hhciArIHZhbC5yZXBsYWNlKG5ldyBSZWdFeHAoZXNjYXBlSWRDaGFyLCAnZycpLCBlc2NhcGVJZENoYXIgKyBlc2NhcGVJZENoYXIpICsgZXNjYXBlSWRDaGFyO1xuXG4gIGNvbnN0IHN1ZmZpeCA9IGFkZERvdCA/ICcuJyA6ICcnO1xuXG4gIHJldHVybiBlc2NhcGVkICsgc3VmZml4O1xufVxuIl19
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function kebabCase(val) {
|
|
2
|
+
let resp = val.charAt(0).toLowerCase();
|
|
3
|
+
for (let i = 1; i < val.length; ++i) {
|
|
4
|
+
resp += val[i] === val[i].toUpperCase() ? '-' + val[i].toLowerCase() : val[i];
|
|
5
|
+
}
|
|
6
|
+
return resp;
|
|
7
|
+
}
|
|
8
|
+
export function upperFirst(text) {
|
|
9
|
+
return text[0].toUpperCase() + text.slice(1);
|
|
10
|
+
}
|
|
11
|
+
export function lowerFirst(text) {
|
|
12
|
+
return text[0].toLowerCase() + text.slice(1);
|
|
13
|
+
}
|
|
14
|
+
export function snakeCase(val) {
|
|
15
|
+
if (val === undefined || val === null) {
|
|
16
|
+
return val;
|
|
17
|
+
}
|
|
18
|
+
if (!val) {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
let resp = val.charAt(0).toLowerCase();
|
|
22
|
+
for (let i = 1; i < val.length; ++i) {
|
|
23
|
+
const char = val[i];
|
|
24
|
+
const charLower = char.toLowerCase();
|
|
25
|
+
if (char !== charLower && char === char.toUpperCase()) {
|
|
26
|
+
resp += '_' + charLower;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
resp += char;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return resp;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RyaW5nLnV0aWwuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbC9zdHJpbmcudXRpbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLFVBQVUsU0FBUyxDQUFDLEdBQVc7SUFDbkMsSUFBSSxJQUFJLEdBQUcsR0FBRyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUMsQ0FBQyxXQUFXLEVBQUUsQ0FBQztJQUN2QyxLQUFLLElBQUksQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLEdBQUcsR0FBRyxDQUFDLE1BQU0sRUFBRSxFQUFFLENBQUMsRUFBRSxDQUFDO1FBQ3BDLElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxDQUFDLEtBQUssR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLFdBQVcsRUFBRSxDQUFDLENBQUMsQ0FBQyxHQUFHLEdBQUcsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLFdBQVcsRUFBRSxDQUFDLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDaEYsQ0FBQztJQUNELE9BQU8sSUFBSSxDQUFDO0FBQ2QsQ0FBQztBQUVELE1BQU0sVUFBVSxVQUFVLENBQUMsSUFBWTtJQUNyQyxPQUFPLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQyxXQUFXLEVBQUUsR0FBRyxJQUFJLEN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T09IGNoYXJMb3dlciAmJiBjaGFyID09PSBjaGFyLnRvVXBwZXJDYXNlKCkpIHtcbiAgICAgIHJlc3AgKz0gJ18nICsgY2hhckxvd2VyO1xuICAgIH0gZWxzZSB7XG4gICAgICByZXNwICs9IGNoYXI7XG4gICAgfVxuICB9XG4gIHJldHVybiByZXNwO1xufVxuIl19
|
package/package.json
CHANGED
|
@@ -1,30 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uql/core",
|
|
3
|
-
"homepage": "https://
|
|
4
|
-
"description": "
|
|
3
|
+
"homepage": "https://uql.app",
|
|
4
|
+
"description": "One Language. Frontend to Backend.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "1.0
|
|
7
|
-
"
|
|
6
|
+
"version": "3.1.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./index.js",
|
|
8
9
|
"types": "./index.d.ts",
|
|
10
|
+
"bin": {
|
|
11
|
+
"uql-migrate": "./migrate/cli.js"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./index.js",
|
|
15
|
+
"./dialect": "./dialect/index.js",
|
|
16
|
+
"./entity": "./entity/index.js",
|
|
17
|
+
"./querier": "./querier/index.js",
|
|
18
|
+
"./repository": "./repository/index.js",
|
|
19
|
+
"./type": "./type/index.js",
|
|
20
|
+
"./util": "./util/index.js",
|
|
21
|
+
"./namingStrategy": "./namingStrategy/index.js",
|
|
22
|
+
"./migrate": "./migrate/index.js",
|
|
23
|
+
"./options": "./options.js",
|
|
24
|
+
"./test": "./test/index.js",
|
|
25
|
+
"./mysql": "./mysql/index.js",
|
|
26
|
+
"./postgres": "./postgres/index.js",
|
|
27
|
+
"./maria": "./maria/index.js",
|
|
28
|
+
"./sqlite": "./sqlite/index.js",
|
|
29
|
+
"./mongo": "./mongo/index.js",
|
|
30
|
+
"./express": "./express/index.js",
|
|
31
|
+
"./browser": {
|
|
32
|
+
"types": "./browser/index.d.ts",
|
|
33
|
+
"import": "./browser/index.js",
|
|
34
|
+
"default": "./browser/uql-browser.min.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": false,
|
|
9
38
|
"scripts": {
|
|
10
|
-
"copyfiles": "copyfiles -f package.json
|
|
11
|
-
"
|
|
39
|
+
"copyfiles": "copyfiles -f package.json ../README.md ../CHANGELOG.md dist",
|
|
40
|
+
"compile.browser": "bunchee --clean false --no-dts ./src/browser/index.ts --sourcemap -o ./dist/browser/uql-browser.min.js",
|
|
41
|
+
"build": "bun run clean && tsc -b tsconfig.build.json && bun run compile.browser && bun run copyfiles",
|
|
12
42
|
"start": "tsc --watch",
|
|
13
43
|
"clean": "rimraf dist *.tsbuildinfo"
|
|
14
44
|
},
|
|
15
45
|
"dependencies": {
|
|
16
|
-
"reflect-metadata": "^0.
|
|
46
|
+
"reflect-metadata": "^0.2.2",
|
|
17
47
|
"sqlstring": "^2.3.3",
|
|
18
|
-
"
|
|
48
|
+
"sqlstring-sqlite": "^0.1.1",
|
|
49
|
+
"tslib": "^2.8.1"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"better-sqlite3": ">=9.0.0",
|
|
53
|
+
"express": ">=5.0.0",
|
|
54
|
+
"mariadb": ">=3.0.0",
|
|
55
|
+
"mongodb": ">=6.0.0",
|
|
56
|
+
"mysql2": ">=3.0.0",
|
|
57
|
+
"pg": ">=8.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"express": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"mariadb": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"mongodb": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"mysql2": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"pg": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"better-sqlite3": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
19
78
|
},
|
|
20
79
|
"devDependencies": {
|
|
21
|
-
"@types/
|
|
22
|
-
"@types/
|
|
23
|
-
"@types/
|
|
80
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
81
|
+
"@types/express": "^5.0.6",
|
|
82
|
+
"@types/node": "^25.0.3",
|
|
83
|
+
"@types/pg": "^8.16.0",
|
|
84
|
+
"@types/sqlstring": "^2.3.2",
|
|
85
|
+
"better-sqlite3": "^12.5.0",
|
|
86
|
+
"bunchee": "^6.9.1",
|
|
24
87
|
"copyfiles": "^2.4.1",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
88
|
+
"express": "^5.2.1",
|
|
89
|
+
"mariadb": "^3.4.5",
|
|
90
|
+
"mongodb": "^7.0.0",
|
|
91
|
+
"mysql2": "^3.16.0",
|
|
92
|
+
"pg": "^8.16.3",
|
|
93
|
+
"rimraf": "^6.1.2",
|
|
94
|
+
"typescript": "~5.4.5"
|
|
28
95
|
},
|
|
29
96
|
"author": "Roger Padilla",
|
|
30
97
|
"repository": {
|
|
@@ -54,10 +121,11 @@
|
|
|
54
121
|
"dao",
|
|
55
122
|
"transaction",
|
|
56
123
|
"repository",
|
|
57
|
-
"service"
|
|
124
|
+
"service",
|
|
125
|
+
"migrations"
|
|
58
126
|
],
|
|
59
127
|
"publishConfig": {
|
|
60
128
|
"access": "public"
|
|
61
129
|
},
|
|
62
|
-
"gitHead": "
|
|
63
|
-
}
|
|
130
|
+
"gitHead": "47f2055cf30ab5655ac57ba4278e8c7b4541db0b"
|
|
131
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './jest';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import type { RequestNotification } from '../type/index.js';
|
|
3
|
+
import { notify, on } from './bus.js';
|
|
4
|
+
|
|
5
|
+
it('bus', () => {
|
|
6
|
+
const off = on((msg) => {
|
|
7
|
+
const expected: RequestNotification = {
|
|
8
|
+
phase: 'start',
|
|
9
|
+
opts: {
|
|
10
|
+
silent: true,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
expect(msg).toEqual(expected);
|
|
14
|
+
off();
|
|
15
|
+
});
|
|
16
|
+
notify({
|
|
17
|
+
phase: 'start',
|
|
18
|
+
opts: {
|
|
19
|
+
silent: true,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RequestCallback, RequestNotification } from '../type/index.js';
|
|
2
|
+
|
|
3
|
+
const subscriptors: RequestCallback[] = [];
|
|
4
|
+
|
|
5
|
+
export function notify(notification: RequestNotification): void {
|
|
6
|
+
for (const subscriptor of subscriptors) {
|
|
7
|
+
subscriptor(notification);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function on(cb: RequestCallback): () => void {
|
|
12
|
+
subscriptors.push(cb);
|
|
13
|
+
const index = subscriptors.length - 1;
|
|
14
|
+
return (): void => {
|
|
15
|
+
subscriptors.splice(index, 1);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, jest } from 'bun:test';
|
|
2
|
+
import { get, patch, post, put, remove } from './http.js';
|
|
3
|
+
|
|
4
|
+
describe('http', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
globalThis.fetch = jest.fn() as any;
|
|
7
|
+
(globalThis.fetch as unknown as jest.Mock).mockImplementation(setupFetchStub({}));
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
delete globalThis.fetch;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('post', async () => {
|
|
15
|
+
const body = {};
|
|
16
|
+
await post('/', body);
|
|
17
|
+
expect(globalThis.fetch).toHaveBeenCalledWith(
|
|
18
|
+
'/',
|
|
19
|
+
expect.objectContaining({ body: JSON.stringify(body), method: 'post' }),
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('patch', async () => {
|
|
24
|
+
const body = {};
|
|
25
|
+
await patch('/', body);
|
|
26
|
+
expect(globalThis.fetch).toHaveBeenCalledWith(
|
|
27
|
+
'/',
|
|
28
|
+
expect.objectContaining({ body: JSON.stringify(body), method: 'patch' }),
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('put', async () => {
|
|
33
|
+
const body = {};
|
|
34
|
+
await put('/', body);
|
|
35
|
+
expect(globalThis.fetch).toHaveBeenCalledWith(
|
|
36
|
+
'/',
|
|
37
|
+
expect.objectContaining({ body: JSON.stringify(body), method: 'put' }),
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('get', async () => {
|
|
42
|
+
await get('/?a=1');
|
|
43
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/?a=1', expect.objectContaining({ method: 'get' }));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('remove', async () => {
|
|
47
|
+
await remove('/?a=1');
|
|
48
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/?a=1', expect.objectContaining({ method: 'delete' }));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('error', async () => {
|
|
52
|
+
globalThis.fetch = jest.fn() as any;
|
|
53
|
+
(globalThis.fetch as unknown as jest.Mock).mockImplementation(setupFetchStubError(new Error('some error')));
|
|
54
|
+
await expect(remove('/?a=1')).rejects.toThrow('some error');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
function setupFetchStub(data: object) {
|
|
59
|
+
return async (_url: any) => ({
|
|
60
|
+
status: 200,
|
|
61
|
+
json: async () => ({ data }),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function setupFetchStubError(error: Error) {
|
|
66
|
+
return async (_url: any) => ({
|
|
67
|
+
status: 500,
|
|
68
|
+
json: async () => ({ error }),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { RequestErrorResponse, RequestOptions, RequestSuccessResponse } from '../type/index.js';
|
|
2
|
+
import { notify } from './bus.js';
|
|
3
|
+
|
|
4
|
+
export function get<T>(url: string, opts?: RequestOptions) {
|
|
5
|
+
return request<T>(url, { method: 'get' }, opts);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function post<T>(url: string, payload: unknown, opts?: RequestOptions) {
|
|
9
|
+
const body = JSON.stringify(payload);
|
|
10
|
+
return request<T>(url, { method: 'post', body }, opts);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function patch<T>(url: string, payload: unknown, opts?: RequestOptions) {
|
|
14
|
+
const body = JSON.stringify(payload);
|
|
15
|
+
return request<T>(url, { method: 'patch', body }, opts);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function put<T>(url: string, payload: unknown, opts?: RequestOptions) {
|
|
19
|
+
const body = JSON.stringify(payload);
|
|
20
|
+
return request<T>(url, { method: 'put', body }, opts);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function remove<T>(url: string, opts?: RequestOptions) {
|
|
24
|
+
return request<T>(url, { method: 'delete' }, opts);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function request<T>(url: string, init: RequestInit, opts?: RequestOptions) {
|
|
28
|
+
notify({ phase: 'start', opts });
|
|
29
|
+
|
|
30
|
+
init.headers = {
|
|
31
|
+
accept: 'application/json',
|
|
32
|
+
'content-type': 'application/json',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return fetch(url, init)
|
|
36
|
+
.then((rawResp) =>
|
|
37
|
+
rawResp.json().then((resp: unknown) => {
|
|
38
|
+
const isSuccess = rawResp.status >= 200 && rawResp.status < 300;
|
|
39
|
+
if (isSuccess) {
|
|
40
|
+
notify({ phase: 'success', opts });
|
|
41
|
+
return resp as RequestSuccessResponse<T>;
|
|
42
|
+
}
|
|
43
|
+
const errorResp = resp as RequestErrorResponse;
|
|
44
|
+
notify({
|
|
45
|
+
phase: 'error',
|
|
46
|
+
error: errorResp.error,
|
|
47
|
+
opts,
|
|
48
|
+
});
|
|
49
|
+
throw Error(errorResp.error.message);
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
.finally(() => {
|
|
53
|
+
notify({ phase: 'complete', opts });
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { User } from '../test/index.js';
|
|
3
|
+
import { getQuerier, getQuerierPool, setQuerierPool } from './options.js';
|
|
4
|
+
import { GenericClientRepository, HttpQuerier } from './querier/index.js';
|
|
5
|
+
import type { ClientQuerierPool } from './type/clientQuerierPool.js';
|
|
6
|
+
|
|
7
|
+
describe('options', () => {
|
|
8
|
+
it('default getQuerier', () => {
|
|
9
|
+
const querier = getQuerier();
|
|
10
|
+
expect(querier).toBeInstanceOf(HttpQuerier);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('default querierPool', () => {
|
|
14
|
+
expect(getQuerierPool()).toBeDefined();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('custom querierPool', () => {
|
|
18
|
+
const querierMock = new HttpQuerier('/');
|
|
19
|
+
|
|
20
|
+
const querierPool: ClientQuerierPool = {
|
|
21
|
+
getQuerier: () => querierMock,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
setQuerierPool(querierPool);
|
|
25
|
+
|
|
26
|
+
const querier1 = getQuerierPool().getQuerier();
|
|
27
|
+
expect(querier1).toBe(querierMock);
|
|
28
|
+
|
|
29
|
+
const querier2 = getQuerier();
|
|
30
|
+
expect(querier2).toBe(querierMock);
|
|
31
|
+
|
|
32
|
+
const repository1 = querier2.getRepository(User);
|
|
33
|
+
expect(repository1).toBeInstanceOf(GenericClientRepository);
|
|
34
|
+
|
|
35
|
+
expect(getQuerierPool()).toBe(getQuerierPool());
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HttpQuerier } from './querier/httpQuerier.js';
|
|
2
|
+
import type { ClientQuerier, ClientQuerierPool } from './type/index.js';
|
|
3
|
+
|
|
4
|
+
let defaultPool: ClientQuerierPool = {
|
|
5
|
+
getQuerier: () => new HttpQuerier('/api'),
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function setQuerierPool<T extends ClientQuerierPool>(pool: T) {
|
|
9
|
+
defaultPool = pool;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getQuerierPool(): ClientQuerierPool {
|
|
13
|
+
return defaultPool;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getQuerier(): ClientQuerier {
|
|
17
|
+
return getQuerierPool().getQuerier();
|
|
18
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, jest } from 'bun:test';
|
|
2
|
+
import { User } from '../../test/index.js';
|
|
3
|
+
import { GenericClientRepository } from './genericClientRepository.js';
|
|
4
|
+
import { HttpQuerier } from './httpQuerier.js';
|
|
5
|
+
|
|
6
|
+
describe('repository', () => {
|
|
7
|
+
let repository: GenericClientRepository<User>;
|
|
8
|
+
const querier = new HttpQuerier('');
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
globalThis.fetch = jest.fn() as any;
|
|
12
|
+
(globalThis.fetch as unknown as jest.Mock).mockImplementation(setupFetchStub({}));
|
|
13
|
+
repository = new GenericClientRepository(User, querier);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
delete globalThis.fetch;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('count', async () => {
|
|
21
|
+
await repository.count({});
|
|
22
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user/count', expect.objectContaining({ method: 'get' }));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('findOneById', async () => {
|
|
26
|
+
await repository.findOneById(1);
|
|
27
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user/1', expect.objectContaining({ method: 'get' }));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('findOne', async () => {
|
|
31
|
+
await repository.findOne({});
|
|
32
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user/one', expect.objectContaining({ method: 'get' }));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('findMany', async () => {
|
|
36
|
+
await repository.findMany({});
|
|
37
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user', expect.objectContaining({ method: 'get' }));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('findManyAndCount', async () => {
|
|
41
|
+
await repository.findManyAndCount({});
|
|
42
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user?count=true', expect.objectContaining({ method: 'get' }));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('insertOne', async () => {
|
|
46
|
+
await repository.insertOne({});
|
|
47
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user', expect.objectContaining({ method: 'post' }));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('updateOneById', async () => {
|
|
51
|
+
await repository.updateOneById(1, {});
|
|
52
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user/1', expect.objectContaining({ method: 'patch' }));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('saveOne', async () => {
|
|
56
|
+
await repository.saveOne({});
|
|
57
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user', expect.objectContaining({ method: 'post' }));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('saveOne id', async () => {
|
|
61
|
+
await repository.saveOne({ id: 2 });
|
|
62
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user/2', expect.objectContaining({ method: 'patch' }));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('deleteOneById', async () => {
|
|
66
|
+
await repository.deleteOneById(1);
|
|
67
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user/1', expect.objectContaining({ method: 'delete' }));
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('deleteOneById soft', async () => {
|
|
71
|
+
await repository.deleteOneById(1, { softDelete: true });
|
|
72
|
+
expect(globalThis.fetch).toHaveBeenCalledWith(
|
|
73
|
+
'/user/1?softDelete=true',
|
|
74
|
+
expect.objectContaining({ method: 'delete' }),
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('deleteMany', async () => {
|
|
79
|
+
await repository.deleteMany({});
|
|
80
|
+
expect(globalThis.fetch).toHaveBeenCalledWith('/user', expect.objectContaining({ method: 'delete' }));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('deleteMany soft', async () => {
|
|
84
|
+
await repository.deleteMany({}, { softDelete: true });
|
|
85
|
+
expect(globalThis.fetch).toHaveBeenCalledWith(
|
|
86
|
+
'/user?softDelete=true',
|
|
87
|
+
expect.objectContaining({ method: 'delete' }),
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('entity property', () => {
|
|
92
|
+
expect(repository.entity).toBe(User);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('repository property', () => {
|
|
96
|
+
expect(repository.querier).toBe(querier);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
function setupFetchStub(data: object) {
|
|
101
|
+
return async (_url: any) => ({
|
|
102
|
+
status: 200,
|
|
103
|
+
json: async () => ({ data }),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { IdValue, Query, QueryOne, QueryOptions, QuerySearch, Type } from '../../type/index.js';
|
|
2
|
+
import type { ClientQuerier, ClientRepository, RequestOptions } from '../type/index.js';
|
|
3
|
+
|
|
4
|
+
export class GenericClientRepository<E> implements ClientRepository<E> {
|
|
5
|
+
constructor(
|
|
6
|
+
readonly entity: Type<E>,
|
|
7
|
+
readonly querier: ClientQuerier,
|
|
8
|
+
) {}
|
|
9
|
+
|
|
10
|
+
findOneById(id: IdValue<E>, q?: QueryOne<E>, opts?: RequestOptions) {
|
|
11
|
+
return this.querier.findOneById(this.entity, id, q, opts);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
findOne(q: QueryOne<E>, opts?: RequestOptions) {
|
|
15
|
+
return this.querier.findOne(this.entity, q, opts);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
findMany(q: Query<E>, opts?: RequestOptions) {
|
|
19
|
+
return this.querier.findMany(this.entity, q, opts);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
findManyAndCount(q: Query<E>, opts?: RequestOptions) {
|
|
23
|
+
return this.querier.findManyAndCount(this.entity, q, opts);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
count(qm?: QuerySearch<E>, opts?: RequestOptions) {
|
|
27
|
+
return this.querier.count(this.entity, qm, opts);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
insertOne(payload: E, opts?: RequestOptions) {
|
|
31
|
+
return this.querier.insertOne(this.entity, payload, opts);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
updateOneById(id: IdValue<E>, payload: E, opts?: RequestOptions) {
|
|
35
|
+
return this.querier.updateOneById(this.entity, id, payload, opts);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
saveOne(payload: E, opts?: RequestOptions) {
|
|
39
|
+
return this.querier.saveOne(this.entity, payload, opts);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
deleteOneById(id: IdValue<E>, opts?: QueryOptions) {
|
|
43
|
+
return this.querier.deleteOneById(this.entity, id, opts);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
deleteMany(qm: QuerySearch<E>, opts?: QueryOptions) {
|
|
47
|
+
return this.querier.deleteMany(this.entity, qm, opts);
|
|
48
|
+
}
|
|
49
|
+
}
|