@loomcore/api 0.1.92 → 0.1.94

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 (38) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +77 -77
  3. package/dist/__tests__/common-test.utils.js +0 -4
  4. package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +266 -266
  5. package/dist/__tests__/postgres.test-database.js +8 -8
  6. package/dist/config/base-api-config.d.ts +1 -1
  7. package/dist/config/base-api-config.js +12 -7
  8. package/dist/databases/migrations/migration-runner.d.ts +3 -5
  9. package/dist/databases/migrations/migration-runner.js +40 -44
  10. package/dist/databases/mongo-db/migrations/mongo-initial-schema.d.ts +2 -3
  11. package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +102 -81
  12. package/dist/databases/mongo-db/utils/build-mongo-url.util.d.ts +4 -2
  13. package/dist/databases/postgres/commands/postgres-batch-update.command.js +7 -7
  14. package/dist/databases/postgres/commands/postgres-create-many.command.js +4 -4
  15. package/dist/databases/postgres/commands/postgres-create.command.js +4 -4
  16. package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +13 -13
  17. package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +7 -7
  18. package/dist/databases/postgres/commands/postgres-update.command.js +7 -7
  19. package/dist/databases/postgres/migrations/__tests__/test-migration-helper.js +8 -1
  20. package/dist/databases/postgres/migrations/postgres-initial-schema.d.ts +2 -3
  21. package/dist/databases/postgres/migrations/postgres-initial-schema.js +263 -266
  22. package/dist/databases/postgres/postgres.database.js +17 -17
  23. package/dist/databases/postgres/utils/build-join-clauses.js +151 -151
  24. package/dist/databases/postgres/utils/build-postgres-url.util.d.ts +4 -2
  25. package/dist/databases/postgres/utils/build-select-clause.js +6 -6
  26. package/dist/databases/postgres/utils/does-table-exist.util.js +4 -4
  27. package/dist/models/app-config.interface.d.ts +8 -0
  28. package/dist/models/base-api-config.interface.d.ts +4 -17
  29. package/dist/models/database-config.interface.d.ts +7 -0
  30. package/dist/models/index.d.ts +3 -1
  31. package/dist/models/index.js +3 -1
  32. package/dist/models/initial-database-config.interface.d.ts +16 -0
  33. package/dist/models/initial-database-config.interface.js +1 -0
  34. package/package.json +92 -92
  35. package/dist/models/multi-tenant-config.interface.d.ts +0 -4
  36. package/dist/models/reset-api-config.interface.d.ts +0 -6
  37. /package/dist/models/{multi-tenant-config.interface.js → app-config.interface.js} +0 -0
  38. /package/dist/models/{reset-api-config.interface.js → database-config.interface.js} +0 -0
@@ -2,12 +2,12 @@ import { BadRequestError, IdNotFoundError } from "../../../errors/index.js";
2
2
  import { buildJoinClauses } from '../utils/build-join-clauses.js';
3
3
  export async function fullUpdateById(client, operations, id, entity, pluralResourceName) {
4
4
  try {
5
- const tableColumns = await client.query(`
6
- SELECT column_name, column_default
7
- FROM information_schema.columns
8
- WHERE table_schema = current_schema()
9
- AND table_name = $1
10
- ORDER BY ordinal_position
5
+ const tableColumns = await client.query(`
6
+ SELECT column_name, column_default
7
+ FROM information_schema.columns
8
+ WHERE table_schema = current_schema()
9
+ AND table_name = $1
10
+ ORDER BY ordinal_position
11
11
  `, [pluralResourceName]);
12
12
  if (tableColumns.rows.length === 0) {
13
13
  throw new BadRequestError(`Unable to resolve columns for ${pluralResourceName}`);
@@ -40,19 +40,19 @@ export async function fullUpdateById(client, operations, id, entity, pluralResou
40
40
  throw new BadRequestError('Cannot perform full update with no fields to update');
41
41
  }
42
42
  const setClause = updateColumns.join(', ');
43
- const query = `
44
- UPDATE "${pluralResourceName}"
45
- SET ${setClause}
46
- WHERE "_id" = $${paramIndex}
43
+ const query = `
44
+ UPDATE "${pluralResourceName}"
45
+ SET ${setClause}
46
+ WHERE "_id" = $${paramIndex}
47
47
  `;
48
48
  const result = await client.query(query, [...updateValues, id]);
49
49
  if (result.rowCount === 0) {
50
50
  throw new IdNotFoundError();
51
51
  }
52
52
  const joinClauses = buildJoinClauses(operations);
53
- const selectQuery = `
54
- SELECT * FROM "${pluralResourceName}" ${joinClauses}
55
- WHERE "_id" = $1 LIMIT 1
53
+ const selectQuery = `
54
+ SELECT * FROM "${pluralResourceName}" ${joinClauses}
55
+ WHERE "_id" = $1 LIMIT 1
56
56
  `;
57
57
  const selectResult = await client.query(selectQuery, [id]);
58
58
  if (selectResult.rows.length === 0) {
@@ -10,19 +10,19 @@ export async function partialUpdateById(client, operations, id, entity, pluralRe
10
10
  throw new BadRequestError('Cannot perform partial update with no fields to update');
11
11
  }
12
12
  const setClause = updateColumns.map((col, index) => `${col} = $${index + 1}`).join(', ');
13
- const query = `
14
- UPDATE "${pluralResourceName}"
15
- SET ${setClause}
16
- WHERE "_id" = $${updateValues.length + 1}
13
+ const query = `
14
+ UPDATE "${pluralResourceName}"
15
+ SET ${setClause}
16
+ WHERE "_id" = $${updateValues.length + 1}
17
17
  `;
18
18
  const result = await client.query(query, [...updateValues, id]);
19
19
  if (result.rowCount === 0) {
20
20
  throw new IdNotFoundError();
21
21
  }
22
22
  const joinClauses = buildJoinClauses(operations);
23
- const selectQuery = `
24
- SELECT * FROM "${pluralResourceName}" ${joinClauses}
25
- WHERE "_id" = $1 LIMIT 1
23
+ const selectQuery = `
24
+ SELECT * FROM "${pluralResourceName}" ${joinClauses}
25
+ WHERE "_id" = $1 LIMIT 1
26
26
  `;
27
27
  const selectResult = await client.query(selectQuery, [id]);
28
28
  if (selectResult.rows.length === 0) {
@@ -17,10 +17,10 @@ export async function update(client, queryObject, entity, operations, pluralReso
17
17
  const originalIndex = parseInt(num, 10);
18
18
  return `$${originalIndex + updateValues.length}`;
19
19
  });
20
- const updateQuery = `
21
- UPDATE "${pluralResourceName}"
22
- SET ${setClause}
23
- ${whereClauseWithAdjustedParams}
20
+ const updateQuery = `
21
+ UPDATE "${pluralResourceName}"
22
+ SET ${setClause}
23
+ ${whereClauseWithAdjustedParams}
24
24
  `;
25
25
  const allUpdateValues = [...updateValues, ...whereValues];
26
26
  const result = await client.query(updateQuery, allUpdateValues);
@@ -29,9 +29,9 @@ export async function update(client, queryObject, entity, operations, pluralReso
29
29
  }
30
30
  const joinClauses = buildJoinClauses(operations);
31
31
  const orderByClause = buildOrderByClause(queryObject);
32
- const selectQuery = `
33
- SELECT * FROM "${pluralResourceName}" ${joinClauses}
34
- ${whereClause} ${orderByClause}
32
+ const selectQuery = `
33
+ SELECT * FROM "${pluralResourceName}" ${joinClauses}
34
+ ${whereClause} ${orderByClause}
35
35
  `.trim();
36
36
  const selectResult = await client.query(selectQuery, whereValues);
37
37
  return selectResult.rows;
@@ -2,7 +2,14 @@ import { Umzug } from 'umzug';
2
2
  import { getPostgresInitialSchema } from '../postgres-initial-schema.js';
3
3
  import { getPostgresTestSchema } from '../../../../__tests__/postgres-test-migrations/postgres-test-schema.js';
4
4
  export async function runInitialSchemaMigrations(pool, config) {
5
- const initialSchema = getPostgresInitialSchema(config, { adminUser: { email: 'admin@test.com', password: 'admin-password' } });
5
+ const migrationConfig = {
6
+ app: config.app,
7
+ database: config.database,
8
+ adminUser: config.adminUser ?? { email: 'admin@test.com', password: 'admin-password' },
9
+ multiTenant: config.multiTenant ?? (config.app.isMultiTenant ? { metaOrgName: 'Test Meta Organization', metaOrgCode: 'TEST_META_ORG' } : { metaOrgName: '', metaOrgCode: '' }),
10
+ email: config.email,
11
+ };
12
+ const initialSchema = getPostgresInitialSchema(migrationConfig);
6
13
  const umzug = new Umzug({
7
14
  migrations: async () => {
8
15
  return initialSchema.map(m => ({
@@ -1,6 +1,5 @@
1
1
  import { Pool } from 'pg';
2
- import { IBaseApiConfig } from '../../../models/base-api-config.interface.js';
3
- import { IResetApiConfig } from '../../../models/reset-api-config.interface.js';
2
+ import { IInitialDbMigrationConfig } from '../../../models/initial-database-config.interface.js';
4
3
  export interface SyntheticMigration {
5
4
  name: string;
6
5
  up: (context: {
@@ -10,4 +9,4 @@ export interface SyntheticMigration {
10
9
  context: Pool;
11
10
  }) => Promise<void>;
12
11
  }
13
- export declare const getPostgresInitialSchema: (config: IBaseApiConfig, resetConfig?: IResetApiConfig) => SyntheticMigration[];
12
+ export declare const getPostgresInitialSchema: (dbConfig: IInitialDbMigrationConfig) => SyntheticMigration[];