remult 0.22.7-exp.0 → 0.22.7
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/SseSubscriptionServer.d.ts +25 -25
- package/SseSubscriptionServer.js +145 -145
- package/ably.d.ts +13 -13
- package/ably.js +59 -59
- package/assign.d.ts +1 -1
- package/assign.js +9 -9
- package/classType.d.ts +3 -3
- package/classType.js +2 -2
- package/esm/SseSubscriptionServer.d.ts +25 -25
- package/esm/SseSubscriptionServer.js +107 -104
- package/esm/ably.d.ts +13 -13
- package/esm/ably.js +30 -28
- package/esm/assign.d.ts +1 -1
- package/esm/assign.js +5 -5
- package/esm/classType.d.ts +3 -3
- package/esm/classType.js +1 -1
- package/esm/graphql.d.ts +14 -14
- package/esm/graphql.js +785 -785
- package/esm/index.d.ts +31 -31
- package/esm/index.js +25 -25
- package/esm/inputTypes.d.ts +9 -9
- package/esm/inputTypes.js +9 -9
- package/esm/live-query/data-provider-live-query-storage.d.ts +23 -23
- package/esm/live-query/data-provider-live-query-storage.js +91 -93
- package/esm/myLog.d.ts +1 -1
- package/esm/myLog.js +5 -5
- package/esm/postgres/index.d.ts +2 -2
- package/esm/postgres/index.js +2 -2
- package/esm/postgres/postgres-data-provider.d.ts +36 -36
- package/esm/postgres/postgres-data-provider.js +126 -122
- package/esm/postgres/schema-builder.d.ts +19 -19
- package/esm/postgres/schema-builder.js +197 -196
- package/esm/remult-express.d.ts +9 -9
- package/esm/remult-express.js +26 -25
- package/esm/remult-fastify.d.ts +6 -6
- package/esm/remult-fastify.js +68 -68
- package/esm/remult-fresh.d.ts +17 -17
- package/esm/remult-fresh.js +26 -26
- package/esm/remult-knex/index.d.ts +30 -30
- package/esm/remult-knex/index.js +466 -460
- package/esm/remult-mongo.d.ts +24 -24
- package/esm/remult-mongo.js +269 -262
- package/esm/remult-next.d.ts +25 -25
- package/esm/remult-next.js +114 -114
- package/esm/remult-sveltekit.d.ts +4 -4
- package/esm/remult-sveltekit.js +71 -71
- package/esm/server/JsonEntityFileStorage.d.ts +11 -11
- package/esm/server/JsonEntityFileStorage.js +27 -26
- package/esm/server/core.d.ts +4 -4
- package/esm/server/core.js +4 -4
- package/esm/server/expressBridge.d.ts +128 -128
- package/esm/server/expressBridge.js +988 -971
- package/esm/server/index.d.ts +6 -6
- package/esm/server/index.js +12 -12
- package/esm/server/initAsyncHooks.d.ts +1 -1
- package/esm/server/initAsyncHooks.js +9 -9
- package/esm/server/initDataProvider.d.ts +2 -2
- package/esm/server/initDataProvider.js +14 -14
- package/esm/src/CompoundIdField.d.ts +27 -27
- package/esm/src/CompoundIdField.js +54 -41
- package/esm/src/__EntityValueProvider.d.ts +11 -11
- package/esm/src/__EntityValueProvider.js +1 -1
- package/esm/src/__RowsOfDataForTesting.d.ts +3 -3
- package/esm/src/__RowsOfDataForTesting.js +1 -1
- package/esm/src/buildRestDataProvider.d.ts +31 -31
- package/esm/src/buildRestDataProvider.js +121 -120
- package/esm/src/column-interfaces.d.ts +160 -160
- package/esm/src/column-interfaces.js +7 -7
- package/esm/src/column.d.ts +31 -31
- package/esm/src/column.js +108 -101
- package/esm/src/context.d.ts +134 -134
- package/esm/src/context.js +287 -282
- package/esm/src/data-api.d.ts +38 -38
- package/esm/src/data-api.js +281 -279
- package/esm/src/data-interfaces.d.ts +41 -41
- package/esm/src/data-interfaces.js +12 -12
- package/esm/src/data-providers/array-entity-data-provider.d.ts +22 -22
- package/esm/src/data-providers/array-entity-data-provider.js +252 -249
- package/esm/src/data-providers/in-memory-database.d.ts +9 -9
- package/esm/src/data-providers/in-memory-database.js +16 -18
- package/esm/src/data-providers/json-data-provider.d.ts +12 -12
- package/esm/src/data-providers/json-data-provider.js +55 -52
- package/esm/src/data-providers/rest-data-provider.d.ts +39 -39
- package/esm/src/data-providers/rest-data-provider.js +272 -267
- package/esm/src/data-providers/sql-database.d.ts +33 -33
- package/esm/src/data-providers/sql-database.js +401 -394
- package/esm/src/data-providers/web-sql-data-provider.d.ts +21 -21
- package/esm/src/data-providers/web-sql-data-provider.js +145 -137
- package/esm/src/entity.d.ts +95 -95
- package/esm/src/entity.js +1 -1
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -50
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +165 -162
- package/esm/src/filter/filter-interfaces.d.ts +86 -86
- package/esm/src/filter/filter-interfaces.js +524 -515
- package/esm/src/live-query/LiveQueryClient.d.ts +1 -1
- package/esm/src/live-query/LiveQueryClient.js +196 -192
- package/esm/src/live-query/SseSubscriptionClient.d.ts +5 -5
- package/esm/src/live-query/SseSubscriptionClient.js +86 -86
- package/esm/src/live-query/SubscriptionChannel.d.ts +41 -41
- package/esm/src/live-query/SubscriptionChannel.js +126 -121
- package/esm/src/live-query/SubscriptionServer.d.ts +38 -38
- package/esm/src/live-query/SubscriptionServer.js +114 -112
- package/esm/src/remult-proxy.d.ts +2 -2
- package/esm/src/remult-proxy.js +177 -178
- package/esm/src/remult3/DecoratorReplacer.d.ts +10 -10
- package/esm/src/remult3/DecoratorReplacer.js +20 -20
- package/esm/src/remult3/RepositoryImplementation.d.ts +332 -332
- package/esm/src/remult3/RepositoryImplementation.js +2122 -2051
- package/esm/src/remult3/__updateEntityBasedOnWhere.d.ts +2 -2
- package/esm/src/remult3/__updateEntityBasedOnWhere.js +24 -24
- package/esm/src/remult3/entity.d.ts +28 -28
- package/esm/src/remult3/entity.js +70 -70
- package/esm/src/remult3/getEntityRef.d.ts +9 -9
- package/esm/src/remult3/getEntityRef.js +27 -27
- package/esm/src/remult3/remult3.d.ts +397 -397
- package/esm/src/remult3/remult3.js +1 -1
- package/esm/src/resultCompoundIdFilter.d.ts +3 -3
- package/esm/src/resultCompoundIdFilter.js +16 -16
- package/esm/src/server-action-info.d.ts +10 -10
- package/esm/src/server-action-info.js +12 -12
- package/esm/src/server-action.d.ts +79 -79
- package/esm/src/server-action.js +397 -387
- package/esm/src/sort.d.ts +16 -16
- package/esm/src/sort.js +105 -104
- package/esm/src/sql-command.d.ts +19 -19
- package/esm/src/sql-command.js +1 -1
- package/esm/src/validators.d.ts +14 -14
- package/esm/src/validators.js +36 -36
- package/esm/src/valueConverters.d.ts +13 -13
- package/esm/src/valueConverters.js +210 -210
- package/esm/urlBuilder.d.ts +6 -6
- package/esm/urlBuilder.js +20 -19
- package/graphql.d.ts +14 -14
- package/graphql.js +953 -953
- package/index.d.ts +31 -31
- package/index.js +67 -67
- package/inputTypes.d.ts +9 -9
- package/inputTypes.js +16 -16
- package/live-query/data-provider-live-query-storage.d.ts +23 -23
- package/live-query/data-provider-live-query-storage.js +263 -263
- package/myLog.d.ts +1 -1
- package/myLog.js +20 -20
- package/package.json +1 -1
- package/postgres/index.d.ts +2 -2
- package/postgres/index.js +5 -5
- package/postgres/postgres-data-provider.d.ts +36 -36
- package/postgres/postgres-data-provider.js +191 -191
- package/postgres/schema-builder.d.ts +19 -19
- package/postgres/schema-builder.js +369 -369
- package/remult-express.d.ts +9 -9
- package/remult-express.js +34 -33
- package/remult-fastify.d.ts +6 -6
- package/remult-fastify.js +79 -79
- package/remult-fresh.d.ts +17 -17
- package/remult-fresh.js +41 -41
- package/remult-knex/index.d.ts +30 -30
- package/remult-knex/index.js +917 -915
- package/remult-mongo.d.ts +24 -24
- package/remult-mongo.js +515 -515
- package/remult-next.d.ts +25 -25
- package/remult-next.js +171 -171
- package/remult-sveltekit.d.ts +4 -4
- package/remult-sveltekit.js +110 -110
- package/server/JsonEntityFileStorage.d.ts +11 -11
- package/server/JsonEntityFileStorage.js +35 -35
- package/server/core.d.ts +4 -4
- package/server/core.js +12 -12
- package/server/expressBridge.d.ts +128 -128
- package/server/expressBridge.js +1401 -1402
- package/server/index.d.ts +6 -6
- package/server/index.js +24 -24
- package/server/initAsyncHooks.d.ts +1 -1
- package/server/initAsyncHooks.js +13 -13
- package/server/initDataProvider.d.ts +2 -2
- package/server/initDataProvider.js +26 -26
- package/src/CompoundIdField.d.ts +27 -27
- package/src/CompoundIdField.js +54 -54
- package/src/__EntityValueProvider.d.ts +11 -11
- package/src/__EntityValueProvider.js +2 -2
- package/src/__RowsOfDataForTesting.d.ts +3 -3
- package/src/__RowsOfDataForTesting.js +2 -2
- package/src/buildRestDataProvider.d.ts +31 -31
- package/src/buildRestDataProvider.js +177 -174
- package/src/column-interfaces.d.ts +160 -160
- package/src/column-interfaces.js +11 -11
- package/src/column.d.ts +31 -31
- package/src/column.js +132 -132
- package/src/context.d.ts +134 -134
- package/src/context.js +451 -451
- package/src/data-api.d.ts +38 -38
- package/src/data-api.js +524 -524
- package/src/data-interfaces.d.ts +41 -41
- package/src/data-interfaces.js +16 -16
- package/src/data-providers/array-entity-data-provider.d.ts +22 -22
- package/src/data-providers/array-entity-data-provider.js +364 -364
- package/src/data-providers/in-memory-database.d.ts +9 -9
- package/src/data-providers/in-memory-database.js +33 -33
- package/src/data-providers/json-data-provider.d.ts +12 -12
- package/src/data-providers/json-data-provider.js +106 -106
- package/src/data-providers/rest-data-provider.d.ts +39 -39
- package/src/data-providers/rest-data-provider.js +388 -388
- package/src/data-providers/sql-database.d.ts +33 -33
- package/src/data-providers/sql-database.js +653 -653
- package/src/data-providers/web-sql-data-provider.d.ts +21 -21
- package/src/data-providers/web-sql-data-provider.js +229 -229
- package/src/entity.d.ts +95 -95
- package/src/entity.js +2 -2
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -50
- package/src/filter/filter-consumer-bridge-to-sql-request.js +307 -307
- package/src/filter/filter-interfaces.d.ts +86 -86
- package/src/filter/filter-interfaces.js +693 -685
- package/src/live-query/LiveQueryClient.d.ts +1 -1
- package/src/live-query/LiveQueryClient.js +293 -293
- package/src/live-query/SseSubscriptionClient.d.ts +5 -5
- package/src/live-query/SseSubscriptionClient.js +154 -154
- package/src/live-query/SubscriptionChannel.d.ts +41 -41
- package/src/live-query/SubscriptionChannel.js +189 -189
- package/src/live-query/SubscriptionServer.d.ts +38 -38
- package/src/live-query/SubscriptionServer.js +264 -264
- package/src/remult-proxy.d.ts +2 -2
- package/src/remult-proxy.js +307 -307
- package/src/remult3/DecoratorReplacer.d.ts +10 -10
- package/src/remult3/DecoratorReplacer.js +24 -24
- package/src/remult3/RepositoryImplementation.d.ts +332 -332
- package/src/remult3/RepositoryImplementation.js +3391 -3373
- package/src/remult3/__updateEntityBasedOnWhere.d.ts +2 -2
- package/src/remult3/__updateEntityBasedOnWhere.js +28 -28
- package/src/remult3/entity.d.ts +28 -28
- package/src/remult3/entity.js +88 -88
- package/src/remult3/getEntityRef.d.ts +9 -9
- package/src/remult3/getEntityRef.js +35 -35
- package/src/remult3/remult3.d.ts +397 -397
- package/src/remult3/remult3.js +2 -2
- package/src/resultCompoundIdFilter.d.ts +3 -3
- package/src/resultCompoundIdFilter.js +20 -20
- package/src/server-action-info.d.ts +10 -10
- package/src/server-action-info.js +15 -15
- package/src/server-action.d.ts +79 -79
- package/src/server-action.js +632 -632
- package/src/sort.d.ts +16 -16
- package/src/sort.js +161 -161
- package/src/sql-command.d.ts +19 -19
- package/src/sql-command.js +2 -2
- package/src/validators.d.ts +14 -14
- package/src/validators.js +71 -69
- package/src/valueConverters.d.ts +13 -13
- package/src/valueConverters.js +213 -213
- package/urlBuilder.d.ts +6 -6
- package/urlBuilder.js +25 -25
package/esm/remult-mongo.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { ClientSession, Db, MongoClient } from 'mongodb';
|
|
2
|
-
import type { DataProvider, EntityDataProvider, EntityFilter, EntityMetadata, Remult } from '.';
|
|
3
|
-
import type { RepositoryOverloads } from './src/remult3/RepositoryImplementation';
|
|
4
|
-
export declare class MongoDataProvider implements DataProvider {
|
|
5
|
-
private db;
|
|
6
|
-
private client;
|
|
7
|
-
constructor(db: Db, client: MongoClient, options?: {
|
|
8
|
-
session?: ClientSession;
|
|
9
|
-
disableTransactions?: boolean;
|
|
10
|
-
});
|
|
11
|
-
session?: ClientSession;
|
|
12
|
-
disableTransactions: boolean;
|
|
13
|
-
static getDb(remult?: Remult): {
|
|
14
|
-
db: Db;
|
|
15
|
-
session: ClientSession;
|
|
16
|
-
};
|
|
17
|
-
getEntityDataProvider(entity: EntityMetadata<any>): EntityDataProvider;
|
|
18
|
-
transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
|
|
19
|
-
static filterToRaw<entityType>(entity: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>): Promise<{
|
|
20
|
-
$and: any[];
|
|
21
|
-
} | {
|
|
22
|
-
$and?: undefined;
|
|
23
|
-
}>;
|
|
24
|
-
}
|
|
1
|
+
import type { ClientSession, Db, MongoClient } from 'mongodb';
|
|
2
|
+
import type { DataProvider, EntityDataProvider, EntityFilter, EntityMetadata, Remult } from '.';
|
|
3
|
+
import type { RepositoryOverloads } from './src/remult3/RepositoryImplementation';
|
|
4
|
+
export declare class MongoDataProvider implements DataProvider {
|
|
5
|
+
private db;
|
|
6
|
+
private client;
|
|
7
|
+
constructor(db: Db, client: MongoClient, options?: {
|
|
8
|
+
session?: ClientSession;
|
|
9
|
+
disableTransactions?: boolean;
|
|
10
|
+
});
|
|
11
|
+
session?: ClientSession;
|
|
12
|
+
disableTransactions: boolean;
|
|
13
|
+
static getDb(remult?: Remult): {
|
|
14
|
+
db: Db;
|
|
15
|
+
session: ClientSession;
|
|
16
|
+
};
|
|
17
|
+
getEntityDataProvider(entity: EntityMetadata<any>): EntityDataProvider;
|
|
18
|
+
transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
|
|
19
|
+
static filterToRaw<entityType>(entity: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>): Promise<{
|
|
20
|
+
$and: any[];
|
|
21
|
+
} | {
|
|
22
|
+
$and?: undefined;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
package/esm/remult-mongo.js
CHANGED
|
@@ -1,262 +1,269 @@
|
|
|
1
|
-
import { CompoundIdField, Filter } from '.';
|
|
2
|
-
import { dbNamesOf } from './src/filter/filter-consumer-bridge-to-sql-request';
|
|
3
|
-
import { remult as remultContext } from './src/remult-proxy';
|
|
4
|
-
import { getRepository } from './src/remult3/RepositoryImplementation';
|
|
5
|
-
import { resultCompoundIdFilter } from './src/resultCompoundIdFilter';
|
|
6
|
-
export class MongoDataProvider {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
await session.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
let
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (options
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
if (options.
|
|
106
|
-
op.
|
|
107
|
-
|
|
108
|
-
op.
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
async
|
|
151
|
-
|
|
152
|
-
let
|
|
153
|
-
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
this.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
this.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}));
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
//
|
|
260
|
-
//
|
|
261
|
-
|
|
262
|
-
|
|
1
|
+
import { CompoundIdField, Filter } from '.';
|
|
2
|
+
import { dbNamesOf } from './src/filter/filter-consumer-bridge-to-sql-request';
|
|
3
|
+
import { remult as remultContext } from './src/remult-proxy';
|
|
4
|
+
import { getRepository } from './src/remult3/RepositoryImplementation';
|
|
5
|
+
import { resultCompoundIdFilter } from './src/resultCompoundIdFilter';
|
|
6
|
+
export class MongoDataProvider {
|
|
7
|
+
db;
|
|
8
|
+
client;
|
|
9
|
+
constructor(db, client, options) {
|
|
10
|
+
this.db = db;
|
|
11
|
+
this.client = client;
|
|
12
|
+
this.session = options?.session;
|
|
13
|
+
this.disableTransactions = options?.disableTransactions;
|
|
14
|
+
}
|
|
15
|
+
session;
|
|
16
|
+
disableTransactions = false;
|
|
17
|
+
static getDb(remult) {
|
|
18
|
+
const r = (remult || remultContext).dataProvider;
|
|
19
|
+
if (!r.db)
|
|
20
|
+
throw 'the data provider is not a MongoDataProvider';
|
|
21
|
+
return { db: r.db, session: r.session };
|
|
22
|
+
}
|
|
23
|
+
getEntityDataProvider(entity) {
|
|
24
|
+
return new MongoEntityDataProvider(this.db, entity, this.session);
|
|
25
|
+
}
|
|
26
|
+
async transaction(action) {
|
|
27
|
+
if (this.disableTransactions) {
|
|
28
|
+
await action(this);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
let session = await this.client.startSession();
|
|
32
|
+
session.startTransaction();
|
|
33
|
+
const db = this.client.db(this.db.databaseName);
|
|
34
|
+
try {
|
|
35
|
+
await action(new MongoDataProvider(db, undefined, { session }));
|
|
36
|
+
await session.commitTransaction();
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
await session.abortTransaction();
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
await session.endSession();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
static async filterToRaw(entity, condition) {
|
|
48
|
+
const repo = getRepository(entity);
|
|
49
|
+
var b = new FilterConsumerBridgeToMongo(await dbNamesOf(repo.metadata));
|
|
50
|
+
b._addWhere = false;
|
|
51
|
+
await (await repo.translateWhereToFilter(condition)).__applyToConsumer(b);
|
|
52
|
+
let r = await b.resolveWhere();
|
|
53
|
+
return r;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const NULL = { $null: '$null' };
|
|
57
|
+
function isNull(x) {
|
|
58
|
+
return x?.$null === NULL.$null;
|
|
59
|
+
}
|
|
60
|
+
class MongoEntityDataProvider {
|
|
61
|
+
db;
|
|
62
|
+
entity;
|
|
63
|
+
session;
|
|
64
|
+
constructor(db, entity, session) {
|
|
65
|
+
this.db = db;
|
|
66
|
+
this.entity = entity;
|
|
67
|
+
this.session = session;
|
|
68
|
+
}
|
|
69
|
+
translateFromDb(row, nameProvider) {
|
|
70
|
+
let result = {};
|
|
71
|
+
for (const col of this.entity.fields) {
|
|
72
|
+
let val = row[nameProvider.$dbNameOf(col)];
|
|
73
|
+
if (isNull(val))
|
|
74
|
+
val = null;
|
|
75
|
+
result[col.key] = col.valueConverter.fromDb(val);
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
translateToDb(row, nameProvider) {
|
|
80
|
+
let result = {};
|
|
81
|
+
for (const col of this.entity.fields) {
|
|
82
|
+
let val = col.valueConverter.toDb(row[col.key]);
|
|
83
|
+
if (val === null)
|
|
84
|
+
val = NULL;
|
|
85
|
+
result[nameProvider.$dbNameOf(col)] = val;
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
async count(where) {
|
|
90
|
+
const { collection, e } = await this.collection();
|
|
91
|
+
let x = new FilterConsumerBridgeToMongo(e);
|
|
92
|
+
where.__applyToConsumer(x);
|
|
93
|
+
let w = await x.resolveWhere();
|
|
94
|
+
return await collection.countDocuments(w, { session: this.session });
|
|
95
|
+
}
|
|
96
|
+
async find(options) {
|
|
97
|
+
let { collection, e } = await this.collection();
|
|
98
|
+
let x = new FilterConsumerBridgeToMongo(e);
|
|
99
|
+
if (options?.where)
|
|
100
|
+
options.where.__applyToConsumer(x);
|
|
101
|
+
let where = await x.resolveWhere();
|
|
102
|
+
let op = {
|
|
103
|
+
session: this.session,
|
|
104
|
+
};
|
|
105
|
+
if (options.limit) {
|
|
106
|
+
op.limit = options.limit;
|
|
107
|
+
if (options.page) {
|
|
108
|
+
op.skip = (options.page - 1) * options.limit;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (options.orderBy) {
|
|
112
|
+
op.sort = {};
|
|
113
|
+
for (const s of options.orderBy.Segments) {
|
|
114
|
+
op.sort[e.$dbNameOf(s.field)] = s.isDescending ? -1 : 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return await Promise.all(await collection
|
|
118
|
+
.find(where, op)
|
|
119
|
+
.map((x) => this.translateFromDb(x, e))
|
|
120
|
+
.toArray());
|
|
121
|
+
}
|
|
122
|
+
async update(id, data) {
|
|
123
|
+
let { collection, e } = await this.collection();
|
|
124
|
+
let f = new FilterConsumerBridgeToMongo(e);
|
|
125
|
+
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
126
|
+
let resultFilter = this.entity.idMetadata.getIdFilter(id);
|
|
127
|
+
if (data.id != undefined)
|
|
128
|
+
resultFilter = this.entity.idMetadata.getIdFilter(data.id);
|
|
129
|
+
for (const x of this.entity.fields) {
|
|
130
|
+
if (x instanceof CompoundIdField) {
|
|
131
|
+
resultFilter = resultCompoundIdFilter(x, id, data);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let newR = {};
|
|
135
|
+
let keys = Object.keys(data);
|
|
136
|
+
for (const f of this.entity.fields) {
|
|
137
|
+
if (!f.dbReadOnly && !f.isServerExpression) {
|
|
138
|
+
if (keys.includes(f.key)) {
|
|
139
|
+
newR[f.key] = f.valueConverter.toDb(data[f.key]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
let r = await collection.updateOne(await f.resolveWhere(), {
|
|
144
|
+
$set: newR,
|
|
145
|
+
}, { session: this.session });
|
|
146
|
+
return this.find({
|
|
147
|
+
where: Filter.fromEntityFilter(this.entity, resultFilter),
|
|
148
|
+
}).then((y) => y[0]);
|
|
149
|
+
}
|
|
150
|
+
async delete(id) {
|
|
151
|
+
const { e, collection } = await this.collection();
|
|
152
|
+
let f = new FilterConsumerBridgeToMongo(e);
|
|
153
|
+
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
154
|
+
collection.deleteOne(await f.resolveWhere(), { session: this.session });
|
|
155
|
+
}
|
|
156
|
+
async insert(data) {
|
|
157
|
+
let { collection, e } = await this.collection();
|
|
158
|
+
let r = await collection.insertOne(await this.translateToDb(data, e), {
|
|
159
|
+
session: this.session,
|
|
160
|
+
});
|
|
161
|
+
return await this.translateFromDb(await collection.findOne({ _id: r.insertedId }, { session: this.session }), e);
|
|
162
|
+
}
|
|
163
|
+
async collection() {
|
|
164
|
+
const e = await dbNamesOf(this.entity);
|
|
165
|
+
const collection = this.db.collection(e.$entityName);
|
|
166
|
+
return { e, collection };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
class FilterConsumerBridgeToMongo {
|
|
170
|
+
nameProvider;
|
|
171
|
+
_addWhere = true;
|
|
172
|
+
promises = [];
|
|
173
|
+
result = [];
|
|
174
|
+
async resolveWhere() {
|
|
175
|
+
while (this.promises.length > 0) {
|
|
176
|
+
let p = this.promises;
|
|
177
|
+
this.promises = [];
|
|
178
|
+
for (const pr of p) {
|
|
179
|
+
await pr;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (this.result.length > 0)
|
|
183
|
+
return { $and: this.result.map((x) => x()) };
|
|
184
|
+
else
|
|
185
|
+
return {};
|
|
186
|
+
}
|
|
187
|
+
constructor(nameProvider) {
|
|
188
|
+
this.nameProvider = nameProvider;
|
|
189
|
+
}
|
|
190
|
+
custom(key, customItem) {
|
|
191
|
+
throw new Error('Custom filter should be translated before it gets here');
|
|
192
|
+
}
|
|
193
|
+
or(orElements) {
|
|
194
|
+
this.promises.push((async () => {
|
|
195
|
+
let result = [];
|
|
196
|
+
for (const element of orElements) {
|
|
197
|
+
let f = new FilterConsumerBridgeToMongo(this.nameProvider);
|
|
198
|
+
f._addWhere = false;
|
|
199
|
+
element.__applyToConsumer(f);
|
|
200
|
+
let where = await f.resolveWhere();
|
|
201
|
+
if (where?.$and?.length > 0) {
|
|
202
|
+
result.push(where);
|
|
203
|
+
}
|
|
204
|
+
else
|
|
205
|
+
return; //since empty or is all rows;
|
|
206
|
+
}
|
|
207
|
+
this.result.push(() => ({
|
|
208
|
+
$or: result,
|
|
209
|
+
}));
|
|
210
|
+
})());
|
|
211
|
+
}
|
|
212
|
+
isNull(col) {
|
|
213
|
+
this.add(col, NULL, '$eq');
|
|
214
|
+
}
|
|
215
|
+
isNotNull(col) {
|
|
216
|
+
this.add(col, NULL, '$ne');
|
|
217
|
+
}
|
|
218
|
+
isIn(col, val) {
|
|
219
|
+
this.result.push(() => ({
|
|
220
|
+
[this.nameProvider.$dbNameOf(col)]: {
|
|
221
|
+
$in: val.map((x) => col.valueConverter.toDb(x)),
|
|
222
|
+
},
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
isEqualTo(col, val) {
|
|
226
|
+
this.add(col, val, '$eq');
|
|
227
|
+
}
|
|
228
|
+
isDifferentFrom(col, val) {
|
|
229
|
+
this.add(col, val, '$ne');
|
|
230
|
+
}
|
|
231
|
+
isGreaterOrEqualTo(col, val) {
|
|
232
|
+
this.add(col, val, '$gte');
|
|
233
|
+
}
|
|
234
|
+
isGreaterThan(col, val) {
|
|
235
|
+
this.add(col, val, '$gt');
|
|
236
|
+
}
|
|
237
|
+
isLessOrEqualTo(col, val) {
|
|
238
|
+
this.add(col, val, '$lte');
|
|
239
|
+
}
|
|
240
|
+
isLessThan(col, val) {
|
|
241
|
+
this.add(col, val, '$lt');
|
|
242
|
+
}
|
|
243
|
+
containsCaseInsensitive(col, val) {
|
|
244
|
+
this.add(col, val, '$regex');
|
|
245
|
+
// this.promises.push(col.getDbName().then(colName => {
|
|
246
|
+
// this.result.push(b => b.whereRaw(
|
|
247
|
+
// 'lower (' + colName + ") like lower ('%" + val.replace(/'/g, '\'\'') + "%')"));
|
|
248
|
+
// }));
|
|
249
|
+
}
|
|
250
|
+
add(col, val, operator) {
|
|
251
|
+
this.result.push(() => ({
|
|
252
|
+
[this.nameProvider.$dbNameOf(col)]: {
|
|
253
|
+
[operator]: isNull(val) ? val : col.valueConverter.toDb(val),
|
|
254
|
+
},
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
databaseCustom(databaseCustom) {
|
|
258
|
+
throw 'error';
|
|
259
|
+
// this.promises.push((async () => {
|
|
260
|
+
// if (databaseCustom?.buildSql) {
|
|
261
|
+
// let item = new CustomSqlFilterBuilder(this.knex);
|
|
262
|
+
// await databaseCustom.buildSql(item);
|
|
263
|
+
// if (item.sql) {
|
|
264
|
+
// this.addToWhere("(" + item.sql + ")");
|
|
265
|
+
// }
|
|
266
|
+
// }
|
|
267
|
+
// })());
|
|
268
|
+
}
|
|
269
|
+
}
|
package/esm/remult-next.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { GetServerSideProps, NextApiHandler, NextApiRequest, PreviewData } from 'next';
|
|
3
|
-
import type { ParsedUrlQuery } from 'querystring';
|
|
4
|
-
import type { RemultServerCore, RemultServerOptions } from './server';
|
|
5
|
-
export declare function remultNext(options?: RemultServerOptions<NextApiRequest>): RemultNextServer;
|
|
6
|
-
export
|
|
7
|
-
getServerSideProps<P extends {
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
} = {
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
}, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData>(getServerPropsFunction: GetServerSideProps<P, Q, D>): GetServerSideProps<P, Q, D>;
|
|
12
|
-
/** Creates a `next.js` handler with remult defined in the correct context
|
|
13
|
-
* @see
|
|
14
|
-
* https://remult.dev/tutorials/react-next/appendix-1-get-server-side-props.html#using-remult-in-a-next-js-api-handler
|
|
15
|
-
*/
|
|
16
|
-
handle<T>(handler: NextApiHandler<T>): NextApiHandler<T>;
|
|
17
|
-
};
|
|
18
|
-
export declare function remultNextApp(options?: RemultServerOptions<Request>): RemultNextAppServer;
|
|
19
|
-
export
|
|
20
|
-
GET: (req: Request) => Promise<Response>;
|
|
21
|
-
PUT: (req: Request) => Promise<Response>;
|
|
22
|
-
POST: (req: Request) => Promise<Response>;
|
|
23
|
-
DELETE: (req: Request) => Promise<Response>;
|
|
24
|
-
withRemult<T>(what: () => Promise<T>): Promise<T>;
|
|
25
|
-
};
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { GetServerSideProps, NextApiHandler, NextApiRequest, PreviewData } from 'next';
|
|
3
|
+
import type { ParsedUrlQuery } from 'querystring';
|
|
4
|
+
import type { RemultServerCore, RemultServerOptions } from './server';
|
|
5
|
+
export declare function remultNext(options?: RemultServerOptions<NextApiRequest>): RemultNextServer;
|
|
6
|
+
export type RemultNextServer = RemultServerCore<NextApiRequest> & NextApiHandler & {
|
|
7
|
+
getServerSideProps<P extends {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
} = {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData>(getServerPropsFunction: GetServerSideProps<P, Q, D>): GetServerSideProps<P, Q, D>;
|
|
12
|
+
/** Creates a `next.js` handler with remult defined in the correct context
|
|
13
|
+
* @see
|
|
14
|
+
* https://remult.dev/tutorials/react-next/appendix-1-get-server-side-props.html#using-remult-in-a-next-js-api-handler
|
|
15
|
+
*/
|
|
16
|
+
handle<T>(handler: NextApiHandler<T>): NextApiHandler<T>;
|
|
17
|
+
};
|
|
18
|
+
export declare function remultNextApp(options?: RemultServerOptions<Request>): RemultNextAppServer;
|
|
19
|
+
export type RemultNextAppServer = RemultServerCore<Request> & {
|
|
20
|
+
GET: (req: Request) => Promise<Response>;
|
|
21
|
+
PUT: (req: Request) => Promise<Response>;
|
|
22
|
+
POST: (req: Request) => Promise<Response>;
|
|
23
|
+
DELETE: (req: Request) => Promise<Response>;
|
|
24
|
+
withRemult<T>(what: () => Promise<T>): Promise<T>;
|
|
25
|
+
};
|