@aws-blocks/create-block 0.2.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.
- package/LICENSE +174 -0
- package/dist/index.js +789 -0
- package/dist/index.test.js +247 -0
- package/package.json +37 -0
- package/templates/primitive/DESIGN.md +27 -0
- package/templates/primitive/LICENSE +174 -0
- package/templates/primitive/README.md +43 -0
- package/templates/primitive/api-extractor.json +4 -0
- package/templates/primitive/package.json +43 -0
- package/templates/primitive/src/errors.ts +12 -0
- package/templates/primitive/src/index.aws.ts +34 -0
- package/templates/primitive/src/index.browser.ts +12 -0
- package/templates/primitive/src/index.cdk.test.ts +47 -0
- package/templates/primitive/src/index.cdk.ts +34 -0
- package/templates/primitive/src/index.mock.ts +46 -0
- package/templates/primitive/src/index.test.ts +29 -0
- package/templates/primitive/src/parity.test.ts +16 -0
- package/templates/primitive/src/types.ts +13 -0
- package/templates/primitive/tsconfig.json +11 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import assert from 'node:assert';
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { describe, test } from 'node:test';
|
|
8
|
+
import { deriveNames, findCustomerWorkspaceRoot, findMonorepoRoot, insertBetweenMarkers, normalizeClassName, normalizeWorkspaces, parseArgs, run, scopeFromPkgName, substituteTokens, toKebabCase, validateClassName, validateScope, workspacesCover, } from './index.js';
|
|
9
|
+
describe('name validation', () => {
|
|
10
|
+
test('accepts PascalCase', () => {
|
|
11
|
+
assert.strictEqual(validateClassName('SearchIndex').ok, true);
|
|
12
|
+
assert.strictEqual(validateClassName('KVStore').ok, true);
|
|
13
|
+
});
|
|
14
|
+
test('rejects non-PascalCase', () => {
|
|
15
|
+
assert.strictEqual(validateClassName('searchIndex').ok, false);
|
|
16
|
+
assert.strictEqual(validateClassName('search-index').ok, false);
|
|
17
|
+
assert.strictEqual(validateClassName('').ok, false);
|
|
18
|
+
assert.strictEqual(validateClassName('9Lives').ok, false);
|
|
19
|
+
});
|
|
20
|
+
test('strips a leading BB prefix', () => {
|
|
21
|
+
assert.strictEqual(normalizeClassName('BBQueue'), 'Queue');
|
|
22
|
+
assert.strictEqual(normalizeClassName('bb-queue'), 'queue');
|
|
23
|
+
assert.strictEqual(normalizeClassName('SearchIndex'), 'SearchIndex');
|
|
24
|
+
});
|
|
25
|
+
test('does NOT mangle names that merely start with "Bb"', () => {
|
|
26
|
+
assert.strictEqual(normalizeClassName('BBox'), 'BBox');
|
|
27
|
+
assert.strictEqual(normalizeClassName('Bbox'), 'Bbox');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('scope validation', () => {
|
|
31
|
+
test('accepts valid npm scopes', () => {
|
|
32
|
+
assert.strictEqual(validateScope('acme').ok, true);
|
|
33
|
+
assert.strictEqual(validateScope('my-org').ok, true);
|
|
34
|
+
assert.strictEqual(validateScope('a1._-').ok, true);
|
|
35
|
+
});
|
|
36
|
+
test('rejects invalid scopes', () => {
|
|
37
|
+
assert.strictEqual(validateScope('Acme').ok, false); // uppercase
|
|
38
|
+
assert.strictEqual(validateScope('-bad').ok, false); // leading dash
|
|
39
|
+
assert.strictEqual(validateScope('has space').ok, false);
|
|
40
|
+
assert.strictEqual(validateScope('has"quote').ok, false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('kebab derivation', () => {
|
|
44
|
+
test('converts PascalCase to kebab-case', () => {
|
|
45
|
+
assert.strictEqual(toKebabCase('DemoStore'), 'demo-store');
|
|
46
|
+
assert.strictEqual(toKebabCase('SearchIndex'), 'search-index');
|
|
47
|
+
assert.strictEqual(toKebabCase('Queue'), 'queue');
|
|
48
|
+
});
|
|
49
|
+
test('handles acronyms', () => {
|
|
50
|
+
assert.strictEqual(toKebabCase('SQLCache'), 'sql-cache');
|
|
51
|
+
assert.strictEqual(toKebabCase('HTTPQueue'), 'http-queue');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('name derivation by mode', () => {
|
|
55
|
+
test('contributor uses @aws-blocks scope', () => {
|
|
56
|
+
const n = deriveNames('SearchIndex', 'contributor', 'ignored');
|
|
57
|
+
assert.strictEqual(n.folder, 'bb-search-index');
|
|
58
|
+
assert.strictEqual(n.pkgName, '@aws-blocks/bb-search-index');
|
|
59
|
+
});
|
|
60
|
+
test('external uses the given scope', () => {
|
|
61
|
+
const n = deriveNames('SearchIndex', 'external', 'acme');
|
|
62
|
+
assert.strictEqual(n.pkgName, '@acme/bb-search-index');
|
|
63
|
+
assert.strictEqual(n.folder, 'bb-search-index');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('token substitution', () => {
|
|
67
|
+
test('replaces both tokens everywhere', () => {
|
|
68
|
+
const out = substituteTokens('class __BB_CLASS__ {} // from __BB_PKG_NAME__ (__BB_CLASS__)', {
|
|
69
|
+
className: 'Foo',
|
|
70
|
+
pkgName: '@x/bb-foo',
|
|
71
|
+
});
|
|
72
|
+
assert.strictEqual(out, 'class Foo {} // from @x/bb-foo (Foo)');
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe('marker insertion', () => {
|
|
76
|
+
test('adds markers when absent and inserts the entry', () => {
|
|
77
|
+
const out = insertBetweenMarkers('export const x = 1;\n', "export { Foo } from '@x/bb-foo';");
|
|
78
|
+
assert.match(out, /BEGIN:generated-block-exports/);
|
|
79
|
+
assert.match(out, /END:generated-block-exports/);
|
|
80
|
+
assert.match(out, /export \{ Foo \} from '@x\/bb-foo';/);
|
|
81
|
+
});
|
|
82
|
+
test('is idempotent — inserting the same entry twice adds it once', () => {
|
|
83
|
+
const entry = "export { Foo } from '@x/bb-foo';";
|
|
84
|
+
const once = insertBetweenMarkers('x\n', entry);
|
|
85
|
+
const twice = insertBetweenMarkers(once, entry);
|
|
86
|
+
assert.strictEqual(once, twice);
|
|
87
|
+
assert.strictEqual(twice.match(/@x\/bb-foo/g)?.length, 1);
|
|
88
|
+
});
|
|
89
|
+
test('keeps existing entries when adding a new one', () => {
|
|
90
|
+
const a = insertBetweenMarkers('x\n', "export { A } from '@x/bb-a';");
|
|
91
|
+
const b = insertBetweenMarkers(a, "export { B } from '@x/bb-b';");
|
|
92
|
+
assert.match(b, /bb-a/);
|
|
93
|
+
assert.match(b, /bb-b/);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('arg parsing', () => {
|
|
97
|
+
test('parses positional + flags', () => {
|
|
98
|
+
const o = parseArgs(['MyBlock', '--scope', 'acme', '--yes', '--dir', './x']);
|
|
99
|
+
assert.strictEqual(o.className, 'MyBlock');
|
|
100
|
+
assert.strictEqual(o.scope, 'acme');
|
|
101
|
+
assert.strictEqual(o.yes, true);
|
|
102
|
+
assert.strictEqual(o.dir, './x');
|
|
103
|
+
});
|
|
104
|
+
test('rejects unknown flags and extra positionals', () => {
|
|
105
|
+
assert.throws(() => parseArgs(['--bogus']));
|
|
106
|
+
assert.throws(() => parseArgs(['A', 'B']));
|
|
107
|
+
});
|
|
108
|
+
test('rejects a value flag with no value or a flag as its value', () => {
|
|
109
|
+
assert.throws(() => parseArgs(['MyBlock', '--dir', '--yes']), /--dir requires a value/);
|
|
110
|
+
assert.throws(() => parseArgs(['MyBlock', '--scope']), /--scope requires a value/);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('mode detection', () => {
|
|
114
|
+
test('detects a monorepo root by workspaces + packages/blocks', async () => {
|
|
115
|
+
const dir = mkdtempSync(join(tmpdir(), 'cb-root-'));
|
|
116
|
+
try {
|
|
117
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ workspaces: ['packages/blocks'] }));
|
|
118
|
+
mkdirSync(join(dir, 'packages', 'blocks'), { recursive: true });
|
|
119
|
+
const nested = join(dir, 'packages', 'bb-foo', 'src');
|
|
120
|
+
mkdirSync(nested, { recursive: true });
|
|
121
|
+
assert.strictEqual(await findMonorepoRoot(nested), dir);
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
rmSync(dir, { recursive: true, force: true });
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
test('returns null outside a monorepo', async () => {
|
|
128
|
+
const dir = mkdtempSync(join(tmpdir(), 'cb-ext-'));
|
|
129
|
+
try {
|
|
130
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'random-app' }));
|
|
131
|
+
assert.strictEqual(await findMonorepoRoot(dir), null);
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
rmSync(dir, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('workspaces helpers', () => {
|
|
139
|
+
test('normalizeWorkspaces handles array, object, and missing forms', () => {
|
|
140
|
+
assert.deepEqual(normalizeWorkspaces(['packages/*']), ['packages/*']);
|
|
141
|
+
assert.deepEqual(normalizeWorkspaces({ packages: ['apps/*', 'libs/*'] }), ['apps/*', 'libs/*']);
|
|
142
|
+
assert.deepEqual(normalizeWorkspaces(undefined), []);
|
|
143
|
+
});
|
|
144
|
+
test('scopeFromPkgName extracts the npm scope', () => {
|
|
145
|
+
assert.strictEqual(scopeFromPkgName('@acme/app'), 'acme');
|
|
146
|
+
assert.strictEqual(scopeFromPkgName('plain-app'), null);
|
|
147
|
+
assert.strictEqual(scopeFromPkgName(undefined), null);
|
|
148
|
+
});
|
|
149
|
+
test('workspacesCover matches exact entries and parent globs', () => {
|
|
150
|
+
assert.strictEqual(workspacesCover(['packages/*'], 'packages/bb-foo'), true);
|
|
151
|
+
assert.strictEqual(workspacesCover(['packages/**'], 'packages/bb-foo'), true);
|
|
152
|
+
assert.strictEqual(workspacesCover(['packages/bb-foo'], 'packages/bb-foo'), true);
|
|
153
|
+
assert.strictEqual(workspacesCover(['apps/*'], 'packages/bb-foo'), false);
|
|
154
|
+
assert.strictEqual(workspacesCover([], 'packages/bb-foo'), false);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
describe('customer-mode detection', () => {
|
|
158
|
+
test('detects a customer workspace (workspaces, but not the Blocks repo)', async () => {
|
|
159
|
+
const dir = mkdtempSync(join(tmpdir(), 'cb-cust-'));
|
|
160
|
+
try {
|
|
161
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: '@acme/app', workspaces: ['packages/*'] }));
|
|
162
|
+
const nested = join(dir, 'src');
|
|
163
|
+
mkdirSync(nested, { recursive: true });
|
|
164
|
+
const found = await findCustomerWorkspaceRoot(nested);
|
|
165
|
+
assert.strictEqual(found?.root, dir);
|
|
166
|
+
assert.strictEqual(found?.pkg.name, '@acme/app');
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
rmSync(dir, { recursive: true, force: true });
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
test('does NOT treat the AWS Blocks monorepo as a customer workspace', async () => {
|
|
173
|
+
const dir = mkdtempSync(join(tmpdir(), 'cb-blk-'));
|
|
174
|
+
try {
|
|
175
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ workspaces: ['packages/blocks'] }));
|
|
176
|
+
mkdirSync(join(dir, 'packages', 'blocks'), { recursive: true });
|
|
177
|
+
assert.strictEqual(await findCustomerWorkspaceRoot(dir), null);
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
rmSync(dir, { recursive: true, force: true });
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
test('returns null when there are no workspaces', async () => {
|
|
184
|
+
const dir = mkdtempSync(join(tmpdir(), 'cb-none-'));
|
|
185
|
+
try {
|
|
186
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'plain-app' }));
|
|
187
|
+
assert.strictEqual(await findCustomerWorkspaceRoot(dir), null);
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
rmSync(dir, { recursive: true, force: true });
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
// End-to-end run() coverage for the file-writing / JSON-mutation paths that the
|
|
195
|
+
// pure-helper tests can't reach. Hermetic: CREATE_BLOCK_SKIP_REGISTRY avoids the
|
|
196
|
+
// npm-view call, and --skip-install/--skip-verify avoid shelling out.
|
|
197
|
+
describe('run() integration — customer mode', () => {
|
|
198
|
+
function withWorkspace(fn) {
|
|
199
|
+
return async () => {
|
|
200
|
+
const dir = mkdtempSync(join(tmpdir(), 'cb-run-'));
|
|
201
|
+
const prev = process.env.CREATE_BLOCK_SKIP_REGISTRY;
|
|
202
|
+
process.env.CREATE_BLOCK_SKIP_REGISTRY = '1';
|
|
203
|
+
try {
|
|
204
|
+
await fn(dir);
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
if (prev === undefined)
|
|
208
|
+
delete process.env.CREATE_BLOCK_SKIP_REGISTRY;
|
|
209
|
+
else
|
|
210
|
+
process.env.CREATE_BLOCK_SKIP_REGISTRY = prev;
|
|
211
|
+
rmSync(dir, { recursive: true, force: true });
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
test('scaffolds packages/bb-*, links it into workspaces, substitutes tokens', withWorkspace(async (dir) => {
|
|
216
|
+
// workspaces glob does NOT cover packages/ → the entry must be appended.
|
|
217
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: '@acme/app', workspaces: ['apps/*'] }));
|
|
218
|
+
const code = await run(['SearchCache', '--yes', '--skip-install', '--skip-verify'], dir);
|
|
219
|
+
assert.strictEqual(code, 0);
|
|
220
|
+
const pkgDir = join(dir, 'packages', 'bb-search-cache');
|
|
221
|
+
const pkg = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf-8'));
|
|
222
|
+
assert.strictEqual(pkg.name, '@acme/bb-search-cache');
|
|
223
|
+
assert.ok(pkg.keywords.includes('aws-blocks'));
|
|
224
|
+
const rootWs = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8')).workspaces;
|
|
225
|
+
assert.ok(rootWs.includes('packages/bb-search-cache'));
|
|
226
|
+
const mock = readFileSync(join(pkgDir, 'src', 'index.mock.ts'), 'utf-8');
|
|
227
|
+
assert.match(mock, /class SearchCache extends Scope/);
|
|
228
|
+
assert.doesNotMatch(mock, /__BB_CLASS__|__BB_PKG_NAME__/);
|
|
229
|
+
// standalone build helper written; core-coupled CDK synth test omitted
|
|
230
|
+
assert.ok(existsSync(join(pkgDir, 'scripts', 'generate-version.mjs')));
|
|
231
|
+
assert.ok(!existsSync(join(pkgDir, 'src', 'index.cdk.test.ts')));
|
|
232
|
+
}));
|
|
233
|
+
test('does not touch workspaces when a glob already covers packages/', withWorkspace(async (dir) => {
|
|
234
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: '@acme/app', workspaces: ['packages/*'] }));
|
|
235
|
+
const code = await run(['Widget', '--yes', '--skip-install', '--skip-verify'], dir);
|
|
236
|
+
assert.strictEqual(code, 0);
|
|
237
|
+
assert.deepEqual(JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8')).workspaces, ['packages/*']);
|
|
238
|
+
assert.ok(existsSync(join(dir, 'packages', 'bb-widget', 'package.json')));
|
|
239
|
+
}));
|
|
240
|
+
test('--dry-run writes nothing', withWorkspace(async (dir) => {
|
|
241
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: '@acme/app', workspaces: ['apps/*'] }));
|
|
242
|
+
const code = await run(['SearchCache', '--yes', '--dry-run'], dir);
|
|
243
|
+
assert.strictEqual(code, 0);
|
|
244
|
+
assert.ok(!existsSync(join(dir, 'packages')));
|
|
245
|
+
assert.deepEqual(JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8')).workspaces, ['apps/*']);
|
|
246
|
+
}));
|
|
247
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aws-blocks/create-block",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"aws-blocks"
|
|
6
|
+
],
|
|
7
|
+
"description": "Scaffold a new AWS Blocks Building Block (bb-*) — inside the monorepo (contributor mode) or in your own project (external mode).",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/aws-devtools-labs/aws-blocks.git",
|
|
11
|
+
"directory": "packages/create-block"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/aws-devtools-labs/aws-blocks/tree/main/packages/create-block#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/aws-devtools-labs/aws-blocks/issues"
|
|
16
|
+
},
|
|
17
|
+
"author": "Amazon Web Services",
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"bin": {
|
|
21
|
+
"create-block": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"dev": "tsc --watch",
|
|
26
|
+
"test": "node --test dist/**/*.test.js"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^20.0.0",
|
|
30
|
+
"typescript": "^5.3.0"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"templates",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# __BB_CLASS__ — Design
|
|
2
|
+
|
|
3
|
+
TODO: describe the block's internals and the differences between the mock and
|
|
4
|
+
AWS implementations. Delete the guidance below once filled in.
|
|
5
|
+
|
|
6
|
+
## Infrastructure (CDK)
|
|
7
|
+
|
|
8
|
+
`index.cdk.ts` provisions this block's resources (named off `this.fullId` so the
|
|
9
|
+
runtime can derive the same name) and grants the shared Blocks Lambda access.
|
|
10
|
+
Every runtime method is stubbed with `synthGuard` so a top-level call during
|
|
11
|
+
synth fails loudly.
|
|
12
|
+
|
|
13
|
+
## Runtime (AWS)
|
|
14
|
+
|
|
15
|
+
`index.aws.ts` resolves resource identifiers from the registry **at call time**
|
|
16
|
+
(`getSdkIdentifiers(this)`) and calls AWS via the SDK.
|
|
17
|
+
|
|
18
|
+
## Mock Implementation
|
|
19
|
+
|
|
20
|
+
`index.mock.ts` implements the same surface locally (in-memory or on-disk under
|
|
21
|
+
`.bb-data/{fullId}/`) so `npm run dev` and tests need no AWS account.
|
|
22
|
+
|
|
23
|
+
### Mock vs AWS Behavior Differences
|
|
24
|
+
|
|
25
|
+
TODO: document any behavior that differs between the mock and AWS paths (e.g.
|
|
26
|
+
eventual consistency, size limits, error names). Parity is covered by
|
|
27
|
+
`parity.test.ts`.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# __BB_CLASS__
|
|
2
|
+
|
|
3
|
+
TODO: one-sentence summary of what this Building Block does. (The first sentence
|
|
4
|
+
becomes the block's blurb in the `@aws-blocks/blocks` catalog table.)
|
|
5
|
+
|
|
6
|
+
**Keywords:** TODO, comma, separated
|
|
7
|
+
|
|
8
|
+
A **primitive** block: it provisions and owns its own AWS infrastructure. The
|
|
9
|
+
generated code is a storage-agnostic `Scope` skeleton with one example method —
|
|
10
|
+
replace it with your block's real API and infrastructure. See `bb-kv-store` for a
|
|
11
|
+
worked key/value example, `bb-file-bucket` for object storage.
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
### `new __BB_CLASS__(scope, id, options?)`
|
|
16
|
+
|
|
17
|
+
| Option | Type | Notes |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| `label` | `string` | TODO — replace with your real options. |
|
|
20
|
+
|
|
21
|
+
### Methods
|
|
22
|
+
|
|
23
|
+
- `echo(input): Promise<string>` — TODO: replace with your block's methods.
|
|
24
|
+
|
|
25
|
+
## Examples
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Scope, ApiNamespace } from '@aws-blocks/blocks';
|
|
29
|
+
import { __BB_CLASS__ } from '__BB_PKG_NAME__';
|
|
30
|
+
|
|
31
|
+
const scope = new Scope('my-app');
|
|
32
|
+
const thing = new __BB_CLASS__(scope, 'thing');
|
|
33
|
+
|
|
34
|
+
export const api = new ApiNamespace(scope, 'api', () => ({
|
|
35
|
+
echo: (input: string) => thing.echo(input),
|
|
36
|
+
}));
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Local Development
|
|
40
|
+
|
|
41
|
+
`npm run dev` runs the mock entry (`index.mock.ts`) — no AWS account required.
|
|
42
|
+
Implement local state there (in-memory or on-disk under `.bb-data/`). Wipe local
|
|
43
|
+
state with `rm -rf .bb-data`.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__BB_PKG_NAME__",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TODO: one-line description of the __BB_CLASS__ Building Block.",
|
|
5
|
+
"author": "Amazon Web Services",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md",
|
|
11
|
+
"DESIGN.md",
|
|
12
|
+
"src",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"browser": "./dist/index.browser.js",
|
|
18
|
+
"cdk": {
|
|
19
|
+
"types": "./dist/index.cdk.d.ts",
|
|
20
|
+
"default": "./dist/index.cdk.js"
|
|
21
|
+
},
|
|
22
|
+
"aws-runtime": "./dist/index.aws.js",
|
|
23
|
+
"types": "./dist/index.mock.d.ts",
|
|
24
|
+
"default": "./dist/index.mock.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"prebuild": "node ../../scripts/generate-version.mjs __BB_CLASS__",
|
|
29
|
+
"build": "tsc --build",
|
|
30
|
+
"test": "node --test --test-concurrency=1 dist/*.test.js"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@aws-blocks/core": "^0.2.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^20.0.0",
|
|
37
|
+
"typescript": "^5.3.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"aws-cdk-lib": "^2.257.0",
|
|
41
|
+
"constructs": "^10.6.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Typed error constants for __BB_CLASS__. Match them in catch blocks with
|
|
6
|
+
* `isBlocksError(e, __BB_CLASS__Errors.Foo)` from `@aws-blocks/core` — errors
|
|
7
|
+
* cross the wire by `name`, so the same guard works server- and client-side.
|
|
8
|
+
*/
|
|
9
|
+
export const __BB_CLASS__Errors = {
|
|
10
|
+
/** TODO: rename/extend for this block's real failure modes. */
|
|
11
|
+
InvalidInput: 'InvalidInputException',
|
|
12
|
+
} as const;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Scope, registerSdkIdentifiers } from '@aws-blocks/core';
|
|
5
|
+
import type { ScopeParent } from '@aws-blocks/core';
|
|
6
|
+
import { BB_NAME, BB_VERSION } from './version.js';
|
|
7
|
+
|
|
8
|
+
// ── Public types + errors ────────────────────────────────────────────────────
|
|
9
|
+
export { __BB_CLASS__Errors } from './errors.js';
|
|
10
|
+
export type { __BB_CLASS__Options } from './types.js';
|
|
11
|
+
|
|
12
|
+
import type { __BB_CLASS__Options } from './types.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* See `index.mock.ts` for the authoritative JSDoc — the public surface must be
|
|
16
|
+
* identical. This is the **deployed Lambda runtime** (`aws-runtime` export): it
|
|
17
|
+
* talks to real AWS services via the SDK.
|
|
18
|
+
*/
|
|
19
|
+
export class __BB_CLASS__ extends Scope {
|
|
20
|
+
readonly bbName = BB_NAME;
|
|
21
|
+
|
|
22
|
+
constructor(scope: ScopeParent, id: string, _options?: __BB_CLASS__Options) {
|
|
23
|
+
super(id, { parent: scope, bbName: BB_NAME, bbVersion: BB_VERSION });
|
|
24
|
+
registerSdkIdentifiers(this.fullId, {});
|
|
25
|
+
// TODO: create your SDK client(s) here, e.g.:
|
|
26
|
+
// this.client = new SomeClient({ customUserAgent: this.buildUserAgentChain() });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async echo(input: string): Promise<string> {
|
|
30
|
+
// TODO: resolve resource identifiers with `getSdkIdentifiers(this)` (at
|
|
31
|
+
// call time, never in the constructor) and call AWS.
|
|
32
|
+
return input;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Browser stub — __BB_CLASS__ runs server-side only. Per the AWS Blocks
|
|
5
|
+
// convention this entry re-exports the block's public types + error constants so
|
|
6
|
+
// isomorphic/bundled client code type-checks; the methods live on the server
|
|
7
|
+
// (mock/aws) entries and are absent here.
|
|
8
|
+
export class __BB_CLASS__ {
|
|
9
|
+
constructor(..._args: unknown[]) {}
|
|
10
|
+
}
|
|
11
|
+
export { __BB_CLASS__Errors } from './errors.js';
|
|
12
|
+
export type { __BB_CLASS__Options } from './types.js';
|