@shipfox/api-projects 9.2.0 → 10.0.0
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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +35 -0
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/projects.d.ts +6 -0
- package/dist/db/projects.d.ts.map +1 -1
- package/dist/db/projects.js +15 -1
- package/dist/db/projects.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/presentation/inter-module.d.ts.map +1 -1
- package/dist/presentation/inter-module.js +7 -2
- package/dist/presentation/inter-module.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/db/index.ts +1 -0
- package/src/db/projects.test.ts +9 -1
- package/src/db/projects.ts +17 -1
- package/src/index.ts +1 -0
- package/src/presentation/inter-module.ts +4 -1
- package/tsconfig.build.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipfox/api-projects",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "10.0.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/ShipfoxHQ/shipfox.git",
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
"@temporalio/workflow": "1.18.1",
|
|
22
22
|
"drizzle-orm": "^0.45.2",
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@shipfox/api-auth-context": "9.2.0",
|
|
25
24
|
"@shipfox/api-integration-core-dto": "9.0.2",
|
|
26
|
-
"@shipfox/api-
|
|
25
|
+
"@shipfox/api-auth-context": "10.0.0",
|
|
26
|
+
"@shipfox/api-projects-dto": "10.0.0",
|
|
27
27
|
"@shipfox/inter-module": "0.2.2",
|
|
28
28
|
"@shipfox/node-drizzle": "0.3.4",
|
|
29
|
-
"@shipfox/node-fastify": "0.
|
|
30
|
-
"@shipfox/node-module": "1.0.
|
|
31
|
-
"@shipfox/node-opentelemetry": "0.6.
|
|
29
|
+
"@shipfox/node-fastify": "0.4.0",
|
|
30
|
+
"@shipfox/node-module": "1.0.4",
|
|
31
|
+
"@shipfox/node-opentelemetry": "0.6.3",
|
|
32
32
|
"@shipfox/node-outbox": "0.2.6",
|
|
33
33
|
"@shipfox/node-postgres": "0.4.4",
|
|
34
|
-
"@shipfox/node-temporal": "0.4.
|
|
34
|
+
"@shipfox/node-temporal": "0.4.4"
|
|
35
35
|
},
|
|
36
36
|
"imports": {
|
|
37
37
|
"#*": "./dist/*"
|
package/src/db/index.ts
CHANGED
package/src/db/projects.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {projectFactory} from '#test/index.js';
|
|
2
|
-
import {getProjectCount} from './projects.js';
|
|
2
|
+
import {getProjectCount, getWorkspaceProjectCounts} from './projects.js';
|
|
3
3
|
|
|
4
4
|
describe('getProjectCount', () => {
|
|
5
5
|
it('reports the current project count', async () => {
|
|
@@ -19,4 +19,12 @@ describe('getProjectCount', () => {
|
|
|
19
19
|
|
|
20
20
|
expect(after - before).toBe(2);
|
|
21
21
|
});
|
|
22
|
+
|
|
23
|
+
it('returns zero for workspaces without projects', async () => {
|
|
24
|
+
const workspaceId = crypto.randomUUID();
|
|
25
|
+
|
|
26
|
+
const counts = await getWorkspaceProjectCounts({workspaceIds: [workspaceId]});
|
|
27
|
+
|
|
28
|
+
expect(counts).toEqual([{workspaceId, count: 0}]);
|
|
29
|
+
});
|
|
22
30
|
});
|
package/src/db/projects.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {and, count, desc, eq, ilike, lt, or, type SQL} from 'drizzle-orm';
|
|
1
|
+
import {and, count, desc, eq, ilike, inArray, lt, or, type SQL} from 'drizzle-orm';
|
|
2
2
|
import type {Project} from '#core/entities/project.js';
|
|
3
3
|
import {ProjectAlreadyExistsError, ProjectNotFoundError} from '#core/errors.js';
|
|
4
4
|
import {recordProjectCreated} from '#metrics/instance.js';
|
|
@@ -156,3 +156,19 @@ export async function getProjectCount(): Promise<number> {
|
|
|
156
156
|
const [row] = await db().select({value: count()}).from(projects);
|
|
157
157
|
return row?.value ?? 0;
|
|
158
158
|
}
|
|
159
|
+
|
|
160
|
+
export async function getWorkspaceProjectCounts(params: {
|
|
161
|
+
workspaceIds: string[];
|
|
162
|
+
}): Promise<Array<{workspaceId: string; count: number}>> {
|
|
163
|
+
const rows = await db()
|
|
164
|
+
.select({workspaceId: projects.workspaceId, count: count()})
|
|
165
|
+
.from(projects)
|
|
166
|
+
.where(inArray(projects.workspaceId, params.workspaceIds))
|
|
167
|
+
.groupBy(projects.workspaceId);
|
|
168
|
+
|
|
169
|
+
const countsByWorkspace = new Map(rows.map((row) => [row.workspaceId, Number(row.count)]));
|
|
170
|
+
return params.workspaceIds.map((workspaceId) => ({
|
|
171
|
+
workspaceId,
|
|
172
|
+
count: countsByWorkspace.get(workspaceId) ?? 0,
|
|
173
|
+
}));
|
|
174
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
defineInterModulePresentation,
|
|
5
5
|
type InterModulePresentation,
|
|
6
6
|
} from '@shipfox/inter-module';
|
|
7
|
-
import {getProjectById} from '#db/projects.js';
|
|
7
|
+
import {getProjectById, getWorkspaceProjectCounts} from '#db/projects.js';
|
|
8
8
|
|
|
9
9
|
export function createProjectsInterModulePresentation(): InterModulePresentation<
|
|
10
10
|
typeof projectsInterModuleContract
|
|
@@ -29,5 +29,8 @@ export function createProjectsInterModulePresentation(): InterModulePresentation
|
|
|
29
29
|
}
|
|
30
30
|
return {project};
|
|
31
31
|
},
|
|
32
|
+
getWorkspaceProjectCounts: async ({workspaceIds}) => ({
|
|
33
|
+
counts: await getWorkspaceProjectCounts({workspaceIds}),
|
|
34
|
+
}),
|
|
32
35
|
});
|
|
33
36
|
}
|