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,1157 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { SseSubscriptionServer } from '../SseSubscriptionServer.js';
|
|
3
|
+
import { Remult, RemultAsyncLocalStorage, withRemult } from '../src/context.js';
|
|
4
|
+
import { DataApi, serializeError } from '../src/data-api.js';
|
|
5
|
+
import { liveQueryKeepAliveRoute, streamUrl, } from '../src/live-query/SubscriptionChannel.js';
|
|
6
|
+
import { InMemoryLiveQueryStorage, LiveQueryPublisher, } from '../src/live-query/SubscriptionServer.js';
|
|
7
|
+
import { IdEntity } from '../src/remult3/IdEntity.js';
|
|
8
|
+
import { Fields } from '../src/remult3/Fields.js';
|
|
9
|
+
import { Entity } from '../src/remult3/entity.js';
|
|
10
|
+
import { getEntityKey } from '../src/remult3/getEntityRef.js';
|
|
11
|
+
import { Action, classBackendMethodsArray } from '../src/server-action.js';
|
|
12
|
+
import { serverActionField } from '../src/server-action-info.js';
|
|
13
|
+
import { remultStatic } from '../src/remult-static.js';
|
|
14
|
+
import remultAdminHtml from './remult-admin.js';
|
|
15
|
+
import { isOfType } from '../src/isOfType.js';
|
|
16
|
+
import { initDataProviderOrJson } from './initDataProviderOrJson.js';
|
|
17
|
+
export function createRemultServerCore(options, serverCoreOptions) {
|
|
18
|
+
const safeOptions = options ?? {};
|
|
19
|
+
if (!safeOptions.subscriptionServer) {
|
|
20
|
+
safeOptions.subscriptionServer = new SseSubscriptionServer();
|
|
21
|
+
}
|
|
22
|
+
if (safeOptions.logApiEndPoints === undefined)
|
|
23
|
+
safeOptions.logApiEndPoints = true;
|
|
24
|
+
remultStatic.actionInfo.runningOnServer = true;
|
|
25
|
+
if (safeOptions.defaultGetLimit) {
|
|
26
|
+
DataApi.defaultGetLimit = safeOptions.defaultGetLimit;
|
|
27
|
+
}
|
|
28
|
+
if (!safeOptions.queueStorage) {
|
|
29
|
+
safeOptions.queueStorage = new InMemoryQueueStorage();
|
|
30
|
+
}
|
|
31
|
+
let dataProvider = initDataProviderOrJson(safeOptions.dataProvider);
|
|
32
|
+
remultStatic.defaultDataProvider = () => dataProvider;
|
|
33
|
+
if (safeOptions.ensureSchema === undefined)
|
|
34
|
+
safeOptions.ensureSchema = true;
|
|
35
|
+
RemultAsyncLocalStorage.enable();
|
|
36
|
+
{
|
|
37
|
+
let allControllers = [];
|
|
38
|
+
if (safeOptions.entities)
|
|
39
|
+
allControllers.push(...safeOptions.entities);
|
|
40
|
+
if (safeOptions.controllers)
|
|
41
|
+
allControllers.push(...safeOptions.controllers);
|
|
42
|
+
safeOptions.controllers = allControllers;
|
|
43
|
+
}
|
|
44
|
+
if (safeOptions.rootPath === undefined)
|
|
45
|
+
safeOptions.rootPath = '/api';
|
|
46
|
+
remultStatic.actionInfo.runningOnServer = true;
|
|
47
|
+
let bridge = new RemultServerImplementation(new inProcessQueueHandler(safeOptions.queueStorage), safeOptions, dataProvider, serverCoreOptions);
|
|
48
|
+
return bridge;
|
|
49
|
+
}
|
|
50
|
+
/* @internal*/
|
|
51
|
+
export class RemultServerImplementation {
|
|
52
|
+
queue;
|
|
53
|
+
options;
|
|
54
|
+
dataProvider;
|
|
55
|
+
coreOptions;
|
|
56
|
+
liveQueryStorage = new InMemoryLiveQueryStorage();
|
|
57
|
+
constructor(queue, options, dataProvider, coreOptions) {
|
|
58
|
+
this.queue = queue;
|
|
59
|
+
this.options = options;
|
|
60
|
+
this.dataProvider = dataProvider;
|
|
61
|
+
this.coreOptions = coreOptions;
|
|
62
|
+
if (options.liveQueryStorage)
|
|
63
|
+
this.liveQueryStorage = options.liveQueryStorage;
|
|
64
|
+
if (options.subscriptionServer)
|
|
65
|
+
this.subscriptionServer = options.subscriptionServer;
|
|
66
|
+
const entitiesMetaData = [];
|
|
67
|
+
this.dataProvider = dataProvider.then(async (dp) => {
|
|
68
|
+
await this.runWithRemult(async (remult) => {
|
|
69
|
+
remult.dataProvider = dp;
|
|
70
|
+
if (options.ensureSchema) {
|
|
71
|
+
let started = false;
|
|
72
|
+
const startConsoleLog = () => {
|
|
73
|
+
if (started)
|
|
74
|
+
return;
|
|
75
|
+
started = true;
|
|
76
|
+
console.time('Schema ensured');
|
|
77
|
+
};
|
|
78
|
+
if (options.entities)
|
|
79
|
+
entitiesMetaData.push(...options.entities.map((e) => remult.repo(e).metadata));
|
|
80
|
+
if (dp.ensureSchema) {
|
|
81
|
+
startConsoleLog();
|
|
82
|
+
await dp.ensureSchema(entitiesMetaData);
|
|
83
|
+
}
|
|
84
|
+
for (const item of [
|
|
85
|
+
options.liveQueryStorage,
|
|
86
|
+
options.queueStorage,
|
|
87
|
+
]) {
|
|
88
|
+
if (item?.ensureSchema) {
|
|
89
|
+
startConsoleLog();
|
|
90
|
+
await item.ensureSchema();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (started)
|
|
94
|
+
console.timeEnd('Schema ensured');
|
|
95
|
+
}
|
|
96
|
+
if (options.initApi)
|
|
97
|
+
await options.initApi(remult);
|
|
98
|
+
}, { skipDataProvider: true });
|
|
99
|
+
return dp;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
withRemultAsync(request, what) {
|
|
103
|
+
if (!request)
|
|
104
|
+
return this.runWithRemult(what);
|
|
105
|
+
return new Promise(async (resolve, error) => {
|
|
106
|
+
try {
|
|
107
|
+
return await this.withRemult(request, undefined, async () => {
|
|
108
|
+
try {
|
|
109
|
+
what().then(resolve).catch(error);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
error(err);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
error(err);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
getEntities() {
|
|
122
|
+
//TODO V2 - consider using entitiesMetaData - but it may require making it all awaitable
|
|
123
|
+
var r = new Remult();
|
|
124
|
+
return this.options.entities.map((x) => r.repo(x).metadata);
|
|
125
|
+
}
|
|
126
|
+
runWithSerializedJsonContextData = async (jsonContextData, entityKey, what) => {
|
|
127
|
+
for (const e of this.options.entities) {
|
|
128
|
+
let key = getEntityKey(e);
|
|
129
|
+
if (key === entityKey) {
|
|
130
|
+
await this.runWithRemult(async (remult) => {
|
|
131
|
+
remult.user = jsonContextData.user;
|
|
132
|
+
if (this.options.contextSerializer) {
|
|
133
|
+
await this.options.contextSerializer.deserialize(jsonContextData.context, {
|
|
134
|
+
remult,
|
|
135
|
+
get liveQueryStorage() {
|
|
136
|
+
return remult.liveQueryStorage;
|
|
137
|
+
},
|
|
138
|
+
set liveQueryStorage(value) {
|
|
139
|
+
remult.liveQueryStorage = value;
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
await what(remult.repo(e));
|
|
144
|
+
});
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
throw new Error("Couldn't find entity " + entityKey);
|
|
149
|
+
};
|
|
150
|
+
subscriptionServer;
|
|
151
|
+
withRemult = async (req, res, next) => {
|
|
152
|
+
await this.process(async () => {
|
|
153
|
+
await next();
|
|
154
|
+
})(req, res);
|
|
155
|
+
};
|
|
156
|
+
routeImpl;
|
|
157
|
+
getRouteImpl() {
|
|
158
|
+
if (!this.routeImpl) {
|
|
159
|
+
this.routeImpl = new RouteImplementation(this.coreOptions);
|
|
160
|
+
this.registerRouter(this.routeImpl);
|
|
161
|
+
}
|
|
162
|
+
return this.routeImpl;
|
|
163
|
+
}
|
|
164
|
+
handle(req, gRes) {
|
|
165
|
+
return this.getRouteImpl().handle(req, gRes);
|
|
166
|
+
}
|
|
167
|
+
registeredRouter = false;
|
|
168
|
+
registerRouter(r) {
|
|
169
|
+
if (this.registeredRouter)
|
|
170
|
+
throw 'Router already registered';
|
|
171
|
+
this.registeredRouter = true;
|
|
172
|
+
{
|
|
173
|
+
for (const c of this.options.controllers) {
|
|
174
|
+
let z = c[classBackendMethodsArray];
|
|
175
|
+
if (z)
|
|
176
|
+
for (const a of z) {
|
|
177
|
+
let x = a[serverActionField];
|
|
178
|
+
if (!x) {
|
|
179
|
+
throw 'failed to set server action, did you forget the BackendMethod Decorator?';
|
|
180
|
+
}
|
|
181
|
+
this.addAction(x, r);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (this.hasQueue)
|
|
185
|
+
this.addAction({
|
|
186
|
+
__register: (x) => {
|
|
187
|
+
x(Action.apiUrlForJobStatus, false, () => true, async (data, req, res) => {
|
|
188
|
+
let job = await this.queue.getJobInfo(data.queuedJobId);
|
|
189
|
+
let userId = undefined;
|
|
190
|
+
if (req?.user)
|
|
191
|
+
userId = req.user.id;
|
|
192
|
+
if (job.userId == '')
|
|
193
|
+
job.userId = undefined;
|
|
194
|
+
if (userId != job.userId)
|
|
195
|
+
res.forbidden();
|
|
196
|
+
else
|
|
197
|
+
res.success(job.info);
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
doWork: undefined,
|
|
201
|
+
}, r);
|
|
202
|
+
if (this.options.admin !== undefined && this.options.admin !== false) {
|
|
203
|
+
const admin = this.process(async (remult, req, res, orig, origResponse) => {
|
|
204
|
+
if (remult.isAllowed(this.options.admin))
|
|
205
|
+
origResponse.send(remultAdminHtml({
|
|
206
|
+
remult: remult,
|
|
207
|
+
entities: this.options.entities,
|
|
208
|
+
baseUrl: this.options.rootPath + '/admin',
|
|
209
|
+
}));
|
|
210
|
+
else
|
|
211
|
+
res.notFound();
|
|
212
|
+
});
|
|
213
|
+
r.route(this.options.rootPath + '/admin/:id').get(admin);
|
|
214
|
+
r.route(this.options.rootPath + '/admin/').get(admin);
|
|
215
|
+
r.route(this.options.rootPath + '/admin').get(admin);
|
|
216
|
+
}
|
|
217
|
+
if (this.options.subscriptionServer instanceof SseSubscriptionServer) {
|
|
218
|
+
const streamPath = this.options.rootPath + '/' + streamUrl;
|
|
219
|
+
r.route(streamPath).get(this.process(async (remult, req, res, origReq, origRes) => {
|
|
220
|
+
;
|
|
221
|
+
remult.subscriptionServer.openHttpServerStream(origReq, origRes);
|
|
222
|
+
}));
|
|
223
|
+
r.route(streamPath + '/subscribe').post(this.process(async (remult, _2, res, _, _1, origReq) => {
|
|
224
|
+
const body = remult.subscriptionServer.subscribeToChannel(await this.coreOptions.getRequestBody(origReq), res, remult);
|
|
225
|
+
}));
|
|
226
|
+
r.route(streamPath + '/unsubscribe').post(this.process(async (remult, req, res, reqInfo, origRes, origReq) => {
|
|
227
|
+
;
|
|
228
|
+
remult.subscriptionServer.subscribeToChannel(await this.coreOptions.getRequestBody(origReq), res, remult, true);
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
r.route(this.options.rootPath + '/' + liveQueryKeepAliveRoute).post(this.process(async (remult, req, res, reqInfo, origRes, origReq) => {
|
|
232
|
+
res.success(await remult.liveQueryStorage.keepAliveAndReturnUnknownQueryIds(await this.coreOptions.getRequestBody(origReq)));
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
this.options.entities?.forEach((e) => {
|
|
236
|
+
let key = getEntityKey(e);
|
|
237
|
+
if (key != undefined)
|
|
238
|
+
this.add(key, (c) => {
|
|
239
|
+
return new DataApi(c.repo(e), c);
|
|
240
|
+
}, r);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
async serializeContext(remult) {
|
|
244
|
+
let result = {
|
|
245
|
+
user: remult.user,
|
|
246
|
+
context: undefined,
|
|
247
|
+
};
|
|
248
|
+
if (this.options.contextSerializer) {
|
|
249
|
+
result.context = await this.options.contextSerializer.serialize(remult);
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
add(key, dataApiFactory, r) {
|
|
254
|
+
let myRoute = this.options.rootPath + '/' + key;
|
|
255
|
+
if (this.options.logApiEndPoints)
|
|
256
|
+
console.info('[remult] ' + myRoute);
|
|
257
|
+
r.route(myRoute)
|
|
258
|
+
.get(this.process((c, req, res, orig) => dataApiFactory(c).httpGet(res, req, () => this.serializeContext(c))))
|
|
259
|
+
.put(this.process(async (c, req, res, _, __, orig) => dataApiFactory(c).updateManyThroughPutRequest(res, req, await this.coreOptions.getRequestBody(orig))))
|
|
260
|
+
.delete(this.process(async (c, req, res, _, __, orig) => dataApiFactory(c).deleteMany(res, req, undefined)))
|
|
261
|
+
.post(this.process(async (c, req, res, _, __, orig) => dataApiFactory(c).httpPost(res, req, await this.coreOptions.getRequestBody(orig), () => this.serializeContext(c))));
|
|
262
|
+
r.route(myRoute + '/:id')
|
|
263
|
+
//@ts-ignore
|
|
264
|
+
.get(this.process(async (c, req, res, orig) => dataApiFactory(c).get(res, orig.params.id)))
|
|
265
|
+
//@ts-ignore
|
|
266
|
+
.put(this.process(async (c, req, res, reqInfo, _, orig) => dataApiFactory(c).put(res, reqInfo.params.id, await this.coreOptions.getRequestBody(orig))))
|
|
267
|
+
//@ts-ignore
|
|
268
|
+
.delete(this.process(async (c, req, res, orig) => dataApiFactory(c).delete(res, orig.params.id)));
|
|
269
|
+
}
|
|
270
|
+
//runs with remult but without init request
|
|
271
|
+
async runWithRemult(what, options) {
|
|
272
|
+
let dataProvider;
|
|
273
|
+
if (!options?.skipDataProvider)
|
|
274
|
+
dataProvider = await this.dataProvider;
|
|
275
|
+
return await withRemult(async (remult) => {
|
|
276
|
+
var x = remult;
|
|
277
|
+
x.liveQueryPublisher = new LiveQueryPublisher(() => remult.subscriptionServer, () => remult.liveQueryStorage, this.runWithSerializedJsonContextData);
|
|
278
|
+
if (!options?.skipDataProvider)
|
|
279
|
+
x.dataProvider = dataProvider;
|
|
280
|
+
x.subscriptionServer = this.subscriptionServer;
|
|
281
|
+
x.liveQueryStorage = this.liveQueryStorage;
|
|
282
|
+
return await what(x);
|
|
283
|
+
}, {
|
|
284
|
+
dataProvider: dataProvider,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
process(what) {
|
|
288
|
+
return async (req, origRes) => {
|
|
289
|
+
const genReq = req ? this.coreOptions.buildGenericRequestInfo(req) : {};
|
|
290
|
+
if (req) {
|
|
291
|
+
if (!genReq.query) {
|
|
292
|
+
genReq.query = req['_tempQuery'];
|
|
293
|
+
}
|
|
294
|
+
if (!genReq.params)
|
|
295
|
+
genReq.params = req['_tempParams'];
|
|
296
|
+
}
|
|
297
|
+
let myReq = new RequestBridgeToDataApiRequest(genReq);
|
|
298
|
+
let myRes = new ResponseBridgeToDataApiResponse(origRes, req, genReq, this.options.error);
|
|
299
|
+
try {
|
|
300
|
+
if (remultStatic.asyncContext.isInInitRequest())
|
|
301
|
+
return await what(remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req);
|
|
302
|
+
else
|
|
303
|
+
await this.runWithRemult(async (remult) => {
|
|
304
|
+
if (req) {
|
|
305
|
+
;
|
|
306
|
+
remult.context.request = req;
|
|
307
|
+
remultStatic.asyncContext.setInInitRequest(true);
|
|
308
|
+
try {
|
|
309
|
+
let user;
|
|
310
|
+
if (this.options.getUser)
|
|
311
|
+
user = await this.options.getUser(req);
|
|
312
|
+
else {
|
|
313
|
+
user = req['user'];
|
|
314
|
+
if (!user)
|
|
315
|
+
user = req['auth'];
|
|
316
|
+
}
|
|
317
|
+
if (user)
|
|
318
|
+
remult.user = user;
|
|
319
|
+
if (this.options.initRequest) {
|
|
320
|
+
await this.options.initRequest(req, {
|
|
321
|
+
remult,
|
|
322
|
+
get liveQueryStorage() {
|
|
323
|
+
return remult.liveQueryStorage;
|
|
324
|
+
},
|
|
325
|
+
set liveQueryStorage(value) {
|
|
326
|
+
remult.liveQueryStorage = value;
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
finally {
|
|
332
|
+
remultStatic.asyncContext.setInInitRequest(false);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
await what(remult, myReq, myRes, genReq, origRes, req);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
catch (err) {
|
|
339
|
+
if (origRes)
|
|
340
|
+
myRes.error(err, undefined);
|
|
341
|
+
else
|
|
342
|
+
throw err;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
async getRemult(req) {
|
|
347
|
+
let remult;
|
|
348
|
+
if (!req)
|
|
349
|
+
return await this.runWithRemult(async (c) => (remult = c));
|
|
350
|
+
await this.process(async (c) => {
|
|
351
|
+
remult = c;
|
|
352
|
+
})(req, undefined);
|
|
353
|
+
return remult;
|
|
354
|
+
}
|
|
355
|
+
hasQueue = false;
|
|
356
|
+
addAction(action, r) {
|
|
357
|
+
action.__register((url, queue, allowed, what) => {
|
|
358
|
+
let myUrl = this.options.rootPath + '/' + url;
|
|
359
|
+
let tag = (() => {
|
|
360
|
+
let split = url.split('/');
|
|
361
|
+
if (split.length == 1)
|
|
362
|
+
return 'Static Backend Methods';
|
|
363
|
+
else
|
|
364
|
+
return split[0];
|
|
365
|
+
})();
|
|
366
|
+
this.backendMethodsOpenApi.push({ path: myUrl, allowed, tag });
|
|
367
|
+
if (this.options.logApiEndPoints)
|
|
368
|
+
console.info('[remult] ' + myUrl);
|
|
369
|
+
if (queue) {
|
|
370
|
+
this.hasQueue = true;
|
|
371
|
+
this.queue.mapQueuedAction(myUrl, what);
|
|
372
|
+
}
|
|
373
|
+
r.route(myUrl).post(this.process(async (remult, req, res, _, __, orig) => {
|
|
374
|
+
if (queue) {
|
|
375
|
+
let r = {
|
|
376
|
+
queuedJobId: await this.queue.submitJob(myUrl, remult, await this.coreOptions.getRequestBody(orig)),
|
|
377
|
+
};
|
|
378
|
+
res.success(r);
|
|
379
|
+
}
|
|
380
|
+
else
|
|
381
|
+
return what(await this.coreOptions.getRequestBody(orig), remult, res);
|
|
382
|
+
}));
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
openApiDoc(options) {
|
|
386
|
+
if (!options.version)
|
|
387
|
+
options.version = '1.0.0';
|
|
388
|
+
let spec = {
|
|
389
|
+
info: { title: options.title, version: options.version },
|
|
390
|
+
openapi: '3.0.0',
|
|
391
|
+
//swagger: "2.0",
|
|
392
|
+
components: {
|
|
393
|
+
schemas: {},
|
|
394
|
+
securitySchemes: {
|
|
395
|
+
bearerAuth: {
|
|
396
|
+
scheme: 'bearer',
|
|
397
|
+
bearerFormat: 'JWT',
|
|
398
|
+
type: 'http',
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
paths: {},
|
|
403
|
+
};
|
|
404
|
+
let validationError = {
|
|
405
|
+
'400': {
|
|
406
|
+
description: 'Error: Bad Request',
|
|
407
|
+
content: {
|
|
408
|
+
'application/json': {
|
|
409
|
+
schema: {
|
|
410
|
+
$ref: '#/components/schemas/InvalidResponse',
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
let security = {
|
|
417
|
+
security: [
|
|
418
|
+
{
|
|
419
|
+
bearerAuth: [],
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
};
|
|
423
|
+
let secureBase = (condition, def, item) => {
|
|
424
|
+
if (condition === undefined)
|
|
425
|
+
condition = def;
|
|
426
|
+
if (condition != false) {
|
|
427
|
+
if (condition != true) {
|
|
428
|
+
item = { ...item, ...security };
|
|
429
|
+
item.responses['403'] = { description: 'forbidden' };
|
|
430
|
+
}
|
|
431
|
+
return item;
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
for (const meta of this.getEntities()) {
|
|
435
|
+
let key = meta.key;
|
|
436
|
+
let parameters = [];
|
|
437
|
+
if (key) {
|
|
438
|
+
let mutationKey = key;
|
|
439
|
+
let properties = {};
|
|
440
|
+
let mutationProperties = {};
|
|
441
|
+
for (const f of meta.fields) {
|
|
442
|
+
let type = f.valueType == String
|
|
443
|
+
? 'string'
|
|
444
|
+
: f.valueType == Boolean
|
|
445
|
+
? 'boolean'
|
|
446
|
+
: f.valueType == Date
|
|
447
|
+
? 'string'
|
|
448
|
+
: f.valueType == Number
|
|
449
|
+
? 'number'
|
|
450
|
+
: 'object';
|
|
451
|
+
if (f.options.includeInApi !== false) {
|
|
452
|
+
properties[f.key] = {
|
|
453
|
+
type,
|
|
454
|
+
};
|
|
455
|
+
if (f.options.allowApiUpdate !== false) {
|
|
456
|
+
mutationProperties[f.key] = {
|
|
457
|
+
type,
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
parameters.push({
|
|
461
|
+
name: f.key,
|
|
462
|
+
in: 'query',
|
|
463
|
+
description: 'filter equal to ' +
|
|
464
|
+
f.key +
|
|
465
|
+
'. See [more filtering options](https://remult.dev/docs/rest-api.html#filter)',
|
|
466
|
+
required: false,
|
|
467
|
+
style: 'simple',
|
|
468
|
+
type,
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
spec.components.schemas[key] = {
|
|
473
|
+
type: 'object',
|
|
474
|
+
properties,
|
|
475
|
+
};
|
|
476
|
+
if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
|
|
477
|
+
mutationKey += 'Mutation';
|
|
478
|
+
spec.components.schemas[mutationKey] = {
|
|
479
|
+
type: 'object',
|
|
480
|
+
properties: mutationProperties,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
let definition = {
|
|
484
|
+
$ref: '#/components/schemas/' + key,
|
|
485
|
+
};
|
|
486
|
+
let secure = (condition, def, item) => {
|
|
487
|
+
item.tags = [meta.key];
|
|
488
|
+
if (condition === undefined)
|
|
489
|
+
condition = meta.options.allowApiCrud;
|
|
490
|
+
return secureBase(condition, def, item);
|
|
491
|
+
};
|
|
492
|
+
let apiPath = (spec.paths[this.options.rootPath + '/' + key] = {});
|
|
493
|
+
let itemInBody = {
|
|
494
|
+
requestBody: {
|
|
495
|
+
content: {
|
|
496
|
+
'application/json': {
|
|
497
|
+
schema: {
|
|
498
|
+
$ref: '#/components/schemas/' + mutationKey,
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
};
|
|
504
|
+
let apiPathWithId = (spec.paths[this.options.rootPath + '/' + key + '/{id}'] = {});
|
|
505
|
+
//https://github.com/2fd/open-api.d.ts
|
|
506
|
+
apiPath.get = secure(meta.options.allowApiRead, true, {
|
|
507
|
+
description: 'return an array of ' +
|
|
508
|
+
key +
|
|
509
|
+
'. supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)',
|
|
510
|
+
parameters: [
|
|
511
|
+
{
|
|
512
|
+
name: '_limit',
|
|
513
|
+
in: 'query',
|
|
514
|
+
description: 'limit the number of returned rows, default 100',
|
|
515
|
+
required: false,
|
|
516
|
+
style: 'simple',
|
|
517
|
+
schema: { type: 'integer' },
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
name: '_page',
|
|
521
|
+
in: 'query',
|
|
522
|
+
description: 'to be used for paging',
|
|
523
|
+
required: false,
|
|
524
|
+
schema: { type: 'integer' },
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
name: '_sort',
|
|
528
|
+
in: 'query',
|
|
529
|
+
description: 'the columns to sort on',
|
|
530
|
+
required: false,
|
|
531
|
+
schema: { type: 'string' },
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
name: '_order',
|
|
535
|
+
in: 'query',
|
|
536
|
+
description: 'the sort order to user for the columns in `_sort`',
|
|
537
|
+
required: false,
|
|
538
|
+
schema: { type: 'string' },
|
|
539
|
+
},
|
|
540
|
+
...parameters,
|
|
541
|
+
],
|
|
542
|
+
responses: {
|
|
543
|
+
'200': {
|
|
544
|
+
description: 'returns an array of ' + key,
|
|
545
|
+
content: {
|
|
546
|
+
'application/json': {
|
|
547
|
+
schema: {
|
|
548
|
+
type: 'array',
|
|
549
|
+
items: definition,
|
|
550
|
+
},
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
});
|
|
556
|
+
apiPath.delete = secure(meta.options.allowApiDelete, true, {
|
|
557
|
+
description: 'deletes row of ' +
|
|
558
|
+
key +
|
|
559
|
+
'. supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)',
|
|
560
|
+
parameters: [...parameters],
|
|
561
|
+
responses: {
|
|
562
|
+
'400': {
|
|
563
|
+
description: 'Error: Bad Request',
|
|
564
|
+
content: {
|
|
565
|
+
'application/json': {
|
|
566
|
+
schema: {
|
|
567
|
+
$ref: '#/components/schemas/InvalidResponse',
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
'200': {
|
|
573
|
+
description: 'returns the number of deleted rows ' + key,
|
|
574
|
+
content: {
|
|
575
|
+
'application/json': {
|
|
576
|
+
schema: {
|
|
577
|
+
type: 'object',
|
|
578
|
+
properties: {
|
|
579
|
+
deleted: {
|
|
580
|
+
type: 'number',
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
},
|
|
587
|
+
},
|
|
588
|
+
});
|
|
589
|
+
apiPath.put = secure(meta.options.allowApiDelete, true, {
|
|
590
|
+
description: 'updates row of ' +
|
|
591
|
+
key +
|
|
592
|
+
'. supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)',
|
|
593
|
+
parameters: [...parameters],
|
|
594
|
+
...itemInBody,
|
|
595
|
+
responses: {
|
|
596
|
+
'400': {
|
|
597
|
+
description: 'Error: Bad Request',
|
|
598
|
+
content: {
|
|
599
|
+
'application/json': {
|
|
600
|
+
schema: {
|
|
601
|
+
$ref: '#/components/schemas/InvalidResponse',
|
|
602
|
+
},
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
},
|
|
606
|
+
'200': {
|
|
607
|
+
description: 'returns the number of updated rows ' + key,
|
|
608
|
+
content: {
|
|
609
|
+
'application/json': {
|
|
610
|
+
schema: {
|
|
611
|
+
type: 'object',
|
|
612
|
+
properties: {
|
|
613
|
+
updated: {
|
|
614
|
+
type: 'number',
|
|
615
|
+
},
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
},
|
|
621
|
+
},
|
|
622
|
+
});
|
|
623
|
+
let idParameter = {
|
|
624
|
+
name: 'id',
|
|
625
|
+
in: 'path',
|
|
626
|
+
description: 'id of ' + key,
|
|
627
|
+
required: true,
|
|
628
|
+
schema: { type: 'string' },
|
|
629
|
+
};
|
|
630
|
+
apiPath.post = secure(meta.options.allowApiInsert, false, {
|
|
631
|
+
//"summary": "insert a " + key,
|
|
632
|
+
//"description": "insert a " + key,
|
|
633
|
+
produces: ['application/json'],
|
|
634
|
+
...itemInBody,
|
|
635
|
+
responses: {
|
|
636
|
+
'201': {
|
|
637
|
+
description: 'Created',
|
|
638
|
+
content: {
|
|
639
|
+
'application/json': {
|
|
640
|
+
schema: {
|
|
641
|
+
$ref: '#/components/schemas/' + key,
|
|
642
|
+
},
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
...validationError,
|
|
647
|
+
},
|
|
648
|
+
});
|
|
649
|
+
apiPathWithId.get = secure(meta.options.allowApiRead, true, {
|
|
650
|
+
parameters: [idParameter],
|
|
651
|
+
responses: {
|
|
652
|
+
'200': {
|
|
653
|
+
// "description": "returns an item of " + key,
|
|
654
|
+
content: {
|
|
655
|
+
'application/json': {
|
|
656
|
+
schema: {
|
|
657
|
+
$ref: '#/components/schemas/' + key,
|
|
658
|
+
},
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
},
|
|
663
|
+
});
|
|
664
|
+
apiPathWithId.put = secure(meta.options.allowApiUpdate, false, {
|
|
665
|
+
//"summary": "Update a " + key,
|
|
666
|
+
//"description": "Update a " + key,
|
|
667
|
+
produces: ['application/json'],
|
|
668
|
+
parameters: [idParameter],
|
|
669
|
+
...itemInBody,
|
|
670
|
+
responses: {
|
|
671
|
+
'200': {
|
|
672
|
+
description: 'successful operation',
|
|
673
|
+
content: {
|
|
674
|
+
'application/json': {
|
|
675
|
+
schema: {
|
|
676
|
+
$ref: '#/components/schemas/' + key,
|
|
677
|
+
},
|
|
678
|
+
},
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
...validationError,
|
|
682
|
+
},
|
|
683
|
+
});
|
|
684
|
+
apiPathWithId.delete = secure(meta.options.allowApiDelete, false, {
|
|
685
|
+
// "summary": "Delete a " + key,
|
|
686
|
+
// "description": "Delete a " + key,
|
|
687
|
+
produces: ['application/json'],
|
|
688
|
+
parameters: [idParameter],
|
|
689
|
+
responses: {
|
|
690
|
+
'204': {
|
|
691
|
+
description: 'Deleted',
|
|
692
|
+
},
|
|
693
|
+
...validationError,
|
|
694
|
+
},
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
for (const b of this.backendMethodsOpenApi) {
|
|
699
|
+
spec.paths[b.path] = {
|
|
700
|
+
post: secureBase(b.allowed, false, {
|
|
701
|
+
produces: ['application/json'],
|
|
702
|
+
tags: [b.tag],
|
|
703
|
+
requestBody: {
|
|
704
|
+
content: {
|
|
705
|
+
'application/json': {
|
|
706
|
+
schema: {
|
|
707
|
+
type: 'object',
|
|
708
|
+
properties: {
|
|
709
|
+
args: {
|
|
710
|
+
type: 'array',
|
|
711
|
+
items: { type: 'string' },
|
|
712
|
+
},
|
|
713
|
+
},
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
},
|
|
717
|
+
},
|
|
718
|
+
responses: {
|
|
719
|
+
'201': {
|
|
720
|
+
description: 'Created',
|
|
721
|
+
content: {
|
|
722
|
+
'application/json': {
|
|
723
|
+
schema: {
|
|
724
|
+
type: 'object',
|
|
725
|
+
properties: {
|
|
726
|
+
data: {
|
|
727
|
+
type: 'object',
|
|
728
|
+
},
|
|
729
|
+
},
|
|
730
|
+
},
|
|
731
|
+
},
|
|
732
|
+
},
|
|
733
|
+
},
|
|
734
|
+
...validationError,
|
|
735
|
+
},
|
|
736
|
+
}),
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
spec.components.schemas['InvalidResponse'] = {
|
|
740
|
+
type: 'object',
|
|
741
|
+
properties: {
|
|
742
|
+
message: {
|
|
743
|
+
type: 'string',
|
|
744
|
+
},
|
|
745
|
+
modelState: {
|
|
746
|
+
type: 'object',
|
|
747
|
+
},
|
|
748
|
+
},
|
|
749
|
+
};
|
|
750
|
+
return spec;
|
|
751
|
+
}
|
|
752
|
+
/* internal */
|
|
753
|
+
backendMethodsOpenApi = [];
|
|
754
|
+
}
|
|
755
|
+
class RequestBridgeToDataApiRequest {
|
|
756
|
+
r;
|
|
757
|
+
get(key) {
|
|
758
|
+
return this.r?.query[key];
|
|
759
|
+
}
|
|
760
|
+
constructor(r) {
|
|
761
|
+
this.r = r;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
class ResponseBridgeToDataApiResponse {
|
|
765
|
+
r;
|
|
766
|
+
req;
|
|
767
|
+
genReq;
|
|
768
|
+
handleError;
|
|
769
|
+
forbidden() {
|
|
770
|
+
this.error({ message: 'Forbidden' }, undefined, 403);
|
|
771
|
+
}
|
|
772
|
+
setStatus(status) {
|
|
773
|
+
return this.r.status(status);
|
|
774
|
+
}
|
|
775
|
+
constructor(r, req, genReq, handleError) {
|
|
776
|
+
this.r = r;
|
|
777
|
+
this.req = req;
|
|
778
|
+
this.genReq = genReq;
|
|
779
|
+
this.handleError = handleError;
|
|
780
|
+
}
|
|
781
|
+
progress(progress) { }
|
|
782
|
+
success(data) {
|
|
783
|
+
this.r.json(data);
|
|
784
|
+
}
|
|
785
|
+
created(data) {
|
|
786
|
+
this.setStatus(201).json(data);
|
|
787
|
+
}
|
|
788
|
+
deleted() {
|
|
789
|
+
this.setStatus(204).end();
|
|
790
|
+
}
|
|
791
|
+
notFound() {
|
|
792
|
+
this.error({ message: 'NotFound' }, undefined, 404);
|
|
793
|
+
}
|
|
794
|
+
async error(exception, entity, httpStatusCode) {
|
|
795
|
+
let data = serializeError(exception);
|
|
796
|
+
if (!httpStatusCode) {
|
|
797
|
+
if (data.httpStatusCode) {
|
|
798
|
+
httpStatusCode = data.httpStatusCode;
|
|
799
|
+
}
|
|
800
|
+
else if (isOfType(exception, 'isForbiddenError') &&
|
|
801
|
+
exception.isForbiddenError) {
|
|
802
|
+
httpStatusCode = 403;
|
|
803
|
+
}
|
|
804
|
+
else if (data.modelState) {
|
|
805
|
+
httpStatusCode = 400;
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
httpStatusCode = 400;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
let responseSent = false;
|
|
812
|
+
const sendError = (httpStatusCode, body) => {
|
|
813
|
+
if (responseSent) {
|
|
814
|
+
throw Error('Error response already sent');
|
|
815
|
+
}
|
|
816
|
+
responseSent = true;
|
|
817
|
+
console.error({
|
|
818
|
+
message: body.message,
|
|
819
|
+
httpStatusCode,
|
|
820
|
+
stack: data.stack?.split('\n'),
|
|
821
|
+
url: this.genReq?.url,
|
|
822
|
+
method: this.genReq?.method,
|
|
823
|
+
});
|
|
824
|
+
this.setStatus(httpStatusCode).json(body);
|
|
825
|
+
};
|
|
826
|
+
await this.handleError?.({
|
|
827
|
+
httpStatusCode,
|
|
828
|
+
req: this.req,
|
|
829
|
+
entity,
|
|
830
|
+
exception,
|
|
831
|
+
responseBody: data,
|
|
832
|
+
sendError,
|
|
833
|
+
});
|
|
834
|
+
if (!responseSent) {
|
|
835
|
+
sendError(httpStatusCode, data);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
class inProcessQueueHandler {
|
|
840
|
+
storage;
|
|
841
|
+
constructor(storage) {
|
|
842
|
+
this.storage = storage;
|
|
843
|
+
}
|
|
844
|
+
async submitJob(url, req, body) {
|
|
845
|
+
let id = await this.storage.createJob(url, req.user ? req.user.id : undefined);
|
|
846
|
+
let job = await this.storage.getJobInfo(id);
|
|
847
|
+
this.actions.get(url)(body, req, {
|
|
848
|
+
error: (error) => job.setErrorResult(serializeError(error)),
|
|
849
|
+
success: (result) => job.setResult(result),
|
|
850
|
+
progress: (progress) => job.setProgress(progress),
|
|
851
|
+
created: () => {
|
|
852
|
+
throw Error('Created response not expected for queue');
|
|
853
|
+
},
|
|
854
|
+
deleted: () => {
|
|
855
|
+
throw Error('deleted response not expected for queue');
|
|
856
|
+
},
|
|
857
|
+
notFound: () => {
|
|
858
|
+
throw Error('notFound response not expected for queue');
|
|
859
|
+
},
|
|
860
|
+
forbidden: () => job.setErrorResult('Forbidden'),
|
|
861
|
+
});
|
|
862
|
+
return id;
|
|
863
|
+
}
|
|
864
|
+
mapQueuedAction(url, what) {
|
|
865
|
+
this.actions.set(url, what);
|
|
866
|
+
}
|
|
867
|
+
actions = new Map();
|
|
868
|
+
async getJobInfo(queuedJobId) {
|
|
869
|
+
return await this.storage.getJobInfo(queuedJobId);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
class InMemoryQueueStorage {
|
|
873
|
+
async getJobInfo(queuedJobId) {
|
|
874
|
+
return this.jobs.get(queuedJobId);
|
|
875
|
+
}
|
|
876
|
+
async createJob(url, userId) {
|
|
877
|
+
let id = this.jobs.size.toString();
|
|
878
|
+
this.jobs.set(id, {
|
|
879
|
+
info: {
|
|
880
|
+
done: false,
|
|
881
|
+
},
|
|
882
|
+
userId: userId,
|
|
883
|
+
setErrorResult: (error) => {
|
|
884
|
+
let job = this.jobs.get(id);
|
|
885
|
+
job.info.done = true;
|
|
886
|
+
job.info.error = error;
|
|
887
|
+
},
|
|
888
|
+
setResult: (result) => {
|
|
889
|
+
let job = this.jobs.get(id);
|
|
890
|
+
job.info.done = true;
|
|
891
|
+
job.info.result = result;
|
|
892
|
+
},
|
|
893
|
+
setProgress: (progress) => {
|
|
894
|
+
let job = this.jobs.get(id);
|
|
895
|
+
job.info.progress = progress;
|
|
896
|
+
},
|
|
897
|
+
});
|
|
898
|
+
return id;
|
|
899
|
+
}
|
|
900
|
+
jobs = new Map();
|
|
901
|
+
}
|
|
902
|
+
let test = 0;
|
|
903
|
+
export class EntityQueueStorage {
|
|
904
|
+
repo;
|
|
905
|
+
constructor(repo) {
|
|
906
|
+
this.repo = repo;
|
|
907
|
+
}
|
|
908
|
+
sync = Promise.resolve();
|
|
909
|
+
doSync(what) {
|
|
910
|
+
return (this.sync = this.sync.then(() => what()));
|
|
911
|
+
}
|
|
912
|
+
async getJobInfo(queuedJobId) {
|
|
913
|
+
let q = (await this.repo.findId(queuedJobId));
|
|
914
|
+
let lastProgress = undefined;
|
|
915
|
+
return {
|
|
916
|
+
userId: q.userId,
|
|
917
|
+
info: {
|
|
918
|
+
done: q.done,
|
|
919
|
+
error: q.error ? JSON.parse(q.result) : undefined,
|
|
920
|
+
result: q.done && !q.error ? JSON.parse(q.result) : undefined,
|
|
921
|
+
progress: q.progress,
|
|
922
|
+
},
|
|
923
|
+
setErrorResult: async (error) => {
|
|
924
|
+
await this.sync;
|
|
925
|
+
q.error = true;
|
|
926
|
+
q.done = true;
|
|
927
|
+
q.result = JSON.stringify(error);
|
|
928
|
+
q.doneTime = new Date();
|
|
929
|
+
q.progress = 1;
|
|
930
|
+
await this.doSync(() => q._.save());
|
|
931
|
+
},
|
|
932
|
+
setResult: async (result) => {
|
|
933
|
+
await this.sync;
|
|
934
|
+
q.done = true;
|
|
935
|
+
q.result = JSON.stringify(result);
|
|
936
|
+
q.doneTime = new Date();
|
|
937
|
+
await this.doSync(() => q._.save());
|
|
938
|
+
},
|
|
939
|
+
setProgress: async (progress) => {
|
|
940
|
+
if (progress === 0)
|
|
941
|
+
return;
|
|
942
|
+
let now = new Date();
|
|
943
|
+
if (lastProgress && now.valueOf() - lastProgress.valueOf() < 200)
|
|
944
|
+
return;
|
|
945
|
+
lastProgress = new Date();
|
|
946
|
+
await this.sync;
|
|
947
|
+
q.progress = progress;
|
|
948
|
+
await this.doSync(() => q._.save());
|
|
949
|
+
},
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
async createJob(url, userId) {
|
|
953
|
+
let q = this.repo.create();
|
|
954
|
+
q.userId = userId;
|
|
955
|
+
q.submitTime = new Date();
|
|
956
|
+
q.url = url;
|
|
957
|
+
await q._.save();
|
|
958
|
+
return q.id;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
export class RouteImplementation {
|
|
962
|
+
coreOptions;
|
|
963
|
+
constructor(coreOptions) {
|
|
964
|
+
this.coreOptions = coreOptions;
|
|
965
|
+
}
|
|
966
|
+
map = new Map();
|
|
967
|
+
starRoutes = [];
|
|
968
|
+
route(path) {
|
|
969
|
+
//consider using:
|
|
970
|
+
//* https://raw.githubusercontent.com/cmorten/opine/main/src/utils/pathToRegex.ts
|
|
971
|
+
//* https://github.com/pillarjs/path-to-regexp
|
|
972
|
+
let r = path.toLowerCase();
|
|
973
|
+
let m = new Map();
|
|
974
|
+
this.map.set(r, m);
|
|
975
|
+
if (path.endsWith('*'))
|
|
976
|
+
this.starRoutes.push({ route: r.substring(0, r.length - 1), handler: m });
|
|
977
|
+
const route = {
|
|
978
|
+
get: (h) => {
|
|
979
|
+
m.set('get', h);
|
|
980
|
+
return route;
|
|
981
|
+
},
|
|
982
|
+
put: (h) => {
|
|
983
|
+
m.set('put', h);
|
|
984
|
+
return route;
|
|
985
|
+
},
|
|
986
|
+
post: (h) => {
|
|
987
|
+
m.set('post', h);
|
|
988
|
+
return route;
|
|
989
|
+
},
|
|
990
|
+
delete: (h) => {
|
|
991
|
+
m.set('delete', h);
|
|
992
|
+
return route;
|
|
993
|
+
},
|
|
994
|
+
};
|
|
995
|
+
return route;
|
|
996
|
+
}
|
|
997
|
+
async handle(req, gRes) {
|
|
998
|
+
return new Promise((res, rej) => {
|
|
999
|
+
const response = new (class {
|
|
1000
|
+
write(data) {
|
|
1001
|
+
;
|
|
1002
|
+
gRes.write(data);
|
|
1003
|
+
}
|
|
1004
|
+
writeHead(statusCode, headers) {
|
|
1005
|
+
;
|
|
1006
|
+
gRes.writeHead(statusCode, headers);
|
|
1007
|
+
this.statusCode = statusCode;
|
|
1008
|
+
res({ statusCode });
|
|
1009
|
+
}
|
|
1010
|
+
flush() {
|
|
1011
|
+
if (isOfType(gRes, 'flush')) {
|
|
1012
|
+
gRes.flush();
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
statusCode = 200;
|
|
1016
|
+
json(data) {
|
|
1017
|
+
if (gRes !== undefined)
|
|
1018
|
+
gRes.json(data);
|
|
1019
|
+
res({ statusCode: this.statusCode, data });
|
|
1020
|
+
}
|
|
1021
|
+
send(html) {
|
|
1022
|
+
if (gRes !== undefined)
|
|
1023
|
+
gRes.send(html);
|
|
1024
|
+
res({ statusCode: this.statusCode, html });
|
|
1025
|
+
}
|
|
1026
|
+
status(statusCode) {
|
|
1027
|
+
if (gRes !== undefined)
|
|
1028
|
+
gRes.status(statusCode);
|
|
1029
|
+
this.statusCode = statusCode;
|
|
1030
|
+
return this;
|
|
1031
|
+
}
|
|
1032
|
+
end() {
|
|
1033
|
+
if (gRes !== undefined)
|
|
1034
|
+
gRes.end();
|
|
1035
|
+
res({
|
|
1036
|
+
statusCode: this.statusCode,
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
})();
|
|
1040
|
+
try {
|
|
1041
|
+
this.middleware(req, response, () => res(undefined));
|
|
1042
|
+
}
|
|
1043
|
+
catch (err) {
|
|
1044
|
+
rej(err);
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
middleware(origReq, res, next) {
|
|
1049
|
+
const req = this.coreOptions.buildGenericRequestInfo(origReq);
|
|
1050
|
+
let theUrl = req.url?.toString() || '';
|
|
1051
|
+
if (theUrl.startsWith('/'))
|
|
1052
|
+
//next sends a partial url '/api/tasks' and not the full url
|
|
1053
|
+
theUrl = 'http://stam' + theUrl;
|
|
1054
|
+
const url = new URL(theUrl);
|
|
1055
|
+
const path = url.pathname;
|
|
1056
|
+
if (!req.query) {
|
|
1057
|
+
let query = {};
|
|
1058
|
+
url.searchParams.forEach((val, key) => {
|
|
1059
|
+
let current = query[key];
|
|
1060
|
+
if (!current) {
|
|
1061
|
+
query[key] = val;
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
if (Array.isArray(current)) {
|
|
1065
|
+
current.push(val);
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
query[key] = [current, val];
|
|
1069
|
+
});
|
|
1070
|
+
origReq['_tempQuery'] = query;
|
|
1071
|
+
req.query = query;
|
|
1072
|
+
}
|
|
1073
|
+
let lowerPath = path.toLowerCase();
|
|
1074
|
+
let m = this.map.get(lowerPath);
|
|
1075
|
+
if (!m)
|
|
1076
|
+
for (const route of this.starRoutes) {
|
|
1077
|
+
if (lowerPath.startsWith(route.route)) {
|
|
1078
|
+
m = route.handler;
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (m) {
|
|
1083
|
+
let h = m.get(req.method.toLowerCase());
|
|
1084
|
+
if (h) {
|
|
1085
|
+
h(origReq, res, next);
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
let idPosition = path.lastIndexOf('/');
|
|
1090
|
+
if (idPosition >= 0) {
|
|
1091
|
+
lowerPath = lowerPath.substring(0, idPosition) + '/:id';
|
|
1092
|
+
m = this.map.get(lowerPath);
|
|
1093
|
+
if (m) {
|
|
1094
|
+
let h = m.get(req.method.toLowerCase());
|
|
1095
|
+
if (h) {
|
|
1096
|
+
if (!req.params) {
|
|
1097
|
+
req.params = {};
|
|
1098
|
+
origReq['_tempParams'] = req.params;
|
|
1099
|
+
}
|
|
1100
|
+
req.params.id = path.substring(idPosition + 1).replace(/%2C/g, ',');
|
|
1101
|
+
h(origReq, res, next);
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
next();
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
let JobsInQueueEntity = class JobsInQueueEntity extends IdEntity {
|
|
1110
|
+
userId = '';
|
|
1111
|
+
url = '';
|
|
1112
|
+
submitTime;
|
|
1113
|
+
doneTime;
|
|
1114
|
+
result = '';
|
|
1115
|
+
done = false;
|
|
1116
|
+
error = false;
|
|
1117
|
+
progress = 0;
|
|
1118
|
+
};
|
|
1119
|
+
__decorate([
|
|
1120
|
+
Fields.string(),
|
|
1121
|
+
__metadata("design:type", Object)
|
|
1122
|
+
], JobsInQueueEntity.prototype, "userId", void 0);
|
|
1123
|
+
__decorate([
|
|
1124
|
+
Fields.string(),
|
|
1125
|
+
__metadata("design:type", Object)
|
|
1126
|
+
], JobsInQueueEntity.prototype, "url", void 0);
|
|
1127
|
+
__decorate([
|
|
1128
|
+
Fields.date(),
|
|
1129
|
+
__metadata("design:type", Date)
|
|
1130
|
+
], JobsInQueueEntity.prototype, "submitTime", void 0);
|
|
1131
|
+
__decorate([
|
|
1132
|
+
Fields.date(),
|
|
1133
|
+
__metadata("design:type", Date)
|
|
1134
|
+
], JobsInQueueEntity.prototype, "doneTime", void 0);
|
|
1135
|
+
__decorate([
|
|
1136
|
+
Fields.string(),
|
|
1137
|
+
__metadata("design:type", Object)
|
|
1138
|
+
], JobsInQueueEntity.prototype, "result", void 0);
|
|
1139
|
+
__decorate([
|
|
1140
|
+
Fields.boolean(),
|
|
1141
|
+
__metadata("design:type", Object)
|
|
1142
|
+
], JobsInQueueEntity.prototype, "done", void 0);
|
|
1143
|
+
__decorate([
|
|
1144
|
+
Fields.boolean(),
|
|
1145
|
+
__metadata("design:type", Object)
|
|
1146
|
+
], JobsInQueueEntity.prototype, "error", void 0);
|
|
1147
|
+
__decorate([
|
|
1148
|
+
Fields.number(),
|
|
1149
|
+
__metadata("design:type", Object)
|
|
1150
|
+
], JobsInQueueEntity.prototype, "progress", void 0);
|
|
1151
|
+
JobsInQueueEntity = __decorate([
|
|
1152
|
+
Entity(undefined, {
|
|
1153
|
+
dbName: 'jobsInQueue',
|
|
1154
|
+
})
|
|
1155
|
+
], JobsInQueueEntity);
|
|
1156
|
+
export { JobsInQueueEntity };
|
|
1157
|
+
remultStatic.allEntities.splice(remultStatic.allEntities.indexOf(JobsInQueueEntity), 1);
|