@loomcore/api 0.2.41 → 0.2.44
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 -201
- package/dist/__tests__/common-test.utils.d.ts +13 -13
- package/dist/__tests__/common-test.utils.js +72 -72
- package/dist/__tests__/models/category.model.d.ts +1 -1
- package/dist/__tests__/models/category.model.js +2 -2
- package/dist/__tests__/models/product-with-category.model.d.ts +3 -3
- package/dist/__tests__/models/product-with-category.model.js +4 -4
- package/dist/__tests__/models/product.model.d.ts +2 -2
- package/dist/__tests__/models/product.model.js +2 -2
- package/dist/__tests__/models/test-entity.model.d.ts +2 -2
- package/dist/__tests__/models/test-entity.model.js +2 -2
- package/dist/__tests__/models/test-item.model.d.ts +1 -1
- package/dist/__tests__/models/test-item.model.js +3 -3
- package/dist/__tests__/mongo-db.test-database.js +1 -1
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.d.ts +2 -2
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +38 -38
- package/dist/__tests__/postgres.test-database.d.ts +2 -2
- package/dist/__tests__/postgres.test-database.js +25 -25
- package/dist/__tests__/test-database.interface.d.ts +1 -1
- package/dist/__tests__/test-email-client.d.ts +1 -1
- package/dist/__tests__/test-express-app.d.ts +3 -3
- package/dist/__tests__/test-express-app.js +12 -12
- package/dist/__tests__/test-objects.d.ts +1 -1
- package/dist/__tests__/test-objects.js +26 -26
- package/dist/config/base-api-config.d.ts +2 -2
- package/dist/config/base-api-config.js +17 -17
- package/dist/controllers/auth.controller.d.ts +4 -4
- package/dist/controllers/auth.controller.js +32 -32
- package/dist/controllers/authorizations.controller.d.ts +4 -4
- package/dist/controllers/authorizations.controller.js +4 -4
- package/dist/controllers/features.controller.d.ts +4 -4
- package/dist/controllers/features.controller.js +4 -4
- package/dist/controllers/index.d.ts +10 -10
- package/dist/controllers/index.js +10 -10
- package/dist/controllers/organizations.controller.d.ts +5 -5
- package/dist/controllers/organizations.controller.js +10 -10
- package/dist/controllers/roles.controller.d.ts +4 -4
- package/dist/controllers/roles.controller.js +4 -4
- package/dist/controllers/types.d.ts +2 -2
- package/dist/controllers/user-roles.controller.d.ts +4 -4
- package/dist/controllers/user-roles.controller.js +4 -4
- package/dist/controllers/users.controller.d.ts +5 -5
- package/dist/controllers/users.controller.js +4 -4
- package/dist/databases/models/database.interface.d.ts +5 -5
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.js +5 -5
- package/dist/databases/mongo-db/commands/mongo-create-many.command.d.ts +1 -1
- package/dist/databases/mongo-db/commands/mongo-create-many.command.js +1 -1
- package/dist/databases/mongo-db/commands/mongo-create.command.d.ts +1 -1
- package/dist/databases/mongo-db/commands/mongo-create.command.js +1 -1
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.js +2 -2
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-update.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-update.command.js +3 -3
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.d.ts +2 -2
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +108 -108
- package/dist/databases/mongo-db/models/no-sql-pipeline.d.ts +4 -4
- package/dist/databases/mongo-db/models/no-sql-pipeline.interface.d.ts +3 -3
- package/dist/databases/mongo-db/models/no-sql-pipeline.js +1 -1
- package/dist/databases/mongo-db/mongo-db.database.d.ts +7 -7
- package/dist/databases/mongo-db/mongo-db.database.js +5 -5
- package/dist/databases/mongo-db/queries/mongo-find-one.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-find-one.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-find.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-find.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-get-all.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-get-all.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.d.ts +4 -4
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.js +3 -3
- package/dist/databases/mongo-db/queries/mongo-get-count.query.d.ts +1 -1
- package/dist/databases/mongo-db/queries/mongo-get.query.d.ts +3 -3
- package/dist/databases/mongo-db/queries/mongo-get.query.js +2 -2
- package/dist/databases/mongo-db/utils/build-find-options.util.d.ts +2 -2
- package/dist/databases/mongo-db/utils/build-mongo-url.util.d.ts +1 -1
- package/dist/databases/mongo-db/utils/build-mongo-url.util.js +4 -4
- package/dist/databases/operations/__tests__/models/test-agent.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-agent.model.js +3 -3
- package/dist/databases/operations/__tests__/models/test-client-report.model.d.ts +4 -4
- package/dist/databases/operations/__tests__/models/test-client-report.model.js +5 -5
- package/dist/databases/operations/__tests__/models/test-district.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-district.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-email-address.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-email-address.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-person.model.d.ts +4 -4
- package/dist/databases/operations/__tests__/models/test-person.model.js +4 -4
- package/dist/databases/operations/__tests__/models/test-phone-number.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-phone-number.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-policy.model.d.ts +3 -3
- package/dist/databases/operations/__tests__/models/test-policy.model.js +4 -4
- package/dist/databases/operations/__tests__/models/test-premium.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-premium.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-school.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-school.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-state.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-state.model.js +2 -2
- package/dist/databases/operations/operation.d.ts +3 -3
- package/dist/databases/postgres/commands/postgres-batch-update.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-batch-update.command.js +11 -11
- package/dist/databases/postgres/commands/postgres-create-many.command.js +5 -5
- package/dist/databases/postgres/commands/postgres-create.command.d.ts +3 -3
- package/dist/databases/postgres/commands/postgres-create.command.js +5 -5
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.js +1 -1
- package/dist/databases/postgres/commands/postgres-delete-many.command.d.ts +2 -2
- package/dist/databases/postgres/commands/postgres-delete-many.command.js +1 -1
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +4 -4
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +11 -11
- package/dist/databases/postgres/commands/postgres-update.command.d.ts +2 -2
- package/dist/databases/postgres/commands/postgres-update.command.js +11 -11
- package/dist/databases/postgres/migrations/postgres-initial-schema.d.ts +2 -2
- package/dist/databases/postgres/migrations/postgres-initial-schema.js +69 -69
- package/dist/databases/postgres/postgres.database.d.ts +6 -6
- package/dist/databases/postgres/postgres.database.js +18 -18
- package/dist/databases/postgres/queries/postgres-find-one.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-find-one.query.js +2 -2
- package/dist/databases/postgres/queries/postgres-find.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-find.query.js +2 -2
- package/dist/databases/postgres/queries/postgres-get-all.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-get-all.query.js +3 -3
- package/dist/databases/postgres/queries/postgres-get-by-id.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-get-by-id.query.js +5 -5
- package/dist/databases/postgres/queries/postgres-get-count.query.js +1 -1
- package/dist/databases/postgres/queries/postgres-get.query.d.ts +2 -2
- package/dist/databases/postgres/queries/postgres-get.query.js +9 -9
- package/dist/databases/postgres/utils/build-count-query.d.ts +1 -1
- package/dist/databases/postgres/utils/build-count-query.js +1 -1
- package/dist/databases/postgres/utils/build-join-clauses.d.ts +1 -1
- package/dist/databases/postgres/utils/build-join-clauses.js +7 -7
- package/dist/databases/postgres/utils/build-order-by-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-pagination-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-postgres-url.util.d.ts +1 -1
- package/dist/databases/postgres/utils/build-postgres-url.util.js +2 -2
- package/dist/databases/postgres/utils/build-select-clause.js +9 -9
- package/dist/databases/postgres/utils/build-where-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-where-clause.js +1 -1
- package/dist/databases/postgres/utils/columns-and-values-from-entity.d.ts +1 -1
- package/dist/databases/postgres/utils/does-table-exist.util.d.ts +1 -1
- package/dist/databases/postgres/utils/does-table-exist.util.js +5 -5
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/middleware/authorize/authenticate-request.d.ts +2 -2
- package/dist/middleware/authorize/authenticate-request.js +5 -5
- package/dist/middleware/index.d.ts +4 -4
- package/dist/middleware/index.js +4 -4
- package/dist/models/app-config.interface.d.ts +1 -1
- package/dist/models/base-api-config.interface.d.ts +6 -6
- package/dist/models/initial-database-config.interface.d.ts +3 -3
- package/dist/models/log-level.type.d.ts +1 -1
- package/dist/services/authorizations.service.d.ts +3 -3
- package/dist/services/authorizations.service.js +7 -7
- package/dist/services/email.service.js +5 -5
- package/dist/services/features.service.d.ts +3 -3
- package/dist/services/features.service.js +4 -4
- package/dist/services/generic-api-service/generic-api-service.interface.d.ts +6 -6
- package/dist/services/generic-api-service/generic-api.service.d.ts +8 -8
- package/dist/services/generic-api-service/generic-api.service.js +7 -7
- package/dist/services/index.d.ts +16 -16
- package/dist/services/index.js +16 -16
- package/dist/services/multi-tenant-api.service.d.ts +4 -4
- package/dist/services/multi-tenant-api.service.js +9 -9
- package/dist/services/organization-domain.service.d.ts +3 -3
- package/dist/services/organization-domain.service.js +3 -3
- package/dist/services/organization.service.d.ts +4 -4
- package/dist/services/organization.service.js +7 -7
- package/dist/services/password-reset-token.service.d.ts +3 -3
- package/dist/services/password-reset-token.service.js +5 -5
- package/dist/services/refresh-token.service.d.ts +3 -3
- package/dist/services/refresh-token.service.js +3 -3
- package/dist/services/roles.service.d.ts +3 -3
- package/dist/services/roles.service.js +4 -4
- package/dist/services/tenant-query-decorator.d.ts +1 -1
- package/dist/services/tenant-query-decorator.js +8 -8
- package/dist/services/user-roles.service.d.ts +3 -3
- package/dist/services/user-roles.service.js +4 -4
- package/dist/services/user.service.d.ts +4 -4
- package/dist/services/user.service.js +11 -11
- package/dist/services/utils/audit-for-create.util.d.ts +1 -1
- package/dist/services/utils/audit-for-create.util.js +2 -2
- package/dist/services/utils/audit-for-update.util.d.ts +1 -1
- package/dist/services/utils/audit-for-update.util.js +2 -2
- package/dist/services/utils/strip-sender-provided-system-properties.util.d.ts +1 -1
- package/dist/services/utils/strip-sender-provided-system-properties.util.js +4 -4
- package/dist/utils/auth/assert-admin-or-feature.util.d.ts +1 -1
- package/dist/utils/auth/assert-admin-or-feature.util.js +2 -2
- package/dist/utils/auth/assert-admin.util.d.ts +1 -1
- package/dist/utils/auth/assert-admin.util.js +2 -2
- package/dist/utils/auth/assert-owner-or-admin.util.d.ts +1 -1
- package/dist/utils/auth/assert-owner-or-admin.util.js +2 -2
- package/dist/utils/auth/assert-user-has-feature.util.d.ts +1 -1
- package/dist/utils/auth/assert-user-has-feature.util.js +1 -1
- package/dist/utils/auth/assert-user-or-admin.util.d.ts +2 -2
- package/dist/utils/auth/assert-user-or-admin.util.js +2 -2
- package/dist/utils/auth/attempt-login.util.d.ts +4 -4
- package/dist/utils/auth/attempt-login.util.js +8 -8
- package/dist/utils/auth/auth-user-specs.util.d.ts +1 -1
- package/dist/utils/auth/auth-user-specs.util.js +3 -3
- package/dist/utils/auth/change-password.util.d.ts +4 -4
- package/dist/utils/auth/change-password.util.js +2 -2
- package/dist/utils/auth/create-new-refresh-token.util.d.ts +3 -3
- package/dist/utils/auth/create-new-refresh-token.util.js +8 -8
- package/dist/utils/auth/create-new-tokens.util.d.ts +1 -1
- package/dist/utils/auth/create-new-tokens.util.js +3 -3
- package/dist/utils/auth/generate-device-id.util.js +2 -2
- package/dist/utils/auth/generate-refresh-token.util.js +2 -2
- package/dist/utils/auth/get-active-refresh-token.util.d.ts +2 -2
- package/dist/utils/auth/get-active-refresh-token.util.js +1 -1
- package/dist/utils/auth/get-and-set-device-id-cookie.util.d.ts +1 -1
- package/dist/utils/auth/get-and-set-device-id-cookie.util.js +4 -4
- package/dist/utils/auth/get-auth-config.util.d.ts +1 -1
- package/dist/utils/auth/get-auth-config.util.js +3 -3
- package/dist/utils/auth/get-device-id-from-cookie.util.d.ts +1 -1
- package/dist/utils/auth/index.d.ts +26 -26
- package/dist/utils/auth/index.js +26 -26
- package/dist/utils/auth/is-admin.util.d.ts +1 -1
- package/dist/utils/auth/is-admin.util.js +1 -1
- package/dist/utils/auth/log-user-in.util.d.ts +3 -3
- package/dist/utils/auth/log-user-in.util.js +5 -5
- package/dist/utils/auth/request-token-using-refresh-token.util.d.ts +4 -4
- package/dist/utils/auth/request-token-using-refresh-token.util.js +7 -7
- package/dist/utils/auth/reset-password.util.d.ts +4 -4
- package/dist/utils/auth/reset-password.util.js +8 -8
- package/dist/utils/auth/send-reset-password-email.util.d.ts +2 -2
- package/dist/utils/auth/send-reset-password-email.util.js +5 -5
- package/dist/utils/auth/update-last-logged-in.util.d.ts +3 -3
- package/dist/utils/auth/update-last-logged-in.util.js +3 -3
- package/dist/utils/create-public-spec.utils.d.ts +1 -1
- package/dist/utils/create-public-spec.utils.js +3 -3
- package/dist/utils/express.utils.d.ts +4 -4
- package/dist/utils/express.utils.js +5 -5
- package/dist/utils/index.d.ts +10 -10
- package/dist/utils/index.js +10 -10
- package/dist/utils/jwt.utils.d.ts +1 -1
- package/dist/utils/jwt.utils.js +3 -3
- package/dist/utils/logger.utils.d.ts +1 -1
- package/dist/utils/logger.utils.js +10 -10
- package/dist/utils/password.utils.js +7 -7
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { FindOptions } from
|
|
2
|
-
import { IQueryOptions } from
|
|
1
|
+
import { FindOptions } from 'mongodb';
|
|
2
|
+
import { IQueryOptions } from '@loomcore/common/models';
|
|
3
3
|
export declare function buildFindOptions(queryOptions: IQueryOptions): FindOptions;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
function isAtlasSrvHost(host) {
|
|
2
|
-
return host.toLowerCase().endsWith(
|
|
2
|
+
return host.toLowerCase().endsWith('.mongodb.net');
|
|
3
3
|
}
|
|
4
4
|
export function buildMongoUrl(config) {
|
|
5
5
|
const { database } = config;
|
|
6
6
|
if (!database) {
|
|
7
|
-
throw new Error(
|
|
7
|
+
throw new Error('Database configuration is required to build the MongoDB URL.');
|
|
8
8
|
}
|
|
9
9
|
const { username, password, host, port, name } = database;
|
|
10
10
|
if (!username || !password || !host || !name) {
|
|
11
|
-
throw new Error(
|
|
11
|
+
throw new Error('Database configuration must include user, password, host, and name to build the MongoDB URL.');
|
|
12
12
|
}
|
|
13
13
|
const encodedUsername = encodeURIComponent(username);
|
|
14
14
|
const encodedPassword = encodeURIComponent(password);
|
|
@@ -16,7 +16,7 @@ export function buildMongoUrl(config) {
|
|
|
16
16
|
return `mongodb+srv://${encodedUsername}:${encodedPassword}@${host}/${name}?authSource=admin&retryWrites=true&w=majority`;
|
|
17
17
|
}
|
|
18
18
|
if (!port) {
|
|
19
|
-
throw new Error(
|
|
19
|
+
throw new Error('Database configuration must include port to build a non-SRV MongoDB URL.');
|
|
20
20
|
}
|
|
21
21
|
return `mongodb://${encodedUsername}:${encodedPassword}@${host}:${port}/${name}?authSource=admin`;
|
|
22
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IAuditable, IEntity } from
|
|
2
|
-
import { ITestPersonModel } from
|
|
1
|
+
import { IAuditable, IEntity } from '@loomcore/common/models';
|
|
2
|
+
import { ITestPersonModel } from './test-person.model.js';
|
|
3
3
|
export interface ITestAgentModel extends IEntity, IAuditable {
|
|
4
4
|
personId: number;
|
|
5
5
|
agentPerson?: ITestPersonModel;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
3
|
-
import { testPersonSchema } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { testPersonSchema } from './test-person.model.js';
|
|
4
4
|
export const testAgentSchema = Type.Object({
|
|
5
5
|
personId: Type.Number(),
|
|
6
6
|
agentPerson: Type.Optional(testPersonSchema),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ITestPersonModel } from
|
|
2
|
-
import { ITestAgentModel } from
|
|
3
|
-
import { ITestPolicyModel } from
|
|
4
|
-
import type { IAuditable, IEntity } from
|
|
1
|
+
import { ITestPersonModel } from './test-person.model.js';
|
|
2
|
+
import { ITestAgentModel } from './test-agent.model.js';
|
|
3
|
+
import { ITestPolicyModel } from './test-policy.model.js';
|
|
4
|
+
import type { IAuditable, IEntity } from '@loomcore/common/models';
|
|
5
5
|
export interface ITestClientReportsModel extends IEntity, IAuditable {
|
|
6
6
|
clientPerson: ITestPersonModel;
|
|
7
7
|
agent?: ITestAgentModel;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { testPersonSchema } from
|
|
2
|
-
import { testAgentSchema } from
|
|
3
|
-
import { testPolicySchema } from
|
|
4
|
-
import { entityUtils } from
|
|
5
|
-
import { Type } from
|
|
1
|
+
import { testPersonSchema } from './test-person.model.js';
|
|
2
|
+
import { testAgentSchema } from './test-agent.model.js';
|
|
3
|
+
import { testPolicySchema } from './test-policy.model.js';
|
|
4
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
5
|
+
import { Type } from '@sinclair/typebox';
|
|
6
6
|
export const testClientReportsSchema = Type.Object({
|
|
7
7
|
clientPerson: testPersonSchema,
|
|
8
8
|
agent: Type.Optional(testAgentSchema),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IAuditable, IEntity } from
|
|
2
|
-
import { ITestStateModel } from
|
|
1
|
+
import type { IAuditable, IEntity } from '@loomcore/common/models';
|
|
2
|
+
import { ITestStateModel } from './test-state.model.js';
|
|
3
3
|
export interface ITestDistrictModel extends IEntity, IAuditable {
|
|
4
4
|
name: string;
|
|
5
5
|
stateId: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
3
|
export const testDistrictSchema = Type.Object({
|
|
4
4
|
name: Type.String(),
|
|
5
5
|
stateId: Type.Number(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
3
|
export const testEmailAddressSchema = Type.Object({
|
|
4
4
|
personId: Type.Number(),
|
|
5
5
|
emailAddress: Type.String(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IAuditable, IEntity } from
|
|
2
|
-
import { ITestEmailAddressModel } from
|
|
3
|
-
import { ITestPhoneNumberModel } from
|
|
4
|
-
import { ITestSchoolModel } from
|
|
1
|
+
import type { IAuditable, IEntity } from '@loomcore/common/models';
|
|
2
|
+
import { ITestEmailAddressModel } from './test-email-address.model.js';
|
|
3
|
+
import { ITestPhoneNumberModel } from './test-phone-number.model.js';
|
|
4
|
+
import { ITestSchoolModel } from './test-school.model.js';
|
|
5
5
|
export interface ITestPersonModel extends IEntity, IAuditable {
|
|
6
6
|
firstName: string;
|
|
7
7
|
middleName: string | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
3
|
-
import { testEmailAddressSchema } from
|
|
4
|
-
import { testPhoneNumberSchema } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { testEmailAddressSchema } from './test-email-address.model.js';
|
|
4
|
+
import { testPhoneNumberSchema } from './test-phone-number.model.js';
|
|
5
5
|
export const testPersonSchema = Type.Object({
|
|
6
6
|
firstName: Type.String(),
|
|
7
7
|
middleName: Type.Optional(Type.String()),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
3
|
export const testPhoneNumberSchema = Type.Object({
|
|
4
4
|
phoneNumber: Type.String(),
|
|
5
5
|
phoneNumberType: Type.String(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { IAuditable, IEntity } from
|
|
2
|
-
import { ITestAgentModel } from
|
|
3
|
-
import { ITestPremiumModel } from
|
|
1
|
+
import type { IAuditable, IEntity } from '@loomcore/common/models';
|
|
2
|
+
import { ITestAgentModel } from './test-agent.model.js';
|
|
3
|
+
import { ITestPremiumModel } from './test-premium.model.js';
|
|
4
4
|
export interface ITestPolicyModel extends IEntity, IAuditable {
|
|
5
5
|
clientId: number;
|
|
6
6
|
amount: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
3
|
-
import { testAgentSchema } from
|
|
4
|
-
import { testPremiumSchema } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { testAgentSchema } from './test-agent.model.js';
|
|
4
|
+
import { testPremiumSchema } from './test-premium.model.js';
|
|
5
5
|
export const testPolicySchema = Type.Object({
|
|
6
6
|
clientId: Type.Number(),
|
|
7
7
|
amount: Type.Number(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
3
|
export const testPremiumSchema = Type.Object({
|
|
4
4
|
policyId: Type.Number(),
|
|
5
5
|
amount: Type.Number(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IAuditable, IEntity } from
|
|
2
|
-
import { ITestDistrictModel } from
|
|
1
|
+
import type { IAuditable, IEntity } from '@loomcore/common/models';
|
|
2
|
+
import { ITestDistrictModel } from './test-district.model.js';
|
|
3
3
|
export interface ITestSchoolModel extends IEntity, IAuditable {
|
|
4
4
|
name: string;
|
|
5
5
|
districtId: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
3
|
export const testSchoolSchema = Type.Object({
|
|
4
4
|
name: Type.String(),
|
|
5
5
|
districtId: Type.Number(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
3
|
export const testStateSchema = Type.Object({
|
|
4
4
|
name: Type.String(),
|
|
5
5
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LeftJoin } from
|
|
2
|
-
import { InnerJoin } from
|
|
3
|
-
import { LeftJoinMany } from
|
|
1
|
+
import { LeftJoin } from './left-join.operation.js';
|
|
2
|
+
import { InnerJoin } from './inner-join.operation.js';
|
|
3
|
+
import { LeftJoinMany } from './left-join-many.operation.js';
|
|
4
4
|
export type Operation = LeftJoin | InnerJoin | LeftJoinMany;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PostgresConnection } from '../postgres-connection.js';
|
|
2
|
-
import { Operation } from
|
|
2
|
+
import { Operation } from '../../operations/operation.js';
|
|
3
3
|
import { IEntity, IQueryOptions } from '@loomcore/common/models';
|
|
4
4
|
export declare function batchUpdate<T extends IEntity>(connection: PostgresConnection, entities: Partial<T>[], operations: Operation[], queryObject: IQueryOptions, pluralResourceName: string): Promise<T[]>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Pool } from 'pg';
|
|
2
|
-
import { LeftJoin } from
|
|
3
|
-
import { InnerJoin } from
|
|
4
|
-
import { LeftJoinMany } from
|
|
5
|
-
import { BadRequestError } from
|
|
2
|
+
import { LeftJoin } from '../../operations/left-join.operation.js';
|
|
3
|
+
import { InnerJoin } from '../../operations/inner-join.operation.js';
|
|
4
|
+
import { LeftJoinMany } from '../../operations/left-join-many.operation.js';
|
|
5
|
+
import { BadRequestError } from '../../../errors/index.js';
|
|
6
6
|
import { buildJoinClauses } from '../utils/build-join-clauses.js';
|
|
7
7
|
import { buildSelectClause } from '../utils/build-select-clause.js';
|
|
8
8
|
import { transformJoinResults } from '../utils/transform-join-results.js';
|
|
@@ -41,10 +41,10 @@ export async function batchUpdate(connection, entities, operations, queryObject,
|
|
|
41
41
|
queryObject.filters._id = { eq: _id };
|
|
42
42
|
const { whereClause } = buildWhereClause(queryObject, values);
|
|
43
43
|
const query = `
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
UPDATE "${pluralResourceName}"
|
|
45
|
+
SET ${setClause}
|
|
46
|
+
${whereClause}
|
|
47
|
+
`;
|
|
48
48
|
await session.query(query, values);
|
|
49
49
|
}
|
|
50
50
|
await session.query('COMMIT');
|
|
@@ -57,9 +57,9 @@ export async function batchUpdate(connection, entities, operations, queryObject,
|
|
|
57
57
|
? await buildSelectClause(session, pluralResourceName, operations)
|
|
58
58
|
: '*';
|
|
59
59
|
const selectQuery = `
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
SELECT ${selectClause} FROM "${pluralResourceName}" ${joinClauses}
|
|
61
|
+
${whereClause}
|
|
62
|
+
`;
|
|
63
63
|
const result = await session.query(selectQuery, values);
|
|
64
64
|
return hasJoins
|
|
65
65
|
? transformJoinResults(result.rows, operations)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BadRequestError, DuplicateKeyError } from
|
|
1
|
+
import { BadRequestError, DuplicateKeyError } from '../../../errors/index.js';
|
|
2
2
|
export async function createMany(client, pluralResourceName, entities) {
|
|
3
3
|
if (entities.length === 0) {
|
|
4
4
|
return {
|
|
@@ -34,10 +34,10 @@ export async function createMany(client, pluralResourceName, entities) {
|
|
|
34
34
|
allValues.push(...values);
|
|
35
35
|
});
|
|
36
36
|
const query = `
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
INSERT INTO "${pluralResourceName}" (${columns.map(col => `"${col}"`).join(', ')})
|
|
38
|
+
VALUES ${valueClauses.join(', ')}
|
|
39
|
+
RETURNING *
|
|
40
|
+
`;
|
|
41
41
|
const result = await client.query(query, allValues);
|
|
42
42
|
if (result.rows.length !== entities.length) {
|
|
43
43
|
throw new BadRequestError(`Error creating ${pluralResourceName}: Expected ${entities.length} rows, got ${result.rows.length}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { IEntity } from
|
|
2
|
-
import type { AppIdType } from
|
|
3
|
-
import type { PostgresConnection } from
|
|
1
|
+
import type { IEntity } from '@loomcore/common/models';
|
|
2
|
+
import type { AppIdType } from '@loomcore/common/types';
|
|
3
|
+
import type { PostgresConnection } from '../postgres-connection.js';
|
|
4
4
|
export declare function create<T extends IEntity>(client: PostgresConnection, pluralResourceName: string, entity: Partial<T>): Promise<{
|
|
5
5
|
insertedId: AppIdType;
|
|
6
6
|
entity: T;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BadRequestError, DuplicateKeyError } from
|
|
2
|
-
import { columnsAndValuesFromEntity } from
|
|
1
|
+
import { BadRequestError, DuplicateKeyError } from '../../../errors/index.js';
|
|
2
|
+
import { columnsAndValuesFromEntity } from '../utils/columns-and-values-from-entity.js';
|
|
3
3
|
export async function create(client, pluralResourceName, entity) {
|
|
4
4
|
try {
|
|
5
5
|
delete entity._id;
|
|
6
6
|
const { columns, values } = columnsAndValuesFromEntity(entity);
|
|
7
|
-
const placeholders = columns.map((_, index) => `$${index + 1}`).join(
|
|
7
|
+
const placeholders = columns.map((_, index) => `$${index + 1}`).join(', ');
|
|
8
8
|
const query = `
|
|
9
|
-
INSERT INTO "${pluralResourceName}" (${columns.join(
|
|
9
|
+
INSERT INTO "${pluralResourceName}" (${columns.join(', ')})
|
|
10
10
|
VALUES (${placeholders})
|
|
11
11
|
RETURNING *
|
|
12
12
|
`;
|
|
@@ -22,7 +22,7 @@ export async function create(client, pluralResourceName, entity) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
catch (err) {
|
|
25
|
-
if (err.code ===
|
|
25
|
+
if (err.code === '23505') {
|
|
26
26
|
throw new DuplicateKeyError(`${pluralResourceName} already exists`);
|
|
27
27
|
}
|
|
28
28
|
throw new BadRequestError(`Error creating ${pluralResourceName}: ${err.message}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PostgresConnection } from '../postgres-connection.js';
|
|
2
|
-
import { DeleteResult } from
|
|
2
|
+
import { DeleteResult } from '../../models/delete-result.js';
|
|
3
3
|
import type { AppIdType } from '@loomcore/common/types';
|
|
4
4
|
export declare function deleteById(client: PostgresConnection, id: AppIdType, pluralResourceName: string): Promise<DeleteResult>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeleteResult } from
|
|
1
|
+
import { DeleteResult } from '../../models/delete-result.js';
|
|
2
2
|
export async function deleteById(client, id, pluralResourceName) {
|
|
3
3
|
const query = `DELETE FROM "${pluralResourceName}" WHERE "_id" = $1`;
|
|
4
4
|
const result = await client.query(query, [id]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PostgresConnection } from '../postgres-connection.js';
|
|
2
|
-
import { IQueryOptions } from
|
|
3
|
-
import { DeleteResult } from
|
|
2
|
+
import { IQueryOptions } from '@loomcore/common/models';
|
|
3
|
+
import { DeleteResult } from '../../models/delete-result.js';
|
|
4
4
|
export declare function deleteMany(client: PostgresConnection, queryObject: IQueryOptions, pluralResourceName: string): Promise<DeleteResult>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildWhereClause } from '../utils/build-where-clause.js';
|
|
2
|
-
import { DeleteResult } from
|
|
2
|
+
import { DeleteResult } from '../../models/delete-result.js';
|
|
3
3
|
export async function deleteMany(client, queryObject, pluralResourceName) {
|
|
4
4
|
try {
|
|
5
5
|
const { whereClause, values } = buildWhereClause(queryObject);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PostgresConnection } from '../postgres-connection.js';
|
|
2
|
-
import { Operation } from
|
|
2
|
+
import { Operation } from '../../operations/operation.js';
|
|
3
3
|
import { IEntity } from '@loomcore/common/models';
|
|
4
4
|
import type { AppIdType } from '@loomcore/common/types';
|
|
5
5
|
export declare function fullUpdateById<T extends IEntity>(client: PostgresConnection, operations: Operation[], id: AppIdType, entity: Partial<T>, pluralResourceName: string): Promise<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { LeftJoin } from
|
|
2
|
-
import { InnerJoin } from
|
|
3
|
-
import { LeftJoinMany } from
|
|
4
|
-
import { BadRequestError, IdNotFoundError } from
|
|
1
|
+
import { LeftJoin } from '../../operations/left-join.operation.js';
|
|
2
|
+
import { InnerJoin } from '../../operations/inner-join.operation.js';
|
|
3
|
+
import { LeftJoinMany } from '../../operations/left-join-many.operation.js';
|
|
4
|
+
import { BadRequestError, IdNotFoundError } from '../../../errors/index.js';
|
|
5
5
|
import { buildJoinClauses } from '../utils/build-join-clauses.js';
|
|
6
6
|
import { buildSelectClause } from '../utils/build-select-clause.js';
|
|
7
7
|
export async function fullUpdateById(client, operations, id, entity, pluralResourceName) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PostgresConnection } from '../postgres-connection.js';
|
|
2
|
-
import { Operation } from
|
|
2
|
+
import { Operation } from '../../operations/operation.js';
|
|
3
3
|
import { IEntity } from '@loomcore/common/models';
|
|
4
4
|
import type { AppIdType } from '@loomcore/common/types';
|
|
5
5
|
export declare function partialUpdateById<T extends IEntity>(client: PostgresConnection, operations: Operation[], id: AppIdType, entity: Partial<T>, pluralResourceName: string): Promise<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { LeftJoin } from
|
|
2
|
-
import { InnerJoin } from
|
|
3
|
-
import { LeftJoinMany } from
|
|
4
|
-
import { BadRequestError, IdNotFoundError } from
|
|
1
|
+
import { LeftJoin } from '../../operations/left-join.operation.js';
|
|
2
|
+
import { InnerJoin } from '../../operations/inner-join.operation.js';
|
|
3
|
+
import { LeftJoinMany } from '../../operations/left-join-many.operation.js';
|
|
4
|
+
import { BadRequestError, IdNotFoundError } from '../../../errors/index.js';
|
|
5
5
|
import { buildJoinClauses } from '../utils/build-join-clauses.js';
|
|
6
6
|
import { buildSelectClause } from '../utils/build-select-clause.js';
|
|
7
7
|
import { columnsAndValuesFromEntity } from '../utils/columns-and-values-from-entity.js';
|
|
@@ -15,10 +15,10 @@ export async function partialUpdateById(client, operations, id, entity, pluralRe
|
|
|
15
15
|
}
|
|
16
16
|
const setClause = updateColumns.map((col, index) => `${col} = $${index + 1}`).join(', ');
|
|
17
17
|
const query = `
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
UPDATE "${pluralResourceName}"
|
|
19
|
+
SET ${setClause}
|
|
20
|
+
WHERE "_id" = $${updateValues.length + 1}
|
|
21
|
+
`;
|
|
22
22
|
const result = await client.query(query, [...updateValues, id]);
|
|
23
23
|
if (result.rowCount === 0) {
|
|
24
24
|
throw new IdNotFoundError();
|
|
@@ -32,9 +32,9 @@ export async function partialUpdateById(client, operations, id, entity, pluralRe
|
|
|
32
32
|
: '*';
|
|
33
33
|
const idColumn = hasJoins ? `"${pluralResourceName}"."_id"` : '"_id"';
|
|
34
34
|
const selectQuery = `
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
SELECT ${selectClause} FROM "${pluralResourceName}" ${joinClauses}
|
|
36
|
+
WHERE ${idColumn} = $1 LIMIT 1
|
|
37
|
+
`;
|
|
38
38
|
const selectResult = await client.query(selectQuery, [id]);
|
|
39
39
|
if (selectResult.rows.length === 0) {
|
|
40
40
|
throw new IdNotFoundError();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PostgresConnection } from '../postgres-connection.js';
|
|
2
|
-
import { IQueryOptions } from
|
|
3
|
-
import { Operation } from
|
|
2
|
+
import { IQueryOptions } from '@loomcore/common/models';
|
|
3
|
+
import { Operation } from '../../operations/operation.js';
|
|
4
4
|
import { IEntity } from '@loomcore/common/models';
|
|
5
5
|
export declare function update<T extends IEntity>(client: PostgresConnection, queryObject: IQueryOptions, entity: Partial<T>, operations: Operation[], pluralResourceName: string): Promise<T[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { LeftJoin } from
|
|
2
|
-
import { InnerJoin } from
|
|
3
|
-
import { LeftJoinMany } from
|
|
4
|
-
import { BadRequestError, NotFoundError } from
|
|
1
|
+
import { LeftJoin } from '../../operations/left-join.operation.js';
|
|
2
|
+
import { InnerJoin } from '../../operations/inner-join.operation.js';
|
|
3
|
+
import { LeftJoinMany } from '../../operations/left-join-many.operation.js';
|
|
4
|
+
import { BadRequestError, NotFoundError } from '../../../errors/index.js';
|
|
5
5
|
import { buildWhereClause } from '../utils/build-where-clause.js';
|
|
6
6
|
import { buildJoinClauses } from '../utils/build-join-clauses.js';
|
|
7
7
|
import { buildOrderByClause } from '../utils/build-order-by-clause.js';
|
|
@@ -22,10 +22,10 @@ export async function update(client, queryObject, entity, operations, pluralReso
|
|
|
22
22
|
return `$${originalIndex + updateValues.length}`;
|
|
23
23
|
});
|
|
24
24
|
const updateQuery = `
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
UPDATE "${pluralResourceName}"
|
|
26
|
+
SET ${setClause}
|
|
27
|
+
${whereClauseWithAdjustedParams}
|
|
28
|
+
`;
|
|
29
29
|
const allUpdateValues = [...updateValues, ...whereValues];
|
|
30
30
|
const result = await client.query(updateQuery, allUpdateValues);
|
|
31
31
|
if (result.rowCount === 0) {
|
|
@@ -42,9 +42,9 @@ export async function update(client, queryObject, entity, operations, pluralReso
|
|
|
42
42
|
? await buildSelectClause(client, pluralResourceName, operations)
|
|
43
43
|
: '*';
|
|
44
44
|
const selectQuery = `
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
SELECT ${selectClause} FROM "${pluralResourceName}" ${joinClauses}
|
|
46
|
+
${selectWhereClause} ${orderByClause}
|
|
47
|
+
`.trim();
|
|
48
48
|
const selectResult = await client.query(selectQuery, selectWhereValues);
|
|
49
49
|
return hasJoins
|
|
50
50
|
? selectResult.rows.map(r => r.entity)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Pool } from
|
|
2
|
-
import type { IInitialDbMigrationConfig } from
|
|
1
|
+
import type { Pool } from 'pg';
|
|
2
|
+
import type { IInitialDbMigrationConfig } from '../../../models/initial-database-config.interface.js';
|
|
3
3
|
export interface SyntheticMigration {
|
|
4
4
|
name: string;
|
|
5
5
|
up: (context: {
|