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.
Files changed (118) hide show
  1. package/dist/browser.d.ts +1 -0
  2. package/dist/browser.d.ts.map +1 -1
  3. package/dist/browser.js +1 -0
  4. package/dist/cognito/client.d.ts +6 -0
  5. package/dist/cognito/client.d.ts.map +1 -0
  6. package/dist/cognito/client.js +10 -0
  7. package/dist/cognito/errors.d.ts +95 -0
  8. package/dist/cognito/errors.d.ts.map +1 -0
  9. package/dist/cognito/errors.js +128 -0
  10. package/dist/cognito/index.d.ts +5 -0
  11. package/dist/cognito/index.d.ts.map +1 -0
  12. package/dist/cognito/index.js +4 -0
  13. package/dist/cognito/password.d.ts +53 -0
  14. package/dist/cognito/password.d.ts.map +1 -0
  15. package/dist/cognito/password.js +161 -0
  16. package/dist/cognito/user.d.ts +14 -0
  17. package/dist/cognito/user.d.ts.map +1 -0
  18. package/dist/cognito/user.js +34 -0
  19. package/dist/dynamo/errors.d.ts +9 -0
  20. package/dist/dynamo/errors.d.ts.map +1 -0
  21. package/dist/dynamo/errors.js +7 -0
  22. package/dist/dynamo/index.d.ts +2 -0
  23. package/dist/dynamo/index.d.ts.map +1 -0
  24. package/dist/dynamo/index.js +1 -0
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +6 -0
  28. package/dist/lambda/authentication.d.ts +2 -0
  29. package/dist/lambda/authentication.d.ts.map +1 -0
  30. package/dist/lambda/authentication.js +1 -0
  31. package/dist/lambda/client-types.d.ts +19 -19
  32. package/dist/lambda/client-types.d.ts.map +1 -1
  33. package/dist/lambda/client-types.js +9 -1
  34. package/dist/lambda/client.d.ts.map +1 -1
  35. package/dist/lambda/client.js +7 -2
  36. package/dist/lambda/errors.d.ts +19 -19
  37. package/dist/lambda/errors.d.ts.map +1 -1
  38. package/dist/lambda/errors.js +12 -12
  39. package/dist/lambda/handlerUtils.d.ts +8 -3
  40. package/dist/lambda/handlerUtils.d.ts.map +1 -1
  41. package/dist/lambda/handlerUtils.js +3 -2
  42. package/dist/lambda/index.d.ts +1 -0
  43. package/dist/lambda/index.d.ts.map +1 -1
  44. package/dist/lambda/index.js +2 -0
  45. package/dist/lambda/response.d.ts +48 -95
  46. package/dist/lambda/response.d.ts.map +1 -1
  47. package/dist/lambda/response.js +42 -18
  48. package/dist/lambda/server/authentication.d.ts +10 -0
  49. package/dist/lambda/server/authentication.d.ts.map +1 -0
  50. package/dist/lambda/server/authentication.js +24 -0
  51. package/dist/s3/client.d.ts +6 -0
  52. package/dist/s3/client.d.ts.map +1 -0
  53. package/dist/s3/client.js +7 -0
  54. package/dist/s3/errors.d.ts +7 -0
  55. package/dist/s3/errors.d.ts.map +1 -0
  56. package/dist/s3/errors.js +6 -0
  57. package/dist/s3/index.d.ts +5 -0
  58. package/dist/s3/index.d.ts.map +1 -0
  59. package/dist/s3/index.js +4 -0
  60. package/dist/s3/object.d.ts +17 -0
  61. package/dist/s3/object.d.ts.map +1 -0
  62. package/dist/s3/object.js +32 -0
  63. package/dist/s3/signedUrl.d.ts +3 -0
  64. package/dist/s3/signedUrl.d.ts.map +1 -0
  65. package/dist/s3/signedUrl.js +3 -0
  66. package/dist/scripts/clean.js +30 -59
  67. package/dist/scripts/ts-alias.d.ts +3 -0
  68. package/dist/scripts/ts-alias.d.ts.map +1 -0
  69. package/dist/scripts/ts-alias.js +167 -0
  70. package/dist/ses/errors.d.ts +4 -0
  71. package/dist/ses/errors.d.ts.map +1 -0
  72. package/dist/ses/errors.js +3 -0
  73. package/dist/ses/index.d.ts +2 -0
  74. package/dist/ses/index.d.ts.map +1 -0
  75. package/dist/ses/index.js +1 -0
  76. package/dist/ts-alias.js +0 -0
  77. package/dist/types/deep.d.ts +24 -0
  78. package/dist/types/deep.d.ts.map +1 -0
  79. package/dist/types/deep.js +1 -0
  80. package/dist/types/index.d.ts +3 -0
  81. package/dist/types/index.d.ts.map +1 -0
  82. package/dist/types/index.js +2 -0
  83. package/dist/types/safe.d.ts +2 -0
  84. package/dist/types/safe.d.ts.map +1 -0
  85. package/dist/types/safe.js +1 -0
  86. package/dist/utils/fs.d.ts +7 -1
  87. package/dist/utils/fs.d.ts.map +1 -1
  88. package/dist/utils/fs.js +11 -1
  89. package/package.json +32 -22
  90. package/src/browser.ts +3 -1
  91. package/src/cognito/client.ts +11 -0
  92. package/src/cognito/errors.ts +175 -0
  93. package/src/cognito/index.ts +5 -0
  94. package/src/cognito/password.ts +233 -0
  95. package/src/cognito/user.ts +46 -0
  96. package/src/dynamo/errors.ts +11 -0
  97. package/src/dynamo/index.ts +1 -0
  98. package/src/index.ts +8 -0
  99. package/src/lambda/client-types.ts +55 -29
  100. package/src/lambda/client.ts +7 -2
  101. package/src/lambda/errors.ts +25 -25
  102. package/src/lambda/handlerUtils.ts +30 -25
  103. package/src/lambda/index.ts +3 -0
  104. package/src/lambda/response.ts +90 -26
  105. package/src/lambda/server/authentication.ts +32 -0
  106. package/src/s3/client.ts +8 -0
  107. package/src/s3/errors.ts +6 -0
  108. package/src/s3/index.ts +6 -0
  109. package/src/s3/object.ts +37 -0
  110. package/src/s3/signedUrl.ts +4 -0
  111. package/src/scripts/clean.ts +34 -68
  112. package/src/ses/errors.ts +3 -0
  113. package/src/ses/index.ts +1 -0
  114. package/src/types/deep.ts +43 -0
  115. package/src/types/index.ts +2 -0
  116. package/src/types/safe.ts +1 -0
  117. package/src/utils/fs.ts +13 -2
  118. /package/src/{ts-alias.ts → scripts/ts-alias.ts} +0 -0
@@ -1,75 +1,41 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import * as fs from 'fs';
4
- import * as path from 'path';
5
-
6
- interface Args {
7
- dirExcludes: string[];
8
- dirIncludes: string[];
9
- }
10
-
11
- function parseArgs(): Args {
12
- const args = process.argv.slice(2);
13
- const dirExcludes: string[] = [];
14
- const dirIncludes: string[] = [];
15
- for (let i = 0; i < args.length; i++) {
16
- if (args[i] === '--dir-excludes' && args[i + 1]) {
17
- dirExcludes.push(args[i + 1]);
18
- i++;
19
- } else if (args[i] === '--dir-includes' && args[i + 1]) {
20
- dirIncludes.push(args[i + 1]);
21
- i++;
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 args = parseArgs();
75
- clean(process.cwd(), args);
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
+ }
@@ -0,0 +1,3 @@
1
+ export const error_ses = {
2
+ type: 'ses' as const
3
+ };
@@ -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,2 @@
1
+ export * from './deep.js';
2
+ export * from './safe.js';
@@ -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