ts-ag 0.0.1-dev.2 → 1.0.0

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 (122) 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/browser.d.ts +2 -0
  32. package/dist/lambda/browser.d.ts.map +1 -1
  33. package/dist/lambda/browser.js +2 -0
  34. package/dist/lambda/client-types.d.ts +19 -19
  35. package/dist/lambda/client-types.d.ts.map +1 -1
  36. package/dist/lambda/client-types.js +9 -1
  37. package/dist/lambda/client.d.ts.map +1 -1
  38. package/dist/lambda/client.js +7 -2
  39. package/dist/lambda/errors.d.ts +19 -19
  40. package/dist/lambda/errors.d.ts.map +1 -1
  41. package/dist/lambda/errors.js +12 -12
  42. package/dist/lambda/handlerUtils.d.ts +8 -3
  43. package/dist/lambda/handlerUtils.d.ts.map +1 -1
  44. package/dist/lambda/handlerUtils.js +3 -2
  45. package/dist/lambda/index.d.ts +1 -0
  46. package/dist/lambda/index.d.ts.map +1 -1
  47. package/dist/lambda/index.js +2 -0
  48. package/dist/lambda/response.d.ts +48 -95
  49. package/dist/lambda/response.d.ts.map +1 -1
  50. package/dist/lambda/response.js +42 -18
  51. package/dist/lambda/server/authentication.d.ts +10 -0
  52. package/dist/lambda/server/authentication.d.ts.map +1 -0
  53. package/dist/lambda/server/authentication.js +24 -0
  54. package/dist/s3/client.d.ts +6 -0
  55. package/dist/s3/client.d.ts.map +1 -0
  56. package/dist/s3/client.js +7 -0
  57. package/dist/s3/errors.d.ts +7 -0
  58. package/dist/s3/errors.d.ts.map +1 -0
  59. package/dist/s3/errors.js +6 -0
  60. package/dist/s3/index.d.ts +5 -0
  61. package/dist/s3/index.d.ts.map +1 -0
  62. package/dist/s3/index.js +4 -0
  63. package/dist/s3/object.d.ts +17 -0
  64. package/dist/s3/object.d.ts.map +1 -0
  65. package/dist/s3/object.js +32 -0
  66. package/dist/s3/signedUrl.d.ts +3 -0
  67. package/dist/s3/signedUrl.d.ts.map +1 -0
  68. package/dist/s3/signedUrl.js +3 -0
  69. package/dist/scripts/clean.js +30 -59
  70. package/dist/scripts/ts-alias.d.ts +3 -0
  71. package/dist/scripts/ts-alias.d.ts.map +1 -0
  72. package/dist/scripts/ts-alias.js +167 -0
  73. package/dist/ses/errors.d.ts +4 -0
  74. package/dist/ses/errors.d.ts.map +1 -0
  75. package/dist/ses/errors.js +3 -0
  76. package/dist/ses/index.d.ts +2 -0
  77. package/dist/ses/index.d.ts.map +1 -0
  78. package/dist/ses/index.js +1 -0
  79. package/dist/ts-alias.js +0 -0
  80. package/dist/types/deep.d.ts +24 -0
  81. package/dist/types/deep.d.ts.map +1 -0
  82. package/dist/types/deep.js +1 -0
  83. package/dist/types/index.d.ts +3 -0
  84. package/dist/types/index.d.ts.map +1 -0
  85. package/dist/types/index.js +2 -0
  86. package/dist/types/safe.d.ts +2 -0
  87. package/dist/types/safe.d.ts.map +1 -0
  88. package/dist/types/safe.js +1 -0
  89. package/dist/utils/fs.d.ts +2 -1
  90. package/dist/utils/fs.d.ts.map +1 -1
  91. package/dist/utils/fs.js +3 -1
  92. package/package.json +31 -22
  93. package/src/browser.ts +3 -1
  94. package/src/cognito/client.ts +11 -0
  95. package/src/cognito/errors.ts +175 -0
  96. package/src/cognito/index.ts +5 -0
  97. package/src/cognito/password.ts +233 -0
  98. package/src/cognito/user.ts +46 -0
  99. package/src/dynamo/errors.ts +11 -0
  100. package/src/dynamo/index.ts +1 -0
  101. package/src/index.ts +8 -0
  102. package/src/lambda/browser.ts +2 -0
  103. package/src/lambda/client-types.ts +55 -29
  104. package/src/lambda/client.ts +7 -2
  105. package/src/lambda/errors.ts +25 -25
  106. package/src/lambda/handlerUtils.ts +30 -25
  107. package/src/lambda/index.ts +3 -0
  108. package/src/lambda/response.ts +90 -26
  109. package/src/lambda/server/authentication.ts +32 -0
  110. package/src/s3/client.ts +8 -0
  111. package/src/s3/errors.ts +6 -0
  112. package/src/s3/index.ts +6 -0
  113. package/src/s3/object.ts +37 -0
  114. package/src/s3/signedUrl.ts +4 -0
  115. package/src/scripts/clean.ts +34 -68
  116. package/src/ses/errors.ts +3 -0
  117. package/src/ses/index.ts +1 -0
  118. package/src/types/deep.ts +43 -0
  119. package/src/types/index.ts +2 -0
  120. package/src/types/safe.ts +1 -0
  121. package/src/utils/fs.ts +4 -2
  122. /package/src/{ts-alias.ts → scripts/ts-alias.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { badRequestError } from './errors.js';
1
+ import { error_lambda_badRequest } from './errors.js';
2
2
  function field(obj) {
3
3
  return obj.fieldName === undefined || obj.fieldValue === undefined
4
4
  ? {}
@@ -9,52 +9,59 @@ function field(obj) {
9
9
  }
10
10
  };
11
11
  }
12
- /**
13
- * Takes a lambda error and gives an error response suitable to be returned from the lambda handler
14
- */
15
- export function errorResponse(e, headers) {
12
+ export function response_error(e, headers, type = '', extras = {}) {
16
13
  switch (e.type) {
17
- case 'BadRequest':
14
+ case 'lambda_badRequest':
18
15
  return {
19
16
  headers,
20
17
  statusCode: 400,
21
18
  body: {
22
19
  message: e.message,
23
- ...field(e)
20
+ type: type,
21
+ ...field(e),
22
+ ...extras
24
23
  }
25
24
  };
26
- case 'Unauthorized':
25
+ case 'lambda_unauthorized':
27
26
  return {
28
27
  headers,
29
28
  statusCode: 401,
30
29
  body: {
31
- message: e.message
30
+ message: e.message,
31
+ type: type,
32
+ ...extras
32
33
  }
33
34
  };
34
- case 'Forbidden':
35
+ case 'lambda_forbidden':
35
36
  return {
36
37
  headers,
37
38
  statusCode: 403,
38
39
  body: {
39
- message: e.message
40
+ message: e.message,
41
+ type: type,
42
+ ...extras
40
43
  }
41
44
  };
42
- case 'NotFound':
45
+ case 'lambda_notFound':
43
46
  return {
44
47
  headers,
45
48
  statusCode: 404,
46
49
  body: {
47
50
  message: e.message,
48
- ...field(e)
51
+ type: type,
52
+ ...field(e),
53
+ ...extras
49
54
  }
50
55
  };
51
- case 'Conflict':
56
+ case 'lambda_conflict':
52
57
  return {
53
58
  headers,
54
59
  statusCode: 409,
55
60
  body: {
56
61
  message: e.message,
57
- ...field(e)
62
+ type: type,
63
+ ...field(e),
64
+ ...extras
58
65
  }
59
66
  };
60
67
  default:
@@ -62,15 +69,32 @@ export function errorResponse(e, headers) {
62
69
  headers,
63
70
  statusCode: 500,
64
71
  body: {
65
- message: 'Unknown error'
72
+ message: 'Unknown error',
73
+ type: type,
74
+ ...extras
66
75
  }
67
76
  };
68
77
  }
69
78
  }
70
79
  /**
71
80
  * Helper function to get a reasonable default error response from a valibot parse result
81
+ * @param res - The output from calling safeParse on the input
82
+ * @param headers - The headers to return in the response
72
83
  */
73
- export function valibotErrorResponse(res, headers) {
84
+ export function response_valibotError(res, headers) {
74
85
  const issue = res.issues[0];
75
- return errorResponse(badRequestError('Invalid parameters', issue.path[0].key, issue.message), headers);
86
+ if (issue.path && issue.path[0] && typeof issue.path[0].key === 'string') {
87
+ return response_error(error_lambda_badRequest('Invalid input', issue.path[0].key, issue.message), headers);
88
+ }
89
+ else {
90
+ return response_error(error_lambda_badRequest(`Invalid input: ${issue.message}`), headers);
91
+ }
92
+ }
93
+ export function response_ok(body, headers, cookies) {
94
+ return {
95
+ headers,
96
+ cookies,
97
+ statusCode: 200,
98
+ body
99
+ };
76
100
  }
@@ -0,0 +1,10 @@
1
+ import type { APIGatewayProxyEventV2WithLambdaAuthorizer, APIGatewayRequestAuthorizerEventV2 } from 'aws-lambda';
2
+ import { Result } from 'neverthrow';
3
+ /**
4
+ * Wraps cookies parse along with the api gateway event with neverthrow
5
+ */
6
+ export declare const getCookies: (event: APIGatewayProxyEventV2WithLambdaAuthorizer<any> | APIGatewayRequestAuthorizerEventV2) => Result<Record<string, string | undefined>, {
7
+ type: "lambda_unauthorized";
8
+ message: string;
9
+ }>;
10
+ //# sourceMappingURL=authentication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../../src/lambda/server/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0CAA0C,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAC;AACjH,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAIpC;;GAEG;AACH,eAAO,MAAM,UAAU;;;EAuBtB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { Result } from 'neverthrow';
2
+ import { parse } from 'cookie';
3
+ import { error_lambda_unauthorized } from '../errors.js';
4
+ /**
5
+ * Wraps cookies parse along with the api gateway event with neverthrow
6
+ */
7
+ export const getCookies = Result.fromThrowable((event) => {
8
+ if (!('headers' in event) || !event.headers) {
9
+ throw new Error('No headers in event');
10
+ }
11
+ // First try to get cookies from the cookies array (API Gateway v2 format)
12
+ const cookieString = Array.isArray(event.cookies) && event.cookies.length > 0
13
+ ? event.cookies.join('; ')
14
+ : event.headers.Cookie || event.headers.cookie;
15
+ if (!cookieString) {
16
+ throw new Error('No cookies found in event');
17
+ }
18
+ const res = parse(cookieString);
19
+ return res;
20
+ }, (e) => {
21
+ if (e instanceof Error)
22
+ return error_lambda_unauthorized(e.message);
23
+ return error_lambda_unauthorized('Invalid Cookies');
24
+ });
@@ -0,0 +1,6 @@
1
+ import { S3Client } from '@aws-sdk/client-s3';
2
+ /**
3
+ * Convenience function for S3Client when process.env.REGION is set
4
+ */
5
+ export declare function getS3(): S3Client;
6
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/s3/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;GAEG;AACH,wBAAgB,KAAK,aAEpB"}
@@ -0,0 +1,7 @@
1
+ import { S3Client } from '@aws-sdk/client-s3';
2
+ /**
3
+ * Convenience function for S3Client when process.env.REGION is set
4
+ */
5
+ export function getS3() {
6
+ return new S3Client({ endpoint: `https://s3.${process.env.REGION}.amazonaws.com`, region: process.env.REGION });
7
+ }
@@ -0,0 +1,7 @@
1
+ export declare const error_s3_internal: {
2
+ type: "s3_internal";
3
+ };
4
+ export declare const error_s3_get: {
5
+ type: "s3_get";
6
+ };
7
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/s3/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;CAE7B,CAAC;AACF,eAAO,MAAM,YAAY;;CAExB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export const error_s3_internal = {
2
+ type: 's3_internal'
3
+ };
4
+ export const error_s3_get = {
5
+ type: 's3_get'
6
+ };
@@ -0,0 +1,5 @@
1
+ export * from './client.js';
2
+ export * from './errors.js';
3
+ export * from './signedUrl.js';
4
+ export * from './object.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/s3/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAE5B,cAAc,aAAa,CAAC;AAE5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './client.js';
2
+ export * from './errors.js';
3
+ export * from './signedUrl.js';
4
+ export * from './object.js';
@@ -0,0 +1,17 @@
1
+ import { ResultAsync } from 'neverthrow';
2
+ import { error_s3_get } from './errors.js';
3
+ /**
4
+ * Retrieves an object from an S3 bucket.
5
+ *
6
+ * @param {string} bucketName - The name of the S3 bucket.
7
+ * @param {string} key - The key of the object to retrieve.
8
+ * @returns {Promise<Buffer>} A promise that resolves to the object data as a Buffer.
9
+ */
10
+ export declare const getObject: (bucketName: string, key: string) => ResultAsync<Buffer<ArrayBufferLike>, {
11
+ type: "s3_get";
12
+ }>;
13
+ /**
14
+ * Convenience function to get an object from S3 and return it as a string.
15
+ */
16
+ export declare function getObjectString(bucketName: string, key: string): ResultAsync<string, typeof error_s3_get>;
17
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/s3/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS;;EAiBrB,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,YAAY,CAAC,CAEzG"}
@@ -0,0 +1,32 @@
1
+ import { ResultAsync } from 'neverthrow';
2
+ import { getS3 } from './client.js';
3
+ import { GetObjectCommand } from '@aws-sdk/client-s3';
4
+ import { error_s3_get } from './errors.js';
5
+ /**
6
+ * Retrieves an object from an S3 bucket.
7
+ *
8
+ * @param {string} bucketName - The name of the S3 bucket.
9
+ * @param {string} key - The key of the object to retrieve.
10
+ * @returns {Promise<Buffer>} A promise that resolves to the object data as a Buffer.
11
+ */
12
+ export const getObject = ResultAsync.fromThrowable(async (bucketName, key) => {
13
+ const s3 = getS3();
14
+ const cmd = new GetObjectCommand({ Bucket: bucketName, Key: key });
15
+ const res = await s3.send(cmd);
16
+ const stream = res.Body;
17
+ return new Promise((resolve, reject) => {
18
+ const chunks = [];
19
+ stream.on('data', (chunk) => chunks.push(chunk));
20
+ stream.on('end', () => resolve(Buffer.concat(chunks)));
21
+ stream.on('error', reject);
22
+ });
23
+ }, (e) => {
24
+ console.error(`Error getting object from S3: ${e}`);
25
+ return error_s3_get;
26
+ });
27
+ /**
28
+ * Convenience function to get an object from S3 and return it as a string.
29
+ */
30
+ export function getObjectString(bucketName, key) {
31
+ return getObject(bucketName, key).map((buffer) => buffer.toString('utf-8'));
32
+ }
@@ -0,0 +1,3 @@
1
+ import { ResultAsync } from 'neverthrow';
2
+ export declare const getSignedUrl: <InputTypesUnion extends object, InputType extends InputTypesUnion, OutputType extends import("@smithy/types").MetadataBearer = import("@smithy/types").MetadataBearer>(client: import("@aws-sdk/client-cognito-identity-provider").__Client<any, InputTypesUnion, import("@smithy/types").MetadataBearer, any>, command: import("@aws-sdk/client-cognito-identity-provider").$Command<InputType, OutputType, any, InputTypesUnion, import("@smithy/types").MetadataBearer>, options?: import("@smithy/types").RequestPresigningArguments | undefined) => ResultAsync<string, unknown>;
3
+ //# sourceMappingURL=signedUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signedUrl.d.ts","sourceRoot":"","sources":["../../src/s3/signedUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,eAAO,MAAM,YAAY,wjBAAwD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ResultAsync } from 'neverthrow';
2
+ import { getSignedUrl as baseGetSignedUrl } from '@aws-sdk/s3-request-presigner';
3
+ export const getSignedUrl = ResultAsync.fromThrowable(baseGetSignedUrl, (e) => e);
@@ -1,64 +1,35 @@
1
1
  #!/usr/bin/env node
2
- import * as fs from 'fs';
3
- import * as path from 'path';
4
- function parseArgs() {
5
- const args = process.argv.slice(2);
6
- const dirExcludes = [];
7
- const dirIncludes = [];
8
- for (let i = 0; i < args.length; i++) {
9
- if (args[i] === '--dir-excludes' && args[i + 1]) {
10
- dirExcludes.push(args[i + 1]);
11
- i++;
12
- }
13
- else if (args[i] === '--dir-includes' && args[i + 1]) {
14
- dirIncludes.push(args[i + 1]);
15
- i++;
16
- }
17
- }
18
- return { dirExcludes, dirIncludes };
19
- }
20
- function shouldExclude(dir, excludes) {
21
- return excludes.some((ex) => path.basename(dir) === ex);
22
- }
23
- function shouldInclude(dir, includes) {
24
- if (includes.length === 0)
25
- return true;
26
- return includes.some((inc) => dir.includes(inc));
27
- }
28
- function removeDir(targetPath) {
29
- if (fs.existsSync(targetPath)) {
30
- fs.rmSync(targetPath, { recursive: true, force: true });
31
- console.log(`Removed: ${targetPath}`);
32
- }
33
- }
34
- function clean(root, args) {
35
- const entries = fs.readdirSync(root, { withFileTypes: true });
36
- for (const entry of entries) {
37
- const fullPath = path.join(root, entry.name);
38
- if (entry.isDirectory()) {
39
- if (entry.name === 'node_modules')
40
- continue;
41
- if (entry.name === 'dist') {
42
- const distParentDir = path.dirname(fullPath);
43
- const siblingDirs = fs
44
- .readdirSync(distParentDir, { withFileTypes: true })
45
- .filter((d) => d.isDirectory())
46
- .map((d) => d.name);
47
- const shouldExcludeSibling = args.dirExcludes.some((ex) => siblingDirs.includes(ex));
48
- const shouldIncludeSibling = args.dirIncludes.length === 0 || args.dirIncludes.some((inc) => siblingDirs.includes(inc));
49
- if (!shouldExcludeSibling && shouldIncludeSibling) {
50
- removeDir(fullPath);
51
- }
52
- continue;
53
- }
54
- if (!shouldExclude(fullPath, args.dirExcludes)) {
55
- clean(fullPath, args);
2
+ import { rmSync } from 'fs';
3
+ import { resolve, dirname, join } from 'path';
4
+ import { parse } from 'tsconfck';
5
+ async function listReferences(tsconfigPath, visited = new Set()) {
6
+ // console.log(`Processing: ${tsconfigPath}`);
7
+ tsconfigPath = resolve(tsconfigPath);
8
+ if (visited.has(tsconfigPath))
9
+ return;
10
+ visited.add(tsconfigPath);
11
+ const { tsconfig } = await parse(tsconfigPath);
12
+ const dir = dirname(tsconfigPath);
13
+ // console.log(`Found tsconfig: ${tsconfigPath}`, tsconfig);
14
+ if (tsconfig.references && Array.isArray(tsconfig.references)) {
15
+ for (const ref of tsconfig.references) {
16
+ if (typeof ref.path === 'string') {
17
+ const dirPath = ref.path.split('/').slice(0, -1).join('/');
18
+ const configFilename = ref.path.endsWith('.json') ? ref.path.split('/').pop() : 'tsconfig.json';
19
+ await listReferences(resolve(dir, dirPath, configFilename), visited);
56
20
  }
57
21
  }
58
- else if (entry.name === 'tsconfig.tsbuildinfo') {
59
- removeDir(fullPath);
60
- }
61
22
  }
62
23
  }
63
- const args = parseArgs();
64
- clean(process.cwd(), args);
24
+ const configs = new Set();
25
+ await listReferences(process.argv[2] || 'tsconfig.json', configs);
26
+ console.log('Referenced tsconfig files:');
27
+ for (const conf of configs) {
28
+ const dir = dirname(conf);
29
+ const configName = conf.split('/').pop()?.slice(0, -5) || 'tsconfig';
30
+ rmSync(join(dir, 'dist'), { recursive: true, force: true });
31
+ rmSync(join(dir, configName + '.tsbuildinfo'), { recursive: true, force: true });
32
+ console.log('Removed dist and tsbuildinfo for:', conf);
33
+ // console.log(' Dist: ', join(dir, 'dist'));
34
+ // console.log(' tsbuildinfo: ', join(dir, configName + '.tsbuildinfo'));
35
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=ts-alias.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-alias.d.ts","sourceRoot":"","sources":["../../src/scripts/ts-alias.ts"],"names":[],"mappings":""}
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env node
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+ import * as chokidar from 'chokidar';
5
+ import { replaceTscAliasPaths } from 'tsc-alias';
6
+ import { glob } from 'glob';
7
+ import console from 'console';
8
+ // Cache for tsconfig.json files
9
+ const tsconfigCache = new Map();
10
+ // Parse command-line arguments
11
+ const args = process.argv.slice(2);
12
+ const watchMode = args.includes('-w') || args.includes('--watch');
13
+ /**
14
+ * Find all dist folders in the project directory, excluding certain patterns.
15
+ */
16
+ async function findDistFolders(baseDir) {
17
+ const ignorePatterns = [
18
+ '**/node_modules/**',
19
+ '**/\\.git/**',
20
+ '**/\\.vscode/**',
21
+ '**/\\.idea/**',
22
+ '**/coverage/**',
23
+ '**/build/**',
24
+ '**/cdk.out/**'
25
+ ];
26
+ const distFolders = await glob('**/dist', {
27
+ cwd: baseDir,
28
+ ignore: ignorePatterns,
29
+ absolute: true
30
+ });
31
+ return distFolders;
32
+ }
33
+ /**
34
+ * Get the tsconfig.json file for a given dist folder.
35
+ * This function caches the tsconfig file to avoid reading it multiple times.
36
+ */
37
+ function getTsconfig(distFolder) {
38
+ const projectRoot = path.dirname(distFolder);
39
+ const tsconfigPath = path.join(projectRoot, 'tsconfig.json');
40
+ try {
41
+ const stats = fs.statSync(tsconfigPath);
42
+ const mtime = stats.mtimeMs;
43
+ // Check cache
44
+ const cached = tsconfigCache.get(tsconfigPath);
45
+ if (cached && cached.mtime === mtime) {
46
+ return cached.config;
47
+ }
48
+ // Read and cache the config
49
+ const config = JSON.parse(fs.readFileSync(tsconfigPath, 'utf8'));
50
+ tsconfigCache.set(tsconfigPath, { config, mtime });
51
+ return config;
52
+ }
53
+ catch (error) {
54
+ console.error(`Error reading tsconfig at ${tsconfigPath}:`, error);
55
+ return null;
56
+ }
57
+ }
58
+ /**
59
+ * Process the dist folder by replacing TypeScript alias paths with relative paths.
60
+ */
61
+ async function processDistFolder(distFolder) {
62
+ const projectRoot = path.dirname(distFolder);
63
+ const tsconfigPath = path.join(projectRoot, 'tsconfig.json');
64
+ if (!fs.existsSync(tsconfigPath)) {
65
+ console.warn(`No tsconfig.json found at ${tsconfigPath}`);
66
+ return;
67
+ }
68
+ const tsconfig = getTsconfig(distFolder);
69
+ if (!tsconfig) {
70
+ console.warn(`Invalid tsconfig.json found for ${distFolder}`);
71
+ return;
72
+ }
73
+ try {
74
+ await replaceTscAliasPaths({
75
+ configFile: tsconfigPath,
76
+ outDir: distFolder
77
+ });
78
+ console.log(`Successfully processed aliases in ${distFolder}`);
79
+ }
80
+ catch (error) {
81
+ console.error(`Error processing aliases in ${distFolder}:`, error);
82
+ }
83
+ }
84
+ /**
85
+ * Watch the dist folder for changes and process it when files are added or changed.
86
+ */
87
+ function watchDistFolder(distFolder) {
88
+ console.log(`Setting up watcher for: ${distFolder}`);
89
+ const watcher = chokidar.watch(distFolder, {
90
+ persistent: true,
91
+ ignoreInitial: true,
92
+ awaitWriteFinish: {
93
+ stabilityThreshold: 300,
94
+ pollInterval: 100
95
+ }
96
+ });
97
+ watcher.on('add', (filePath) => {
98
+ if (filePath.endsWith('.js') || filePath.endsWith('.jsx')) {
99
+ console.log(`File added: ${filePath}`);
100
+ processDistFolder(distFolder);
101
+ }
102
+ });
103
+ watcher.on('change', (filePath) => {
104
+ if (filePath.endsWith('.js') || filePath.endsWith('.jsx')) {
105
+ console.log(`File changed: ${filePath}`);
106
+ processDistFolder(distFolder);
107
+ }
108
+ });
109
+ return watcher;
110
+ }
111
+ // Main function
112
+ async function main() {
113
+ const baseDir = process.cwd();
114
+ console.log(`Searching for dist folders in: ${baseDir}`);
115
+ const distFolders = await findDistFolders(baseDir);
116
+ // Process all folders initially if any exist
117
+ if (distFolders.length > 0) {
118
+ console.log(`Found ${distFolders.length} dist folders:`);
119
+ distFolders.forEach((folder) => console.log(` - ${folder}`));
120
+ for (const folder of distFolders) {
121
+ await processDistFolder(folder);
122
+ }
123
+ }
124
+ else {
125
+ console.log('No dist folders found initially');
126
+ }
127
+ // Set up watchers if in watch mode
128
+ if (watchMode) {
129
+ console.log('Watch mode enabled, monitoring for changes...');
130
+ // Set up watchers for existing dist folders
131
+ distFolders.forEach(watchDistFolder);
132
+ // Watch for new dist folders being created
133
+ console.log('Watching for new dist folders...');
134
+ const dirWatcher = chokidar.watch(baseDir, {
135
+ persistent: true,
136
+ ignoreInitial: true,
137
+ depth: 5, // Adjust depth as needed for your project structure
138
+ ignored: [
139
+ '**/node_modules/**',
140
+ '**/\\.git/**',
141
+ '**/\\.vscode/**',
142
+ '**/\\.idea/**',
143
+ '**/coverage/**',
144
+ '**/build/**',
145
+ '**/cdk.out/**',
146
+ // Don't watch the contents of existing dist folders (they'll be watched separately)
147
+ ...distFolders.map((folder) => `${folder}/**`)
148
+ ]
149
+ });
150
+ // Handle directory creation events
151
+ dirWatcher.on('addDir', async (dirPath) => {
152
+ if (path.basename(dirPath) === 'dist') {
153
+ // Make sure it's not already being watched
154
+ if (!distFolders.includes(dirPath)) {
155
+ console.log(`New dist folder detected: ${dirPath}`);
156
+ distFolders.push(dirPath);
157
+ await processDistFolder(dirPath);
158
+ watchDistFolder(dirPath);
159
+ }
160
+ }
161
+ });
162
+ }
163
+ }
164
+ main().catch((error) => {
165
+ console.error('Error in ts-alias script:', error);
166
+ process.exit(1);
167
+ });
@@ -0,0 +1,4 @@
1
+ export declare const error_ses: {
2
+ type: "ses";
3
+ };
4
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/ses/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;CAErB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export const error_ses = {
2
+ type: 'ses'
3
+ };
@@ -0,0 +1,2 @@
1
+ export * from './errors.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ses/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './errors.js';
package/dist/ts-alias.js CHANGED
File without changes
@@ -0,0 +1,24 @@
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 ? R[K] extends infer RK ? RK extends Record<string, any> ? T[K] extends Record<string, any> ? DeepOverride<T[K], RK> : RK : RK extends Array<infer RU> ? T[K] extends Array<infer TU> ? Array<DeepOverride<TU, RU>> : RK : RK : never : T[K];
14
+ };
15
+ /**
16
+ *
17
+ */
18
+ export type DeepPartial<T> = {
19
+ [P in keyof T]?: T[P] extends object ? T[P] extends Function ? T[P] : DeepPartial<T[P]> : T[P];
20
+ };
21
+ export type DeepRequired<T> = {
22
+ [P in keyof T]-?: NonNullable<T[P] extends object ? (T[P] extends Function ? T[P] : DeepRequired<T[P]>) : T[P]>;
23
+ };
24
+ //# sourceMappingURL=deep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep.d.ts","sourceRoot":"","sources":["../../src/types/deep.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI;KAC9B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAC7B,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,EAAE,GACnB,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC9B,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GACtB,EAAE,GACJ,EAAE,SAAS,KAAK,CAAC,MAAM,EAAE,CAAC,GACxB,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,EAAE,CAAC,GAC1B,KAAK,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAC3B,EAAE,GACJ,EAAE,GACN,KAAK,GACP,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAEhC,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GACnB,CAAC,CAAC,CAAC,CAAC,GACJ,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACnB,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;KAE3B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;CAChH,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './deep.js';
2
+ export * from './safe.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './deep.js';
2
+ export * from './safe.js';
@@ -0,0 +1,2 @@
1
+ export type SafeOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
2
+ //# sourceMappingURL=safe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe.d.ts","sourceRoot":"","sources":["../../src/types/safe.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,CAAC,SAAS,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -4,6 +4,7 @@
4
4
  export declare function exists(filePath: string): Promise<boolean>;
5
5
  /**
6
6
  * Writes data to a filepath if it is different
7
+ * @returns true if the file is written to
7
8
  */
8
- export declare function writeIfDifferent(filePath: string, newData: string): Promise<void>;
9
+ export declare function writeIfDifferent(filePath: string, newData: string): Promise<boolean>;
9
10
  //# sourceMappingURL=fs.d.ts.map