@loomcore/api 0.0.58 → 0.1.0
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/LICENSE +201 -0
- package/README.md +50 -0
- package/dist/__tests__/common-test.utils.d.ts +29 -60
- package/dist/__tests__/common-test.utils.js +88 -166
- package/dist/__tests__/index.d.ts +6 -0
- package/dist/__tests__/index.js +6 -0
- package/dist/__tests__/models/category.model.d.ts +8 -0
- package/dist/__tests__/models/category.model.js +6 -0
- package/dist/__tests__/models/mongo-test-entity.model.d.ts +11 -0
- package/dist/__tests__/models/mongo-test-entity.model.js +13 -0
- package/dist/__tests__/models/product.model.d.ts +17 -0
- package/dist/__tests__/models/product.model.js +10 -0
- package/dist/__tests__/models/test-entity.model.d.ts +11 -0
- package/dist/__tests__/models/test-entity.model.js +10 -0
- package/dist/__tests__/models/test-item.model.d.ts +12 -0
- package/dist/__tests__/models/test-item.model.js +9 -0
- package/dist/__tests__/mongo-db.test-database.d.ts +15 -0
- package/dist/__tests__/mongo-db.test-database.js +74 -0
- package/dist/__tests__/postgres-test-migrations/001-create-test-entities-table.migration.d.ts +11 -0
- package/dist/__tests__/postgres-test-migrations/001-create-test-entities-table.migration.js +59 -0
- package/dist/__tests__/postgres-test-migrations/002-create-categories-table.migration.d.ts +11 -0
- package/dist/__tests__/postgres-test-migrations/002-create-categories-table.migration.js +52 -0
- package/dist/__tests__/postgres-test-migrations/003-create-products-table.migration.d.ts +11 -0
- package/dist/__tests__/postgres-test-migrations/003-create-products-table.migration.js +62 -0
- package/dist/__tests__/postgres-test-migrations/004-create-test-users-table.migration.d.ts +11 -0
- package/dist/__tests__/postgres-test-migrations/004-create-test-users-table.migration.js +66 -0
- package/dist/__tests__/postgres-test-migrations/005-create-test-items-table.migration.d.ts +11 -0
- package/dist/__tests__/postgres-test-migrations/005-create-test-items-table.migration.js +50 -0
- package/dist/__tests__/postgres-test-migrations/run-test-migrations.d.ts +2 -0
- package/dist/__tests__/postgres-test-migrations/run-test-migrations.js +22 -0
- package/dist/__tests__/postgres.test-database.d.ts +13 -0
- package/dist/__tests__/postgres.test-database.js +85 -0
- package/dist/__tests__/test-database.interface.d.ts +7 -0
- package/dist/__tests__/test-express-app.d.ts +9 -7
- package/dist/__tests__/test-express-app.js +38 -48
- package/dist/__tests__/test-mongo-db.d.ts +14 -0
- package/dist/__tests__/test-mongo-db.js +81 -0
- package/dist/__tests__/test-objects.d.ts +23 -0
- package/dist/__tests__/test-objects.js +45 -0
- package/dist/__tests__/test-user.d.ts +3 -0
- package/dist/__tests__/test-user.js +16 -0
- package/dist/config/base-api-config.d.ts +2 -2
- package/dist/config/base-api-config.js +2 -2
- package/dist/controllers/api.controller.d.ts +1 -5
- package/dist/controllers/api.controller.js +4 -11
- package/dist/controllers/auth.controller.d.ts +2 -2
- package/dist/controllers/auth.controller.js +4 -5
- package/dist/controllers/organizations.controller.d.ts +2 -2
- package/dist/controllers/organizations.controller.js +4 -4
- package/dist/controllers/users.controller.d.ts +2 -2
- package/dist/controllers/users.controller.js +2 -2
- package/dist/databases/index.d.ts +1 -0
- package/dist/databases/index.js +1 -0
- package/dist/databases/models/constants.d.ts +1 -0
- package/dist/databases/models/constants.js +1 -0
- package/dist/databases/models/database.d.ts +3 -0
- package/dist/databases/models/database.interface.d.ts +28 -0
- package/dist/databases/models/delete-result.d.ts +5 -0
- package/dist/databases/models/delete-result.js +8 -0
- package/dist/databases/models/index.d.ts +5 -0
- package/dist/databases/models/index.js +5 -0
- package/dist/databases/models/update-result.d.ts +5 -0
- package/dist/databases/models/update-result.js +8 -0
- package/dist/databases/mongo-db/commands/batch-update.command.d.ts +3 -0
- package/dist/databases/mongo-db/commands/batch-update.command.js +41 -0
- package/dist/databases/mongo-db/commands/create-many.command.d.ts +5 -0
- package/dist/databases/mongo-db/commands/create-many.command.js +17 -0
- package/dist/databases/mongo-db/commands/create.command.d.ts +5 -0
- package/dist/databases/mongo-db/commands/create.command.js +17 -0
- package/dist/databases/mongo-db/commands/delete-by-id.command.d.ts +3 -0
- package/dist/databases/mongo-db/commands/delete-by-id.command.js +9 -0
- package/dist/databases/mongo-db/commands/delete-many.command.d.ts +4 -0
- package/dist/databases/mongo-db/commands/delete-many.command.js +9 -0
- package/dist/databases/mongo-db/commands/full-updateby-id.command.d.ts +3 -0
- package/dist/databases/mongo-db/commands/full-updateby-id.command.js +21 -0
- package/dist/databases/mongo-db/commands/index.d.ts +8 -0
- package/dist/databases/mongo-db/commands/index.js +8 -0
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.d.ts +4 -0
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.js +41 -0
- package/dist/databases/mongo-db/commands/mongo-create-many.command.d.ts +5 -0
- package/dist/databases/mongo-db/commands/mongo-create-many.command.js +17 -0
- package/dist/databases/mongo-db/commands/mongo-create.command.d.ts +5 -0
- package/dist/databases/mongo-db/commands/mongo-create.command.js +17 -0
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.d.ts +3 -0
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.js +14 -0
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.d.ts +4 -0
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.js +9 -0
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.d.ts +3 -0
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.js +25 -0
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.d.ts +3 -0
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.js +25 -0
- package/dist/databases/mongo-db/commands/mongo-update.command.d.ts +4 -0
- package/dist/databases/mongo-db/commands/mongo-update.command.js +19 -0
- package/dist/databases/mongo-db/commands/partial-update-by-id.command.d.ts +3 -0
- package/dist/databases/mongo-db/commands/partial-update-by-id.command.js +21 -0
- package/dist/databases/mongo-db/commands/update.command.d.ts +4 -0
- package/dist/databases/mongo-db/commands/update.command.js +19 -0
- package/dist/databases/mongo-db/index.d.ts +4 -0
- package/dist/databases/mongo-db/index.js +4 -0
- package/dist/databases/mongo-db/models/no-sql-pipeline.d.ts +15 -0
- package/dist/databases/mongo-db/models/no-sql-pipeline.interface.d.ts +11 -0
- package/dist/databases/mongo-db/models/no-sql-pipeline.js +43 -0
- package/dist/databases/mongo-db/mongo-db.database.d.ts +32 -0
- package/dist/databases/mongo-db/mongo-db.database.js +65 -0
- package/dist/databases/mongo-db/queries/find-one.query.d.ts +3 -0
- package/dist/databases/mongo-db/queries/find-one.query.js +9 -0
- package/dist/databases/mongo-db/queries/find.query.d.ts +3 -0
- package/dist/databases/mongo-db/queries/find.query.js +9 -0
- package/dist/databases/mongo-db/queries/get-all.query.d.ts +3 -0
- package/dist/databases/mongo-db/queries/get-all.query.js +17 -0
- package/dist/databases/mongo-db/queries/get-by-id.query.d.ts +3 -0
- package/dist/databases/mongo-db/queries/get-by-id.query.js +20 -0
- package/dist/databases/mongo-db/queries/get-count.query.d.ts +2 -0
- package/dist/databases/mongo-db/queries/get-count.query.js +5 -0
- package/dist/databases/mongo-db/queries/get.query.d.ts +4 -0
- package/dist/databases/mongo-db/queries/get.query.js +14 -0
- package/dist/databases/mongo-db/queries/index.d.ts +6 -0
- package/dist/databases/mongo-db/queries/index.js +6 -0
- package/dist/databases/mongo-db/queries/mongo-find-one.query.d.ts +3 -0
- package/dist/databases/mongo-db/queries/mongo-find-one.query.js +9 -0
- package/dist/databases/mongo-db/queries/mongo-find.query.d.ts +3 -0
- package/dist/databases/mongo-db/queries/mongo-find.query.js +9 -0
- package/dist/databases/mongo-db/queries/mongo-get-all.query.d.ts +3 -0
- package/dist/databases/mongo-db/queries/mongo-get-all.query.js +17 -0
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.d.ts +4 -0
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.js +17 -0
- package/dist/databases/mongo-db/queries/mongo-get-count.query.d.ts +2 -0
- package/dist/databases/mongo-db/queries/mongo-get-count.query.js +5 -0
- package/dist/databases/mongo-db/queries/mongo-get.query.d.ts +4 -0
- package/dist/databases/mongo-db/queries/mongo-get.query.js +14 -0
- package/dist/databases/mongo-db/utils/build-find-options.util.d.ts +3 -0
- package/dist/databases/mongo-db/utils/build-find-options.util.js +15 -0
- package/dist/databases/mongo-db/utils/build-no-sql-match.util.d.ts +3 -0
- package/dist/databases/mongo-db/utils/build-no-sql-match.util.js +59 -0
- package/dist/databases/mongo-db/utils/convert-object-ids-to-strings.util.d.ts +1 -0
- package/dist/databases/mongo-db/utils/convert-object-ids-to-strings.util.js +32 -0
- package/dist/databases/mongo-db/utils/convert-operations-to-pipeline.util.d.ts +3 -0
- package/dist/databases/mongo-db/utils/convert-operations-to-pipeline.util.js +68 -0
- package/dist/databases/mongo-db/utils/convert-query-options-to-pipeline.util.d.ts +3 -0
- package/dist/databases/mongo-db/utils/convert-query-options-to-pipeline.util.js +31 -0
- package/dist/databases/mongo-db/utils/convert-strings-to-object-ids.util.d.ts +3 -0
- package/dist/databases/mongo-db/utils/convert-strings-to-object-ids.util.js +72 -0
- package/dist/databases/mongo-db/utils/index.d.ts +7 -0
- package/dist/databases/mongo-db/utils/index.js +7 -0
- package/dist/databases/operations/join.operation.d.ts +7 -0
- package/dist/databases/operations/join.operation.js +12 -0
- package/dist/databases/operations/operation.d.ts +2 -0
- package/dist/databases/postgres/commands/postgres-batch-update.command.d.ts +4 -0
- package/dist/databases/postgres/commands/postgres-batch-update.command.js +56 -0
- package/dist/databases/postgres/commands/postgres-create-many.command.d.ts +6 -0
- package/dist/databases/postgres/commands/postgres-create-many.command.js +63 -0
- package/dist/databases/postgres/commands/postgres-create.command.d.ts +6 -0
- package/dist/databases/postgres/commands/postgres-create.command.js +29 -0
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.d.ts +3 -0
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.js +6 -0
- package/dist/databases/postgres/commands/postgres-delete-many.command.d.ts +4 -0
- package/dist/databases/postgres/commands/postgres-delete-many.command.js +13 -0
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.d.ts +4 -0
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +72 -0
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.d.ts +4 -0
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +42 -0
- package/dist/databases/postgres/commands/postgres-update.command.d.ts +5 -0
- package/dist/databases/postgres/commands/postgres-update.command.js +48 -0
- package/dist/databases/postgres/migrations/001-create-migrations-table.migration.d.ts +11 -0
- package/dist/databases/postgres/migrations/001-create-migrations-table.migration.js +52 -0
- package/dist/databases/postgres/migrations/002-create-organizations-table.migration.d.ts +11 -0
- package/dist/databases/postgres/migrations/002-create-organizations-table.migration.js +55 -0
- package/dist/databases/postgres/migrations/003-create-users-table.migration.d.ts +11 -0
- package/dist/databases/postgres/migrations/003-create-users-table.migration.js +65 -0
- package/dist/databases/postgres/migrations/004-create-refresh-token-table.migration.d.ts +11 -0
- package/dist/databases/postgres/migrations/004-create-refresh-token-table.migration.js +57 -0
- package/dist/databases/postgres/migrations/index.d.ts +3 -0
- package/dist/databases/postgres/migrations/index.js +3 -0
- package/dist/databases/postgres/migrations/migration.d.ts +6 -0
- package/dist/databases/postgres/migrations/migration.interface.d.ts +6 -0
- package/dist/databases/postgres/migrations/migration.interface.js +1 -0
- package/dist/databases/postgres/migrations/migration.js +14 -0
- package/dist/databases/postgres/migrations/runMigrations.d.ts +2 -0
- package/dist/databases/postgres/migrations/runMigrations.js +20 -0
- package/dist/databases/postgres/migrations/setup-for-auth.migration.d.ts +2 -0
- package/dist/databases/postgres/migrations/setup-for-auth.migration.js +18 -0
- package/dist/databases/postgres/migrations/setup-for-multitenant.migration.d.ts +2 -0
- package/dist/databases/postgres/migrations/setup-for-multitenant.migration.js +16 -0
- package/dist/databases/postgres/postgres.database.d.ts +31 -0
- package/dist/databases/postgres/postgres.database.js +69 -0
- package/dist/databases/postgres/queries/postgres-find-one.query.d.ts +3 -0
- package/dist/databases/postgres/queries/postgres-find-one.query.js +13 -0
- package/dist/databases/postgres/queries/postgres-find.query.d.ts +3 -0
- package/dist/databases/postgres/queries/postgres-find.query.js +11 -0
- package/dist/databases/postgres/queries/postgres-get-all.query.d.ts +3 -0
- package/dist/databases/postgres/queries/postgres-get-all.query.js +14 -0
- package/dist/databases/postgres/queries/postgres-get-by-id.query.d.ts +4 -0
- package/dist/databases/postgres/queries/postgres-get-by-id.query.js +26 -0
- package/dist/databases/postgres/queries/postgres-get-count.query.d.ts +2 -0
- package/dist/databases/postgres/queries/postgres-get-count.query.js +4 -0
- package/dist/databases/postgres/queries/postgres-get.query.d.ts +4 -0
- package/dist/databases/postgres/queries/postgres-get.query.js +26 -0
- package/dist/databases/postgres/utils/build-count-query.d.ts +3 -0
- package/dist/databases/postgres/utils/build-count-query.js +7 -0
- package/dist/databases/postgres/utils/build-join-clauses.d.ts +2 -0
- package/dist/databases/postgres/utils/build-join-clauses.js +12 -0
- package/dist/databases/postgres/utils/build-order-by-clause.d.ts +2 -0
- package/dist/databases/postgres/utils/build-order-by-clause.js +8 -0
- package/dist/databases/postgres/utils/build-pagination-clause.d.ts +2 -0
- package/dist/databases/postgres/utils/build-pagination-clause.js +9 -0
- package/dist/databases/postgres/utils/build-select-clause.d.ts +3 -0
- package/dist/databases/postgres/utils/build-select-clause.js +28 -0
- package/dist/databases/postgres/utils/build-where-clause.d.ts +5 -0
- package/dist/databases/postgres/utils/build-where-clause.js +50 -0
- package/dist/databases/postgres/utils/columns-and-values-from-entity.d.ts +5 -0
- package/dist/databases/postgres/utils/columns-and-values-from-entity.js +9 -0
- package/dist/databases/postgres/utils/convert-null-to-undefined.util.d.ts +2 -0
- package/dist/databases/postgres/utils/convert-null-to-undefined.util.js +70 -0
- package/dist/databases/postgres/utils/transform-join-results.d.ts +2 -0
- package/dist/databases/postgres/utils/transform-join-results.js +33 -0
- package/dist/databases/utils/database-to-idatabase.util.d.ts +3 -0
- package/dist/databases/utils/database-to-idatabase.util.js +14 -0
- package/dist/databases/utils/get-property-schema.util.d.ts +2 -0
- package/dist/databases/utils/get-property-schema.util.js +15 -0
- package/dist/databases/utils/index.d.ts +1 -0
- package/dist/databases/utils/index.js +1 -0
- package/dist/models/base-api-config.interface.d.ts +3 -2
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.js +1 -1
- package/dist/models/refresh-token.d.ts +9 -0
- package/dist/models/refresh-token.js +2 -0
- package/dist/models/refresh-token.model.d.ts +18 -0
- package/dist/models/refresh-token.model.js +13 -0
- package/dist/models/refresh-token.spec.d.ts +1 -0
- package/dist/models/refresh-token.spec.js +12 -0
- package/dist/services/auth.service.d.ts +11 -18
- package/dist/services/auth.service.js +29 -50
- package/dist/services/generic-api-service/generic-api-service.interface.d.ts +29 -0
- package/dist/services/generic-api-service/generic-api-service.interface.js +1 -0
- package/dist/services/generic-api-service/generic-api.service.d.ts +37 -0
- package/dist/services/generic-api-service/generic-api.service.js +178 -0
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.js +2 -2
- package/dist/services/multi-tenant-api.service.d.ts +9 -6
- package/dist/services/multi-tenant-api.service.js +10 -23
- package/dist/services/organization.service.d.ts +5 -5
- package/dist/services/organization.service.js +9 -6
- package/dist/services/password-reset-token.service.d.ts +3 -3
- package/dist/services/password-reset-token.service.js +5 -5
- package/dist/services/tenant-query-decorator.d.ts +1 -1
- package/dist/services/tenant-query-decorator.js +1 -1
- package/dist/services/user.service.d.ts +4 -6
- package/dist/services/user.service.js +4 -10
- package/dist/services/utils/audit-for-create.util.d.ts +2 -0
- package/dist/services/utils/audit-for-create.util.js +9 -0
- package/dist/services/utils/audit-for-update.util.d.ts +2 -0
- package/dist/services/utils/audit-for-update.util.js +7 -0
- package/dist/services/utils/strip-sender-provided-system-properties.util.d.ts +2 -0
- package/dist/services/utils/strip-sender-provided-system-properties.util.js +15 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/api.utils.js +2 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/sql.db.utils.d.ts +14 -0
- package/dist/utils/sql.db.utils.js +94 -0
- package/package.json +4 -2
- package/dist/services/generic-api-service.interface.d.ts +0 -27
- package/dist/services/generic-api.service.d.ts +0 -50
- package/dist/services/generic-api.service.js +0 -424
- package/dist/utils/db.utils.d.ts +0 -27
- package/dist/utils/db.utils.js +0 -323
- /package/dist/{controllers/api-controller.utils.d.ts → __tests__/test-database.interface.js} +0 -0
- /package/dist/{controllers/api-controller.utils.js → databases/models/database.interface.js} +0 -0
- /package/dist/{models/types/index.d.ts → databases/models/database.js} +0 -0
- /package/dist/{models/types/index.js → databases/mongo-db/models/no-sql-pipeline.interface.js} +0 -0
- /package/dist/{services/generic-api-service.interface.js → databases/operations/operation.js} +0 -0
package/dist/utils/db.utils.js
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import { ObjectId } from 'mongodb';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import { entityUtils } from '@loomcore/common/utils';
|
|
4
|
-
import { stringUtils } from './string.utils.js';
|
|
5
|
-
function getPropertySchema(key, schema) {
|
|
6
|
-
if (!schema || typeof schema !== 'object')
|
|
7
|
-
return undefined;
|
|
8
|
-
if (schema.allOf && Array.isArray(schema.allOf)) {
|
|
9
|
-
for (const nestedSchema of schema.allOf) {
|
|
10
|
-
const propSchema = getPropertySchema(key, nestedSchema);
|
|
11
|
-
if (propSchema)
|
|
12
|
-
return propSchema;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
if (schema.type === 'object' && schema.properties) {
|
|
16
|
-
return schema.properties[key];
|
|
17
|
-
}
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
export const PROPERTIES_THAT_ARE_NOT_OBJECT_IDS = ['_orgId'];
|
|
21
|
-
function convertObjectIdsToStrings(entity, schema) {
|
|
22
|
-
if (!entity)
|
|
23
|
-
return entity;
|
|
24
|
-
const clone = _.cloneDeep(entity);
|
|
25
|
-
if (!schema) {
|
|
26
|
-
if (clone._id && clone._id instanceof ObjectId) {
|
|
27
|
-
clone._id = clone._id.toString();
|
|
28
|
-
}
|
|
29
|
-
return clone;
|
|
30
|
-
}
|
|
31
|
-
const processEntity = (obj, subSchema, path = []) => {
|
|
32
|
-
if (!obj || typeof obj !== 'object')
|
|
33
|
-
return;
|
|
34
|
-
if (subSchema.allOf && Array.isArray(subSchema.allOf)) {
|
|
35
|
-
for (const nestedSchema of subSchema.allOf) {
|
|
36
|
-
processEntity(obj, nestedSchema, path);
|
|
37
|
-
}
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (subSchema.type === 'object' && subSchema.properties) {
|
|
41
|
-
for (const [key, propSchema] of Object.entries(subSchema.properties)) {
|
|
42
|
-
if (!propSchema || typeof propSchema !== 'object')
|
|
43
|
-
continue;
|
|
44
|
-
const typedPropSchema = propSchema;
|
|
45
|
-
const fullPath = [...path, key];
|
|
46
|
-
if (typedPropSchema.format === 'objectid') {
|
|
47
|
-
if (path.length === 0 && PROPERTIES_THAT_ARE_NOT_OBJECT_IDS.includes(key)) {
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (obj[key] instanceof ObjectId) {
|
|
51
|
-
obj[key] = obj[key].toString();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else if (typedPropSchema.type === 'object' && obj[key]) {
|
|
55
|
-
processEntity(obj[key], typedPropSchema, fullPath);
|
|
56
|
-
}
|
|
57
|
-
else if (typedPropSchema.type === 'array' && Array.isArray(obj[key])) {
|
|
58
|
-
const items = typedPropSchema.items;
|
|
59
|
-
if (items) {
|
|
60
|
-
for (let i = 0; i < obj[key].length; i++) {
|
|
61
|
-
if (items.format === 'objectid') {
|
|
62
|
-
if (path.length === 0 && PROPERTIES_THAT_ARE_NOT_OBJECT_IDS.includes(key)) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (obj[key][i] instanceof ObjectId) {
|
|
66
|
-
obj[key][i] = obj[key][i].toString();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else if (items.type === 'object') {
|
|
70
|
-
processEntity(obj[key][i], items, [...fullPath, i.toString()]);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
processEntity(clone, schema);
|
|
79
|
-
return clone;
|
|
80
|
-
}
|
|
81
|
-
function convertStringsToObjectIds(entity, schema) {
|
|
82
|
-
if (!entity)
|
|
83
|
-
return entity;
|
|
84
|
-
const clone = _.cloneDeep(entity);
|
|
85
|
-
if (clone._id && typeof clone._id === 'string' && entityUtils.isValidObjectId(clone._id)) {
|
|
86
|
-
clone._id = new ObjectId(clone._id);
|
|
87
|
-
}
|
|
88
|
-
const processEntity = (obj, subSchema, path = []) => {
|
|
89
|
-
if (!obj || typeof obj !== 'object')
|
|
90
|
-
return obj;
|
|
91
|
-
if (obj instanceof Date) {
|
|
92
|
-
return obj;
|
|
93
|
-
}
|
|
94
|
-
if (subSchema.allOf && Array.isArray(subSchema.allOf)) {
|
|
95
|
-
let result = { ...obj };
|
|
96
|
-
for (const nestedSchema of subSchema.allOf) {
|
|
97
|
-
result = processEntity(result, nestedSchema, path);
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
if (Array.isArray(obj)) {
|
|
102
|
-
const items = subSchema.items;
|
|
103
|
-
if (!items)
|
|
104
|
-
return obj;
|
|
105
|
-
if (items.format === 'objectid') {
|
|
106
|
-
if (path.length === 1 && PROPERTIES_THAT_ARE_NOT_OBJECT_IDS.includes(path[0])) {
|
|
107
|
-
return obj;
|
|
108
|
-
}
|
|
109
|
-
return obj.map(item => {
|
|
110
|
-
if (typeof item === 'string' && entityUtils.isValidObjectId(item)) {
|
|
111
|
-
return new ObjectId(item);
|
|
112
|
-
}
|
|
113
|
-
return item;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (items.type === 'object') {
|
|
117
|
-
return obj.map((item, index) => processEntity(item, items, [...path, index.toString()]));
|
|
118
|
-
}
|
|
119
|
-
return obj;
|
|
120
|
-
}
|
|
121
|
-
const result = { ...obj };
|
|
122
|
-
if (subSchema.type === 'object' && subSchema.properties) {
|
|
123
|
-
for (const [key, propSchema] of Object.entries(subSchema.properties)) {
|
|
124
|
-
if (!propSchema || typeof propSchema !== 'object' || result[key] === null || result[key] === undefined) {
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
const typedPropSchema = propSchema;
|
|
128
|
-
const fullPath = [...path, key];
|
|
129
|
-
const value = result[key];
|
|
130
|
-
const isObjectIdField = typedPropSchema.format === 'objectid';
|
|
131
|
-
if (isObjectIdField && path.length === 0 && PROPERTIES_THAT_ARE_NOT_OBJECT_IDS.includes(key)) {
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
if (isObjectIdField && typeof value === 'string' && entityUtils.isValidObjectId(value)) {
|
|
135
|
-
result[key] = new ObjectId(value);
|
|
136
|
-
}
|
|
137
|
-
else if (typedPropSchema.type === 'array' && Array.isArray(value)) {
|
|
138
|
-
result[key] = processEntity(value, typedPropSchema, fullPath);
|
|
139
|
-
}
|
|
140
|
-
else if (typedPropSchema.type === 'object' && typeof value === 'object' && !Array.isArray(value)) {
|
|
141
|
-
result[key] = processEntity(value, typedPropSchema, fullPath);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return result;
|
|
146
|
-
};
|
|
147
|
-
return processEntity(clone, schema);
|
|
148
|
-
}
|
|
149
|
-
function convertStringToObjectId(value) {
|
|
150
|
-
if (value instanceof ObjectId) {
|
|
151
|
-
return value;
|
|
152
|
-
}
|
|
153
|
-
if (value === null || value === undefined) {
|
|
154
|
-
return value;
|
|
155
|
-
}
|
|
156
|
-
if (typeof value === 'string' && entityUtils.isValidObjectId(value)) {
|
|
157
|
-
try {
|
|
158
|
-
return new ObjectId(value);
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
console.warn(`Failed to convert string "${value}" to ObjectId:`, error);
|
|
162
|
-
return value;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return value;
|
|
166
|
-
}
|
|
167
|
-
function buildMongoMatchFromQueryOptions(queryOptions, modelSpec) {
|
|
168
|
-
const filters = queryOptions.filters || {};
|
|
169
|
-
const schema = modelSpec?.fullSchema;
|
|
170
|
-
let match = {};
|
|
171
|
-
console.log('--- Building Mongo Match ---');
|
|
172
|
-
console.log('Received queryOptions.filters:', JSON.stringify(filters, null, 2));
|
|
173
|
-
console.log('Received modelSpec:', !!modelSpec);
|
|
174
|
-
for (const [key, value] of Object.entries(filters)) {
|
|
175
|
-
if (value) {
|
|
176
|
-
const propSchema = schema ? getPropertySchema(key, schema) : undefined;
|
|
177
|
-
if (value.eq !== undefined) {
|
|
178
|
-
const isObjectIdField = propSchema?.format === 'objectid';
|
|
179
|
-
const valueToCompare = value.eq;
|
|
180
|
-
if ((isObjectIdField || (!schema && key.endsWith('Id') && !PROPERTIES_THAT_ARE_NOT_OBJECT_IDS.includes(key)))
|
|
181
|
-
&& typeof valueToCompare === 'string' && entityUtils.isValidObjectId(valueToCompare)) {
|
|
182
|
-
match[key] = new ObjectId(valueToCompare);
|
|
183
|
-
}
|
|
184
|
-
else if (typeof valueToCompare === 'string' && !isNaN(Number(valueToCompare))) {
|
|
185
|
-
match[key] = Number(valueToCompare);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
match[key] = valueToCompare;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
else if (value.in !== undefined && Array.isArray(value.in)) {
|
|
192
|
-
const isObjectIdArray = propSchema?.type === 'array' && propSchema.items?.format === 'objectid';
|
|
193
|
-
if (isObjectIdArray || (!schema && (key.endsWith('Id') || key.endsWith('Ids')) && !PROPERTIES_THAT_ARE_NOT_OBJECT_IDS.includes(key))) {
|
|
194
|
-
const objectIds = value.in
|
|
195
|
-
.filter(val => typeof val === 'string' && entityUtils.isValidObjectId(val))
|
|
196
|
-
.map(val => new ObjectId(val));
|
|
197
|
-
if (objectIds.length > 0) {
|
|
198
|
-
match[key] = { $in: objectIds };
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
const convertedValues = value.in.map(val => typeof val === 'string' && !isNaN(Number(val)) ? Number(val) : val);
|
|
203
|
-
match[key] = { $in: convertedValues };
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
else if (value.gte !== undefined) {
|
|
207
|
-
match[key] = { $gte: value.gte };
|
|
208
|
-
}
|
|
209
|
-
else if (value.lte !== undefined) {
|
|
210
|
-
match[key] = { $lte: value.lte };
|
|
211
|
-
}
|
|
212
|
-
else if (value.gt !== undefined) {
|
|
213
|
-
match[key] = { $gt: value.gt };
|
|
214
|
-
}
|
|
215
|
-
else if (value.lt !== undefined) {
|
|
216
|
-
match[key] = { $lt: value.lt };
|
|
217
|
-
}
|
|
218
|
-
else if (value.contains !== undefined) {
|
|
219
|
-
match[key] = { $regex: value.contains, $options: 'i' };
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
console.log('Constructed $match object:', JSON.stringify(match, null, 2));
|
|
224
|
-
console.log('--------------------------');
|
|
225
|
-
return { $match: match };
|
|
226
|
-
}
|
|
227
|
-
function buildSQLWhereClauseFromQueryOptions(queryOptions, columnAliasMap) {
|
|
228
|
-
const filters = queryOptions.filters || {};
|
|
229
|
-
let whereClause = '';
|
|
230
|
-
for (const [key, value] of Object.entries(filters)) {
|
|
231
|
-
if (value) {
|
|
232
|
-
const tableAlias = (columnAliasMap && columnAliasMap[key]) || '';
|
|
233
|
-
whereClause = addKeyValueToWhereClause(whereClause, key, value, tableAlias);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return whereClause;
|
|
237
|
-
}
|
|
238
|
-
function addKeyValueToWhereClause(whereClause, key, value, tableAlias = '') {
|
|
239
|
-
let column = tableAlias ? `${tableAlias}.${stringUtils.pascalCase(key)}` : stringUtils.pascalCase(key);
|
|
240
|
-
let formattedValue = '';
|
|
241
|
-
let operator = '=';
|
|
242
|
-
if (value) {
|
|
243
|
-
if (value.eq !== undefined) {
|
|
244
|
-
formattedValue = formatValue(value.eq);
|
|
245
|
-
operator = '=';
|
|
246
|
-
}
|
|
247
|
-
else if (value.in !== undefined && Array.isArray(value.in)) {
|
|
248
|
-
const formattedValues = value.in.map(val => formatValue(val)).join(', ');
|
|
249
|
-
formattedValue = `(${formattedValues})`;
|
|
250
|
-
operator = 'IN';
|
|
251
|
-
}
|
|
252
|
-
else if (value.gte !== undefined) {
|
|
253
|
-
formattedValue = formatValue(value.gte);
|
|
254
|
-
operator = '>=';
|
|
255
|
-
}
|
|
256
|
-
else if (value.lte !== undefined) {
|
|
257
|
-
formattedValue = formatValue(value.lte);
|
|
258
|
-
operator = '<=';
|
|
259
|
-
}
|
|
260
|
-
else if (value.gt !== undefined) {
|
|
261
|
-
formattedValue = formatValue(value.gt);
|
|
262
|
-
operator = '>';
|
|
263
|
-
}
|
|
264
|
-
else if (value.lt !== undefined) {
|
|
265
|
-
formattedValue = formatValue(value.lt);
|
|
266
|
-
operator = '<';
|
|
267
|
-
}
|
|
268
|
-
else if (value.contains !== undefined) {
|
|
269
|
-
column = `LOWER(${column})`;
|
|
270
|
-
formattedValue = formatValue(value.contains, true).toLowerCase();
|
|
271
|
-
operator = 'LIKE';
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
const condition = `${column} ${operator} ${formattedValue}`;
|
|
275
|
-
return appendToWhereClause(whereClause, condition);
|
|
276
|
-
}
|
|
277
|
-
function appendToWhereClause(whereClause, condition) {
|
|
278
|
-
let newWhereClause = whereClause.trim();
|
|
279
|
-
if (newWhereClause.toUpperCase() === 'WHERE' || newWhereClause === '') {
|
|
280
|
-
newWhereClause = `WHERE ${condition}`;
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
newWhereClause = `${newWhereClause} AND ${condition}`;
|
|
284
|
-
}
|
|
285
|
-
return newWhereClause;
|
|
286
|
-
}
|
|
287
|
-
function formatValue(value, isLikeOperator = false) {
|
|
288
|
-
if (typeof value === 'string') {
|
|
289
|
-
if (!isNaN(Number(value))) {
|
|
290
|
-
return value;
|
|
291
|
-
}
|
|
292
|
-
if (value.toLowerCase() === 'true') {
|
|
293
|
-
return 'TRUE';
|
|
294
|
-
}
|
|
295
|
-
if (value.toLowerCase() === 'false') {
|
|
296
|
-
return 'FALSE';
|
|
297
|
-
}
|
|
298
|
-
return isLikeOperator ? `'%${value}%'` : `'${value}'`;
|
|
299
|
-
}
|
|
300
|
-
else if (typeof value === 'number') {
|
|
301
|
-
return value.toString();
|
|
302
|
-
}
|
|
303
|
-
else if (typeof value === 'boolean') {
|
|
304
|
-
return value ? 'TRUE' : 'FALSE';
|
|
305
|
-
}
|
|
306
|
-
else if (value instanceof Date) {
|
|
307
|
-
const dateString = value.toISOString().split('T')[0];
|
|
308
|
-
return `DATETIME('${dateString}')`;
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
throw new Error('Unsupported value type');
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
export const dbUtils = {
|
|
315
|
-
buildMongoMatchFromQueryOptions,
|
|
316
|
-
buildSQLWhereClauseFromQueryOptions,
|
|
317
|
-
addKeyValueToWhereClause,
|
|
318
|
-
appendToWhereClause,
|
|
319
|
-
formatValue,
|
|
320
|
-
convertStringToObjectId,
|
|
321
|
-
convertStringsToObjectIds,
|
|
322
|
-
convertObjectIdsToStrings,
|
|
323
|
-
};
|
/package/dist/{controllers/api-controller.utils.d.ts → __tests__/test-database.interface.js}
RENAMED
|
File without changes
|
/package/dist/{controllers/api-controller.utils.js → databases/models/database.interface.js}
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/{models/types/index.js → databases/mongo-db/models/no-sql-pipeline.interface.js}
RENAMED
|
File without changes
|
/package/dist/{services/generic-api-service.interface.js → databases/operations/operation.js}
RENAMED
|
File without changes
|