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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { setControllerSettings } from '../context.js';
|
|
2
|
+
import { entityInfo, entityInfo_key, getEntitySettings, } from './getEntityRef.js';
|
|
3
|
+
import { remultStatic } from '../remult-static.js';
|
|
4
|
+
/**Decorates classes that should be used as entities.
|
|
5
|
+
* Receives a key and an array of EntityOptions.
|
|
6
|
+
* @example
|
|
7
|
+
* import { Entity, Fields } from "remult";
|
|
8
|
+
* @Entity("tasks", {
|
|
9
|
+
* allowApiCrud: true
|
|
10
|
+
* })
|
|
11
|
+
* export class Task {
|
|
12
|
+
* @Fields.uuid()
|
|
13
|
+
* id!: string;
|
|
14
|
+
* @Fields.string()
|
|
15
|
+
* title = '';
|
|
16
|
+
* @Fields.boolean()
|
|
17
|
+
* completed = false;
|
|
18
|
+
* }
|
|
19
|
+
* @note
|
|
20
|
+
* EntityOptions can be set in two ways:
|
|
21
|
+
* @example
|
|
22
|
+
* // as an object
|
|
23
|
+
* @Entity("tasks",{ allowApiCrud:true })
|
|
24
|
+
* @example
|
|
25
|
+
* // as an arrow function that receives `remult` as a parameter
|
|
26
|
+
* @Entity("tasks", (options,remult) => options.allowApiCrud = true)
|
|
27
|
+
*/
|
|
28
|
+
export function Entity(key, ...options) {
|
|
29
|
+
return (target, info) => {
|
|
30
|
+
for (const rawFilterMember in target) {
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(target, rawFilterMember)) {
|
|
32
|
+
const element = target[rawFilterMember];
|
|
33
|
+
if (element?.rawFilterInfo) {
|
|
34
|
+
if (!element.rawFilterInfo.key)
|
|
35
|
+
element.rawFilterInfo.key = rawFilterMember;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let factory = (remult) => {
|
|
40
|
+
let r = {};
|
|
41
|
+
for (const o of options) {
|
|
42
|
+
if (o) {
|
|
43
|
+
if (typeof o === 'function')
|
|
44
|
+
o(r, remult);
|
|
45
|
+
else
|
|
46
|
+
Object.assign(r, o);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
let base = Object.getPrototypeOf(target);
|
|
50
|
+
if (base) {
|
|
51
|
+
let baseFactory = getEntitySettings(base, false);
|
|
52
|
+
if (baseFactory) {
|
|
53
|
+
let opt = baseFactory(remult);
|
|
54
|
+
if (opt) {
|
|
55
|
+
r = {
|
|
56
|
+
...opt,
|
|
57
|
+
...r,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return r;
|
|
63
|
+
};
|
|
64
|
+
remultStatic.allEntities.push(target);
|
|
65
|
+
setControllerSettings(target, { key });
|
|
66
|
+
target[entityInfo] = factory;
|
|
67
|
+
target[entityInfo_key] = key;
|
|
68
|
+
return target;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the EntityRef object associated with the specified entity instance.
|
|
3
|
+
* The EntityRef provides methods for performing operations on the entity instance.
|
|
4
|
+
* @param {entityType} entity - The entity instance.
|
|
5
|
+
* @param {boolean} [throwException=true] - Indicates whether to throw an exception if the EntityRef object cannot be retrieved.
|
|
6
|
+
* @returns {EntityRef<entityType>} The EntityRef object associated with the specified entity instance.
|
|
7
|
+
* @throws {Error} If throwException is true and the EntityRef object cannot be retrieved.
|
|
8
|
+
* @see [Active Record & EntityBase](https://remult.dev/docs/active-record)
|
|
9
|
+
*/
|
|
10
|
+
export function getEntityRef(entity, throwException = true) {
|
|
11
|
+
let x = entity[entityMember];
|
|
12
|
+
if (!x && throwException)
|
|
13
|
+
throw new Error('item ' +
|
|
14
|
+
(entity.constructor?.name || entity) +
|
|
15
|
+
' was not initialized using a context');
|
|
16
|
+
return x;
|
|
17
|
+
}
|
|
18
|
+
export const entityMember = Symbol.for('entityMember');
|
|
19
|
+
export const entityInfo = Symbol.for('entityInfo');
|
|
20
|
+
export const entityInfo_key = Symbol.for('entityInfo_key');
|
|
21
|
+
export function getEntitySettings(entity, throwError = true) {
|
|
22
|
+
if (entity === undefined)
|
|
23
|
+
if (throwError) {
|
|
24
|
+
throw new Error('Undefined is not an entity :)');
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
return undefined;
|
|
28
|
+
let info = entity[entityInfo];
|
|
29
|
+
if (!info && throwError)
|
|
30
|
+
throw new Error(entity.prototype.constructor.name +
|
|
31
|
+
" is not a known entity, did you forget to set @Entity() or did you forget to add the '@' before the call to Entity?");
|
|
32
|
+
return info;
|
|
33
|
+
}
|
|
34
|
+
export function getEntityKey(entity) {
|
|
35
|
+
return entity[entityInfo_key];
|
|
36
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { findOptionsToJson } from '../data-providers/rest-data-provider.js';
|
|
2
|
+
import { getEntityRef } from './getEntityRef.js';
|
|
3
|
+
import { getRelationFieldInfo } from './relationInfoMember.js';
|
|
4
|
+
export class RelationLoader {
|
|
5
|
+
entityLoaders = new Map();
|
|
6
|
+
promises = [];
|
|
7
|
+
load(rel, findOptions) {
|
|
8
|
+
let e = this.entityLoaders.get(rel.entityType);
|
|
9
|
+
if (!e) {
|
|
10
|
+
this.entityLoaders.set(rel.entityType, (e = new EntityLoader(rel)));
|
|
11
|
+
}
|
|
12
|
+
const p = e.find(findOptions);
|
|
13
|
+
this.promises.push(p);
|
|
14
|
+
return p;
|
|
15
|
+
}
|
|
16
|
+
constructor() { }
|
|
17
|
+
async resolveAll() {
|
|
18
|
+
for (const entity of this.entityLoaders.values()) {
|
|
19
|
+
for (const variation of entity.queries.values()) {
|
|
20
|
+
variation.resolve();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (this.promises.length === 0)
|
|
24
|
+
return;
|
|
25
|
+
const x = this.promises;
|
|
26
|
+
this.promises = [];
|
|
27
|
+
await Promise.all(x);
|
|
28
|
+
await this.resolveAll();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class EntityLoader {
|
|
32
|
+
rel;
|
|
33
|
+
queries = new Map();
|
|
34
|
+
find(findOptions) {
|
|
35
|
+
const { where, ...options } = findOptionsToJson(findOptions, this.rel.metadata);
|
|
36
|
+
const optionKeys = JSON.stringify(options);
|
|
37
|
+
let q = this.queries.get(optionKeys);
|
|
38
|
+
if (!q) {
|
|
39
|
+
this.queries.set(optionKeys, (q = new QueryVariation(this.rel)));
|
|
40
|
+
}
|
|
41
|
+
return q.find(findOptions, where);
|
|
42
|
+
}
|
|
43
|
+
constructor(rel) {
|
|
44
|
+
this.rel = rel;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
class QueryVariation {
|
|
48
|
+
rel;
|
|
49
|
+
find(findOptions, where) {
|
|
50
|
+
const whereKey = JSON.stringify(where);
|
|
51
|
+
let w = this.whereVariations.get(whereKey);
|
|
52
|
+
if (!w) {
|
|
53
|
+
const keys = Object.keys(where);
|
|
54
|
+
if (keys.length === 1 &&
|
|
55
|
+
typeof where[keys[0]] !== 'object' &&
|
|
56
|
+
!findOptions.limit // because merging calls in that case may bring non more rows than the limit
|
|
57
|
+
) {
|
|
58
|
+
let inVariation = this.pendingInStatements.get(keys[0]);
|
|
59
|
+
if (!inVariation) {
|
|
60
|
+
this.pendingInStatements.set(keys[0], (inVariation = new PendingInStatements(this.rel, keys[0], findOptions)));
|
|
61
|
+
}
|
|
62
|
+
this.whereVariations.set(whereKey, (w = {
|
|
63
|
+
result: inVariation.find(where),
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.whereVariations.set(whereKey, (w = {
|
|
68
|
+
result: this.rel.find(findOptions),
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return w.result;
|
|
73
|
+
}
|
|
74
|
+
constructor(rel) {
|
|
75
|
+
this.rel = rel;
|
|
76
|
+
}
|
|
77
|
+
resolve() {
|
|
78
|
+
const statements = [...this.pendingInStatements.values()];
|
|
79
|
+
this.pendingInStatements.clear();
|
|
80
|
+
for (const statement of statements) {
|
|
81
|
+
statement.resolve();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
pendingInStatements = new Map();
|
|
85
|
+
whereVariations = new Map();
|
|
86
|
+
}
|
|
87
|
+
class PendingInStatements {
|
|
88
|
+
rel;
|
|
89
|
+
key;
|
|
90
|
+
options;
|
|
91
|
+
async resolve() {
|
|
92
|
+
const values = [...this.values.values()];
|
|
93
|
+
if (values.length == 1) {
|
|
94
|
+
this.rel.find(this.options).then(values[0].resolve, values[0].reject);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
var op = { ...this.options };
|
|
98
|
+
op.where = { [this.key]: values.map((v) => v.value) };
|
|
99
|
+
op.limit = 1000;
|
|
100
|
+
op.page = 1;
|
|
101
|
+
let vals = [];
|
|
102
|
+
try {
|
|
103
|
+
while (true) {
|
|
104
|
+
const val = await this.rel.find(op);
|
|
105
|
+
vals.push(...val);
|
|
106
|
+
if (val.length < op.limit)
|
|
107
|
+
break;
|
|
108
|
+
op.page++;
|
|
109
|
+
}
|
|
110
|
+
for (const value of this.values.values()) {
|
|
111
|
+
value.resolve(vals.filter((x) => {
|
|
112
|
+
const ref = getEntityRef(x);
|
|
113
|
+
const field = ref.fields.find(this.key);
|
|
114
|
+
const rel = getRelationFieldInfo(field.metadata);
|
|
115
|
+
const val = rel?.type === 'reference'
|
|
116
|
+
? field.getId()
|
|
117
|
+
: x[this.key];
|
|
118
|
+
return value.value == val;
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
for (const value of this.values.values()) {
|
|
124
|
+
value.reject(err);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
find(where) {
|
|
129
|
+
const val = where[this.key];
|
|
130
|
+
let valHandler = this.values.get(val);
|
|
131
|
+
if (!valHandler) {
|
|
132
|
+
let resolve;
|
|
133
|
+
let reject;
|
|
134
|
+
let result = new Promise((resolve1, reject1) => {
|
|
135
|
+
resolve = resolve1;
|
|
136
|
+
reject = reject1;
|
|
137
|
+
});
|
|
138
|
+
this.values.set(val, (valHandler = {
|
|
139
|
+
value: val,
|
|
140
|
+
resolve: resolve,
|
|
141
|
+
reject: reject,
|
|
142
|
+
result,
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
return valHandler.result;
|
|
146
|
+
}
|
|
147
|
+
values = new Map();
|
|
148
|
+
constructor(rel, key, options) {
|
|
149
|
+
this.rel = rel;
|
|
150
|
+
this.key = key;
|
|
151
|
+
this.options = options;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { CompoundIdField } from '../CompoundIdField.js';
|
|
2
|
+
export function relationInfoMemberInOptions(toEntityType, type) {
|
|
3
|
+
return {
|
|
4
|
+
[relationInfoMember]: {
|
|
5
|
+
toType: toEntityType,
|
|
6
|
+
type: type,
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const relationInfoMember = Symbol.for('relationInfo');
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
14
|
+
export function getRelationInfo(options) {
|
|
15
|
+
return options?.[relationInfoMember];
|
|
16
|
+
}
|
|
17
|
+
const fieldRelationInfo = Symbol.for('fieldRelationInfo');
|
|
18
|
+
export function getRelationFieldInfo(field) {
|
|
19
|
+
return field[fieldRelationInfo];
|
|
20
|
+
}
|
|
21
|
+
export function verifyFieldRelationInfo(repo, remult, dp) {
|
|
22
|
+
for (const field of repo.fields.toArray()) {
|
|
23
|
+
const r = getRelationInfo(field.options);
|
|
24
|
+
if (r) {
|
|
25
|
+
if (!field[fieldRelationInfo]) {
|
|
26
|
+
const toEntity = r.toType();
|
|
27
|
+
const toRepo = remult.repo(toEntity, dp);
|
|
28
|
+
const options = field.options;
|
|
29
|
+
field[fieldRelationInfo] = {
|
|
30
|
+
type: r.type,
|
|
31
|
+
toEntity,
|
|
32
|
+
options,
|
|
33
|
+
toRepo,
|
|
34
|
+
getFields: () => {
|
|
35
|
+
let relationField = options.field;
|
|
36
|
+
let relFields = {
|
|
37
|
+
fields: options.fields,
|
|
38
|
+
compoundIdField: undefined,
|
|
39
|
+
};
|
|
40
|
+
function buildError(what) {
|
|
41
|
+
return Error(`Error for relation: "${field.key}" to "${toRepo.metadata.key}": ` +
|
|
42
|
+
what);
|
|
43
|
+
}
|
|
44
|
+
let hasFields = () => relationField || relFields.fields;
|
|
45
|
+
if (r.type === 'toMany' && !hasFields()) {
|
|
46
|
+
for (const fieldInOtherRepo of toRepo.fields.toArray()) {
|
|
47
|
+
if (!hasFields()) {
|
|
48
|
+
const reverseRel = getRelationFieldInfo(fieldInOtherRepo);
|
|
49
|
+
const relOp = fieldInOtherRepo.options;
|
|
50
|
+
if (reverseRel)
|
|
51
|
+
if (reverseRel.toEntity === repo.metadata.entityType)
|
|
52
|
+
if (reverseRel.type === 'reference') {
|
|
53
|
+
relationField = fieldInOtherRepo.key;
|
|
54
|
+
}
|
|
55
|
+
else if (reverseRel.type === 'toOne') {
|
|
56
|
+
if (relOp.field) {
|
|
57
|
+
relationField = relOp.field;
|
|
58
|
+
}
|
|
59
|
+
else if (relOp.fields) {
|
|
60
|
+
let fields = {};
|
|
61
|
+
for (const key in relOp.fields) {
|
|
62
|
+
if (Object.prototype.hasOwnProperty.call(relOp.fields, key)) {
|
|
63
|
+
const keyInMyTable = relOp.fields[key];
|
|
64
|
+
fields[keyInMyTable] = key;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
relFields.fields = fields;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!hasFields())
|
|
73
|
+
throw buildError(`No matching field found on target. Please specify field/fields`);
|
|
74
|
+
}
|
|
75
|
+
function requireField(field, meta) {
|
|
76
|
+
const result = meta.fields.find(field);
|
|
77
|
+
if (!result)
|
|
78
|
+
throw buildError(`Field "${field}" was not found in "${meta.key}".`);
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
if (r.type === 'reference') {
|
|
82
|
+
relationField = field.key;
|
|
83
|
+
}
|
|
84
|
+
if (relationField) {
|
|
85
|
+
if (r.type === 'toOne' || r.type === 'reference') {
|
|
86
|
+
if (toRepo.metadata.idMetadata.field instanceof CompoundIdField) {
|
|
87
|
+
relFields.compoundIdField = relationField;
|
|
88
|
+
}
|
|
89
|
+
else
|
|
90
|
+
relFields.fields = {
|
|
91
|
+
[toRepo.metadata.idMetadata.field.key]: relationField,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
if (repo.metadata.idMetadata.field instanceof CompoundIdField) {
|
|
96
|
+
relFields.compoundIdField = relationField;
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
relFields.fields = {
|
|
100
|
+
[relationField]: repo.metadata.idMetadata.field.key,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
for (const key in relFields.fields) {
|
|
105
|
+
if (Object.prototype.hasOwnProperty.call(relFields.fields, key)) {
|
|
106
|
+
requireField(key, toRepo.metadata);
|
|
107
|
+
requireField(relFields.fields[key], repo.metadata);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return relFields;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function getRepositoryInternals(repo) {
|
|
2
|
+
const x = repo;
|
|
3
|
+
if (typeof x[getInternalKey] === 'function')
|
|
4
|
+
return x[getInternalKey]();
|
|
5
|
+
throw Error('Error getting repository internal from ' + repo);
|
|
6
|
+
}
|
|
7
|
+
export const getInternalKey = Symbol.for('getInternal');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const serverActionField = Symbol.for('serverActionField');
|
|
@@ -919,7 +919,7 @@ testAll('test contains with names with casing', async ({ createEntity }) => {
|
|
|
919
919
|
let item = await r.findFirst({ firstName: { $contains: 'oa' } });
|
|
920
920
|
expect(item.firstName).toBe('noam');
|
|
921
921
|
}, false, {
|
|
922
|
-
exclude: [TestDbs.mongo
|
|
922
|
+
exclude: [TestDbs.mongo],
|
|
923
923
|
});
|
|
924
924
|
testAll('test live query storage', async (x) => {
|
|
925
925
|
await x.createEntity(LiveQueryStorageEntity);
|
package/graphql.js
CHANGED
|
@@ -117,7 +117,7 @@ function remultGraphql(options) {
|
|
|
117
117
|
}
|
|
118
118
|
if (whereType === 'String') {
|
|
119
119
|
try {
|
|
120
|
-
for (var _p = (e_4 = void 0, tslib_1.__values(['
|
|
120
|
+
for (var _p = (e_4 = void 0, tslib_1.__values(['contains'])), _q = _p.next(); !_q.done; _q = _p.next()) {
|
|
121
121
|
var operator = _q.value;
|
|
122
122
|
var field = {
|
|
123
123
|
key: operator,
|
|
@@ -926,6 +926,7 @@ function translateWhereToRestBody(fields, _a) {
|
|
|
926
926
|
}
|
|
927
927
|
tr('nin', function (x) { return (result[field.key + '.ne'] = x); });
|
|
928
928
|
tr('eq', function (x) { return (result[field.key] = x); });
|
|
929
|
+
tr('contains', function (x) { return (result[field.key + '.contains'] = x); });
|
|
929
930
|
}
|
|
930
931
|
};
|
|
931
932
|
try {
|
package/internals.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { getRelationInfo, getRelationFieldInfo, RelationFieldInfo, RelationInfo, RelationFields, } from './src/remult3/relationInfoMember.js';
|
|
2
|
+
export { decorateColumnSettings, controllerRefImpl, getControllerRef, } from './src/remult3/RepositoryImplementation.js';
|
|
3
|
+
export { getEntitySettings } from './src/remult3/getEntityRef.js';
|
|
4
|
+
export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces.js';
|
|
5
|
+
export declare const actionInfo: {
|
|
6
|
+
allActions: any[];
|
|
7
|
+
runningOnServer: boolean;
|
|
8
|
+
runActionWithoutBlockingUI: <T>(what: () => Promise<T>) => Promise<T>;
|
|
9
|
+
startBusyWithProgress: () => {
|
|
10
|
+
progress: (percent: number) => void;
|
|
11
|
+
close: () => void;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export { ClassType } from './classType.js';
|
|
15
|
+
export { flags } from './src/remult3/remult3.js';
|
package/internals.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flags = exports.actionInfo = exports.__updateEntityBasedOnWhere = exports.getEntitySettings = exports.getControllerRef = exports.controllerRefImpl = exports.decorateColumnSettings = exports.getRelationFieldInfo = exports.getRelationInfo = void 0;
|
|
4
|
+
var remult_static_js_1 = require("./src/remult-static.js");
|
|
5
|
+
var relationInfoMember_js_1 = require("./src/remult3/relationInfoMember.js");
|
|
6
|
+
Object.defineProperty(exports, "getRelationInfo", { enumerable: true, get: function () { return relationInfoMember_js_1.getRelationInfo; } });
|
|
7
|
+
Object.defineProperty(exports, "getRelationFieldInfo", { enumerable: true, get: function () { return relationInfoMember_js_1.getRelationFieldInfo; } });
|
|
8
|
+
var RepositoryImplementation_js_1 = require("./src/remult3/RepositoryImplementation.js");
|
|
9
|
+
Object.defineProperty(exports, "decorateColumnSettings", { enumerable: true, get: function () { return RepositoryImplementation_js_1.decorateColumnSettings; } });
|
|
10
|
+
Object.defineProperty(exports, "controllerRefImpl", { enumerable: true, get: function () { return RepositoryImplementation_js_1.controllerRefImpl; } });
|
|
11
|
+
Object.defineProperty(exports, "getControllerRef", { enumerable: true, get: function () { return RepositoryImplementation_js_1.getControllerRef; } });
|
|
12
|
+
var getEntityRef_js_1 = require("./src/remult3/getEntityRef.js");
|
|
13
|
+
Object.defineProperty(exports, "getEntitySettings", { enumerable: true, get: function () { return getEntityRef_js_1.getEntitySettings; } });
|
|
14
|
+
var filter_interfaces_js_1 = require("./src/filter/filter-interfaces.js");
|
|
15
|
+
Object.defineProperty(exports, "__updateEntityBasedOnWhere", { enumerable: true, get: function () { return filter_interfaces_js_1.__updateEntityBasedOnWhere; } });
|
|
16
|
+
exports.actionInfo = remult_static_js_1.remultStatic.actionInfo;
|
|
17
|
+
var remult3_js_1 = require("./src/remult3/remult3.js");
|
|
18
|
+
Object.defineProperty(exports, "flags", { enumerable: true, get: function () { return remult3_js_1.flags; } });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MigrationBuilder } from './migration-types.js';
|
|
2
|
+
export declare function compareMigrationSnapshot({ entities, snapshot, migrationBuilder, reporter, }: {
|
|
3
|
+
entities: any[];
|
|
4
|
+
snapshot: EntitiesSnapshot;
|
|
5
|
+
migrationBuilder: Required<MigrationBuilder>;
|
|
6
|
+
reporter: (what: string) => void;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
version: number;
|
|
9
|
+
entities: Record<string, {
|
|
10
|
+
key: string;
|
|
11
|
+
className: string;
|
|
12
|
+
columns: Record<string, {
|
|
13
|
+
key: string;
|
|
14
|
+
}>;
|
|
15
|
+
}>;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function emptySnapshot(): {
|
|
18
|
+
version: number;
|
|
19
|
+
entities: Record<string, {
|
|
20
|
+
key: string;
|
|
21
|
+
className: string;
|
|
22
|
+
columns: Record<string, {
|
|
23
|
+
key: string;
|
|
24
|
+
}>;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
export type EntitiesSnapshot = ReturnType<typeof emptySnapshot>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareMigrationSnapshot = compareMigrationSnapshot;
|
|
4
|
+
exports.emptySnapshot = emptySnapshot;
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
var index_js_1 = require("../index.js");
|
|
7
|
+
var filter_consumer_bridge_to_sql_request_js_1 = require("../src/filter/filter-consumer-bridge-to-sql-request.js");
|
|
8
|
+
function compareMigrationSnapshot(_a) {
|
|
9
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (_b) {
|
|
10
|
+
var processedEntities, entities_1, entities_1_1, entity, meta, e, entitySnapshot, createColumns, processedColumns, _c, _d, field, columnDbName, column, e_1_1, _e, _f, columnDbName, e_2_1, e_3_1, _g, _h, entityDbName, e_4_1;
|
|
11
|
+
var e_3, _j, e_1, _k, e_2, _l, e_4, _m;
|
|
12
|
+
var entities = _b.entities, snapshot = _b.snapshot, migrationBuilder = _b.migrationBuilder, reporter = _b.reporter;
|
|
13
|
+
return tslib_1.__generator(this, function (_o) {
|
|
14
|
+
switch (_o.label) {
|
|
15
|
+
case 0:
|
|
16
|
+
snapshot = JSON.parse(JSON.stringify(snapshot));
|
|
17
|
+
processedEntities = new Set();
|
|
18
|
+
_o.label = 1;
|
|
19
|
+
case 1:
|
|
20
|
+
_o.trys.push([1, 23, 24, 25]);
|
|
21
|
+
entities_1 = tslib_1.__values(entities), entities_1_1 = entities_1.next();
|
|
22
|
+
_o.label = 2;
|
|
23
|
+
case 2:
|
|
24
|
+
if (!!entities_1_1.done) return [3 /*break*/, 22];
|
|
25
|
+
entity = entities_1_1.value;
|
|
26
|
+
meta = (0, index_js_1.repo)(entity).metadata;
|
|
27
|
+
return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.dbNamesOf)(meta, function (x) { return x; })];
|
|
28
|
+
case 3:
|
|
29
|
+
e = _o.sent();
|
|
30
|
+
processedEntities.add(e.$entityName);
|
|
31
|
+
if (!(0, filter_consumer_bridge_to_sql_request_js_1.shouldCreateEntity)(meta, e)) return [3 /*break*/, 21];
|
|
32
|
+
entitySnapshot = snapshot.entities[e.$entityName];
|
|
33
|
+
createColumns = true;
|
|
34
|
+
if (!!entitySnapshot) return [3 /*break*/, 5];
|
|
35
|
+
createColumns = false;
|
|
36
|
+
reporter('create table ' + e.$entityName);
|
|
37
|
+
return [4 /*yield*/, migrationBuilder.createTable(meta)];
|
|
38
|
+
case 4:
|
|
39
|
+
_o.sent();
|
|
40
|
+
entitySnapshot = snapshot.entities[e.$entityName] = {
|
|
41
|
+
key: meta.key,
|
|
42
|
+
className: meta.entityType.name,
|
|
43
|
+
columns: {},
|
|
44
|
+
};
|
|
45
|
+
_o.label = 5;
|
|
46
|
+
case 5:
|
|
47
|
+
processedColumns = new Set();
|
|
48
|
+
_o.label = 6;
|
|
49
|
+
case 6:
|
|
50
|
+
_o.trys.push([6, 12, 13, 14]);
|
|
51
|
+
_c = (e_1 = void 0, tslib_1.__values(meta.fields)), _d = _c.next();
|
|
52
|
+
_o.label = 7;
|
|
53
|
+
case 7:
|
|
54
|
+
if (!!_d.done) return [3 /*break*/, 11];
|
|
55
|
+
field = _d.value;
|
|
56
|
+
if (!!(0, filter_consumer_bridge_to_sql_request_js_1.shouldNotCreateField)(field, e)) return [3 /*break*/, 10];
|
|
57
|
+
columnDbName = e.$dbNameOf(field);
|
|
58
|
+
processedColumns.add(columnDbName);
|
|
59
|
+
column = entitySnapshot.columns[columnDbName];
|
|
60
|
+
if (!!column) return [3 /*break*/, 10];
|
|
61
|
+
if (!createColumns) return [3 /*break*/, 9];
|
|
62
|
+
reporter('add column ' + e.$entityName + '.' + columnDbName);
|
|
63
|
+
return [4 /*yield*/, migrationBuilder.addColumn(meta, field)];
|
|
64
|
+
case 8:
|
|
65
|
+
_o.sent();
|
|
66
|
+
_o.label = 9;
|
|
67
|
+
case 9:
|
|
68
|
+
entitySnapshot.columns[columnDbName] = { key: field.key };
|
|
69
|
+
_o.label = 10;
|
|
70
|
+
case 10:
|
|
71
|
+
_d = _c.next();
|
|
72
|
+
return [3 /*break*/, 7];
|
|
73
|
+
case 11: return [3 /*break*/, 14];
|
|
74
|
+
case 12:
|
|
75
|
+
e_1_1 = _o.sent();
|
|
76
|
+
e_1 = { error: e_1_1 };
|
|
77
|
+
return [3 /*break*/, 14];
|
|
78
|
+
case 13:
|
|
79
|
+
try {
|
|
80
|
+
if (_d && !_d.done && (_k = _c.return)) _k.call(_c);
|
|
81
|
+
}
|
|
82
|
+
finally { if (e_1) throw e_1.error; }
|
|
83
|
+
return [7 /*endfinally*/];
|
|
84
|
+
case 14:
|
|
85
|
+
_o.trys.push([14, 19, 20, 21]);
|
|
86
|
+
_e = (e_2 = void 0, tslib_1.__values(Object.keys(entitySnapshot.columns))), _f = _e.next();
|
|
87
|
+
_o.label = 15;
|
|
88
|
+
case 15:
|
|
89
|
+
if (!!_f.done) return [3 /*break*/, 18];
|
|
90
|
+
columnDbName = _f.value;
|
|
91
|
+
if (!!processedColumns.has(columnDbName)) return [3 /*break*/, 17];
|
|
92
|
+
reporter('remove column ' + e.$entityName + '.' + columnDbName);
|
|
93
|
+
return [4 /*yield*/, migrationBuilder.removeColumn(e.$entityName, columnDbName)];
|
|
94
|
+
case 16:
|
|
95
|
+
_o.sent();
|
|
96
|
+
delete entitySnapshot.columns[columnDbName];
|
|
97
|
+
_o.label = 17;
|
|
98
|
+
case 17:
|
|
99
|
+
_f = _e.next();
|
|
100
|
+
return [3 /*break*/, 15];
|
|
101
|
+
case 18: return [3 /*break*/, 21];
|
|
102
|
+
case 19:
|
|
103
|
+
e_2_1 = _o.sent();
|
|
104
|
+
e_2 = { error: e_2_1 };
|
|
105
|
+
return [3 /*break*/, 21];
|
|
106
|
+
case 20:
|
|
107
|
+
try {
|
|
108
|
+
if (_f && !_f.done && (_l = _e.return)) _l.call(_e);
|
|
109
|
+
}
|
|
110
|
+
finally { if (e_2) throw e_2.error; }
|
|
111
|
+
return [7 /*endfinally*/];
|
|
112
|
+
case 21:
|
|
113
|
+
entities_1_1 = entities_1.next();
|
|
114
|
+
return [3 /*break*/, 2];
|
|
115
|
+
case 22: return [3 /*break*/, 25];
|
|
116
|
+
case 23:
|
|
117
|
+
e_3_1 = _o.sent();
|
|
118
|
+
e_3 = { error: e_3_1 };
|
|
119
|
+
return [3 /*break*/, 25];
|
|
120
|
+
case 24:
|
|
121
|
+
try {
|
|
122
|
+
if (entities_1_1 && !entities_1_1.done && (_j = entities_1.return)) _j.call(entities_1);
|
|
123
|
+
}
|
|
124
|
+
finally { if (e_3) throw e_3.error; }
|
|
125
|
+
return [7 /*endfinally*/];
|
|
126
|
+
case 25:
|
|
127
|
+
_o.trys.push([25, 30, 31, 32]);
|
|
128
|
+
_g = tslib_1.__values(Object.keys(snapshot.entities)), _h = _g.next();
|
|
129
|
+
_o.label = 26;
|
|
130
|
+
case 26:
|
|
131
|
+
if (!!_h.done) return [3 /*break*/, 29];
|
|
132
|
+
entityDbName = _h.value;
|
|
133
|
+
if (!!processedEntities.has(entityDbName)) return [3 /*break*/, 28];
|
|
134
|
+
reporter('remove table ' + entityDbName);
|
|
135
|
+
return [4 /*yield*/, migrationBuilder.removeTable(entityDbName)];
|
|
136
|
+
case 27:
|
|
137
|
+
_o.sent();
|
|
138
|
+
delete snapshot.entities[entityDbName];
|
|
139
|
+
_o.label = 28;
|
|
140
|
+
case 28:
|
|
141
|
+
_h = _g.next();
|
|
142
|
+
return [3 /*break*/, 26];
|
|
143
|
+
case 29: return [3 /*break*/, 32];
|
|
144
|
+
case 30:
|
|
145
|
+
e_4_1 = _o.sent();
|
|
146
|
+
e_4 = { error: e_4_1 };
|
|
147
|
+
return [3 /*break*/, 32];
|
|
148
|
+
case 31:
|
|
149
|
+
try {
|
|
150
|
+
if (_h && !_h.done && (_m = _g.return)) _m.call(_g);
|
|
151
|
+
}
|
|
152
|
+
finally { if (e_4) throw e_4.error; }
|
|
153
|
+
return [7 /*endfinally*/];
|
|
154
|
+
case 32: return [2 /*return*/, snapshot];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function emptySnapshot() {
|
|
160
|
+
return {
|
|
161
|
+
version: 1,
|
|
162
|
+
entities: {},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DataProvider } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates migration scripts based on changes in entities.
|
|
4
|
+
*
|
|
5
|
+
* @param options - Configuration options for generating migrations.
|
|
6
|
+
* @param options.entities - An array of entity classes whose changes will be included in the migration.
|
|
7
|
+
* @param options.dataProvider - The data provider instance or a function returning a promise of the data provider.
|
|
8
|
+
* @param options.migrationsFolder - (Optional) The path to the folder where migration scripts will be stored. Default is 'src/migrations'.
|
|
9
|
+
* @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`.
|
|
10
|
+
* @param options.migrationsTSFile - (Optional) The path to the TypeScript file where the generated migrations will be written. Default is 'migrations.ts' in the `migrationsFolder`.
|
|
11
|
+
* @param options.endConnection - (Optional) Determines whether to close the database connection after generating migrations. Default is false.
|
|
12
|
+
* @see [Migrations](https://remult.dev/docs/migrations.html)
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateMigrations(options: {
|
|
15
|
+
entities: any[];
|
|
16
|
+
dataProvider: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>);
|
|
17
|
+
migrationsFolder?: string;
|
|
18
|
+
snapshotFile?: string;
|
|
19
|
+
migrationsTSFile?: string;
|
|
20
|
+
endConnection?: boolean;
|
|
21
|
+
}): Promise<boolean>;
|