Skip to content

Commit

Permalink
FIX: ES modules release dist
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael O'Brien committed Sep 2, 2023
1 parent 6be50c0 commit 552c839
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 deletions.
39 changes: 16 additions & 23 deletions dist/mjs/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomMetrics = exports.DefaultSpans = void 0;
const process_1 = __importDefault(require("process"));
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
import process from 'process';
import { DynamoDBClient, GetItemCommand, PutItemCommand, QueryCommand, } from '@aws-sdk/client-dynamodb';
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
const Version = 1;
const Assert = true;
const Buffering = true;
const DefaultResolution = 0;
const MaxSeq = Number.MAX_SAFE_INTEGER;
const MaxRetries = 10;
const MetricListLimit = 10000;
exports.DefaultSpans = [
export const DefaultSpans = [
{ period: 5 * 60, samples: 10 },
{ period: 60 * 60, samples: 12 },
{ period: 24 * 60 * 60, samples: 12 },
Expand All @@ -23,10 +17,10 @@ exports.DefaultSpans = [
{ period: 365 * 24 * 60 * 60, samples: 12 },
];
var Instances = {};
process_1.default.on('SIGTERM', async () => {
process.on('SIGTERM', async () => {
await CustomMetrics.terminate();
});
class CustomMetrics {
export class CustomMetrics {
consistent = false;
buffer;
buffers = {};
Expand Down Expand Up @@ -82,15 +76,15 @@ class CustomMetrics {
credentials,
region: credentials.region || options.region,
};
this.client = new client_dynamodb_1.DynamoDBClient(params);
this.client = new DynamoDBClient(params);
}
if (!options.table && !options.tableName) {
throw new Error('Missing DynamoDB table name property');
}
this.table = options.table || options.tableName;
this.options = options;
this.owner = options.owner || 'default';
this.spans = options.spans || exports.DefaultSpans;
this.spans = options.spans || DefaultSpans;
this.ttl = options.ttl || this.spans[this.spans.length - 1].period;
if (options.consistent != null) {
this.consistent = options.consistent;
Expand Down Expand Up @@ -569,7 +563,7 @@ class CustomMetrics {
return metric;
}
async getMetric(owner, namespace, metric, dimensions) {
let command = new client_dynamodb_1.GetItemCommand({
let command = new GetItemCommand({
TableName: this.table,
Key: {
[this.primaryKey]: { S: `${this.prefix}#${Version}#${owner}` },
Expand All @@ -579,7 +573,7 @@ class CustomMetrics {
});
let data = await this.client.send(command);
if (data.Item) {
let item = (0, util_dynamodb_1.unmarshall)(data.Item);
let item = unmarshall(data.Item);
return this.mapItemFromDB(item);
}
return null;
Expand All @@ -589,8 +583,8 @@ class CustomMetrics {
if (metric) {
key.push(metric);
}
let start = startKey ? (0, util_dynamodb_1.marshall)(startKey) : undefined;
let command = new client_dynamodb_1.QueryCommand({
let start = startKey ? marshall(startKey) : undefined;
let command = new QueryCommand({
TableName: this.table,
ExpressionAttributeNames: {
'#_0': this.primaryKey,
Expand All @@ -611,13 +605,13 @@ class CustomMetrics {
let items = [];
if (result.Items) {
for (let i = 0; i < result.Items.length; i++) {
let item = (0, util_dynamodb_1.unmarshall)(result.Items[i]);
let item = unmarshall(result.Items[i]);
items.push(this.mapItemFromDB(item));
}
}
let next = undefined;
if (result.LastEvaluatedKey) {
next = (0, util_dynamodb_1.unmarshall)(result.LastEvaluatedKey);
next = unmarshall(result.LastEvaluatedKey);
}
return { items, next, command };
}
Expand All @@ -639,11 +633,11 @@ class CustomMetrics {
let params = {
TableName: this.table,
ReturnValues: 'NONE',
Item: (0, util_dynamodb_1.marshall)(mapped, { removeUndefinedValues: true }),
Item: marshall(mapped, { removeUndefinedValues: true }),
ConditionExpression,
ExpressionAttributeValues,
};
let command = new client_dynamodb_1.PutItemCommand(params);
let command = new PutItemCommand(params);
let chan = options.log == true ? 'info' : 'trace';
this.log[chan](`Put metric ${item.namespace}, ${item.metric}`, { dimensions: item.dimensions, command });
try {
Expand Down Expand Up @@ -810,7 +804,6 @@ class CustomMetrics {
});
}
}
exports.CustomMetrics = CustomMetrics;
class Log {
senselogs = null;
logger = null;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "custom-metrics",
"version": "0.7.6",
"description": "Low cost custom metrics for AWS",
"description": "Custom metrics for AWS",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
"types": "dist/mjs/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1286,4 +1286,4 @@ class Log {
metric.points = points
}
} */
}
}
1 change: 1 addition & 0 deletions tsconfig-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lib": ["esnext"],
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": false,
"pretty": true,
Expand Down
1 change: 0 additions & 1 deletion tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"lib": ["esnext"],
"module": "commonjs",
"outDir": "dist/cjs",
"target": "es2020"
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"lib": ["esnext"],
"module": "nodenext",
"module": "esnext",
"outDir": "dist/mjs",
"target": "esnext"
}
Expand Down

0 comments on commit 552c839

Please sign in to comment.