working rss feed to nostr publish
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
describe("emitWarningIfUnsupportedVersion", () => {
|
||||
let emitWarningIfUnsupportedVersion;
|
||||
const emitWarning = process.emitWarning;
|
||||
const supportedVersion = "16.0.0";
|
||||
|
||||
beforeEach(() => {
|
||||
const module = require("./emitWarningIfUnsupportedVersion");
|
||||
emitWarningIfUnsupportedVersion = module.emitWarningIfUnsupportedVersion;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.resetModules();
|
||||
process.emitWarning = emitWarning;
|
||||
});
|
||||
|
||||
describe(`emits warning for Node.js <${supportedVersion}`, () => {
|
||||
const getPreviousMajorVersion = (major: number) => (major === 0 ? 0 : major - 1);
|
||||
|
||||
const getPreviousMinorVersion = ([major, minor]: [number, number]) =>
|
||||
minor === 0 ? [getPreviousMajorVersion(major), 9] : [major, minor - 1];
|
||||
|
||||
const getPreviousPatchVersion = ([major, minor, patch]: [number, number, number]) =>
|
||||
patch === 0 ? [...getPreviousMinorVersion([major, minor]), 9] : [major, minor, patch - 1];
|
||||
|
||||
const [major, minor, patch] = supportedVersion.split(".").map(Number);
|
||||
it.each(
|
||||
[
|
||||
getPreviousPatchVersion([major, minor, patch]),
|
||||
[...getPreviousMinorVersion([major, minor]), 0],
|
||||
[getPreviousMajorVersion(major), 0, 0],
|
||||
].map((arr) => `v${arr.join(".")}`)
|
||||
)(`%s`, async (unsupportedVersion) => {
|
||||
process.emitWarning = jest.fn();
|
||||
emitWarningIfUnsupportedVersion(unsupportedVersion);
|
||||
|
||||
// Verify that the warning was emitted.
|
||||
expect(process.emitWarning).toHaveBeenCalledTimes(1);
|
||||
expect(process.emitWarning).toHaveBeenCalledWith(
|
||||
`NodeDeprecationWarning: The AWS SDK for JavaScript (v3) will
|
||||
no longer support Node.js 14.x on May 1, 2024.
|
||||
|
||||
To continue receiving updates to AWS services, bug fixes, and security
|
||||
updates please upgrade to an active Node.js LTS version.
|
||||
|
||||
More information can be found at: https://a.co/dzr2AJd`
|
||||
);
|
||||
|
||||
// Verify that the warning emits only once.
|
||||
emitWarningIfUnsupportedVersion(unsupportedVersion);
|
||||
expect(process.emitWarning).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe(`emits no warning for Node.js >=${supportedVersion}`, () => {
|
||||
const [major, minor, patch] = supportedVersion.split(".").map(Number);
|
||||
it.each(
|
||||
[
|
||||
[major, minor, patch],
|
||||
[major, minor, patch + 1],
|
||||
[major, minor + 1, 0],
|
||||
[major + 1, 0, 0],
|
||||
].map((arr) => `v${arr.join(".")}`)
|
||||
)(`%s`, async (unsupportedVersion) => {
|
||||
process.emitWarning = jest.fn();
|
||||
emitWarningIfUnsupportedVersion(unsupportedVersion);
|
||||
expect(process.emitWarning).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// Stores whether the warning was already emitted.
|
||||
let warningEmitted = false;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Emits warning if the provided Node.js version string is
|
||||
* pending deprecation by AWS SDK JSv3.
|
||||
*
|
||||
* @param version - The Node.js version string.
|
||||
*/
|
||||
export const emitWarningIfUnsupportedVersion = (version: string) => {
|
||||
if (version && !warningEmitted && parseInt(version.substring(1, version.indexOf("."))) < 16) {
|
||||
warningEmitted = true;
|
||||
process.emitWarning(
|
||||
`NodeDeprecationWarning: The AWS SDK for JavaScript (v3) will
|
||||
no longer support Node.js 14.x on May 1, 2024.
|
||||
|
||||
To continue receiving updates to AWS services, bug fixes, and security
|
||||
updates please upgrade to an active Node.js LTS version.
|
||||
|
||||
More information can be found at: https://a.co/dzr2AJd`
|
||||
);
|
||||
}
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * from "./emitWarningIfUnsupportedVersion";
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./client/index";
|
||||
export * from "./protocols/index";
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
import { _toBool, _toNum, _toStr } from "./coercing-serializers";
|
||||
|
||||
const consoleWarn = console.warn;
|
||||
|
||||
beforeAll(() => {
|
||||
console.warn = () => {};
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
console.warn = consoleWarn;
|
||||
});
|
||||
|
||||
describe(_toBool.name, () => {
|
||||
it("ignores nullish", () => {
|
||||
expect(_toBool(null)).toBe(null);
|
||||
expect(_toBool(undefined)).toBe(undefined);
|
||||
});
|
||||
|
||||
it("converts strings", () => {
|
||||
expect(_toBool("false")).toEqual(false);
|
||||
expect(_toBool("true")).toEqual(true);
|
||||
|
||||
expect(_toBool("False")).toEqual(false);
|
||||
expect(_toBool("True")).toEqual(true);
|
||||
|
||||
expect(_toBool("")).toEqual(false);
|
||||
expect(_toBool("a")).toEqual(true); // warns
|
||||
});
|
||||
|
||||
it("does not convert numbers", () => {
|
||||
expect(_toBool(0)).toEqual(0);
|
||||
expect(_toBool(1)).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe(_toStr.name, () => {
|
||||
it("ignores nullish", () => {
|
||||
expect(_toStr(null)).toBe(null);
|
||||
expect(_toStr(undefined)).toBe(undefined);
|
||||
});
|
||||
|
||||
it("converts numbers", () => {
|
||||
expect(_toStr(0)).toEqual("0");
|
||||
expect(_toStr(1)).toEqual("1");
|
||||
});
|
||||
|
||||
it("converts booleans", () => {
|
||||
expect(_toStr(false)).toEqual("false");
|
||||
expect(_toStr(true)).toEqual("true");
|
||||
});
|
||||
});
|
||||
|
||||
describe(_toNum.name, () => {
|
||||
it("ignores nullish", () => {
|
||||
expect(_toNum(null)).toBe(null);
|
||||
expect(_toNum(undefined)).toBe(undefined);
|
||||
});
|
||||
|
||||
it("converts numeric strings", () => {
|
||||
expect(_toNum("1234")).toEqual(1234);
|
||||
expect(_toNum("1234.56")).toEqual(1234.56);
|
||||
});
|
||||
|
||||
it("does not convert prefix-numeric strings", () => {
|
||||
expect(_toNum("1234abc")).toEqual("1234abc");
|
||||
expect(_toNum("1234.56abc")).toEqual("1234.56abc");
|
||||
});
|
||||
|
||||
it("does not convert non-numeric strings", () => {
|
||||
expect(_toNum("abcdef")).toEqual("abcdef");
|
||||
});
|
||||
it("does not convert bools", () => {
|
||||
expect(_toNum(false)).toEqual(false);
|
||||
expect(_toNum(true)).toEqual(true);
|
||||
});
|
||||
});
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Used for awsQueryCompatibility trait.
|
||||
*/
|
||||
export const _toStr = (val: unknown): string | undefined => {
|
||||
if (val == null) {
|
||||
return val as undefined;
|
||||
}
|
||||
if (typeof val === "number" || typeof val === "bigint") {
|
||||
const warning = new Error(`Received number ${val} where a string was expected.`);
|
||||
warning.name = "Warning";
|
||||
console.warn(warning);
|
||||
return String(val);
|
||||
}
|
||||
if (typeof val === "boolean") {
|
||||
const warning = new Error(`Received boolean ${val} where a string was expected.`);
|
||||
warning.name = "Warning";
|
||||
console.warn(warning);
|
||||
return String(val);
|
||||
}
|
||||
return val as string;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Used for awsQueryCompatibility trait.
|
||||
*/
|
||||
export const _toBool = (val: unknown): boolean | undefined => {
|
||||
if (val == null) {
|
||||
return val as undefined;
|
||||
}
|
||||
if (typeof val === "number") {
|
||||
// transmit to service to be rejected.
|
||||
}
|
||||
if (typeof val === "string") {
|
||||
const lowercase = val.toLowerCase();
|
||||
if (val !== "" && lowercase !== "false" && lowercase !== "true") {
|
||||
const warning = new Error(`Received string "${val}" where a boolean was expected.`);
|
||||
warning.name = "Warning";
|
||||
console.warn(warning);
|
||||
}
|
||||
return val !== "" && lowercase !== "false";
|
||||
}
|
||||
return val as boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Used for awsQueryCompatibility trait.
|
||||
*/
|
||||
export const _toNum = (val: unknown): number | undefined => {
|
||||
if (val == null) {
|
||||
return val as undefined;
|
||||
}
|
||||
if (typeof val === "boolean") {
|
||||
// transmit to service to be rejected.
|
||||
}
|
||||
if (typeof val === "string") {
|
||||
const num = Number(val);
|
||||
if (num.toString() !== val) {
|
||||
const warning = new Error(`Received string "${val}" where a number was expected.`);
|
||||
warning.name = "Warning";
|
||||
console.warn(warning);
|
||||
return val as unknown as undefined;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
return val as number;
|
||||
};
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./coercing-serializers";
|
||||
export * from "./json/awsExpectUnion";
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import { awsExpectUnion } from "./awsExpectUnion";
|
||||
|
||||
describe(awsExpectUnion.name, () => {
|
||||
it("ignores the __type field", () => {
|
||||
expect(
|
||||
awsExpectUnion({
|
||||
K: "V",
|
||||
__type: "X",
|
||||
})
|
||||
).toEqual({
|
||||
K: "V",
|
||||
});
|
||||
});
|
||||
|
||||
it("throws when there are extra keys or no keys", () => {
|
||||
expect(() =>
|
||||
awsExpectUnion({
|
||||
__type: "X",
|
||||
})
|
||||
).toThrowError();
|
||||
|
||||
expect(() =>
|
||||
awsExpectUnion({
|
||||
K: "V",
|
||||
I: "S",
|
||||
__type: "X",
|
||||
})
|
||||
).toThrowError();
|
||||
});
|
||||
});
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { expectUnion } from "@smithy/smithy-client";
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Forwards to Smithy's expectUnion function, but also ignores
|
||||
* the `__type` field if it is present.
|
||||
*/
|
||||
export const awsExpectUnion = (value: unknown): Record<string, any> | undefined => {
|
||||
if (value == null) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof value === "object" && "__type" in value) {
|
||||
delete value.__type;
|
||||
}
|
||||
return expectUnion(value);
|
||||
};
|
||||
Reference in New Issue
Block a user