Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIN-6093 - Add client SQL splitters #1477

Draft
wants to merge 42 commits into
base: PIN-6073_scaffolding-readmodel-package
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4804c9e
Add sql models for client
shuyec Feb 5, 2025
2976e71
Delete sample.ts
shuyec Feb 5, 2025
3dc1d30
Add client SQL parsers
shuyec Feb 5, 2025
7bb47c7
Add client SQL splitters
shuyec Feb 5, 2025
e30daa6
Fix ClientSQL attributes names
shuyec Feb 5, 2025
2aae5f9
Merge branch 'PIN-6080_client-sql' into PIN-6093_client-splitter
shuyec Feb 5, 2025
2465f8b
Fix ClientSQL types names
shuyec Feb 5, 2025
53d0326
Merge branch 'PIN-6093_client-splitter' of https://github.com/pagopa/…
shuyec Feb 5, 2025
3f50a1f
Fix use type
shuyec Feb 5, 2025
33d5706
Merge branch 'PIN-6080_client-sql' into PIN-6093_client-splitter
shuyec Feb 5, 2025
1bbdeb8
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6080_c…
taglioni-r Feb 10, 2025
26c4d86
Rename version field
taglioni-r Feb 10, 2025
c4208eb
Merge branch 'PIN-6080_client-sql' into PIN-6093_client-splitter
shuyec Feb 10, 2025
610e13c
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6080_c…
shuyec Feb 10, 2025
5d7af93
Merge branch 'PIN-6080_client-sql' into PIN-6093_client-splitter
shuyec Feb 10, 2025
e069d43
Fix metadata_version
shuyec Feb 10, 2025
b83171c
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6080_c…
taglioni-r Feb 12, 2025
ae69c6a
Remove previous SQL types
taglioni-r Feb 12, 2025
76b2a5f
Delete parser
taglioni-r Feb 12, 2025
57282c6
Merge branch 'PIN-6080_client-sql' of https://github.com/pagopa/inter…
taglioni-r Feb 12, 2025
49633cb
Export generated types
taglioni-r Feb 12, 2025
c3eae74
Fix
taglioni-r Feb 12, 2025
2709596
Merge branch 'PIN-6080_client-sql' into PIN-6093_client-splitter
taglioni-r Feb 12, 2025
c92ac08
Refactor
taglioni-r Feb 12, 2025
e6b71aa
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6080_c…
shuyec Feb 12, 2025
fea1543
Merge branch 'PIN-6080_client-sql' into PIN-6093_client-splitter
shuyec Feb 12, 2025
29e82ab
Rename metadataVersion
shuyec Feb 12, 2025
7daf56d
Replace ReadModel types
shuyec Feb 12, 2025
62f2994
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6080_c…
shuyec Feb 12, 2025
c9a7fb4
Merge branch 'PIN-6080_client-sql' into PIN-6093_client-splitter
shuyec Feb 12, 2025
504907f
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6093_c…
taglioni-r Feb 12, 2025
c86b1c8
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6093_c…
shuyec Feb 14, 2025
3282953
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6093_c…
shuyec Feb 14, 2025
06d21e0
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6093_c…
shuyec Feb 14, 2025
a232e8e
Fix client description in splitter
shuyec Feb 14, 2025
83ebb76
Add client SQL splitter test
shuyec Feb 14, 2025
cd806d5
Merge branch 'PIN-6093_client-splitter' of https://github.com/pagopa/…
shuyec Feb 14, 2025
4f53fd4
Rename client splitter test file
shuyec Feb 17, 2025
81c8361
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6093_c…
paolomanca-pagopa Feb 17, 2025
f51cece
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6093_c…
shuyec Feb 19, 2025
181a346
Fix models imports
shuyec Feb 19, 2025
da2fe19
Merge branch 'PIN-6073_scaffolding-readmodel-package' into PIN-6093_c…
shuyec Feb 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions packages/readmodel/src/authorization/clientSplitters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Client, dateToString } from "pagopa-interop-models";
import {
ClientKeySQL,
ClientPurposeSQL,
ClientSQL,
ClientUserSQL,
} from "pagopa-interop-readmodel-models";

export const splitClientIntoObjectsSQL = (
{
id,
consumerId,
name,
purposes,
description,
users,
kind,
createdAt,
keys,
...rest
}: Client,
metadataVersion: number
): {
clientSQL: ClientSQL;
clientUsersSQL: ClientUserSQL[];
clientPurposesSQL: ClientPurposeSQL[];
clientKeysSQL: ClientKeySQL[];
} => {
void (rest satisfies Record<string, never>);

const clientSQL: ClientSQL = {
id,
metadataVersion,
consumerId,
name,
description: description || null,
kind,
createdAt: dateToString(createdAt),
};

const clientUsersSQL: ClientUserSQL[] = users.map((userId) => ({
metadataVersion,
clientId: id,
userId,
}));

const clientPurposesSQL: ClientPurposeSQL[] = purposes.map((purposeId) => ({
metadataVersion,
clientId: id,
purposeId,
}));

const clientKeysSQL: ClientKeySQL[] = keys.map((key) => ({
metadataVersion,
clientId: id,
userId: key.userId,
kid: key.kid,
name: key.name,
encodedPem: key.encodedPem,
algorithm: key.algorithm,
use: key.use,
createdAt: dateToString(key.createdAt),
}));

return {
clientSQL,
clientUsersSQL,
clientPurposesSQL,
clientKeysSQL,
};
};
91 changes: 91 additions & 0 deletions packages/readmodel/test/clientSplitter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { getMockClient, getMockKey } from "pagopa-interop-commons-test";
import { Client, generateId, PurposeId, UserId } from "pagopa-interop-models";
import { describe, it, expect } from "vitest";
import {
ClientKeySQL,
ClientPurposeSQL,
ClientSQL,
ClientUserSQL,
} from "pagopa-interop-readmodel-models";
import { splitClientIntoObjectsSQL } from "../src/authorization/clientSplitters.js";

describe("Client splitter", () => {
it("should convert a client into client SQL objects", () => {
const userId1 = generateId<UserId>();
const userId2 = generateId<UserId>();
const purposeId1 = generateId<PurposeId>();
const purposeId2 = generateId<PurposeId>();
const key1 = getMockKey();
const key2 = getMockKey();

const client: Client = {
...getMockClient(),
users: [userId1, userId2],
purposes: [purposeId1, purposeId2],
keys: [key1, key2],
description: undefined,
};

const { clientSQL, clientUsersSQL, clientPurposesSQL, clientKeysSQL } =
splitClientIntoObjectsSQL(client, 1);

const expectedClientSQL: ClientSQL = {
id: client.id,
consumerId: client.consumerId,
name: client.name,
createdAt: client.createdAt.toISOString(),
description: null,
kind: client.kind,
metadataVersion: 1,
};

const expectedClientUserSQL1: ClientUserSQL = {
metadataVersion: 1,
clientId: client.id,
userId: userId1,
};
const expectedClientUserSQL2: ClientUserSQL = {
metadataVersion: 1,
clientId: client.id,
userId: userId2,
};

const expectedClientEServicesSQL1: ClientPurposeSQL = {
metadataVersion: 1,
clientId: client.id,
purposeId: purposeId1,
};
const expectedClientEServicesSQL2: ClientPurposeSQL = {
metadataVersion: 1,
clientId: client.id,
purposeId: purposeId2,
};

const expectedClientKeySQL1: ClientKeySQL = {
...key1,
metadataVersion: 1,
clientId: client.id,
createdAt: key1.createdAt.toISOString(),
};
const expectedClientKeySQL2: ClientKeySQL = {
...key2,
metadataVersion: 1,
clientId: client.id,
createdAt: key2.createdAt.toISOString(),
};

expect(clientSQL).toEqual(expectedClientSQL);
expect(clientUsersSQL).toEqual(
expect.arrayContaining([expectedClientUserSQL1, expectedClientUserSQL2])
);
expect(clientPurposesSQL).toEqual(
expect.arrayContaining([
expectedClientEServicesSQL1,
expectedClientEServicesSQL2,
])
);
expect(clientKeysSQL).toEqual(
expect.arrayContaining([expectedClientKeySQL1, expectedClientKeySQL2])
);
});
});
9 changes: 0 additions & 9 deletions packages/readmodel/test/sample.test.ts

This file was deleted.