declapract-typescript-ehmpathy 0.49.1 → 0.49.3
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/dist/practices/environments/best-practice/package.json +1 -1
- package/dist/practices/logs/bad-practices/simple-log-methods/src/<star><star>/<star>.ts.declapract.ts +36 -5
- package/dist/practices/logs/best-practice/package.json +1 -0
- package/dist/practices/logs/best-practice/src/utils/logger.ts +4 -1
- package/dist/practices/node-service/bad-practices/simple-lambda-client/.declapract.readme.md +55 -0
- package/dist/practices/node-service/bad-practices/simple-lambda-client/package.json +5 -0
- package/dist/practices/node-service/bad-practices/simple-lambda-client/package.json.declapract.ts +27 -0
- package/dist/practices/node-service/bad-practices/simple-lambda-client/src/<star><star>/<star>.ts.declapract.ts +44 -0
- package/dist/practices/node-service/bad-practices/simple-lambda-handlers/.declapract.readme.md +52 -0
- package/dist/practices/node-service/bad-practices/simple-lambda-handlers/package.json +5 -0
- package/dist/practices/node-service/bad-practices/simple-lambda-handlers/package.json.declapract.ts +27 -0
- package/dist/practices/node-service/bad-practices/simple-lambda-handlers/src/<star><star>/<star>.ts.declapract.ts +50 -0
- package/dist/practices/node-service/best-practice/package.json +4 -1
- package/dist/practices/rhachet/bad-practices/review-peer-artifacts/.behavior/<star><star>/.reviews/<star><star>/<star>peer-review<star>.md.declapract.ts +16 -0
- package/dist/practices/rhachet/bad-practices/review-peer-artifacts/.behavior/<star><star>/.reviews/peer/<star><star>/<star>.md.declapract.ts +16 -0
- package/dist/practices/rhachet/bad-practices/review-peer-artifacts/.declapract.readme.md +12 -0
- package/dist/practices/{runtime-type-checking → runtime-schemas}/bad-practices/joi/package.json.declapract.ts +4 -0
- package/dist/practices/runtime-schemas/bad-practices/joi/src/<star><star>/<star>.ts.declapract.ts +50 -0
- package/dist/useCases.yml +1 -3
- package/package.json +6 -5
- package/dist/practices/lambda-clients/bad-practices/lambda-service-client-package/.declapract.readme.md +0 -1
- package/dist/practices/lambda-clients/bad-practices/lambda-service-client-package/package.json +0 -5
- package/dist/practices/lambda-clients/bad-practices/lambda-service-client-package/package.json.declapract.ts +0 -16
- package/dist/practices/lambda-clients/best-practice/package.json +0 -5
- package/dist/practices/lambda-clients/best-practice/src/data/clients/<star>.ts +0 -1
- package/dist/practices/lambda-clients/best-practice/src/data/clients/<star>.ts.declapract.ts +0 -3
- package/dist/practices/lambda-handlers/best-practice/package.json +0 -6
- package/dist/practices/lambda-handlers/best-practice/package.json.declapract.ts +0 -3
- package/dist/practices/lambda-handlers/best-practice/src/contract/handlers/<star><star>/<star>.declapract.ts +0 -3
- package/dist/practices/runtime-type-checking/bad-practices/joi-types/package.json +0 -5
- package/dist/practices/runtime-type-checking/bad-practices/joi-types/package.json.declapract.ts +0 -18
- package/dist/practices/runtime-type-checking/bad-practices/old-joi-syntax-valid-input-cant-be-array/.declapract.readme.md +0 -1
- package/dist/practices/runtime-type-checking/bad-practices/old-joi-syntax-valid-input-cant-be-array/src/<star><star>/<star>.ts.declapract.ts +0 -15
- package/dist/practices/runtime-type-checking/best-practice/package.json.declapract.ts +0 -3
- /package/dist/practices/{runtime-type-checking → runtime-schemas}/bad-practices/joi/.declapract.readme.md +0 -0
- /package/dist/practices/{runtime-type-checking → runtime-schemas}/bad-practices/joi/package.json +0 -0
- /package/dist/practices/{runtime-type-checking → runtime-schemas}/best-practice/package.json +0 -0
- /package/dist/practices/{lambda-clients → runtime-schemas}/best-practice/package.json.declapract.ts +0 -0
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"dependencies": {
|
|
3
3
|
"@aws-sdk/client-account": "@declapract{check.minVersion('3.1042.0')}",
|
|
4
4
|
"@aws-sdk/client-iam": "@declapract{check.minVersion('3.1042.0')}",
|
|
5
|
-
"sdk-environment": "@declapract{check.minVersion('0.1.
|
|
5
|
+
"sdk-environment": "@declapract{check.minVersion('0.1.5')}"
|
|
6
6
|
}
|
|
7
7
|
}
|
|
@@ -1,15 +1,46 @@
|
|
|
1
1
|
import type { FileCheckFunction, FileFixFunction } from 'declapract';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* .what = migrates simple-log-methods to sdk-logs with commit flow
|
|
5
|
+
* .why = sdk-logs with commit flow enables traceability in production logs
|
|
6
|
+
*
|
|
7
|
+
* .note = declapract semantics:
|
|
8
|
+
* - check returns = bad practice detected (file will be flagged)
|
|
9
|
+
* - check throws = bad practice not detected (file will be skipped)
|
|
10
|
+
* - fix returns {} = no changes needed
|
|
11
|
+
*/
|
|
12
|
+
|
|
3
13
|
export const check: FileCheckFunction = (contents) => {
|
|
14
|
+
// detect files that import from simple-log-methods
|
|
4
15
|
if (contents?.includes("from 'simple-log-methods'")) return;
|
|
5
16
|
throw new Error('does not match bad practice');
|
|
6
17
|
};
|
|
7
18
|
|
|
8
19
|
export const fix: FileFixFunction = (contents) => {
|
|
20
|
+
// no contents means no file to fix
|
|
9
21
|
if (!contents) return {};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
|
|
23
|
+
// step 1: replace package import and method name
|
|
24
|
+
const withSdkLogs = contents
|
|
25
|
+
.replace(/from 'simple-log-methods'/g, "from 'sdk-logs'")
|
|
26
|
+
.replace(/generateLogMethods/g, 'genLogMethods');
|
|
27
|
+
|
|
28
|
+
// step 2: add sdk-environment import if not already present (idempotent)
|
|
29
|
+
const needsEnvImport = !withSdkLogs.includes("from 'sdk-environment'");
|
|
30
|
+
const withEnvImport = needsEnvImport
|
|
31
|
+
? withSdkLogs.replace(
|
|
32
|
+
/import { genLogMethods } from 'sdk-logs';/g,
|
|
33
|
+
"import { getEnvironment } from 'sdk-environment';\nimport { genLogMethods } from 'sdk-logs';",
|
|
34
|
+
)
|
|
35
|
+
: withSdkLogs;
|
|
36
|
+
|
|
37
|
+
// step 3: flow commit through env (only for no-arg calls)
|
|
38
|
+
const withCommitFlow = withEnvImport.replace(
|
|
39
|
+
/genLogMethods\(\)/g,
|
|
40
|
+
`genLogMethods({
|
|
41
|
+
env: { commit: getEnvironment.static().commit },
|
|
42
|
+
})`,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return { contents: withCommitFlow };
|
|
15
46
|
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# simple-lambda-client
|
|
2
|
+
|
|
3
|
+
## what
|
|
4
|
+
|
|
5
|
+
detects and transforms simple-lambda-client usage to sdk-aws-lambda.
|
|
6
|
+
|
|
7
|
+
## why
|
|
8
|
+
|
|
9
|
+
sdk-aws-lambda provides modern lambda client patterns:
|
|
10
|
+
- context-based configuration
|
|
11
|
+
- trail.exid auto-propagation through call chain
|
|
12
|
+
- better cache support
|
|
13
|
+
|
|
14
|
+
## transforms
|
|
15
|
+
|
|
16
|
+
| old | new |
|
|
17
|
+
|-----|-----|
|
|
18
|
+
| `import { invokeLambdaFunction } from 'simple-lambda-client'` | `import { askLambdaEndpoint } from 'sdk-aws-lambda'` |
|
|
19
|
+
| `invokeLambdaFunction(...)` | `askLambdaEndpoint(...)` |
|
|
20
|
+
|
|
21
|
+
## limitations
|
|
22
|
+
|
|
23
|
+
these patterns require manual migration:
|
|
24
|
+
|
|
25
|
+
- `{ service, function, stage, event }` → `{ which: { service, function }, event }, context`
|
|
26
|
+
- `stage: string` → `context.env.access: string`
|
|
27
|
+
- `logDebug?: LogMethod` → `context.log: LogMethods` (required)
|
|
28
|
+
- `cache?: SimpleCache<O>` → `context.cache?: { response?, dedupe? }`
|
|
29
|
+
|
|
30
|
+
## example
|
|
31
|
+
|
|
32
|
+
before:
|
|
33
|
+
```ts
|
|
34
|
+
import { invokeLambdaFunction } from 'simple-lambda-client';
|
|
35
|
+
|
|
36
|
+
const result = await invokeLambdaFunction({
|
|
37
|
+
service: 'svc-users',
|
|
38
|
+
function: 'getUser',
|
|
39
|
+
stage: 'prod',
|
|
40
|
+
event: { userId: '123' },
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
after (requires manual refinement):
|
|
45
|
+
```ts
|
|
46
|
+
import { askLambdaEndpoint } from 'sdk-aws-lambda';
|
|
47
|
+
|
|
48
|
+
const result = await askLambdaEndpoint(
|
|
49
|
+
{
|
|
50
|
+
which: { service: 'svc-users', function: 'getUser' },
|
|
51
|
+
event: { userId: '123' },
|
|
52
|
+
},
|
|
53
|
+
{ log, env: { access: 'prod' } },
|
|
54
|
+
);
|
|
55
|
+
```
|
package/dist/practices/node-service/bad-practices/simple-lambda-client/package.json.declapract.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FileCheckType, type FileFixFunction } from 'declapract';
|
|
2
|
+
|
|
3
|
+
export const check = FileCheckType.CONTAINS;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* .what = removes simple-lambda-client and adds sdk-aws-lambda
|
|
7
|
+
* .why = sdk-aws-lambda is the modern replacement with better patterns
|
|
8
|
+
*/
|
|
9
|
+
export const fix: FileFixFunction = (contents) => {
|
|
10
|
+
if (!contents) return { contents };
|
|
11
|
+
|
|
12
|
+
const packageJSON = JSON.parse(contents);
|
|
13
|
+
|
|
14
|
+
const updatedPackageJSON = {
|
|
15
|
+
...packageJSON,
|
|
16
|
+
dependencies: {
|
|
17
|
+
...packageJSON.dependencies,
|
|
18
|
+
'simple-lambda-client': undefined,
|
|
19
|
+
'sdk-aws-lambda':
|
|
20
|
+
packageJSON.dependencies?.['sdk-aws-lambda'] ?? '^0.1.0',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
contents: JSON.stringify(updatedPackageJSON, null, 2),
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { FileCheckFunction, FileFixFunction } from 'declapract';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* .what = detects simple-lambda-client imports in source files
|
|
5
|
+
* .why = simple-lambda-client should be replaced with sdk-aws-lambda
|
|
6
|
+
*/
|
|
7
|
+
export const check: FileCheckFunction = (contents) => {
|
|
8
|
+
// match if file imports from simple-lambda-client
|
|
9
|
+
if (contents?.includes("from 'simple-lambda-client'")) return;
|
|
10
|
+
if (contents?.includes('from "simple-lambda-client"')) return;
|
|
11
|
+
|
|
12
|
+
// no match
|
|
13
|
+
throw new Error('does not import from simple-lambda-client');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* .what = transforms simple-lambda-client imports to sdk-aws-lambda
|
|
18
|
+
* .why = automated migration reduces manual toil
|
|
19
|
+
*
|
|
20
|
+
* .note = basic transforms only; complex patterns require manual fix
|
|
21
|
+
*
|
|
22
|
+
* API map:
|
|
23
|
+
* - invokeLambdaFunction → askLambdaEndpoint
|
|
24
|
+
*/
|
|
25
|
+
export const fix: FileFixFunction = (contents) => {
|
|
26
|
+
if (!contents) return {};
|
|
27
|
+
|
|
28
|
+
const updated = contents
|
|
29
|
+
// transform imports
|
|
30
|
+
.replace(
|
|
31
|
+
/import\s+\{([^}]*)\}\s+from\s+['"]simple-lambda-client['"]/g,
|
|
32
|
+
(match, imports) => {
|
|
33
|
+
const updatedImports = imports.replace(
|
|
34
|
+
/invokeLambdaFunction/g,
|
|
35
|
+
'askLambdaEndpoint',
|
|
36
|
+
);
|
|
37
|
+
return `import {${updatedImports}} from 'sdk-aws-lambda'`;
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
// transform function calls
|
|
41
|
+
.replace(/invokeLambdaFunction/g, 'askLambdaEndpoint');
|
|
42
|
+
|
|
43
|
+
return { contents: updated };
|
|
44
|
+
};
|
package/dist/practices/node-service/bad-practices/simple-lambda-handlers/.declapract.readme.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# simple-lambda-handlers
|
|
2
|
+
|
|
3
|
+
## what
|
|
4
|
+
|
|
5
|
+
detects and transforms simple-lambda-handlers usage to sdk-aws-lambda.
|
|
6
|
+
|
|
7
|
+
## why
|
|
8
|
+
|
|
9
|
+
sdk-aws-lambda provides modern lambda handler patterns:
|
|
10
|
+
- better schema validation with zod (input + output)
|
|
11
|
+
- log context passed to invoke function
|
|
12
|
+
- trail.exid auto-propagation
|
|
13
|
+
|
|
14
|
+
## transforms
|
|
15
|
+
|
|
16
|
+
| old | new |
|
|
17
|
+
|-----|-----|
|
|
18
|
+
| `import { createStandardHandler } from 'simple-lambda-handlers'` | `import { genLambdaEndpoint } from 'sdk-aws-lambda'` |
|
|
19
|
+
| `import { createApiGatewayHandler } from 'simple-lambda-handlers'` | `import { genLambdaEndpoint } from 'sdk-aws-lambda'` |
|
|
20
|
+
| `createStandardHandler(...)` | `genLambdaEndpoint(...)` |
|
|
21
|
+
| `createApiGatewayHandler(...)` | `genLambdaEndpoint.for.apiGateway(...)` |
|
|
22
|
+
|
|
23
|
+
## limitations
|
|
24
|
+
|
|
25
|
+
these patterns require manual migration:
|
|
26
|
+
|
|
27
|
+
- `schema` (single joi) → `schema: { input, output }` (split zod)
|
|
28
|
+
- `logic: (event) => O` → `invoke: ({ event }, { log }) => O`
|
|
29
|
+
- `log` passed at creation → `log` also received in invoke context
|
|
30
|
+
|
|
31
|
+
## example
|
|
32
|
+
|
|
33
|
+
before:
|
|
34
|
+
```ts
|
|
35
|
+
import { createStandardHandler } from 'simple-lambda-handlers';
|
|
36
|
+
|
|
37
|
+
export const handler = createStandardHandler({
|
|
38
|
+
log,
|
|
39
|
+
schema,
|
|
40
|
+
logic: async (event) => doStuff(event),
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
after (requires manual refinement):
|
|
45
|
+
```ts
|
|
46
|
+
import { genLambdaEndpoint } from 'sdk-aws-lambda';
|
|
47
|
+
|
|
48
|
+
export const handler = genLambdaEndpoint({
|
|
49
|
+
schema: { input: inputSchema, output: outputSchema },
|
|
50
|
+
invoke: async ({ event }, { log }) => doStuff(event),
|
|
51
|
+
}, { log });
|
|
52
|
+
```
|
package/dist/practices/node-service/bad-practices/simple-lambda-handlers/package.json.declapract.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FileCheckType, type FileFixFunction } from 'declapract';
|
|
2
|
+
|
|
3
|
+
export const check = FileCheckType.CONTAINS;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* .what = removes simple-lambda-handlers and adds sdk-aws-lambda
|
|
7
|
+
* .why = sdk-aws-lambda is the modern replacement with better patterns
|
|
8
|
+
*/
|
|
9
|
+
export const fix: FileFixFunction = (contents) => {
|
|
10
|
+
if (!contents) return { contents };
|
|
11
|
+
|
|
12
|
+
const packageJSON = JSON.parse(contents);
|
|
13
|
+
|
|
14
|
+
const updatedPackageJSON = {
|
|
15
|
+
...packageJSON,
|
|
16
|
+
dependencies: {
|
|
17
|
+
...packageJSON.dependencies,
|
|
18
|
+
'simple-lambda-handlers': undefined,
|
|
19
|
+
'sdk-aws-lambda':
|
|
20
|
+
packageJSON.dependencies?.['sdk-aws-lambda'] ?? '^0.1.0',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
contents: JSON.stringify(updatedPackageJSON, null, 2),
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { FileCheckFunction, FileFixFunction } from 'declapract';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* .what = detects simple-lambda-handlers imports in source files
|
|
5
|
+
* .why = simple-lambda-handlers should be replaced with sdk-aws-lambda
|
|
6
|
+
*/
|
|
7
|
+
export const check: FileCheckFunction = (contents) => {
|
|
8
|
+
// match if file imports from simple-lambda-handlers
|
|
9
|
+
if (contents?.includes("from 'simple-lambda-handlers'")) return;
|
|
10
|
+
if (contents?.includes('from "simple-lambda-handlers"')) return;
|
|
11
|
+
|
|
12
|
+
// no match
|
|
13
|
+
throw new Error('does not import from simple-lambda-handlers');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* .what = transforms simple-lambda-handlers imports to sdk-aws-lambda
|
|
18
|
+
* .why = automated migration reduces manual toil
|
|
19
|
+
*
|
|
20
|
+
* .note = basic transforms only; complex patterns require manual fix
|
|
21
|
+
*
|
|
22
|
+
* API map:
|
|
23
|
+
* - createStandardHandler → genLambdaEndpoint
|
|
24
|
+
* - createApiGatewayHandler → genLambdaEndpoint.for.apiGateway
|
|
25
|
+
*/
|
|
26
|
+
export const fix: FileFixFunction = (contents) => {
|
|
27
|
+
if (!contents) return {};
|
|
28
|
+
|
|
29
|
+
const updated = contents
|
|
30
|
+
// transform imports (dedupe to avoid duplicate genLambdaEndpoint)
|
|
31
|
+
.replace(
|
|
32
|
+
/import\s+\{([^}]*)\}\s+from\s+['"]simple-lambda-handlers['"]/g,
|
|
33
|
+
(match, imports) => {
|
|
34
|
+
// split, replace, dedupe, join
|
|
35
|
+
const importList = imports.split(',').map((s: string) => s.trim());
|
|
36
|
+
const transformed = importList.map((name: string) => {
|
|
37
|
+
if (name === 'createStandardHandler') return 'genLambdaEndpoint';
|
|
38
|
+
if (name === 'createApiGatewayHandler') return 'genLambdaEndpoint';
|
|
39
|
+
return name;
|
|
40
|
+
});
|
|
41
|
+
const deduped = [...new Set(transformed)];
|
|
42
|
+
return `import { ${deduped.join(', ')} } from 'sdk-aws-lambda'`;
|
|
43
|
+
},
|
|
44
|
+
)
|
|
45
|
+
// transform function calls
|
|
46
|
+
.replace(/createStandardHandler/g, 'genLambdaEndpoint')
|
|
47
|
+
.replace(/createApiGatewayHandler/g, 'genLambdaEndpoint.for.apiGateway');
|
|
48
|
+
|
|
49
|
+
return { contents: updated };
|
|
50
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FileCheckType, type FileFixFunction } from 'declapract';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* .what = detects committed peer-review artifacts under .behavior/**\/.reviews
|
|
5
|
+
* .why = peer-review files are noise; far less important than the root behavior
|
|
6
|
+
* files, so they should not be tracked in git
|
|
7
|
+
*
|
|
8
|
+
* .note = matches the old flat shape, where peer-review files sit directly in
|
|
9
|
+
* .reviews with `peer-review` in the filename
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const check = FileCheckType.EXISTS;
|
|
13
|
+
|
|
14
|
+
export const fix: FileFixFunction = () => {
|
|
15
|
+
return { contents: null }; // delete the file
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FileCheckType, type FileFixFunction } from 'declapract';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* .what = detects committed peer-review artifacts under .behavior/**\/.reviews/peer
|
|
5
|
+
* .why = peer-review files are noise; far less important than the root behavior
|
|
6
|
+
* files, so they should not be tracked in git
|
|
7
|
+
*
|
|
8
|
+
* .note = matches the new shape, where all peer-review files live under a
|
|
9
|
+
* dedicated `peer` directory
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const check = FileCheckType.EXISTS;
|
|
13
|
+
|
|
14
|
+
export const fix: FileFixFunction = () => {
|
|
15
|
+
return { contents: null }; // delete the file
|
|
16
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
peer review artifacts should not be committed to git
|
|
2
|
+
|
|
3
|
+
these files live under `.behavior/**/.reviews/` and capture peer-review feedback
|
|
4
|
+
from the behavior build lifecycle. they are noise for the most part — far less
|
|
5
|
+
important than the root behavior files themselves.
|
|
6
|
+
|
|
7
|
+
two path shapes are removed:
|
|
8
|
+
|
|
9
|
+
- old (flat): `.behavior/**/.reviews/**/*peer-review*.md`
|
|
10
|
+
- new (peer dir): `.behavior/**/.reviews/peer/**/*.md`
|
|
11
|
+
|
|
12
|
+
self-reviews and other non-peer artifacts under `.reviews/` are intentionally left alone.
|
|
@@ -12,6 +12,10 @@ export const fix: FileFixFunction = (contents) => {
|
|
|
12
12
|
joi: undefined,
|
|
13
13
|
zod: packageJSON.dependencies?.zod ?? '^3.24.0',
|
|
14
14
|
},
|
|
15
|
+
devDependencies: {
|
|
16
|
+
...packageJSON.devDependencies,
|
|
17
|
+
'@types/joi': undefined,
|
|
18
|
+
},
|
|
15
19
|
};
|
|
16
20
|
return {
|
|
17
21
|
contents: JSON.stringify(updatedPackageJSON, null, 2),
|
package/dist/practices/runtime-schemas/bad-practices/joi/src/<star><star>/<star>.ts.declapract.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { FileCheckFunction, FileFixFunction } from 'declapract';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* .what = detects joi imports in source files
|
|
5
|
+
* .why = joi should be replaced with zod for better typescript integration
|
|
6
|
+
*/
|
|
7
|
+
export const check: FileCheckFunction = (contents) => {
|
|
8
|
+
// match if file imports from joi
|
|
9
|
+
if (contents?.includes("from 'joi'")) return;
|
|
10
|
+
if (contents?.includes('from "joi"')) return;
|
|
11
|
+
|
|
12
|
+
// no match
|
|
13
|
+
throw new Error('does not import from joi');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* .what = transforms joi imports and basic schema patterns to zod
|
|
18
|
+
* .why = automated migration reduces manual toil
|
|
19
|
+
*
|
|
20
|
+
* .note = basic transforms only; complex patterns require manual fix
|
|
21
|
+
*/
|
|
22
|
+
export const fix: FileFixFunction = (contents) => {
|
|
23
|
+
if (!contents) return {};
|
|
24
|
+
|
|
25
|
+
const updated = contents
|
|
26
|
+
// transform imports: import Joi from 'joi' → import { z } from 'zod'
|
|
27
|
+
.replace(/import\s+Joi\s+from\s+['"]joi['"]/g, "import { z } from 'zod'")
|
|
28
|
+
// transform imports: import * as Joi from 'joi' → import { z } from 'zod'
|
|
29
|
+
.replace(
|
|
30
|
+
/import\s+\*\s+as\s+Joi\s+from\s+['"]joi['"]/g,
|
|
31
|
+
"import { z } from 'zod'",
|
|
32
|
+
)
|
|
33
|
+
// transform imports: import { ... } from 'joi' → import { z } from 'zod'
|
|
34
|
+
.replace(
|
|
35
|
+
/import\s+\{[^}]*\}\s+from\s+['"]joi['"]/g,
|
|
36
|
+
"import { z } from 'zod'",
|
|
37
|
+
)
|
|
38
|
+
// transform basic schema patterns: Joi.* → z.*
|
|
39
|
+
.replace(/Joi\.object/g, 'z.object')
|
|
40
|
+
.replace(/Joi\.string/g, 'z.string')
|
|
41
|
+
.replace(/Joi\.number/g, 'z.number')
|
|
42
|
+
.replace(/Joi\.boolean/g, 'z.boolean')
|
|
43
|
+
.replace(/Joi\.array/g, 'z.array')
|
|
44
|
+
.replace(/Joi\.date/g, 'z.date')
|
|
45
|
+
.replace(/Joi\.any/g, 'z.any')
|
|
46
|
+
// transform .required() → remove (zod is required by default)
|
|
47
|
+
.replace(/\.required\(\)/g, '');
|
|
48
|
+
|
|
49
|
+
return { contents: updated };
|
|
50
|
+
};
|
package/dist/useCases.yml
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "declapract-typescript-ehmpathy",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "declapract best practices declarations for typescript",
|
|
5
|
-
"version": "0.49.
|
|
5
|
+
"version": "0.49.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"repository": "ehmpathy/declapract-typescript-ehmpathy",
|
|
@@ -76,12 +76,13 @@
|
|
|
76
76
|
"esbuild-register": "3.6.0",
|
|
77
77
|
"husky": "8.0.3",
|
|
78
78
|
"jest": "30.2.0",
|
|
79
|
-
"rhachet": "1.
|
|
79
|
+
"rhachet": "1.42.2",
|
|
80
80
|
"rhachet-brains-anthropic": "0.4.1",
|
|
81
|
+
"rhachet-brains-fireworksai": "0.1.3",
|
|
81
82
|
"rhachet-brains-xai": "0.3.3",
|
|
82
|
-
"rhachet-roles-bhrain": "0.29.
|
|
83
|
-
"rhachet-roles-bhuild": "0.21.
|
|
84
|
-
"rhachet-roles-ehmpathy": "1.
|
|
83
|
+
"rhachet-roles-bhrain": "0.29.10",
|
|
84
|
+
"rhachet-roles-bhuild": "0.21.18",
|
|
85
|
+
"rhachet-roles-ehmpathy": "1.37.0",
|
|
85
86
|
"tsc-alias": "1.8.10",
|
|
86
87
|
"tsx": "4.20.6",
|
|
87
88
|
"type-fns": "1.21.2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
our `simple-lambda-client` package used to be called `lambda-service-client`. its no longer maintained, but may still be used in some services. it shouldn't be anymore though
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FileCheckType, type FileFixFunction } from 'declapract';
|
|
2
|
-
|
|
3
|
-
export const check = FileCheckType.CONTAINS;
|
|
4
|
-
|
|
5
|
-
export const fix: FileFixFunction = (contents) => {
|
|
6
|
-
if (!contents) return {}; // should not reach here, file should exist; if doesnt though, do nothing
|
|
7
|
-
const parsedContents = JSON.parse(contents);
|
|
8
|
-
const fixedParsedContents = {
|
|
9
|
-
...parsedContents,
|
|
10
|
-
dependencies: {
|
|
11
|
-
...parsedContents.dependencies,
|
|
12
|
-
'lambda-service-client': undefined, // remove this module
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
return { contents: JSON.stringify(fixedParsedContents, null, 2) };
|
|
16
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { invokeLambdaFunction } from 'simple-lambda-client';
|
package/dist/practices/runtime-type-checking/bad-practices/joi-types/package.json.declapract.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { FileCheckType, type FileFixFunction } from 'declapract';
|
|
2
|
-
|
|
3
|
-
export const check = FileCheckType.CONTAINS;
|
|
4
|
-
|
|
5
|
-
export const fix: FileFixFunction = (contents) => {
|
|
6
|
-
if (!contents) return { contents }; // do nothing if no contents
|
|
7
|
-
const packageJSON = JSON.parse(contents);
|
|
8
|
-
const updatedPackageJSON = {
|
|
9
|
-
...packageJSON,
|
|
10
|
-
devDependencies: {
|
|
11
|
-
...packageJSON.devDependencies,
|
|
12
|
-
'@types/joi': undefined,
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
return {
|
|
16
|
-
contents: JSON.stringify(updatedPackageJSON, null, 2),
|
|
17
|
-
};
|
|
18
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
joi updated their syntax and now throws an error if `.valid([])`, instead we need to give `.valid(...[])`
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { FileCheckFunction, FileFixFunction } from 'declapract';
|
|
2
|
-
|
|
3
|
-
export const check: FileCheckFunction = (contents) => {
|
|
4
|
-
if (contents?.includes('.valid(Object.values(')) return; // matches bad practice if this is found
|
|
5
|
-
throw new Error('passes, does not match bad practice');
|
|
6
|
-
};
|
|
7
|
-
export const fix: FileFixFunction = (contents) => {
|
|
8
|
-
if (!contents) return {};
|
|
9
|
-
return {
|
|
10
|
-
contents: contents.replace(
|
|
11
|
-
/\.valid\(Object\.values/g,
|
|
12
|
-
'.valid(...Object.values',
|
|
13
|
-
),
|
|
14
|
-
};
|
|
15
|
-
};
|
|
File without changes
|
/package/dist/practices/{runtime-type-checking → runtime-schemas}/bad-practices/joi/package.json
RENAMED
|
File without changes
|
/package/dist/practices/{runtime-type-checking → runtime-schemas}/best-practice/package.json
RENAMED
|
File without changes
|
/package/dist/practices/{lambda-clients → runtime-schemas}/best-practice/package.json.declapract.ts
RENAMED
|
File without changes
|