Skip to content

Commit 2e93c11

Browse files
authored
Feature/ccm 13194 lint internal (#271)
* lint internal datastore * lint internal events * lint internal events * typecheck * replace uuid with node:crypto * increment event package version
1 parent 518f65c commit 2e93c11

38 files changed

+922
-718
lines changed

docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"build": "JEKYLL_ENV=production bundle exec jekyll build --trace --config _config.yml,_config.version.yml",
1515
"debug": "JEKYLL_ENV=development BUNDLE_GEMFILE=Gemfile bundle exec jekyll serve --config _config.yml,_config.dev.yml,_config.version.yml --limit_posts 100 --trace",
1616
"generate-includes": "./generate-includes.sh",
17-
"test:unit": "echo \"Documentation module has no unit tests\""
17+
"test:unit": "echo \"Documentation module has no unit tests\"",
18+
"typecheck": "echo \"Documentation module has no typescript to typecheck\""
1819
},
1920
"version": "1.0.0"
2021
}

eslint.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export default defineConfig([
184184
rules: { 'no-relative-import-paths/no-relative-import-paths': 2 },
185185
},
186186
{
187-
files: ['scripts/**'],
187+
files: ['scripts/**', '**/__test__/**/*.ts', '**/__tests__/**/*.ts'],
188188
rules: {
189189
'import-x/no-extraneous-dependencies': [
190190
'error',
@@ -229,8 +229,8 @@ export default defineConfig([
229229
'no-await-in-loop': 0,
230230
'no-plusplus': [2, { allowForLoopAfterthoughts: true }],
231231
'unicorn/prefer-top-level-await': 0,
232-
'import-x/no-relative-packages': 1,
233-
'no-relative-import-paths/no-relative-import-paths': 1
232+
'import-x/no-relative-packages': 0,
233+
'no-relative-import-paths/no-relative-import-paths': 0
234234
},
235235
},
236236
]);

internal/datastore/jest.config.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Config } from 'jest';
1+
import type { Config } from "jest";
22

33
export const baseJestConfig: Config = {
4-
preset: 'ts-jest',
4+
preset: "ts-jest",
55

66
// Automatically clear mock calls, instances, contexts and results before every test
77
clearMocks: true,
@@ -10,14 +10,14 @@ export const baseJestConfig: Config = {
1010
collectCoverage: true,
1111

1212
// The directory where Jest should output its coverage files
13-
coverageDirectory: './.reports/unit/coverage',
13+
coverageDirectory: "./.reports/unit/coverage",
1414

1515
// Indicates which provider should be used to instrument code for coverage
16-
coverageProvider: 'babel',
16+
coverageProvider: "babel",
1717

1818
// Module name mapper to handle TypeScript path aliases
1919
moduleNameMapper: {
20-
'^@internal/helpers$': '<rootDir>/../helpers/src'
20+
"^@internal/helpers$": "<rootDir>/../helpers/src",
2121
},
2222

2323
coverageThreshold: {
@@ -29,36 +29,36 @@ export const baseJestConfig: Config = {
2929
},
3030
},
3131

32-
coveragePathIgnorePatterns: ['/__tests__/'],
33-
transform: { '^.+\\.ts$': 'ts-jest' },
34-
testPathIgnorePatterns: ['.build'],
35-
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
32+
coveragePathIgnorePatterns: ["/__tests__/"],
33+
transform: { "^.+\\.ts$": "ts-jest" },
34+
testPathIgnorePatterns: [".build"],
35+
testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"],
3636

3737
// Use this configuration option to add custom reporters to Jest
3838
reporters: [
39-
'default',
39+
"default",
4040
[
41-
'jest-html-reporter',
41+
"jest-html-reporter",
4242
{
43-
pageTitle: 'Test Report',
44-
outputPath: './.reports/unit/test-report.html',
43+
pageTitle: "Test Report",
44+
outputPath: "./.reports/unit/test-report.html",
4545
includeFailureMsg: true,
4646
},
4747
],
4848
],
4949

5050
// The test environment that will be used for testing
51-
testEnvironment: 'jsdom',
51+
testEnvironment: "jsdom",
5252
};
5353

5454
const utilsJestConfig = {
5555
...baseJestConfig,
5656

57-
testEnvironment: 'node',
57+
testEnvironment: "node",
5858

5959
coveragePathIgnorePatterns: [
6060
...(baseJestConfig.coveragePathIgnorePatterns ?? []),
61-
'zod-validators.ts',
61+
"zod-validators.ts",
6262
],
6363
};
6464

internal/datastore/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"@aws-sdk/lib-dynamodb": "^3.858.0",
55
"@internal/helpers": "*",
66
"pino": "^9.7.0",
7-
"zod": "^4.1.11"
7+
"zod": "^4.1.11",
8+
"zod-mermaid": "^1.0.9"
89
},
910
"devDependencies": {
1011
"@stylistic/eslint-plugin": "^3.1.0",
@@ -19,8 +20,7 @@
1920
"testcontainers": "^11.4.0",
2021
"ts-jest": "^29.4.0",
2122
"ts-node": "^10.9.2",
22-
"typescript": "^5.9.3",
23-
"zod-mermaid": "^1.0.9"
23+
"typescript": "^5.9.3"
2424
},
2525
"license": "MIT",
2626
"main": "src/index.ts",
Lines changed: 97 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,122 @@
1-
import { GenericContainer } from 'testcontainers';
1+
import { GenericContainer } from "testcontainers";
22
import {
33
CreateTableCommand,
44
DeleteTableCommand,
55
DynamoDBClient,
6-
UpdateTimeToLiveCommand
7-
} from '@aws-sdk/client-dynamodb';
8-
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
9-
import { DatastoreConfig } from '../config';
6+
UpdateTimeToLiveCommand,
7+
} from "@aws-sdk/client-dynamodb";
8+
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
9+
import { DatastoreConfig } from "../config";
1010

1111
export async function setupDynamoDBContainer() {
12-
const container = await new GenericContainer('amazon/dynamodb-local')
12+
const container = await new GenericContainer("amazon/dynamodb-local")
1313
.withExposedPorts(8000)
1414
.start();
1515

1616
const endpoint = `http://${container.getHost()}:${container.getMappedPort(8000)}`;
1717

1818
const ddbClient = new DynamoDBClient({
19-
region: 'us-west-2',
19+
region: "us-west-2",
2020
endpoint,
2121
credentials: {
22-
accessKeyId: 'fakeMyKeyId',
23-
secretAccessKey: 'fakeSecretAccessKey'
24-
}
22+
accessKeyId: "fakeMyKeyId",
23+
secretAccessKey: "fakeSecretAccessKey",
24+
},
2525
});
2626

2727
const docClient = DynamoDBDocumentClient.from(ddbClient);
2828

29-
const config : DatastoreConfig = {
30-
region: 'us-west-2',
29+
const config: DatastoreConfig = {
30+
region: "us-west-2",
3131
endpoint,
32-
lettersTableName: 'letters',
33-
miTableName: 'management-info',
34-
suppliersTableName: 'suppliers',
32+
lettersTableName: "letters",
33+
miTableName: "management-info",
34+
suppliersTableName: "suppliers",
3535
lettersTtlHours: 1,
36-
miTtlHours: 1
36+
miTtlHours: 1,
3737
};
3838

3939
return {
4040
container,
4141
ddbClient,
4242
docClient,
4343
endpoint,
44-
config
44+
config,
4545
};
4646
}
4747

4848
export type DBContext = Awaited<ReturnType<typeof setupDynamoDBContainer>>;
4949

5050
const createLetterTableCommand = new CreateTableCommand({
51-
TableName: 'letters',
52-
BillingMode: 'PAY_PER_REQUEST',
53-
KeySchema: [
54-
{ AttributeName: 'supplierId', KeyType: 'HASH' }, // Partition key
55-
{ AttributeName: 'id', KeyType: 'RANGE' } // Sort key
56-
],
57-
GlobalSecondaryIndexes: [
58-
{
59-
IndexName: 'supplierStatus-index',
60-
KeySchema: [
61-
{ AttributeName: 'supplierStatus', KeyType: 'HASH' }, // Partition key for GSI
62-
{ AttributeName: 'supplierStatusSk', KeyType: 'RANGE' } // Sort key for GSI
63-
],
64-
Projection: {
65-
ProjectionType: 'ALL'
66-
}
67-
}
68-
],
69-
AttributeDefinitions: [
70-
{ AttributeName: 'supplierId', AttributeType: 'S' },
71-
{ AttributeName: 'id', AttributeType: 'S' },
72-
{ AttributeName: 'supplierStatus', AttributeType: 'S' },
73-
{ AttributeName: 'supplierStatusSk', AttributeType: 'S' },
74-
]
75-
});
51+
TableName: "letters",
52+
BillingMode: "PAY_PER_REQUEST",
53+
KeySchema: [
54+
{ AttributeName: "supplierId", KeyType: "HASH" }, // Partition key
55+
{ AttributeName: "id", KeyType: "RANGE" }, // Sort key
56+
],
57+
GlobalSecondaryIndexes: [
58+
{
59+
IndexName: "supplierStatus-index",
60+
KeySchema: [
61+
{ AttributeName: "supplierStatus", KeyType: "HASH" }, // Partition key for GSI
62+
{ AttributeName: "supplierStatusSk", KeyType: "RANGE" }, // Sort key for GSI
63+
],
64+
Projection: {
65+
ProjectionType: "ALL",
66+
},
67+
},
68+
],
69+
AttributeDefinitions: [
70+
{ AttributeName: "supplierId", AttributeType: "S" },
71+
{ AttributeName: "id", AttributeType: "S" },
72+
{ AttributeName: "supplierStatus", AttributeType: "S" },
73+
{ AttributeName: "supplierStatusSk", AttributeType: "S" },
74+
],
75+
});
7676

7777
const updateTimeToLiveCommand = new UpdateTimeToLiveCommand({
78-
TableName: 'letters',
79-
TimeToLiveSpecification: {
80-
AttributeName: 'ttl',
81-
Enabled: true
82-
}
83-
});
78+
TableName: "letters",
79+
TimeToLiveSpecification: {
80+
AttributeName: "ttl",
81+
Enabled: true,
82+
},
83+
});
8484

8585
const createMITableCommand = new CreateTableCommand({
86-
TableName: 'management-info',
87-
BillingMode: 'PAY_PER_REQUEST',
88-
KeySchema: [
89-
{ AttributeName: 'supplierId', KeyType: 'HASH' }, // Partition key
90-
{ AttributeName: 'id', KeyType: 'RANGE' } // Sort key
91-
],
92-
AttributeDefinitions: [
93-
{ AttributeName: 'supplierId', AttributeType: 'S' },
94-
{ AttributeName: 'id', AttributeType: 'S' },
95-
]
96-
});
86+
TableName: "management-info",
87+
BillingMode: "PAY_PER_REQUEST",
88+
KeySchema: [
89+
{ AttributeName: "supplierId", KeyType: "HASH" }, // Partition key
90+
{ AttributeName: "id", KeyType: "RANGE" }, // Sort key
91+
],
92+
AttributeDefinitions: [
93+
{ AttributeName: "supplierId", AttributeType: "S" },
94+
{ AttributeName: "id", AttributeType: "S" },
95+
],
96+
});
9797

9898
const createSupplierTableCommand = new CreateTableCommand({
99-
TableName: 'suppliers',
100-
BillingMode: 'PAY_PER_REQUEST',
101-
KeySchema: [
102-
{ AttributeName: 'id', KeyType: 'HASH' } // Partition key
103-
],
104-
GlobalSecondaryIndexes: [
105-
{
106-
IndexName: 'supplier-apim-index',
107-
KeySchema: [
108-
{ AttributeName: 'apimId', KeyType: 'HASH' } // Partition key for GSI
109-
],
110-
Projection: {
111-
ProjectionType: 'ALL'
112-
}
113-
}
114-
],
115-
AttributeDefinitions: [
116-
{ AttributeName: 'id', AttributeType: 'S' },
117-
{ AttributeName: 'apimId', AttributeType: 'S' }
118-
]
119-
});
120-
99+
TableName: "suppliers",
100+
BillingMode: "PAY_PER_REQUEST",
101+
KeySchema: [
102+
{ AttributeName: "id", KeyType: "HASH" }, // Partition key
103+
],
104+
GlobalSecondaryIndexes: [
105+
{
106+
IndexName: "supplier-apim-index",
107+
KeySchema: [
108+
{ AttributeName: "apimId", KeyType: "HASH" }, // Partition key for GSI
109+
],
110+
Projection: {
111+
ProjectionType: "ALL",
112+
},
113+
},
114+
],
115+
AttributeDefinitions: [
116+
{ AttributeName: "id", AttributeType: "S" },
117+
{ AttributeName: "apimId", AttributeType: "S" },
118+
],
119+
});
121120

122121
export async function createTables(context: DBContext) {
123122
const { ddbClient } = context;
@@ -129,19 +128,24 @@ export async function createTables(context: DBContext) {
129128
await ddbClient.send(createSupplierTableCommand);
130129
}
131130

132-
133131
export async function deleteTables(context: DBContext) {
134132
const { ddbClient } = context;
135133

136-
await ddbClient.send(new DeleteTableCommand({
137-
TableName: 'letters'
138-
}));
139-
140-
await ddbClient.send(new DeleteTableCommand({
141-
TableName: 'management-info'
142-
}));
143-
144-
await ddbClient.send(new DeleteTableCommand({
145-
TableName: 'suppliers'
146-
}));
134+
await ddbClient.send(
135+
new DeleteTableCommand({
136+
TableName: "letters",
137+
}),
138+
);
139+
140+
await ddbClient.send(
141+
new DeleteTableCommand({
142+
TableName: "management-info",
143+
}),
144+
);
145+
146+
await ddbClient.send(
147+
new DeleteTableCommand({
148+
TableName: "suppliers",
149+
}),
150+
);
147151
}

0 commit comments

Comments
 (0)