remult 0.20.0-exp.16 → 0.20.0-exp.18

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { RemultServer } from "./server/expressBridge";
2
- export declare function remultGraphql(api: RemultServer<any>): {
1
+ import { RemultExpressServer } from "./remult-express";
2
+ export declare function remultGraphql(api: RemultExpressServer): {
3
3
  rootValue: {};
4
4
  schema: string;
5
5
  };
@@ -28,4 +28,9 @@ export declare function createPostgresConnection(options?: {
28
28
  sslInDev?: boolean;
29
29
  configuration?: "heroku" | PoolConfig;
30
30
  }): Promise<SqlDatabase>;
31
+ export declare function createPostgresDataProvider(options?: {
32
+ connectionString?: string;
33
+ sslInDev?: boolean;
34
+ configuration?: "heroku" | PoolConfig;
35
+ }): Promise<SqlDatabase>;
31
36
  export declare function preparePostgresQueueStorage(sql: SqlDatabase): Promise<import("../server/expressBridge").EntityQueueStorage>;
@@ -37,6 +37,7 @@ export class PostgresDataProvider {
37
37
  entityIsUsedForTheFirstTime: this.entityIsUsedForTheFirstTime,
38
38
  transaction: () => { throw "nested transactions not allowed"; },
39
39
  getLimitSqlSyntax: this.getLimitSqlSyntax,
40
+ supportsJsonColumnType: this.supportsJsonColumnType,
40
41
  //@ts-ignore
41
42
  pool: client
42
43
  });
@@ -74,6 +75,9 @@ class PostgresBridgeToSQLQueryResult {
74
75
  }
75
76
  }
76
77
  export async function createPostgresConnection(options) {
78
+ return createPostgresDataProvider(options);
79
+ }
80
+ export async function createPostgresDataProvider(options) {
77
81
  if (!options)
78
82
  options = {};
79
83
  let config = {};
@@ -44,7 +44,7 @@ export interface RemultServerOptions<RequestType> {
44
44
  /** Used to store the context relevant info for re running a live query */
45
45
  contextSerializer?: {
46
46
  serialize(remult: Remult): Promise<any>;
47
- deserialize(json: any, remult: Remult): Promise<void>;
47
+ deserialize(json: any, options: InitRequestOptions): Promise<void>;
48
48
  };
49
49
  /** Storage to use for backend methods that use queue */
50
50
  queueStorage?: QueueStorage;
@@ -125,7 +125,15 @@ export class RemultServerImplementation {
125
125
  await this.runWithRemult(async (remult) => {
126
126
  remult.user = jsonContextData.user;
127
127
  if (this.options.contextSerializer) {
128
- await this.options.contextSerializer.deserialize(jsonContextData, remult);
128
+ await this.options.contextSerializer.deserialize(jsonContextData, {
129
+ remult,
130
+ get liveQueryStorage() {
131
+ return remult.liveQueryStorage;
132
+ },
133
+ set liveQueryStorage(value) {
134
+ remult.liveQueryStorage = value;
135
+ }
136
+ });
129
137
  }
130
138
  await what(remult.repo(e));
131
139
  });
@@ -5,8 +5,8 @@ export declare class DataApi<T = any> {
5
5
  private repository;
6
6
  private remult;
7
7
  constructor(repository: Repository<T>, remult: Remult);
8
- httpGet(res: DataApiResponse, req: DataApiRequest, serializeRequest: () => Promise<any>): Promise<void>;
9
- httpPost(res: DataApiResponse, req: DataApiRequest, body: any, serializeRequest: () => Promise<any>): Promise<void>;
8
+ httpGet(res: DataApiResponse, req: DataApiRequest, serializeContext: () => Promise<any>): Promise<void>;
9
+ httpPost(res: DataApiResponse, req: DataApiRequest, body: any, serializeContext: () => Promise<any>): Promise<void>;
10
10
  static defaultGetLimit: number;
11
11
  get(response: DataApiResponse, id: any): Promise<void>;
12
12
  count(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
@@ -15,7 +15,7 @@ export declare class DataApi<T = any> {
15
15
  findOptions: FindOptions<T>;
16
16
  }>;
17
17
  getArray(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
18
- liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any, serializeRequest: () => Promise<any>, queryChannel: string): Promise<void>;
18
+ liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any, serializeContext: () => Promise<any>, queryChannel: string): Promise<void>;
19
19
  private buildWhere;
20
20
  private doOnId;
21
21
  put(response: DataApiResponse, id: any, body: any): Promise<void>;
@@ -8,10 +8,10 @@ export class DataApi {
8
8
  this.repository = repository;
9
9
  this.remult = remult;
10
10
  }
11
- httpGet(res, req, serializeRequest) {
11
+ httpGet(res, req, serializeContext) {
12
12
  const action = req?.get("__action");
13
13
  if (action?.startsWith(liveQueryAction))
14
- return this.liveQuery(res, req, undefined, serializeRequest, getLiveQueryChannel(action.substring(liveQueryAction.length), this.remult.user?.id));
14
+ return this.liveQuery(res, req, undefined, serializeContext, getLiveQueryChannel(action.substring(liveQueryAction.length), this.remult.user?.id));
15
15
  switch (action) {
16
16
  case "get":
17
17
  case "count":
@@ -19,10 +19,10 @@ export class DataApi {
19
19
  }
20
20
  return this.getArray(res, req, undefined);
21
21
  }
22
- async httpPost(res, req, body, serializeRequest) {
22
+ async httpPost(res, req, body, serializeContext) {
23
23
  const action = req?.get("__action");
24
24
  if (action?.startsWith(liveQueryAction))
25
- return this.liveQuery(res, req, undefined, serializeRequest, getLiveQueryChannel(action.substring(liveQueryAction.length), this.remult.user?.id));
25
+ return this.liveQuery(res, req, undefined, serializeContext, getLiveQueryChannel(action.substring(liveQueryAction.length), this.remult.user?.id));
26
26
  switch (action) {
27
27
  case "get":
28
28
  return this.getArray(res, req, body);
@@ -120,7 +120,7 @@ export class DataApi {
120
120
  response.error(err);
121
121
  }
122
122
  }
123
- async liveQuery(response, request, filterBody, serializeRequest, queryChannel) {
123
+ async liveQuery(response, request, filterBody, serializeContext, queryChannel) {
124
124
  if (!this.repository.metadata.apiReadAllowed) {
125
125
  response.forbidden();
126
126
  return;
@@ -128,7 +128,7 @@ export class DataApi {
128
128
  try {
129
129
  const r = await this.getArrayImpl(response, request, filterBody);
130
130
  const data = {
131
- requestJson: await serializeRequest(),
131
+ requestJson: await serializeContext(),
132
132
  findOptionsJson: findOptionsToJson(r.findOptions, this.repository.metadata),
133
133
  lastIds: r.r.map(y => this.repository.metadata.idMetadata.getId(y))
134
134
  };
package/graphql.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { RemultServer } from "./server/expressBridge";
2
- export declare function remultGraphql(api: RemultServer<any>): {
1
+ import { RemultExpressServer } from "./remult-express";
2
+ export declare function remultGraphql(api: RemultExpressServer): {
3
3
  rootValue: {};
4
4
  schema: string;
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.20.0-exp.16",
3
+ "version": "0.20.0-exp.18",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,4 +28,9 @@ export declare function createPostgresConnection(options?: {
28
28
  sslInDev?: boolean;
29
29
  configuration?: "heroku" | PoolConfig;
30
30
  }): Promise<SqlDatabase>;
31
+ export declare function createPostgresDataProvider(options?: {
32
+ connectionString?: string;
33
+ sslInDev?: boolean;
34
+ configuration?: "heroku" | PoolConfig;
35
+ }): Promise<SqlDatabase>;
31
36
  export declare function preparePostgresQueueStorage(sql: SqlDatabase): Promise<import("../server/expressBridge").EntityQueueStorage>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.preparePostgresQueueStorage = exports.createPostgresConnection = exports.PostgresDataProvider = void 0;
3
+ exports.preparePostgresQueueStorage = exports.createPostgresDataProvider = exports.createPostgresConnection = exports.PostgresDataProvider = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var pg_1 = require("pg");
6
6
  var context_1 = require("../src/context");
@@ -67,6 +67,7 @@ var PostgresDataProvider = /** @class */ (function () {
67
67
  entityIsUsedForTheFirstTime: this.entityIsUsedForTheFirstTime,
68
68
  transaction: function () { throw "nested transactions not allowed"; },
69
69
  getLimitSqlSyntax: this.getLimitSqlSyntax,
70
+ supportsJsonColumnType: this.supportsJsonColumnType,
70
71
  //@ts-ignore
71
72
  pool: client
72
73
  })];
@@ -119,6 +120,14 @@ var PostgresBridgeToSQLQueryResult = /** @class */ (function () {
119
120
  return PostgresBridgeToSQLQueryResult;
120
121
  }());
121
122
  function createPostgresConnection(options) {
123
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
124
+ return tslib_1.__generator(this, function (_a) {
125
+ return [2 /*return*/, createPostgresDataProvider(options)];
126
+ });
127
+ });
128
+ }
129
+ exports.createPostgresConnection = createPostgresConnection;
130
+ function createPostgresDataProvider(options) {
122
131
  return tslib_1.__awaiter(this, void 0, void 0, function () {
123
132
  var config, db, remult;
124
133
  return tslib_1.__generator(this, function (_a) {
@@ -150,7 +159,7 @@ function createPostgresConnection(options) {
150
159
  });
151
160
  });
152
161
  }
153
- exports.createPostgresConnection = createPostgresConnection;
162
+ exports.createPostgresDataProvider = createPostgresDataProvider;
154
163
  function preparePostgresQueueStorage(sql) {
155
164
  return tslib_1.__awaiter(this, void 0, void 0, function () {
156
165
  var c, JobsInQueueEntity, e;
@@ -44,7 +44,7 @@ export interface RemultServerOptions<RequestType> {
44
44
  /** Used to store the context relevant info for re running a live query */
45
45
  contextSerializer?: {
46
46
  serialize(remult: Remult): Promise<any>;
47
- deserialize(json: any, remult: Remult): Promise<void>;
47
+ deserialize(json: any, options: InitRequestOptions): Promise<void>;
48
48
  };
49
49
  /** Storage to use for backend methods that use queue */
50
50
  queueStorage?: QueueStorage;
@@ -192,7 +192,15 @@ var RemultServerImplementation = /** @class */ (function () {
192
192
  case 0:
193
193
  remult.user = jsonContextData.user;
194
194
  if (!this.options.contextSerializer) return [3 /*break*/, 2];
195
- return [4 /*yield*/, this.options.contextSerializer.deserialize(jsonContextData, remult)];
195
+ return [4 /*yield*/, this.options.contextSerializer.deserialize(jsonContextData, {
196
+ remult: remult,
197
+ get liveQueryStorage() {
198
+ return remult.liveQueryStorage;
199
+ },
200
+ set liveQueryStorage(value) {
201
+ remult.liveQueryStorage = value;
202
+ }
203
+ })];
196
204
  case 1:
197
205
  _a.sent();
198
206
  _a.label = 2;
package/src/data-api.d.ts CHANGED
@@ -5,8 +5,8 @@ export declare class DataApi<T = any> {
5
5
  private repository;
6
6
  private remult;
7
7
  constructor(repository: Repository<T>, remult: Remult);
8
- httpGet(res: DataApiResponse, req: DataApiRequest, serializeRequest: () => Promise<any>): Promise<void>;
9
- httpPost(res: DataApiResponse, req: DataApiRequest, body: any, serializeRequest: () => Promise<any>): Promise<void>;
8
+ httpGet(res: DataApiResponse, req: DataApiRequest, serializeContext: () => Promise<any>): Promise<void>;
9
+ httpPost(res: DataApiResponse, req: DataApiRequest, body: any, serializeContext: () => Promise<any>): Promise<void>;
10
10
  static defaultGetLimit: number;
11
11
  get(response: DataApiResponse, id: any): Promise<void>;
12
12
  count(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
@@ -15,7 +15,7 @@ export declare class DataApi<T = any> {
15
15
  findOptions: FindOptions<T>;
16
16
  }>;
17
17
  getArray(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
18
- liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any, serializeRequest: () => Promise<any>, queryChannel: string): Promise<void>;
18
+ liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any, serializeContext: () => Promise<any>, queryChannel: string): Promise<void>;
19
19
  private buildWhere;
20
20
  private doOnId;
21
21
  put(response: DataApiResponse, id: any, body: any): Promise<void>;
package/src/data-api.js CHANGED
@@ -12,11 +12,11 @@ var DataApi = /** @class */ (function () {
12
12
  this.repository = repository;
13
13
  this.remult = remult;
14
14
  }
15
- DataApi.prototype.httpGet = function (res, req, serializeRequest) {
15
+ DataApi.prototype.httpGet = function (res, req, serializeContext) {
16
16
  var _a;
17
17
  var action = req === null || req === void 0 ? void 0 : req.get("__action");
18
18
  if (action === null || action === void 0 ? void 0 : action.startsWith(rest_data_provider_1.liveQueryAction))
19
- return this.liveQuery(res, req, undefined, serializeRequest, getLiveQueryChannel(action.substring(rest_data_provider_1.liveQueryAction.length), (_a = this.remult.user) === null || _a === void 0 ? void 0 : _a.id));
19
+ return this.liveQuery(res, req, undefined, serializeContext, getLiveQueryChannel(action.substring(rest_data_provider_1.liveQueryAction.length), (_a = this.remult.user) === null || _a === void 0 ? void 0 : _a.id));
20
20
  switch (action) {
21
21
  case "get":
22
22
  case "count":
@@ -24,7 +24,7 @@ var DataApi = /** @class */ (function () {
24
24
  }
25
25
  return this.getArray(res, req, undefined);
26
26
  };
27
- DataApi.prototype.httpPost = function (res, req, body, serializeRequest) {
27
+ DataApi.prototype.httpPost = function (res, req, body, serializeContext) {
28
28
  var _a, _b;
29
29
  return tslib_1.__awaiter(this, void 0, void 0, function () {
30
30
  var action, _c;
@@ -33,7 +33,7 @@ var DataApi = /** @class */ (function () {
33
33
  case 0:
34
34
  action = req === null || req === void 0 ? void 0 : req.get("__action");
35
35
  if (action === null || action === void 0 ? void 0 : action.startsWith(rest_data_provider_1.liveQueryAction))
36
- return [2 /*return*/, this.liveQuery(res, req, undefined, serializeRequest, getLiveQueryChannel(action.substring(rest_data_provider_1.liveQueryAction.length), (_a = this.remult.user) === null || _a === void 0 ? void 0 : _a.id))];
36
+ return [2 /*return*/, this.liveQuery(res, req, undefined, serializeContext, getLiveQueryChannel(action.substring(rest_data_provider_1.liveQueryAction.length), (_a = this.remult.user) === null || _a === void 0 ? void 0 : _a.id))];
37
37
  _c = action;
38
38
  switch (_c) {
39
39
  case "get": return [3 /*break*/, 1];
@@ -207,7 +207,7 @@ var DataApi = /** @class */ (function () {
207
207
  });
208
208
  });
209
209
  };
210
- DataApi.prototype.liveQuery = function (response, request, filterBody, serializeRequest, queryChannel) {
210
+ DataApi.prototype.liveQuery = function (response, request, filterBody, serializeContext, queryChannel) {
211
211
  return tslib_1.__awaiter(this, void 0, void 0, function () {
212
212
  var r, data, err_3;
213
213
  var _a;
@@ -226,7 +226,7 @@ var DataApi = /** @class */ (function () {
226
226
  case 2:
227
227
  r = _b.sent();
228
228
  _a = {};
229
- return [4 /*yield*/, serializeRequest()];
229
+ return [4 /*yield*/, serializeContext()];
230
230
  case 3:
231
231
  data = (_a.requestJson = _b.sent(),
232
232
  _a.findOptionsJson = rest_data_provider_1.findOptionsToJson(r.findOptions, this.repository.metadata),