remult 0.22.5 → 0.22.6-exp.2
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/esm/graphql.js +29 -28
- package/esm/internals.js +7 -0
- package/esm/migrations/compare-migration-snapshots.js +61 -0
- package/esm/migrations/generate-migrations.js +68 -0
- package/esm/migrations/index.js +2 -0
- package/esm/migrations/migrate.js +85 -0
- package/esm/migrations/migration-types.js +36 -0
- package/esm/migrations/update-migrations-ts-file.js +115 -0
- package/esm/package.json +3 -0
- package/esm/postgres/schema-builder.js +4 -4
- package/esm/remult-better-sqlite3.js +47 -0
- package/esm/remult-bun-sqlite.js +41 -0
- package/esm/remult-duckdb.js +111 -0
- package/esm/remult-hapi.js +114 -0
- package/esm/remult-hono.js +104 -0
- package/esm/remult-mongo.js +1 -1
- package/esm/remult-nuxt.js +54 -0
- package/esm/remult-solid-start.js +97 -0
- package/esm/remult-sql-js.js +41 -0
- package/esm/remult-sqlite-core.js +137 -0
- package/esm/remult-sqlite3.js +61 -0
- package/esm/remult-turso.js +59 -0
- package/esm/server/get-remult-admin-html.js +3 -0
- package/esm/server/initDataProviderOrJson.js +6 -0
- package/esm/server/remult-admin.js +95 -0
- package/esm/server/remult-api-server.js +1157 -0
- package/esm/src/CompoundIdField.js +62 -0
- package/esm/src/backend-tests/backend-database-test-setup.backend-spec.js +11 -10
- package/esm/src/data-api.js +4 -2
- package/esm/src/data-providers/json-entity-opfs-storage.js +26 -0
- package/esm/src/isOfType.js +9 -0
- package/esm/src/live-query/SubscriptionServer.js +2 -2
- package/esm/src/remult-static.js +43 -0
- package/esm/src/remult3/Fields.js +335 -0
- package/esm/src/remult3/IdEntity.js +10 -0
- package/esm/src/remult3/RepositoryImplementation.js +7 -4
- package/esm/src/remult3/__updateEntityBasedOnWhere.js +28 -0
- package/esm/src/remult3/addValidator.js +15 -0
- package/esm/{core/src/remult3/DecoratorReplacer.js → src/remult3/classDescribers.js} +18 -3
- package/esm/src/remult3/entity.js +70 -0
- package/esm/src/remult3/getEntityRef.js +36 -0
- package/esm/src/remult3/relation-loader.js +153 -0
- package/esm/src/remult3/relationInfoMember.js +116 -0
- package/esm/src/remult3/repository-internals.js +7 -0
- package/esm/src/server-action-info.js +1 -0
- package/esm/src/shared-tests/db-tests.db-tests.js +1 -1
- package/graphql.js +2 -1
- package/internals.d.ts +15 -0
- package/internals.js +18 -0
- package/migrations/compare-migration-snapshots.d.ts +27 -0
- package/migrations/compare-migration-snapshots.js +164 -0
- package/migrations/generate-migrations.d.ts +21 -0
- package/migrations/generate-migrations.js +103 -0
- package/migrations/index.d.ts +3 -0
- package/migrations/index.js +7 -0
- package/migrations/migrate.d.ts +27 -0
- package/migrations/migrate.js +170 -0
- package/migrations/migration-types.d.ts +48 -0
- package/migrations/migration-types.js +88 -0
- package/migrations/update-migrations-ts-file.d.ts +1 -0
- package/migrations/update-migrations-ts-file.js +140 -0
- package/package.json +1 -1
- package/remult-better-sqlite3.d.ts +12 -0
- package/remult-better-sqlite3.js +64 -0
- package/remult-bun-sqlite.d.ts +11 -0
- package/remult-bun-sqlite.js +56 -0
- package/remult-duckdb.d.ts +9 -0
- package/remult-duckdb.js +150 -0
- package/remult-hapi.d.ts +6 -0
- package/remult-hapi.js +127 -0
- package/remult-hono.d.ts +7 -0
- package/remult-hono.js +115 -0
- package/remult-mongo.js +1 -1
- package/remult-nuxt.d.ts +6 -0
- package/remult-nuxt.js +78 -0
- package/remult-solid-start.d.ts +12 -0
- package/remult-solid-start.js +133 -0
- package/remult-sql-js.d.ts +5 -0
- package/remult-sql-js.js +73 -0
- package/remult-sqlite-core.d.ts +25 -0
- package/remult-sqlite-core.js +314 -0
- package/remult-sqlite3.d.ts +5 -0
- package/remult-sqlite3.js +76 -0
- package/remult-turso.d.ts +8 -0
- package/remult-turso.js +100 -0
- package/server/get-remult-admin-html.d.ts +1 -0
- package/server/get-remult-admin-html.js +6 -0
- package/server/initDataProviderOrJson.d.ts +2 -0
- package/server/initDataProviderOrJson.js +16 -0
- package/server/remult-admin.d.ts +43 -0
- package/server/remult-admin.js +123 -0
- package/{esm/core/server/expressBridge.d.ts → server/remult-api-server.d.ts} +75 -77
- package/server/remult-api-server.js +1626 -0
- package/src/CompoundIdField.d.ts +27 -0
- package/src/CompoundIdField.js +72 -0
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +11 -10
- package/src/data-api.js +4 -2
- package/src/data-providers/json-entity-opfs-storage.d.ts +5 -0
- package/src/data-providers/json-entity-opfs-storage.js +74 -0
- package/src/isOfType.d.ts +2 -0
- package/src/isOfType.js +13 -0
- package/src/live-query/SubscriptionServer.js +2 -2
- package/src/remult-static.d.ts +26 -0
- package/src/remult-static.js +50 -0
- package/src/remult3/Fields.d.ts +170 -0
- package/src/remult3/Fields.js +419 -0
- package/src/remult3/IdEntity.d.ts +4 -0
- package/src/remult3/IdEntity.js +18 -0
- package/src/remult3/RepositoryImplementation.js +24 -22
- package/src/remult3/__updateEntityBasedOnWhere.d.ts +2 -0
- package/src/remult3/__updateEntityBasedOnWhere.js +31 -0
- package/src/remult3/addValidator.d.ts +2 -0
- package/src/remult3/addValidator.js +19 -0
- package/src/remult3/classDescribers.d.ts +16 -0
- package/src/remult3/classDescribers.js +40 -0
- package/src/remult3/columnInfo.d.ts +6 -0
- package/src/remult3/columnInfo.js +2 -0
- package/src/remult3/entity.d.ts +28 -0
- package/src/remult3/entity.js +86 -0
- package/src/remult3/getEntityRef.d.ts +18 -0
- package/src/remult3/getEntityRef.js +45 -0
- package/src/remult3/relation-loader-types.d.ts +7 -0
- package/src/remult3/relation-loader-types.js +2 -0
- package/src/remult3/relation-loader.d.ts +40 -0
- package/src/remult3/relation-loader.js +245 -0
- package/src/remult3/relationInfoMember.d.ts +30 -0
- package/src/remult3/relationInfoMember.js +149 -0
- package/src/remult3/repository-internals.d.ts +20 -0
- package/src/remult3/repository-internals.js +11 -0
- package/src/server-action-info.d.ts +1 -0
- package/src/server-action-info.js +4 -0
- package/src/shared-tests/db-tests.db-tests.js +1 -1
- package/esm/angular/interfaces/index.d.ts +0 -1
- package/esm/angular/interfaces/index.js +0 -1
- package/esm/angular/interfaces/src/column-collection.d.ts +0 -70
- package/esm/angular/interfaces/src/column-collection.js +0 -341
- package/esm/angular/interfaces/src/data-area-settings.d.ts +0 -15
- package/esm/angular/interfaces/src/data-area-settings.js +0 -35
- package/esm/angular/interfaces/src/data-control-interfaces.d.ts +0 -36
- package/esm/angular/interfaces/src/data-control-interfaces.js +0 -57
- package/esm/angular/interfaces/src/dataList.d.ts +0 -13
- package/esm/angular/interfaces/src/dataList.js +0 -42
- package/esm/angular/interfaces/src/filter-helper.d.ts +0 -13
- package/esm/angular/interfaces/src/filter-helper.js +0 -59
- package/esm/angular/interfaces/src/grid-settings.d.ts +0 -145
- package/esm/angular/interfaces/src/grid-settings.js +0 -387
- package/esm/angular/interfaces/src/public_api.d.ts +0 -4
- package/esm/angular/interfaces/src/public_api.js +0 -4
- package/esm/angular/src/angular/RemultAngularPluginsService.d.ts +0 -4
- package/esm/angular/src/angular/RemultAngularPluginsService.js +0 -3
- package/esm/angular/src/angular/data-control/data-control2.component.d.ts +0 -49
- package/esm/angular/src/angular/data-control/data-control2.component.js +0 -138
- package/esm/core/SseSubscriptionServer.d.ts +0 -33
- package/esm/core/SseSubscriptionServer.js +0 -107
- package/esm/core/assign.d.ts +0 -1
- package/esm/core/assign.js +0 -5
- package/esm/core/classType.d.ts +0 -3
- package/esm/core/index.d.ts +0 -27
- package/esm/core/index.js +0 -25
- package/esm/core/inputTypes.d.ts +0 -9
- package/esm/core/inputTypes.js +0 -9
- package/esm/core/live-query/data-provider-live-query-storage.d.ts +0 -22
- package/esm/core/live-query/data-provider-live-query-storage.js +0 -71
- package/esm/core/postgres/index.d.ts +0 -2
- package/esm/core/postgres/index.js +0 -2
- package/esm/core/postgres/postgres-data-provider.d.ts +0 -36
- package/esm/core/postgres/postgres-data-provider.js +0 -120
- package/esm/core/postgres/schema-builder.d.ts +0 -17
- package/esm/core/postgres/schema-builder.js +0 -153
- package/esm/core/remult-fresh.d.ts +0 -17
- package/esm/core/remult-fresh.js +0 -29
- package/esm/core/remult-knex/index.d.ts +0 -30
- package/esm/core/remult-knex/index.js +0 -446
- package/esm/core/remult-mongo.d.ts +0 -24
- package/esm/core/remult-mongo.js +0 -254
- package/esm/core/server/JsonEntityFileStorage.d.ts +0 -10
- package/esm/core/server/JsonEntityFileStorage.js +0 -25
- package/esm/core/server/core.d.ts +0 -4
- package/esm/core/server/core.js +0 -4
- package/esm/core/server/expressBridge.js +0 -938
- package/esm/core/server/index.d.ts +0 -6
- package/esm/core/server/index.js +0 -9
- package/esm/core/server/initAsyncHooks.d.ts +0 -1
- package/esm/core/server/initAsyncHooks.js +0 -9
- package/esm/core/server/initDataProvider.d.ts +0 -2
- package/esm/core/server/initDataProvider.js +0 -14
- package/esm/core/src/__EntityValueProvider.d.ts +0 -11
- package/esm/core/src/__RowsOfDataForTesting.d.ts +0 -3
- package/esm/core/src/__RowsOfDataForTesting.js +0 -1
- package/esm/core/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +0 -6
- package/esm/core/src/backend-tests/backend-database-test-setup.backend-spec.js +0 -147
- package/esm/core/src/backend-tests/my-test.backend-spec.d.ts +0 -1
- package/esm/core/src/backend-tests/my-test.backend-spec.js +0 -197
- package/esm/core/src/backend-tests/test-http-server.backend-spec.d.ts +0 -1
- package/esm/core/src/backend-tests/test-http-server.backend-spec.js +0 -167
- package/esm/core/src/buildRestDataProvider.d.ts +0 -31
- package/esm/core/src/buildRestDataProvider.js +0 -113
- package/esm/core/src/column-interfaces.d.ts +0 -154
- package/esm/core/src/column-interfaces.js +0 -7
- package/esm/core/src/column.d.ts +0 -58
- package/esm/core/src/column.js +0 -174
- package/esm/core/src/context.d.ts +0 -134
- package/esm/core/src/context.js +0 -286
- package/esm/core/src/data-api.d.ts +0 -39
- package/esm/core/src/data-api.js +0 -279
- package/esm/core/src/data-interfaces.d.ts +0 -41
- package/esm/core/src/data-interfaces.js +0 -12
- package/esm/core/src/data-providers/array-entity-data-provider.d.ts +0 -22
- package/esm/core/src/data-providers/array-entity-data-provider.js +0 -252
- package/esm/core/src/data-providers/in-memory-database.d.ts +0 -9
- package/esm/core/src/data-providers/in-memory-database.js +0 -14
- package/esm/core/src/data-providers/json-data-provider.d.ts +0 -12
- package/esm/core/src/data-providers/json-data-provider.js +0 -55
- package/esm/core/src/data-providers/rest-data-provider.d.ts +0 -49
- package/esm/core/src/data-providers/rest-data-provider.js +0 -256
- package/esm/core/src/data-providers/sql-database.d.ts +0 -33
- package/esm/core/src/data-providers/sql-database.js +0 -384
- package/esm/core/src/data-providers/web-sql-data-provider.d.ts +0 -24
- package/esm/core/src/data-providers/web-sql-data-provider.js +0 -143
- package/esm/core/src/entity.d.ts +0 -91
- package/esm/core/src/entity.js +0 -1
- package/esm/core/src/filter/filter-consumer-bridge-to-sql-request.d.ts +0 -50
- package/esm/core/src/filter/filter-consumer-bridge-to-sql-request.js +0 -150
- package/esm/core/src/filter/filter-consumer-bridge-to-url-builder.d.ts +0 -1
- package/esm/core/src/filter/filter-consumer-bridge-to-url-builder.js +0 -1
- package/esm/core/src/filter/filter-interfaces.d.ts +0 -85
- package/esm/core/src/filter/filter-interfaces.js +0 -477
- package/esm/core/src/live-query/LiveQueryClient.d.ts +0 -20
- package/esm/core/src/live-query/LiveQueryClient.js +0 -188
- package/esm/core/src/live-query/SseSubscriptionClient.d.ts +0 -5
- package/esm/core/src/live-query/SseSubscriptionClient.js +0 -86
- package/esm/core/src/live-query/SubscriptionChannel.d.ts +0 -72
- package/esm/core/src/live-query/SubscriptionChannel.js +0 -123
- package/esm/core/src/live-query/SubscriptionServer.d.ts +0 -53
- package/esm/core/src/live-query/SubscriptionServer.js +0 -111
- package/esm/core/src/live-query/live-query-tests.spec.d.ts +0 -6
- package/esm/core/src/live-query/live-query-tests.spec.js +0 -952
- package/esm/core/src/remult-proxy.d.ts +0 -35
- package/esm/core/src/remult-proxy.js +0 -113
- package/esm/core/src/remult3/DecoratorReplacer.d.ts +0 -10
- package/esm/core/src/remult3/RepositoryImplementation.d.ts +0 -355
- package/esm/core/src/remult3/RepositoryImplementation.js +0 -2109
- package/esm/core/src/remult3/index.d.ts +0 -2
- package/esm/core/src/remult3/index.js +0 -2
- package/esm/core/src/remult3/remult3.d.ts +0 -395
- package/esm/core/src/remult3/remult3.js +0 -2
- package/esm/core/src/server-action.d.ts +0 -81
- package/esm/core/src/server-action.js +0 -394
- package/esm/core/src/shared-tests/db-tests-setup.d.ts +0 -32
- package/esm/core/src/shared-tests/db-tests-setup.js +0 -78
- package/esm/core/src/shared-tests/db-tests.db-tests.d.ts +0 -25
- package/esm/core/src/shared-tests/db-tests.db-tests.js +0 -810
- package/esm/core/src/shared-tests/deleteAll.d.ts +0 -2
- package/esm/core/src/shared-tests/deleteAll.js +0 -4
- package/esm/core/src/shared-tests/entityWithValidations.d.ts +0 -14
- package/esm/core/src/shared-tests/entityWithValidations.js +0 -43
- package/esm/core/src/shared-tests/index.d.ts +0 -4
- package/esm/core/src/shared-tests/index.js +0 -4
- package/esm/core/src/shared-tests/test-custom-id-column.spec.d.ts +0 -1
- package/esm/core/src/shared-tests/test-custom-id-column.spec.js +0 -67
- package/esm/core/src/shared-tests/test-special-value.spec.d.ts +0 -10
- package/esm/core/src/shared-tests/test-special-value.spec.js +0 -73
- package/esm/core/src/shared-tests/test-update-with-null.spec.d.ts +0 -1
- package/esm/core/src/shared-tests/test-update-with-null.spec.js +0 -31
- package/esm/core/src/sort.d.ts +0 -16
- package/esm/core/src/sort.js +0 -103
- package/esm/core/src/sql-command.d.ts +0 -19
- package/esm/core/src/sql-command.js +0 -1
- package/esm/core/src/test.d.ts +0 -3
- package/esm/core/src/test.js +0 -12
- package/esm/core/src/tests/Done.d.ts +0 -5
- package/esm/core/src/tests/Done.js +0 -9
- package/esm/core/src/tests/RowProvider.spec.d.ts +0 -16
- package/esm/core/src/tests/RowProvider.spec.js +0 -631
- package/esm/core/src/tests/TestDataApiResponse.d.ts +0 -10
- package/esm/core/src/tests/TestDataApiResponse.js +0 -22
- package/esm/core/src/tests/basicRowFunctionality.spec.d.ts +0 -8
- package/esm/core/src/tests/basicRowFunctionality.spec.js +0 -2103
- package/esm/core/src/tests/c.d.ts +0 -8
- package/esm/core/src/tests/c.js +0 -13
- package/esm/core/src/tests/createData.d.ts +0 -7
- package/esm/core/src/tests/createData.js +0 -22
- package/esm/core/src/tests/d.d.ts +0 -6
- package/esm/core/src/tests/d.js +0 -11
- package/esm/core/src/tests/dWithPrefilter.d.ts +0 -7
- package/esm/core/src/tests/dWithPrefilter.js +0 -18
- package/esm/core/src/tests/entityForCustomFilter.d.ts +0 -16
- package/esm/core/src/tests/entityForCustomFilter.js +0 -33
- package/esm/core/src/tests/entityWithValidationsOnColumn.d.ts +0 -5
- package/esm/core/src/tests/entityWithValidationsOnColumn.js +0 -13
- package/esm/core/src/tests/frontend-database-tests-setup.spec.d.ts +0 -4
- package/esm/core/src/tests/frontend-database-tests-setup.spec.js +0 -37
- package/esm/core/src/tests/h.d.ts +0 -6
- package/esm/core/src/tests/h.js +0 -24
- package/esm/core/src/tests/remult-3-basic-tests.spec.d.ts +0 -1
- package/esm/core/src/tests/remult-3-basic-tests.spec.js +0 -236
- package/esm/core/src/tests/remult-3-entities.d.ts +0 -23
- package/esm/core/src/tests/remult-3-entities.js +0 -39
- package/esm/core/src/tests/tasks.d.ts +0 -6
- package/esm/core/src/tests/tasks.js +0 -10
- package/esm/core/src/tests/test-context-as-storage.spec.d.ts +0 -0
- package/esm/core/src/tests/test-context-as-storage.spec.js +0 -1
- package/esm/core/src/tests/test-data-api/predefined-filter.spec.d.ts +0 -1
- package/esm/core/src/tests/test-data-api/predefined-filter.spec.js +0 -389
- package/esm/core/src/tests/test-data-api/test-put-with-validation.spec.d.ts +0 -5
- package/esm/core/src/tests/test-data-api/test-put-with-validation.spec.js +0 -152
- package/esm/core/src/tests/test-decorator-precedence.spec.d.ts +0 -1
- package/esm/core/src/tests/test-decorator-precedence.spec.js +0 -38
- package/esm/core/src/tests/test-default-value.spec.d.ts +0 -1
- package/esm/core/src/tests/test-default-value.spec.js +0 -33
- package/esm/core/src/tests/test-entity-inheritance.spec.d.ts +0 -14
- package/esm/core/src/tests/test-entity-inheritance.spec.js +0 -82
- package/esm/core/src/tests/test-exceptions.spec.d.ts +0 -1
- package/esm/core/src/tests/test-exceptions.spec.js +0 -375
- package/esm/core/src/tests/test-json.spec.d.ts +0 -1
- package/esm/core/src/tests/test-json.spec.js +0 -115
- package/esm/core/src/tests/test-many-to-one-relation-in-entity.spec.d.ts +0 -9
- package/esm/core/src/tests/test-many-to-one-relation-in-entity.spec.js +0 -809
- package/esm/core/src/tests/test-non-active-record.spec.d.ts +0 -1
- package/esm/core/src/tests/test-non-active-record.spec.js +0 -66
- package/esm/core/src/tests/test-object-column.spec.d.ts +0 -1
- package/esm/core/src/tests/test-object-column.spec.js +0 -189
- package/esm/core/src/tests/test-paged-foreach.spec.d.ts +0 -1
- package/esm/core/src/tests/test-paged-foreach.spec.js +0 -328
- package/esm/core/src/tests/test-remult-angular.spec.d.ts +0 -1
- package/esm/core/src/tests/test-remult-angular.spec.js +0 -23
- package/esm/core/src/tests/test-server-controller.spec.d.ts +0 -7
- package/esm/core/src/tests/test-server-controller.spec.js +0 -489
- package/esm/core/src/tests/test-server-expressions.spec.d.ts +0 -1
- package/esm/core/src/tests/test-server-expressions.spec.js +0 -178
- package/esm/core/src/tests/test-server-method-on-entity.spec.d.ts +0 -1
- package/esm/core/src/tests/test-server-method-on-entity.spec.js +0 -306
- package/esm/core/src/tests/test-sql-expression.spec.d.ts +0 -5
- package/esm/core/src/tests/test-sql-expression.spec.js +0 -205
- package/esm/core/src/tests/test-sql.spec.d.ts +0 -1
- package/esm/core/src/tests/test-sql.spec.js +0 -170
- package/esm/core/src/tests/test-subscribe.spec.d.ts +0 -1
- package/esm/core/src/tests/test-subscribe.spec.js +0 -135
- package/esm/core/src/tests/test-type-recovery.spec.d.ts +0 -1
- package/esm/core/src/tests/test-type-recovery.spec.js +0 -49
- package/esm/core/src/tests/test-where-api.spec.d.ts +0 -1
- package/esm/core/src/tests/test-where-api.spec.js +0 -434
- package/esm/core/src/tests/testHelper.spec.d.ts +0 -36
- package/esm/core/src/tests/testHelper.spec.js +0 -226
- package/esm/core/src/tests/testModel/models.d.ts +0 -16
- package/esm/core/src/tests/testModel/models.js +0 -25
- package/esm/core/src/validators.d.ts +0 -14
- package/esm/core/src/validators.js +0 -33
- package/esm/core/src/valueConverters.d.ts +0 -13
- package/esm/core/src/valueConverters.js +0 -197
- package/esm/core/urlBuilder.d.ts +0 -6
- package/esm/core/urlBuilder.js +0 -20
- package/esm/test-servers/shared/Task.d.ts +0 -9
- package/esm/test-servers/shared/Task.js +0 -32
- package/esm/test.d.ts +0 -5
- package/esm/test.js +0 -6
- /package/esm/{core/classType.js → src/remult3/columnInfo.js} +0 -0
- /package/esm/{core/src/__EntityValueProvider.js → src/remult3/relation-loader-types.js} +0 -0
package/esm/graphql.js
CHANGED
|
@@ -87,7 +87,7 @@ export function remultGraphql(options) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
if (whereType === 'String') {
|
|
90
|
-
for (const operator of ['
|
|
90
|
+
for (const operator of ['contains']) {
|
|
91
91
|
const field = {
|
|
92
92
|
key: operator,
|
|
93
93
|
value: whereType,
|
|
@@ -208,16 +208,16 @@ export function remultGraphql(options) {
|
|
|
208
208
|
{
|
|
209
209
|
key: 'limit',
|
|
210
210
|
value: 'Int',
|
|
211
|
-
comment: `
|
|
212
|
-
For **page by page** pagination.
|
|
213
|
-
Limit the number of result.
|
|
211
|
+
comment: `
|
|
212
|
+
For **page by page** pagination.
|
|
213
|
+
Limit the number of result.
|
|
214
214
|
_Side note: \`Math.ceil(totalCount / limit)\` to determine how many pages there are._`,
|
|
215
215
|
},
|
|
216
216
|
{
|
|
217
217
|
key: 'page',
|
|
218
218
|
value: 'Int',
|
|
219
|
-
comment: `
|
|
220
|
-
For **page by page** pagination.
|
|
219
|
+
comment: `
|
|
220
|
+
For **page by page** pagination.
|
|
221
221
|
Select a dedicated page.`,
|
|
222
222
|
},
|
|
223
223
|
{
|
|
@@ -235,26 +235,26 @@ Select a dedicated page.`,
|
|
|
235
235
|
queryArgsConnection.push({
|
|
236
236
|
key: 'first',
|
|
237
237
|
value: 'Int',
|
|
238
|
-
comment: `
|
|
239
|
-
For **forward cursor** pagination
|
|
238
|
+
comment: `
|
|
239
|
+
For **forward cursor** pagination
|
|
240
240
|
Takes the \`first\`: \`n\` elements from the list.`,
|
|
241
241
|
}, {
|
|
242
242
|
key: 'after',
|
|
243
243
|
value: 'String',
|
|
244
|
-
comment: `
|
|
245
|
-
For **forward cursor** pagination
|
|
244
|
+
comment: `
|
|
245
|
+
For **forward cursor** pagination
|
|
246
246
|
\`after\` this \`cursor\`.`,
|
|
247
247
|
}, {
|
|
248
248
|
key: 'last',
|
|
249
249
|
value: 'Int',
|
|
250
|
-
comment: `
|
|
251
|
-
For **backward cursor** pagination
|
|
250
|
+
comment: `
|
|
251
|
+
For **backward cursor** pagination
|
|
252
252
|
Takes the \`last\`: \`n\` elements from the list.`,
|
|
253
253
|
}, {
|
|
254
254
|
key: 'before',
|
|
255
255
|
value: 'String',
|
|
256
|
-
comment: `
|
|
257
|
-
For **backward cursor** pagination
|
|
256
|
+
comment: `
|
|
257
|
+
For **backward cursor** pagination
|
|
258
258
|
\`before\` this \`cursor\`.`,
|
|
259
259
|
});
|
|
260
260
|
}
|
|
@@ -668,7 +668,7 @@ Select a dedicated page.`,
|
|
|
668
668
|
: ``;
|
|
669
669
|
return `${type}${orderByStr}${whereTypeStr}${whereTypeSubFieldsStr}`;
|
|
670
670
|
})
|
|
671
|
-
.join(`\n\n`)}
|
|
671
|
+
.join(`\n\n`)}
|
|
672
672
|
`,
|
|
673
673
|
};
|
|
674
674
|
}
|
|
@@ -690,12 +690,12 @@ function blockFormat(obj) {
|
|
|
690
690
|
if (obj.data.length === 0) {
|
|
691
691
|
return ``;
|
|
692
692
|
}
|
|
693
|
-
const str = `${obj.prefix} {
|
|
694
|
-
${obj.data.join('\n ')}
|
|
693
|
+
const str = `${obj.prefix} {
|
|
694
|
+
${obj.data.join('\n ')}
|
|
695
695
|
}`;
|
|
696
|
-
let commentsStr = `"""
|
|
697
|
-
${obj.comment}
|
|
698
|
-
"""
|
|
696
|
+
let commentsStr = `"""
|
|
697
|
+
${obj.comment}
|
|
698
|
+
"""
|
|
699
699
|
`;
|
|
700
700
|
if (_removeComments) {
|
|
701
701
|
commentsStr = ``;
|
|
@@ -706,16 +706,16 @@ function argsFormat(args) {
|
|
|
706
706
|
if (args) {
|
|
707
707
|
return `(${args
|
|
708
708
|
.map((arg) => {
|
|
709
|
-
let strComment = `
|
|
710
|
-
"""
|
|
711
|
-
${arg.comment}
|
|
712
|
-
"""
|
|
709
|
+
let strComment = `
|
|
710
|
+
"""
|
|
711
|
+
${arg.comment}
|
|
712
|
+
"""
|
|
713
713
|
`;
|
|
714
714
|
if (_removeComments || !arg.comment) {
|
|
715
715
|
strComment = ``;
|
|
716
716
|
}
|
|
717
717
|
if (strComment) {
|
|
718
|
-
return `${strComment} ${arg.key}: ${arg.value}
|
|
718
|
+
return `${strComment} ${arg.key}: ${arg.value}
|
|
719
719
|
`;
|
|
720
720
|
}
|
|
721
721
|
return `${arg.key}: ${arg.value}`;
|
|
@@ -726,9 +726,9 @@ function argsFormat(args) {
|
|
|
726
726
|
}
|
|
727
727
|
function fieldFormat(field) {
|
|
728
728
|
// First, the comment
|
|
729
|
-
let strComment = `"""
|
|
730
|
-
${field.comment}
|
|
731
|
-
"""
|
|
729
|
+
let strComment = `"""
|
|
730
|
+
${field.comment}
|
|
731
|
+
"""
|
|
732
732
|
`;
|
|
733
733
|
if (_removeComments || !field.comment) {
|
|
734
734
|
strComment = ``;
|
|
@@ -801,6 +801,7 @@ export function translateWhereToRestBody(fields, { where }) {
|
|
|
801
801
|
}
|
|
802
802
|
tr('nin', (x) => (result[field.key + '.ne'] = x));
|
|
803
803
|
tr('eq', (x) => (result[field.key] = x));
|
|
804
|
+
tr('contains', (x) => (result[field.key + '.contains'] = x));
|
|
804
805
|
}
|
|
805
806
|
}
|
|
806
807
|
if (where.OR) {
|
package/esm/internals.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { remultStatic } from './src/remult-static.js';
|
|
2
|
+
export { getRelationInfo, getRelationFieldInfo, } from './src/remult3/relationInfoMember.js';
|
|
3
|
+
export { decorateColumnSettings, controllerRefImpl, getControllerRef, } from './src/remult3/RepositoryImplementation.js';
|
|
4
|
+
export { getEntitySettings } from './src/remult3/getEntityRef.js';
|
|
5
|
+
export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces.js';
|
|
6
|
+
export const actionInfo = remultStatic.actionInfo;
|
|
7
|
+
export { flags } from './src/remult3/remult3.js';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { repo } from '../index.js';
|
|
2
|
+
import { dbNamesOf, shouldCreateEntity, shouldNotCreateField, } from '../src/filter/filter-consumer-bridge-to-sql-request.js';
|
|
3
|
+
export async function compareMigrationSnapshot({ entities, snapshot, migrationBuilder, reporter, }) {
|
|
4
|
+
snapshot = JSON.parse(JSON.stringify(snapshot));
|
|
5
|
+
let processedEntities = new Set();
|
|
6
|
+
for (const entity of entities) {
|
|
7
|
+
const meta = repo(entity).metadata;
|
|
8
|
+
const e = await dbNamesOf(meta, (x) => x);
|
|
9
|
+
processedEntities.add(e.$entityName);
|
|
10
|
+
if (shouldCreateEntity(meta, e)) {
|
|
11
|
+
let entitySnapshot = snapshot.entities[e.$entityName];
|
|
12
|
+
let createColumns = true;
|
|
13
|
+
if (!entitySnapshot) {
|
|
14
|
+
createColumns = false;
|
|
15
|
+
reporter('create table ' + e.$entityName);
|
|
16
|
+
await migrationBuilder.createTable(meta);
|
|
17
|
+
entitySnapshot = snapshot.entities[e.$entityName] = {
|
|
18
|
+
key: meta.key,
|
|
19
|
+
className: meta.entityType.name,
|
|
20
|
+
columns: {},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const processedColumns = new Set();
|
|
24
|
+
for (const field of meta.fields) {
|
|
25
|
+
if (!shouldNotCreateField(field, e)) {
|
|
26
|
+
const columnDbName = e.$dbNameOf(field);
|
|
27
|
+
processedColumns.add(columnDbName);
|
|
28
|
+
const column = entitySnapshot.columns[columnDbName];
|
|
29
|
+
if (!column) {
|
|
30
|
+
if (createColumns) {
|
|
31
|
+
reporter('add column ' + e.$entityName + '.' + columnDbName);
|
|
32
|
+
await migrationBuilder.addColumn(meta, field);
|
|
33
|
+
}
|
|
34
|
+
entitySnapshot.columns[columnDbName] = { key: field.key };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const columnDbName of Object.keys(entitySnapshot.columns)) {
|
|
39
|
+
if (!processedColumns.has(columnDbName)) {
|
|
40
|
+
reporter('remove column ' + e.$entityName + '.' + columnDbName);
|
|
41
|
+
await migrationBuilder.removeColumn(e.$entityName, columnDbName);
|
|
42
|
+
delete entitySnapshot.columns[columnDbName];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const entityDbName of Object.keys(snapshot.entities)) {
|
|
48
|
+
if (!processedEntities.has(entityDbName)) {
|
|
49
|
+
reporter('remove table ' + entityDbName);
|
|
50
|
+
await migrationBuilder.removeTable(entityDbName);
|
|
51
|
+
delete snapshot.entities[entityDbName];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return snapshot;
|
|
55
|
+
}
|
|
56
|
+
export function emptySnapshot() {
|
|
57
|
+
return {
|
|
58
|
+
version: 1,
|
|
59
|
+
entities: {},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { compareMigrationSnapshot, emptySnapshot, } from './compare-migration-snapshots.js';
|
|
4
|
+
import { updateMigrationsFile } from './update-migrations-ts-file.js';
|
|
5
|
+
import { DefaultMigrationBuilder, } from './migration-types.js';
|
|
6
|
+
import { isOfType } from '../src/isOfType.js';
|
|
7
|
+
import { initDataProviderOrJson } from '../server/initDataProviderOrJson.js';
|
|
8
|
+
/**
|
|
9
|
+
* Generates migration scripts based on changes in entities.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Configuration options for generating migrations.
|
|
12
|
+
* @param options.entities - An array of entity classes whose changes will be included in the migration.
|
|
13
|
+
* @param options.dataProvider - The data provider instance or a function returning a promise of the data provider.
|
|
14
|
+
* @param options.migrationsFolder - (Optional) The path to the folder where migration scripts will be stored. Default is 'src/migrations'.
|
|
15
|
+
* @param options.snapshotFile - (Optional) The path to the file where the snapshot of the last known state will be stored. Default is 'migrations-snapshot.json' in the `migrationsFolder`.
|
|
16
|
+
* @param options.migrationsTSFile - (Optional) The path to the TypeScript file where the generated migrations will be written. Default is 'migrations.ts' in the `migrationsFolder`.
|
|
17
|
+
* @param options.endConnection - (Optional) Determines whether to close the database connection after generating migrations. Default is false.
|
|
18
|
+
* @see [Migrations](https://remult.dev/docs/migrations.html)
|
|
19
|
+
*/
|
|
20
|
+
export async function generateMigrations(options) {
|
|
21
|
+
const migrationDir = options.migrationsFolder || path.join(process.cwd(), 'src/migrations');
|
|
22
|
+
const snapshotFileName = options.snapshotFile || path.join(migrationDir, 'migrations-snapshot.json');
|
|
23
|
+
const migrationsTSFilename = options.migrationsTSFile || path.join(migrationDir, 'migrations.ts');
|
|
24
|
+
const dataProvider = await initDataProviderOrJson(options.dataProvider);
|
|
25
|
+
for (const p of [snapshotFileName, migrationsTSFilename]) {
|
|
26
|
+
if (!fs.existsSync(path.dirname(p))) {
|
|
27
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let snapshot = emptySnapshot();
|
|
31
|
+
if (fs.existsSync(snapshotFileName)) {
|
|
32
|
+
snapshot = JSON.parse(fs.readFileSync(snapshotFileName).toString());
|
|
33
|
+
}
|
|
34
|
+
let hasSql = false;
|
|
35
|
+
let steps = [];
|
|
36
|
+
const code = {
|
|
37
|
+
//https://marketplace.visualstudio.com/items?itemName=qufiwefefwoyn.inline-sql-syntax
|
|
38
|
+
addSql: (sql) => {
|
|
39
|
+
steps.push('await sql(`--sql\n' + sql + '`)');
|
|
40
|
+
hasSql = true;
|
|
41
|
+
},
|
|
42
|
+
addTypescriptCode: (code) => steps.push(code),
|
|
43
|
+
addComment: (comment) => steps.push(comment.indexOf('\n') >= 0 ? `/*${comment}*/` : `// ${comment}`),
|
|
44
|
+
};
|
|
45
|
+
let migrationBuilder = new DefaultMigrationBuilder(code);
|
|
46
|
+
if (isOfType(dataProvider, 'provideMigrationBuilder')) {
|
|
47
|
+
migrationBuilder = new DefaultMigrationBuilder(code, dataProvider.provideMigrationBuilder(code));
|
|
48
|
+
}
|
|
49
|
+
let reporter = (what) => console.log('[generateMigrations] ' + what);
|
|
50
|
+
snapshot = await compareMigrationSnapshot({
|
|
51
|
+
entities: options.entities,
|
|
52
|
+
snapshot,
|
|
53
|
+
reporter,
|
|
54
|
+
migrationBuilder,
|
|
55
|
+
});
|
|
56
|
+
if (steps.length)
|
|
57
|
+
await updateMigrationsFile(migrationsTSFilename, [
|
|
58
|
+
`async (${hasSql ? '{sql}' : ''})=>{\n${steps.join('\n')}\n}`,
|
|
59
|
+
]);
|
|
60
|
+
else {
|
|
61
|
+
reporter('No changes detected');
|
|
62
|
+
}
|
|
63
|
+
fs.writeFileSync(snapshotFileName, JSON.stringify(snapshot, null, 2));
|
|
64
|
+
if (options.endConnection && isOfType(dataProvider, 'end')) {
|
|
65
|
+
await dataProvider.end();
|
|
66
|
+
}
|
|
67
|
+
return steps.length > 0;
|
|
68
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Entity, IdEntity, Fields, remult, Remult, describeClass, } from '../index.js';
|
|
2
|
+
import { initDataProviderOrJson } from '../server/initDataProviderOrJson.js';
|
|
3
|
+
import { doTransaction } from '../src/context.js';
|
|
4
|
+
import { cast, isOfType } from '../src/isOfType.js';
|
|
5
|
+
/**
|
|
6
|
+
* Applies migration scripts to update the database schema.
|
|
7
|
+
*
|
|
8
|
+
* @param options - Configuration options for applying migrations.
|
|
9
|
+
* @param options.migrations - An object containing the migration scripts, each keyed by a unique identifier.
|
|
10
|
+
* @param options.dataProvider - The data provider instance or a function returning a promise of the data provider.
|
|
11
|
+
* @param options.migrationsTable - (Optional) The name of the table that tracks applied migrations. Default is '__remult_migrations_version'.
|
|
12
|
+
* @param options.endConnection - (Optional) Determines whether to close the database connection after applying migrations. Default is false.
|
|
13
|
+
* @param options.beforeMigration - (Optional) A callback function that is called before each migration is applied. Receives an object with the migration index.
|
|
14
|
+
* @param options.afterMigration - (Optional) A callback function that is called after each migration is applied. Receives an object with the migration index and the duration of the migration.
|
|
15
|
+
* @see [Migrations](https://remult.dev/docs/migrations.html)
|
|
16
|
+
*/
|
|
17
|
+
export async function migrate(options) {
|
|
18
|
+
let migrationTableName = options.migrationsTable || '__remult_migrations_version';
|
|
19
|
+
const dataProvider = await initDataProviderOrJson(options.dataProvider);
|
|
20
|
+
const prev = remult.dataProvider;
|
|
21
|
+
remult.dataProvider = dataProvider;
|
|
22
|
+
try {
|
|
23
|
+
class VersionInfo extends IdEntity {
|
|
24
|
+
version = -1;
|
|
25
|
+
}
|
|
26
|
+
describeClass(VersionInfo, Entity(migrationTableName), {
|
|
27
|
+
version: Fields.integer(),
|
|
28
|
+
});
|
|
29
|
+
const steps = Object.entries(options.migrations).sort(([a], [b]) => parseInt(a) - parseInt(b));
|
|
30
|
+
if (dataProvider.ensureSchema) {
|
|
31
|
+
await dataProvider.ensureSchema([
|
|
32
|
+
new Remult(dataProvider).repo(VersionInfo).metadata,
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
await doTransaction(remult, async (dp) => {
|
|
36
|
+
const repo = new Remult(dataProvider).repo(VersionInfo, dp);
|
|
37
|
+
let v = await repo.findFirst();
|
|
38
|
+
if (!v) {
|
|
39
|
+
v = repo.create();
|
|
40
|
+
v.version = -1;
|
|
41
|
+
}
|
|
42
|
+
for (const [stepText, action] of steps) {
|
|
43
|
+
const step = parseInt(stepText);
|
|
44
|
+
if (step < 0)
|
|
45
|
+
throw new Error('Migration step number must be a non-negative integer');
|
|
46
|
+
if (v.version >= step)
|
|
47
|
+
continue;
|
|
48
|
+
if (options.beforeMigration) {
|
|
49
|
+
await options.beforeMigration({ index: step });
|
|
50
|
+
}
|
|
51
|
+
const startTime = Date.now();
|
|
52
|
+
console.info('Executing migration step ' + step);
|
|
53
|
+
console.time('Completed migration step ' + step);
|
|
54
|
+
try {
|
|
55
|
+
const utils = {
|
|
56
|
+
sql: async (sql) => {
|
|
57
|
+
return await cast(dp, 'execute').execute(sql);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
await action(utils);
|
|
61
|
+
if (options.afterMigration) {
|
|
62
|
+
await options.afterMigration({
|
|
63
|
+
index: step,
|
|
64
|
+
duration: Date.now() - startTime,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
console.timeEnd('Completed migration step ' + step);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
console.error('Failed to execute migration step ' + step);
|
|
71
|
+
console.error(err);
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
v.version = step;
|
|
75
|
+
await v.save();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
remult.dataProvider = prev;
|
|
81
|
+
}
|
|
82
|
+
if (options.endConnection && isOfType(dataProvider, 'end')) {
|
|
83
|
+
await dataProvider.end();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class DefaultMigrationBuilder {
|
|
2
|
+
code;
|
|
3
|
+
wrapped;
|
|
4
|
+
constructor(code, wrapped) {
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.wrapped = wrapped;
|
|
7
|
+
}
|
|
8
|
+
async createTable(meta) {
|
|
9
|
+
if (this.wrapped?.createTable) {
|
|
10
|
+
await this.wrapped.createTable(meta);
|
|
11
|
+
}
|
|
12
|
+
else
|
|
13
|
+
this.code.addComment('TODO: implement create table ' + meta.dbName);
|
|
14
|
+
}
|
|
15
|
+
async addColumn(meta, field) {
|
|
16
|
+
if (this.wrapped?.addColumn) {
|
|
17
|
+
await this.wrapped.addColumn(meta, field);
|
|
18
|
+
}
|
|
19
|
+
else
|
|
20
|
+
this.code.addComment('TODO: implement add column ' + meta.dbName + '.' + field.dbName);
|
|
21
|
+
}
|
|
22
|
+
async removeTable(entityDbName) {
|
|
23
|
+
if (this.wrapped?.removeTable) {
|
|
24
|
+
await this.wrapped.removeTable(entityDbName);
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
this.code.addComment('TODO: implement remove table ' + entityDbName);
|
|
28
|
+
}
|
|
29
|
+
async removeColumn(entityName, columnDbName) {
|
|
30
|
+
if (this.wrapped?.removeColumn) {
|
|
31
|
+
await this.wrapped.removeColumn(entityName, columnDbName);
|
|
32
|
+
}
|
|
33
|
+
else
|
|
34
|
+
this.code.addComment('TODO: implement remove column ' + entityName + '.' + columnDbName);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// consider replacing with https://www.npmjs.com/package/ts-morph
|
|
2
|
+
export async function updateMigrationsFile(filePath, steps) {
|
|
3
|
+
let ts = await import('typescript');
|
|
4
|
+
//@ts-ignore
|
|
5
|
+
if (ts.default)
|
|
6
|
+
ts = ts.default;
|
|
7
|
+
const fs = await import('fs');
|
|
8
|
+
let maxStep = -1;
|
|
9
|
+
function buildSteps() {
|
|
10
|
+
return steps.map((step) => ts.factory.createPropertyAssignment(ts.factory.createIdentifier((++maxStep).toString()), ts.factory.createIdentifier(step)));
|
|
11
|
+
}
|
|
12
|
+
if (!fs.existsSync(filePath)) {
|
|
13
|
+
fs.writeFileSync(filePath, '');
|
|
14
|
+
}
|
|
15
|
+
const importPath = 'remult/migrations';
|
|
16
|
+
const importName = 'Migrations';
|
|
17
|
+
// Load the file
|
|
18
|
+
const sourceFile = ts.createSourceFile(filePath, fs.readFileSync(filePath).toString(), ts.ScriptTarget.Latest, true);
|
|
19
|
+
let migrationsExportFound = false;
|
|
20
|
+
// Find the "migrations" named export and add the new member
|
|
21
|
+
let updatedSourceFile = ts.transform(sourceFile, [
|
|
22
|
+
(context) => {
|
|
23
|
+
return (node) => {
|
|
24
|
+
const visitor = (node) => {
|
|
25
|
+
if (ts.isVariableStatement(node) &&
|
|
26
|
+
node.declarationList.declarations.length > 0) {
|
|
27
|
+
const declaration = node.declarationList.declarations[0];
|
|
28
|
+
if (ts.isIdentifier(declaration.name) &&
|
|
29
|
+
declaration.name.text === 'migrations' &&
|
|
30
|
+
declaration.initializer &&
|
|
31
|
+
ts.isObjectLiteralExpression(declaration.initializer)) {
|
|
32
|
+
migrationsExportFound = true;
|
|
33
|
+
declaration.initializer.properties.forEach((property) => {
|
|
34
|
+
if (ts.isPropertyAssignment(property)) {
|
|
35
|
+
if (ts.isNumericLiteral(property.name)) {
|
|
36
|
+
const step = parseInt(property.name.text);
|
|
37
|
+
if (step > maxStep) {
|
|
38
|
+
maxStep = step;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
let steps = buildSteps();
|
|
44
|
+
// Found the "migrations" array
|
|
45
|
+
// Update the initializer with the new steps
|
|
46
|
+
const updatedInitializer = ts.factory.updateObjectLiteralExpression(declaration.initializer, [...declaration.initializer.properties, ...steps]);
|
|
47
|
+
// Update the declaration with the new initializer
|
|
48
|
+
const updatedDeclaration = ts.factory.updateVariableDeclaration(declaration, declaration.name, undefined, declaration.type, // Preserve the original type annotation if present
|
|
49
|
+
updatedInitializer);
|
|
50
|
+
return ts.factory.updateVariableStatement(node, node.modifiers, ts.factory.updateVariableDeclarationList(node.declarationList, [
|
|
51
|
+
updatedDeclaration,
|
|
52
|
+
]));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return ts.visitEachChild(node, visitor, context);
|
|
56
|
+
};
|
|
57
|
+
return ts.visitNode(node, visitor);
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
]).transformed[0];
|
|
61
|
+
if (!migrationsExportFound) {
|
|
62
|
+
let importFound = false;
|
|
63
|
+
// Check if the import statement already exists
|
|
64
|
+
sourceFile.statements.forEach((statement) => {
|
|
65
|
+
if (ts.isImportDeclaration(statement) &&
|
|
66
|
+
ts.isStringLiteral(statement.moduleSpecifier) &&
|
|
67
|
+
statement.moduleSpecifier.text === `${importPath}`) {
|
|
68
|
+
statement.importClause?.namedBindings?.forEachChild((namedBinding) => {
|
|
69
|
+
if (ts.isImportSpecifier(namedBinding) &&
|
|
70
|
+
namedBinding.name.text === importName) {
|
|
71
|
+
importFound = true;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
// If the import statement doesn't exist, create it
|
|
77
|
+
if (!importFound) {
|
|
78
|
+
updatedSourceFile = ts.factory.updateSourceFile(updatedSourceFile, [
|
|
79
|
+
ts.factory.createExpressionStatement(ts.factory.createIdentifier(`import type { ${importName} } from '${importPath}'`)),
|
|
80
|
+
...updatedSourceFile.statements,
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
// Create a new export for migrations if it doesn't exist
|
|
84
|
+
const newMigrationsExport = ts.factory.createVariableStatement([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
85
|
+
ts.factory.createVariableDeclaration('migrations', undefined, // You can add a type annotation here if needed
|
|
86
|
+
ts.factory.createTypeReferenceNode(importName, undefined), ts.factory.createObjectLiteralExpression(buildSteps(), false)),
|
|
87
|
+
], ts.NodeFlags.Const));
|
|
88
|
+
// Add the new export to the end of the file
|
|
89
|
+
updatedSourceFile = ts.factory.updateSourceFile(updatedSourceFile, [
|
|
90
|
+
...updatedSourceFile.statements,
|
|
91
|
+
newMigrationsExport,
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
let code = ts.createPrinter().printFile(updatedSourceFile);
|
|
95
|
+
try {
|
|
96
|
+
let prettier;
|
|
97
|
+
try {
|
|
98
|
+
prettier = await import('prettier' + '');
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
console.warn('error importing prettier,for better formatting run `npm i -D prettier`. Writing raw code to file.');
|
|
102
|
+
}
|
|
103
|
+
if (prettier) {
|
|
104
|
+
let options = await prettier.resolveConfig();
|
|
105
|
+
code = await prettier.format(code, {
|
|
106
|
+
...options,
|
|
107
|
+
parser: 'typescript',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.log('error formatting code, writing raw code to file.');
|
|
113
|
+
}
|
|
114
|
+
fs.writeFileSync(filePath, code);
|
|
115
|
+
}
|
package/esm/package.json
ADDED
|
@@ -116,8 +116,8 @@ export class PostgresSchemaBuilder {
|
|
|
116
116
|
try {
|
|
117
117
|
let cmd = this.pool.createCommand();
|
|
118
118
|
const colName = e.$dbNameOf(c(entity));
|
|
119
|
-
if ((await cmd.execute(`select 1
|
|
120
|
-
FROM information_schema.columns
|
|
119
|
+
if ((await cmd.execute(`select 1
|
|
120
|
+
FROM information_schema.columns
|
|
121
121
|
WHERE table_name=${cmd.addParameterAndReturnSqlToken(e.$entityName.toLocaleLowerCase())} and column_name=${cmd.addParameterAndReturnSqlToken(colName.toLocaleLowerCase())}` + this.additionalWhere)).rows.length == 0) {
|
|
122
122
|
let sql = `alter table ${e.$entityName} add column ${postgresColumnSyntax(c(entity), colName)}`;
|
|
123
123
|
if (PostgresSchemaBuilder.logToConsole)
|
|
@@ -133,8 +133,8 @@ export class PostgresSchemaBuilder {
|
|
|
133
133
|
try {
|
|
134
134
|
let cmd = this.pool.createCommand();
|
|
135
135
|
let e = await dbNamesOf(entity);
|
|
136
|
-
let cols = (await cmd.execute(`select column_name
|
|
137
|
-
FROM information_schema.columns
|
|
136
|
+
let cols = (await cmd.execute(`select column_name
|
|
137
|
+
FROM information_schema.columns
|
|
138
138
|
WHERE table_name=${cmd.addParameterAndReturnSqlToken(e.$entityName.toLocaleLowerCase())} ` + this.additionalWhere)).rows.map((x) => x.column_name.toLocaleLowerCase());
|
|
139
139
|
for (const col of entity.fields) {
|
|
140
140
|
if (!isDbReadonly(col, e)) {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SqliteCoreDataProvider } from './remult-sqlite-core.js';
|
|
2
|
+
export class BetterSqlite3DataProvider extends SqliteCoreDataProvider {
|
|
3
|
+
constructor(db) {
|
|
4
|
+
super(() => new BetterSqlite3Command(db), async () => { db.close(); });
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
class BetterSqlite3Command {
|
|
8
|
+
db;
|
|
9
|
+
values = {};
|
|
10
|
+
i = 0;
|
|
11
|
+
constructor(db) {
|
|
12
|
+
this.db = db;
|
|
13
|
+
}
|
|
14
|
+
async execute(sql) {
|
|
15
|
+
const s = this.db.prepare(sql);
|
|
16
|
+
if (s.reader) {
|
|
17
|
+
return new BetterSqlite3SqlResult(s.all(this.values));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const result = s.run(this.values);
|
|
21
|
+
return new BetterSqlite3SqlResult([]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
addParameterAndReturnSqlToken(val) {
|
|
25
|
+
return this.param(val);
|
|
26
|
+
}
|
|
27
|
+
param(val) {
|
|
28
|
+
if (val instanceof Date)
|
|
29
|
+
val = val.valueOf();
|
|
30
|
+
if (typeof val === "boolean")
|
|
31
|
+
val = val ? 1 : 0;
|
|
32
|
+
const key = ':' + (this.i++);
|
|
33
|
+
this.values[key.substring(1)] = (val);
|
|
34
|
+
return key;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class BetterSqlite3SqlResult {
|
|
38
|
+
result;
|
|
39
|
+
constructor(result) {
|
|
40
|
+
this.result = result;
|
|
41
|
+
this.rows = result;
|
|
42
|
+
}
|
|
43
|
+
rows;
|
|
44
|
+
getColumnKeyInResultForIndexInSelect(index) {
|
|
45
|
+
return Object.keys(this.result[0])[index];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SqliteCoreDataProvider } from "./remult-sqlite-core.js";
|
|
2
|
+
export class BunSqliteDataProvider extends SqliteCoreDataProvider {
|
|
3
|
+
constructor(db) {
|
|
4
|
+
super(() => new BunSqliteCommand(db), async () => { db.close(); });
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
class BunSqliteCommand {
|
|
8
|
+
db;
|
|
9
|
+
values = {};
|
|
10
|
+
i = 0;
|
|
11
|
+
constructor(db) {
|
|
12
|
+
this.db = db;
|
|
13
|
+
}
|
|
14
|
+
async execute(sql) {
|
|
15
|
+
const s = this.db.query(sql);
|
|
16
|
+
return new BunSqliteSqlResult(s.all(this.values));
|
|
17
|
+
}
|
|
18
|
+
addParameterAndReturnSqlToken(val) {
|
|
19
|
+
return this.param(val);
|
|
20
|
+
}
|
|
21
|
+
param(val) {
|
|
22
|
+
if (val instanceof Date)
|
|
23
|
+
val = val.valueOf();
|
|
24
|
+
if (typeof val === "boolean")
|
|
25
|
+
val = val ? 1 : 0;
|
|
26
|
+
const key = ':' + (this.i++);
|
|
27
|
+
this.values[key] = (val);
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class BunSqliteSqlResult {
|
|
32
|
+
result;
|
|
33
|
+
constructor(result) {
|
|
34
|
+
this.result = result;
|
|
35
|
+
this.rows = result;
|
|
36
|
+
}
|
|
37
|
+
rows;
|
|
38
|
+
getColumnKeyInResultForIndexInSelect(index) {
|
|
39
|
+
return Object.keys(this.result[0])[index];
|
|
40
|
+
}
|
|
41
|
+
}
|