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,810 @@
|
|
|
1
|
+
import { DataApi } from "../data-api";
|
|
2
|
+
import { Fields, Entity, EntityBase, Field, IdEntity } from "../remult3";
|
|
3
|
+
import { c } from "../tests/c";
|
|
4
|
+
import { Done } from "../tests/Done";
|
|
5
|
+
import { h } from "../tests/h";
|
|
6
|
+
import { Categories as newCategories } from "../tests/remult-3-entities";
|
|
7
|
+
import { tasks } from "../tests/tasks";
|
|
8
|
+
import { TestDataApiResponse } from "../tests/TestDataApiResponse";
|
|
9
|
+
import { testAll, testAllDbs, TestDbs } from "./db-tests-setup";
|
|
10
|
+
import { entityWithValidations, testConfiguration } from "./entityWithValidations";
|
|
11
|
+
import { Remult } from "../context";
|
|
12
|
+
import { dWithPrefilter } from "../tests/dWithPrefilter";
|
|
13
|
+
import { entityFilterToJson, Filter } from "../filter/filter-interfaces";
|
|
14
|
+
import { d } from "../tests/d";
|
|
15
|
+
import { entityForrawFilter1 } from "../tests/entityForCustomFilter";
|
|
16
|
+
import { entityWithValidationsOnColumn } from "../tests/entityWithValidationsOnColumn";
|
|
17
|
+
import { Validators } from "../validators";
|
|
18
|
+
import { Status } from "../tests/testModel/models";
|
|
19
|
+
import { describeClass } from "../remult3/DecoratorReplacer";
|
|
20
|
+
import { DataProviderLiveQueryStorage, LiveQueryStorageEntity } from "../../live-query/data-provider-live-query-storage";
|
|
21
|
+
import { v4 as uuid } from 'uuid';
|
|
22
|
+
testAll("what", async ({ remult, createEntity }) => {
|
|
23
|
+
await (await createEntity(stam)).create({ id: 1, title: 'noam' }).save();
|
|
24
|
+
expect(await remult.repo(stam).count()).toBe(1);
|
|
25
|
+
}, false);
|
|
26
|
+
testAll("data types", async ({ remult, createEntity }) => {
|
|
27
|
+
let r = await (await createEntity(stam)).create({
|
|
28
|
+
id: 1,
|
|
29
|
+
//@ts-ignore
|
|
30
|
+
title: 42
|
|
31
|
+
}).save();
|
|
32
|
+
expect(r.title).toEqual("42");
|
|
33
|
+
}, false);
|
|
34
|
+
testAll("filter works on all db", async ({ createEntity }) => {
|
|
35
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
36
|
+
expect((await s.find({ where: { myId: [1, 3] } })).length).toBe(2);
|
|
37
|
+
}, false);
|
|
38
|
+
testAll("test in statement and ", async ({ createEntity }) => {
|
|
39
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
40
|
+
expect(await repo.count({ myId: [1, 3], $and: [{ myId: [3] }] })).toBe(1);
|
|
41
|
+
}, false);
|
|
42
|
+
testAll("filter with and", async ({ createEntity }) => {
|
|
43
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
44
|
+
expect((await s.find({ where: { $and: [{ myId: 1 }, { myId: 3 }] } })).length).toBe(0);
|
|
45
|
+
}, false);
|
|
46
|
+
testAll("test empty in", async ({ createEntity }) => {
|
|
47
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
48
|
+
expect((await s.find({ where: { myId: [] } })).length).toBe(0);
|
|
49
|
+
}, false);
|
|
50
|
+
testAll("filter works on all db or", async ({ createEntity }) => {
|
|
51
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
52
|
+
expect((await s.find({ where: { $or: [{ myId: 1 }, { myId: 3 }] } })).length).toBe(2);
|
|
53
|
+
}, false);
|
|
54
|
+
testAll("filter works on all db or_1", async ({ createEntity }) => {
|
|
55
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
56
|
+
expect((await s.find({ where: { $or: [{}, {}] } })).length).toBe(4);
|
|
57
|
+
}, false);
|
|
58
|
+
testAll("filter works on all db or_2", async ({ createEntity }) => {
|
|
59
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
60
|
+
expect((await s.find({ where: { $or: [{}, { myId: 3 }] } })).length).toBe(4);
|
|
61
|
+
}, false);
|
|
62
|
+
testAll("entity with different id column still works well", async ({ createEntity }) => {
|
|
63
|
+
let s = await createEntity(entityWithValidations);
|
|
64
|
+
let c = s.create();
|
|
65
|
+
c.myId = 1;
|
|
66
|
+
c.name = 'noam';
|
|
67
|
+
await c._.save();
|
|
68
|
+
c.name = 'yael';
|
|
69
|
+
await c._.save();
|
|
70
|
+
expect(c.name).toBe('yael');
|
|
71
|
+
expect((await s.find()).length).toBe(1);
|
|
72
|
+
}, false);
|
|
73
|
+
testAll("empty find works", async ({ remult, createEntity }) => {
|
|
74
|
+
let c = (await createEntity(newCategories)).create();
|
|
75
|
+
c.id = 5;
|
|
76
|
+
c.categoryName = 'test';
|
|
77
|
+
await c._.save();
|
|
78
|
+
let l = await remult.repo(newCategories).find();
|
|
79
|
+
expect(l.length).toBe(1);
|
|
80
|
+
expect(l[0].categoryName).toBe('test');
|
|
81
|
+
}, false);
|
|
82
|
+
testAll("test descending", async ({ createEntity }) => {
|
|
83
|
+
const repo = await createEntity(newCategories);
|
|
84
|
+
await repo.create({ id: 1, categoryName: 'a' }).save();
|
|
85
|
+
await repo.create({ id: 2, categoryName: 'b' }).save();
|
|
86
|
+
const rows = await repo.find({
|
|
87
|
+
orderBy: { categoryName: 'desc' },
|
|
88
|
+
page: -1
|
|
89
|
+
});
|
|
90
|
+
expect(rows[0].id).toBe(2);
|
|
91
|
+
}, false);
|
|
92
|
+
testAll("test descending 2", async ({ createEntity }) => {
|
|
93
|
+
const repo = await createEntity(newCategories);
|
|
94
|
+
await repo.insert([{ id: 1, categoryName: 'a' }, { id: 2, categoryName: 'b' }]);
|
|
95
|
+
const rows = await repo.find({
|
|
96
|
+
orderBy: { categoryName: 'desc' },
|
|
97
|
+
page: -1
|
|
98
|
+
});
|
|
99
|
+
expect(rows[0].id).toBe(2);
|
|
100
|
+
}, false);
|
|
101
|
+
testAll("partial updates", async ({ remult, createEntity }) => {
|
|
102
|
+
let c = (await createEntity(newCategories)).create({
|
|
103
|
+
id: 5, categoryName: 'test', description: 'desc'
|
|
104
|
+
});
|
|
105
|
+
await c._.save();
|
|
106
|
+
let l = await remult.repo(newCategories).findId(5);
|
|
107
|
+
c.categoryName = 'newname';
|
|
108
|
+
l.description = 'new desc';
|
|
109
|
+
await c.save();
|
|
110
|
+
await l.save();
|
|
111
|
+
expect(l.categoryName).toBe('newname');
|
|
112
|
+
expect(l.description).toBe('new desc');
|
|
113
|
+
}, false);
|
|
114
|
+
testAll("put with validations on entity fails", async ({ remult, createEntity }) => {
|
|
115
|
+
let s = await createEntity(entityWithValidations);
|
|
116
|
+
let c = s.create();
|
|
117
|
+
c.myId = 1;
|
|
118
|
+
c.name = 'noam';
|
|
119
|
+
await c._.save();
|
|
120
|
+
let api = new DataApi(s, remult);
|
|
121
|
+
let t = new TestDataApiResponse();
|
|
122
|
+
let d = new Done();
|
|
123
|
+
t.error = async (data) => {
|
|
124
|
+
expect(data.modelState.name).toBe('invalid');
|
|
125
|
+
d.ok();
|
|
126
|
+
};
|
|
127
|
+
await api.put(t, 1, {
|
|
128
|
+
name: '1'
|
|
129
|
+
});
|
|
130
|
+
d.test();
|
|
131
|
+
var x = await s.find({ where: { myId: 1 } });
|
|
132
|
+
expect(x[0].name).toBe('noam');
|
|
133
|
+
x = await s.find({ where: { myId: 1 } });
|
|
134
|
+
expect(x[0].name).toBe('noam');
|
|
135
|
+
});
|
|
136
|
+
testAll("test date only with null works", async ({ createEntity }) => {
|
|
137
|
+
let repo = await createEntity(testDateWithNull);
|
|
138
|
+
let r = repo.create({ id: 0 });
|
|
139
|
+
await r.save();
|
|
140
|
+
r = await repo.findFirst();
|
|
141
|
+
expect(r.d).toBeNull();
|
|
142
|
+
expect(await repo.count({ d: null })).toBe(1);
|
|
143
|
+
r.d = new Date(1976, 5, 16);
|
|
144
|
+
await r.save();
|
|
145
|
+
expect(r.d.getFullYear()).toBe(1976);
|
|
146
|
+
r = await repo.findFirst();
|
|
147
|
+
expect(r.d.getFullYear()).toBe(1976);
|
|
148
|
+
r.d = null;
|
|
149
|
+
await r.save();
|
|
150
|
+
expect(r.d).toBeNull();
|
|
151
|
+
}, false);
|
|
152
|
+
testAll("test date with null works", async ({ createEntity }) => {
|
|
153
|
+
let repo = await createEntity(testDateWithNull);
|
|
154
|
+
let r = repo.create({ id: 0 });
|
|
155
|
+
await r.save();
|
|
156
|
+
r = await repo.findFirst();
|
|
157
|
+
expect(r.fullDate).toBeNull("expected null after");
|
|
158
|
+
expect(await repo.count({ fullDate: null })).toBe(1);
|
|
159
|
+
r.fullDate = new Date(1976, 5, 16);
|
|
160
|
+
await r.save();
|
|
161
|
+
expect(r.fullDate.getFullYear()).toBe(1976);
|
|
162
|
+
r = await repo.findFirst();
|
|
163
|
+
expect(r.fullDate.getFullYear()).toBe(1976);
|
|
164
|
+
r.fullDate = null;
|
|
165
|
+
await r.save();
|
|
166
|
+
expect(r.fullDate).toBeNull();
|
|
167
|
+
}, false);
|
|
168
|
+
testAll("test original value of date", async ({ createEntity }) => {
|
|
169
|
+
let r = await (await createEntity(testDateWithNull)).create({ id: 1, d: new Date(1976, 6, 16) }).save();
|
|
170
|
+
expect(r.$.d.originalValue.getFullYear()).toBe(1976);
|
|
171
|
+
});
|
|
172
|
+
@Entity('testDateWithNull', { allowApiCrud: true })
|
|
173
|
+
class testDateWithNull extends EntityBase {
|
|
174
|
+
@Fields.integer()
|
|
175
|
+
id = 0;
|
|
176
|
+
@Fields.dateOnly({ allowNull: true })
|
|
177
|
+
d;
|
|
178
|
+
@Fields.date({ allowNull: true })
|
|
179
|
+
fullDate = null;
|
|
180
|
+
}
|
|
181
|
+
testAll("test string with null works", async ({ createEntity }) => {
|
|
182
|
+
let repo = await createEntity(testStringWithNull);
|
|
183
|
+
let r = repo.create({ id: 0 });
|
|
184
|
+
await r.save();
|
|
185
|
+
r = await repo.findFirst();
|
|
186
|
+
expect(r.d).toBeNull();
|
|
187
|
+
});
|
|
188
|
+
testAll("test tasks", async ({ createEntity }) => {
|
|
189
|
+
let c = await createEntity(tasks);
|
|
190
|
+
let t = c.create();
|
|
191
|
+
t.id = 1;
|
|
192
|
+
await t._.save();
|
|
193
|
+
t = c.create();
|
|
194
|
+
t.id = 2;
|
|
195
|
+
t.completed = true;
|
|
196
|
+
await t._.save();
|
|
197
|
+
t = c.create();
|
|
198
|
+
t.id = 3;
|
|
199
|
+
t.completed = true;
|
|
200
|
+
await t._.save();
|
|
201
|
+
await c.create({ id: 4, completed: false }).save();
|
|
202
|
+
expect(await c.count({ completed: false })).toBe(2);
|
|
203
|
+
expect(await c.count({ completed: { $ne: true } })).toBe(2);
|
|
204
|
+
expect(await c.count({ completed: true })).toBe(2);
|
|
205
|
+
}, false);
|
|
206
|
+
testAll("test filtering of null/''", async ({ createEntity }) => {
|
|
207
|
+
let repo = await createEntity(h);
|
|
208
|
+
let a = await repo.create({ id: 'a' }).save();
|
|
209
|
+
let b = await repo.create({ id: 'b' }).save();
|
|
210
|
+
let c = await repo.create({ id: 'c', refH: b }).save();
|
|
211
|
+
expect(await repo.count({ refH: null })).toBe(2);
|
|
212
|
+
expect(await repo.count({ refH: { "!=": null } })).toBe(1);
|
|
213
|
+
}, false);
|
|
214
|
+
testAll("test paging with complex object", async ({ remult, createEntity }) => {
|
|
215
|
+
await createEntity(c);
|
|
216
|
+
await createEntity(p);
|
|
217
|
+
let c1 = await remult.repo(c).create({ id: 1, name: 'c1' }).save();
|
|
218
|
+
let c2 = await remult.repo(c).create({ id: 2, name: 'c2' }).save();
|
|
219
|
+
let c3 = await remult.repo(c).create({ id: 3, name: 'c3' }).save();
|
|
220
|
+
await remult.repo(p).create({ id: 1, name: 'p1', c: c1 }).save();
|
|
221
|
+
await remult.repo(p).create({ id: 2, name: 'p2', c: c2 }).save();
|
|
222
|
+
await remult.repo(p).create({ id: 3, name: 'p3', c: c3 }).save();
|
|
223
|
+
await remult.repo(p).create({ id: 4, name: 'p4', c: c3 }).save();
|
|
224
|
+
await remult.repo(p).create({ id: 5, name: 'p5', c: c3 }).save();
|
|
225
|
+
let i = 0;
|
|
226
|
+
for await (const x of remult.repo(p).query({
|
|
227
|
+
orderBy: { c: "asc", id: "asc" }
|
|
228
|
+
})) {
|
|
229
|
+
i++;
|
|
230
|
+
}
|
|
231
|
+
expect(i).toBe(5);
|
|
232
|
+
}, false);
|
|
233
|
+
testAll("test paging with complex object_2", async ({ remult, createEntity }) => {
|
|
234
|
+
let c1 = await (await createEntity(c)).create({ id: 1, name: 'c1' }).save();
|
|
235
|
+
await (await createEntity(p)).create({ id: 1, name: 'p1', c: c1 }).save();
|
|
236
|
+
expect((await remult.repo(p).findFirst({ c: c1 })).id).toBe(1);
|
|
237
|
+
});
|
|
238
|
+
testAll("test filter doesn't collapse", async ({ createEntity }) => {
|
|
239
|
+
let repo = await createEntity(dWithPrefilter);
|
|
240
|
+
let d1 = await repo.create({ id: 1, b: 1 }).save();
|
|
241
|
+
await repo.create({ id: 2, b: 2 }).save();
|
|
242
|
+
let d4 = await repo.create({ id: 4, b: 2 }).save();
|
|
243
|
+
let f = { id: 1, $and: [{ id: 2 }] };
|
|
244
|
+
expect(await repo.count(f)).toBe(0);
|
|
245
|
+
expect((await repo.find({ where: f })).length).toBe(0);
|
|
246
|
+
let json = Filter.entityFilterToJson(repo.metadata, f);
|
|
247
|
+
f = Filter.entityFilterFromJson(repo.metadata, json);
|
|
248
|
+
expect(await repo.count(f)).toBe(0);
|
|
249
|
+
expect((await repo.find({ where: f })).length).toBe(0);
|
|
250
|
+
});
|
|
251
|
+
testAll("test filter doesn't collapse", async ({ createEntity }) => {
|
|
252
|
+
let repo = await createEntity(d);
|
|
253
|
+
let d1 = await repo.create({ id: 1, b: 1 }).save();
|
|
254
|
+
await repo.create({ id: 2, b: 2 }).save();
|
|
255
|
+
let d4 = await repo.create({ id: 4, b: 2 }).save();
|
|
256
|
+
let f = { id: [1, 2] };
|
|
257
|
+
expect(await repo.count(f)).toBe(2);
|
|
258
|
+
expect((await repo.find({ where: f })).length).toBe(2);
|
|
259
|
+
let json = Filter.entityFilterToJson(repo.metadata, f);
|
|
260
|
+
f = Filter.entityFilterFromJson(repo.metadata, json);
|
|
261
|
+
expect(await repo.count(f)).toBe(2);
|
|
262
|
+
expect((await repo.find({ where: f })).length).toBe(2);
|
|
263
|
+
});
|
|
264
|
+
testAll("test that it works with inheritance", async ({ createEntity }) => {
|
|
265
|
+
let c = await createEntity(entityForrawFilter1);
|
|
266
|
+
for (let id = 0; id < 5; id++) {
|
|
267
|
+
await c.create({ id }).save();
|
|
268
|
+
}
|
|
269
|
+
expect(await (c.count(entityForrawFilter1.oneAndThree()))).toBe(2);
|
|
270
|
+
expect((await (c.findFirst(entityForrawFilter1.testNumericValue(2)))).id).toBe(2);
|
|
271
|
+
expect((await (c.findFirst(entityForrawFilter1.testObjectValue({ val: 2 })))).id).toBe(2);
|
|
272
|
+
});
|
|
273
|
+
testAll("put with validations on column fails", async ({ remult, createEntity }) => {
|
|
274
|
+
var s = await createEntity(entityWithValidationsOnColumn);
|
|
275
|
+
let c = s.create();
|
|
276
|
+
c.myId = 1;
|
|
277
|
+
c.name = 'noam';
|
|
278
|
+
await c._.save();
|
|
279
|
+
let api = new DataApi(s, remult);
|
|
280
|
+
let t = new TestDataApiResponse();
|
|
281
|
+
let d = new Done();
|
|
282
|
+
t.error = async (data) => {
|
|
283
|
+
expect(data.modelState.name).toBe('invalid on column');
|
|
284
|
+
d.ok();
|
|
285
|
+
};
|
|
286
|
+
await api.put(t, 1, {
|
|
287
|
+
name: '1'
|
|
288
|
+
});
|
|
289
|
+
d.test();
|
|
290
|
+
var x = await s.find({ where: { myId: 1 } });
|
|
291
|
+
expect(x[0].name).toBe('noam');
|
|
292
|
+
});
|
|
293
|
+
testAllDbs("Insert", async ({ createData }) => {
|
|
294
|
+
let forCat = await createData(async (x) => { });
|
|
295
|
+
let rows = await forCat.find();
|
|
296
|
+
expect(rows.length).toBe(0);
|
|
297
|
+
let c = forCat.create();
|
|
298
|
+
c.id = 1;
|
|
299
|
+
c.categoryName = 'noam';
|
|
300
|
+
await c._.save();
|
|
301
|
+
rows = await forCat.find();
|
|
302
|
+
expect(rows.length).toBe(1);
|
|
303
|
+
expect(rows[0].id).toBe(1);
|
|
304
|
+
expect(rows[0].categoryName).toBe('noam');
|
|
305
|
+
}, false);
|
|
306
|
+
testAllDbs("test delete", async ({ createData }) => {
|
|
307
|
+
let c = await createData(async (insert) => await insert(5, 'noam'));
|
|
308
|
+
let rows = await c.find();
|
|
309
|
+
expect(rows.length).toBe(1);
|
|
310
|
+
expect(rows[0].id).toBe(5);
|
|
311
|
+
await rows[0]._.delete();
|
|
312
|
+
rows = await c.find();
|
|
313
|
+
expect(rows.length).toBe(0);
|
|
314
|
+
}, false);
|
|
315
|
+
testAllDbs("test filter packer", async ({ insertFourRows }) => {
|
|
316
|
+
let r = await insertFourRows();
|
|
317
|
+
let rows = await r.find();
|
|
318
|
+
expect(rows.length).toBe(4);
|
|
319
|
+
rows = await r.find({
|
|
320
|
+
where: Filter.entityFilterFromJson(r.metadata, entityFilterToJson(r.metadata, { description: 'x' }))
|
|
321
|
+
});
|
|
322
|
+
expect(rows.length).toBe(2);
|
|
323
|
+
rows = await r.find({ where: Filter.entityFilterFromJson(r.metadata, entityFilterToJson(r.metadata, { id: 4 })) });
|
|
324
|
+
expect(rows.length).toBe(1);
|
|
325
|
+
expect(rows[0].categoryName).toBe('yael');
|
|
326
|
+
rows = await r.find({ where: Filter.entityFilterFromJson(r.metadata, entityFilterToJson(r.metadata, { description: 'y', categoryName: 'yoni' })) });
|
|
327
|
+
expect(rows.length).toBe(1);
|
|
328
|
+
expect(rows[0].id).toBe(2);
|
|
329
|
+
rows = await r.find({ where: Filter.entityFilterFromJson(r.metadata, entityFilterToJson(r.metadata, { id: { $ne: [2, 4] } })) });
|
|
330
|
+
expect(rows.length).toBe(2);
|
|
331
|
+
}, false);
|
|
332
|
+
testAll("Test unique Validation,", async ({ createEntity }) => {
|
|
333
|
+
let type = class extends newCategories {
|
|
334
|
+
a;
|
|
335
|
+
};
|
|
336
|
+
Entity('categories')(type);
|
|
337
|
+
Fields.string({
|
|
338
|
+
validate: async (en, col) => {
|
|
339
|
+
if (en._.isNew() || en.a != en._.fields.a.originalValue) {
|
|
340
|
+
if (await c.count({ a: en.a }))
|
|
341
|
+
en._.fields.a.error = 'already exists';
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
})(type.prototype, "a");
|
|
345
|
+
var c = await createEntity(type);
|
|
346
|
+
var cat = c.create();
|
|
347
|
+
cat.a = '12';
|
|
348
|
+
cat.id = 1;
|
|
349
|
+
await cat._.save();
|
|
350
|
+
cat = c.create();
|
|
351
|
+
cat.a = '12';
|
|
352
|
+
var saved = false;
|
|
353
|
+
try {
|
|
354
|
+
await cat._.save();
|
|
355
|
+
saved = true;
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
expect(cat._.fields.a.error).toEqual("already exists");
|
|
359
|
+
}
|
|
360
|
+
expect(saved).toBe(false);
|
|
361
|
+
});
|
|
362
|
+
testAll("Test unique Validation 2", async ({ createEntity }) => {
|
|
363
|
+
let type = class extends newCategories {
|
|
364
|
+
a;
|
|
365
|
+
};
|
|
366
|
+
Entity('sdfgds')(type);
|
|
367
|
+
Fields.string({
|
|
368
|
+
validate: Validators.unique
|
|
369
|
+
})(type.prototype, "a");
|
|
370
|
+
var c = await createEntity(type);
|
|
371
|
+
var cat = c.create();
|
|
372
|
+
cat.a = '12';
|
|
373
|
+
await cat._.save();
|
|
374
|
+
cat = c.create();
|
|
375
|
+
cat.a = '12';
|
|
376
|
+
var saved = false;
|
|
377
|
+
try {
|
|
378
|
+
await cat._.save();
|
|
379
|
+
saved = true;
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
expect(cat._.fields.a.error).toEqual("already exists");
|
|
383
|
+
}
|
|
384
|
+
expect(saved).toBe(false);
|
|
385
|
+
});
|
|
386
|
+
@Entity('testNumbers', { allowApiCrud: true })
|
|
387
|
+
class testNumbers extends EntityBase {
|
|
388
|
+
@Fields.integer()
|
|
389
|
+
id;
|
|
390
|
+
@Fields.number()
|
|
391
|
+
a;
|
|
392
|
+
}
|
|
393
|
+
testAll("test that integer and int work", async ({ createEntity }) => {
|
|
394
|
+
let e = await (await createEntity(testNumbers)).create({
|
|
395
|
+
id: 1.5,
|
|
396
|
+
a: 1.5
|
|
397
|
+
}).save();
|
|
398
|
+
expect(e.id).toBe(2);
|
|
399
|
+
expect(e.a).toBe(1.5);
|
|
400
|
+
});
|
|
401
|
+
testAll("post with logic works and max in entity", async ({ remult, createEntity }) => {
|
|
402
|
+
let c = await createEntity(entityWithValidations);
|
|
403
|
+
var api = new DataApi(c, remult);
|
|
404
|
+
let t = new TestDataApiResponse();
|
|
405
|
+
let d = new Done();
|
|
406
|
+
t.created = async (data) => {
|
|
407
|
+
expect(data.name).toBe('noam honig');
|
|
408
|
+
expect(data.myId).toBe(1);
|
|
409
|
+
d.ok();
|
|
410
|
+
};
|
|
411
|
+
entityWithValidations.savingRowCount = 0;
|
|
412
|
+
await api.post(t, { name: 'noam honig', myId: 1 });
|
|
413
|
+
expect(entityWithValidations.savingRowCount).toBe(1);
|
|
414
|
+
d.test();
|
|
415
|
+
});
|
|
416
|
+
testAllDbs("get array works with filter in body", async ({ createData, remult }) => {
|
|
417
|
+
let c = await createData(async (i) => {
|
|
418
|
+
await i(1, 'noam', undefined, Status.open);
|
|
419
|
+
await i(2, 'yael', undefined, Status.closed);
|
|
420
|
+
await i(3, 'yoni', undefined, Status.hold);
|
|
421
|
+
});
|
|
422
|
+
var api = new DataApi(c, remult);
|
|
423
|
+
let t = new TestDataApiResponse();
|
|
424
|
+
let d = new Done();
|
|
425
|
+
t.success = data => {
|
|
426
|
+
expect(data.length).toBe(2);
|
|
427
|
+
expect(data[0].id).toBe(2);
|
|
428
|
+
expect(data[1].id).toBe(3);
|
|
429
|
+
d.ok();
|
|
430
|
+
};
|
|
431
|
+
await api.getArray(t, {
|
|
432
|
+
get: x => {
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
}, {
|
|
436
|
+
"status.in": '[1, 2]'
|
|
437
|
+
});
|
|
438
|
+
d.test();
|
|
439
|
+
}, false);
|
|
440
|
+
testAllDbs("entity order by works", async ({ createData }) => {
|
|
441
|
+
let type = class extends newCategories {
|
|
442
|
+
};
|
|
443
|
+
Entity('', {
|
|
444
|
+
defaultOrderBy: { categoryName: "asc" },
|
|
445
|
+
})(type);
|
|
446
|
+
let c = await createData(async (insert) => {
|
|
447
|
+
await insert(1, 'noam');
|
|
448
|
+
await insert(2, "yoni");
|
|
449
|
+
await insert(3, "yael");
|
|
450
|
+
}, type);
|
|
451
|
+
var x = await c.find();
|
|
452
|
+
expect(x[0].id).toBe(1);
|
|
453
|
+
expect(x[1].id).toBe(3);
|
|
454
|
+
expect(x[2].id).toBe(2);
|
|
455
|
+
var x = await c.find({ orderBy: {} });
|
|
456
|
+
expect(x[0].id).toBe(1);
|
|
457
|
+
expect(x[1].id).toBe(3);
|
|
458
|
+
expect(x[2].id).toBe(2);
|
|
459
|
+
var x = (await c.query({ orderBy: {}, pageSize: 100 }).paginator()).items;
|
|
460
|
+
expect(x[0].id).toBe(1);
|
|
461
|
+
expect(x[1].id).toBe(3);
|
|
462
|
+
expect(x[2].id).toBe(2);
|
|
463
|
+
}, false);
|
|
464
|
+
testAllDbs("put with validation works", async ({ createData, remult }) => {
|
|
465
|
+
let count = 0;
|
|
466
|
+
let type = class extends newCategories {
|
|
467
|
+
};
|
|
468
|
+
Entity(undefined, {
|
|
469
|
+
allowApiCrud: true,
|
|
470
|
+
saving: () => {
|
|
471
|
+
if (!testConfiguration.restDbRunningOnServer)
|
|
472
|
+
count++;
|
|
473
|
+
}
|
|
474
|
+
})(type);
|
|
475
|
+
let c = await createData(async (insert) => await insert(1, 'noam'), type);
|
|
476
|
+
var api = new DataApi(c, remult);
|
|
477
|
+
let t = new TestDataApiResponse();
|
|
478
|
+
let d = new Done();
|
|
479
|
+
t.success = async (data) => {
|
|
480
|
+
d.ok();
|
|
481
|
+
};
|
|
482
|
+
count = 0;
|
|
483
|
+
await api.put(t, 1, {
|
|
484
|
+
categoryName: 'noam 1'
|
|
485
|
+
});
|
|
486
|
+
d.test();
|
|
487
|
+
var x = await c.find({
|
|
488
|
+
where: { id: 1 }
|
|
489
|
+
});
|
|
490
|
+
expect(x[0].categoryName).toBe('noam 1');
|
|
491
|
+
expect(count).toBe(1);
|
|
492
|
+
});
|
|
493
|
+
testAll("saves correctly to db", async ({ createEntity }) => {
|
|
494
|
+
let type = class extends EntityBase {
|
|
495
|
+
id;
|
|
496
|
+
ok = false;
|
|
497
|
+
};
|
|
498
|
+
Entity('asdf', { allowApiCrud: true })(type);
|
|
499
|
+
Fields.number()(type.prototype, 'id');
|
|
500
|
+
Fields.boolean()(type.prototype, "ok");
|
|
501
|
+
let r = (await createEntity(type)).create();
|
|
502
|
+
r.id = 1;
|
|
503
|
+
r.ok = true;
|
|
504
|
+
await r._.save();
|
|
505
|
+
expect(r.ok).toBe(true);
|
|
506
|
+
r.ok = false;
|
|
507
|
+
await r._.save();
|
|
508
|
+
expect(r.ok).toBe(false);
|
|
509
|
+
});
|
|
510
|
+
@Entity("autoi", { allowApiCrud: true })
|
|
511
|
+
class autoIncrement extends EntityBase {
|
|
512
|
+
@Fields.autoIncrement()
|
|
513
|
+
id;
|
|
514
|
+
@Fields.integer()
|
|
515
|
+
stam;
|
|
516
|
+
}
|
|
517
|
+
testAll("auto increment can't be affected by insert or update", async ({ createEntity }) => {
|
|
518
|
+
let repo = await createEntity(autoIncrement);
|
|
519
|
+
let r = await repo.create({ id: 1234, stam: 1 }).save();
|
|
520
|
+
let x = r.id;
|
|
521
|
+
expect(x == 1234).toBe(false);
|
|
522
|
+
r.id = 4321;
|
|
523
|
+
await r.save();
|
|
524
|
+
expect(r.id).toBe(x);
|
|
525
|
+
}, false);
|
|
526
|
+
testAll("Paging", async ({ createEntity }) => {
|
|
527
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
528
|
+
expect((await s.find({ limit: 3, orderBy: { myId: "asc" } })).length).toBe(3);
|
|
529
|
+
expect((await s.find({ limit: 3, orderBy: { myId: "asc" }, page: 2 })).length).toBe(1);
|
|
530
|
+
}, false);
|
|
531
|
+
testAll("filter", async ({ createEntity }) => {
|
|
532
|
+
const s = await createEntity(testFilter);
|
|
533
|
+
await s.insert({ id: 1, a: 'a', b: 'b', c: 'c' });
|
|
534
|
+
expect(await s.count({
|
|
535
|
+
a: 'z',
|
|
536
|
+
$and: [testFilter.search('')]
|
|
537
|
+
})).toBe(0);
|
|
538
|
+
}, false);
|
|
539
|
+
testAll("large string field", async ({ createEntity }) => {
|
|
540
|
+
const s = await createEntity(stam);
|
|
541
|
+
await s.insert({ title: "1234567890".repeat(100) });
|
|
542
|
+
const r = await s.findFirst();
|
|
543
|
+
expect(r.title).toBe("1234567890".repeat(100));
|
|
544
|
+
}, false);
|
|
545
|
+
@Entity("testfilter", { allowApiCrud: true })
|
|
546
|
+
class testFilter {
|
|
547
|
+
@Fields.integer()
|
|
548
|
+
id = 0;
|
|
549
|
+
@Fields.string()
|
|
550
|
+
a = '';
|
|
551
|
+
@Fields.string()
|
|
552
|
+
b = '';
|
|
553
|
+
@Fields.string()
|
|
554
|
+
c = '';
|
|
555
|
+
static search = Filter.createCustom((str, remult) => ({
|
|
556
|
+
$and: [{
|
|
557
|
+
$or: [
|
|
558
|
+
{ a: 'a' },
|
|
559
|
+
{ b: 'a' },
|
|
560
|
+
{ c: 'a' }
|
|
561
|
+
]
|
|
562
|
+
}]
|
|
563
|
+
}));
|
|
564
|
+
}
|
|
565
|
+
@Entity('teststringWithNull', { allowApiCrud: true })
|
|
566
|
+
class testStringWithNull extends EntityBase {
|
|
567
|
+
@Fields.integer()
|
|
568
|
+
id = 0;
|
|
569
|
+
@Fields.string({ allowNull: true })
|
|
570
|
+
d;
|
|
571
|
+
}
|
|
572
|
+
@Entity("a", { allowApiCrud: true })
|
|
573
|
+
export class stam extends EntityBase {
|
|
574
|
+
@Fields.integer()
|
|
575
|
+
id = 0;
|
|
576
|
+
@Fields.string({ maxLength: 1500 })
|
|
577
|
+
title = '';
|
|
578
|
+
}
|
|
579
|
+
@Entity('p', { allowApiCrud: true })
|
|
580
|
+
class p extends EntityBase {
|
|
581
|
+
remult;
|
|
582
|
+
@Fields.integer()
|
|
583
|
+
id;
|
|
584
|
+
@Fields.string()
|
|
585
|
+
name;
|
|
586
|
+
@Field(() => c)
|
|
587
|
+
c;
|
|
588
|
+
constructor(remult) {
|
|
589
|
+
super();
|
|
590
|
+
this.remult = remult;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
@Entity('tasksWithEnum', {
|
|
594
|
+
allowApiCrud: true
|
|
595
|
+
})
|
|
596
|
+
export class tasksWithEnum extends IdEntity {
|
|
597
|
+
@Fields.string()
|
|
598
|
+
title = '';
|
|
599
|
+
@Fields.boolean()
|
|
600
|
+
completed = false;
|
|
601
|
+
@Fields.object()
|
|
602
|
+
priority = Priority.Low;
|
|
603
|
+
}
|
|
604
|
+
export var Priority;
|
|
605
|
+
(function (Priority) {
|
|
606
|
+
Priority[Priority["Low"] = 0] = "Low";
|
|
607
|
+
Priority[Priority["High"] = 1] = "High";
|
|
608
|
+
Priority[Priority["Critical"] = 2] = "Critical";
|
|
609
|
+
})(Priority || (Priority = {}));
|
|
610
|
+
testAll("task with enum", async ({ createEntity }) => {
|
|
611
|
+
const r = await createEntity(tasksWithEnum);
|
|
612
|
+
await r.insert({
|
|
613
|
+
title: 'a',
|
|
614
|
+
priority: Priority.Critical
|
|
615
|
+
});
|
|
616
|
+
const item = await r.findFirst();
|
|
617
|
+
expect(item.priority).toBe(Priority.Critical);
|
|
618
|
+
expect(await r.count({ priority: Priority.Critical })).toBe(1);
|
|
619
|
+
expect(await r.count({ priority: Priority.Low })).toBe(0);
|
|
620
|
+
});
|
|
621
|
+
@Entity('tasksWithStringEnum', {
|
|
622
|
+
allowApiCrud: true
|
|
623
|
+
})
|
|
624
|
+
export class tasksWithStringEnum extends IdEntity {
|
|
625
|
+
@Fields.string()
|
|
626
|
+
title = '';
|
|
627
|
+
@Fields.boolean()
|
|
628
|
+
completed = false;
|
|
629
|
+
@Fields.object()
|
|
630
|
+
priority = PriorityWithString.Low;
|
|
631
|
+
}
|
|
632
|
+
export var PriorityWithString;
|
|
633
|
+
(function (PriorityWithString) {
|
|
634
|
+
PriorityWithString["Low"] = "Low";
|
|
635
|
+
PriorityWithString["High"] = "High";
|
|
636
|
+
PriorityWithString["Critical"] = "Critical";
|
|
637
|
+
})(PriorityWithString || (PriorityWithString = {}));
|
|
638
|
+
testAll("task with enum string", async ({ createEntity }) => {
|
|
639
|
+
const r = await createEntity(tasksWithStringEnum);
|
|
640
|
+
await r.insert({
|
|
641
|
+
title: 'a',
|
|
642
|
+
priority: PriorityWithString.Critical
|
|
643
|
+
});
|
|
644
|
+
const item = await r.findFirst();
|
|
645
|
+
expect(item.priority).toBe(PriorityWithString.Critical);
|
|
646
|
+
expect(await r.count({ priority: PriorityWithString.Critical })).toBe(1);
|
|
647
|
+
expect(await r.count({ priority: PriorityWithString.Low })).toBe(0);
|
|
648
|
+
});
|
|
649
|
+
testAll("test transaction rollback", async ({ db, createEntity }) => {
|
|
650
|
+
let fail = true;
|
|
651
|
+
const r = await createEntity(stam);
|
|
652
|
+
await r.insert({ title: "task b", id: 1 });
|
|
653
|
+
try {
|
|
654
|
+
await db.transaction(async (db) => {
|
|
655
|
+
var remultWithTransaction = new Remult(db).repo(stam);
|
|
656
|
+
await remultWithTransaction.insert({ title: "task a", id: 2 });
|
|
657
|
+
expect(await remultWithTransaction.count()).toBe(2);
|
|
658
|
+
throw "error";
|
|
659
|
+
});
|
|
660
|
+
fail = false;
|
|
661
|
+
}
|
|
662
|
+
catch {
|
|
663
|
+
}
|
|
664
|
+
expect(await r.count()).toBe(1);
|
|
665
|
+
expect(fail).toBe(true);
|
|
666
|
+
}, false, { exclude: [TestDbs.inMemory] });
|
|
667
|
+
testAll("test date", async ({ createEntity }) => {
|
|
668
|
+
const e = class {
|
|
669
|
+
a = 0;
|
|
670
|
+
d = new Date();
|
|
671
|
+
};
|
|
672
|
+
describeClass(e, Entity("tdate", { allowApiCrud: true }), {
|
|
673
|
+
a: Fields.number(),
|
|
674
|
+
d: Fields.date()
|
|
675
|
+
});
|
|
676
|
+
const r = await createEntity(e);
|
|
677
|
+
await r.insert({ a: 1, d: new Date(1976, 5, 16) });
|
|
678
|
+
let item = await r.findFirst();
|
|
679
|
+
expect(item.d.getFullYear()).toBe(1976);
|
|
680
|
+
}, false);
|
|
681
|
+
testAll("test live query storage", async ({ db, remult, createEntity }) => {
|
|
682
|
+
await createEntity(LiveQueryStorageEntity);
|
|
683
|
+
var x = new DataProviderLiveQueryStorage(db);
|
|
684
|
+
if (db.ensureSchema)
|
|
685
|
+
await x.ensureSchema();
|
|
686
|
+
const id = uuid();
|
|
687
|
+
await x.add({ id, entityKey: 'x', data: "noam" });
|
|
688
|
+
await x.forEach("x", async (args) => {
|
|
689
|
+
expect(args.query.data).toBe("noam");
|
|
690
|
+
});
|
|
691
|
+
expect((await x.keepAliveAndReturnUnknownQueryIds([id]))).toEqual([]);
|
|
692
|
+
}, false, {
|
|
693
|
+
exclude: [TestDbs.restDataProvider]
|
|
694
|
+
});
|
|
695
|
+
testAll("test contains with names with casing", async ({ createEntity }) => {
|
|
696
|
+
const e = class {
|
|
697
|
+
a = 0;
|
|
698
|
+
firstName = '';
|
|
699
|
+
};
|
|
700
|
+
describeClass(e, Entity("testNameContains", { allowApiCrud: true }), {
|
|
701
|
+
a: Fields.number(),
|
|
702
|
+
firstName: Fields.string()
|
|
703
|
+
});
|
|
704
|
+
const r = await createEntity(e);
|
|
705
|
+
await r.insert({ a: 1, firstName: "noam" });
|
|
706
|
+
let item = await r.findFirst({ firstName: { $contains: "oa" } });
|
|
707
|
+
expect(item.firstName).toBe("noam");
|
|
708
|
+
}, false, {
|
|
709
|
+
exclude: [TestDbs.mongo]
|
|
710
|
+
});
|
|
711
|
+
testAll("test live query storage", async (x) => {
|
|
712
|
+
await x.createEntity(LiveQueryStorageEntity);
|
|
713
|
+
const s = new DataProviderLiveQueryStorage(x.db);
|
|
714
|
+
await s.ensureSchema();
|
|
715
|
+
const entityKey = "ek";
|
|
716
|
+
const id = 'id';
|
|
717
|
+
await s.add({ id, entityKey, data: {} });
|
|
718
|
+
await s.add({ id, entityKey, data: {} });
|
|
719
|
+
x.remult.clearAllCache();
|
|
720
|
+
await s.add({ id, entityKey, data: {} });
|
|
721
|
+
await s.keepAliveAndReturnUnknownQueryIds([id]);
|
|
722
|
+
await s.remove(id);
|
|
723
|
+
await s.remove(id);
|
|
724
|
+
}, false, { exclude: [TestDbs.restDataProvider] });
|
|
725
|
+
testAll("test json structure using object", async ({ createEntity }) => {
|
|
726
|
+
const e = class {
|
|
727
|
+
a = 0;
|
|
728
|
+
person;
|
|
729
|
+
};
|
|
730
|
+
describeClass(e, Entity("testJsonStructure", { allowApiCrud: true }), {
|
|
731
|
+
a: Fields.number(),
|
|
732
|
+
person: Fields.object()
|
|
733
|
+
});
|
|
734
|
+
const r = await createEntity(e);
|
|
735
|
+
await r.insert({ a: 1, person: { firstName: "noam", lastName: "honig" } });
|
|
736
|
+
let item = await r.findFirst();
|
|
737
|
+
expect(item.person).toEqual({ firstName: "noam", lastName: "honig" });
|
|
738
|
+
}, false);
|
|
739
|
+
@Entity("testObject", { allowApiCrud: true })
|
|
740
|
+
class testObject {
|
|
741
|
+
@Fields.integer()
|
|
742
|
+
id = 0;
|
|
743
|
+
@Fields.object()
|
|
744
|
+
person = { firstName: "noam", lastName: "honig" };
|
|
745
|
+
}
|
|
746
|
+
testAll("test object entity", async ({ createEntity }) => {
|
|
747
|
+
const r = await createEntity(testObject);
|
|
748
|
+
await r.insert({ id: 1, person: { firstName: "noam", lastName: "honig" } });
|
|
749
|
+
let item = await r.findFirst();
|
|
750
|
+
expect(item.person).toEqual({ firstName: "noam", lastName: "honig" });
|
|
751
|
+
}, false);
|
|
752
|
+
@Entity("testObjectJson", { allowApiCrud: true })
|
|
753
|
+
class testObjectJson {
|
|
754
|
+
@Fields.integer()
|
|
755
|
+
id = 0;
|
|
756
|
+
@Fields.json()
|
|
757
|
+
person = { firstName: "noam", lastName: "honig" };
|
|
758
|
+
}
|
|
759
|
+
testAll("test object entity", async ({ createEntity }) => {
|
|
760
|
+
const r = await createEntity(testObjectJson);
|
|
761
|
+
await r.insert({ id: 1, person: { firstName: "noam", lastName: "honig" } });
|
|
762
|
+
let item = await r.findFirst();
|
|
763
|
+
expect(item.person).toEqual({ firstName: "noam", lastName: "honig" });
|
|
764
|
+
}, false);
|
|
765
|
+
testAll("test json structure", async ({ createEntity }) => {
|
|
766
|
+
const e = class {
|
|
767
|
+
a = 0;
|
|
768
|
+
person;
|
|
769
|
+
};
|
|
770
|
+
describeClass(e, Entity("testJsonFieldType", { allowApiCrud: true }), {
|
|
771
|
+
a: Fields.number(),
|
|
772
|
+
person: Fields.json()
|
|
773
|
+
});
|
|
774
|
+
const r = await createEntity(e);
|
|
775
|
+
await r.insert({ a: 1, person: { firstName: "noam", lastName: "honig" } });
|
|
776
|
+
let item = await r.findFirst();
|
|
777
|
+
expect(item.person).toEqual({ firstName: "noam", lastName: "honig" });
|
|
778
|
+
}, false);
|
|
779
|
+
testAll("test json structure 2", async ({ createEntity }) => {
|
|
780
|
+
const e = class {
|
|
781
|
+
a = 0;
|
|
782
|
+
items = [];
|
|
783
|
+
};
|
|
784
|
+
describeClass(e, Entity("testJsonFieldType2", { allowApiCrud: true }), {
|
|
785
|
+
a: Fields.number(),
|
|
786
|
+
items: Fields.json()
|
|
787
|
+
});
|
|
788
|
+
const r = await createEntity(e);
|
|
789
|
+
await r.insert({ a: 1, items: ["a", "b"] });
|
|
790
|
+
let item = await r.findFirst();
|
|
791
|
+
expect(item.items).toEqual(["a", "b"]);
|
|
792
|
+
//expect(await r.count({ items: { $contains: "b" } })).toBe(1)
|
|
793
|
+
}, false);
|
|
794
|
+
testAll("test json structure 3", async ({ createEntity }) => {
|
|
795
|
+
const e = class {
|
|
796
|
+
a = 0;
|
|
797
|
+
items = [];
|
|
798
|
+
};
|
|
799
|
+
describeClass(e, Entity("testJsonFieldType3", { allowApiCrud: true }), {
|
|
800
|
+
a: Fields.number(),
|
|
801
|
+
items: Fields.object()
|
|
802
|
+
});
|
|
803
|
+
const r = await createEntity(e);
|
|
804
|
+
await r.insert({ a: 1, items: ["a", "b"] });
|
|
805
|
+
let item = await r.findFirst();
|
|
806
|
+
expect(item.items).toEqual(["a", "b"]);
|
|
807
|
+
expect(await r.count({ items: { $contains: "b" } })).toBe(1);
|
|
808
|
+
}, false, {
|
|
809
|
+
exclude: [TestDbs.mongo]
|
|
810
|
+
});
|