@loomcore/api 0.1.106 → 0.1.110
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 +77 -77
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +266 -266
- package/dist/__tests__/postgres.test-database.js +8 -8
- package/dist/controllers/organizations.controller.d.ts +6 -2
- package/dist/controllers/organizations.controller.js +2 -2
- package/dist/databases/migrations/migration-runner.js +21 -21
- 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/postgres-initial-schema.js +224 -224
- package/dist/databases/postgres/postgres.database.js +17 -17
- package/dist/databases/postgres/utils/build-select-clause.js +26 -9
- package/dist/databases/postgres/utils/does-table-exist.util.js +4 -4
- package/package.json +92 -92
|
@@ -25,12 +25,12 @@ function resolveLocalRef(localField, mainTableName, operations, currentIndex) {
|
|
|
25
25
|
return `${alias}."${snake}"`;
|
|
26
26
|
}
|
|
27
27
|
async function getTableColumns(client, tableName) {
|
|
28
|
-
const result = await client.query(`
|
|
29
|
-
SELECT column_name
|
|
30
|
-
FROM information_schema.columns
|
|
31
|
-
WHERE table_schema = current_schema()
|
|
32
|
-
AND table_name = $1
|
|
33
|
-
ORDER BY ordinal_position
|
|
28
|
+
const result = await client.query(`
|
|
29
|
+
SELECT column_name
|
|
30
|
+
FROM information_schema.columns
|
|
31
|
+
WHERE table_schema = current_schema()
|
|
32
|
+
AND table_name = $1
|
|
33
|
+
ORDER BY ordinal_position
|
|
34
34
|
`, [tableName]);
|
|
35
35
|
return result.rows.map(row => row.column_name);
|
|
36
36
|
}
|
|
@@ -74,9 +74,26 @@ export async function buildSelectClause(client, mainTableName, mainTableAlias, o
|
|
|
74
74
|
if (referencedLeftJoinMany) {
|
|
75
75
|
const [prevAlias, fieldName] = joinMany.localField.split('.');
|
|
76
76
|
const prevFieldSnake = convertFieldToSnakeCase(fieldName);
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
const buildNestedInQuery = (refOp, extractField) => {
|
|
78
|
+
const extractFieldSnake = convertFieldToSnakeCase(extractField);
|
|
79
|
+
const refForeignSnake = convertFieldToSnakeCase(refOp.foreignField);
|
|
80
|
+
if (!refOp.localField.includes('.')) {
|
|
81
|
+
const refLocalSnake = convertFieldToSnakeCase(refOp.localField);
|
|
82
|
+
return `(SELECT "${extractFieldSnake}" FROM "${refOp.from}" WHERE "${refOp.from}"."${refForeignSnake}" = "${mainTableName}"."${refLocalSnake}")`;
|
|
83
|
+
}
|
|
84
|
+
const [parentAlias, parentField] = refOp.localField.split('.');
|
|
85
|
+
const parentOpIndex = operations.indexOf(refOp);
|
|
86
|
+
const parentOp = operations.slice(0, parentOpIndex).find((op) => op instanceof LeftJoinMany && op.as === parentAlias);
|
|
87
|
+
if (parentOp) {
|
|
88
|
+
const parentFieldSnake = convertFieldToSnakeCase(parentField);
|
|
89
|
+
const nestedQuery = buildNestedInQuery(parentOp, parentFieldSnake);
|
|
90
|
+
return `(SELECT "${extractFieldSnake}" FROM "${refOp.from}" WHERE "${refOp.from}"."${refForeignSnake}" IN ${nestedQuery})`;
|
|
91
|
+
}
|
|
92
|
+
const parentFieldSnake = convertFieldToSnakeCase(parentField);
|
|
93
|
+
return `(SELECT "${extractFieldSnake}" FROM "${refOp.from}" WHERE "${refOp.from}"."${refForeignSnake}" = ${parentAlias}."${parentFieldSnake}")`;
|
|
94
|
+
};
|
|
95
|
+
const nestedQuery = buildNestedInQuery(referencedLeftJoinMany, prevFieldSnake);
|
|
96
|
+
whereClause = `${subAlias}."${foreignSnake}" IN ${nestedQuery}`;
|
|
80
97
|
}
|
|
81
98
|
else {
|
|
82
99
|
whereClause = `${subAlias}."${foreignSnake}" = ${localRef}`;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export async function doesTableExist(client, tableName) {
|
|
2
|
-
const result = await client.query(`
|
|
3
|
-
SELECT EXISTS (
|
|
4
|
-
SELECT 1 FROM information_schema.tables WHERE table_schema = current_schema() AND table_name = $1
|
|
5
|
-
)
|
|
2
|
+
const result = await client.query(`
|
|
3
|
+
SELECT EXISTS (
|
|
4
|
+
SELECT 1 FROM information_schema.tables WHERE table_schema = current_schema() AND table_name = $1
|
|
5
|
+
)
|
|
6
6
|
`, [tableName]);
|
|
7
7
|
return result.rows[0].exists;
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@loomcore/api",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"private": false,
|
|
5
|
-
"description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"clean": "rm -rf dist",
|
|
8
|
-
"tsc": "tsc --project tsconfig.prod.json",
|
|
9
|
-
"build": "npm-run-all -s clean tsc",
|
|
10
|
-
"add": "git add .",
|
|
11
|
-
"commit": "git commit -m \"Updates\"",
|
|
12
|
-
"patch": "npm version patch",
|
|
13
|
-
"push": "git push",
|
|
14
|
-
"publishMe": "npm publish --access public",
|
|
15
|
-
"pub": "npm-run-all -s add commit patch build push publishMe",
|
|
16
|
-
"update-lib-versions": "npx --yes npm-check-updates -u -f @loomcore/common",
|
|
17
|
-
"install-updated-libs": "npm i @loomcore/common",
|
|
18
|
-
"update-libs": "npm-run-all -s update-lib-versions install-updated-libs",
|
|
19
|
-
"typecheck": "tsc",
|
|
20
|
-
"test": "npm-run-all -s test:postgres test:mongodb",
|
|
21
|
-
"test:postgres": "cross-env NODE_ENV=test TEST_DATABASE=postgres vitest run",
|
|
22
|
-
"test:postgres:real": "cross-env NODE_ENV=test TEST_DATABASE=postgres USE_REAL_POSTGRES=true vitest run",
|
|
23
|
-
"test:mongodb": "cross-env NODE_ENV=test TEST_DATABASE=mongodb vitest run",
|
|
24
|
-
"test:ci": "npm-run-all -s test:ci:postgres test:ci:mongodb",
|
|
25
|
-
"test:ci:postgres": "cross-env NODE_ENV=test TEST_DATABASE=postgres vitest run --reporter=json --outputFile=test-results-postgres.json",
|
|
26
|
-
"test:ci:mongodb": "cross-env NODE_ENV=test TEST_DATABASE=mongodb vitest run --reporter=json --outputFile=test-results-mongodb.json",
|
|
27
|
-
"test:watch": "cross-env NODE_ENV=test vitest",
|
|
28
|
-
"coverage": "npm-run-all -s coverage:postgres coverage:mongodb",
|
|
29
|
-
"coverage:postgres": "cross-env NODE_ENV=test TEST_DATABASE=postgres vitest run --coverage",
|
|
30
|
-
"coverage:mongodb": "cross-env NODE_ENV=test TEST_DATABASE=mongodb vitest run --coverage",
|
|
31
|
-
"test:db:start": "docker-compose -f docker-compose.test.yml up -d",
|
|
32
|
-
"test:db:stop": "docker-compose -f docker-compose.test.yml down",
|
|
33
|
-
"test:db:logs": "docker-compose -f docker-compose.test.yml logs -f"
|
|
34
|
-
},
|
|
35
|
-
"author": "Tim Hardy",
|
|
36
|
-
"license": "Apache 2.0",
|
|
37
|
-
"main": "dist/index.js",
|
|
38
|
-
"type": "module",
|
|
39
|
-
"types": "dist/index.d.ts",
|
|
40
|
-
"files": [
|
|
41
|
-
"dist/**/*"
|
|
42
|
-
],
|
|
43
|
-
"exports": {
|
|
44
|
-
"./__tests__": "./dist/__tests__/index.js",
|
|
45
|
-
"./config": "./dist/config/index.js",
|
|
46
|
-
"./controllers": "./dist/controllers/index.js",
|
|
47
|
-
"./databases": "./dist/databases/index.js",
|
|
48
|
-
"./errors": "./dist/errors/index.js",
|
|
49
|
-
"./middleware": "./dist/middleware/index.js",
|
|
50
|
-
"./models": "./dist/models/index.js",
|
|
51
|
-
"./services": "./dist/services/index.js",
|
|
52
|
-
"./utils": "./dist/utils/index.js"
|
|
53
|
-
},
|
|
54
|
-
"dependencies": {
|
|
55
|
-
"jsonwebtoken": "^9.0.2",
|
|
56
|
-
"node-mailjet": "^6.0.8",
|
|
57
|
-
"qs": "^6.15.0"
|
|
58
|
-
},
|
|
59
|
-
"peerDependencies": {
|
|
60
|
-
"@loomcore/common": "^0.0.51",
|
|
61
|
-
"@sinclair/typebox": "0.34.33",
|
|
62
|
-
"cookie-parser": "^1.4.6",
|
|
63
|
-
"cors": "^2.8.5",
|
|
64
|
-
"express": "^5.1.0",
|
|
65
|
-
"lodash": "^4.17.21",
|
|
66
|
-
"moment": "^2.30.1",
|
|
67
|
-
"mongodb": "^6.16.0",
|
|
68
|
-
"pg": "^8.15.6",
|
|
69
|
-
"rxjs": "^7.8.0",
|
|
70
|
-
"umzug": "^3.8.2"
|
|
71
|
-
},
|
|
72
|
-
"devDependencies": {
|
|
73
|
-
"@types/cookie-parser": "^1.4.7",
|
|
74
|
-
"@types/cors": "^2.8.18",
|
|
75
|
-
"@types/express": "^5.0.1",
|
|
76
|
-
"@types/jsonwebtoken": "^9.0.9",
|
|
77
|
-
"@types/lodash": "^4.17.13",
|
|
78
|
-
"@types/pg": "^8.15.6",
|
|
79
|
-
"@types/qs": "^6.14.0",
|
|
80
|
-
"@types/supertest": "^6.0.3",
|
|
81
|
-
"@vitest/coverage-v8": "^3.0.9",
|
|
82
|
-
"cross-env": "^7.0.3",
|
|
83
|
-
"mongodb-memory-server": "^9.3.0",
|
|
84
|
-
"npm-run-all": "^4.1.5",
|
|
85
|
-
"pg-mem": "^3.0.12",
|
|
86
|
-
"rxjs": "^7.8.0",
|
|
87
|
-
"supertest": "^7.1.0",
|
|
88
|
-
"typescript": "^5.8.3",
|
|
89
|
-
"vite": "^6.2.5",
|
|
90
|
-
"vitest": "^3.0.9"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@loomcore/api",
|
|
3
|
+
"version": "0.1.110",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "rm -rf dist",
|
|
8
|
+
"tsc": "tsc --project tsconfig.prod.json",
|
|
9
|
+
"build": "npm-run-all -s clean tsc",
|
|
10
|
+
"add": "git add .",
|
|
11
|
+
"commit": "git commit -m \"Updates\"",
|
|
12
|
+
"patch": "npm version patch",
|
|
13
|
+
"push": "git push",
|
|
14
|
+
"publishMe": "npm publish --access public",
|
|
15
|
+
"pub": "npm-run-all -s add commit patch build push publishMe",
|
|
16
|
+
"update-lib-versions": "npx --yes npm-check-updates -u -f @loomcore/common",
|
|
17
|
+
"install-updated-libs": "npm i @loomcore/common",
|
|
18
|
+
"update-libs": "npm-run-all -s update-lib-versions install-updated-libs",
|
|
19
|
+
"typecheck": "tsc",
|
|
20
|
+
"test": "npm-run-all -s test:postgres test:mongodb",
|
|
21
|
+
"test:postgres": "cross-env NODE_ENV=test TEST_DATABASE=postgres vitest run",
|
|
22
|
+
"test:postgres:real": "cross-env NODE_ENV=test TEST_DATABASE=postgres USE_REAL_POSTGRES=true vitest run",
|
|
23
|
+
"test:mongodb": "cross-env NODE_ENV=test TEST_DATABASE=mongodb vitest run",
|
|
24
|
+
"test:ci": "npm-run-all -s test:ci:postgres test:ci:mongodb",
|
|
25
|
+
"test:ci:postgres": "cross-env NODE_ENV=test TEST_DATABASE=postgres vitest run --reporter=json --outputFile=test-results-postgres.json",
|
|
26
|
+
"test:ci:mongodb": "cross-env NODE_ENV=test TEST_DATABASE=mongodb vitest run --reporter=json --outputFile=test-results-mongodb.json",
|
|
27
|
+
"test:watch": "cross-env NODE_ENV=test vitest",
|
|
28
|
+
"coverage": "npm-run-all -s coverage:postgres coverage:mongodb",
|
|
29
|
+
"coverage:postgres": "cross-env NODE_ENV=test TEST_DATABASE=postgres vitest run --coverage",
|
|
30
|
+
"coverage:mongodb": "cross-env NODE_ENV=test TEST_DATABASE=mongodb vitest run --coverage",
|
|
31
|
+
"test:db:start": "docker-compose -f docker-compose.test.yml up -d",
|
|
32
|
+
"test:db:stop": "docker-compose -f docker-compose.test.yml down",
|
|
33
|
+
"test:db:logs": "docker-compose -f docker-compose.test.yml logs -f"
|
|
34
|
+
},
|
|
35
|
+
"author": "Tim Hardy",
|
|
36
|
+
"license": "Apache 2.0",
|
|
37
|
+
"main": "dist/index.js",
|
|
38
|
+
"type": "module",
|
|
39
|
+
"types": "dist/index.d.ts",
|
|
40
|
+
"files": [
|
|
41
|
+
"dist/**/*"
|
|
42
|
+
],
|
|
43
|
+
"exports": {
|
|
44
|
+
"./__tests__": "./dist/__tests__/index.js",
|
|
45
|
+
"./config": "./dist/config/index.js",
|
|
46
|
+
"./controllers": "./dist/controllers/index.js",
|
|
47
|
+
"./databases": "./dist/databases/index.js",
|
|
48
|
+
"./errors": "./dist/errors/index.js",
|
|
49
|
+
"./middleware": "./dist/middleware/index.js",
|
|
50
|
+
"./models": "./dist/models/index.js",
|
|
51
|
+
"./services": "./dist/services/index.js",
|
|
52
|
+
"./utils": "./dist/utils/index.js"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"jsonwebtoken": "^9.0.2",
|
|
56
|
+
"node-mailjet": "^6.0.8",
|
|
57
|
+
"qs": "^6.15.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@loomcore/common": "^0.0.51",
|
|
61
|
+
"@sinclair/typebox": "0.34.33",
|
|
62
|
+
"cookie-parser": "^1.4.6",
|
|
63
|
+
"cors": "^2.8.5",
|
|
64
|
+
"express": "^5.1.0",
|
|
65
|
+
"lodash": "^4.17.21",
|
|
66
|
+
"moment": "^2.30.1",
|
|
67
|
+
"mongodb": "^6.16.0",
|
|
68
|
+
"pg": "^8.15.6",
|
|
69
|
+
"rxjs": "^7.8.0",
|
|
70
|
+
"umzug": "^3.8.2"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@types/cookie-parser": "^1.4.7",
|
|
74
|
+
"@types/cors": "^2.8.18",
|
|
75
|
+
"@types/express": "^5.0.1",
|
|
76
|
+
"@types/jsonwebtoken": "^9.0.9",
|
|
77
|
+
"@types/lodash": "^4.17.13",
|
|
78
|
+
"@types/pg": "^8.15.6",
|
|
79
|
+
"@types/qs": "^6.14.0",
|
|
80
|
+
"@types/supertest": "^6.0.3",
|
|
81
|
+
"@vitest/coverage-v8": "^3.0.9",
|
|
82
|
+
"cross-env": "^7.0.3",
|
|
83
|
+
"mongodb-memory-server": "^9.3.0",
|
|
84
|
+
"npm-run-all": "^4.1.5",
|
|
85
|
+
"pg-mem": "^3.0.12",
|
|
86
|
+
"rxjs": "^7.8.0",
|
|
87
|
+
"supertest": "^7.1.0",
|
|
88
|
+
"typescript": "^5.8.3",
|
|
89
|
+
"vite": "^6.2.5",
|
|
90
|
+
"vitest": "^3.0.9"
|
|
91
|
+
}
|
|
92
|
+
}
|