wirejs-deploy-amplify-basic 0.0.15-alpha → 0.0.17-alpha

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.
@@ -1,6 +1,8 @@
1
1
  import { env } from 'process';
2
2
  import { LambdaFunctionURLHandler, APIGatewayProxyEventV2 } from 'aws-lambda';
3
3
  import { CookieJar, Context, requiresContext } from 'wirejs-resources';
4
+
5
+ // @ts-ignore
4
6
  import * as api from '../../../api/index';
5
7
 
6
8
  function createContext(event: APIGatewayProxyEventV2) {
@@ -3,6 +3,6 @@
3
3
  "dependencies": {
4
4
  "jsdom": "^25.0.0",
5
5
  "wirejs-dom": "^1.0.34",
6
- "wirejs-resources": "^0.1.6-alpha"
6
+ "wirejs-resources": "^0.1.8-alpha"
7
7
  }
8
8
  }
package/build.js CHANGED
@@ -12,9 +12,6 @@ const CWD = process.cwd();
12
12
  const __filename = import.meta.url.replace(/^file:/, '');
13
13
  const SELF_DIR = path.dirname(__filename);
14
14
  const TEMP_DIR = path.join(SELF_DIR, 'temp');
15
- const RESOURCE_OVERRIDES_BUILD = path.join(
16
- TEMP_DIR, 'wirejs-resource-overrides.build.js'
17
- );
18
15
  const PROJECT_API_DIR = path.join(CWD, 'api');
19
16
  const PROJECT_DIST_DIR = path.join(CWD, 'dist');
20
17
  const BACKEND_DIR = path.join(CWD, 'amplify');
@@ -64,7 +61,7 @@ async function installDeps() {
64
61
  'esbuild': '^0.24.2',
65
62
  'tsx': '^4.19.2',
66
63
  'typescript': '^5.7.3',
67
- '@aws-sdk/client-s3': "^3.735.0",
64
+ 'wirejs-resources': `file:${SELF_DIR}`
68
65
  }
69
66
  };
70
67
  await fs.promises.writeFile(
@@ -89,7 +86,7 @@ async function buildApiBundle() {
89
86
  // looks like cruft at the moment, but we'll see ...
90
87
  // await import(path.join(PROJECT_API_DIR, 'index.js'));
91
88
 
92
- const outputPath = path.join(PROJECT_DIST_DIR, 'api', 'dist', 'index.js');
89
+ const outputPath = path.join(BACKEND_DIR, 'api.js');
93
90
 
94
91
  // intermediate build of the resource overrides. this includes any deps we have
95
92
  // on the original `wirejs-resources` into the intermediate bundle. doing this
@@ -102,6 +99,7 @@ async function buildApiBundle() {
102
99
  outfile: RESOURCE_OVERRIDES_BUILD,
103
100
  platform: 'node',
104
101
  format: 'esm',
102
+ external: ['@aws-sdk/client-s3']
105
103
  });
106
104
 
107
105
  // exploratory build. builds using our overrides, which will emit a manifest of
@@ -115,7 +113,8 @@ async function buildApiBundle() {
115
113
  format: 'esm',
116
114
  alias: {
117
115
  'wirejs-resources': RESOURCE_OVERRIDES_BUILD
118
- }
116
+ },
117
+ external: ['@aws-sdk/client-s3']
119
118
  });
120
119
 
121
120
  // exploratory import. not strictly necessary until we're actually using the manifest
@@ -148,7 +147,8 @@ if (action === 'prebuild') {
148
147
  console.log("starting prebuild");
149
148
  await createSkeleton();
150
149
  await installDeps();
151
- await buildApiBundle();
150
+ // await buildApiBundle();
151
+
152
152
  console.log("prebuild done");
153
153
  } else if (action === 'inject-backend') {
154
154
  console.log("starting inject-backend");
@@ -0,0 +1,14 @@
1
+ import { Resource } from 'wirejs-resources';
2
+ export { AuthenticationService, withContext, requiresContext, Context, CookieJar, Resource, overrides, } from 'wirejs-resources';
3
+ export declare class FileService extends Resource {
4
+ constructor(scope: Resource | string, id: string);
5
+ read(filename: string, encoding?: BufferEncoding): Promise<string>;
6
+ write(filename: string, data: string, { onlyIfNotExists }?: {
7
+ onlyIfNotExists?: boolean | undefined;
8
+ }): Promise<void>;
9
+ delete(filename: string): Promise<void>;
10
+ list({ prefix }?: {
11
+ prefix?: string | undefined;
12
+ }): AsyncGenerator<string | undefined, void, unknown>;
13
+ isAlreadyExistsError(error: any): boolean;
14
+ }
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ import { env } from 'process';
2
+ import { S3Client, ListObjectsCommand, PutObjectCommand, GetObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3';
3
+ import { overrides, Resource, } from 'wirejs-resources';
4
+ export { AuthenticationService, withContext, requiresContext, Context, CookieJar, Resource, overrides, } from 'wirejs-resources';
5
+ const Bucket = env['BUCKET'];
6
+ const s3 = new S3Client();
7
+ export class FileService extends Resource {
8
+ constructor(scope, id) {
9
+ super(scope, id);
10
+ addResource('FileService', { absoluteId: this.absoluteId });
11
+ }
12
+ async read(filename, encoding = 'utf8') {
13
+ const Key = `${this.absoluteId}/${filename}`;
14
+ const command = new GetObjectCommand({ Bucket, Key });
15
+ const result = await s3.send(command);
16
+ return result.Body.transformToString(encoding);
17
+ }
18
+ async write(filename, data, { onlyIfNotExists = false } = {}) {
19
+ const Key = `${this.absoluteId}/${filename}`;
20
+ const Body = data;
21
+ const commandDetails = {
22
+ Bucket, Key, Body
23
+ };
24
+ if (onlyIfNotExists) {
25
+ commandDetails['IfNoneMatch'] = '*';
26
+ }
27
+ const command = new PutObjectCommand(commandDetails);
28
+ await s3.send(command);
29
+ }
30
+ async delete(filename) {
31
+ const Key = `${this.absoluteId}/${filename}`;
32
+ const command = new DeleteObjectCommand({
33
+ Bucket,
34
+ Key
35
+ });
36
+ await s3.send(command);
37
+ }
38
+ async *list({ prefix = '' } = {}) {
39
+ const Prefix = `${this.absoluteId}/${prefix}`;
40
+ let Marker = undefined;
41
+ while (true) {
42
+ const command = new ListObjectsCommand({
43
+ Bucket,
44
+ Prefix,
45
+ MaxKeys: 1000,
46
+ Marker
47
+ });
48
+ const result = await s3.send(command);
49
+ Marker = result.Marker;
50
+ for (const o of result.Contents || []) {
51
+ yield o.Key;
52
+ }
53
+ if (!Marker)
54
+ break;
55
+ }
56
+ }
57
+ isAlreadyExistsError(error) {
58
+ // https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
59
+ return error?.$metadata?.httpStatusCode === 412;
60
+ }
61
+ }
62
+ // expose resources to other resources that might depend on it.
63
+ overrides.FileService = FileService;
64
+ globalThis.wirejsResources = [];
65
+ function addResource(type, options) {
66
+ globalThis.wirejsResources.push({
67
+ type,
68
+ options
69
+ });
70
+ }
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.0.15-alpha",
3
+ "version": "0.0.17-alpha",
4
4
  "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
5
7
  "bin": {
6
- "wirejs-deploy-amplify-basic": "./build.js"
8
+ "wirejs-deploy-amplify-basic": "build.js"
7
9
  },
8
10
  "dependencies": {
9
11
  "@aws-sdk/client-s3": "^3.738.0",
@@ -16,6 +18,17 @@
16
18
  "wirejs-resources": "^0.1.8-alpha"
17
19
  },
18
20
  "devDependencies": {
19
- "@aws-amplify/backend": "^1.14.0"
20
- }
21
+ "@aws-amplify/backend": "^1.14.0",
22
+ "typescript": "^5.7.3"
23
+ },
24
+ "scripts": {
25
+ "build": "tsc"
26
+ },
27
+ "files": [
28
+ "amplify-backend-assets/*",
29
+ "amplify-hosting-assets/*",
30
+ "dist/*",
31
+ "build.js",
32
+ "package.json"
33
+ ]
21
34
  }