@loomcore/api 0.2.42 → 0.2.45

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 (245) hide show
  1. package/LICENSE +201 -201
  2. package/dist/__tests__/common-test.utils.d.ts +13 -13
  3. package/dist/__tests__/common-test.utils.js +72 -72
  4. package/dist/__tests__/models/category.model.d.ts +1 -1
  5. package/dist/__tests__/models/category.model.js +2 -2
  6. package/dist/__tests__/models/product-with-category.model.d.ts +3 -3
  7. package/dist/__tests__/models/product-with-category.model.js +4 -4
  8. package/dist/__tests__/models/product.model.d.ts +2 -2
  9. package/dist/__tests__/models/product.model.js +2 -2
  10. package/dist/__tests__/models/test-entity.model.d.ts +2 -2
  11. package/dist/__tests__/models/test-entity.model.js +2 -2
  12. package/dist/__tests__/models/test-item.model.d.ts +1 -1
  13. package/dist/__tests__/models/test-item.model.js +3 -3
  14. package/dist/__tests__/mongo-db.test-database.js +1 -1
  15. package/dist/__tests__/postgres-test-migrations/postgres-test-schema.d.ts +2 -2
  16. package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +38 -38
  17. package/dist/__tests__/postgres.test-database.d.ts +2 -2
  18. package/dist/__tests__/postgres.test-database.js +25 -25
  19. package/dist/__tests__/test-database.interface.d.ts +1 -1
  20. package/dist/__tests__/test-email-client.d.ts +1 -1
  21. package/dist/__tests__/test-express-app.d.ts +3 -3
  22. package/dist/__tests__/test-express-app.js +12 -12
  23. package/dist/__tests__/test-objects.d.ts +1 -1
  24. package/dist/__tests__/test-objects.js +26 -26
  25. package/dist/config/base-api-config.d.ts +2 -2
  26. package/dist/config/base-api-config.js +17 -17
  27. package/dist/controllers/auth.controller.d.ts +4 -4
  28. package/dist/controllers/auth.controller.js +32 -32
  29. package/dist/controllers/authorizations.controller.d.ts +4 -4
  30. package/dist/controllers/authorizations.controller.js +4 -4
  31. package/dist/controllers/features.controller.d.ts +4 -4
  32. package/dist/controllers/features.controller.js +4 -4
  33. package/dist/controllers/index.d.ts +10 -10
  34. package/dist/controllers/index.js +10 -10
  35. package/dist/controllers/organizations.controller.d.ts +5 -5
  36. package/dist/controllers/organizations.controller.js +10 -10
  37. package/dist/controllers/roles.controller.d.ts +4 -4
  38. package/dist/controllers/roles.controller.js +4 -4
  39. package/dist/controllers/types.d.ts +2 -2
  40. package/dist/controllers/user-roles.controller.d.ts +4 -4
  41. package/dist/controllers/user-roles.controller.js +4 -4
  42. package/dist/controllers/users.controller.d.ts +5 -5
  43. package/dist/controllers/users.controller.js +4 -4
  44. package/dist/databases/models/database.interface.d.ts +5 -5
  45. package/dist/databases/mongo-db/commands/mongo-batch-update.command.d.ts +3 -3
  46. package/dist/databases/mongo-db/commands/mongo-batch-update.command.js +5 -5
  47. package/dist/databases/mongo-db/commands/mongo-create-many.command.d.ts +1 -1
  48. package/dist/databases/mongo-db/commands/mongo-create-many.command.js +1 -1
  49. package/dist/databases/mongo-db/commands/mongo-create.command.d.ts +1 -1
  50. package/dist/databases/mongo-db/commands/mongo-create.command.js +1 -1
  51. package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.d.ts +3 -3
  52. package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.js +4 -4
  53. package/dist/databases/mongo-db/commands/mongo-delete-many.command.d.ts +3 -3
  54. package/dist/databases/mongo-db/commands/mongo-delete-many.command.js +2 -2
  55. package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.d.ts +3 -3
  56. package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.js +4 -4
  57. package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.d.ts +3 -3
  58. package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.js +4 -4
  59. package/dist/databases/mongo-db/commands/mongo-update.command.d.ts +3 -3
  60. package/dist/databases/mongo-db/commands/mongo-update.command.js +3 -3
  61. package/dist/databases/mongo-db/migrations/mongo-initial-schema.d.ts +2 -2
  62. package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +108 -108
  63. package/dist/databases/mongo-db/models/no-sql-pipeline.d.ts +4 -4
  64. package/dist/databases/mongo-db/models/no-sql-pipeline.interface.d.ts +3 -3
  65. package/dist/databases/mongo-db/models/no-sql-pipeline.js +1 -1
  66. package/dist/databases/mongo-db/mongo-db.database.d.ts +7 -7
  67. package/dist/databases/mongo-db/mongo-db.database.js +5 -5
  68. package/dist/databases/mongo-db/queries/mongo-find-one.query.d.ts +2 -2
  69. package/dist/databases/mongo-db/queries/mongo-find-one.query.js +1 -1
  70. package/dist/databases/mongo-db/queries/mongo-find.query.d.ts +2 -2
  71. package/dist/databases/mongo-db/queries/mongo-find.query.js +1 -1
  72. package/dist/databases/mongo-db/queries/mongo-get-all.query.d.ts +2 -2
  73. package/dist/databases/mongo-db/queries/mongo-get-all.query.js +1 -1
  74. package/dist/databases/mongo-db/queries/mongo-get-by-id.query.d.ts +4 -4
  75. package/dist/databases/mongo-db/queries/mongo-get-by-id.query.js +3 -3
  76. package/dist/databases/mongo-db/queries/mongo-get-count.query.d.ts +1 -1
  77. package/dist/databases/mongo-db/queries/mongo-get.query.d.ts +3 -3
  78. package/dist/databases/mongo-db/queries/mongo-get.query.js +2 -2
  79. package/dist/databases/mongo-db/utils/build-find-options.util.d.ts +2 -2
  80. package/dist/databases/mongo-db/utils/build-mongo-url.util.d.ts +1 -1
  81. package/dist/databases/mongo-db/utils/build-mongo-url.util.js +4 -4
  82. package/dist/databases/operations/__tests__/models/test-agent.model.d.ts +2 -2
  83. package/dist/databases/operations/__tests__/models/test-agent.model.js +3 -3
  84. package/dist/databases/operations/__tests__/models/test-client-report.model.d.ts +4 -4
  85. package/dist/databases/operations/__tests__/models/test-client-report.model.js +5 -5
  86. package/dist/databases/operations/__tests__/models/test-district.model.d.ts +2 -2
  87. package/dist/databases/operations/__tests__/models/test-district.model.js +2 -2
  88. package/dist/databases/operations/__tests__/models/test-email-address.model.d.ts +1 -1
  89. package/dist/databases/operations/__tests__/models/test-email-address.model.js +2 -2
  90. package/dist/databases/operations/__tests__/models/test-person.model.d.ts +4 -4
  91. package/dist/databases/operations/__tests__/models/test-person.model.js +4 -4
  92. package/dist/databases/operations/__tests__/models/test-phone-number.model.d.ts +1 -1
  93. package/dist/databases/operations/__tests__/models/test-phone-number.model.js +2 -2
  94. package/dist/databases/operations/__tests__/models/test-policy.model.d.ts +3 -3
  95. package/dist/databases/operations/__tests__/models/test-policy.model.js +4 -4
  96. package/dist/databases/operations/__tests__/models/test-premium.model.d.ts +1 -1
  97. package/dist/databases/operations/__tests__/models/test-premium.model.js +2 -2
  98. package/dist/databases/operations/__tests__/models/test-school.model.d.ts +2 -2
  99. package/dist/databases/operations/__tests__/models/test-school.model.js +2 -2
  100. package/dist/databases/operations/__tests__/models/test-state.model.d.ts +1 -1
  101. package/dist/databases/operations/__tests__/models/test-state.model.js +2 -2
  102. package/dist/databases/operations/operation.d.ts +3 -3
  103. package/dist/databases/postgres/commands/postgres-batch-update.command.d.ts +1 -1
  104. package/dist/databases/postgres/commands/postgres-batch-update.command.js +11 -11
  105. package/dist/databases/postgres/commands/postgres-create-many.command.js +5 -5
  106. package/dist/databases/postgres/commands/postgres-create.command.d.ts +3 -3
  107. package/dist/databases/postgres/commands/postgres-create.command.js +5 -5
  108. package/dist/databases/postgres/commands/postgres-delete-by-id.command.d.ts +1 -1
  109. package/dist/databases/postgres/commands/postgres-delete-by-id.command.js +1 -1
  110. package/dist/databases/postgres/commands/postgres-delete-many.command.d.ts +2 -2
  111. package/dist/databases/postgres/commands/postgres-delete-many.command.js +1 -1
  112. package/dist/databases/postgres/commands/postgres-full-update-by-id.command.d.ts +1 -1
  113. package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +4 -4
  114. package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.d.ts +1 -1
  115. package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +11 -11
  116. package/dist/databases/postgres/commands/postgres-update.command.d.ts +2 -2
  117. package/dist/databases/postgres/commands/postgres-update.command.js +11 -11
  118. package/dist/databases/postgres/migrations/postgres-initial-schema.d.ts +2 -2
  119. package/dist/databases/postgres/migrations/postgres-initial-schema.js +69 -69
  120. package/dist/databases/postgres/postgres.database.d.ts +6 -6
  121. package/dist/databases/postgres/postgres.database.js +18 -18
  122. package/dist/databases/postgres/queries/postgres-find-one.query.d.ts +1 -1
  123. package/dist/databases/postgres/queries/postgres-find-one.query.js +2 -2
  124. package/dist/databases/postgres/queries/postgres-find.query.d.ts +1 -1
  125. package/dist/databases/postgres/queries/postgres-find.query.js +2 -2
  126. package/dist/databases/postgres/queries/postgres-get-all.query.d.ts +1 -1
  127. package/dist/databases/postgres/queries/postgres-get-all.query.js +3 -3
  128. package/dist/databases/postgres/queries/postgres-get-by-id.query.d.ts +1 -1
  129. package/dist/databases/postgres/queries/postgres-get-by-id.query.js +5 -5
  130. package/dist/databases/postgres/queries/postgres-get-count.query.js +1 -1
  131. package/dist/databases/postgres/queries/postgres-get.query.d.ts +2 -2
  132. package/dist/databases/postgres/queries/postgres-get.query.js +9 -9
  133. package/dist/databases/postgres/utils/build-count-query.d.ts +1 -1
  134. package/dist/databases/postgres/utils/build-count-query.js +1 -1
  135. package/dist/databases/postgres/utils/build-join-clauses.d.ts +1 -1
  136. package/dist/databases/postgres/utils/build-join-clauses.js +7 -7
  137. package/dist/databases/postgres/utils/build-order-by-clause.d.ts +1 -1
  138. package/dist/databases/postgres/utils/build-pagination-clause.d.ts +1 -1
  139. package/dist/databases/postgres/utils/build-postgres-url.util.d.ts +1 -1
  140. package/dist/databases/postgres/utils/build-postgres-url.util.js +2 -2
  141. package/dist/databases/postgres/utils/build-select-clause.js +9 -9
  142. package/dist/databases/postgres/utils/build-where-clause.d.ts +1 -1
  143. package/dist/databases/postgres/utils/build-where-clause.js +1 -1
  144. package/dist/databases/postgres/utils/columns-and-values-from-entity.d.ts +1 -1
  145. package/dist/databases/postgres/utils/does-table-exist.util.d.ts +1 -1
  146. package/dist/databases/postgres/utils/does-table-exist.util.js +5 -5
  147. package/dist/decorators/index.d.ts +1 -0
  148. package/dist/decorators/index.js +1 -0
  149. package/dist/middleware/authorize/authenticate-request.d.ts +2 -2
  150. package/dist/middleware/authorize/authenticate-request.js +5 -5
  151. package/dist/middleware/index.d.ts +4 -4
  152. package/dist/middleware/index.js +4 -4
  153. package/dist/models/app-config.interface.d.ts +1 -1
  154. package/dist/models/base-api-config.interface.d.ts +6 -6
  155. package/dist/models/initial-database-config.interface.d.ts +3 -3
  156. package/dist/models/log-level.type.d.ts +1 -1
  157. package/dist/services/authorizations.service.d.ts +3 -3
  158. package/dist/services/authorizations.service.js +7 -7
  159. package/dist/services/email.service.js +5 -5
  160. package/dist/services/features.service.d.ts +3 -3
  161. package/dist/services/features.service.js +4 -4
  162. package/dist/services/generic-api-service/generic-api-service.interface.d.ts +6 -6
  163. package/dist/services/generic-api-service/generic-api.service.d.ts +8 -8
  164. package/dist/services/generic-api-service/generic-api.service.js +7 -7
  165. package/dist/services/index.d.ts +16 -16
  166. package/dist/services/index.js +16 -16
  167. package/dist/services/multi-tenant-api.service.d.ts +4 -4
  168. package/dist/services/multi-tenant-api.service.js +9 -9
  169. package/dist/services/organization-domain.service.d.ts +3 -3
  170. package/dist/services/organization-domain.service.js +3 -3
  171. package/dist/services/organization.service.d.ts +4 -4
  172. package/dist/services/organization.service.js +7 -7
  173. package/dist/services/password-reset-token.service.d.ts +3 -3
  174. package/dist/services/password-reset-token.service.js +5 -5
  175. package/dist/services/refresh-token.service.d.ts +3 -3
  176. package/dist/services/refresh-token.service.js +3 -3
  177. package/dist/services/roles.service.d.ts +3 -3
  178. package/dist/services/roles.service.js +4 -4
  179. package/dist/services/tenant-query-decorator.d.ts +1 -1
  180. package/dist/services/tenant-query-decorator.js +8 -8
  181. package/dist/services/user-roles.service.d.ts +3 -3
  182. package/dist/services/user-roles.service.js +4 -4
  183. package/dist/services/user.service.d.ts +4 -4
  184. package/dist/services/user.service.js +11 -11
  185. package/dist/services/utils/audit-for-create.util.d.ts +1 -1
  186. package/dist/services/utils/audit-for-create.util.js +2 -2
  187. package/dist/services/utils/audit-for-update.util.d.ts +1 -1
  188. package/dist/services/utils/audit-for-update.util.js +2 -2
  189. package/dist/services/utils/strip-sender-provided-system-properties.util.d.ts +1 -1
  190. package/dist/services/utils/strip-sender-provided-system-properties.util.js +4 -4
  191. package/dist/utils/auth/assert-admin-or-feature.util.d.ts +1 -1
  192. package/dist/utils/auth/assert-admin-or-feature.util.js +2 -2
  193. package/dist/utils/auth/assert-admin.util.d.ts +1 -1
  194. package/dist/utils/auth/assert-admin.util.js +2 -2
  195. package/dist/utils/auth/assert-owner-or-admin.util.d.ts +1 -1
  196. package/dist/utils/auth/assert-owner-or-admin.util.js +2 -2
  197. package/dist/utils/auth/assert-user-has-feature.util.d.ts +1 -1
  198. package/dist/utils/auth/assert-user-has-feature.util.js +1 -1
  199. package/dist/utils/auth/assert-user-or-admin.util.d.ts +2 -2
  200. package/dist/utils/auth/assert-user-or-admin.util.js +2 -2
  201. package/dist/utils/auth/attempt-login.util.d.ts +4 -4
  202. package/dist/utils/auth/attempt-login.util.js +8 -8
  203. package/dist/utils/auth/auth-user-specs.util.d.ts +1 -1
  204. package/dist/utils/auth/auth-user-specs.util.js +3 -3
  205. package/dist/utils/auth/change-password.util.d.ts +4 -4
  206. package/dist/utils/auth/change-password.util.js +2 -2
  207. package/dist/utils/auth/create-new-refresh-token.util.d.ts +3 -3
  208. package/dist/utils/auth/create-new-refresh-token.util.js +8 -8
  209. package/dist/utils/auth/create-new-tokens.util.d.ts +1 -1
  210. package/dist/utils/auth/create-new-tokens.util.js +3 -3
  211. package/dist/utils/auth/generate-device-id.util.js +2 -2
  212. package/dist/utils/auth/generate-refresh-token.util.js +2 -2
  213. package/dist/utils/auth/get-active-refresh-token.util.d.ts +2 -2
  214. package/dist/utils/auth/get-active-refresh-token.util.js +1 -1
  215. package/dist/utils/auth/get-and-set-device-id-cookie.util.d.ts +1 -1
  216. package/dist/utils/auth/get-and-set-device-id-cookie.util.js +4 -4
  217. package/dist/utils/auth/get-auth-config.util.d.ts +1 -1
  218. package/dist/utils/auth/get-auth-config.util.js +3 -3
  219. package/dist/utils/auth/get-device-id-from-cookie.util.d.ts +1 -1
  220. package/dist/utils/auth/index.d.ts +26 -26
  221. package/dist/utils/auth/index.js +26 -26
  222. package/dist/utils/auth/is-admin.util.d.ts +1 -1
  223. package/dist/utils/auth/is-admin.util.js +1 -1
  224. package/dist/utils/auth/log-user-in.util.d.ts +3 -3
  225. package/dist/utils/auth/log-user-in.util.js +5 -5
  226. package/dist/utils/auth/request-token-using-refresh-token.util.d.ts +4 -4
  227. package/dist/utils/auth/request-token-using-refresh-token.util.js +7 -7
  228. package/dist/utils/auth/reset-password.util.d.ts +4 -4
  229. package/dist/utils/auth/reset-password.util.js +8 -8
  230. package/dist/utils/auth/send-reset-password-email.util.d.ts +2 -2
  231. package/dist/utils/auth/send-reset-password-email.util.js +5 -5
  232. package/dist/utils/auth/update-last-logged-in.util.d.ts +3 -3
  233. package/dist/utils/auth/update-last-logged-in.util.js +3 -3
  234. package/dist/utils/create-public-spec.utils.d.ts +1 -1
  235. package/dist/utils/create-public-spec.utils.js +2 -2
  236. package/dist/utils/express.utils.d.ts +4 -4
  237. package/dist/utils/express.utils.js +5 -5
  238. package/dist/utils/index.d.ts +10 -10
  239. package/dist/utils/index.js +10 -10
  240. package/dist/utils/jwt.utils.d.ts +1 -1
  241. package/dist/utils/jwt.utils.js +3 -3
  242. package/dist/utils/logger.utils.d.ts +1 -1
  243. package/dist/utils/logger.utils.js +10 -10
  244. package/dist/utils/password.utils.js +7 -7
  245. package/package.json +2 -1
@@ -1,3 +1,3 @@
1
- import { FindOptions } from "mongodb";
2
- import { IQueryOptions } from "@loomcore/common/models";
1
+ import { FindOptions } from 'mongodb';
2
+ import { IQueryOptions } from '@loomcore/common/models';
3
3
  export declare function buildFindOptions(queryOptions: IQueryOptions): FindOptions;
@@ -1,4 +1,4 @@
1
- import { IDatabaseConfig } from "../../../models/database-config.interface.js";
1
+ import { IDatabaseConfig } from '../../../models/database-config.interface.js';
2
2
  export declare function buildMongoUrl(config: {
3
3
  database: IDatabaseConfig;
4
4
  }): string;
@@ -1,14 +1,14 @@
1
1
  function isAtlasSrvHost(host) {
2
- return host.toLowerCase().endsWith(".mongodb.net");
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("Database configuration is required to build the MongoDB URL.");
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("Database configuration must include user, password, host, and name to build the MongoDB URL.");
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("Database configuration must include port to build a non-SRV MongoDB URL.");
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 "@loomcore/common/models";
2
- import { ITestPersonModel } from "./test-person.model.js";
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 "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
3
- import { testPersonSchema } from "./test-person.model.js";
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 "./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";
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 "./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";
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 "@loomcore/common/models";
2
- import { ITestStateModel } from "./test-state.model.js";
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 "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
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,4 +1,4 @@
1
- import { IAuditable, IEntity } from "@loomcore/common/models";
1
+ import { IAuditable, IEntity } from '@loomcore/common/models';
2
2
  export interface ITestEmailAddressModel extends IEntity, IAuditable {
3
3
  personId: number;
4
4
  emailAddress: string;
@@ -1,5 +1,5 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
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 "@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";
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 "@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";
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,4 +1,4 @@
1
- import { IAuditable, IEntity } from "@loomcore/common/models";
1
+ import { IAuditable, IEntity } from '@loomcore/common/models';
2
2
  export interface ITestPhoneNumberModel extends IEntity, IAuditable {
3
3
  phoneNumber: string;
4
4
  phoneNumberType: string;
@@ -1,5 +1,5 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
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 "@loomcore/common/models";
2
- import { ITestAgentModel } from "./test-agent.model.js";
3
- import { ITestPremiumModel } from "./test-premium.model.js";
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 "@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";
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,4 +1,4 @@
1
- import type { IAuditable, IEntity } from "@loomcore/common/models";
1
+ import type { IAuditable, IEntity } from '@loomcore/common/models';
2
2
  export interface ITestPremiumModel extends IEntity, IAuditable {
3
3
  policyId: number;
4
4
  amount: number;
@@ -1,5 +1,5 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
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 "@loomcore/common/models";
2
- import { ITestDistrictModel } from "./test-district.model.js";
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 "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
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,4 +1,4 @@
1
- import type { IAuditable, IEntity } from "@loomcore/common/models";
1
+ import type { IAuditable, IEntity } from '@loomcore/common/models';
2
2
  export interface ITestStateModel extends IEntity, IAuditable {
3
3
  name: string;
4
4
  }
@@ -1,5 +1,5 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
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 "./left-join.operation.js";
2
- import { InnerJoin } from "./inner-join.operation.js";
3
- import { LeftJoinMany } from "./left-join-many.operation.js";
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 "../../operations/operation.js";
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 "../../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";
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
- UPDATE "${pluralResourceName}"
45
- SET ${setClause}
46
- ${whereClause}
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
- SELECT ${selectClause} FROM "${pluralResourceName}" ${joinClauses}
61
- ${whereClause}
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 "../../../errors/index.js";
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
- INSERT INTO "${pluralResourceName}" (${columns.map(col => `"${col}"`).join(', ')})
38
- VALUES ${valueClauses.join(', ')}
39
- RETURNING *
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 "@loomcore/common/models";
2
- import type { AppIdType } from "@loomcore/common/types";
3
- import type { PostgresConnection } from "../postgres-connection.js";
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 "../../../errors/index.js";
2
- import { columnsAndValuesFromEntity } from "../utils/columns-and-values-from-entity.js";
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 === "23505") {
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 "../../models/delete-result.js";
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 "../../models/delete-result.js";
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 "@loomcore/common/models";
3
- import { DeleteResult } from "../../models/delete-result.js";
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 "../../models/delete-result.js";
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 "../../operations/operation.js";
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 "../../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";
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 "../../operations/operation.js";
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 "../../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";
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
- UPDATE "${pluralResourceName}"
19
- SET ${setClause}
20
- WHERE "_id" = $${updateValues.length + 1}
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
- SELECT ${selectClause} FROM "${pluralResourceName}" ${joinClauses}
36
- WHERE ${idColumn} = $1 LIMIT 1
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 "@loomcore/common/models";
3
- import { Operation } from "../../operations/operation.js";
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 "../../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";
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
- UPDATE "${pluralResourceName}"
26
- SET ${setClause}
27
- ${whereClauseWithAdjustedParams}
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
- SELECT ${selectClause} FROM "${pluralResourceName}" ${joinClauses}
46
- ${selectWhereClause} ${orderByClause}
47
- `.trim();
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 "pg";
2
- import type { IInitialDbMigrationConfig } from "../../../models/initial-database-config.interface.js";
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: {