@loomcore/api 0.1.0 → 0.1.2

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.
Files changed (48) hide show
  1. package/package.json +15 -6
  2. package/dist/__tests__/models/mongo-test-entity.model.d.ts +0 -11
  3. package/dist/__tests__/models/mongo-test-entity.model.js +0 -13
  4. package/dist/__tests__/test-mongo-db.d.ts +0 -14
  5. package/dist/__tests__/test-mongo-db.js +0 -81
  6. package/dist/__tests__/test-user.d.ts +0 -3
  7. package/dist/__tests__/test-user.js +0 -16
  8. package/dist/databases/mongo-db/commands/batch-update.command.d.ts +0 -3
  9. package/dist/databases/mongo-db/commands/batch-update.command.js +0 -41
  10. package/dist/databases/mongo-db/commands/create-many.command.d.ts +0 -5
  11. package/dist/databases/mongo-db/commands/create-many.command.js +0 -17
  12. package/dist/databases/mongo-db/commands/create.command.d.ts +0 -5
  13. package/dist/databases/mongo-db/commands/create.command.js +0 -17
  14. package/dist/databases/mongo-db/commands/delete-by-id.command.d.ts +0 -3
  15. package/dist/databases/mongo-db/commands/delete-by-id.command.js +0 -9
  16. package/dist/databases/mongo-db/commands/delete-many.command.d.ts +0 -4
  17. package/dist/databases/mongo-db/commands/delete-many.command.js +0 -9
  18. package/dist/databases/mongo-db/commands/full-updateby-id.command.d.ts +0 -3
  19. package/dist/databases/mongo-db/commands/full-updateby-id.command.js +0 -21
  20. package/dist/databases/mongo-db/commands/partial-update-by-id.command.d.ts +0 -3
  21. package/dist/databases/mongo-db/commands/partial-update-by-id.command.js +0 -21
  22. package/dist/databases/mongo-db/commands/update.command.d.ts +0 -4
  23. package/dist/databases/mongo-db/commands/update.command.js +0 -19
  24. package/dist/databases/mongo-db/queries/find-one.query.d.ts +0 -3
  25. package/dist/databases/mongo-db/queries/find-one.query.js +0 -9
  26. package/dist/databases/mongo-db/queries/find.query.d.ts +0 -3
  27. package/dist/databases/mongo-db/queries/find.query.js +0 -9
  28. package/dist/databases/mongo-db/queries/get-all.query.d.ts +0 -3
  29. package/dist/databases/mongo-db/queries/get-all.query.js +0 -17
  30. package/dist/databases/mongo-db/queries/get-by-id.query.d.ts +0 -3
  31. package/dist/databases/mongo-db/queries/get-by-id.query.js +0 -20
  32. package/dist/databases/mongo-db/queries/get-count.query.d.ts +0 -2
  33. package/dist/databases/mongo-db/queries/get-count.query.js +0 -5
  34. package/dist/databases/mongo-db/queries/get.query.d.ts +0 -4
  35. package/dist/databases/mongo-db/queries/get.query.js +0 -14
  36. package/dist/databases/postgres/migrations/migration.d.ts +0 -6
  37. package/dist/databases/postgres/migrations/migration.js +0 -14
  38. package/dist/databases/postgres/migrations/runMigrations.d.ts +0 -2
  39. package/dist/databases/postgres/migrations/runMigrations.js +0 -20
  40. package/dist/databases/utils/database-to-idatabase.util.d.ts +0 -3
  41. package/dist/databases/utils/database-to-idatabase.util.js +0 -14
  42. package/dist/models/refresh-token.d.ts +0 -9
  43. package/dist/models/refresh-token.js +0 -2
  44. package/dist/models/refresh-token.spec.d.ts +0 -1
  45. package/dist/models/refresh-token.spec.js +0 -12
  46. package/dist/tsconfig.tsbuildinfo +0 -1
  47. package/dist/utils/sql.db.utils.d.ts +0 -14
  48. package/dist/utils/sql.db.utils.js +0 -94
@@ -1,94 +0,0 @@
1
- import { stringUtils } from './string.utils.js';
2
- function buildSQLWhereClauseFromQueryOptions(queryOptions, columnAliasMap) {
3
- const filters = queryOptions.filters || {};
4
- let whereClause = '';
5
- for (const [key, value] of Object.entries(filters)) {
6
- if (value) {
7
- const tableAlias = (columnAliasMap && columnAliasMap[key]) || '';
8
- whereClause = addKeyValueToWhereClause(whereClause, key, value, tableAlias);
9
- }
10
- }
11
- return whereClause;
12
- }
13
- function addKeyValueToWhereClause(whereClause, key, value, tableAlias = '') {
14
- let column = tableAlias ? `${tableAlias}.${stringUtils.pascalCase(key)}` : stringUtils.pascalCase(key);
15
- let formattedValue = '';
16
- let operator = '=';
17
- if (value) {
18
- if (value.eq !== undefined) {
19
- formattedValue = formatValue(value.eq);
20
- operator = '=';
21
- }
22
- else if (value.in !== undefined && Array.isArray(value.in)) {
23
- const formattedValues = value.in.map(val => formatValue(val)).join(', ');
24
- formattedValue = `(${formattedValues})`;
25
- operator = 'IN';
26
- }
27
- else if (value.gte !== undefined) {
28
- formattedValue = formatValue(value.gte);
29
- operator = '>=';
30
- }
31
- else if (value.lte !== undefined) {
32
- formattedValue = formatValue(value.lte);
33
- operator = '<=';
34
- }
35
- else if (value.gt !== undefined) {
36
- formattedValue = formatValue(value.gt);
37
- operator = '>';
38
- }
39
- else if (value.lt !== undefined) {
40
- formattedValue = formatValue(value.lt);
41
- operator = '<';
42
- }
43
- else if (value.contains !== undefined) {
44
- column = `LOWER(${column})`;
45
- formattedValue = formatValue(value.contains, true).toLowerCase();
46
- operator = 'LIKE';
47
- }
48
- }
49
- const condition = `${column} ${operator} ${formattedValue}`;
50
- return appendToWhereClause(whereClause, condition);
51
- }
52
- function appendToWhereClause(whereClause, condition) {
53
- let newWhereClause = whereClause.trim();
54
- if (newWhereClause.toUpperCase() === 'WHERE' || newWhereClause === '') {
55
- newWhereClause = `WHERE ${condition}`;
56
- }
57
- else {
58
- newWhereClause = `${newWhereClause} AND ${condition}`;
59
- }
60
- return newWhereClause;
61
- }
62
- function formatValue(value, isLikeOperator = false) {
63
- if (typeof value === 'string') {
64
- if (!isNaN(Number(value))) {
65
- return value;
66
- }
67
- if (value.toLowerCase() === 'true') {
68
- return 'TRUE';
69
- }
70
- if (value.toLowerCase() === 'false') {
71
- return 'FALSE';
72
- }
73
- return isLikeOperator ? `'%${value}%'` : `'${value}'`;
74
- }
75
- else if (typeof value === 'number') {
76
- return value.toString();
77
- }
78
- else if (typeof value === 'boolean') {
79
- return value ? 'TRUE' : 'FALSE';
80
- }
81
- else if (value instanceof Date) {
82
- const dateString = value.toISOString().split('T')[0];
83
- return `DATETIME('${dateString}')`;
84
- }
85
- else {
86
- throw new Error('Unsupported value type');
87
- }
88
- }
89
- export const sqlDbUtils = {
90
- buildSQLWhereClauseFromQueryOptions,
91
- addKeyValueToWhereClause,
92
- appendToWhereClause,
93
- formatValue,
94
- };