remult 0.21.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -46
- package/SseSubscriptionServer.js +9 -9
- package/ably.js +1 -1
- package/esm/SseSubscriptionServer.js +11 -11
- package/esm/ably.js +2 -2
- package/esm/angular/interfaces/index.d.ts +1 -0
- package/esm/angular/interfaces/index.js +1 -0
- package/esm/angular/interfaces/src/column-collection.d.ts +70 -0
- package/esm/angular/interfaces/src/column-collection.js +341 -0
- package/esm/angular/interfaces/src/data-area-settings.d.ts +15 -0
- package/esm/angular/interfaces/src/data-area-settings.js +35 -0
- package/esm/angular/interfaces/src/data-control-interfaces.d.ts +36 -0
- package/esm/angular/interfaces/src/data-control-interfaces.js +57 -0
- package/esm/angular/interfaces/src/dataList.d.ts +13 -0
- package/esm/angular/interfaces/src/dataList.js +42 -0
- package/esm/angular/interfaces/src/filter-helper.d.ts +13 -0
- package/esm/angular/interfaces/src/filter-helper.js +59 -0
- package/esm/angular/interfaces/src/grid-settings.d.ts +145 -0
- package/esm/angular/interfaces/src/grid-settings.js +387 -0
- package/esm/angular/interfaces/src/public_api.d.ts +4 -0
- package/esm/angular/interfaces/src/public_api.js +4 -0
- package/esm/angular/src/angular/RemultAngularPluginsService.d.ts +4 -0
- package/esm/angular/src/angular/RemultAngularPluginsService.js +3 -0
- package/esm/angular/src/angular/data-control/data-control2.component.d.ts +49 -0
- package/esm/angular/src/angular/data-control/data-control2.component.js +138 -0
- package/esm/core/SseSubscriptionServer.d.ts +33 -0
- package/esm/core/SseSubscriptionServer.js +107 -0
- package/esm/core/assign.d.ts +1 -0
- package/esm/core/assign.js +5 -0
- package/esm/core/classType.d.ts +3 -0
- package/esm/core/classType.js +1 -0
- package/esm/core/index.d.ts +27 -0
- package/esm/core/index.js +25 -0
- package/esm/core/inputTypes.d.ts +9 -0
- package/esm/core/inputTypes.js +9 -0
- package/esm/core/live-query/data-provider-live-query-storage.d.ts +22 -0
- package/esm/core/live-query/data-provider-live-query-storage.js +71 -0
- package/esm/core/postgres/index.d.ts +2 -0
- package/esm/core/postgres/index.js +2 -0
- package/esm/core/postgres/postgres-data-provider.d.ts +36 -0
- package/esm/core/postgres/postgres-data-provider.js +120 -0
- package/esm/core/postgres/schema-builder.d.ts +17 -0
- package/esm/core/postgres/schema-builder.js +153 -0
- package/esm/core/remult-fresh.d.ts +17 -0
- package/esm/core/remult-fresh.js +29 -0
- package/esm/core/remult-knex/index.d.ts +30 -0
- package/esm/core/remult-knex/index.js +446 -0
- package/esm/core/remult-mongo.d.ts +24 -0
- package/esm/core/remult-mongo.js +254 -0
- package/esm/core/server/JsonEntityFileStorage.d.ts +10 -0
- package/esm/core/server/JsonEntityFileStorage.js +25 -0
- package/esm/core/server/core.d.ts +4 -0
- package/esm/core/server/core.js +4 -0
- package/esm/core/server/expressBridge.d.ts +182 -0
- package/esm/core/server/expressBridge.js +938 -0
- package/esm/core/server/index.d.ts +6 -0
- package/esm/core/server/index.js +9 -0
- package/esm/core/server/initAsyncHooks.d.ts +1 -0
- package/esm/core/server/initAsyncHooks.js +9 -0
- package/esm/core/server/initDataProvider.d.ts +2 -0
- package/esm/core/server/initDataProvider.js +14 -0
- package/esm/core/src/__EntityValueProvider.d.ts +11 -0
- package/esm/core/src/__EntityValueProvider.js +1 -0
- package/esm/core/src/__RowsOfDataForTesting.d.ts +3 -0
- package/esm/core/src/__RowsOfDataForTesting.js +1 -0
- package/esm/core/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +6 -0
- package/esm/core/src/backend-tests/backend-database-test-setup.backend-spec.js +147 -0
- package/esm/core/src/backend-tests/my-test.backend-spec.d.ts +1 -0
- package/esm/core/src/backend-tests/my-test.backend-spec.js +197 -0
- package/esm/core/src/backend-tests/test-http-server.backend-spec.d.ts +1 -0
- package/esm/core/src/backend-tests/test-http-server.backend-spec.js +167 -0
- package/esm/core/src/buildRestDataProvider.d.ts +31 -0
- package/esm/core/src/buildRestDataProvider.js +113 -0
- package/esm/core/src/column-interfaces.d.ts +154 -0
- package/esm/core/src/column-interfaces.js +7 -0
- package/esm/core/src/column.d.ts +58 -0
- package/esm/core/src/column.js +174 -0
- package/esm/core/src/context.d.ts +134 -0
- package/esm/core/src/context.js +286 -0
- package/esm/core/src/data-api.d.ts +39 -0
- package/esm/core/src/data-api.js +279 -0
- package/esm/core/src/data-interfaces.d.ts +41 -0
- package/esm/core/src/data-interfaces.js +12 -0
- package/esm/core/src/data-providers/array-entity-data-provider.d.ts +22 -0
- package/esm/core/src/data-providers/array-entity-data-provider.js +252 -0
- package/esm/core/src/data-providers/in-memory-database.d.ts +9 -0
- package/esm/core/src/data-providers/in-memory-database.js +14 -0
- package/esm/core/src/data-providers/json-data-provider.d.ts +12 -0
- package/esm/core/src/data-providers/json-data-provider.js +55 -0
- package/esm/core/src/data-providers/rest-data-provider.d.ts +49 -0
- package/esm/core/src/data-providers/rest-data-provider.js +256 -0
- package/esm/core/src/data-providers/sql-database.d.ts +33 -0
- package/esm/core/src/data-providers/sql-database.js +384 -0
- package/esm/core/src/data-providers/web-sql-data-provider.d.ts +24 -0
- package/esm/core/src/data-providers/web-sql-data-provider.js +143 -0
- package/esm/core/src/entity.d.ts +91 -0
- package/esm/core/src/entity.js +1 -0
- package/esm/core/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -0
- package/esm/core/src/filter/filter-consumer-bridge-to-sql-request.js +150 -0
- package/esm/core/src/filter/filter-consumer-bridge-to-url-builder.d.ts +1 -0
- package/esm/core/src/filter/filter-consumer-bridge-to-url-builder.js +1 -0
- package/esm/core/src/filter/filter-interfaces.d.ts +85 -0
- package/esm/core/src/filter/filter-interfaces.js +477 -0
- package/esm/core/src/live-query/LiveQueryClient.d.ts +20 -0
- package/esm/core/src/live-query/LiveQueryClient.js +188 -0
- package/esm/core/src/live-query/SseSubscriptionClient.d.ts +5 -0
- package/esm/core/src/live-query/SseSubscriptionClient.js +86 -0
- package/esm/core/src/live-query/SubscriptionChannel.d.ts +72 -0
- package/esm/core/src/live-query/SubscriptionChannel.js +123 -0
- package/esm/core/src/live-query/SubscriptionServer.d.ts +53 -0
- package/esm/core/src/live-query/SubscriptionServer.js +111 -0
- package/esm/core/src/live-query/live-query-tests.spec.d.ts +6 -0
- package/esm/core/src/live-query/live-query-tests.spec.js +952 -0
- package/esm/core/src/remult-proxy.d.ts +35 -0
- package/esm/core/src/remult-proxy.js +113 -0
- package/esm/core/src/remult3/DecoratorReplacer.d.ts +10 -0
- package/esm/core/src/remult3/DecoratorReplacer.js +20 -0
- package/esm/core/src/remult3/RepositoryImplementation.d.ts +355 -0
- package/esm/core/src/remult3/RepositoryImplementation.js +2109 -0
- package/esm/core/src/remult3/index.d.ts +2 -0
- package/esm/core/src/remult3/index.js +2 -0
- package/esm/core/src/remult3/remult3.d.ts +395 -0
- package/esm/core/src/remult3/remult3.js +2 -0
- package/esm/core/src/server-action.d.ts +81 -0
- package/esm/core/src/server-action.js +394 -0
- package/esm/core/src/shared-tests/db-tests-setup.d.ts +32 -0
- package/esm/core/src/shared-tests/db-tests-setup.js +78 -0
- package/esm/core/src/shared-tests/db-tests.db-tests.d.ts +25 -0
- package/esm/core/src/shared-tests/db-tests.db-tests.js +810 -0
- package/esm/core/src/shared-tests/deleteAll.d.ts +2 -0
- package/esm/core/src/shared-tests/deleteAll.js +4 -0
- package/esm/core/src/shared-tests/entityWithValidations.d.ts +14 -0
- package/esm/core/src/shared-tests/entityWithValidations.js +43 -0
- package/esm/core/src/shared-tests/index.d.ts +4 -0
- package/esm/core/src/shared-tests/index.js +4 -0
- package/esm/core/src/shared-tests/test-custom-id-column.spec.d.ts +1 -0
- package/esm/core/src/shared-tests/test-custom-id-column.spec.js +67 -0
- package/esm/core/src/shared-tests/test-special-value.spec.d.ts +10 -0
- package/esm/core/src/shared-tests/test-special-value.spec.js +73 -0
- package/esm/core/src/shared-tests/test-update-with-null.spec.d.ts +1 -0
- package/esm/core/src/shared-tests/test-update-with-null.spec.js +31 -0
- package/esm/core/src/sort.d.ts +16 -0
- package/esm/core/src/sort.js +103 -0
- package/esm/core/src/sql-command.d.ts +19 -0
- package/esm/core/src/sql-command.js +1 -0
- package/esm/core/src/test.d.ts +3 -0
- package/esm/core/src/test.js +12 -0
- package/esm/core/src/tests/Done.d.ts +5 -0
- package/esm/core/src/tests/Done.js +9 -0
- package/esm/core/src/tests/RowProvider.spec.d.ts +16 -0
- package/esm/core/src/tests/RowProvider.spec.js +631 -0
- package/esm/core/src/tests/TestDataApiResponse.d.ts +10 -0
- package/esm/core/src/tests/TestDataApiResponse.js +22 -0
- package/esm/core/src/tests/basicRowFunctionality.spec.d.ts +8 -0
- package/esm/core/src/tests/basicRowFunctionality.spec.js +2103 -0
- package/esm/core/src/tests/c.d.ts +8 -0
- package/esm/core/src/tests/c.js +13 -0
- package/esm/core/src/tests/createData.d.ts +7 -0
- package/esm/core/src/tests/createData.js +22 -0
- package/esm/core/src/tests/d.d.ts +6 -0
- package/esm/core/src/tests/d.js +11 -0
- package/esm/core/src/tests/dWithPrefilter.d.ts +7 -0
- package/esm/core/src/tests/dWithPrefilter.js +18 -0
- package/esm/core/src/tests/entityForCustomFilter.d.ts +16 -0
- package/esm/core/src/tests/entityForCustomFilter.js +33 -0
- package/esm/core/src/tests/entityWithValidationsOnColumn.d.ts +5 -0
- package/esm/core/src/tests/entityWithValidationsOnColumn.js +13 -0
- package/esm/core/src/tests/frontend-database-tests-setup.spec.d.ts +4 -0
- package/esm/core/src/tests/frontend-database-tests-setup.spec.js +37 -0
- package/esm/core/src/tests/h.d.ts +6 -0
- package/esm/core/src/tests/h.js +24 -0
- package/esm/core/src/tests/remult-3-basic-tests.spec.d.ts +1 -0
- package/esm/core/src/tests/remult-3-basic-tests.spec.js +236 -0
- package/esm/core/src/tests/remult-3-entities.d.ts +23 -0
- package/esm/core/src/tests/remult-3-entities.js +39 -0
- package/esm/core/src/tests/tasks.d.ts +6 -0
- package/esm/core/src/tests/tasks.js +10 -0
- 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 +1 -0
- package/esm/core/src/tests/test-data-api/predefined-filter.spec.d.ts +1 -0
- package/esm/core/src/tests/test-data-api/predefined-filter.spec.js +389 -0
- package/esm/core/src/tests/test-data-api/test-put-with-validation.spec.d.ts +5 -0
- package/esm/core/src/tests/test-data-api/test-put-with-validation.spec.js +152 -0
- package/esm/core/src/tests/test-decorator-precedence.spec.d.ts +1 -0
- package/esm/core/src/tests/test-decorator-precedence.spec.js +38 -0
- package/esm/core/src/tests/test-default-value.spec.d.ts +1 -0
- package/esm/core/src/tests/test-default-value.spec.js +33 -0
- package/esm/core/src/tests/test-entity-inheritance.spec.d.ts +14 -0
- package/esm/core/src/tests/test-entity-inheritance.spec.js +82 -0
- package/esm/core/src/tests/test-exceptions.spec.d.ts +1 -0
- package/esm/core/src/tests/test-exceptions.spec.js +375 -0
- package/esm/core/src/tests/test-json.spec.d.ts +1 -0
- package/esm/core/src/tests/test-json.spec.js +115 -0
- package/esm/core/src/tests/test-many-to-one-relation-in-entity.spec.d.ts +9 -0
- package/esm/core/src/tests/test-many-to-one-relation-in-entity.spec.js +809 -0
- package/esm/core/src/tests/test-non-active-record.spec.d.ts +1 -0
- package/esm/core/src/tests/test-non-active-record.spec.js +66 -0
- package/esm/core/src/tests/test-object-column.spec.d.ts +1 -0
- package/esm/core/src/tests/test-object-column.spec.js +189 -0
- package/esm/core/src/tests/test-paged-foreach.spec.d.ts +1 -0
- package/esm/core/src/tests/test-paged-foreach.spec.js +328 -0
- package/esm/core/src/tests/test-remult-angular.spec.d.ts +1 -0
- package/esm/core/src/tests/test-remult-angular.spec.js +23 -0
- package/esm/core/src/tests/test-server-controller.spec.d.ts +7 -0
- package/esm/core/src/tests/test-server-controller.spec.js +489 -0
- package/esm/core/src/tests/test-server-expressions.spec.d.ts +1 -0
- package/esm/core/src/tests/test-server-expressions.spec.js +178 -0
- package/esm/core/src/tests/test-server-method-on-entity.spec.d.ts +1 -0
- package/esm/core/src/tests/test-server-method-on-entity.spec.js +306 -0
- package/esm/core/src/tests/test-sql-expression.spec.d.ts +5 -0
- package/esm/core/src/tests/test-sql-expression.spec.js +205 -0
- package/esm/core/src/tests/test-sql.spec.d.ts +1 -0
- package/esm/core/src/tests/test-sql.spec.js +170 -0
- package/esm/core/src/tests/test-subscribe.spec.d.ts +1 -0
- package/esm/core/src/tests/test-subscribe.spec.js +135 -0
- package/esm/core/src/tests/test-type-recovery.spec.d.ts +1 -0
- package/esm/core/src/tests/test-type-recovery.spec.js +49 -0
- package/esm/core/src/tests/test-where-api.spec.d.ts +1 -0
- package/esm/core/src/tests/test-where-api.spec.js +434 -0
- package/esm/core/src/tests/testHelper.spec.d.ts +36 -0
- package/esm/core/src/tests/testHelper.spec.js +226 -0
- package/esm/core/src/tests/testModel/models.d.ts +16 -0
- package/esm/core/src/tests/testModel/models.js +25 -0
- package/esm/core/src/validators.d.ts +14 -0
- package/esm/core/src/validators.js +33 -0
- package/esm/core/src/valueConverters.d.ts +13 -0
- package/esm/core/src/valueConverters.js +197 -0
- package/esm/core/urlBuilder.d.ts +6 -0
- package/esm/core/urlBuilder.js +20 -0
- package/esm/graphql.js +194 -73
- package/esm/index.d.ts +10 -10
- package/esm/index.js +8 -8
- package/esm/inputTypes.js +1 -1
- package/esm/live-query/data-provider-live-query-storage.d.ts +3 -3
- package/esm/live-query/data-provider-live-query-storage.js +12 -9
- package/esm/myLog.js +2 -2
- package/esm/postgres/postgres-data-provider.d.ts +2 -2
- package/esm/postgres/postgres-data-provider.js +20 -14
- package/esm/postgres/schema-builder.d.ts +1 -1
- package/esm/postgres/schema-builder.js +28 -21
- package/esm/remult-express.js +2 -2
- package/esm/remult-fastify.js +9 -7
- package/esm/remult-fresh.d.ts +1 -1
- package/esm/remult-fresh.js +5 -8
- package/esm/remult-knex/index.d.ts +4 -4
- package/esm/remult-knex/index.js +75 -59
- package/esm/remult-mongo.js +36 -27
- package/esm/remult-next.d.ts +3 -3
- package/esm/remult-next.js +17 -11
- package/esm/remult-sveltekit.js +10 -10
- package/esm/server/JsonEntityFileStorage.js +3 -1
- package/esm/server/core.d.ts +2 -2
- package/esm/server/core.js +2 -2
- package/esm/server/expressBridge.d.ts +3 -12
- package/esm/server/expressBridge.js +265 -278
- package/esm/server/index.d.ts +2 -2
- package/esm/server/index.js +5 -2
- package/esm/server/initAsyncHooks.js +1 -1
- package/esm/server/initDataProvider.js +1 -1
- package/esm/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +1 -1
- package/esm/src/backend-tests/backend-database-test-setup.backend-spec.js +47 -38
- package/esm/src/buildRestDataProvider.d.ts +1 -1
- package/esm/src/buildRestDataProvider.js +21 -13
- package/esm/src/column-interfaces.d.ts +9 -9
- package/esm/src/column.d.ts +4 -0
- package/esm/src/column.js +23 -11
- package/esm/src/context.d.ts +20 -8
- package/esm/src/context.js +65 -24
- package/esm/src/data-api.d.ts +0 -1
- package/esm/src/data-api.js +38 -37
- package/esm/src/data-interfaces.d.ts +1 -1
- package/esm/src/data-interfaces.js +1 -1
- package/esm/src/data-providers/array-entity-data-provider.js +9 -9
- package/esm/src/data-providers/in-memory-database.d.ts +1 -1
- package/esm/src/data-providers/in-memory-database.js +3 -1
- package/esm/src/data-providers/json-data-provider.js +8 -8
- package/esm/src/data-providers/rest-data-provider.d.ts +1 -1
- package/esm/src/data-providers/rest-data-provider.js +52 -36
- package/esm/src/data-providers/sql-database.d.ts +5 -5
- package/esm/src/data-providers/sql-database.js +53 -36
- package/esm/src/data-providers/web-sql-data-provider.d.ts +4 -4
- package/esm/src/data-providers/web-sql-data-provider.js +15 -13
- package/esm/src/entity.d.ts +24 -24
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.d.ts +4 -4
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +35 -20
- package/esm/src/filter/filter-interfaces.d.ts +7 -7
- package/esm/src/filter/filter-interfaces.js +108 -88
- package/esm/src/live-query/LiveQueryClient.js +37 -29
- package/esm/src/live-query/SseSubscriptionClient.d.ts +1 -1
- package/esm/src/live-query/SseSubscriptionClient.js +14 -14
- package/esm/src/live-query/SubscriptionChannel.d.ts +3 -3
- package/esm/src/live-query/SubscriptionChannel.js +27 -25
- package/esm/src/live-query/SubscriptionServer.js +24 -20
- package/esm/src/remult-proxy.d.ts +1 -1
- package/esm/src/remult-proxy.js +87 -29
- package/esm/src/remult3/DecoratorReplacer.d.ts +2 -2
- package/esm/src/remult3/RepositoryImplementation.d.ts +51 -41
- package/esm/src/remult3/RepositoryImplementation.js +336 -206
- package/esm/src/remult3/remult3.d.ts +56 -51
- package/esm/src/remult3/remult3.js +0 -1
- package/esm/src/server-action.d.ts +12 -5
- package/esm/src/server-action.js +79 -53
- package/esm/src/shared-tests/db-tests-setup.d.ts +8 -8
- package/esm/src/shared-tests/db-tests-setup.js +10 -10
- package/esm/src/shared-tests/db-tests.db-tests.d.ts +1 -1
- package/esm/src/shared-tests/db-tests.db-tests.js +279 -177
- package/esm/src/shared-tests/deleteAll.d.ts +1 -1
- package/esm/src/shared-tests/deleteAll.js +1 -1
- package/esm/src/shared-tests/entityWithValidations.js +1 -1
- package/esm/src/shared-tests/test-custom-id-column.spec.js +4 -4
- package/esm/src/shared-tests/test-special-value.spec.js +12 -12
- package/esm/src/shared-tests/test-update-with-null.spec.js +10 -6
- package/esm/src/sort.d.ts +2 -2
- package/esm/src/sort.js +12 -10
- package/esm/src/tests/TestDataApiResponse.d.ts +1 -1
- package/esm/src/tests/TestDataApiResponse.js +3 -4
- package/esm/src/tests/createData.js +2 -2
- package/esm/src/tests/d.js +1 -1
- package/esm/src/tests/dWithPrefilter.js +1 -1
- package/esm/src/tests/entityForCustomFilter.d.ts +4 -4
- package/esm/src/tests/entityForCustomFilter.js +12 -4
- package/esm/src/tests/entityWithValidationsOnColumn.js +1 -1
- package/esm/src/tests/frontend-database-tests-setup.spec.d.ts +1 -1
- package/esm/src/tests/frontend-database-tests-setup.spec.js +14 -14
- package/esm/src/tests/h.js +4 -4
- package/esm/src/tests/remult-3-entities.d.ts +2 -2
- package/esm/src/tests/remult-3-entities.js +6 -6
- package/esm/src/tests/testHelper.spec.d.ts +7 -7
- package/esm/src/tests/testHelper.spec.js +50 -39
- package/esm/src/tests/testModel/models.js +4 -4
- package/esm/src/validators.d.ts +1 -1
- package/esm/src/validators.js +10 -7
- package/esm/src/valueConverters.d.ts +1 -1
- package/esm/src/valueConverters.js +68 -55
- package/esm/test-servers/shared/Task.d.ts +9 -0
- package/esm/test-servers/shared/Task.js +32 -0
- package/esm/test.d.ts +5 -0
- package/esm/test.js +6 -0
- package/graphql.js +157 -45
- package/index.d.ts +10 -10
- package/inputTypes.js +1 -1
- package/live-query/data-provider-live-query-storage.d.ts +3 -3
- package/live-query/data-provider-live-query-storage.js +7 -4
- package/myLog.js +2 -2
- package/package.json +2 -2
- package/postgres/postgres-data-provider.d.ts +2 -2
- package/postgres/postgres-data-provider.js +21 -16
- package/postgres/schema-builder.d.ts +1 -1
- package/postgres/schema-builder.js +22 -15
- package/remult-express.js +1 -1
- package/remult-fastify.js +7 -7
- package/remult-fresh.d.ts +1 -1
- package/remult-fresh.js +1 -4
- package/remult-knex/index.d.ts +4 -4
- package/remult-knex/index.js +50 -35
- package/remult-mongo.js +33 -23
- package/remult-next.d.ts +3 -3
- package/remult-next.js +15 -11
- package/remult-sveltekit.js +14 -15
- package/server/core.d.ts +2 -2
- package/server/expressBridge.d.ts +3 -12
- package/server/expressBridge.js +278 -279
- package/server/index.d.ts +2 -2
- package/server/index.js +5 -2
- package/server/initAsyncHooks.js +2 -2
- package/server/initDataProvider.js +1 -1
- package/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +1 -1
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +40 -31
- package/src/buildRestDataProvider.d.ts +1 -1
- package/src/buildRestDataProvider.js +18 -10
- package/src/column-interfaces.d.ts +9 -9
- package/src/column.d.ts +4 -0
- package/src/column.js +20 -8
- package/src/context.d.ts +20 -8
- package/src/context.js +61 -18
- package/src/data-api.d.ts +0 -1
- package/src/data-api.js +40 -43
- package/src/data-interfaces.d.ts +1 -1
- package/src/data-providers/array-entity-data-provider.js +2 -2
- package/src/data-providers/in-memory-database.d.ts +1 -1
- package/src/data-providers/in-memory-database.js +3 -1
- package/src/data-providers/json-data-provider.js +33 -15
- package/src/data-providers/rest-data-provider.d.ts +1 -1
- package/src/data-providers/rest-data-provider.js +47 -32
- package/src/data-providers/sql-database.d.ts +5 -5
- package/src/data-providers/sql-database.js +41 -24
- package/src/data-providers/web-sql-data-provider.d.ts +4 -4
- package/src/data-providers/web-sql-data-provider.js +10 -8
- package/src/entity.d.ts +24 -24
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +4 -4
- package/src/filter/filter-consumer-bridge-to-sql-request.js +34 -17
- package/src/filter/filter-interfaces.d.ts +7 -7
- package/src/filter/filter-interfaces.js +73 -47
- package/src/live-query/LiveQueryClient.js +35 -25
- package/src/live-query/SseSubscriptionClient.d.ts +1 -1
- package/src/live-query/SseSubscriptionClient.js +80 -76
- package/src/live-query/SubscriptionChannel.d.ts +3 -3
- package/src/live-query/SubscriptionChannel.js +26 -18
- package/src/live-query/SubscriptionServer.js +23 -17
- package/src/remult-proxy.d.ts +1 -1
- package/src/remult-proxy.js +84 -35
- package/src/remult3/DecoratorReplacer.d.ts +2 -2
- package/src/remult3/RepositoryImplementation.d.ts +51 -41
- package/src/remult3/RepositoryImplementation.js +402 -257
- package/src/remult3/remult3.d.ts +56 -51
- package/src/remult3/remult3.js +0 -1
- package/src/server-action.d.ts +12 -5
- package/src/server-action.js +78 -48
- package/src/shared-tests/db-tests-setup.d.ts +8 -8
- package/src/shared-tests/db-tests-setup.js +6 -6
- package/src/shared-tests/db-tests.db-tests.d.ts +1 -1
- package/src/shared-tests/db-tests.db-tests.js +350 -153
- package/src/shared-tests/deleteAll.d.ts +1 -1
- package/src/shared-tests/entityWithValidations.js +1 -1
- package/src/shared-tests/test-custom-id-column.spec.js +4 -4
- package/src/shared-tests/test-special-value.spec.js +9 -9
- package/src/shared-tests/test-update-with-null.spec.js +8 -4
- package/src/sort.d.ts +2 -2
- package/src/sort.js +9 -7
- package/src/tests/TestDataApiResponse.d.ts +1 -1
- package/src/tests/TestDataApiResponse.js +3 -4
- package/src/tests/createData.js +1 -1
- package/src/tests/d.js +1 -1
- package/src/tests/dWithPrefilter.js +1 -1
- package/src/tests/entityForCustomFilter.d.ts +4 -4
- package/src/tests/entityForCustomFilter.js +16 -6
- package/src/tests/entityWithValidationsOnColumn.js +1 -1
- package/src/tests/frontend-database-tests-setup.spec.d.ts +1 -1
- package/src/tests/frontend-database-tests-setup.spec.js +8 -8
- package/src/tests/h.js +3 -3
- package/src/tests/remult-3-entities.d.ts +2 -2
- package/src/tests/remult-3-entities.js +8 -4
- package/src/tests/testHelper.spec.d.ts +7 -7
- package/src/tests/testHelper.spec.js +38 -27
- package/src/tests/testModel/models.js +3 -3
- package/src/validators.d.ts +1 -1
- package/src/validators.js +18 -9
- package/src/valueConverters.d.ts +1 -1
- package/src/valueConverters.js +38 -21
- package/esm/remult-svletekit.d.ts +0 -3
- package/esm/remult-svletekit.js +0 -83
- package/esm/src/id-entity.d.ts +0 -4
- package/esm/src/id-entity.js +0 -8
- package/esm/src/remult3/getId.d.ts +0 -2
- package/esm/src/remult3/getId.js +0 -7
- package/postgres/getEntityTypescriptPostgres.d.ts +0 -1
- package/postgres/getEntityTypescriptPostgres.js +0 -125
- package/src/id-entity.d.ts +0 -4
- package/src/id-entity.js +0 -17
- package/src/remult3/getId.d.ts +0 -2
- package/src/remult3/getId.js +0 -11
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { CompoundIdField, LookupColumn, makeTitle } from '../column';
|
|
3
|
-
import { allEntities, Remult, isBackend, queryConfig as queryConfig, setControllerSettings } from
|
|
4
|
-
import {
|
|
5
|
-
import { Sort } from
|
|
3
|
+
import { allEntities, Remult, isBackend, queryConfig as queryConfig, setControllerSettings, } from '../context';
|
|
4
|
+
import { Filter, } from '../filter/filter-interfaces';
|
|
5
|
+
import { Sort } from '../sort';
|
|
6
6
|
import { v4 as uuid } from 'uuid';
|
|
7
|
-
import
|
|
8
|
-
import { ValueConverters } from
|
|
9
|
-
import { filterHelper } from
|
|
10
|
-
import { assign } from
|
|
11
|
-
import { remult as defaultRemult
|
|
7
|
+
import { createId } from '@paralleldrive/cuid2';
|
|
8
|
+
import { ValueConverters } from '../valueConverters';
|
|
9
|
+
import { filterHelper } from '../filter/filter-interfaces';
|
|
10
|
+
import { assign } from '../../assign';
|
|
11
|
+
import { remult as defaultRemult } from '../remult-proxy';
|
|
12
|
+
import { findOptionsToJson } from '../data-providers/rest-data-provider';
|
|
12
13
|
//import { remult } from "../remult-proxy";
|
|
13
14
|
let classValidatorValidate = undefined;
|
|
14
15
|
// import("class-validator".toString())
|
|
@@ -39,7 +40,8 @@ export class RepositoryImplementation {
|
|
|
39
40
|
}
|
|
40
41
|
async createAfterFilter(orderBy, lastRow) {
|
|
41
42
|
let values = new Map();
|
|
42
|
-
for (const s of Sort.translateOrderByToSort(this.metadata, orderBy)
|
|
43
|
+
for (const s of Sort.translateOrderByToSort(this.metadata, orderBy)
|
|
44
|
+
.Segments) {
|
|
43
45
|
let existingVal = lastRow[s.field.key];
|
|
44
46
|
// if (typeof existingVal !== "string" && typeof existingVal !== "number") {
|
|
45
47
|
// }
|
|
@@ -53,7 +55,8 @@ export class RepositoryImplementation {
|
|
|
53
55
|
}
|
|
54
56
|
let r = { $or: [] };
|
|
55
57
|
let equalToColumn = [];
|
|
56
|
-
for (const s of Sort.translateOrderByToSort(this.metadata, orderBy)
|
|
58
|
+
for (const s of Sort.translateOrderByToSort(this.metadata, orderBy)
|
|
59
|
+
.Segments) {
|
|
57
60
|
let ff = new filterHelper(s.field);
|
|
58
61
|
let f = {};
|
|
59
62
|
for (const c of equalToColumn) {
|
|
@@ -70,7 +73,9 @@ export class RepositoryImplementation {
|
|
|
70
73
|
return r;
|
|
71
74
|
}
|
|
72
75
|
get edp() {
|
|
73
|
-
return this.__edp
|
|
76
|
+
return this.__edp
|
|
77
|
+
? this.__edp
|
|
78
|
+
: (this.__edp = this.dataProvider.getEntityDataProvider(this.metadata));
|
|
74
79
|
}
|
|
75
80
|
getCachedById(id) {
|
|
76
81
|
id = id + '';
|
|
@@ -89,7 +94,7 @@ export class RepositoryImplementation {
|
|
|
89
94
|
return r;
|
|
90
95
|
}
|
|
91
96
|
this.idCache.set(id, undefined);
|
|
92
|
-
let row = this.findId(id).then(row => {
|
|
97
|
+
let row = this.findId(id).then((row) => {
|
|
93
98
|
if (row === undefined) {
|
|
94
99
|
r = null;
|
|
95
100
|
}
|
|
@@ -106,8 +111,9 @@ export class RepositoryImplementation {
|
|
|
106
111
|
if (item)
|
|
107
112
|
this.idCache.set(this.getEntityRef(item).getId() + '', item);
|
|
108
113
|
}
|
|
109
|
-
get metadata() {
|
|
110
|
-
|
|
114
|
+
get metadata() {
|
|
115
|
+
return this._info;
|
|
116
|
+
}
|
|
111
117
|
addEventListener(listener) {
|
|
112
118
|
if (!this.listeners)
|
|
113
119
|
this.listeners = [];
|
|
@@ -125,14 +131,15 @@ export class RepositoryImplementation {
|
|
|
125
131
|
this.fixTypes(entity);
|
|
126
132
|
x = new rowHelperImplementation(this._info, entity, this, this.edp, this.remult, true);
|
|
127
133
|
Object.defineProperty(entity, entityMember, {
|
|
128
|
-
|
|
134
|
+
//I've used define property to hide this member from console.lo g
|
|
135
|
+
get: () => x,
|
|
129
136
|
});
|
|
130
137
|
x.saveOriginalData();
|
|
131
138
|
}
|
|
132
139
|
return x;
|
|
133
140
|
}
|
|
134
141
|
async delete(item) {
|
|
135
|
-
if (typeof item ===
|
|
142
|
+
if (typeof item === 'string' || typeof item === 'number')
|
|
136
143
|
return this.edp.delete(item);
|
|
137
144
|
else {
|
|
138
145
|
return this.getRefForExistingRow(item, undefined).delete();
|
|
@@ -150,7 +157,7 @@ export class RepositoryImplementation {
|
|
|
150
157
|
let ref = getEntityRef(entity, false);
|
|
151
158
|
if (ref) {
|
|
152
159
|
if (!ref.isNew())
|
|
153
|
-
throw
|
|
160
|
+
throw 'Item is not new';
|
|
154
161
|
return await ref.save();
|
|
155
162
|
}
|
|
156
163
|
else {
|
|
@@ -163,7 +170,9 @@ export class RepositoryImplementation {
|
|
|
163
170
|
}
|
|
164
171
|
async validate(entity, ...fields) {
|
|
165
172
|
{
|
|
166
|
-
let ref =
|
|
173
|
+
let ref = getEntityRef(entity, false);
|
|
174
|
+
if (!ref)
|
|
175
|
+
ref = this.getEntityRef({ ...entity });
|
|
167
176
|
if (!fields || fields.length === 0) {
|
|
168
177
|
return await ref.validate();
|
|
169
178
|
}
|
|
@@ -171,7 +180,7 @@ export class RepositoryImplementation {
|
|
|
171
180
|
ref.__clearErrorsAndReportChanged();
|
|
172
181
|
let hasError = false;
|
|
173
182
|
for (const f of fields) {
|
|
174
|
-
if (!await ref.fields.find(f).validate())
|
|
183
|
+
if (!(await ref.fields.find(f).validate()))
|
|
175
184
|
hasError = true;
|
|
176
185
|
}
|
|
177
186
|
if (!hasError)
|
|
@@ -193,7 +202,7 @@ export class RepositoryImplementation {
|
|
|
193
202
|
}
|
|
194
203
|
this.fixTypes(instance);
|
|
195
204
|
let row = new rowHelperImplementation(this._info, instance, this, this.edp, this.remult, false);
|
|
196
|
-
if (typeof
|
|
205
|
+
if (typeof id === 'object')
|
|
197
206
|
id = this.metadata.idMetadata.getId(id);
|
|
198
207
|
if (id) {
|
|
199
208
|
row.id = id;
|
|
@@ -203,14 +212,14 @@ export class RepositoryImplementation {
|
|
|
203
212
|
row.id = row.getId();
|
|
204
213
|
ref = row;
|
|
205
214
|
Object.defineProperty(instance, entityMember, {
|
|
206
|
-
get: () => row
|
|
215
|
+
get: () => row,
|
|
207
216
|
});
|
|
208
217
|
}
|
|
209
218
|
return ref;
|
|
210
219
|
}
|
|
211
220
|
async save(entity) {
|
|
212
221
|
if (Array.isArray(entity)) {
|
|
213
|
-
return Promise.all(entity.map(x => this.save(x)));
|
|
222
|
+
return Promise.all(entity.map((x) => this.save(x)));
|
|
214
223
|
}
|
|
215
224
|
else {
|
|
216
225
|
let ref = getEntityRef(entity, false);
|
|
@@ -233,17 +242,17 @@ export class RepositoryImplementation {
|
|
|
233
242
|
return {
|
|
234
243
|
subscribe: (l) => {
|
|
235
244
|
let listener = l;
|
|
236
|
-
if (typeof l ===
|
|
245
|
+
if (typeof l === 'function') {
|
|
237
246
|
listener = {
|
|
238
247
|
next: l,
|
|
239
248
|
complete: () => { },
|
|
240
|
-
error: () => { }
|
|
249
|
+
error: () => { },
|
|
241
250
|
};
|
|
242
251
|
}
|
|
243
252
|
listener.error ??= () => { };
|
|
244
253
|
listener.complete ??= () => { };
|
|
245
254
|
return this.remult.liveQuerySubscriber.subscribe(this, options, listener);
|
|
246
|
-
}
|
|
255
|
+
},
|
|
247
256
|
};
|
|
248
257
|
}
|
|
249
258
|
async find(options, skipOrderByAndLimit = false) {
|
|
@@ -272,7 +281,7 @@ export class RepositoryImplementation {
|
|
|
272
281
|
return opt;
|
|
273
282
|
}
|
|
274
283
|
async fromJsonArray(jsonItems, load) {
|
|
275
|
-
return this.loadManyToOneForManyRows(jsonItems.map(row => {
|
|
284
|
+
return this.loadManyToOneForManyRows(jsonItems.map((row) => {
|
|
276
285
|
let result = {};
|
|
277
286
|
for (const col of this.metadata.fields.toArray()) {
|
|
278
287
|
result[col.key] = col.valueConverter.fromJson(row[col.key]);
|
|
@@ -295,7 +304,10 @@ export class RepositoryImplementation {
|
|
|
295
304
|
let toLoad = [];
|
|
296
305
|
for (const r of rawRows) {
|
|
297
306
|
let val = r[col.key];
|
|
298
|
-
if (val !== undefined &&
|
|
307
|
+
if (val !== undefined &&
|
|
308
|
+
val !== null &&
|
|
309
|
+
!toLoad.includes(val) &&
|
|
310
|
+
!repo.idCache.has(val)) {
|
|
299
311
|
toLoad.push(val);
|
|
300
312
|
}
|
|
301
313
|
}
|
|
@@ -320,28 +332,54 @@ export class RepositoryImplementation {
|
|
|
320
332
|
let x = new this.entity(this.remult);
|
|
321
333
|
let helper = new rowHelperImplementation(this._info, x, this, this.edp, this.remult, false);
|
|
322
334
|
Object.defineProperty(x, entityMember, {
|
|
323
|
-
|
|
335
|
+
//I've used define property to hide this member from console.lo g
|
|
336
|
+
get: () => helper,
|
|
324
337
|
});
|
|
325
338
|
await helper.loadDataFrom(r, loadFields);
|
|
326
339
|
helper.saveOriginalData();
|
|
327
340
|
return x;
|
|
328
341
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
342
|
+
toJson(item) {
|
|
343
|
+
if (item === undefined || item === null)
|
|
344
|
+
return item;
|
|
345
|
+
if (Array.isArray(item))
|
|
346
|
+
return item.map((x) => this.toJson(x));
|
|
347
|
+
if (typeof item.then === 'function')
|
|
348
|
+
return item.then((x) => this.toJson(x));
|
|
349
|
+
return this.getEntityRef(item).toApiJson(true);
|
|
350
|
+
}
|
|
351
|
+
fromJson(json, newRow) {
|
|
352
|
+
if (json === null || json === undefined)
|
|
353
|
+
return json;
|
|
354
|
+
if (Array.isArray(json))
|
|
355
|
+
return json.map((item) => this.fromJson(item, newRow));
|
|
356
|
+
let result = new this.entity(this.remult);
|
|
332
357
|
for (const col of this.fieldsOf(json)) {
|
|
333
|
-
|
|
334
|
-
|
|
358
|
+
let ei = getEntitySettings(col.valueType, false);
|
|
359
|
+
if (ei) {
|
|
360
|
+
result[col.key] = this.remult
|
|
361
|
+
.repo(col.valueType)
|
|
362
|
+
.fromJson(json[col.key]);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
if (json[col.key] !== undefined) {
|
|
366
|
+
result[col.key] = col.valueConverter.fromJson(json[col.key]);
|
|
367
|
+
}
|
|
335
368
|
}
|
|
336
369
|
}
|
|
370
|
+
this.fixTypes(result);
|
|
337
371
|
if (newRow) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
372
|
+
return this.create(result);
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
let row = new rowHelperImplementation(this._info, result, this, this.edp, this.remult, false);
|
|
376
|
+
Object.defineProperty(result, entityMember, {
|
|
377
|
+
//I've used define property to hide this member from console.lo g
|
|
378
|
+
get: () => row,
|
|
379
|
+
});
|
|
380
|
+
row.saveOriginalData();
|
|
381
|
+
return result;
|
|
342
382
|
}
|
|
343
|
-
else
|
|
344
|
-
return this.mapRawDataToResult(obj, undefined);
|
|
345
383
|
}
|
|
346
384
|
async count(where) {
|
|
347
385
|
return this.edp.count(await this.translateWhereToFilter(where));
|
|
@@ -353,10 +391,7 @@ export class RepositoryImplementation {
|
|
|
353
391
|
if (options.where) {
|
|
354
392
|
let w = options.where;
|
|
355
393
|
options.where = {
|
|
356
|
-
$and: [
|
|
357
|
-
w,
|
|
358
|
-
where
|
|
359
|
-
]
|
|
394
|
+
$and: [w, where],
|
|
360
395
|
};
|
|
361
396
|
}
|
|
362
397
|
else
|
|
@@ -365,11 +400,12 @@ export class RepositoryImplementation {
|
|
|
365
400
|
let r;
|
|
366
401
|
let cacheInfo;
|
|
367
402
|
if (options.useCache) {
|
|
368
|
-
let f =
|
|
403
|
+
let f = findOptionsToJson(options, this.metadata);
|
|
369
404
|
let key = JSON.stringify(f);
|
|
370
405
|
cacheInfo = this.cache.get(key);
|
|
371
406
|
if (cacheInfo !== undefined) {
|
|
372
|
-
if (cacheInfo.value &&
|
|
407
|
+
if (cacheInfo.value &&
|
|
408
|
+
this.getEntityRef(cacheInfo.value).wasDeleted()) {
|
|
373
409
|
cacheInfo = undefined;
|
|
374
410
|
this.cache.delete(key);
|
|
375
411
|
}
|
|
@@ -379,7 +415,7 @@ export class RepositoryImplementation {
|
|
|
379
415
|
else {
|
|
380
416
|
cacheInfo = {
|
|
381
417
|
value: undefined,
|
|
382
|
-
promise: undefined
|
|
418
|
+
promise: undefined,
|
|
383
419
|
};
|
|
384
420
|
this.cache.set(key, cacheInfo);
|
|
385
421
|
}
|
|
@@ -397,7 +433,7 @@ export class RepositoryImplementation {
|
|
|
397
433
|
return r;
|
|
398
434
|
});
|
|
399
435
|
if (cacheInfo) {
|
|
400
|
-
cacheInfo.promise = r = r.then(r => {
|
|
436
|
+
cacheInfo.promise = r = r.then((r) => {
|
|
401
437
|
cacheInfo.value = r;
|
|
402
438
|
return r;
|
|
403
439
|
});
|
|
@@ -406,7 +442,7 @@ export class RepositoryImplementation {
|
|
|
406
442
|
}
|
|
407
443
|
fieldsOf(item) {
|
|
408
444
|
let keys = Object.keys(item);
|
|
409
|
-
return this.metadata.fields.toArray().filter(x => keys.includes(x.key));
|
|
445
|
+
return this.metadata.fields.toArray().filter((x) => keys.includes(x.key));
|
|
410
446
|
}
|
|
411
447
|
create(item) {
|
|
412
448
|
let r = new this.entity(this.remult);
|
|
@@ -426,7 +462,11 @@ export class RepositoryImplementation {
|
|
|
426
462
|
if (field.valueType === Date && !(val instanceof Date))
|
|
427
463
|
item[field.key] = field.valueConverter.fromJson(field.valueConverter.toJson(val));
|
|
428
464
|
else
|
|
429
|
-
for (const [type, typeName] of [
|
|
465
|
+
for (const [type, typeName] of [
|
|
466
|
+
[String, 'string'],
|
|
467
|
+
[Number, 'number'],
|
|
468
|
+
[Boolean, 'boolean'],
|
|
469
|
+
]) {
|
|
430
470
|
if (field.valueType === type && typeof val !== typeName)
|
|
431
471
|
item[field.key] = field.valueConverter.fromJson(field.valueConverter.toJson(val));
|
|
432
472
|
}
|
|
@@ -437,8 +477,8 @@ export class RepositoryImplementation {
|
|
|
437
477
|
findId(id, options) {
|
|
438
478
|
if (id === null || id === undefined)
|
|
439
479
|
return null;
|
|
440
|
-
if (typeof id !==
|
|
441
|
-
throw new Error(
|
|
480
|
+
if (typeof id !== 'string' && typeof id !== 'number')
|
|
481
|
+
throw new Error('id can be either number or string, but got: ' + typeof id);
|
|
442
482
|
return this.findFirst({}, {
|
|
443
483
|
useCache: true,
|
|
444
484
|
...options,
|
|
@@ -450,13 +490,11 @@ export class RepositoryImplementation {
|
|
|
450
490
|
if (this.metadata.options.backendPrefilter && isBackend()) {
|
|
451
491
|
let z = where;
|
|
452
492
|
where = {
|
|
453
|
-
$and: [
|
|
454
|
-
z, await Filter.resolve(this.metadata.options.backendPrefilter)
|
|
455
|
-
]
|
|
493
|
+
$and: [z, await Filter.resolve(this.metadata.options.backendPrefilter)],
|
|
456
494
|
};
|
|
457
495
|
}
|
|
458
496
|
let r = await Filter.fromEntityFilter(this.metadata, where);
|
|
459
|
-
if (r && !this.dataProvider.
|
|
497
|
+
if (r && !this.dataProvider.isProxy) {
|
|
460
498
|
r = await Filter.translateCustomWhere(r, this.metadata, this.remult);
|
|
461
499
|
}
|
|
462
500
|
return r;
|
|
@@ -481,23 +519,24 @@ export function __updateEntityBasedOnWhere(entityDefs, where, r) {
|
|
|
481
519
|
isLessThan: emptyFunction,
|
|
482
520
|
isNotNull: emptyFunction,
|
|
483
521
|
isNull: emptyFunction,
|
|
484
|
-
or: emptyFunction
|
|
522
|
+
or: emptyFunction,
|
|
485
523
|
});
|
|
486
524
|
}
|
|
487
525
|
}
|
|
488
|
-
export const entityInfo = Symbol(
|
|
489
|
-
export const entityInfo_key = Symbol(
|
|
490
|
-
const entityMember = Symbol(
|
|
526
|
+
export const entityInfo = Symbol('entityInfo');
|
|
527
|
+
export const entityInfo_key = Symbol('entityInfo_key');
|
|
528
|
+
const entityMember = Symbol('entityMember');
|
|
491
529
|
export function getEntitySettings(entity, throwError = true) {
|
|
492
530
|
if (entity === undefined)
|
|
493
531
|
if (throwError) {
|
|
494
|
-
throw new Error(
|
|
532
|
+
throw new Error('Undefined is not an entity :)');
|
|
495
533
|
}
|
|
496
534
|
else
|
|
497
535
|
return undefined;
|
|
498
536
|
let info = Reflect.getMetadata(entityInfo, entity);
|
|
499
537
|
if (!info && throwError)
|
|
500
|
-
throw new Error(entity.prototype.constructor.name +
|
|
538
|
+
throw new Error(entity.prototype.constructor.name +
|
|
539
|
+
" is not a known entity, did you forget to set @Entity() or did you forget to add the '@' before the call to Entity?");
|
|
501
540
|
return info;
|
|
502
541
|
}
|
|
503
542
|
export function getEntityKey(entity) {
|
|
@@ -507,20 +546,26 @@ export const columnsOfType = new Map();
|
|
|
507
546
|
export function createOldEntity(entity, remult) {
|
|
508
547
|
let r = columnsOfType.get(entity);
|
|
509
548
|
if (!r)
|
|
510
|
-
columnsOfType.set(entity, r = []);
|
|
549
|
+
columnsOfType.set(entity, (r = []));
|
|
511
550
|
let info = getEntitySettings(entity)(remult);
|
|
512
551
|
let key = getEntityKey(entity);
|
|
513
552
|
let base = Object.getPrototypeOf(entity);
|
|
514
553
|
while (base != null) {
|
|
515
554
|
let baseCols = columnsOfType.get(base);
|
|
516
555
|
if (baseCols) {
|
|
517
|
-
r.unshift(...baseCols.filter(x => !r.find(y => y.key == x.key)));
|
|
556
|
+
r.unshift(...baseCols.filter((x) => !r.find((y) => y.key == x.key)));
|
|
518
557
|
}
|
|
519
558
|
let baseSettingsFactory = getEntitySettings(base, false);
|
|
520
559
|
if (baseSettingsFactory) {
|
|
521
560
|
let baseSettings = baseSettingsFactory(remult);
|
|
522
561
|
info = { ...baseSettings, ...info };
|
|
523
|
-
let functions = [
|
|
562
|
+
let functions = [
|
|
563
|
+
'saving',
|
|
564
|
+
'saved',
|
|
565
|
+
'deleting',
|
|
566
|
+
'deleted',
|
|
567
|
+
'validation',
|
|
568
|
+
];
|
|
524
569
|
for (const key of functions) {
|
|
525
570
|
if (baseSettings[key] && baseSettings[key] !== info[key]) {
|
|
526
571
|
let x = info[key];
|
|
@@ -581,7 +626,7 @@ class rowHelperBase {
|
|
|
581
626
|
}
|
|
582
627
|
refImpl._subscribers.reportChanged();
|
|
583
628
|
},
|
|
584
|
-
enumerable: true
|
|
629
|
+
enumerable: true,
|
|
585
630
|
});
|
|
586
631
|
lookup.set(val);
|
|
587
632
|
}
|
|
@@ -604,7 +649,6 @@ class rowHelperBase {
|
|
|
604
649
|
initSubscribers() {
|
|
605
650
|
if (!this._subscribers) {
|
|
606
651
|
this._subscribers = new SubscribableImp();
|
|
607
|
-
;
|
|
608
652
|
for (const col of this.columnsInfo) {
|
|
609
653
|
let ei = getEntitySettings(col.valueType, false);
|
|
610
654
|
let refImpl = this.fields.find(col.key);
|
|
@@ -624,7 +668,7 @@ class rowHelperBase {
|
|
|
624
668
|
this._subscribers.reportChanged();
|
|
625
669
|
refImpl._subscribers.reportChanged();
|
|
626
670
|
},
|
|
627
|
-
enumerable: true
|
|
671
|
+
enumerable: true,
|
|
628
672
|
});
|
|
629
673
|
}
|
|
630
674
|
}
|
|
@@ -639,7 +683,7 @@ class rowHelperBase {
|
|
|
639
683
|
this._subscribers?.reportChanged();
|
|
640
684
|
}
|
|
641
685
|
async waitLoad() {
|
|
642
|
-
await Promise.all([...this.lookups.values()].map(x => x.waitLoad()));
|
|
686
|
+
await Promise.all([...this.lookups.values()].map((x) => x.waitLoad()));
|
|
643
687
|
}
|
|
644
688
|
__assertValidity() {
|
|
645
689
|
if (!this.hasErrors())
|
|
@@ -648,12 +692,13 @@ class rowHelperBase {
|
|
|
648
692
|
buildErrorInfoObject() {
|
|
649
693
|
let error = {
|
|
650
694
|
modelState: Object.assign({}, this.errors),
|
|
651
|
-
message: this.error
|
|
695
|
+
message: this.error,
|
|
652
696
|
};
|
|
653
697
|
if (!error.message) {
|
|
654
698
|
for (const col of this.columnsInfo) {
|
|
655
699
|
if (this.errors[col.key]) {
|
|
656
|
-
error.message =
|
|
700
|
+
error.message =
|
|
701
|
+
this.fields[col.key].metadata.caption + ': ' + this.errors[col.key];
|
|
657
702
|
this.error = error.message;
|
|
658
703
|
break;
|
|
659
704
|
}
|
|
@@ -664,7 +709,7 @@ class rowHelperBase {
|
|
|
664
709
|
catchSaveErrors(err) {
|
|
665
710
|
let e = err;
|
|
666
711
|
if (e instanceof Promise) {
|
|
667
|
-
return e.then(x => this.catchSaveErrors(x));
|
|
712
|
+
return e.then((x) => this.catchSaveErrors(x));
|
|
668
713
|
}
|
|
669
714
|
if (e.error) {
|
|
670
715
|
e = e.error;
|
|
@@ -723,8 +768,7 @@ class rowHelperBase {
|
|
|
723
768
|
this.originalValues = this.copyDataToObject();
|
|
724
769
|
this.saveMoreOriginalData();
|
|
725
770
|
}
|
|
726
|
-
saveMoreOriginalData() {
|
|
727
|
-
}
|
|
771
|
+
saveMoreOriginalData() { }
|
|
728
772
|
async validate() {
|
|
729
773
|
this.__clearErrorsAndReportChanged();
|
|
730
774
|
if (classValidatorValidate)
|
|
@@ -743,16 +787,20 @@ class rowHelperBase {
|
|
|
743
787
|
await this.__performColumnAndEntityValidations();
|
|
744
788
|
this.__assertValidity();
|
|
745
789
|
}
|
|
746
|
-
async __performColumnAndEntityValidations() {
|
|
747
|
-
|
|
748
|
-
toApiJson() {
|
|
790
|
+
async __performColumnAndEntityValidations() { }
|
|
791
|
+
toApiJson(includeRelatedEntities = false) {
|
|
749
792
|
let result = {};
|
|
750
793
|
for (const col of this.columnsInfo) {
|
|
751
|
-
if (!this.remult ||
|
|
794
|
+
if (!this.remult ||
|
|
795
|
+
col.includeInApi === undefined ||
|
|
796
|
+
this.remult.isAllowed(col.includeInApi)) {
|
|
752
797
|
let val;
|
|
753
798
|
let lu = this.lookups.get(col.key);
|
|
754
799
|
if (lu)
|
|
755
|
-
|
|
800
|
+
if (includeRelatedEntities)
|
|
801
|
+
val = lu.toJson();
|
|
802
|
+
else
|
|
803
|
+
val = lu.id;
|
|
756
804
|
else {
|
|
757
805
|
val = this.instance[col.key];
|
|
758
806
|
if (!this.remult) {
|
|
@@ -773,8 +821,11 @@ class rowHelperBase {
|
|
|
773
821
|
let keys = Object.keys(body);
|
|
774
822
|
for (const col of this.columnsInfo) {
|
|
775
823
|
if (keys.includes(col.key))
|
|
776
|
-
if (col.includeInApi === undefined ||
|
|
777
|
-
|
|
824
|
+
if (col.includeInApi === undefined ||
|
|
825
|
+
this.remult.isAllowed(col.includeInApi)) {
|
|
826
|
+
if (!this.remult ||
|
|
827
|
+
col.allowApiUpdate === undefined ||
|
|
828
|
+
this.remult.isAllowedForInstance(this.instance, col.allowApiUpdate)) {
|
|
778
829
|
let lu = this.lookups.get(col.key);
|
|
779
830
|
if (lu)
|
|
780
831
|
lu.id = body[col.key];
|
|
@@ -783,7 +834,7 @@ class rowHelperBase {
|
|
|
783
834
|
}
|
|
784
835
|
}
|
|
785
836
|
}
|
|
786
|
-
await Promise.all([...this.fields].map(x => x.load()));
|
|
837
|
+
await Promise.all([...this.fields].map((x) => x.load()));
|
|
787
838
|
}
|
|
788
839
|
}
|
|
789
840
|
export class rowHelperImplementation extends rowHelperBase {
|
|
@@ -799,7 +850,7 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
799
850
|
if (_isNew) {
|
|
800
851
|
for (const col of info.columnsInfo) {
|
|
801
852
|
if (col.defaultValue && instance[col.key] === undefined) {
|
|
802
|
-
if (typeof col.defaultValue ===
|
|
853
|
+
if (typeof col.defaultValue === 'function') {
|
|
803
854
|
instance[col.key] = col.defaultValue(instance);
|
|
804
855
|
}
|
|
805
856
|
else if (!instance[col.key])
|
|
@@ -812,9 +863,15 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
812
863
|
if (Remult.entityRefInit)
|
|
813
864
|
Remult.entityRefInit(this, instance);
|
|
814
865
|
}
|
|
815
|
-
get apiUpdateAllowed() {
|
|
816
|
-
|
|
817
|
-
|
|
866
|
+
get apiUpdateAllowed() {
|
|
867
|
+
return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiUpdate);
|
|
868
|
+
}
|
|
869
|
+
get apiDeleteAllowed() {
|
|
870
|
+
return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiDelete);
|
|
871
|
+
}
|
|
872
|
+
get apiInsertAllowed() {
|
|
873
|
+
return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiInsert);
|
|
874
|
+
}
|
|
818
875
|
getId() {
|
|
819
876
|
return this.info.idMetadata.getId(this.instance);
|
|
820
877
|
}
|
|
@@ -841,12 +898,12 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
841
898
|
if (!this._columns) {
|
|
842
899
|
let _items = [];
|
|
843
900
|
let r = {
|
|
844
|
-
find: (c) => r[typeof c ===
|
|
901
|
+
find: (c) => r[typeof c === 'string' ? c : c.key],
|
|
845
902
|
[Symbol.iterator]: () => _items[Symbol.iterator](),
|
|
846
|
-
toArray: () => _items
|
|
903
|
+
toArray: () => _items,
|
|
847
904
|
};
|
|
848
905
|
for (const c of this.info.columnsInfo) {
|
|
849
|
-
_items.push(r[c.key] = new FieldRefImplementation(c, this.info.fields[c.key], this.instance, this, this));
|
|
906
|
+
_items.push((r[c.key] = new FieldRefImplementation(c, this.info.fields[c.key], this.instance, this, this)));
|
|
850
907
|
}
|
|
851
908
|
this._columns = r;
|
|
852
909
|
}
|
|
@@ -855,10 +912,10 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
855
912
|
async save() {
|
|
856
913
|
try {
|
|
857
914
|
if (this._saving)
|
|
858
|
-
throw new Error(
|
|
915
|
+
throw new Error('cannot save while entity is already saving');
|
|
859
916
|
this._saving = true;
|
|
860
917
|
if (this.wasDeleted())
|
|
861
|
-
throw new Error(
|
|
918
|
+
throw new Error('cannot save a deleted row');
|
|
862
919
|
this.isLoading = true;
|
|
863
920
|
await this.__validateEntity();
|
|
864
921
|
let doNotSave = false;
|
|
@@ -867,7 +924,7 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
867
924
|
await col.metadata.options.saving(this.instance, col);
|
|
868
925
|
}
|
|
869
926
|
if (this.info.entityInfo.saving) {
|
|
870
|
-
await this.info.entityInfo.saving(this.instance, () => doNotSave = true);
|
|
927
|
+
await this.info.entityInfo.saving(this.instance, () => (doNotSave = true));
|
|
871
928
|
}
|
|
872
929
|
this.__assertValidity();
|
|
873
930
|
let d = this.copyDataToObject();
|
|
@@ -881,7 +938,7 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
881
938
|
}
|
|
882
939
|
}
|
|
883
940
|
if (this.info.idMetadata.field instanceof CompoundIdField)
|
|
884
|
-
delete
|
|
941
|
+
delete d.id;
|
|
885
942
|
let updatedRow;
|
|
886
943
|
let isNew = this.isNew();
|
|
887
944
|
try {
|
|
@@ -895,7 +952,8 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
895
952
|
for (const key in d) {
|
|
896
953
|
if (Object.prototype.hasOwnProperty.call(d, key)) {
|
|
897
954
|
const element = d[key];
|
|
898
|
-
if (this.fields.find(key).valueChanged() &&
|
|
955
|
+
if (this.fields.find(key).valueChanged() &&
|
|
956
|
+
!ignoreKeys.includes(key)) {
|
|
899
957
|
changesOnly[key] = element;
|
|
900
958
|
wasChanged = true;
|
|
901
959
|
}
|
|
@@ -914,7 +972,7 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
914
972
|
if (this.info.entityInfo.saved)
|
|
915
973
|
await this.info.entityInfo.saved(this.instance);
|
|
916
974
|
if (this.repository.listeners)
|
|
917
|
-
for (const listener of this.repository.listeners.filter(x => x.saved)) {
|
|
975
|
+
for (const listener of this.repository.listeners.filter((x) => x.saved)) {
|
|
918
976
|
await listener.saved(this.instance, isNew);
|
|
919
977
|
}
|
|
920
978
|
await this.repository.remult.liveQueryPublisher.itemChanged(this.repository.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: false }]);
|
|
@@ -945,7 +1003,7 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
945
1003
|
if (this.info.entityInfo.deleted)
|
|
946
1004
|
await this.info.entityInfo.deleted(this.instance);
|
|
947
1005
|
if (this.repository.listeners)
|
|
948
|
-
for (const listener of this.repository.listeners.filter(x => x.deleted)) {
|
|
1006
|
+
for (const listener of this.repository.listeners.filter((x) => x.deleted)) {
|
|
949
1007
|
await listener.deleted(this.instance);
|
|
950
1008
|
}
|
|
951
1009
|
await this.repository.remult.liveQueryPublisher.itemChanged(this.repository.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: true }]);
|
|
@@ -1008,14 +1066,14 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
1008
1066
|
if (this.info.entityInfo.validation)
|
|
1009
1067
|
await this.info.entityInfo.validation(this.instance, this);
|
|
1010
1068
|
if (this.repository.listeners)
|
|
1011
|
-
for (const listener of this.repository.listeners.filter(x => x.validating)) {
|
|
1069
|
+
for (const listener of this.repository.listeners.filter((x) => x.validating)) {
|
|
1012
1070
|
await listener.validating(this.instance);
|
|
1013
1071
|
}
|
|
1014
1072
|
}
|
|
1015
1073
|
}
|
|
1016
|
-
const controllerColumns = Symbol(
|
|
1074
|
+
const controllerColumns = Symbol('controllerColumns');
|
|
1017
1075
|
function prepareColumnInfo(r, remult) {
|
|
1018
|
-
return r.map(x => decorateColumnSettings(x.settings(remult), remult));
|
|
1076
|
+
return r.map((x) => decorateColumnSettings(x.settings(remult), remult));
|
|
1019
1077
|
}
|
|
1020
1078
|
export function getFields(container, remult) {
|
|
1021
1079
|
return getControllerRef(container, remult).fields;
|
|
@@ -1028,12 +1086,12 @@ export function getControllerRef(container, remultArg) {
|
|
|
1028
1086
|
if (!result) {
|
|
1029
1087
|
let columnSettings = columnsOfType.get(container.constructor);
|
|
1030
1088
|
if (!columnSettings)
|
|
1031
|
-
columnsOfType.set(container.constructor, columnSettings = []);
|
|
1089
|
+
columnsOfType.set(container.constructor, (columnSettings = []));
|
|
1032
1090
|
let base = Object.getPrototypeOf(container.constructor);
|
|
1033
1091
|
while (base != null) {
|
|
1034
1092
|
let baseCols = columnsOfType.get(base);
|
|
1035
1093
|
if (baseCols) {
|
|
1036
|
-
columnSettings.unshift(...baseCols.filter(x => !columnSettings.find(y => y.key == x.key)));
|
|
1094
|
+
columnSettings.unshift(...baseCols.filter((x) => !columnSettings.find((y) => y.key == x.key)));
|
|
1037
1095
|
}
|
|
1038
1096
|
base = Object.getPrototypeOf(base);
|
|
1039
1097
|
}
|
|
@@ -1046,12 +1104,12 @@ export class controllerRefImpl extends rowHelperBase {
|
|
|
1046
1104
|
super(columnsInfo, instance, remult);
|
|
1047
1105
|
let _items = [];
|
|
1048
1106
|
let r = {
|
|
1049
|
-
find: (c) => r[typeof c ===
|
|
1107
|
+
find: (c) => r[typeof c === 'string' ? c : c.key],
|
|
1050
1108
|
[Symbol.iterator]: () => _items[Symbol.iterator](),
|
|
1051
|
-
toArray: () => _items
|
|
1109
|
+
toArray: () => _items,
|
|
1052
1110
|
};
|
|
1053
1111
|
for (const col of columnsInfo) {
|
|
1054
|
-
_items.push(r[col.key] = new FieldRefImplementation(col, new columnDefsImpl(col, undefined, remult), instance, undefined, this));
|
|
1112
|
+
_items.push((r[col.key] = new FieldRefImplementation(col, new columnDefsImpl(col, undefined, remult), instance, undefined, this)));
|
|
1055
1113
|
}
|
|
1056
1114
|
this.fields = r;
|
|
1057
1115
|
}
|
|
@@ -1132,13 +1190,14 @@ export class FieldRefImplementation {
|
|
|
1132
1190
|
else
|
|
1133
1191
|
return this.value.toString();
|
|
1134
1192
|
}
|
|
1135
|
-
return
|
|
1193
|
+
return '';
|
|
1194
|
+
}
|
|
1195
|
+
get value() {
|
|
1196
|
+
return this.container[this.metadata.key];
|
|
1197
|
+
}
|
|
1198
|
+
set value(value) {
|
|
1199
|
+
this.container[this.metadata.key] = value;
|
|
1136
1200
|
}
|
|
1137
|
-
;
|
|
1138
|
-
get value() { return this.container[this.metadata.key]; }
|
|
1139
|
-
;
|
|
1140
|
-
set value(value) { this.container[this.metadata.key] = value; }
|
|
1141
|
-
;
|
|
1142
1201
|
get originalValue() {
|
|
1143
1202
|
this.reportObserved();
|
|
1144
1203
|
let lu = this.rowBase.lookups.get(this.metadata.key);
|
|
@@ -1146,7 +1205,6 @@ export class FieldRefImplementation {
|
|
|
1146
1205
|
return lu.get(this.rawOriginalValue());
|
|
1147
1206
|
return this.rowBase.originalValues[this.metadata.key];
|
|
1148
1207
|
}
|
|
1149
|
-
;
|
|
1150
1208
|
rawOriginalValue() {
|
|
1151
1209
|
return this.rowBase.originalValues[this.metadata.key];
|
|
1152
1210
|
}
|
|
@@ -1174,7 +1232,6 @@ export class FieldRefImplementation {
|
|
|
1174
1232
|
else
|
|
1175
1233
|
this.value = this.metadata.valueConverter.fromInput(val, this.settings.inputType);
|
|
1176
1234
|
}
|
|
1177
|
-
;
|
|
1178
1235
|
valueChanged() {
|
|
1179
1236
|
this.reportObserved();
|
|
1180
1237
|
let val = this.value;
|
|
@@ -1182,11 +1239,11 @@ export class FieldRefImplementation {
|
|
|
1182
1239
|
if (lu) {
|
|
1183
1240
|
val = lu.id;
|
|
1184
1241
|
}
|
|
1185
|
-
return JSON.stringify(this.metadata.valueConverter.toJson(this.rowBase.originalValues[this.metadata.key])) != JSON.stringify(this.metadata.valueConverter.toJson(val));
|
|
1242
|
+
return (JSON.stringify(this.metadata.valueConverter.toJson(this.rowBase.originalValues[this.metadata.key])) != JSON.stringify(this.metadata.valueConverter.toJson(val)));
|
|
1186
1243
|
}
|
|
1187
1244
|
async __performValidation() {
|
|
1188
1245
|
try {
|
|
1189
|
-
let x = typeof
|
|
1246
|
+
let x = typeof this.settings.validate;
|
|
1190
1247
|
if (Array.isArray(this.settings.validate)) {
|
|
1191
1248
|
for (const v of this.settings.validate) {
|
|
1192
1249
|
await v(this.container, this);
|
|
@@ -1196,7 +1253,7 @@ export class FieldRefImplementation {
|
|
|
1196
1253
|
await this.settings.validate(this.container, this);
|
|
1197
1254
|
}
|
|
1198
1255
|
catch (error) {
|
|
1199
|
-
if (typeof error ===
|
|
1256
|
+
if (typeof error === 'string')
|
|
1200
1257
|
this.error = error;
|
|
1201
1258
|
else
|
|
1202
1259
|
this.error = error.message;
|
|
@@ -1210,15 +1267,17 @@ export class FieldRefImplementation {
|
|
|
1210
1267
|
export function getEntityRef(entity, throwException = true) {
|
|
1211
1268
|
let x = entity[entityMember];
|
|
1212
1269
|
if (!x && throwException)
|
|
1213
|
-
throw new Error(
|
|
1270
|
+
throw new Error('item ' +
|
|
1271
|
+
entity.constructor.name +
|
|
1272
|
+
' was not initialized using a context');
|
|
1214
1273
|
return x;
|
|
1215
1274
|
}
|
|
1216
1275
|
export const CaptionTransformer = {
|
|
1217
|
-
transformCaption: (remult, key, caption) => caption
|
|
1276
|
+
transformCaption: (remult, key, caption) => caption,
|
|
1218
1277
|
};
|
|
1219
1278
|
export function buildCaption(caption, key, remult) {
|
|
1220
1279
|
let result;
|
|
1221
|
-
if (typeof
|
|
1280
|
+
if (typeof caption === 'function') {
|
|
1222
1281
|
if (remult)
|
|
1223
1282
|
result = caption(remult);
|
|
1224
1283
|
}
|
|
@@ -1240,12 +1299,12 @@ export class columnDefsImpl {
|
|
|
1240
1299
|
this.target = this.settings.target;
|
|
1241
1300
|
this.valueConverter = this.settings.valueConverter;
|
|
1242
1301
|
this.allowNull = !!this.settings.allowNull;
|
|
1243
|
-
this.inputType = this.settings.inputType;
|
|
1244
|
-
this.key = this.settings.key;
|
|
1245
1302
|
this.valueType = this.settings.valueType;
|
|
1303
|
+
this.key = this.settings.key;
|
|
1304
|
+
this.inputType = this.settings.inputType;
|
|
1246
1305
|
if (settings.serverExpression)
|
|
1247
1306
|
this.isServerExpression = true;
|
|
1248
|
-
if (typeof
|
|
1307
|
+
if (typeof this.settings.allowApiUpdate === 'boolean')
|
|
1249
1308
|
this.readonly = this.settings.allowApiUpdate;
|
|
1250
1309
|
if (!this.inputType)
|
|
1251
1310
|
this.inputType = this.valueConverter.inputType;
|
|
@@ -1257,7 +1316,9 @@ export class columnDefsImpl {
|
|
|
1257
1316
|
return this.remult.isAllowedForInstance(item, this.options.allowApiUpdate);
|
|
1258
1317
|
}
|
|
1259
1318
|
displayValue(item) {
|
|
1260
|
-
return this.
|
|
1319
|
+
return this.entityDefs
|
|
1320
|
+
.getEntityMetadataWithoutBreakingTheEntity(item)
|
|
1321
|
+
.fields.find(this.key).displayValue;
|
|
1261
1322
|
}
|
|
1262
1323
|
get includedInApi() {
|
|
1263
1324
|
if (this.options.includeInApi === undefined)
|
|
@@ -1274,7 +1335,7 @@ export class columnDefsImpl {
|
|
|
1274
1335
|
try {
|
|
1275
1336
|
if (this.settings.sqlExpression) {
|
|
1276
1337
|
let result;
|
|
1277
|
-
if (typeof this.settings.sqlExpression ===
|
|
1338
|
+
if (typeof this.settings.sqlExpression === 'function') {
|
|
1278
1339
|
result = await this.settings.sqlExpression(this.entityDefs);
|
|
1279
1340
|
}
|
|
1280
1341
|
else
|
|
@@ -1291,7 +1352,7 @@ export class columnDefsImpl {
|
|
|
1291
1352
|
get dbName() {
|
|
1292
1353
|
let result;
|
|
1293
1354
|
if (this.settings.sqlExpression) {
|
|
1294
|
-
if (typeof this.settings.sqlExpression ===
|
|
1355
|
+
if (typeof this.settings.sqlExpression === 'function') {
|
|
1295
1356
|
result = this.settings.sqlExpression(this.entityDefs);
|
|
1296
1357
|
}
|
|
1297
1358
|
else
|
|
@@ -1304,7 +1365,6 @@ export class columnDefsImpl {
|
|
|
1304
1365
|
get dbReadOnly() {
|
|
1305
1366
|
return this.settings.dbReadOnly;
|
|
1306
1367
|
}
|
|
1307
|
-
;
|
|
1308
1368
|
}
|
|
1309
1369
|
class EntityFullInfo {
|
|
1310
1370
|
constructor(columnsInfo, entityInfo, remult, entityType, key) {
|
|
@@ -1313,9 +1373,8 @@ class EntityFullInfo {
|
|
|
1313
1373
|
this.remult = remult;
|
|
1314
1374
|
this.entityType = entityType;
|
|
1315
1375
|
this.key = key;
|
|
1316
|
-
this.options = this.entityInfo;
|
|
1317
1376
|
this.idMetadata = {
|
|
1318
|
-
getId: item => {
|
|
1377
|
+
getId: (item) => {
|
|
1319
1378
|
if (this.idMetadata.field instanceof CompoundIdField)
|
|
1320
1379
|
return this.idMetadata.field.getId(item);
|
|
1321
1380
|
else
|
|
@@ -1325,7 +1384,7 @@ class EntityFullInfo {
|
|
|
1325
1384
|
createIdInFilter: (items) => {
|
|
1326
1385
|
if (items.length > 0)
|
|
1327
1386
|
return {
|
|
1328
|
-
$or: items.map(x => this.idMetadata.getIdFilter(getEntityRef(x).getId()))
|
|
1387
|
+
$or: items.map((x) => this.idMetadata.getIdFilter(getEntityRef(x).getId())),
|
|
1329
1388
|
};
|
|
1330
1389
|
},
|
|
1331
1390
|
isIdField: (col) => {
|
|
@@ -1335,26 +1394,32 @@ class EntityFullInfo {
|
|
|
1335
1394
|
if (this.idMetadata.field instanceof CompoundIdField) {
|
|
1336
1395
|
let field = this.idMetadata.field;
|
|
1337
1396
|
return {
|
|
1338
|
-
$or: ids.map(x => field.isEqualTo(x))
|
|
1397
|
+
$or: ids.map((x) => field.isEqualTo(x)),
|
|
1339
1398
|
};
|
|
1340
1399
|
}
|
|
1341
1400
|
if (ids.length == 1)
|
|
1342
1401
|
return {
|
|
1343
|
-
[this.idMetadata.field.key]: ids[0]
|
|
1402
|
+
[this.idMetadata.field.key]: ids[0],
|
|
1344
1403
|
};
|
|
1345
1404
|
else
|
|
1346
1405
|
return {
|
|
1347
|
-
[this.idMetadata.field.key]: ids
|
|
1406
|
+
[this.idMetadata.field.key]: ids,
|
|
1348
1407
|
};
|
|
1349
|
-
}
|
|
1408
|
+
},
|
|
1350
1409
|
};
|
|
1410
|
+
this.options = entityInfo;
|
|
1351
1411
|
if (this.options.allowApiCrud !== undefined) {
|
|
1412
|
+
let crud;
|
|
1413
|
+
if (typeof this.options.allowApiCrud === 'function')
|
|
1414
|
+
crud = (_, remult) => this.options.allowApiCrud(remult);
|
|
1415
|
+
else
|
|
1416
|
+
crud = this.options.allowApiCrud;
|
|
1352
1417
|
if (this.options.allowApiDelete === undefined)
|
|
1353
|
-
this.options.allowApiDelete =
|
|
1418
|
+
this.options.allowApiDelete = crud;
|
|
1354
1419
|
if (this.options.allowApiInsert === undefined)
|
|
1355
|
-
this.options.allowApiInsert =
|
|
1420
|
+
this.options.allowApiInsert = crud;
|
|
1356
1421
|
if (this.options.allowApiUpdate === undefined)
|
|
1357
|
-
this.options.allowApiUpdate =
|
|
1422
|
+
this.options.allowApiUpdate = crud;
|
|
1358
1423
|
if (this.options.allowApiRead === undefined)
|
|
1359
1424
|
this.options.allowApiRead = this.options.allowApiCrud;
|
|
1360
1425
|
}
|
|
@@ -1366,12 +1431,12 @@ class EntityFullInfo {
|
|
|
1366
1431
|
entityInfo.dbName = this.key;
|
|
1367
1432
|
let _items = [];
|
|
1368
1433
|
let r = {
|
|
1369
|
-
find: (c) => r[typeof c ===
|
|
1434
|
+
find: (c) => r[typeof c === 'string' ? c : c.key],
|
|
1370
1435
|
[Symbol.iterator]: () => _items[Symbol.iterator](),
|
|
1371
|
-
toArray: () => _items
|
|
1436
|
+
toArray: () => _items,
|
|
1372
1437
|
};
|
|
1373
1438
|
for (const x of columnsInfo) {
|
|
1374
|
-
_items.push(r[x.key] = new columnDefsImpl(x, this, remult));
|
|
1439
|
+
_items.push((r[x.key] = new columnDefsImpl(x, this, remult)));
|
|
1375
1440
|
}
|
|
1376
1441
|
this.fields = r;
|
|
1377
1442
|
this.caption = buildCaption(entityInfo.caption, this.key, remult);
|
|
@@ -1387,8 +1452,8 @@ class EntityFullInfo {
|
|
|
1387
1452
|
this.idMetadata.field = r;
|
|
1388
1453
|
}
|
|
1389
1454
|
else {
|
|
1390
|
-
if (this.fields[
|
|
1391
|
-
this.idMetadata.field = this.fields[
|
|
1455
|
+
if (this.fields['id'])
|
|
1456
|
+
this.idMetadata.field = this.fields['id'];
|
|
1392
1457
|
else
|
|
1393
1458
|
this.idMetadata.field = [...this.fields][0];
|
|
1394
1459
|
}
|
|
@@ -1396,7 +1461,9 @@ class EntityFullInfo {
|
|
|
1396
1461
|
apiUpdateAllowed(item) {
|
|
1397
1462
|
if (this.options.allowApiUpdate === undefined)
|
|
1398
1463
|
return false;
|
|
1399
|
-
return !item
|
|
1464
|
+
return !item
|
|
1465
|
+
? this.remult.isAllowedForInstance(undefined, this.options.allowApiUpdate)
|
|
1466
|
+
: this.getEntityMetadataWithoutBreakingTheEntity(item).apiUpdateAllowed;
|
|
1400
1467
|
}
|
|
1401
1468
|
get apiReadAllowed() {
|
|
1402
1469
|
if (this.options.allowApiRead === undefined)
|
|
@@ -1406,12 +1473,22 @@ class EntityFullInfo {
|
|
|
1406
1473
|
apiDeleteAllowed(item) {
|
|
1407
1474
|
if (this.options.allowApiDelete === undefined)
|
|
1408
1475
|
return false;
|
|
1409
|
-
return !item
|
|
1476
|
+
return !item
|
|
1477
|
+
? this.remult.isAllowedForInstance(undefined, this.options.allowApiDelete)
|
|
1478
|
+
: this.getEntityMetadataWithoutBreakingTheEntity(item).apiDeleteAllowed;
|
|
1410
1479
|
}
|
|
1411
1480
|
apiInsertAllowed(item) {
|
|
1412
1481
|
if (this.options.allowApiUpdate === undefined)
|
|
1413
1482
|
return false;
|
|
1414
|
-
return !item
|
|
1483
|
+
return !item
|
|
1484
|
+
? this.remult.isAllowedForInstance(undefined, this.options.allowApiInsert)
|
|
1485
|
+
: this.getEntityMetadataWithoutBreakingTheEntity(item).apiInsertAllowed;
|
|
1486
|
+
}
|
|
1487
|
+
getEntityMetadataWithoutBreakingTheEntity(item) {
|
|
1488
|
+
let result = getEntityRef(item, false);
|
|
1489
|
+
if (result)
|
|
1490
|
+
return result;
|
|
1491
|
+
return this.remult.repo(this.entityType).getEntityRef({ ...item });
|
|
1415
1492
|
}
|
|
1416
1493
|
getDbName() {
|
|
1417
1494
|
if (this.dbNamePromise)
|
|
@@ -1419,16 +1496,16 @@ class EntityFullInfo {
|
|
|
1419
1496
|
if (!this.options.sqlExpression) {
|
|
1420
1497
|
this.dbNamePromise = Promise.resolve(this.options.dbName);
|
|
1421
1498
|
}
|
|
1422
|
-
if (typeof this.options.sqlExpression ===
|
|
1499
|
+
if (typeof this.options.sqlExpression === 'string')
|
|
1423
1500
|
this.dbNamePromise = Promise.resolve(this.options.sqlExpression);
|
|
1424
|
-
else if (typeof this.options.sqlExpression ===
|
|
1501
|
+
else if (typeof this.options.sqlExpression === 'function') {
|
|
1425
1502
|
let r = this.options.sqlExpression(this);
|
|
1426
1503
|
if (r instanceof Promise)
|
|
1427
1504
|
this.dbNamePromise = r;
|
|
1428
1505
|
else if (r)
|
|
1429
1506
|
this.dbNamePromise = Promise.resolve(r);
|
|
1430
1507
|
}
|
|
1431
|
-
this.dbNamePromise = this.dbNamePromise.then(x => {
|
|
1508
|
+
this.dbNamePromise = this.dbNamePromise.then((x) => {
|
|
1432
1509
|
if (!x)
|
|
1433
1510
|
return this.options.dbName;
|
|
1434
1511
|
return x;
|
|
@@ -1437,7 +1514,7 @@ class EntityFullInfo {
|
|
|
1437
1514
|
}
|
|
1438
1515
|
}
|
|
1439
1516
|
export function FieldType(...options) {
|
|
1440
|
-
return target => {
|
|
1517
|
+
return (target, context) => {
|
|
1441
1518
|
if (!options) {
|
|
1442
1519
|
options = [];
|
|
1443
1520
|
}
|
|
@@ -1449,20 +1526,20 @@ export function FieldType(...options) {
|
|
|
1449
1526
|
export class Fields {
|
|
1450
1527
|
/**
|
|
1451
1528
|
* Stored as a JSON.stringify - to store as json use Fields.json
|
|
1452
|
-
|
|
1529
|
+
*/
|
|
1453
1530
|
static object(...options) {
|
|
1454
1531
|
return Field(undefined, ...options);
|
|
1455
1532
|
}
|
|
1456
1533
|
static json(...options) {
|
|
1457
1534
|
return Field(undefined, {
|
|
1458
1535
|
valueConverter: {
|
|
1459
|
-
fieldTypeInDb:
|
|
1460
|
-
}
|
|
1536
|
+
fieldTypeInDb: 'json',
|
|
1537
|
+
},
|
|
1461
1538
|
}, ...options);
|
|
1462
1539
|
}
|
|
1463
1540
|
static dateOnly(...options) {
|
|
1464
1541
|
return Field(() => Date, {
|
|
1465
|
-
valueConverter: ValueConverters.DateOnly
|
|
1542
|
+
valueConverter: ValueConverters.DateOnly,
|
|
1466
1543
|
}, ...options);
|
|
1467
1544
|
}
|
|
1468
1545
|
static date(...options) {
|
|
@@ -1470,14 +1547,17 @@ export class Fields {
|
|
|
1470
1547
|
}
|
|
1471
1548
|
static integer(...options) {
|
|
1472
1549
|
return Field(() => Number, {
|
|
1473
|
-
valueConverter: ValueConverters.Integer
|
|
1550
|
+
valueConverter: ValueConverters.Integer,
|
|
1474
1551
|
}, ...options);
|
|
1475
1552
|
}
|
|
1476
1553
|
static autoIncrement(...options) {
|
|
1477
1554
|
return Field(() => Number, {
|
|
1478
1555
|
allowApiUpdate: false,
|
|
1479
1556
|
dbReadOnly: true,
|
|
1480
|
-
valueConverter: {
|
|
1557
|
+
valueConverter: {
|
|
1558
|
+
...ValueConverters.Integer,
|
|
1559
|
+
fieldTypeInDb: 'autoincrement',
|
|
1560
|
+
},
|
|
1481
1561
|
}, ...options);
|
|
1482
1562
|
}
|
|
1483
1563
|
static number(...options) {
|
|
@@ -1489,7 +1569,7 @@ export class Fields {
|
|
|
1489
1569
|
saving: (_, ref) => {
|
|
1490
1570
|
if (getEntityRef(_).isNew())
|
|
1491
1571
|
ref.value = new Date();
|
|
1492
|
-
}
|
|
1572
|
+
},
|
|
1493
1573
|
}, ...options);
|
|
1494
1574
|
}
|
|
1495
1575
|
static updatedAt(...options) {
|
|
@@ -1497,7 +1577,7 @@ export class Fields {
|
|
|
1497
1577
|
allowApiUpdate: false,
|
|
1498
1578
|
saving: (_, ref) => {
|
|
1499
1579
|
ref.value = new Date();
|
|
1500
|
-
}
|
|
1580
|
+
},
|
|
1501
1581
|
}, ...options);
|
|
1502
1582
|
}
|
|
1503
1583
|
static uuid(...options) {
|
|
@@ -1507,17 +1587,17 @@ export class Fields {
|
|
|
1507
1587
|
saving: (_, r) => {
|
|
1508
1588
|
if (!r.value)
|
|
1509
1589
|
r.value = uuid();
|
|
1510
|
-
}
|
|
1590
|
+
},
|
|
1511
1591
|
}, ...options);
|
|
1512
1592
|
}
|
|
1513
1593
|
static cuid(...options) {
|
|
1514
1594
|
return Field(() => String, {
|
|
1515
1595
|
allowApiUpdate: false,
|
|
1516
|
-
defaultValue: () =>
|
|
1596
|
+
defaultValue: () => createId(),
|
|
1517
1597
|
saving: (_, r) => {
|
|
1518
1598
|
if (!r.value)
|
|
1519
|
-
r.value =
|
|
1520
|
-
}
|
|
1599
|
+
r.value = createId();
|
|
1600
|
+
},
|
|
1521
1601
|
}, ...options);
|
|
1522
1602
|
}
|
|
1523
1603
|
static string(...options) {
|
|
@@ -1531,11 +1611,12 @@ export function isAutoIncrement(f) {
|
|
|
1531
1611
|
return f.options?.valueConverter?.fieldTypeInDb === 'autoincrement';
|
|
1532
1612
|
}
|
|
1533
1613
|
export function ValueListFieldType(...options) {
|
|
1534
|
-
return (type) => {
|
|
1535
|
-
FieldType(o => {
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1614
|
+
return (type, context) => {
|
|
1615
|
+
FieldType((o) => {
|
|
1616
|
+
;
|
|
1617
|
+
(o.valueConverter = ValueListInfo.get(type)),
|
|
1618
|
+
(o.displayValue = (item, val) => val?.caption);
|
|
1619
|
+
}, ...options)(type, context);
|
|
1539
1620
|
};
|
|
1540
1621
|
}
|
|
1541
1622
|
export class ValueListInfo {
|
|
@@ -1566,18 +1647,19 @@ export class ValueListInfo {
|
|
|
1566
1647
|
if (op?.getValues) {
|
|
1567
1648
|
this.values.splice(0, this.values.length, ...op.getValues());
|
|
1568
1649
|
this.byIdMap.clear();
|
|
1569
|
-
this.values.forEach(s => {
|
|
1650
|
+
this.values.forEach((s) => {
|
|
1570
1651
|
if (s.caption === undefined && s.id !== undefined)
|
|
1571
1652
|
s.caption = makeTitle(s.id);
|
|
1572
1653
|
this.byIdMap.set(s.id, s);
|
|
1573
1654
|
});
|
|
1574
1655
|
}
|
|
1575
1656
|
}
|
|
1576
|
-
if (this.values.find(s => s.id === undefined))
|
|
1657
|
+
if (this.values.find((s) => s.id === undefined))
|
|
1577
1658
|
throw new Error(`ValueType ${this.valueListType} has values without an id`);
|
|
1578
1659
|
}
|
|
1579
1660
|
else
|
|
1580
|
-
throw new Error(`ValueType not yet initialized, did you forget to call @ValueListFieldType on ` +
|
|
1661
|
+
throw new Error(`ValueType not yet initialized, did you forget to call @ValueListFieldType on ` +
|
|
1662
|
+
valueListType);
|
|
1581
1663
|
}
|
|
1582
1664
|
static get(type) {
|
|
1583
1665
|
let r = typeCache.get(type);
|
|
@@ -1649,7 +1731,9 @@ export function getValueList(type) {
|
|
|
1649
1731
|
* title='';
|
|
1650
1732
|
*/
|
|
1651
1733
|
export function Field(valueType, ...options) {
|
|
1652
|
-
|
|
1734
|
+
// IMPORTANT!!!! if you call this in another decorator, make sure to set It's return type correctly with the | undefined
|
|
1735
|
+
return (target, context, c) => {
|
|
1736
|
+
const key = typeof context === 'string' ? context : context.name.toString();
|
|
1653
1737
|
let factory = (remult) => {
|
|
1654
1738
|
let r = buildOptions(options, remult);
|
|
1655
1739
|
if (!r.valueType && valueType) {
|
|
@@ -1662,19 +1746,20 @@ export function Field(valueType, ...options) {
|
|
|
1662
1746
|
r.dbName = r.key;
|
|
1663
1747
|
let type = r.valueType;
|
|
1664
1748
|
if (!type) {
|
|
1665
|
-
type = Reflect.getMetadata(
|
|
1749
|
+
type = Reflect.getMetadata('design:type', target, key);
|
|
1666
1750
|
r.valueType = type;
|
|
1667
1751
|
}
|
|
1668
1752
|
if (!r.target)
|
|
1669
1753
|
r.target = target;
|
|
1670
1754
|
return r;
|
|
1671
1755
|
};
|
|
1756
|
+
checkTarget(target);
|
|
1672
1757
|
let names = columnsOfType.get(target.constructor);
|
|
1673
1758
|
if (!names) {
|
|
1674
1759
|
names = [];
|
|
1675
1760
|
columnsOfType.set(target.constructor, names);
|
|
1676
1761
|
}
|
|
1677
|
-
let set = names.find(x => x.key == key);
|
|
1762
|
+
let set = names.find((x) => x.key == key);
|
|
1678
1763
|
if (!set)
|
|
1679
1764
|
names.push({
|
|
1680
1765
|
key,
|
|
@@ -1690,12 +1775,12 @@ export function Field(valueType, ...options) {
|
|
|
1690
1775
|
}
|
|
1691
1776
|
};
|
|
1692
1777
|
}
|
|
1693
|
-
export const storableMember = Symbol(
|
|
1778
|
+
export const storableMember = Symbol('storableMember');
|
|
1694
1779
|
function buildOptions(options, remult) {
|
|
1695
1780
|
let r = {};
|
|
1696
1781
|
for (const o of options) {
|
|
1697
1782
|
if (o) {
|
|
1698
|
-
if (typeof o ===
|
|
1783
|
+
if (typeof o === 'function')
|
|
1699
1784
|
o(r, remult);
|
|
1700
1785
|
else
|
|
1701
1786
|
Object.assign(r, o);
|
|
@@ -1709,7 +1794,7 @@ export function decorateColumnSettings(settings, remult) {
|
|
|
1709
1794
|
if (settingsOnTypeLevel) {
|
|
1710
1795
|
settings = {
|
|
1711
1796
|
...buildOptions(settingsOnTypeLevel, remult),
|
|
1712
|
-
...settings
|
|
1797
|
+
...settings,
|
|
1713
1798
|
};
|
|
1714
1799
|
}
|
|
1715
1800
|
}
|
|
@@ -1737,34 +1822,58 @@ export function decorateColumnSettings(settings, remult) {
|
|
|
1737
1822
|
if (!settings.valueConverter) {
|
|
1738
1823
|
let ei = getEntitySettings(settings.valueType, false);
|
|
1739
1824
|
if (ei) {
|
|
1825
|
+
let isIdNumeric = undefined;
|
|
1740
1826
|
settings.valueConverter = {
|
|
1741
|
-
toDb: x => x,
|
|
1742
|
-
fromDb: x => x
|
|
1827
|
+
toDb: (x) => x,
|
|
1828
|
+
fromDb: (x) => x,
|
|
1743
1829
|
};
|
|
1830
|
+
settings.valueConverter = new Proxy(settings.valueConverter, {
|
|
1831
|
+
get(target, property) {
|
|
1832
|
+
if (target[property] === undefined) {
|
|
1833
|
+
if (isIdNumeric === undefined) {
|
|
1834
|
+
isIdNumeric =
|
|
1835
|
+
remult.repo(settings.valueType).metadata.idMetadata.field
|
|
1836
|
+
.valueType === Number;
|
|
1837
|
+
for (const key of [
|
|
1838
|
+
'fieldTypeInDb',
|
|
1839
|
+
]) {
|
|
1840
|
+
//@ts-ignore
|
|
1841
|
+
target[key] = ValueConverters.Integer[key];
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
return target[property];
|
|
1846
|
+
},
|
|
1847
|
+
set(target, property, value, receiver) {
|
|
1848
|
+
target[property] = value;
|
|
1849
|
+
return true;
|
|
1850
|
+
},
|
|
1851
|
+
});
|
|
1744
1852
|
}
|
|
1745
1853
|
else
|
|
1746
1854
|
settings.valueConverter = ValueConverters.Default;
|
|
1747
1855
|
}
|
|
1748
1856
|
if (!settings.valueConverter.toJson) {
|
|
1749
|
-
settings.valueConverter.toJson = x => x;
|
|
1857
|
+
settings.valueConverter.toJson = (x) => x;
|
|
1750
1858
|
}
|
|
1751
1859
|
if (!settings.valueConverter.fromJson) {
|
|
1752
|
-
settings.valueConverter.fromJson = x => x;
|
|
1860
|
+
settings.valueConverter.fromJson = (x) => x;
|
|
1753
1861
|
}
|
|
1754
1862
|
if (!settings.valueConverter.toDb) {
|
|
1755
|
-
settings.valueConverter.toDb = x => settings.valueConverter.toJson(x);
|
|
1863
|
+
settings.valueConverter.toDb = (x) => settings.valueConverter.toJson(x);
|
|
1756
1864
|
}
|
|
1757
1865
|
if (!settings.valueConverter.fromDb) {
|
|
1758
|
-
settings.valueConverter.fromDb = x => settings.valueConverter.fromJson(x);
|
|
1866
|
+
settings.valueConverter.fromDb = (x) => settings.valueConverter.fromJson(x);
|
|
1759
1867
|
}
|
|
1760
1868
|
if (!settings.valueConverter.toInput) {
|
|
1761
|
-
settings.valueConverter.toInput = x => settings.valueConverter.toJson(x);
|
|
1869
|
+
settings.valueConverter.toInput = (x) => settings.valueConverter.toJson(x);
|
|
1762
1870
|
}
|
|
1763
1871
|
if (!settings.valueConverter.fromInput) {
|
|
1764
|
-
settings.valueConverter.fromInput = x => settings.valueConverter.fromJson(x);
|
|
1872
|
+
settings.valueConverter.fromInput = (x) => settings.valueConverter.fromJson(x);
|
|
1765
1873
|
}
|
|
1766
1874
|
return settings;
|
|
1767
1875
|
}
|
|
1876
|
+
//[ ] YONI - in Typescript 5 I do get the name of the class, what would we like to change because of that?
|
|
1768
1877
|
/**Decorates classes that should be used as entities.
|
|
1769
1878
|
* Receives a key and an array of EntityOptions.
|
|
1770
1879
|
* @example
|
|
@@ -1790,7 +1899,7 @@ export function decorateColumnSettings(settings, remult) {
|
|
|
1790
1899
|
* @Entity("tasks", (options,remult) => options.allowApiCrud = true)
|
|
1791
1900
|
*/
|
|
1792
1901
|
export function Entity(key, ...options) {
|
|
1793
|
-
return target => {
|
|
1902
|
+
return (target, info) => {
|
|
1794
1903
|
for (const rawFilterMember in target) {
|
|
1795
1904
|
if (Object.prototype.hasOwnProperty.call(target, rawFilterMember)) {
|
|
1796
1905
|
const element = target[rawFilterMember];
|
|
@@ -1800,11 +1909,11 @@ export function Entity(key, ...options) {
|
|
|
1800
1909
|
}
|
|
1801
1910
|
}
|
|
1802
1911
|
}
|
|
1803
|
-
let factory = remult => {
|
|
1912
|
+
let factory = (remult) => {
|
|
1804
1913
|
let r = {};
|
|
1805
1914
|
for (const o of options) {
|
|
1806
1915
|
if (o) {
|
|
1807
|
-
if (typeof o ===
|
|
1916
|
+
if (typeof o === 'function')
|
|
1808
1917
|
o(r, remult);
|
|
1809
1918
|
else
|
|
1810
1919
|
Object.assign(r, o);
|
|
@@ -1818,7 +1927,7 @@ export function Entity(key, ...options) {
|
|
|
1818
1927
|
if (opt) {
|
|
1819
1928
|
r = {
|
|
1820
1929
|
...opt,
|
|
1821
|
-
...r
|
|
1930
|
+
...r,
|
|
1822
1931
|
};
|
|
1823
1932
|
}
|
|
1824
1933
|
}
|
|
@@ -1833,15 +1942,25 @@ export function Entity(key, ...options) {
|
|
|
1833
1942
|
};
|
|
1834
1943
|
}
|
|
1835
1944
|
export class EntityBase {
|
|
1836
|
-
get _() {
|
|
1837
|
-
|
|
1945
|
+
get _() {
|
|
1946
|
+
return getEntityRef(this);
|
|
1947
|
+
}
|
|
1948
|
+
save() {
|
|
1949
|
+
return this._.save();
|
|
1950
|
+
}
|
|
1838
1951
|
assign(values) {
|
|
1839
1952
|
assign(this, values);
|
|
1840
1953
|
return this;
|
|
1841
1954
|
}
|
|
1842
|
-
delete() {
|
|
1843
|
-
|
|
1844
|
-
|
|
1955
|
+
delete() {
|
|
1956
|
+
return this._.delete();
|
|
1957
|
+
}
|
|
1958
|
+
isNew() {
|
|
1959
|
+
return this._.isNew();
|
|
1960
|
+
}
|
|
1961
|
+
get $() {
|
|
1962
|
+
return this._.fields;
|
|
1963
|
+
}
|
|
1845
1964
|
}
|
|
1846
1965
|
export class IdEntity extends EntityBase {
|
|
1847
1966
|
}
|
|
@@ -1857,8 +1976,12 @@ export class ControllerBase {
|
|
|
1857
1976
|
assign(this, values);
|
|
1858
1977
|
return this;
|
|
1859
1978
|
}
|
|
1860
|
-
get $() {
|
|
1861
|
-
|
|
1979
|
+
get $() {
|
|
1980
|
+
return getFields(this, this.remult);
|
|
1981
|
+
}
|
|
1982
|
+
get _() {
|
|
1983
|
+
return getControllerRef(this, this.remult);
|
|
1984
|
+
}
|
|
1862
1985
|
}
|
|
1863
1986
|
class QueryResultImpl {
|
|
1864
1987
|
constructor(options, repo) {
|
|
@@ -1879,7 +2002,7 @@ class QueryResultImpl {
|
|
|
1879
2002
|
orderBy: this.options.orderBy,
|
|
1880
2003
|
limit: this.options.pageSize,
|
|
1881
2004
|
page: page,
|
|
1882
|
-
load: this.options.load
|
|
2005
|
+
load: this.options.load,
|
|
1883
2006
|
});
|
|
1884
2007
|
}
|
|
1885
2008
|
async count() {
|
|
@@ -1898,10 +2021,12 @@ class QueryResultImpl {
|
|
|
1898
2021
|
async paginator(pNextPageFilter) {
|
|
1899
2022
|
this.options.orderBy = Sort.createUniqueEntityOrderBy(this.repo.metadata, this.options.orderBy);
|
|
1900
2023
|
let items = await this.repo.find({
|
|
1901
|
-
where: {
|
|
2024
|
+
where: {
|
|
2025
|
+
$and: [this.options.where, pNextPageFilter],
|
|
2026
|
+
},
|
|
1902
2027
|
orderBy: this.options.orderBy,
|
|
1903
2028
|
limit: this.options.pageSize,
|
|
1904
|
-
load: this.options.load
|
|
2029
|
+
load: this.options.load,
|
|
1905
2030
|
});
|
|
1906
2031
|
let nextPage = undefined;
|
|
1907
2032
|
let hasNextPage = items.length == this.options.pageSize;
|
|
@@ -1913,7 +2038,7 @@ class QueryResultImpl {
|
|
|
1913
2038
|
count: () => this.count(),
|
|
1914
2039
|
hasNextPage,
|
|
1915
2040
|
items,
|
|
1916
|
-
nextPage
|
|
2041
|
+
nextPage,
|
|
1917
2042
|
};
|
|
1918
2043
|
}
|
|
1919
2044
|
[Symbol.asyncIterator]() {
|
|
@@ -1928,7 +2053,7 @@ class QueryResultImpl {
|
|
|
1928
2053
|
let j = 0;
|
|
1929
2054
|
itStrategy = async () => {
|
|
1930
2055
|
if (this.options.progress) {
|
|
1931
|
-
this.options.progress.progress(j++ / await this.count());
|
|
2056
|
+
this.options.progress.progress(j++ / (await this.count()));
|
|
1932
2057
|
}
|
|
1933
2058
|
if (currentPage === undefined || itemIndex == currentPage.items.length) {
|
|
1934
2059
|
if (currentPage && !currentPage.hasNextPage)
|
|
@@ -1944,8 +2069,9 @@ class QueryResultImpl {
|
|
|
1944
2069
|
}
|
|
1945
2070
|
else {
|
|
1946
2071
|
if (prev?.items.length > 0) {
|
|
1947
|
-
if (this.repo.getEntityRef(prev.items[0]).getId() ==
|
|
1948
|
-
|
|
2072
|
+
if (this.repo.getEntityRef(prev.items[0]).getId() ==
|
|
2073
|
+
this.repo.getEntityRef(currentPage.items[0]).getId())
|
|
2074
|
+
throw new Error('pagination failure, returned same first row');
|
|
1949
2075
|
}
|
|
1950
2076
|
}
|
|
1951
2077
|
}
|
|
@@ -1956,7 +2082,7 @@ class QueryResultImpl {
|
|
|
1956
2082
|
next: async () => {
|
|
1957
2083
|
let r = itStrategy();
|
|
1958
2084
|
return r;
|
|
1959
|
-
}
|
|
2085
|
+
},
|
|
1960
2086
|
};
|
|
1961
2087
|
}
|
|
1962
2088
|
}
|
|
@@ -1968,18 +2094,18 @@ class cacheEntityInfo {
|
|
|
1968
2094
|
class SubscribableImp {
|
|
1969
2095
|
reportChanged() {
|
|
1970
2096
|
if (this._subscribers)
|
|
1971
|
-
this._subscribers.forEach(x => x.reportChanged());
|
|
2097
|
+
this._subscribers.forEach((x) => x.reportChanged());
|
|
1972
2098
|
}
|
|
1973
2099
|
reportObserved() {
|
|
1974
2100
|
if (this._subscribers)
|
|
1975
|
-
this._subscribers.forEach(x => x.reportObserved());
|
|
2101
|
+
this._subscribers.forEach((x) => x.reportObserved());
|
|
1976
2102
|
}
|
|
1977
2103
|
subscribe(listener) {
|
|
1978
2104
|
let list;
|
|
1979
|
-
if (typeof listener ===
|
|
2105
|
+
if (typeof listener === 'function')
|
|
1980
2106
|
list = {
|
|
1981
2107
|
reportChanged: () => listener(),
|
|
1982
|
-
reportObserved: () => { }
|
|
2108
|
+
reportObserved: () => { },
|
|
1983
2109
|
};
|
|
1984
2110
|
else
|
|
1985
2111
|
list = listener;
|
|
@@ -1987,7 +2113,7 @@ class SubscribableImp {
|
|
|
1987
2113
|
this._subscribers = [];
|
|
1988
2114
|
}
|
|
1989
2115
|
this._subscribers.push(list);
|
|
1990
|
-
return () => this._subscribers = this._subscribers.filter(x => x != list);
|
|
2116
|
+
return () => (this._subscribers = this._subscribers.filter((x) => x != list));
|
|
1991
2117
|
}
|
|
1992
2118
|
}
|
|
1993
2119
|
export function getEntityMetadata(entity) {
|
|
@@ -1995,14 +2121,18 @@ export function getEntityMetadata(entity) {
|
|
|
1995
2121
|
return entity.metadata;
|
|
1996
2122
|
const settings = getEntitySettings(entity, false);
|
|
1997
2123
|
if (settings) {
|
|
1998
|
-
return
|
|
2124
|
+
return defaultRemult.repo(entity).metadata;
|
|
1999
2125
|
}
|
|
2000
2126
|
return entity;
|
|
2001
2127
|
}
|
|
2002
2128
|
export function getRepository(entity) {
|
|
2003
2129
|
const settings = getEntitySettings(entity, false);
|
|
2004
2130
|
if (settings) {
|
|
2005
|
-
return
|
|
2131
|
+
return defaultRemult.repo(entity);
|
|
2006
2132
|
}
|
|
2007
2133
|
return entity;
|
|
2008
2134
|
}
|
|
2135
|
+
export function checkTarget(target) {
|
|
2136
|
+
if (!target)
|
|
2137
|
+
throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)");
|
|
2138
|
+
}
|