remult 0.22.3 → 0.22.5
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/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/{src → esm/core/src}/backend-tests/my-test.backend-spec.d.ts +1 -1
- 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/{valueConverters.d.ts → esm/core/src/valueConverters.d.ts} +13 -12
- 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 +27 -27
- package/esm/postgres/schema-builder.js +4 -4
- package/esm/src/context.d.ts +6 -1
- package/esm/src/remult3/RepositoryImplementation.d.ts +1 -1
- package/esm/src/remult3/RepositoryImplementation.js +27 -4
- package/esm/src/shared-tests/db-tests.db-tests.js +57 -0
- 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/package.json +1 -1
- package/src/context.d.ts +6 -1
- package/src/remult3/RepositoryImplementation.d.ts +1 -1
- package/src/remult3/RepositoryImplementation.js +88 -63
- package/src/shared-tests/db-tests.db-tests.js +97 -0
- package/esm/src/id-entity.d.ts +0 -4
- package/esm/src/id-entity.js +0 -8
- package/postgres/postgresColumnSyntax.d.ts +0 -2
- package/postgres/postgresColumnSyntax.js +0 -34
- package/remult-middleware.d.ts +0 -2
- package/remult-middleware.js +0 -70
- package/server/register-actions-on-server.d.ts +0 -3
- package/server/register-actions-on-server.js +0 -50
- package/server/register-entities-on-server.d.ts +0 -3
- package/server/register-entities-on-server.js +0 -19
- package/src/backend-tests/my-test.backend-spec.js +0 -217
- package/src/backend-tests/test-http-server.backend-spec.d.ts +0 -6
- package/src/backend-tests/test-http-server.backend-spec.js +0 -342
- package/src/id-entity.d.ts +0 -4
- package/src/id-entity.js +0 -17
- package/valueConverters.js +0 -168
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RemultServer, RemultServerOptions, ServerCoreOptions } from './expressBridge';
|
|
2
|
+
export { queuedJobInfo, QueueStorage, GenericRequestInfo, GenericRequestHandler, RemultServerCore, GenericResponse, GenericRouter, RemultServerOptions, SpecificRoute, RemultServer, InitRequestOptions } from './expressBridge';
|
|
3
|
+
export { JsonEntityFileStorage, JsonFileDataProvider } from './JsonEntityFileStorage';
|
|
4
|
+
export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage';
|
|
5
|
+
export { SseSubscriptionServer } from '../SseSubscriptionServer';
|
|
6
|
+
export declare function createRemultServer<RequestType>(options: RemultServerOptions<RequestType>, serverCoreOptions?: ServerCoreOptions<RequestType>): RemultServer<RequestType>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createRemultServerCore, } from './expressBridge';
|
|
2
|
+
import { initAsyncHooks } from './initAsyncHooks';
|
|
3
|
+
export { JsonEntityFileStorage, JsonFileDataProvider } from './JsonEntityFileStorage';
|
|
4
|
+
export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage';
|
|
5
|
+
export { SseSubscriptionServer } from '../SseSubscriptionServer';
|
|
6
|
+
export function createRemultServer(options, serverCoreOptions) {
|
|
7
|
+
initAsyncHooks();
|
|
8
|
+
return createRemultServerCore(options, serverCoreOptions || { buildGenericRequestInfo: req => req, getRequestBody: async (req) => req.body });
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initAsyncHooks(): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
import { RemultAsyncLocalStorage } from '../src/context';
|
|
3
|
+
let init = false;
|
|
4
|
+
export function initAsyncHooks() {
|
|
5
|
+
if (init)
|
|
6
|
+
return;
|
|
7
|
+
init = true;
|
|
8
|
+
RemultAsyncLocalStorage.instance = new RemultAsyncLocalStorage(new AsyncLocalStorage());
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function initDataProvider(optionsDataProvider) {
|
|
2
|
+
let dataProvider;
|
|
3
|
+
if (typeof optionsDataProvider === "function") {
|
|
4
|
+
dataProvider = optionsDataProvider();
|
|
5
|
+
}
|
|
6
|
+
else
|
|
7
|
+
dataProvider = Promise.resolve(optionsDataProvider);
|
|
8
|
+
dataProvider = dataProvider.then(async (dp) => {
|
|
9
|
+
if (dp)
|
|
10
|
+
return dp;
|
|
11
|
+
return new (await import('./JsonEntityFileStorage')).JsonFileDataProvider('./db');
|
|
12
|
+
});
|
|
13
|
+
return dataProvider;
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface packedRowInfo {
|
|
2
|
+
data: any;
|
|
3
|
+
isNewRow: boolean;
|
|
4
|
+
id: string;
|
|
5
|
+
wasChanged: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface entityEventListener<entityType> {
|
|
8
|
+
deleted?: (entity: entityType) => void;
|
|
9
|
+
saved?: (entity: entityType, isNew: boolean) => void;
|
|
10
|
+
validating?: (entity: entityType) => Promise<any> | any;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { dbTestWhatSignature } from "../shared-tests/db-tests-setup";
|
|
2
|
+
export declare const testKnexPGSqlImpl: (key: string, what: dbTestWhatSignature, focus?: boolean) => void;
|
|
3
|
+
export declare const mySqlTest: import("../shared-tests/db-tests-setup").dbTestMethodSignature;
|
|
4
|
+
export declare function testPostgresImplementation(key: string, what: dbTestWhatSignature, focus?: boolean): void;
|
|
5
|
+
export declare function testMongo(key: string, what: dbTestWhatSignature, focus?: boolean): void;
|
|
6
|
+
import '../shared-tests';
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Remult } from "../context";
|
|
2
|
+
import { KnexDataProvider, KnexSchemaBuilder } from '../../remult-knex';
|
|
3
|
+
import * as Knex from 'knex';
|
|
4
|
+
import { MongoClient } from 'mongodb';
|
|
5
|
+
import { config } from 'dotenv';
|
|
6
|
+
import { createPostgresConnection, PostgresSchemaBuilder } from "../../postgres";
|
|
7
|
+
import { addDatabaseToTest, itWithFocus, testAll, TestDbs } from "../shared-tests/db-tests-setup";
|
|
8
|
+
import { describeClass } from "../remult3/DecoratorReplacer";
|
|
9
|
+
import { Entity, Fields } from "../remult3";
|
|
10
|
+
KnexSchemaBuilder.logToConsole = false;
|
|
11
|
+
PostgresSchemaBuilder.logToConsole = false;
|
|
12
|
+
config();
|
|
13
|
+
function testKnexSqlImpl(knex, name) {
|
|
14
|
+
return (key, what, focus = false) => {
|
|
15
|
+
itWithFocus(key + " " + name + " - knex", async () => {
|
|
16
|
+
let db = new KnexDataProvider(knex);
|
|
17
|
+
let remult = new Remult(db);
|
|
18
|
+
await what({
|
|
19
|
+
db, remult,
|
|
20
|
+
createEntity: async (entity) => {
|
|
21
|
+
let repo = remult.repo(entity);
|
|
22
|
+
await knex.schema.dropTableIfExists(await repo.metadata.getDbName());
|
|
23
|
+
await db.ensureSchema([repo.metadata]);
|
|
24
|
+
return repo;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}, focus);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export const testKnexPGSqlImpl = testKnexSqlImpl(Knex.default({
|
|
31
|
+
client: 'pg',
|
|
32
|
+
connection: process.env.DATABASE_URL,
|
|
33
|
+
//debug:true
|
|
34
|
+
}), "postgres");
|
|
35
|
+
addDatabaseToTest(testKnexPGSqlImpl);
|
|
36
|
+
if (process.env['TESTS_SQL_SERVER'])
|
|
37
|
+
addDatabaseToTest(testKnexSqlImpl(Knex.default({
|
|
38
|
+
client: 'mssql',
|
|
39
|
+
connection: {
|
|
40
|
+
server: '127.0.0.1',
|
|
41
|
+
database: 'test2',
|
|
42
|
+
user: 'sa',
|
|
43
|
+
password: 'MASTERKEY',
|
|
44
|
+
options: {
|
|
45
|
+
enableArithAbort: true,
|
|
46
|
+
encrypt: false,
|
|
47
|
+
instanceName: 'sqlexpress'
|
|
48
|
+
}
|
|
49
|
+
} //,debug: true
|
|
50
|
+
}), "sql server"));
|
|
51
|
+
if (true)
|
|
52
|
+
addDatabaseToTest(testKnexSqlImpl(Knex.default({
|
|
53
|
+
client: 'better-sqlite3',
|
|
54
|
+
connection: {
|
|
55
|
+
filename: ":memory:"
|
|
56
|
+
},
|
|
57
|
+
//debug: true
|
|
58
|
+
}), "sqlite3"));
|
|
59
|
+
export const mySqlTest = addDatabaseToTest(testKnexSqlImpl(Knex.default({
|
|
60
|
+
client: 'mysql2',
|
|
61
|
+
connection: {
|
|
62
|
+
user: 'root',
|
|
63
|
+
password: 'MASTERKEY',
|
|
64
|
+
host: '127.0.0.1',
|
|
65
|
+
database: 'test'
|
|
66
|
+
}
|
|
67
|
+
//debug: true
|
|
68
|
+
}), "mysql2"));
|
|
69
|
+
let pg = createPostgresConnection();
|
|
70
|
+
export function testPostgresImplementation(key, what, focus = false) {
|
|
71
|
+
itWithFocus(key + " - postgres", async () => {
|
|
72
|
+
let db = await pg;
|
|
73
|
+
let remult = new Remult(db);
|
|
74
|
+
await what({
|
|
75
|
+
db, remult,
|
|
76
|
+
createEntity: async (entity) => {
|
|
77
|
+
let repo = remult.repo(entity);
|
|
78
|
+
await db.execute("drop table if exists " + await repo.metadata.getDbName());
|
|
79
|
+
await db.ensureSchema([repo.metadata]);
|
|
80
|
+
return repo;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}, focus);
|
|
84
|
+
}
|
|
85
|
+
addDatabaseToTest(testPostgresImplementation);
|
|
86
|
+
import { Categories } from "../tests/remult-3-entities";
|
|
87
|
+
import { MongoDataProvider } from "../../remult-mongo";
|
|
88
|
+
testAll("transactions", async ({ db, createEntity }) => {
|
|
89
|
+
let x = await createEntity(Categories);
|
|
90
|
+
await db.transaction(async (db) => {
|
|
91
|
+
let remult = new Remult(db);
|
|
92
|
+
expect(await remult.repo(Categories).count()).toBe(0);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
const mongoConnectionString = process.env['MONGO_TEST_URL']; //"mongodb://localhost:27017/local"
|
|
96
|
+
let client = new MongoClient(mongoConnectionString);
|
|
97
|
+
let done;
|
|
98
|
+
let mongoDbPromise = client.connect().then(c => {
|
|
99
|
+
done = c;
|
|
100
|
+
return c.db("test");
|
|
101
|
+
});
|
|
102
|
+
afterAll(async () => {
|
|
103
|
+
if (done)
|
|
104
|
+
done.close();
|
|
105
|
+
});
|
|
106
|
+
export function testMongo(key, what, focus = false) {
|
|
107
|
+
itWithFocus(key + " - mongo", async () => {
|
|
108
|
+
let mongoDb = await mongoDbPromise;
|
|
109
|
+
let db = new MongoDataProvider(mongoDb, client);
|
|
110
|
+
let remult = new Remult(db);
|
|
111
|
+
await what({
|
|
112
|
+
db, remult,
|
|
113
|
+
createEntity: async (entity) => {
|
|
114
|
+
let repo = remult.repo(entity);
|
|
115
|
+
await mongoDb.collection(await repo.metadata.getDbName()).deleteMany({});
|
|
116
|
+
return repo;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}, focus);
|
|
120
|
+
}
|
|
121
|
+
addDatabaseToTest(testMongo, TestDbs.mongo);
|
|
122
|
+
it("test mongo without transaction", async () => {
|
|
123
|
+
const client = new MongoClient("mongodb://localhost:27017/local");
|
|
124
|
+
await client.connect();
|
|
125
|
+
const mongoDb = client.db('test');
|
|
126
|
+
const db = new MongoDataProvider(mongoDb, client, { disableTransactions: true });
|
|
127
|
+
var remult = new Remult(db);
|
|
128
|
+
const entity = class {
|
|
129
|
+
id = 0;
|
|
130
|
+
title = '';
|
|
131
|
+
};
|
|
132
|
+
describeClass(entity, Entity("testNoTrans"), { id: Fields.number(), title: Fields.string() });
|
|
133
|
+
const repo = remult.repo(entity);
|
|
134
|
+
for (const item of await repo.find()) {
|
|
135
|
+
await repo.delete(item);
|
|
136
|
+
}
|
|
137
|
+
await repo.insert({ id: 1, title: "a" });
|
|
138
|
+
try {
|
|
139
|
+
await db.transaction(async () => {
|
|
140
|
+
await repo.insert({ id: 2, title: "b" });
|
|
141
|
+
throw new Error();
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
catch { }
|
|
145
|
+
expect(await repo.count()).toBe(2);
|
|
146
|
+
});
|
|
147
|
+
import '../shared-tests';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { Remult } from "../context";
|
|
2
|
+
import { Entity, Fields } from "../remult3";
|
|
3
|
+
import { KnexDataProvider } from '../../remult-knex';
|
|
4
|
+
import { config } from 'dotenv';
|
|
5
|
+
import { testKnexPGSqlImpl, testMongo, testPostgresImplementation } from "./backend-database-test-setup.backend-spec";
|
|
6
|
+
import { entityWithValidations } from "../shared-tests/entityWithValidations";
|
|
7
|
+
import { PostgresDataProvider } from "../../postgres";
|
|
8
|
+
import { MongoDataProvider } from "../../remult-mongo";
|
|
9
|
+
import { SqlDatabase } from "../data-providers/sql-database";
|
|
10
|
+
import { dbNamesOf } from "../filter/filter-consumer-bridge-to-sql-request";
|
|
11
|
+
import { RemultAsyncLocalStorage } from "../../src/context";
|
|
12
|
+
import { remult } from "../remult-proxy";
|
|
13
|
+
import { describeClass } from "../remult3/DecoratorReplacer";
|
|
14
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
15
|
+
config();
|
|
16
|
+
testPostgresImplementation("default order by", async ({ createEntity }) => {
|
|
17
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
18
|
+
await s.update(1, { name: "updated name" });
|
|
19
|
+
expect((await s.find()).map(x => x.myId)).toEqual([1, 2, 3, 4]);
|
|
20
|
+
}, false);
|
|
21
|
+
testKnexPGSqlImpl("default order by", async ({ createEntity }) => {
|
|
22
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
23
|
+
await s.update(1, { name: "updated name" });
|
|
24
|
+
expect((await s.find()).map(x => x.myId)).toEqual([1, 2, 3, 4]);
|
|
25
|
+
}, false);
|
|
26
|
+
testPostgresImplementation("sql filter", async ({ createEntity }) => {
|
|
27
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
28
|
+
expect((await s.find({
|
|
29
|
+
where: SqlDatabase.rawFilter(async (build) => {
|
|
30
|
+
build.sql = s.metadata.fields.myId.options.dbName + ' in (1,3)';
|
|
31
|
+
})
|
|
32
|
+
})).length).toBe(2);
|
|
33
|
+
}, false);
|
|
34
|
+
testPostgresImplementation("sql filter2", async ({ createEntity }) => {
|
|
35
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
36
|
+
expect((await s.find({
|
|
37
|
+
where: {
|
|
38
|
+
$or: [
|
|
39
|
+
SqlDatabase.rawFilter(async (build) => {
|
|
40
|
+
build.sql = s.metadata.fields.myId.options.dbName + ' in (1,3)';
|
|
41
|
+
}),
|
|
42
|
+
{
|
|
43
|
+
myId: 2
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
})).length).toBe(3);
|
|
48
|
+
}, false);
|
|
49
|
+
testKnexPGSqlImpl("knex filter", async ({ createEntity }) => {
|
|
50
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
51
|
+
expect((await s.find({
|
|
52
|
+
where: KnexDataProvider.rawFilter(async () => {
|
|
53
|
+
return build => build.whereIn(s.metadata.fields.myId.options.dbName, [1, 3]);
|
|
54
|
+
})
|
|
55
|
+
})).length).toBe(2);
|
|
56
|
+
}, false);
|
|
57
|
+
testKnexPGSqlImpl("knex filter2", async ({ createEntity }) => {
|
|
58
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
59
|
+
expect((await s.find({
|
|
60
|
+
where: {
|
|
61
|
+
$or: [KnexDataProvider.rawFilter(async () => {
|
|
62
|
+
return build => build.whereIn(s.metadata.fields.myId.options.dbName, [1, 3]);
|
|
63
|
+
}), {
|
|
64
|
+
myId: 4
|
|
65
|
+
}]
|
|
66
|
+
}
|
|
67
|
+
})).length).toBe(3);
|
|
68
|
+
}, false);
|
|
69
|
+
testPostgresImplementation("ensure schema with dbNames that have quotes", async ({ remult }) => {
|
|
70
|
+
const db = SqlDatabase.getDb(remult);
|
|
71
|
+
const entityName = 'test_naming';
|
|
72
|
+
await db.execute("Drop table if exists " + entityName);
|
|
73
|
+
await db.execute(`create table ${entityName}(id int,"createdAt" Date)`);
|
|
74
|
+
const ent = class {
|
|
75
|
+
id = 0;
|
|
76
|
+
createdAt = new Date();
|
|
77
|
+
oneMoreColumn = 0;
|
|
78
|
+
};
|
|
79
|
+
describeClass(ent, Entity(entityName), {
|
|
80
|
+
id: Fields.integer(),
|
|
81
|
+
createdAt: Fields.createdAt({ dbName: '"createdAt"' }),
|
|
82
|
+
oneMoreColumn: Fields.integer()
|
|
83
|
+
});
|
|
84
|
+
await db.ensureSchema([remult.repo(ent).metadata]);
|
|
85
|
+
await remult.repo(ent).insert({ id: 1, oneMoreColumn: 8 });
|
|
86
|
+
expect((await remult.repo(ent).findFirst()).createdAt.getFullYear()).toBe(new Date().getFullYear());
|
|
87
|
+
}, false);
|
|
88
|
+
testPostgresImplementation("work with native sql", async ({ remult, createEntity }) => {
|
|
89
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
90
|
+
const sql = SqlDatabase.getDb(remult);
|
|
91
|
+
const r = await sql.execute("select count(*) as c from " + repo.metadata.options.dbName);
|
|
92
|
+
expect(r.rows[0].c).toBe('4');
|
|
93
|
+
}, false);
|
|
94
|
+
testPostgresImplementation("work with native sql2", async ({ remult, createEntity }) => {
|
|
95
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
96
|
+
const sql = PostgresDataProvider.getDb(remult);
|
|
97
|
+
const r = await sql.query("select count(*) as c from " + repo.metadata.options.dbName);
|
|
98
|
+
expect(r.rows[0].c).toBe('4');
|
|
99
|
+
}, false);
|
|
100
|
+
testPostgresImplementation("work with native sql3", async ({ remult, createEntity }) => {
|
|
101
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
102
|
+
await SqlDatabase.getDb(remult)._getSourceSql().transaction(async (x) => {
|
|
103
|
+
const sql = PostgresDataProvider.getDb(new Remult(new SqlDatabase(x)));
|
|
104
|
+
const r = await sql.query("select count(*) as c from " + repo.metadata.options.dbName);
|
|
105
|
+
expect(r.rows[0].c).toBe('4');
|
|
106
|
+
});
|
|
107
|
+
}, false);
|
|
108
|
+
testKnexPGSqlImpl("work with native knex", async ({ remult, createEntity }) => {
|
|
109
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
110
|
+
const knex = KnexDataProvider.getDb(remult);
|
|
111
|
+
const r = await knex(repo.metadata.options.dbName).count();
|
|
112
|
+
expect(r[0].count).toBe('4');
|
|
113
|
+
}, false);
|
|
114
|
+
testKnexPGSqlImpl("work with native knex2", async ({ remult, createEntity }) => {
|
|
115
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
116
|
+
await (remult.dataProvider).transaction(async (db) => {
|
|
117
|
+
const sql = KnexDataProvider.getDb(new Remult(db));
|
|
118
|
+
const r = await sql(repo.metadata.options.dbName).count();
|
|
119
|
+
expect(r[0].count).toBe('4');
|
|
120
|
+
});
|
|
121
|
+
}, false);
|
|
122
|
+
testKnexPGSqlImpl("work with native knex3", async ({ remult, createEntity }) => {
|
|
123
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
124
|
+
const knex = KnexDataProvider.getDb(remult);
|
|
125
|
+
const t = await dbNamesOf(repo);
|
|
126
|
+
const r = await knex((await t).$entityName).select(t.myId, t.name);
|
|
127
|
+
expect(r.length).toBe(4);
|
|
128
|
+
}, false);
|
|
129
|
+
testMongo("work with native mongo", async ({ remult, createEntity }) => {
|
|
130
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
131
|
+
const mongo = MongoDataProvider.getDb(remult);
|
|
132
|
+
const r = await (await mongo.db.collection(repo.metadata.options.dbName)).countDocuments();
|
|
133
|
+
expect(r).toBe(4);
|
|
134
|
+
}, false);
|
|
135
|
+
testKnexPGSqlImpl("knex with filter", async ({ remult, createEntity }) => {
|
|
136
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
137
|
+
const knex = KnexDataProvider.getDb(remult);
|
|
138
|
+
const e = await dbNamesOf(repo);
|
|
139
|
+
const r = await knex(e.$entityName).count().where(await KnexDataProvider.filterToRaw(repo, { myId: [1, 3] }));
|
|
140
|
+
expect(r[0].count).toBe('2');
|
|
141
|
+
}, false);
|
|
142
|
+
testMongo("work with native mongo and condition", async ({ remult, createEntity }) => {
|
|
143
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
144
|
+
const mongo = MongoDataProvider.getDb(remult);
|
|
145
|
+
const r = await (await mongo.db.collection(repo.metadata.options.dbName)).countDocuments(await MongoDataProvider.filterToRaw(repo, { myId: [1, 2] }));
|
|
146
|
+
expect(r).toBe(2);
|
|
147
|
+
}, false);
|
|
148
|
+
it("test async hooks and static remult", async () => {
|
|
149
|
+
let gotException = true;
|
|
150
|
+
try {
|
|
151
|
+
RemultAsyncLocalStorage.instance.getRemult();
|
|
152
|
+
gotException = false;
|
|
153
|
+
}
|
|
154
|
+
catch { }
|
|
155
|
+
expect(gotException).toBe(true);
|
|
156
|
+
RemultAsyncLocalStorage.instance = new RemultAsyncLocalStorage(new AsyncLocalStorage());
|
|
157
|
+
try {
|
|
158
|
+
expect(RemultAsyncLocalStorage.instance.getRemult()).toBe(undefined);
|
|
159
|
+
RemultAsyncLocalStorage.enable();
|
|
160
|
+
try {
|
|
161
|
+
remult.isAllowed(false);
|
|
162
|
+
gotException = false;
|
|
163
|
+
}
|
|
164
|
+
catch { }
|
|
165
|
+
expect(gotException).toBe(true);
|
|
166
|
+
const promises = [];
|
|
167
|
+
RemultAsyncLocalStorage.instance.run(new Remult(), () => {
|
|
168
|
+
remult.user = { id: 'noam' };
|
|
169
|
+
promises.push(new Promise(res => {
|
|
170
|
+
setTimeout(() => {
|
|
171
|
+
expect(remult.user.id).toBe('noam');
|
|
172
|
+
res({});
|
|
173
|
+
}, 10);
|
|
174
|
+
}));
|
|
175
|
+
RemultAsyncLocalStorage.instance.run(new Remult(), () => {
|
|
176
|
+
remult.user = { id: 'yoni' };
|
|
177
|
+
promises.push(new Promise(res => {
|
|
178
|
+
setTimeout(() => {
|
|
179
|
+
expect(remult.user.id).toBe('yoni');
|
|
180
|
+
res({});
|
|
181
|
+
}, 10);
|
|
182
|
+
}));
|
|
183
|
+
});
|
|
184
|
+
promises.push(new Promise(res => {
|
|
185
|
+
setTimeout(() => {
|
|
186
|
+
expect(remult.user.id).toBe('noam');
|
|
187
|
+
res({});
|
|
188
|
+
}, 10);
|
|
189
|
+
}));
|
|
190
|
+
});
|
|
191
|
+
await Promise.all(promises);
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
RemultAsyncLocalStorage.disable();
|
|
195
|
+
RemultAsyncLocalStorage.instance = new RemultAsyncLocalStorage(undefined);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { remult } from '../remult-proxy';
|
|
3
|
+
import { Categories } from '../tests/remult-3-entities';
|
|
4
|
+
import { Task } from '../../../test-servers/shared/Task';
|
|
5
|
+
import { remultFresh } from '../../remult-fresh';
|
|
6
|
+
import { InMemoryDataProvider } from '../data-providers/in-memory-database';
|
|
7
|
+
import { RemultAsyncLocalStorage } from '../context';
|
|
8
|
+
const servers = {
|
|
9
|
+
koa: "koa",
|
|
10
|
+
fastify: "fastify",
|
|
11
|
+
express: "express",
|
|
12
|
+
mw: "mw",
|
|
13
|
+
fresh: "fresh",
|
|
14
|
+
mwc: "mwc",
|
|
15
|
+
svelteKit: 'svelteKit',
|
|
16
|
+
nextApp: "nextApp"
|
|
17
|
+
};
|
|
18
|
+
remult.apiClient.url = 'http://localhost:3003/api';
|
|
19
|
+
let path = remult.apiClient.url + '/tasks';
|
|
20
|
+
const environments = [
|
|
21
|
+
// ["optine", 3006],
|
|
22
|
+
//["nest", 3001],
|
|
23
|
+
// ["next", 3000],
|
|
24
|
+
// [servers.nextApp, 3010],
|
|
25
|
+
// [servers.koa, 3002],
|
|
26
|
+
// [servers.fastify, 3003],
|
|
27
|
+
// [servers.express, 3004],
|
|
28
|
+
// [servers.mw, 3005],
|
|
29
|
+
// [servers.mwc, 3007],
|
|
30
|
+
// [servers.fresh, 8000],
|
|
31
|
+
// [servers.svelteKit, 5173],
|
|
32
|
+
];
|
|
33
|
+
function test(name, test, ...ignoreList) {
|
|
34
|
+
for (const [env, port] of environments) {
|
|
35
|
+
if (ignoreList?.includes(env))
|
|
36
|
+
continue;
|
|
37
|
+
const theTest = async () => {
|
|
38
|
+
remult.apiClient.url = `http://localhost:${port}/api`;
|
|
39
|
+
path = remult.apiClient.url + '/tasks';
|
|
40
|
+
await test();
|
|
41
|
+
};
|
|
42
|
+
const testName = env + ` ${port}: ${name}`;
|
|
43
|
+
fit(testName, theTest);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
test("works", async () => {
|
|
47
|
+
const repo = await create3Tasks();
|
|
48
|
+
const tasks = await repo.find({ where: { completed: true } });
|
|
49
|
+
expect(tasks.length).toBe(1);
|
|
50
|
+
await repo.save({ ...tasks[0], completed: false });
|
|
51
|
+
expect(await repo.count({ completed: true })).toBe(0);
|
|
52
|
+
});
|
|
53
|
+
test("test multiple items", async () => {
|
|
54
|
+
const repo = await create3Tasks();
|
|
55
|
+
expect(await repo.count({
|
|
56
|
+
title: { "!=": ["a", "c"] }
|
|
57
|
+
})).toBe(1);
|
|
58
|
+
});
|
|
59
|
+
test("validation", async () => {
|
|
60
|
+
const r = await create3Tasks();
|
|
61
|
+
let err = undefined;
|
|
62
|
+
try {
|
|
63
|
+
await r.insert({ "title": "" });
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
err = error;
|
|
67
|
+
}
|
|
68
|
+
expect(err).toEqual({
|
|
69
|
+
message: "Title: Should not be empty",
|
|
70
|
+
httpStatusCode: 400,
|
|
71
|
+
modelState: {
|
|
72
|
+
title: "Should not be empty"
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
test("forbidden", async () => {
|
|
77
|
+
let err = undefined;
|
|
78
|
+
try {
|
|
79
|
+
await Task.testForbidden();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
err = error;
|
|
83
|
+
}
|
|
84
|
+
expect(err.httpStatusCode).toEqual(403);
|
|
85
|
+
});
|
|
86
|
+
test("test static remult", async () => {
|
|
87
|
+
const r = await create3Tasks();
|
|
88
|
+
expect(await Task.testStaticRemult()).toBe(3);
|
|
89
|
+
}, servers.fresh, servers.mwc);
|
|
90
|
+
test("test injected remult", async () => {
|
|
91
|
+
const r = await create3Tasks();
|
|
92
|
+
expect(await Task.testInjectedRemult()).toBe(3);
|
|
93
|
+
});
|
|
94
|
+
test("test http 404", async () => {
|
|
95
|
+
const repo = create3Tasks();
|
|
96
|
+
const task = await (await repo).findFirst();
|
|
97
|
+
let result = await axios.get(path + "/" + task.id);
|
|
98
|
+
expect(result.data.id).toBe(task.id);
|
|
99
|
+
expect(result.status).toBe(200);
|
|
100
|
+
let error = undefined;
|
|
101
|
+
try {
|
|
102
|
+
result = await axios.get(path + "/123");
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
error = err;
|
|
106
|
+
}
|
|
107
|
+
expect(error.response.status).toBe(404);
|
|
108
|
+
});
|
|
109
|
+
test("test http 201", async () => {
|
|
110
|
+
let result = await axios.post(path, { title: "z", id: "" });
|
|
111
|
+
expect(result.data.title).toBe("z");
|
|
112
|
+
expect(result.status).toBe(201);
|
|
113
|
+
result = await axios.delete(path + "/" + result.data.id);
|
|
114
|
+
expect(result.status).toBe(204);
|
|
115
|
+
});
|
|
116
|
+
test("test regular api call", async () => {
|
|
117
|
+
await create3Tasks();
|
|
118
|
+
let result = await axios.get(remult.apiClient.url + "/test");
|
|
119
|
+
expect(result.data.result).toBe(3);
|
|
120
|
+
});
|
|
121
|
+
class FreshResponseTest {
|
|
122
|
+
body;
|
|
123
|
+
init;
|
|
124
|
+
constructor(body, init) {
|
|
125
|
+
this.body = body;
|
|
126
|
+
this.init = init;
|
|
127
|
+
}
|
|
128
|
+
static json(data, init) {
|
|
129
|
+
return new this(data, init);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
it("test fresh", async () => {
|
|
133
|
+
try {
|
|
134
|
+
const api = remultFresh({
|
|
135
|
+
entities: [Categories],
|
|
136
|
+
dataProvider: new InMemoryDataProvider(),
|
|
137
|
+
rootPath: '/api',
|
|
138
|
+
logApiEndPoints: false
|
|
139
|
+
}, FreshResponseTest);
|
|
140
|
+
const r = await api.handle({
|
|
141
|
+
url: '/api/Categories',
|
|
142
|
+
json() {
|
|
143
|
+
return undefined;
|
|
144
|
+
},
|
|
145
|
+
method: "get"
|
|
146
|
+
}, {
|
|
147
|
+
next() {
|
|
148
|
+
return undefined;
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
expect(r.body).toEqual([]);
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
RemultAsyncLocalStorage.disable();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
async function create3Tasks() {
|
|
158
|
+
remult.apiClient.httpClient = axios;
|
|
159
|
+
const taskRepo = remult.repo(Task);
|
|
160
|
+
for (const task of await taskRepo.find()) {
|
|
161
|
+
await taskRepo.delete(task);
|
|
162
|
+
}
|
|
163
|
+
expect(await taskRepo.count()).toBe(0);
|
|
164
|
+
await taskRepo.insert([{ title: "a" }, { title: "b", completed: true }, { title: "c" }]);
|
|
165
|
+
expect(await taskRepo.count()).toBe(3);
|
|
166
|
+
return taskRepo;
|
|
167
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RestDataProviderHttpProvider } from "./data-interfaces";
|
|
2
|
+
import { RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider';
|
|
3
|
+
export declare function buildRestDataProvider(provider: ExternalHttpProvider | typeof fetch): RestDataProviderHttpProviderUsingFetch | RestDataProviderHttpProvider;
|
|
4
|
+
export declare function isExternalHttpProvider(item: any): boolean;
|
|
5
|
+
export declare class HttpProviderBridgeToRestDataProviderHttpProvider implements RestDataProviderHttpProvider {
|
|
6
|
+
private http;
|
|
7
|
+
constructor(http: ExternalHttpProvider);
|
|
8
|
+
post(url: string, data: any): Promise<any>;
|
|
9
|
+
delete(url: string): Promise<void>;
|
|
10
|
+
put(url: string, data: any): Promise<any>;
|
|
11
|
+
get(url: string): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
export declare function retry<T>(what: () => Promise<T>): Promise<T>;
|
|
14
|
+
export declare function toPromise<T>(p: Promise<T> | {
|
|
15
|
+
toPromise(): Promise<T>;
|
|
16
|
+
}): Promise<any>;
|
|
17
|
+
export declare function processHttpException(ex: any): Promise<any>;
|
|
18
|
+
export interface ExternalHttpProvider {
|
|
19
|
+
post(url: string, data: any): Promise<any> | {
|
|
20
|
+
toPromise(): Promise<any>;
|
|
21
|
+
};
|
|
22
|
+
delete(url: string): Promise<void> | {
|
|
23
|
+
toPromise(): Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
put(url: string, data: any): Promise<any> | {
|
|
26
|
+
toPromise(): Promise<any>;
|
|
27
|
+
};
|
|
28
|
+
get(url: string): Promise<any> | {
|
|
29
|
+
toPromise(): Promise<any>;
|
|
30
|
+
};
|
|
31
|
+
}
|