@aws-blocks/bb-metrics 0.1.2 → 0.1.4

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 +1 @@
1
- {"version":3,"file":"index.aws.d.ts","sourceRoot":"","sources":["../src/index.aws.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EACX,cAAc,EACd,WAAW,EACX,WAAW,EAGX,kBAAkB,EAClB,cAAc,EACd,MAAM,YAAY,CAAC;AAUpB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EACX,cAAc,EACd,WAAW,EACX,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACd,MAAM,YAAY,CAAC;AAIpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,qBAAa,OAAQ,SAAQ,KAAM,YAAW,cAAc;IAC3D,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,mEAAmE;IACnE,QAAQ,CAAC,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAE7D,2FAA2F;IAC3F,SAAS,CAAC,GAAG,EAAE,WAAW,CAAC;gBAEf,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc;IAUpE;;;;;;;;;;;;;;;;;;OAkBG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;IAe9D;;;;;;;;;;;;;;;;;OAiBG;IAC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;;;;;;;;;;OAkBG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;IAe9D;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI;IAqBvC;;OAEG;IACH,KAAK,IAAI,IAAI;IAEb;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,cAAc;IAOzD;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB;CAG1D"}
package/dist/index.aws.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Scope } from '@aws-blocks/core';
4
+ import { BB_NAME, BB_VERSION } from './version.js';
4
5
  import { validateMetricName, validateDimensions, validateBatchSize, validateNamespace, mergeDimensions, } from './validation.js';
5
6
  import { Logger } from '@aws-blocks/bb-logger';
6
7
  export { MetricsErrors } from './errors.js';
@@ -61,7 +62,7 @@ export class Metrics extends Scope {
61
62
  /** @internal Logger for internal operations. Defaults to error-level when not provided. */
62
63
  log;
63
64
  constructor(scope, id, options) {
64
- super(id, { parent: scope });
65
+ super(id, { parent: scope, bbName: BB_NAME, bbVersion: BB_VERSION });
65
66
  this.log = options?.logger ?? new Logger(this, 'logger', { level: 'error' });
66
67
  this.namespace = options?.metrics?.namespace
67
68
  ?? options?.namespace
@@ -2,7 +2,14 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { test, describe, beforeEach, afterEach } from 'node:test';
4
4
  import assert from 'node:assert';
5
+ import { readFileSync } from 'node:fs';
6
+ import { dirname, join } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ import { Scope } from '@aws-blocks/core';
5
9
  import { Metrics, MetricsErrors } from './index.mock.js';
10
+ import { Metrics as AwsMetrics } from './index.aws.js';
11
+ import { BB_NAME, BB_VERSION } from './version.js';
12
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
13
  // ── Helpers ─────────────────────────────────────────────────────────────────
7
14
  let stdoutLines = [];
8
15
  let origStdoutWrite;
@@ -493,3 +500,42 @@ describe('scope integration', () => {
493
500
  assert.ok(typeof m.child === 'function');
494
501
  });
495
502
  });
503
+ // ── Telemetry Registration ──────────────────────────────────────────────────
504
+ /**
505
+ * `Scope.getRegisteredBlocks()` only names a block whose `bbName` is in
506
+ * OFFICIAL_BB_NAMES, and that set is generated from the umbrella's
507
+ * `aws-blocks.vendorize` map. These tests pin the three coupled artifacts to
508
+ * each other: the block's generated BB_NAME, its vendorize entry, and the
509
+ * generated name set. A block that omits `bbMeta` still constructs fine and
510
+ * every other test still passes, so that gap is only visible here.
511
+ *
512
+ * Imported through `./index.mock.js`, the package's default entry, which
513
+ * re-exports the AWS runtime class — so both conditions resolve to the class
514
+ * asserted here.
515
+ */
516
+ describe('telemetry registration', () => {
517
+ beforeEach(() => {
518
+ Scope._resetRegistry();
519
+ });
520
+ test('BB_NAME is the name the vendorize map and OFFICIAL_BB_NAMES carry', () => {
521
+ assert.strictEqual(BB_NAME, 'Metrics');
522
+ });
523
+ test('BB_VERSION tracks the package version', () => {
524
+ const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));
525
+ assert.strictEqual(BB_VERSION, pkg.version);
526
+ });
527
+ test('the default entry re-exports the AWS runtime class', () => {
528
+ assert.strictEqual(Metrics, AwsMetrics);
529
+ });
530
+ test('an instance carries bbName and bbVersion', () => {
531
+ const m = new Metrics(fakeScope, 'metrics');
532
+ assert.strictEqual(m.bbName, BB_NAME);
533
+ assert.strictEqual(m.bbVersion, BB_VERSION);
534
+ });
535
+ test('registers as an official block, so telemetry is allowed to name it', () => {
536
+ new Metrics(fakeScope, 'metrics');
537
+ const { blocks, customBlocksCount } = Scope.getRegisteredBlocks();
538
+ assert.deepStrictEqual(blocks.filter(b => b.name === BB_NAME), [{ name: BB_NAME, version: BB_VERSION }]);
539
+ assert.strictEqual(customBlocksCount, 0, 'must not be filtered out as an unnamed custom block');
540
+ });
541
+ });
@@ -0,0 +1,3 @@
1
+ export declare const BB_NAME = "Metrics";
2
+ export declare const BB_VERSION = "0.1.4";
3
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,UAAU,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ // Auto-generated by scripts/generate-version.mjs — do not edit manually
2
+ export const BB_NAME = 'Metrics';
3
+ export const BB_VERSION = '0.1.4';
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "@aws-blocks/bb-metrics",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/aws-devtools-labs/aws-blocks.git",
7
+ "directory": "packages/bb-metrics"
8
+ },
9
+ "homepage": "https://github.com/aws-devtools-labs/aws-blocks/tree/main/packages/bb-metrics#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/aws-devtools-labs/aws-blocks/issues"
12
+ },
4
13
  "author": "Amazon Web Services",
5
14
  "license": "Apache-2.0",
6
15
  "type": "module",
@@ -24,12 +33,13 @@
24
33
  }
25
34
  },
26
35
  "scripts": {
36
+ "prebuild": "node ../../scripts/generate-version.mjs Metrics",
27
37
  "build": "tsc --build",
28
38
  "test": "node --test dist/**/*.test.js"
29
39
  },
30
40
  "dependencies": {
31
- "@aws-blocks/core": "^0.1.1",
32
- "@aws-blocks/bb-logger": "^0.1.2"
41
+ "@aws-blocks/core": "^0.2.0",
42
+ "@aws-blocks/bb-logger": "^0.1.4"
33
43
  },
34
44
  "devDependencies": {
35
45
  "@types/node": "^20.0.0",
package/src/index.aws.ts CHANGED
@@ -13,6 +13,7 @@ import type {
13
13
  MetricsEmitter,
14
14
  } from './types.js';
15
15
  import { MetricsErrors } from './errors.js';
16
+ import { BB_NAME, BB_VERSION } from './version.js';
16
17
  import {
17
18
  validateMetricName,
18
19
  validateDimensions,
@@ -94,7 +95,7 @@ export class Metrics extends Scope implements MetricsEmitter {
94
95
  protected log: ChildLogger;
95
96
 
96
97
  constructor(scope: ScopeParent, id: string, options?: MetricsOptions) {
97
- super(id, { parent: scope });
98
+ super(id, { parent: scope, bbName: BB_NAME, bbVersion: BB_VERSION });
98
99
  this.log = options?.logger ?? new Logger(this, 'logger', { level: 'error' });
99
100
  this.namespace = options?.metrics?.namespace
100
101
  ?? options?.namespace
package/src/index.test.ts CHANGED
@@ -3,8 +3,16 @@
3
3
 
4
4
  import { test, describe, beforeEach, afterEach } from 'node:test';
5
5
  import assert from 'node:assert';
6
+ import { readFileSync } from 'node:fs';
7
+ import { dirname, join } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { Scope } from '@aws-blocks/core';
6
10
  import { Metrics, MetricsErrors } from './index.mock.js';
11
+ import { Metrics as AwsMetrics } from './index.aws.js';
7
12
  import type { MetricsEmitter } from './types.js';
13
+ import { BB_NAME, BB_VERSION } from './version.js';
14
+
15
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
16
 
9
17
  // ── Helpers ─────────────────────────────────────────────────────────────────
10
18
 
@@ -630,3 +638,52 @@ describe('scope integration', () => {
630
638
  assert.ok(typeof m.child === 'function');
631
639
  });
632
640
  });
641
+
642
+ // ── Telemetry Registration ──────────────────────────────────────────────────
643
+
644
+ /**
645
+ * `Scope.getRegisteredBlocks()` only names a block whose `bbName` is in
646
+ * OFFICIAL_BB_NAMES, and that set is generated from the umbrella's
647
+ * `aws-blocks.vendorize` map. These tests pin the three coupled artifacts to
648
+ * each other: the block's generated BB_NAME, its vendorize entry, and the
649
+ * generated name set. A block that omits `bbMeta` still constructs fine and
650
+ * every other test still passes, so that gap is only visible here.
651
+ *
652
+ * Imported through `./index.mock.js`, the package's default entry, which
653
+ * re-exports the AWS runtime class — so both conditions resolve to the class
654
+ * asserted here.
655
+ */
656
+ describe('telemetry registration', () => {
657
+ beforeEach(() => {
658
+ Scope._resetRegistry();
659
+ });
660
+
661
+ test('BB_NAME is the name the vendorize map and OFFICIAL_BB_NAMES carry', () => {
662
+ assert.strictEqual(BB_NAME, 'Metrics');
663
+ });
664
+
665
+ test('BB_VERSION tracks the package version', () => {
666
+ const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));
667
+ assert.strictEqual(BB_VERSION, pkg.version);
668
+ });
669
+
670
+ test('the default entry re-exports the AWS runtime class', () => {
671
+ assert.strictEqual(Metrics, AwsMetrics);
672
+ });
673
+
674
+ test('an instance carries bbName and bbVersion', () => {
675
+ const m = new Metrics(fakeScope, 'metrics');
676
+ assert.strictEqual(m.bbName, BB_NAME);
677
+ assert.strictEqual(m.bbVersion, BB_VERSION);
678
+ });
679
+
680
+ test('registers as an official block, so telemetry is allowed to name it', () => {
681
+ new Metrics(fakeScope, 'metrics');
682
+ const { blocks, customBlocksCount } = Scope.getRegisteredBlocks();
683
+ assert.deepStrictEqual(
684
+ blocks.filter(b => b.name === BB_NAME),
685
+ [{ name: BB_NAME, version: BB_VERSION }],
686
+ );
687
+ assert.strictEqual(customBlocksCount, 0, 'must not be filtered out as an unnamed custom block');
688
+ });
689
+ });
package/src/version.ts ADDED
@@ -0,0 +1,3 @@
1
+ // Auto-generated by scripts/generate-version.mjs — do not edit manually
2
+ export const BB_NAME = 'Metrics';
3
+ export const BB_VERSION = '0.1.4';