ts-ag 0.0.1-dev.3 → 1.0.1
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/browser.d.ts +1 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +1 -0
- package/dist/cognito/client.d.ts +6 -0
- package/dist/cognito/client.d.ts.map +1 -0
- package/dist/cognito/client.js +10 -0
- package/dist/cognito/errors.d.ts +95 -0
- package/dist/cognito/errors.d.ts.map +1 -0
- package/dist/cognito/errors.js +128 -0
- package/dist/cognito/index.d.ts +5 -0
- package/dist/cognito/index.d.ts.map +1 -0
- package/dist/cognito/index.js +4 -0
- package/dist/cognito/password.d.ts +53 -0
- package/dist/cognito/password.d.ts.map +1 -0
- package/dist/cognito/password.js +161 -0
- package/dist/cognito/user.d.ts +14 -0
- package/dist/cognito/user.d.ts.map +1 -0
- package/dist/cognito/user.js +34 -0
- package/dist/dynamo/errors.d.ts +9 -0
- package/dist/dynamo/errors.d.ts.map +1 -0
- package/dist/dynamo/errors.js +7 -0
- package/dist/dynamo/index.d.ts +2 -0
- package/dist/dynamo/index.d.ts.map +1 -0
- package/dist/dynamo/index.js +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/lambda/authentication.d.ts +2 -0
- package/dist/lambda/authentication.d.ts.map +1 -0
- package/dist/lambda/authentication.js +1 -0
- package/dist/lambda/client-types.d.ts +19 -19
- package/dist/lambda/client-types.d.ts.map +1 -1
- package/dist/lambda/client-types.js +9 -1
- package/dist/lambda/client.d.ts.map +1 -1
- package/dist/lambda/client.js +7 -2
- package/dist/lambda/errors.d.ts +19 -19
- package/dist/lambda/errors.d.ts.map +1 -1
- package/dist/lambda/errors.js +12 -12
- package/dist/lambda/handlerUtils.d.ts +8 -3
- package/dist/lambda/handlerUtils.d.ts.map +1 -1
- package/dist/lambda/handlerUtils.js +3 -2
- package/dist/lambda/index.d.ts +1 -0
- package/dist/lambda/index.d.ts.map +1 -1
- package/dist/lambda/index.js +2 -0
- package/dist/lambda/response.d.ts +48 -95
- package/dist/lambda/response.d.ts.map +1 -1
- package/dist/lambda/response.js +42 -18
- package/dist/lambda/server/authentication.d.ts +10 -0
- package/dist/lambda/server/authentication.d.ts.map +1 -0
- package/dist/lambda/server/authentication.js +24 -0
- package/dist/s3/client.d.ts +6 -0
- package/dist/s3/client.d.ts.map +1 -0
- package/dist/s3/client.js +7 -0
- package/dist/s3/errors.d.ts +7 -0
- package/dist/s3/errors.d.ts.map +1 -0
- package/dist/s3/errors.js +6 -0
- package/dist/s3/index.d.ts +5 -0
- package/dist/s3/index.d.ts.map +1 -0
- package/dist/s3/index.js +4 -0
- package/dist/s3/object.d.ts +17 -0
- package/dist/s3/object.d.ts.map +1 -0
- package/dist/s3/object.js +32 -0
- package/dist/s3/signedUrl.d.ts +3 -0
- package/dist/s3/signedUrl.d.ts.map +1 -0
- package/dist/s3/signedUrl.js +3 -0
- package/dist/scripts/clean.js +30 -59
- package/dist/scripts/ts-alias.d.ts +3 -0
- package/dist/scripts/ts-alias.d.ts.map +1 -0
- package/dist/scripts/ts-alias.js +167 -0
- package/dist/ses/errors.d.ts +4 -0
- package/dist/ses/errors.d.ts.map +1 -0
- package/dist/ses/errors.js +3 -0
- package/dist/ses/index.d.ts +2 -0
- package/dist/ses/index.d.ts.map +1 -0
- package/dist/ses/index.js +1 -0
- package/dist/ts-alias.js +0 -0
- package/dist/types/deep.d.ts +24 -0
- package/dist/types/deep.d.ts.map +1 -0
- package/dist/types/deep.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/safe.d.ts +2 -0
- package/dist/types/safe.d.ts.map +1 -0
- package/dist/types/safe.js +1 -0
- package/dist/utils/fs.d.ts +7 -1
- package/dist/utils/fs.d.ts.map +1 -1
- package/dist/utils/fs.js +11 -1
- package/package.json +32 -22
- package/src/browser.ts +3 -1
- package/src/cognito/client.ts +11 -0
- package/src/cognito/errors.ts +175 -0
- package/src/cognito/index.ts +5 -0
- package/src/cognito/password.ts +233 -0
- package/src/cognito/user.ts +46 -0
- package/src/dynamo/errors.ts +11 -0
- package/src/dynamo/index.ts +1 -0
- package/src/index.ts +8 -0
- package/src/lambda/client-types.ts +55 -29
- package/src/lambda/client.ts +7 -2
- package/src/lambda/errors.ts +25 -25
- package/src/lambda/handlerUtils.ts +30 -25
- package/src/lambda/index.ts +3 -0
- package/src/lambda/response.ts +90 -26
- package/src/lambda/server/authentication.ts +32 -0
- package/src/s3/client.ts +8 -0
- package/src/s3/errors.ts +6 -0
- package/src/s3/index.ts +6 -0
- package/src/s3/object.ts +37 -0
- package/src/s3/signedUrl.ts +4 -0
- package/src/scripts/clean.ts +34 -68
- package/src/ses/errors.ts +3 -0
- package/src/ses/index.ts +1 -0
- package/src/types/deep.ts +43 -0
- package/src/types/index.ts +2 -0
- package/src/types/safe.ts +1 -0
- package/src/utils/fs.ts +13 -2
- /package/src/{ts-alias.ts → scripts/ts-alias.ts} +0 -0
package/src/scripts/clean.ts
CHANGED
|
@@ -1,75 +1,41 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return { dirExcludes, dirIncludes };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function shouldExclude(dir: string, excludes: string[]): boolean {
|
|
28
|
-
return excludes.some((ex) => path.basename(dir) === ex);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function shouldInclude(dir: string, includes: string[]): boolean {
|
|
32
|
-
if (includes.length === 0) return true;
|
|
33
|
-
return includes.some((inc) => dir.includes(inc));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function removeDir(targetPath: string) {
|
|
37
|
-
if (fs.existsSync(targetPath)) {
|
|
38
|
-
fs.rmSync(targetPath, { recursive: true, force: true });
|
|
39
|
-
console.log(`Removed: ${targetPath}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function clean(root: string, args: Args) {
|
|
44
|
-
const entries = fs.readdirSync(root, { withFileTypes: true });
|
|
45
|
-
for (const entry of entries) {
|
|
46
|
-
const fullPath = path.join(root, entry.name);
|
|
47
|
-
if (entry.isDirectory()) {
|
|
48
|
-
if (entry.name === 'node_modules') continue;
|
|
49
|
-
if (entry.name === 'dist') {
|
|
50
|
-
const distParentDir = path.dirname(fullPath);
|
|
51
|
-
const siblingDirs = fs
|
|
52
|
-
.readdirSync(distParentDir, { withFileTypes: true })
|
|
53
|
-
.filter((d) => d.isDirectory())
|
|
54
|
-
.map((d) => d.name);
|
|
55
|
-
|
|
56
|
-
const shouldExcludeSibling = args.dirExcludes.some((ex) => siblingDirs.includes(ex));
|
|
57
|
-
const shouldIncludeSibling =
|
|
58
|
-
args.dirIncludes.length === 0 || args.dirIncludes.some((inc) => siblingDirs.includes(inc));
|
|
59
|
-
|
|
60
|
-
if (!shouldExcludeSibling && shouldIncludeSibling) {
|
|
61
|
-
removeDir(fullPath);
|
|
62
|
-
}
|
|
63
|
-
continue;
|
|
3
|
+
import { readFileSync, rmSync } from 'fs';
|
|
4
|
+
import { resolve, dirname, join } from 'path';
|
|
5
|
+
import { parse } from 'tsconfck';
|
|
6
|
+
|
|
7
|
+
async function listReferences(tsconfigPath: string, visited = new Set<string>()) {
|
|
8
|
+
// console.log(`Processing: ${tsconfigPath}`);
|
|
9
|
+
tsconfigPath = resolve(tsconfigPath);
|
|
10
|
+
if (visited.has(tsconfigPath)) return;
|
|
11
|
+
visited.add(tsconfigPath);
|
|
12
|
+
|
|
13
|
+
const { tsconfig } = await parse(tsconfigPath);
|
|
14
|
+
const dir = dirname(tsconfigPath);
|
|
15
|
+
|
|
16
|
+
// console.log(`Found tsconfig: ${tsconfigPath}`, tsconfig);
|
|
17
|
+
|
|
18
|
+
if (tsconfig.references && Array.isArray(tsconfig.references)) {
|
|
19
|
+
for (const ref of tsconfig.references) {
|
|
20
|
+
if (typeof ref.path === 'string') {
|
|
21
|
+
const dirPath = ref.path.split('/').slice(0, -1).join('/');
|
|
22
|
+
const configFilename = ref.path.endsWith('.json') ? ref.path.split('/').pop() : 'tsconfig.json';
|
|
23
|
+
await listReferences(resolve(dir, dirPath, configFilename), visited);
|
|
64
24
|
}
|
|
65
|
-
if (!shouldExclude(fullPath, args.dirExcludes)) {
|
|
66
|
-
clean(fullPath, args);
|
|
67
|
-
}
|
|
68
|
-
} else if (entry.name === 'tsconfig.tsbuildinfo') {
|
|
69
|
-
removeDir(fullPath);
|
|
70
25
|
}
|
|
71
26
|
}
|
|
72
27
|
}
|
|
73
28
|
|
|
74
|
-
const
|
|
75
|
-
|
|
29
|
+
const configs = new Set<string>();
|
|
30
|
+
await listReferences(process.argv[2] || 'tsconfig.json', configs);
|
|
31
|
+
console.log('Referenced tsconfig files:');
|
|
32
|
+
for (const conf of configs) {
|
|
33
|
+
const dir = dirname(conf);
|
|
34
|
+
const configName = conf.split('/').pop()?.slice(0, -5) || 'tsconfig';
|
|
35
|
+
|
|
36
|
+
rmSync(join(dir, 'dist'), { recursive: true, force: true });
|
|
37
|
+
rmSync(join(dir, configName + '.tsbuildinfo'), { recursive: true, force: true });
|
|
38
|
+
console.log('Removed dist and tsbuildinfo for:', conf);
|
|
39
|
+
// console.log(' Dist: ', join(dir, 'dist'));
|
|
40
|
+
// console.log(' tsbuildinfo: ', join(dir, configName + '.tsbuildinfo'));
|
|
41
|
+
}
|
package/src/ses/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './errors.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example
|
|
3
|
+
* type HomeOverridden = DeepOverride<Home, {
|
|
4
|
+
* test: {
|
|
5
|
+
* featuredImages: never; // Removing the property
|
|
6
|
+
* meta: {
|
|
7
|
+
* updatedAt: string; // Changing the type
|
|
8
|
+
* };
|
|
9
|
+
* };
|
|
10
|
+
* }>;
|
|
11
|
+
*/
|
|
12
|
+
export type DeepOverride<T, R> = {
|
|
13
|
+
[K in keyof T]: K extends keyof R
|
|
14
|
+
? R[K] extends infer RK // Get override type
|
|
15
|
+
? RK extends Record<string, any> // If override is an object
|
|
16
|
+
? T[K] extends Record<string, any> // If original is an object
|
|
17
|
+
? DeepOverride<T[K], RK> // Recursively override
|
|
18
|
+
: RK // Replace value
|
|
19
|
+
: RK extends Array<infer RU> // If override is an array
|
|
20
|
+
? T[K] extends Array<infer TU> // If original is also an array
|
|
21
|
+
? Array<DeepOverride<TU, RU>> // Recursively apply to array items
|
|
22
|
+
: RK // Direct replacement
|
|
23
|
+
: RK // Direct replacement
|
|
24
|
+
: never
|
|
25
|
+
: T[K]; // Keep original type if not overridden
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
export type DeepPartial<T> = {
|
|
32
|
+
[P in keyof T]?: T[P] extends object
|
|
33
|
+
? // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
34
|
+
T[P] extends Function
|
|
35
|
+
? T[P]
|
|
36
|
+
: DeepPartial<T[P]>
|
|
37
|
+
: T[P];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type DeepRequired<T> = {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
42
|
+
[P in keyof T]-?: NonNullable<T[P] extends object ? (T[P] extends Function ? T[P] : DeepRequired<T[P]>) : T[P]>;
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SafeOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
package/src/utils/fs.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { lstat, mkdir, readFile, writeFile } from 'fs/promises';
|
|
2
2
|
import { dirname } from 'path';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
+
import type { PackageJson } from 'type-fest';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @returns true if a filepath exists
|
|
@@ -16,8 +17,9 @@ export async function exists(filePath: string): Promise<boolean> {
|
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Writes data to a filepath if it is different
|
|
20
|
+
* @returns true if the file is written to
|
|
19
21
|
*/
|
|
20
|
-
export async function writeIfDifferent(filePath: string, newData: string) {
|
|
22
|
+
export async function writeIfDifferent(filePath: string, newData: string): Promise<boolean> {
|
|
21
23
|
// Ensure the directory exists
|
|
22
24
|
const directory = dirname(filePath);
|
|
23
25
|
if (!(await exists(directory))) {
|
|
@@ -32,11 +34,20 @@ export async function writeIfDifferent(filePath: string, newData: string) {
|
|
|
32
34
|
// Compare the existing data with the new data
|
|
33
35
|
if (existingData === newData) {
|
|
34
36
|
// console.log('File contents are identical. No write needed.');
|
|
35
|
-
return;
|
|
37
|
+
return false;
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
// Write the new data if it's different or the file doesn't exist
|
|
40
42
|
await writeFile(filePath, newData, 'utf8');
|
|
41
43
|
console.log(chalk.green('Writing to'), filePath);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @returns the json object packageJson or undefined if it doesnt exist
|
|
49
|
+
*/
|
|
50
|
+
export async function readPackageJson(filePath: string): Promise<PackageJson | undefined> {
|
|
51
|
+
if (!(await exists(filePath))) return undefined;
|
|
52
|
+
return JSON.parse(await readFile(filePath, { encoding: 'utf-8' })) as PackageJson;
|
|
42
53
|
}
|
|
File without changes
|