@loomcore/api 0.1.60 → 0.1.63
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/README.md +49 -49
- package/dist/__tests__/common-test.utils.js +10 -8
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +52 -52
- package/dist/__tests__/postgres.test-database.js +8 -8
- package/dist/__tests__/test-email-client.d.ts +4 -0
- package/dist/__tests__/test-email-client.js +6 -0
- package/dist/controllers/auth.controller.d.ts +2 -1
- package/dist/controllers/auth.controller.js +2 -3
- package/dist/databases/migrations/migration-runner.d.ts +3 -1
- package/dist/databases/migrations/migration-runner.js +27 -25
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.d.ts +3 -2
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +119 -110
- package/dist/databases/postgres/commands/postgres-batch-update.command.js +7 -7
- package/dist/databases/postgres/commands/postgres-create-many.command.js +4 -4
- package/dist/databases/postgres/commands/postgres-create.command.js +4 -4
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +13 -13
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +7 -7
- package/dist/databases/postgres/commands/postgres-update.command.js +7 -7
- package/dist/databases/postgres/migrations/__tests__/test-migration-helper.js +2 -1
- package/dist/databases/postgres/migrations/postgres-initial-schema.d.ts +2 -1
- package/dist/databases/postgres/migrations/postgres-initial-schema.js +276 -266
- package/dist/databases/postgres/postgres.database.js +17 -17
- package/dist/databases/postgres/utils/build-select-clause.js +6 -6
- package/dist/databases/postgres/utils/does-table-exist.util.js +4 -4
- package/dist/models/base-api-config.interface.d.ts +7 -10
- package/dist/models/email-client.interface.d.ts +3 -0
- package/dist/models/email-client.interface.js +1 -0
- package/dist/models/email-config.interface.d.ts +4 -0
- package/dist/models/email-config.interface.js +1 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +1 -0
- package/dist/models/multi-tenant-config.interface.d.ts +4 -0
- package/dist/models/multi-tenant-config.interface.js +1 -0
- package/dist/services/auth.service.d.ts +2 -1
- package/dist/services/auth.service.js +2 -2
- package/dist/services/email.service.d.ts +5 -4
- package/dist/services/email.service.js +12 -20
- package/package.json +88 -88
|
@@ -5,10 +5,10 @@ export async function create(client, pluralResourceName, entity) {
|
|
|
5
5
|
delete entity._id;
|
|
6
6
|
const { columns, values } = columnsAndValuesFromEntity(entity);
|
|
7
7
|
const placeholders = columns.map((_, index) => `$${index + 1}`).join(', ');
|
|
8
|
-
const query = `
|
|
9
|
-
INSERT INTO "${pluralResourceName}" (${columns.join(', ')})
|
|
10
|
-
VALUES (${placeholders})
|
|
11
|
-
RETURNING *
|
|
8
|
+
const query = `
|
|
9
|
+
INSERT INTO "${pluralResourceName}" (${columns.join(', ')})
|
|
10
|
+
VALUES (${placeholders})
|
|
11
|
+
RETURNING *
|
|
12
12
|
`;
|
|
13
13
|
const result = await client.query(query, values);
|
|
14
14
|
if (result.rows.length === 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;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
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
|
+
import { TestEmailClient } from '../../../../__tests__/test-email-client.js';
|
|
4
5
|
export async function runInitialSchemaMigrations(pool, config) {
|
|
5
|
-
const initialSchema = getPostgresInitialSchema(config);
|
|
6
|
+
const initialSchema = getPostgresInitialSchema(config, new TestEmailClient());
|
|
6
7
|
const umzug = new Umzug({
|
|
7
8
|
migrations: async () => {
|
|
8
9
|
return initialSchema.map(m => ({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Pool } from 'pg';
|
|
2
2
|
import { IBaseApiConfig } from '../../../models/base-api-config.interface.js';
|
|
3
|
+
import { IEmailClient } from '../../../models/email-client.interface.js';
|
|
3
4
|
export interface SyntheticMigration {
|
|
4
5
|
name: string;
|
|
5
6
|
up: (context: {
|
|
@@ -9,4 +10,4 @@ export interface SyntheticMigration {
|
|
|
9
10
|
context: Pool;
|
|
10
11
|
}) => Promise<void>;
|
|
11
12
|
}
|
|
12
|
-
export declare const getPostgresInitialSchema: (config: IBaseApiConfig) => SyntheticMigration[];
|
|
13
|
+
export declare const getPostgresInitialSchema: (config: IBaseApiConfig, emailClient?: IEmailClient) => SyntheticMigration[];
|