@ruiapp/rapid-core 0.1.75 → 0.1.77

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/dist/index.js CHANGED
@@ -412,27 +412,27 @@ class QueryBuilder {
412
412
  const { entity } = options;
413
413
  let command = "INSERT INTO ";
414
414
  command += this.quoteTable(model);
415
- const propertyNames = Object.keys(entity);
415
+ const columnNames = Object.keys(entity);
416
416
  let values = "";
417
- propertyNames.forEach((propertyName, index) => {
417
+ columnNames.forEach((columnName, index) => {
418
418
  if (index) {
419
419
  values += ", ";
420
420
  }
421
421
  let property = null;
422
422
  if (model) {
423
- property = lodash.find(model.properties, (e) => e.code === propertyName);
423
+ property = lodash.find(model.properties, (e) => (e.columnName || e.code) === columnName);
424
424
  }
425
425
  const columnType = property ? pgPropertyTypeColumnMap[property.type] : null;
426
426
  if (columnType === "jsonb") {
427
- params.push(JSON.stringify(entity[propertyName]));
427
+ params.push(JSON.stringify(entity[columnName]));
428
428
  values += `$${params.length}::jsonb`;
429
429
  }
430
430
  else {
431
- params.push(entity[propertyName]);
431
+ params.push(entity[columnName]);
432
432
  values += `$${params.length}`;
433
433
  }
434
434
  });
435
- command += ` (${propertyNames.map(this.quoteObject).join(", ")})`;
435
+ command += ` (${columnNames.map(this.quoteObject).join(", ")})`;
436
436
  command += ` VALUES (${values}) RETURNING *`;
437
437
  return {
438
438
  command,
@@ -452,23 +452,23 @@ class QueryBuilder {
452
452
  let command = "UPDATE ";
453
453
  command += this.quoteTable(model);
454
454
  command += " SET ";
455
- const propertyNames = Object.keys(entity);
456
- propertyNames.forEach((propertyName, index) => {
455
+ const columnNames = Object.keys(entity);
456
+ columnNames.forEach((columnName, index) => {
457
457
  if (index) {
458
458
  command += ", ";
459
459
  }
460
- command += `${this.quoteObject(propertyName)}=`;
460
+ command += `${this.quoteObject(columnName)}=`;
461
461
  let property = null;
462
462
  if (model) {
463
- property = lodash.find(model.properties, (e) => (e.columnName || e.code) === propertyName);
463
+ property = lodash.find(model.properties, (e) => (e.columnName || e.code) === columnName);
464
464
  }
465
465
  const columnType = property ? pgPropertyTypeColumnMap[property.type] : null;
466
466
  if (columnType === "jsonb") {
467
- params.push(JSON.stringify(entity[propertyName]));
467
+ params.push(JSON.stringify(entity[columnName]));
468
468
  command += `$${params.length}::jsonb`;
469
469
  }
470
470
  else {
471
- params.push(entity[propertyName]);
471
+ params.push(entity[columnName]);
472
472
  command += `$${params.length}`;
473
473
  }
474
474
  });
@@ -5928,9 +5928,10 @@ var downloadDocumentActionHandler = /*#__PURE__*/Object.freeze({
5928
5928
 
5929
5929
  const code$7 = "downloadFile";
5930
5930
  async function handler$7(plugin, ctx, options) {
5931
- const { server, applicationConfig, routerContext, input } = ctx;
5931
+ const { server, applicationConfig, routerContext } = ctx;
5932
5932
  const { request, response } = routerContext;
5933
5933
  //TODO: only public files can download by this handler
5934
+ const input = ctx.input;
5934
5935
  let fileKey = input.fileKey;
5935
5936
  if (!fileKey && input.fileId) {
5936
5937
  const dataAccessor = ctx.server.getDataAccessor({
@@ -5946,7 +5947,8 @@ async function handler$7(plugin, ctx, options) {
5946
5947
  const filePathName = path__default["default"].join(server.config.localFileStoragePath, fileKey);
5947
5948
  const attachmentFileName = input.fileName || path__default["default"].basename(fileKey);
5948
5949
  response.body = await readFile(filePathName);
5949
- response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
5950
+ const dispositionType = input.inline ? "inline" : "attachment";
5951
+ response.headers.set("Content-Disposition", `${dispositionType}; filename="${encodeURIComponent(attachmentFileName)}"`);
5950
5952
  }
5951
5953
 
5952
5954
  var downloadFileActionHandler = /*#__PURE__*/Object.freeze({
@@ -1,4 +1,10 @@
1
1
  import { ActionHandlerContext } from "../../../core/actionHandler";
2
2
  import { RapidPlugin } from "../../../core/server";
3
+ export type DownloadFileInput = {
4
+ fileId?: string;
5
+ fileKey?: string;
6
+ fileName?: string;
7
+ inline?: boolean;
8
+ };
3
9
  export declare const code = "downloadFile";
4
10
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.1.75",
3
+ "version": "0.1.77",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3,13 +3,22 @@ import { readFile } from "~/utilities/fsUtility";
3
3
  import { ActionHandlerContext } from "~/core/actionHandler";
4
4
  import { RapidPlugin } from "~/core/server";
5
5
 
6
+ export type DownloadFileInput = {
7
+ fileId?: string;
8
+ fileKey?: string;
9
+ fileName?: string;
10
+ inline?: boolean;
11
+ };
12
+
6
13
  export const code = "downloadFile";
7
14
 
8
15
  export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
9
- const { server, applicationConfig, routerContext, input } = ctx;
16
+ const { server, applicationConfig, routerContext } = ctx;
10
17
  const { request, response } = routerContext;
11
18
  //TODO: only public files can download by this handler
12
19
 
20
+ const input: DownloadFileInput = ctx.input;
21
+
13
22
  let fileKey: string = input.fileKey;
14
23
 
15
24
  if (!fileKey && input.fileId) {
@@ -29,5 +38,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
29
38
  const attachmentFileName = input.fileName || path.basename(fileKey);
30
39
 
31
40
  response.body = await readFile(filePathName);
32
- response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
41
+
42
+ const dispositionType = input.inline ? "inline" : "attachment";
43
+ response.headers.set("Content-Disposition", `${dispositionType}; filename="${encodeURIComponent(attachmentFileName)}"`);
33
44
  }
@@ -277,28 +277,28 @@ export default class QueryBuilder {
277
277
 
278
278
  command += this.quoteTable(model);
279
279
 
280
- const propertyNames: string[] = Object.keys(entity);
280
+ const columnNames: string[] = Object.keys(entity);
281
281
  let values = "";
282
- propertyNames.forEach((propertyName, index) => {
282
+ columnNames.forEach((columnName, index) => {
283
283
  if (index) {
284
284
  values += ", ";
285
285
  }
286
286
 
287
287
  let property: RpdDataModelProperty | null = null;
288
288
  if (model) {
289
- property = find(model.properties, (e: RpdDataModelProperty) => e.code === propertyName);
289
+ property = find(model.properties, (e: RpdDataModelProperty) => (e.columnName || e.code) === columnName);
290
290
  }
291
291
  const columnType: DataAccessPgColumnTypes | null = property ? pgPropertyTypeColumnMap[property.type] : null;
292
292
  if (columnType === "jsonb") {
293
- params.push(JSON.stringify(entity[propertyName]));
293
+ params.push(JSON.stringify(entity[columnName]));
294
294
  values += `$${params.length}::jsonb`;
295
295
  } else {
296
- params.push(entity[propertyName]);
296
+ params.push(entity[columnName]);
297
297
  values += `$${params.length}`;
298
298
  }
299
299
  });
300
300
 
301
- command += ` (${propertyNames.map(this.quoteObject).join(", ")})`;
301
+ command += ` (${columnNames.map(this.quoteObject).join(", ")})`;
302
302
  command += ` VALUES (${values}) RETURNING *`;
303
303
 
304
304
  return {
@@ -322,24 +322,24 @@ export default class QueryBuilder {
322
322
  command += this.quoteTable(model);
323
323
 
324
324
  command += " SET ";
325
- const propertyNames: string[] = Object.keys(entity);
326
- propertyNames.forEach((propertyName, index) => {
325
+ const columnNames: string[] = Object.keys(entity);
326
+ columnNames.forEach((columnName, index) => {
327
327
  if (index) {
328
328
  command += ", ";
329
329
  }
330
330
 
331
- command += `${this.quoteObject(propertyName)}=`;
331
+ command += `${this.quoteObject(columnName)}=`;
332
332
 
333
333
  let property: RpdDataModelProperty | null = null;
334
334
  if (model) {
335
- property = find(model.properties, (e: RpdDataModelProperty) => (e.columnName || e.code) === propertyName);
335
+ property = find(model.properties, (e: RpdDataModelProperty) => (e.columnName || e.code) === columnName);
336
336
  }
337
337
  const columnType: DataAccessPgColumnTypes | null = property ? pgPropertyTypeColumnMap[property.type] : null;
338
338
  if (columnType === "jsonb") {
339
- params.push(JSON.stringify(entity[propertyName]));
339
+ params.push(JSON.stringify(entity[columnName]));
340
340
  command += `$${params.length}::jsonb`;
341
341
  } else {
342
- params.push(entity[propertyName]);
342
+ params.push(entity[columnName]);
343
343
  command += `$${params.length}`;
344
344
  }
345
345
  });