remult 0.22.1 → 0.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/graphql.js +27 -27
- package/esm/postgres/schema-builder.js +4 -4
- package/esm/remult-knex/index.js +2 -2
- package/esm/remult-mongo.js +6 -6
- package/esm/src/backend-tests/backend-database-test-setup.backend-spec.js +30 -0
- package/esm/src/id-entity.d.ts +4 -0
- package/esm/src/id-entity.js +8 -0
- package/esm/src/remult3/RepositoryImplementation.js +7 -5
- package/esm/src/shared-tests/db-tests.db-tests.js +35 -0
- package/package.json +1 -1
- package/postgres/postgresColumnSyntax.d.ts +2 -0
- package/postgres/postgresColumnSyntax.js +34 -0
- package/remult-knex/index.js +2 -2
- package/remult-middleware.d.ts +2 -0
- package/remult-middleware.js +70 -0
- package/remult-mongo.js +6 -6
- package/server/register-actions-on-server.d.ts +3 -0
- package/server/register-actions-on-server.js +50 -0
- package/server/register-entities-on-server.d.ts +3 -0
- package/server/register-entities-on-server.js +19 -0
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +60 -0
- package/{esm/core/src → src}/backend-tests/my-test.backend-spec.d.ts +1 -1
- package/src/backend-tests/my-test.backend-spec.js +217 -0
- package/src/backend-tests/test-http-server.backend-spec.d.ts +6 -0
- package/src/backend-tests/test-http-server.backend-spec.js +342 -0
- package/src/id-entity.d.ts +4 -0
- package/src/id-entity.js +17 -0
- package/src/remult3/RepositoryImplementation.js +15 -13
- package/src/shared-tests/db-tests.db-tests.js +64 -0
- package/{esm/core/src/valueConverters.d.ts → valueConverters.d.ts} +12 -13
- package/valueConverters.js +168 -0
- package/esm/angular/interfaces/index.d.ts +0 -1
- package/esm/angular/interfaces/index.js +0 -1
- package/esm/angular/interfaces/src/column-collection.d.ts +0 -70
- package/esm/angular/interfaces/src/column-collection.js +0 -341
- package/esm/angular/interfaces/src/data-area-settings.d.ts +0 -15
- package/esm/angular/interfaces/src/data-area-settings.js +0 -35
- package/esm/angular/interfaces/src/data-control-interfaces.d.ts +0 -36
- package/esm/angular/interfaces/src/data-control-interfaces.js +0 -57
- package/esm/angular/interfaces/src/dataList.d.ts +0 -13
- package/esm/angular/interfaces/src/dataList.js +0 -42
- package/esm/angular/interfaces/src/filter-helper.d.ts +0 -13
- package/esm/angular/interfaces/src/filter-helper.js +0 -59
- package/esm/angular/interfaces/src/grid-settings.d.ts +0 -145
- package/esm/angular/interfaces/src/grid-settings.js +0 -387
- package/esm/angular/interfaces/src/public_api.d.ts +0 -4
- package/esm/angular/interfaces/src/public_api.js +0 -4
- package/esm/angular/src/angular/RemultAngularPluginsService.d.ts +0 -4
- package/esm/angular/src/angular/RemultAngularPluginsService.js +0 -3
- package/esm/angular/src/angular/data-control/data-control2.component.d.ts +0 -49
- package/esm/angular/src/angular/data-control/data-control2.component.js +0 -138
- package/esm/core/SseSubscriptionServer.d.ts +0 -33
- package/esm/core/SseSubscriptionServer.js +0 -107
- package/esm/core/assign.d.ts +0 -1
- package/esm/core/assign.js +0 -5
- package/esm/core/classType.d.ts +0 -3
- package/esm/core/classType.js +0 -1
- package/esm/core/index.d.ts +0 -27
- package/esm/core/index.js +0 -25
- package/esm/core/inputTypes.d.ts +0 -9
- package/esm/core/inputTypes.js +0 -9
- package/esm/core/live-query/data-provider-live-query-storage.d.ts +0 -22
- package/esm/core/live-query/data-provider-live-query-storage.js +0 -71
- package/esm/core/postgres/index.d.ts +0 -2
- package/esm/core/postgres/index.js +0 -2
- package/esm/core/postgres/postgres-data-provider.d.ts +0 -36
- package/esm/core/postgres/postgres-data-provider.js +0 -120
- package/esm/core/postgres/schema-builder.d.ts +0 -17
- package/esm/core/postgres/schema-builder.js +0 -153
- package/esm/core/remult-fresh.d.ts +0 -17
- package/esm/core/remult-fresh.js +0 -29
- package/esm/core/remult-knex/index.d.ts +0 -30
- package/esm/core/remult-knex/index.js +0 -446
- package/esm/core/remult-mongo.d.ts +0 -24
- package/esm/core/remult-mongo.js +0 -254
- package/esm/core/server/JsonEntityFileStorage.d.ts +0 -10
- package/esm/core/server/JsonEntityFileStorage.js +0 -25
- package/esm/core/server/core.d.ts +0 -4
- package/esm/core/server/core.js +0 -4
- package/esm/core/server/expressBridge.d.ts +0 -182
- package/esm/core/server/expressBridge.js +0 -938
- package/esm/core/server/index.d.ts +0 -6
- package/esm/core/server/index.js +0 -9
- package/esm/core/server/initAsyncHooks.d.ts +0 -1
- package/esm/core/server/initAsyncHooks.js +0 -9
- package/esm/core/server/initDataProvider.d.ts +0 -2
- package/esm/core/server/initDataProvider.js +0 -14
- package/esm/core/src/__EntityValueProvider.d.ts +0 -11
- package/esm/core/src/__EntityValueProvider.js +0 -1
- package/esm/core/src/__RowsOfDataForTesting.d.ts +0 -3
- package/esm/core/src/__RowsOfDataForTesting.js +0 -1
- package/esm/core/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +0 -6
- package/esm/core/src/backend-tests/backend-database-test-setup.backend-spec.js +0 -147
- package/esm/core/src/backend-tests/my-test.backend-spec.js +0 -197
- package/esm/core/src/backend-tests/test-http-server.backend-spec.d.ts +0 -1
- package/esm/core/src/backend-tests/test-http-server.backend-spec.js +0 -167
- package/esm/core/src/buildRestDataProvider.d.ts +0 -31
- package/esm/core/src/buildRestDataProvider.js +0 -113
- package/esm/core/src/column-interfaces.d.ts +0 -154
- package/esm/core/src/column-interfaces.js +0 -7
- package/esm/core/src/column.d.ts +0 -58
- package/esm/core/src/column.js +0 -174
- package/esm/core/src/context.d.ts +0 -134
- package/esm/core/src/context.js +0 -286
- package/esm/core/src/data-api.d.ts +0 -39
- package/esm/core/src/data-api.js +0 -279
- package/esm/core/src/data-interfaces.d.ts +0 -41
- package/esm/core/src/data-interfaces.js +0 -12
- package/esm/core/src/data-providers/array-entity-data-provider.d.ts +0 -22
- package/esm/core/src/data-providers/array-entity-data-provider.js +0 -252
- package/esm/core/src/data-providers/in-memory-database.d.ts +0 -9
- package/esm/core/src/data-providers/in-memory-database.js +0 -14
- package/esm/core/src/data-providers/json-data-provider.d.ts +0 -12
- package/esm/core/src/data-providers/json-data-provider.js +0 -55
- package/esm/core/src/data-providers/rest-data-provider.d.ts +0 -49
- package/esm/core/src/data-providers/rest-data-provider.js +0 -256
- package/esm/core/src/data-providers/sql-database.d.ts +0 -33
- package/esm/core/src/data-providers/sql-database.js +0 -384
- package/esm/core/src/data-providers/web-sql-data-provider.d.ts +0 -24
- package/esm/core/src/data-providers/web-sql-data-provider.js +0 -143
- package/esm/core/src/entity.d.ts +0 -91
- package/esm/core/src/entity.js +0 -1
- package/esm/core/src/filter/filter-consumer-bridge-to-sql-request.d.ts +0 -50
- package/esm/core/src/filter/filter-consumer-bridge-to-sql-request.js +0 -150
- package/esm/core/src/filter/filter-consumer-bridge-to-url-builder.d.ts +0 -1
- package/esm/core/src/filter/filter-consumer-bridge-to-url-builder.js +0 -1
- package/esm/core/src/filter/filter-interfaces.d.ts +0 -85
- package/esm/core/src/filter/filter-interfaces.js +0 -477
- package/esm/core/src/live-query/LiveQueryClient.d.ts +0 -20
- package/esm/core/src/live-query/LiveQueryClient.js +0 -188
- package/esm/core/src/live-query/SseSubscriptionClient.d.ts +0 -5
- package/esm/core/src/live-query/SseSubscriptionClient.js +0 -86
- package/esm/core/src/live-query/SubscriptionChannel.d.ts +0 -72
- package/esm/core/src/live-query/SubscriptionChannel.js +0 -123
- package/esm/core/src/live-query/SubscriptionServer.d.ts +0 -53
- package/esm/core/src/live-query/SubscriptionServer.js +0 -111
- package/esm/core/src/live-query/live-query-tests.spec.d.ts +0 -6
- package/esm/core/src/live-query/live-query-tests.spec.js +0 -952
- package/esm/core/src/remult-proxy.d.ts +0 -35
- package/esm/core/src/remult-proxy.js +0 -113
- package/esm/core/src/remult3/DecoratorReplacer.d.ts +0 -10
- package/esm/core/src/remult3/DecoratorReplacer.js +0 -20
- package/esm/core/src/remult3/RepositoryImplementation.d.ts +0 -355
- package/esm/core/src/remult3/RepositoryImplementation.js +0 -2109
- package/esm/core/src/remult3/index.d.ts +0 -2
- package/esm/core/src/remult3/index.js +0 -2
- package/esm/core/src/remult3/remult3.d.ts +0 -395
- package/esm/core/src/remult3/remult3.js +0 -2
- package/esm/core/src/server-action.d.ts +0 -81
- package/esm/core/src/server-action.js +0 -394
- package/esm/core/src/shared-tests/db-tests-setup.d.ts +0 -32
- package/esm/core/src/shared-tests/db-tests-setup.js +0 -78
- package/esm/core/src/shared-tests/db-tests.db-tests.d.ts +0 -25
- package/esm/core/src/shared-tests/db-tests.db-tests.js +0 -810
- package/esm/core/src/shared-tests/deleteAll.d.ts +0 -2
- package/esm/core/src/shared-tests/deleteAll.js +0 -4
- package/esm/core/src/shared-tests/entityWithValidations.d.ts +0 -14
- package/esm/core/src/shared-tests/entityWithValidations.js +0 -43
- package/esm/core/src/shared-tests/index.d.ts +0 -4
- package/esm/core/src/shared-tests/index.js +0 -4
- package/esm/core/src/shared-tests/test-custom-id-column.spec.d.ts +0 -1
- package/esm/core/src/shared-tests/test-custom-id-column.spec.js +0 -67
- package/esm/core/src/shared-tests/test-special-value.spec.d.ts +0 -10
- package/esm/core/src/shared-tests/test-special-value.spec.js +0 -73
- package/esm/core/src/shared-tests/test-update-with-null.spec.d.ts +0 -1
- package/esm/core/src/shared-tests/test-update-with-null.spec.js +0 -31
- package/esm/core/src/sort.d.ts +0 -16
- package/esm/core/src/sort.js +0 -103
- package/esm/core/src/sql-command.d.ts +0 -19
- package/esm/core/src/sql-command.js +0 -1
- package/esm/core/src/test.d.ts +0 -3
- package/esm/core/src/test.js +0 -12
- package/esm/core/src/tests/Done.d.ts +0 -5
- package/esm/core/src/tests/Done.js +0 -9
- package/esm/core/src/tests/RowProvider.spec.d.ts +0 -16
- package/esm/core/src/tests/RowProvider.spec.js +0 -631
- package/esm/core/src/tests/TestDataApiResponse.d.ts +0 -10
- package/esm/core/src/tests/TestDataApiResponse.js +0 -22
- package/esm/core/src/tests/basicRowFunctionality.spec.d.ts +0 -8
- package/esm/core/src/tests/basicRowFunctionality.spec.js +0 -2103
- package/esm/core/src/tests/c.d.ts +0 -8
- package/esm/core/src/tests/c.js +0 -13
- package/esm/core/src/tests/createData.d.ts +0 -7
- package/esm/core/src/tests/createData.js +0 -22
- package/esm/core/src/tests/d.d.ts +0 -6
- package/esm/core/src/tests/d.js +0 -11
- package/esm/core/src/tests/dWithPrefilter.d.ts +0 -7
- package/esm/core/src/tests/dWithPrefilter.js +0 -18
- package/esm/core/src/tests/entityForCustomFilter.d.ts +0 -16
- package/esm/core/src/tests/entityForCustomFilter.js +0 -33
- package/esm/core/src/tests/entityWithValidationsOnColumn.d.ts +0 -5
- package/esm/core/src/tests/entityWithValidationsOnColumn.js +0 -13
- package/esm/core/src/tests/frontend-database-tests-setup.spec.d.ts +0 -4
- package/esm/core/src/tests/frontend-database-tests-setup.spec.js +0 -37
- package/esm/core/src/tests/h.d.ts +0 -6
- package/esm/core/src/tests/h.js +0 -24
- package/esm/core/src/tests/remult-3-basic-tests.spec.d.ts +0 -1
- package/esm/core/src/tests/remult-3-basic-tests.spec.js +0 -236
- package/esm/core/src/tests/remult-3-entities.d.ts +0 -23
- package/esm/core/src/tests/remult-3-entities.js +0 -39
- package/esm/core/src/tests/tasks.d.ts +0 -6
- package/esm/core/src/tests/tasks.js +0 -10
- package/esm/core/src/tests/test-context-as-storage.spec.d.ts +0 -0
- package/esm/core/src/tests/test-context-as-storage.spec.js +0 -1
- package/esm/core/src/tests/test-data-api/predefined-filter.spec.d.ts +0 -1
- package/esm/core/src/tests/test-data-api/predefined-filter.spec.js +0 -389
- package/esm/core/src/tests/test-data-api/test-put-with-validation.spec.d.ts +0 -5
- package/esm/core/src/tests/test-data-api/test-put-with-validation.spec.js +0 -152
- package/esm/core/src/tests/test-decorator-precedence.spec.d.ts +0 -1
- package/esm/core/src/tests/test-decorator-precedence.spec.js +0 -38
- package/esm/core/src/tests/test-default-value.spec.d.ts +0 -1
- package/esm/core/src/tests/test-default-value.spec.js +0 -33
- package/esm/core/src/tests/test-entity-inheritance.spec.d.ts +0 -14
- package/esm/core/src/tests/test-entity-inheritance.spec.js +0 -82
- package/esm/core/src/tests/test-exceptions.spec.d.ts +0 -1
- package/esm/core/src/tests/test-exceptions.spec.js +0 -375
- package/esm/core/src/tests/test-json.spec.d.ts +0 -1
- package/esm/core/src/tests/test-json.spec.js +0 -115
- package/esm/core/src/tests/test-many-to-one-relation-in-entity.spec.d.ts +0 -9
- package/esm/core/src/tests/test-many-to-one-relation-in-entity.spec.js +0 -809
- package/esm/core/src/tests/test-non-active-record.spec.d.ts +0 -1
- package/esm/core/src/tests/test-non-active-record.spec.js +0 -66
- package/esm/core/src/tests/test-object-column.spec.d.ts +0 -1
- package/esm/core/src/tests/test-object-column.spec.js +0 -189
- package/esm/core/src/tests/test-paged-foreach.spec.d.ts +0 -1
- package/esm/core/src/tests/test-paged-foreach.spec.js +0 -328
- package/esm/core/src/tests/test-remult-angular.spec.d.ts +0 -1
- package/esm/core/src/tests/test-remult-angular.spec.js +0 -23
- package/esm/core/src/tests/test-server-controller.spec.d.ts +0 -7
- package/esm/core/src/tests/test-server-controller.spec.js +0 -489
- package/esm/core/src/tests/test-server-expressions.spec.d.ts +0 -1
- package/esm/core/src/tests/test-server-expressions.spec.js +0 -178
- package/esm/core/src/tests/test-server-method-on-entity.spec.d.ts +0 -1
- package/esm/core/src/tests/test-server-method-on-entity.spec.js +0 -306
- package/esm/core/src/tests/test-sql-expression.spec.d.ts +0 -5
- package/esm/core/src/tests/test-sql-expression.spec.js +0 -205
- package/esm/core/src/tests/test-sql.spec.d.ts +0 -1
- package/esm/core/src/tests/test-sql.spec.js +0 -170
- package/esm/core/src/tests/test-subscribe.spec.d.ts +0 -1
- package/esm/core/src/tests/test-subscribe.spec.js +0 -135
- package/esm/core/src/tests/test-type-recovery.spec.d.ts +0 -1
- package/esm/core/src/tests/test-type-recovery.spec.js +0 -49
- package/esm/core/src/tests/test-where-api.spec.d.ts +0 -1
- package/esm/core/src/tests/test-where-api.spec.js +0 -434
- package/esm/core/src/tests/testHelper.spec.d.ts +0 -36
- package/esm/core/src/tests/testHelper.spec.js +0 -226
- package/esm/core/src/tests/testModel/models.d.ts +0 -16
- package/esm/core/src/tests/testModel/models.js +0 -25
- package/esm/core/src/validators.d.ts +0 -14
- package/esm/core/src/validators.js +0 -33
- package/esm/core/src/valueConverters.js +0 -197
- package/esm/core/urlBuilder.d.ts +0 -6
- package/esm/core/urlBuilder.js +0 -20
- package/esm/test-servers/shared/Task.d.ts +0 -9
- package/esm/test-servers/shared/Task.js +0 -32
- package/esm/test.d.ts +0 -5
- package/esm/test.js +0 -6
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
import { CompoundIdField } from "../column";
|
|
2
|
-
import { dbNamesOf, FilterConsumerBridgeToSqlRequest, isDbReadonly } from "../filter/filter-consumer-bridge-to-sql-request";
|
|
3
|
-
import { customDatabaseFilterToken, Filter } from '../filter/filter-interfaces';
|
|
4
|
-
import { Sort } from '../sort';
|
|
5
|
-
import { getRepository } from "../remult3";
|
|
6
|
-
import { remult as defaultRemult } from "../remult-proxy";
|
|
7
|
-
import { ValueConverters } from "../valueConverters";
|
|
8
|
-
// @dynamic
|
|
9
|
-
export class SqlDatabase {
|
|
10
|
-
sql;
|
|
11
|
-
static getDb(remult) {
|
|
12
|
-
const r = (remult || defaultRemult).dataProvider;
|
|
13
|
-
if (!r.createCommand)
|
|
14
|
-
throw "the data provider is not an SqlDatabase";
|
|
15
|
-
return r;
|
|
16
|
-
}
|
|
17
|
-
createCommand() {
|
|
18
|
-
return new LogSQLCommand(this.sql.createCommand(), SqlDatabase.LogToConsole);
|
|
19
|
-
}
|
|
20
|
-
async execute(sql) {
|
|
21
|
-
return await this.createCommand().execute(sql);
|
|
22
|
-
}
|
|
23
|
-
/* @internal*/
|
|
24
|
-
_getSourceSql() {
|
|
25
|
-
return this.sql;
|
|
26
|
-
}
|
|
27
|
-
async ensureSchema(entities) {
|
|
28
|
-
if (this.sql.ensureSchema)
|
|
29
|
-
await this.sql.ensureSchema(entities);
|
|
30
|
-
}
|
|
31
|
-
getEntityDataProvider(entity) {
|
|
32
|
-
if (!this.sql.supportsJsonColumnType) {
|
|
33
|
-
for (const f of entity.fields.toArray()) {
|
|
34
|
-
if (f.valueConverter.fieldTypeInDb === "json") {
|
|
35
|
-
//@ts-ignore
|
|
36
|
-
f.valueConverter = { ...f.valueConverter, toDb: ValueConverters.JsonString.toDb, fromDb: ValueConverters.JsonString.fromDb };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return new ActualSQLServerDataProvider(entity, this, async (dbName) => {
|
|
41
|
-
if (this.createdEntities.indexOf(dbName.$entityName) < 0) {
|
|
42
|
-
this.createdEntities.push(dbName.$entityName);
|
|
43
|
-
await this.sql.entityIsUsedForTheFirstTime(entity);
|
|
44
|
-
}
|
|
45
|
-
}, this.sql);
|
|
46
|
-
}
|
|
47
|
-
transaction(action) {
|
|
48
|
-
return this.sql.transaction(async (x) => {
|
|
49
|
-
let completed = false;
|
|
50
|
-
try {
|
|
51
|
-
await action(new SqlDatabase({
|
|
52
|
-
createCommand: () => {
|
|
53
|
-
let c = x.createCommand();
|
|
54
|
-
return {
|
|
55
|
-
addParameterAndReturnSqlToken: x => c.addParameterAndReturnSqlToken(x),
|
|
56
|
-
execute: async (sql) => {
|
|
57
|
-
if (completed)
|
|
58
|
-
throw "can't run a command after the transaction was completed";
|
|
59
|
-
return c.execute(sql);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
getLimitSqlSyntax: this.sql.getLimitSqlSyntax,
|
|
64
|
-
entityIsUsedForTheFirstTime: y => x.entityIsUsedForTheFirstTime(y),
|
|
65
|
-
transaction: z => x.transaction(z),
|
|
66
|
-
supportsJsonColumnType: this.sql.supportsJsonColumnType
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
finally {
|
|
70
|
-
completed = true;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
static rawFilter(build) {
|
|
75
|
-
return {
|
|
76
|
-
[customDatabaseFilterToken]: {
|
|
77
|
-
buildSql: build
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
static async filterToRaw(repo, condition, sqlCommand) {
|
|
82
|
-
if (!sqlCommand) {
|
|
83
|
-
sqlCommand = new myDummySQLCommand();
|
|
84
|
-
}
|
|
85
|
-
const r = getRepository(repo);
|
|
86
|
-
var b = new FilterConsumerBridgeToSqlRequest(sqlCommand, await dbNamesOf(r.metadata));
|
|
87
|
-
b._addWhere = false;
|
|
88
|
-
await (await (r.translateWhereToFilter(condition))).__applyToConsumer(b);
|
|
89
|
-
return await b.resolveWhere();
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* `false` _(default)_ - No logging
|
|
93
|
-
*
|
|
94
|
-
* `true` - to log all queries to the console
|
|
95
|
-
*
|
|
96
|
-
* `oneLiner` - to log all queries to the console as one line
|
|
97
|
-
*
|
|
98
|
-
* a `function` - to log all queries to the console as a custom format
|
|
99
|
-
*/
|
|
100
|
-
static LogToConsole = false;
|
|
101
|
-
/**
|
|
102
|
-
* Threshold in milliseconds for logging queries to the console.
|
|
103
|
-
*/
|
|
104
|
-
static durationThreshold = 0;
|
|
105
|
-
constructor(sql) {
|
|
106
|
-
this.sql = sql;
|
|
107
|
-
}
|
|
108
|
-
createdEntities = [];
|
|
109
|
-
}
|
|
110
|
-
const icons = new Map([
|
|
111
|
-
// CRUD
|
|
112
|
-
['INSERT', '⚪'],
|
|
113
|
-
['SELECT', '🔵'],
|
|
114
|
-
['UPDATE', '🟣'],
|
|
115
|
-
['DELETE', '🟤'],
|
|
116
|
-
// Additional
|
|
117
|
-
['CREATE', '🟩'],
|
|
118
|
-
['ALTER', '🟨'],
|
|
119
|
-
['DROP', '🟥'],
|
|
120
|
-
['TRUNCATE', '⬛'],
|
|
121
|
-
['GRANT', '🟪'],
|
|
122
|
-
['REVOKE', '🟫'], // Used to take back permissions from a user.
|
|
123
|
-
]);
|
|
124
|
-
class LogSQLCommand {
|
|
125
|
-
origin;
|
|
126
|
-
logToConsole;
|
|
127
|
-
constructor(origin, logToConsole) {
|
|
128
|
-
this.origin = origin;
|
|
129
|
-
this.logToConsole = logToConsole;
|
|
130
|
-
}
|
|
131
|
-
args = {};
|
|
132
|
-
addParameterAndReturnSqlToken(val) {
|
|
133
|
-
let r = this.origin.addParameterAndReturnSqlToken(val);
|
|
134
|
-
this.args[r] = val;
|
|
135
|
-
return r;
|
|
136
|
-
}
|
|
137
|
-
async execute(sql) {
|
|
138
|
-
try {
|
|
139
|
-
let start = new Date();
|
|
140
|
-
let r = await this.origin.execute(sql);
|
|
141
|
-
if (this.logToConsole !== false) {
|
|
142
|
-
var d = new Date().valueOf() - start.valueOf();
|
|
143
|
-
if (d > SqlDatabase.durationThreshold) {
|
|
144
|
-
const duration = d / 1000;
|
|
145
|
-
if (this.logToConsole === "oneLiner") {
|
|
146
|
-
const rawSql = sql.replace(/(\r\n|\n|\r|\t)/gm, ' ').replace(/ +/g, ' ').trim();
|
|
147
|
-
const first = rawSql.split(' ')[0].toUpperCase();
|
|
148
|
-
console.info(`${icons.get(first) || '💢'} (${(duration).toFixed(3)}) ${rawSql} ${JSON.stringify(this.args)}`);
|
|
149
|
-
}
|
|
150
|
-
else if (typeof this.logToConsole === "function") {
|
|
151
|
-
this.logToConsole(duration, sql, this.args);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
console.info({ query: sql, arguments: this.args, duration });
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return r;
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
console.error({ error: err, query: sql, arguments: this.args });
|
|
162
|
-
throw err;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
class ActualSQLServerDataProvider {
|
|
167
|
-
entity;
|
|
168
|
-
sql;
|
|
169
|
-
iAmUsed;
|
|
170
|
-
strategy;
|
|
171
|
-
static LogToConsole = false;
|
|
172
|
-
constructor(entity, sql, iAmUsed, strategy) {
|
|
173
|
-
this.entity = entity;
|
|
174
|
-
this.sql = sql;
|
|
175
|
-
this.iAmUsed = iAmUsed;
|
|
176
|
-
this.strategy = strategy;
|
|
177
|
-
}
|
|
178
|
-
async init() {
|
|
179
|
-
let dbNameProvider = await dbNamesOf(this.entity);
|
|
180
|
-
await this.iAmUsed(dbNameProvider);
|
|
181
|
-
return dbNameProvider;
|
|
182
|
-
}
|
|
183
|
-
async count(where) {
|
|
184
|
-
let e = await this.init();
|
|
185
|
-
let select = 'select count(*) count from ' + e.$entityName;
|
|
186
|
-
let r = this.sql.createCommand();
|
|
187
|
-
if (where) {
|
|
188
|
-
let wc = new FilterConsumerBridgeToSqlRequest(r, e);
|
|
189
|
-
where.__applyToConsumer(wc);
|
|
190
|
-
select += await wc.resolveWhere();
|
|
191
|
-
}
|
|
192
|
-
return r.execute(select).then(r => {
|
|
193
|
-
return Number(r.rows[0].count);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
async find(options) {
|
|
197
|
-
let e = await this.init();
|
|
198
|
-
let { colKeys, select } = this.buildSelect(e);
|
|
199
|
-
select = 'select ' + select;
|
|
200
|
-
select += '\n from ' + e.$entityName;
|
|
201
|
-
let r = this.sql.createCommand();
|
|
202
|
-
if (options) {
|
|
203
|
-
if (options.where) {
|
|
204
|
-
let where = new FilterConsumerBridgeToSqlRequest(r, e);
|
|
205
|
-
options.where.__applyToConsumer(where);
|
|
206
|
-
select += await where.resolveWhere();
|
|
207
|
-
}
|
|
208
|
-
if (options.limit) {
|
|
209
|
-
options.orderBy = Sort.createUniqueSort(this.entity, options.orderBy);
|
|
210
|
-
}
|
|
211
|
-
if (!options.orderBy) {
|
|
212
|
-
options.orderBy = Sort.createUniqueSort(this.entity, new Sort());
|
|
213
|
-
}
|
|
214
|
-
if (options.orderBy) {
|
|
215
|
-
let first = true;
|
|
216
|
-
let segs = [];
|
|
217
|
-
for (const s of options.orderBy.Segments) {
|
|
218
|
-
if (s.field instanceof CompoundIdField) {
|
|
219
|
-
segs.push(...s.field.fields.map(c => ({ field: c, isDescending: s.isDescending })));
|
|
220
|
-
}
|
|
221
|
-
else
|
|
222
|
-
segs.push(s);
|
|
223
|
-
}
|
|
224
|
-
for (const c of segs) {
|
|
225
|
-
if (first) {
|
|
226
|
-
select += ' Order By ';
|
|
227
|
-
first = false;
|
|
228
|
-
}
|
|
229
|
-
else
|
|
230
|
-
select += ', ';
|
|
231
|
-
select += e.$dbNameOf(c.field);
|
|
232
|
-
if (c.isDescending)
|
|
233
|
-
select += ' desc';
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
if (options.limit) {
|
|
237
|
-
let page = 1;
|
|
238
|
-
if (options.page)
|
|
239
|
-
page = options.page;
|
|
240
|
-
if (page < 1)
|
|
241
|
-
page = 1;
|
|
242
|
-
select += ' ' + this.strategy.getLimitSqlSyntax(options.limit, (page - 1) * options.limit);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return r.execute(select).then(r => {
|
|
246
|
-
return r.rows.map(y => {
|
|
247
|
-
return this.buildResultRow(colKeys, y, r);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
buildResultRow(colKeys, y, r) {
|
|
252
|
-
let result = {};
|
|
253
|
-
for (let index = 0; index < colKeys.length; index++) {
|
|
254
|
-
const col = colKeys[index];
|
|
255
|
-
try {
|
|
256
|
-
result[col.key] = col.valueConverter.fromDb(y[r.getColumnKeyInResultForIndexInSelect(index)]);
|
|
257
|
-
}
|
|
258
|
-
catch (err) {
|
|
259
|
-
throw new Error("Failed to load from db:" + col.key + "\r\n" + err);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return result;
|
|
263
|
-
}
|
|
264
|
-
buildSelect(e) {
|
|
265
|
-
let select = '';
|
|
266
|
-
let colKeys = [];
|
|
267
|
-
for (const x of this.entity.fields) {
|
|
268
|
-
if (x.isServerExpression) {
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
if (colKeys.length > 0)
|
|
272
|
-
select += ', ';
|
|
273
|
-
select += e.$dbNameOf(x);
|
|
274
|
-
colKeys.push(x);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return { colKeys, select };
|
|
278
|
-
}
|
|
279
|
-
async update(id, data) {
|
|
280
|
-
let e = await this.init();
|
|
281
|
-
let r = this.sql.createCommand();
|
|
282
|
-
let f = new FilterConsumerBridgeToSqlRequest(r, e);
|
|
283
|
-
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
284
|
-
let statement = 'update ' + e.$entityName + ' set ';
|
|
285
|
-
let added = false;
|
|
286
|
-
for (const x of this.entity.fields) {
|
|
287
|
-
if (x instanceof CompoundIdField) {
|
|
288
|
-
}
|
|
289
|
-
if (isDbReadonly(x, e)) { }
|
|
290
|
-
else if (data[x.key] !== undefined) {
|
|
291
|
-
let v = x.valueConverter.toDb(data[x.key]);
|
|
292
|
-
if (v !== undefined) {
|
|
293
|
-
if (!added)
|
|
294
|
-
added = true;
|
|
295
|
-
else
|
|
296
|
-
statement += ', ';
|
|
297
|
-
statement += e.$dbNameOf(x) + ' = ' + r.addParameterAndReturnSqlToken(v);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
statement += await f.resolveWhere();
|
|
302
|
-
let { colKeys, select } = this.buildSelect(e);
|
|
303
|
-
statement += ' returning ' + select;
|
|
304
|
-
return r.execute(statement).then(sqlResult => {
|
|
305
|
-
return this.buildResultRow(colKeys, sqlResult.rows[0], sqlResult);
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
async delete(id) {
|
|
309
|
-
let e = await this.init();
|
|
310
|
-
let r = this.sql.createCommand();
|
|
311
|
-
let f = new FilterConsumerBridgeToSqlRequest(r, e);
|
|
312
|
-
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
313
|
-
let statement = 'delete from ' + e.$entityName;
|
|
314
|
-
statement += await f.resolveWhere();
|
|
315
|
-
return r.execute(statement).then(() => { });
|
|
316
|
-
}
|
|
317
|
-
async insert(data) {
|
|
318
|
-
let e = await this.init();
|
|
319
|
-
let r = this.sql.createCommand();
|
|
320
|
-
let cols = '';
|
|
321
|
-
let vals = '';
|
|
322
|
-
let added = false;
|
|
323
|
-
for (const x of this.entity.fields) {
|
|
324
|
-
if (isDbReadonly(x, e)) { }
|
|
325
|
-
else {
|
|
326
|
-
let v = x.valueConverter.toDb(data[x.key]);
|
|
327
|
-
if (v != undefined) {
|
|
328
|
-
if (!added)
|
|
329
|
-
added = true;
|
|
330
|
-
else {
|
|
331
|
-
cols += ', ';
|
|
332
|
-
vals += ', ';
|
|
333
|
-
}
|
|
334
|
-
cols += e.$dbNameOf(x);
|
|
335
|
-
vals += r.addParameterAndReturnSqlToken(v);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
let statement = `insert into ${e.$entityName} (${cols}) values (${vals})`;
|
|
340
|
-
let { colKeys, select } = this.buildSelect(e);
|
|
341
|
-
statement += ' returning ' + select;
|
|
342
|
-
return await r.execute(statement).then(sql => this.buildResultRow(colKeys, sql.rows[0], sql));
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
class myDummySQLCommand {
|
|
346
|
-
execute(sql) {
|
|
347
|
-
throw new Error("Method not implemented.");
|
|
348
|
-
}
|
|
349
|
-
addParameterAndReturnSqlToken(val) {
|
|
350
|
-
if (val === null)
|
|
351
|
-
return "null";
|
|
352
|
-
if (val instanceof Date)
|
|
353
|
-
val = val.toISOString();
|
|
354
|
-
if (typeof (val) == "string") {
|
|
355
|
-
if (val == undefined)
|
|
356
|
-
val = '';
|
|
357
|
-
return '\'' + val.replace(/'/g, '\'\'') + '\'';
|
|
358
|
-
}
|
|
359
|
-
return val.toString();
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
async function bulkInsert(array, db) {
|
|
363
|
-
if (array.length == 0)
|
|
364
|
-
return;
|
|
365
|
-
const chunkSize = 250;
|
|
366
|
-
for (let i = 0; i < array.length; i += chunkSize) {
|
|
367
|
-
const items = array.slice(i, i + chunkSize);
|
|
368
|
-
// do whatever
|
|
369
|
-
const c = db.createCommand();
|
|
370
|
-
let sql = 'insert into ' +
|
|
371
|
-
(await items[0]._.metadata.getDbName()) +
|
|
372
|
-
' (' +
|
|
373
|
-
(await Promise.all(items[0]._.metadata.fields.toArray().map((f) => f.getDbName()))).join(',') +
|
|
374
|
-
') values ';
|
|
375
|
-
sql += items
|
|
376
|
-
.map((row) => '(' +
|
|
377
|
-
row.$.toArray()
|
|
378
|
-
.map((f) => c.addParameterAndReturnSqlToken(f.metadata.valueConverter.toDb(f.value)))
|
|
379
|
-
.join(', ') +
|
|
380
|
-
')')
|
|
381
|
-
.join(',');
|
|
382
|
-
await c.execute(sql);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/// <reference types="websql" />
|
|
2
|
-
import { __RowsOfDataForTesting } from "../__RowsOfDataForTesting";
|
|
3
|
-
import { SqlCommand, SqlImplementation } from "../sql-command";
|
|
4
|
-
import { EntityMetadata } from "../remult3";
|
|
5
|
-
import { Remult } from "../context";
|
|
6
|
-
export declare class WebSqlDataProvider implements SqlImplementation, __RowsOfDataForTesting {
|
|
7
|
-
private databaseName;
|
|
8
|
-
rows: {
|
|
9
|
-
[tableName: string]: any;
|
|
10
|
-
};
|
|
11
|
-
/** @internal */
|
|
12
|
-
db: Database;
|
|
13
|
-
constructor(databaseName: string, databaseSize?: number);
|
|
14
|
-
static getDb(remult?: Remult): any;
|
|
15
|
-
getLimitSqlSyntax(limit: number, offset: number): string;
|
|
16
|
-
entityIsUsedForTheFirstTime(entity: EntityMetadata): Promise<void>;
|
|
17
|
-
ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
|
|
18
|
-
dropTable(entity: EntityMetadata): Promise<void>;
|
|
19
|
-
createTable(entity: EntityMetadata<any>): Promise<void>;
|
|
20
|
-
createCommand(): SqlCommand;
|
|
21
|
-
transaction(action: (dataProvider: SqlImplementation) => Promise<void>): Promise<void>;
|
|
22
|
-
private addColumnSqlSyntax;
|
|
23
|
-
toString(): string;
|
|
24
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { isAutoIncrement } from "../remult3";
|
|
2
|
-
import { SqlDatabase } from "./sql-database";
|
|
3
|
-
import { dbNamesOf, isDbReadonly } from "../filter/filter-consumer-bridge-to-sql-request";
|
|
4
|
-
//SqlDatabase.LogToConsole = true;
|
|
5
|
-
export class WebSqlDataProvider {
|
|
6
|
-
databaseName;
|
|
7
|
-
rows;
|
|
8
|
-
/** @internal */
|
|
9
|
-
//@ts-ignore
|
|
10
|
-
db;
|
|
11
|
-
constructor(databaseName, databaseSize = 2 * 1024 * 1024) {
|
|
12
|
-
this.databaseName = databaseName;
|
|
13
|
-
//@ts-ignore
|
|
14
|
-
this.db = window.openDatabase(databaseName, '1.0', databaseName, databaseSize);
|
|
15
|
-
}
|
|
16
|
-
// return instance of websql.Database class - see @types/websql
|
|
17
|
-
static getDb(remult) {
|
|
18
|
-
const sql = SqlDatabase.getDb(remult);
|
|
19
|
-
const me = sql._getSourceSql();
|
|
20
|
-
if (!me.db) {
|
|
21
|
-
throw "the data provider is not a WebSqlDataProvider";
|
|
22
|
-
}
|
|
23
|
-
return me.db;
|
|
24
|
-
}
|
|
25
|
-
getLimitSqlSyntax(limit, offset) {
|
|
26
|
-
return ' limit ' + limit + ' offset ' + offset;
|
|
27
|
-
}
|
|
28
|
-
async entityIsUsedForTheFirstTime(entity) {
|
|
29
|
-
await this.createTable(entity);
|
|
30
|
-
}
|
|
31
|
-
async ensureSchema(entities) {
|
|
32
|
-
for (const entity of entities) {
|
|
33
|
-
await this.createTable(entity);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async dropTable(entity) {
|
|
37
|
-
let e = await dbNamesOf(entity);
|
|
38
|
-
let sql = 'drop table if exists ' + e.$entityName;
|
|
39
|
-
if (SqlDatabase.LogToConsole)
|
|
40
|
-
console.info(sql);
|
|
41
|
-
await this.createCommand().execute(sql);
|
|
42
|
-
}
|
|
43
|
-
async createTable(entity) {
|
|
44
|
-
let result = '';
|
|
45
|
-
let e = await dbNamesOf(entity);
|
|
46
|
-
for (const x of entity.fields) {
|
|
47
|
-
if (!isDbReadonly(x, e) || isAutoIncrement(x)) {
|
|
48
|
-
if (result.length != 0)
|
|
49
|
-
result += ',';
|
|
50
|
-
result += '\r\n ';
|
|
51
|
-
if (isAutoIncrement(x)) {
|
|
52
|
-
if (x.key != entity.idMetadata.field.key)
|
|
53
|
-
throw "in web sql, autoincrement is only allowed for primary key";
|
|
54
|
-
result += e.$dbNameOf(x) + ' integer primary key autoincrement';
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
result += this.addColumnSqlSyntax(x, e.$dbNameOf(x));
|
|
58
|
-
if (x.key == entity.idMetadata.field.key) {
|
|
59
|
-
result += ' primary key';
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
let sql = 'create table if not exists ' + e.$entityName + ' (' + result + '\r\n)';
|
|
65
|
-
if (SqlDatabase.LogToConsole)
|
|
66
|
-
console.log(sql);
|
|
67
|
-
await this.createCommand().execute(sql);
|
|
68
|
-
}
|
|
69
|
-
createCommand() {
|
|
70
|
-
return new WebSqlBridgeToSQLCommand(this.db);
|
|
71
|
-
}
|
|
72
|
-
async transaction(action) {
|
|
73
|
-
throw new Error("Method not implemented.");
|
|
74
|
-
}
|
|
75
|
-
addColumnSqlSyntax(x, dbName) {
|
|
76
|
-
let result = dbName;
|
|
77
|
-
const nullNumber = x.allowNull ? "" : " default 0 not null";
|
|
78
|
-
if (x.valueType == Date)
|
|
79
|
-
result += " integer";
|
|
80
|
-
else if (x.valueType == Boolean)
|
|
81
|
-
result += " integer " + nullNumber;
|
|
82
|
-
else if (x.valueType == Number) {
|
|
83
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
84
|
-
result += ' real ' + nullNumber;
|
|
85
|
-
else
|
|
86
|
-
result += ' ' + x.valueConverter.fieldTypeInDb + ' ' + nullNumber;
|
|
87
|
-
}
|
|
88
|
-
else
|
|
89
|
-
result += " text" + (x.allowNull ? " " : " default '' not null ");
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
toString() { return "WebSqlDataProvider"; }
|
|
93
|
-
}
|
|
94
|
-
class WebSqlBridgeToSQLCommand {
|
|
95
|
-
source;
|
|
96
|
-
//@ts-ignore
|
|
97
|
-
constructor(source) {
|
|
98
|
-
this.source = source;
|
|
99
|
-
}
|
|
100
|
-
values = [];
|
|
101
|
-
addParameterAndReturnSqlToken(val) {
|
|
102
|
-
this.values.push(val);
|
|
103
|
-
return '~' + this.values.length + '~';
|
|
104
|
-
}
|
|
105
|
-
execute(sql) {
|
|
106
|
-
return new Promise((resolve, reject) => this.source.transaction(t => {
|
|
107
|
-
let s = sql;
|
|
108
|
-
let v = [];
|
|
109
|
-
var m = s.match(/~\d+~/g);
|
|
110
|
-
if (m != null)
|
|
111
|
-
m.forEach(mr => {
|
|
112
|
-
s = s.replace(mr, '?');
|
|
113
|
-
v.push(this.values[Number.parseInt(mr.substring(1, mr.length - 1)) - 1]);
|
|
114
|
-
});
|
|
115
|
-
t.executeSql(s, v, (t1, r) => resolve(new WebSqlBridgeToSQLQueryResult(r)), (t2, err) => {
|
|
116
|
-
reject(err.message);
|
|
117
|
-
return undefined;
|
|
118
|
-
});
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
class WebSqlBridgeToSQLQueryResult {
|
|
123
|
-
r;
|
|
124
|
-
getColumnKeyInResultForIndexInSelect(index) {
|
|
125
|
-
if (this.rows.length == 0)
|
|
126
|
-
return undefined;
|
|
127
|
-
let i = 0;
|
|
128
|
-
for (let m in this.rows[0]) {
|
|
129
|
-
if (i++ == index)
|
|
130
|
-
return m;
|
|
131
|
-
}
|
|
132
|
-
return undefined;
|
|
133
|
-
}
|
|
134
|
-
//@ts-ignore
|
|
135
|
-
constructor(r) {
|
|
136
|
-
this.r = r;
|
|
137
|
-
this.rows = [];
|
|
138
|
-
for (let i = 0; i < r.rows.length; i++) {
|
|
139
|
-
this.rows.push(r.rows.item(i));
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
rows;
|
|
143
|
-
}
|
package/esm/core/src/entity.d.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Allowed, AllowedForInstance } from "./context";
|
|
2
|
-
import { FieldMetadata } from './column-interfaces';
|
|
3
|
-
import { EntityOrderBy, FieldsMetadata, EntityFilter, EntityRef, EntityMetadata } from "./remult3";
|
|
4
|
-
export interface EntityOptions<entityType = any> {
|
|
5
|
-
/**A human readable name for the entity */
|
|
6
|
-
caption?: string;
|
|
7
|
-
/**
|
|
8
|
-
* Determines if this Entity is available for get requests using Rest Api
|
|
9
|
-
* @description
|
|
10
|
-
* Determines if one has any access to the data of an entity.
|
|
11
|
-
* @see [allowed](http://remult.dev/docs/allowed.html)
|
|
12
|
-
* @see to restrict data based on a criteria, use [apiPrefilter](https://remult.dev/docs/ref_entity.html#apiprefilter)
|
|
13
|
-
* */
|
|
14
|
-
allowApiRead?: Allowed;
|
|
15
|
-
/**
|
|
16
|
-
* Determines if this entity can be updated through the api.
|
|
17
|
-
* @see [allowed](http://remult.dev/docs/allowed.html)*/
|
|
18
|
-
allowApiUpdate?: AllowedForInstance<entityType>;
|
|
19
|
-
/** Determines if entries for this entity can be deleted through the api.
|
|
20
|
-
* @see [allowed](http://remult.dev/docs/allowed.html)*/
|
|
21
|
-
allowApiDelete?: AllowedForInstance<entityType>;
|
|
22
|
-
/** Determines if new entries for this entity can be posted through the api.
|
|
23
|
-
* @see [allowed](http://remult.dev/docs/allowed.html)*/
|
|
24
|
-
allowApiInsert?: AllowedForInstance<entityType>;
|
|
25
|
-
/** sets the `allowApiUpdate`, `allowApiDelete` and `allowApiInsert` properties in a single set */
|
|
26
|
-
allowApiCrud?: Allowed;
|
|
27
|
-
/** A filter that determines which rows can be queries using the api.
|
|
28
|
-
* @description
|
|
29
|
-
* Use apiPrefilter in cases where you to restrict data based on user profile
|
|
30
|
-
* @example
|
|
31
|
-
* apiPrefilter: { archive:false }
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* apiPrefilter: ()=> remult.isAllowed("admin")?{}:{ archive:false }
|
|
35
|
-
* @see [EntityFilter](http://remult.dev/docs/entityFilter.html)
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
apiPrefilter?: EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>);
|
|
39
|
-
/** A filter that will be used for all queries from this entity both from the API and from within the backend.
|
|
40
|
-
* @example
|
|
41
|
-
* backendPrefilter: { archive:false }
|
|
42
|
-
* @see [EntityFilter](http://remult.dev/docs/entityFilter.html)
|
|
43
|
-
*/
|
|
44
|
-
backendPrefilter?: EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>);
|
|
45
|
-
/** An order by to be used, in case no order by was specified
|
|
46
|
-
* @example
|
|
47
|
-
* defaultOrderBy: { name: "asc" }
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* defaultOrderBy: { price: "desc", name: "asc" }
|
|
51
|
-
*/
|
|
52
|
-
defaultOrderBy?: EntityOrderBy<entityType>;
|
|
53
|
-
/** An event that will be fired before the Entity will be saved to the database.
|
|
54
|
-
* If the `error` property of the entity's ref or any of its fields will be set, the save will be aborted and an exception will be thrown.
|
|
55
|
-
* this is the place to run logic that we want to run in any case before an entity is saved.
|
|
56
|
-
* @example
|
|
57
|
-
* @Entity<Task>("tasks", {
|
|
58
|
-
* saving: async task => {
|
|
59
|
-
* task.lastUpdated = new Date()
|
|
60
|
-
* }
|
|
61
|
-
*})
|
|
62
|
-
*/
|
|
63
|
-
saving?: (row: entityType, proceedWithoutSavingToDb: () => void) => Promise<any> | any;
|
|
64
|
-
/** will be called after the Entity was saved to the data source. */
|
|
65
|
-
saved?: (row: entityType) => Promise<any> | any;
|
|
66
|
-
/** Will be called before an Entity is deleted. */
|
|
67
|
-
deleting?: (row: entityType) => Promise<any> | any;
|
|
68
|
-
/** Will be called after an Entity is deleted */
|
|
69
|
-
deleted?: (row: entityType) => Promise<any> | any;
|
|
70
|
-
/** Will be called when the entity is being validated, usually prior to the `saving` event */
|
|
71
|
-
validation?: (row: entityType, ref: EntityRef<entityType>) => Promise<any> | any;
|
|
72
|
-
/** The name of the table in the database that holds the data for this entity.
|
|
73
|
-
* If no name is set, the `key` will be used instead.
|
|
74
|
-
* @example
|
|
75
|
-
* dbName:'myProducts'
|
|
76
|
-
*/
|
|
77
|
-
dbName?: string;
|
|
78
|
-
/** For entities that are based on SQL expressions instead of a physical table or view*/
|
|
79
|
-
sqlExpression?: string | ((entity: EntityMetadata<entityType>) => string | Promise<string>);
|
|
80
|
-
/** An arrow function that identifies the `id` column to use for this entity
|
|
81
|
-
* @example
|
|
82
|
-
* //Single column id
|
|
83
|
-
* @Entity<Products>("products", { id:p=>p.productCode })
|
|
84
|
-
* @example
|
|
85
|
-
* //Multiple columns id
|
|
86
|
-
* @Entity<OrderDetails>("orderDetails", { id:od=> [od.orderId, od.productCode] })
|
|
87
|
-
*/
|
|
88
|
-
id?: (entity: FieldsMetadata<entityType>) => FieldMetadata | FieldMetadata[];
|
|
89
|
-
entityRefInit?: (ref: EntityRef<entityType>, row: entityType) => void;
|
|
90
|
-
apiRequireId?: Allowed;
|
|
91
|
-
}
|
package/esm/core/src/entity.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|