@aws-amplify/core 6.10.6-unstable.cde36a7.0 → 6.10.6
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/dist/cjs/BackgroundProcessManager/BackgroundProcessManager.js +1 -0
- package/dist/cjs/BackgroundProcessManager/BackgroundProcessManager.js.map +1 -1
- package/dist/cjs/Logger/ConsoleLogger.js +1 -0
- package/dist/cjs/Logger/ConsoleLogger.js.map +1 -1
- package/dist/cjs/Platform/version.js +1 -1
- package/dist/cjs/Platform/version.js.map +1 -1
- package/dist/esm/BackgroundProcessManager/BackgroundProcessManager.mjs +1 -0
- package/dist/esm/BackgroundProcessManager/BackgroundProcessManager.mjs.map +1 -1
- package/dist/esm/Logger/ConsoleLogger.mjs +1 -0
- package/dist/esm/Logger/ConsoleLogger.mjs.map +1 -1
- package/dist/esm/Platform/version.d.ts +1 -1
- package/dist/esm/Platform/version.mjs +1 -1
- package/dist/esm/Platform/version.mjs.map +1 -1
- package/dist/esm/types/errors.d.ts +4 -6
- package/package.json +3 -3
- package/src/BackgroundProcessManager/BackgroundProcessManager.ts +1 -0
- package/src/Logger/ConsoleLogger.ts +1 -0
- package/src/Platform/version.ts +1 -1
- package/src/types/errors.ts +5 -4
|
@@ -251,6 +251,7 @@ class BackgroundProcessManager {
|
|
|
251
251
|
// Due to potential races with a job's natural completion, it's
|
|
252
252
|
// reasonable to expect the termination call to fail. Hence,
|
|
253
253
|
// not logging as an error.
|
|
254
|
+
// eslint-disable-next-line no-console
|
|
254
255
|
console.warn(`Failed to send termination signal to job. Error: ${error.message}`, job);
|
|
255
256
|
}
|
|
256
257
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackgroundProcessManager.js","sources":["../../../src/BackgroundProcessManager/BackgroundProcessManager.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.BackgroundProcessManager = void 0;\nconst BackgroundManagerNotOpenError_1 = require(\"./BackgroundManagerNotOpenError\");\nconst types_1 = require(\"./types\");\n/**\n * @private For internal Amplify use.\n *\n * Creates a new scope for promises, observables, and other types of work or\n * processes that may be running in the background. This manager provides\n * an singular entrypoint to request termination and await completion.\n *\n * As work completes on its own prior to close, the manager removes them\n * from the registry to avoid holding references to completed jobs.\n */\nclass BackgroundProcessManager {\n constructor() {\n /**\n * A string indicating whether the manager is accepting new work (\"Open\"),\n * waiting for work to complete (\"Closing\"), or fully done with all\n * submitted work and *not* accepting new jobs (\"Closed\").\n */\n this._state = types_1.BackgroundProcessManagerState.Open;\n /**\n * The list of outstanding jobs we'll need to wait for upon `close()`\n */\n this.jobs = new Set();\n }\n add(jobOrDescription, optionalDescription) {\n let job;\n let description;\n if (typeof jobOrDescription === 'string') {\n job = undefined;\n description = jobOrDescription;\n }\n else {\n job = jobOrDescription;\n description = optionalDescription;\n }\n const error = this.closedFailure(description);\n if (error)\n return error;\n if (job === undefined) {\n return this.addHook(description);\n }\n else if (typeof job === 'function') {\n return this.addFunction(job, description);\n }\n else if (job instanceof BackgroundProcessManager) {\n this.addManager(job, description);\n }\n else {\n throw new Error('If `job` is provided, it must be an Observable, Function, or BackgroundProcessManager.');\n }\n }\n /**\n * Adds a **cleaner** function that doesn't immediately get executed.\n * Instead, the caller gets a **terminate** function back. The *cleaner* is\n * invoked only once the mananger *closes* or the returned **terminate**\n * function is called.\n *\n * @param clean The cleanup function.\n * @param description Optional description to help identify pending jobs.\n * @returns A terminate function.\n */\n addCleaner(clean, description) {\n const { resolve, onTerminate } = this.addHook(description);\n const proxy = async () => {\n await clean();\n resolve();\n };\n onTerminate.then(proxy);\n return proxy;\n }\n addFunction(job, description) {\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n // finally! start the job.\n const jobResult = job(onTerminate);\n // depending on what the job gives back, register the result\n // so we can monitor for completion.\n if (typeof jobResult?.then === 'function') {\n this.registerPromise(jobResult, terminate, description);\n }\n // At the end of the day, or you know, method call, it doesn't matter\n // what the return value is at all; we just pass it through to the\n // caller.\n return jobResult;\n }\n addManager(manager, description) {\n this.addCleaner(async () => manager.close(), description);\n }\n /**\n * Creates and registers a fabricated job for processes that need to operate\n * with callbacks/hooks. The returned `resolve` and `reject`\n * functions can be used to signal the job is done successfully or not.\n * The returned `onTerminate` is a promise that will resolve when the\n * manager is requesting the termination of the job.\n *\n * @param description Optional description to help identify pending jobs.\n * @returns `{ resolve, reject, onTerminate }`\n */\n addHook(description) {\n // the resolve/reject functions we'll provide to the caller to signal\n // the state of the job.\n let promiseResolve;\n let promiseReject;\n // the underlying promise we'll use to manage it, pretty much like\n // any other promise.\n const promise = new Promise((resolve, reject) => {\n promiseResolve = resolve;\n promiseReject = reject;\n });\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n this.registerPromise(promise, terminate, description);\n return {\n resolve: promiseResolve,\n reject: promiseReject,\n onTerminate,\n };\n }\n /**\n * Adds a Promise based job to the list of jobs for monitoring and listens\n * for either a success or failure, upon which the job is considered \"done\"\n * and removed from the registry.\n *\n * @param promise A promise that is on its way to being returned to a\n * caller, which needs to be tracked as a background job.\n * @param terminate The termination function to register, which can be\n * invoked to request the job stop.\n * @param description Optional description to help identify pending jobs.\n */\n registerPromise(promise, terminate, description) {\n const jobEntry = { promise, terminate, description };\n this.jobs.add(jobEntry);\n // in all of my testing, it is safe to multi-subscribe to a promise.\n // so, rather than create another layer of promising, we're just going\n // to hook into the promise we already have, and when it's done\n // (successfully or not), we no longer need to wait for it upon close.\n //\n // sorry this is a bit hand-wavy:\n //\n // i believe we use `.then` and `.catch` instead of `.finally` because\n // `.finally` is invoked in a different order in the sequence, and this\n // breaks assumptions throughout and causes failures.\n promise\n .then(() => {\n this.jobs.delete(jobEntry);\n })\n .catch(() => {\n this.jobs.delete(jobEntry);\n });\n }\n /**\n * The number of jobs being waited on.\n *\n * We don't use this for anything. It's just informational for the caller,\n * and can be used in logging and testing.\n *\n * @returns the number of jobs.\n */\n get length() {\n return this.jobs.size;\n }\n /**\n * The execution state of the manager. One of:\n *\n * 1. \"Open\" -> Accepting new jobs\n * 1. \"Closing\" -> Not accepting new work. Waiting for jobs to complete.\n * 1. \"Closed\" -> Not accepting new work. All submitted jobs are complete.\n */\n get state() {\n return this._state;\n }\n /**\n * The registered `description` of all still-pending jobs.\n *\n * @returns descriptions as an array.\n */\n get pending() {\n return Array.from(this.jobs).map(job => job.description);\n }\n /**\n * Whether the manager is accepting new jobs.\n */\n get isOpen() {\n return this._state === types_1.BackgroundProcessManagerState.Open;\n }\n /**\n * Whether the manager is rejecting new work, but still waiting for\n * submitted work to complete.\n */\n get isClosing() {\n return this._state === types_1.BackgroundProcessManagerState.Closing;\n }\n /**\n * Whether the manager is rejecting work and done waiting for submitted\n * work to complete.\n */\n get isClosed() {\n return this._state === types_1.BackgroundProcessManagerState.Closed;\n }\n closedFailure(description) {\n if (!this.isOpen) {\n return Promise.reject(new BackgroundManagerNotOpenError_1.BackgroundManagerNotOpenError([\n `The manager is ${this.state}.`,\n `You tried to add \"${description}\".`,\n `Pending jobs: [\\n${this.pending\n .map(t => ' ' + t)\n .join(',\\n')}\\n]`,\n ].join('\\n')));\n }\n }\n /**\n * Signals jobs to stop (for those that accept interruptions) and waits\n * for confirmation that jobs have stopped.\n *\n * This immediately puts the manager into a closing state and just begins\n * to reject new work. After all work in the manager is complete, the\n * manager goes into a `Completed` state and `close()` returns.\n *\n * This call is idempotent.\n *\n * If the manager is already closing or closed, `finalCleaup` is not executed.\n *\n * @param onClosed\n * @returns The settled results of each still-running job's promise. If the\n * manager is already closed, this will contain the results as of when the\n * manager's `close()` was called in an `Open` state.\n */\n async close() {\n if (this.isOpen) {\n this._state = types_1.BackgroundProcessManagerState.Closing;\n for (const job of Array.from(this.jobs)) {\n try {\n job.terminate();\n }\n catch (error) {\n // Due to potential races with a job's natural completion, it's\n // reasonable to expect the termination call to fail. Hence,\n // not logging as an error.\n console.warn(`Failed to send termination signal to job. Error: ${error.message}`, job);\n }\n }\n // Use `allSettled()` because we want to wait for all to finish. We do\n // not want to stop waiting if there is a failure.\n this._closingPromise = Promise.allSettled(Array.from(this.jobs).map(j => j.promise));\n await this._closingPromise;\n this._state = types_1.BackgroundProcessManagerState.Closed;\n }\n return this._closingPromise;\n }\n /**\n * Signals the manager to start accepting work (again) and returns once\n * the manager is ready to do so.\n *\n * If the state is already `Open`, this call is a no-op.\n *\n * If the state is `Closed`, this call simply updates state and returns.\n *\n * If the state is `Closing`, this call waits for completion before it\n * updates the state and returns.\n */\n async open() {\n if (this.isClosing) {\n await this.close();\n }\n this._state = types_1.BackgroundProcessManagerState.Open;\n }\n}\nexports.BackgroundProcessManager = BackgroundProcessManager;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,wBAAwB,GAAG,MAAM;AACzC,MAAM,+BAA+B,GAAG,OAAO,CAAC,iCAAiC,CAAC;AAClF,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,wBAAwB,CAAC;AAC/B,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA,QAAQ,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,IAAI;AAChE;AACA;AACA;AACA,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE;AAC7B;AACA,IAAI,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,EAAE;AAC/C,QAAQ,IAAI,GAAG;AACf,QAAQ,IAAI,WAAW;AACvB,QAAQ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AAY,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,MAAM;AACtE;AACA,QAAQ,OAAO,IAAI,CAAC,eAAe;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE;AAC5B,YAAY,MAAM,IAAI,CAAC,KAAK,EAAE;AAC9B;AACA,QAAQ,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,IAAI;AAChE;AACA;AACA,OAAO,CAAC,wBAAwB,GAAG,wBAAwB;;"}
|
|
1
|
+
{"version":3,"file":"BackgroundProcessManager.js","sources":["../../../src/BackgroundProcessManager/BackgroundProcessManager.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.BackgroundProcessManager = void 0;\nconst BackgroundManagerNotOpenError_1 = require(\"./BackgroundManagerNotOpenError\");\nconst types_1 = require(\"./types\");\n/**\n * @private For internal Amplify use.\n *\n * Creates a new scope for promises, observables, and other types of work or\n * processes that may be running in the background. This manager provides\n * an singular entrypoint to request termination and await completion.\n *\n * As work completes on its own prior to close, the manager removes them\n * from the registry to avoid holding references to completed jobs.\n */\nclass BackgroundProcessManager {\n constructor() {\n /**\n * A string indicating whether the manager is accepting new work (\"Open\"),\n * waiting for work to complete (\"Closing\"), or fully done with all\n * submitted work and *not* accepting new jobs (\"Closed\").\n */\n this._state = types_1.BackgroundProcessManagerState.Open;\n /**\n * The list of outstanding jobs we'll need to wait for upon `close()`\n */\n this.jobs = new Set();\n }\n add(jobOrDescription, optionalDescription) {\n let job;\n let description;\n if (typeof jobOrDescription === 'string') {\n job = undefined;\n description = jobOrDescription;\n }\n else {\n job = jobOrDescription;\n description = optionalDescription;\n }\n const error = this.closedFailure(description);\n if (error)\n return error;\n if (job === undefined) {\n return this.addHook(description);\n }\n else if (typeof job === 'function') {\n return this.addFunction(job, description);\n }\n else if (job instanceof BackgroundProcessManager) {\n this.addManager(job, description);\n }\n else {\n throw new Error('If `job` is provided, it must be an Observable, Function, or BackgroundProcessManager.');\n }\n }\n /**\n * Adds a **cleaner** function that doesn't immediately get executed.\n * Instead, the caller gets a **terminate** function back. The *cleaner* is\n * invoked only once the mananger *closes* or the returned **terminate**\n * function is called.\n *\n * @param clean The cleanup function.\n * @param description Optional description to help identify pending jobs.\n * @returns A terminate function.\n */\n addCleaner(clean, description) {\n const { resolve, onTerminate } = this.addHook(description);\n const proxy = async () => {\n await clean();\n resolve();\n };\n onTerminate.then(proxy);\n return proxy;\n }\n addFunction(job, description) {\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n // finally! start the job.\n const jobResult = job(onTerminate);\n // depending on what the job gives back, register the result\n // so we can monitor for completion.\n if (typeof jobResult?.then === 'function') {\n this.registerPromise(jobResult, terminate, description);\n }\n // At the end of the day, or you know, method call, it doesn't matter\n // what the return value is at all; we just pass it through to the\n // caller.\n return jobResult;\n }\n addManager(manager, description) {\n this.addCleaner(async () => manager.close(), description);\n }\n /**\n * Creates and registers a fabricated job for processes that need to operate\n * with callbacks/hooks. The returned `resolve` and `reject`\n * functions can be used to signal the job is done successfully or not.\n * The returned `onTerminate` is a promise that will resolve when the\n * manager is requesting the termination of the job.\n *\n * @param description Optional description to help identify pending jobs.\n * @returns `{ resolve, reject, onTerminate }`\n */\n addHook(description) {\n // the resolve/reject functions we'll provide to the caller to signal\n // the state of the job.\n let promiseResolve;\n let promiseReject;\n // the underlying promise we'll use to manage it, pretty much like\n // any other promise.\n const promise = new Promise((resolve, reject) => {\n promiseResolve = resolve;\n promiseReject = reject;\n });\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n this.registerPromise(promise, terminate, description);\n return {\n resolve: promiseResolve,\n reject: promiseReject,\n onTerminate,\n };\n }\n /**\n * Adds a Promise based job to the list of jobs for monitoring and listens\n * for either a success or failure, upon which the job is considered \"done\"\n * and removed from the registry.\n *\n * @param promise A promise that is on its way to being returned to a\n * caller, which needs to be tracked as a background job.\n * @param terminate The termination function to register, which can be\n * invoked to request the job stop.\n * @param description Optional description to help identify pending jobs.\n */\n registerPromise(promise, terminate, description) {\n const jobEntry = { promise, terminate, description };\n this.jobs.add(jobEntry);\n // in all of my testing, it is safe to multi-subscribe to a promise.\n // so, rather than create another layer of promising, we're just going\n // to hook into the promise we already have, and when it's done\n // (successfully or not), we no longer need to wait for it upon close.\n //\n // sorry this is a bit hand-wavy:\n //\n // i believe we use `.then` and `.catch` instead of `.finally` because\n // `.finally` is invoked in a different order in the sequence, and this\n // breaks assumptions throughout and causes failures.\n promise\n .then(() => {\n this.jobs.delete(jobEntry);\n })\n .catch(() => {\n this.jobs.delete(jobEntry);\n });\n }\n /**\n * The number of jobs being waited on.\n *\n * We don't use this for anything. It's just informational for the caller,\n * and can be used in logging and testing.\n *\n * @returns the number of jobs.\n */\n get length() {\n return this.jobs.size;\n }\n /**\n * The execution state of the manager. One of:\n *\n * 1. \"Open\" -> Accepting new jobs\n * 1. \"Closing\" -> Not accepting new work. Waiting for jobs to complete.\n * 1. \"Closed\" -> Not accepting new work. All submitted jobs are complete.\n */\n get state() {\n return this._state;\n }\n /**\n * The registered `description` of all still-pending jobs.\n *\n * @returns descriptions as an array.\n */\n get pending() {\n return Array.from(this.jobs).map(job => job.description);\n }\n /**\n * Whether the manager is accepting new jobs.\n */\n get isOpen() {\n return this._state === types_1.BackgroundProcessManagerState.Open;\n }\n /**\n * Whether the manager is rejecting new work, but still waiting for\n * submitted work to complete.\n */\n get isClosing() {\n return this._state === types_1.BackgroundProcessManagerState.Closing;\n }\n /**\n * Whether the manager is rejecting work and done waiting for submitted\n * work to complete.\n */\n get isClosed() {\n return this._state === types_1.BackgroundProcessManagerState.Closed;\n }\n closedFailure(description) {\n if (!this.isOpen) {\n return Promise.reject(new BackgroundManagerNotOpenError_1.BackgroundManagerNotOpenError([\n `The manager is ${this.state}.`,\n `You tried to add \"${description}\".`,\n `Pending jobs: [\\n${this.pending\n .map(t => ' ' + t)\n .join(',\\n')}\\n]`,\n ].join('\\n')));\n }\n }\n /**\n * Signals jobs to stop (for those that accept interruptions) and waits\n * for confirmation that jobs have stopped.\n *\n * This immediately puts the manager into a closing state and just begins\n * to reject new work. After all work in the manager is complete, the\n * manager goes into a `Completed` state and `close()` returns.\n *\n * This call is idempotent.\n *\n * If the manager is already closing or closed, `finalCleaup` is not executed.\n *\n * @param onClosed\n * @returns The settled results of each still-running job's promise. If the\n * manager is already closed, this will contain the results as of when the\n * manager's `close()` was called in an `Open` state.\n */\n async close() {\n if (this.isOpen) {\n this._state = types_1.BackgroundProcessManagerState.Closing;\n for (const job of Array.from(this.jobs)) {\n try {\n job.terminate();\n }\n catch (error) {\n // Due to potential races with a job's natural completion, it's\n // reasonable to expect the termination call to fail. Hence,\n // not logging as an error.\n // eslint-disable-next-line no-console\n console.warn(`Failed to send termination signal to job. Error: ${error.message}`, job);\n }\n }\n // Use `allSettled()` because we want to wait for all to finish. We do\n // not want to stop waiting if there is a failure.\n this._closingPromise = Promise.allSettled(Array.from(this.jobs).map(j => j.promise));\n await this._closingPromise;\n this._state = types_1.BackgroundProcessManagerState.Closed;\n }\n return this._closingPromise;\n }\n /**\n * Signals the manager to start accepting work (again) and returns once\n * the manager is ready to do so.\n *\n * If the state is already `Open`, this call is a no-op.\n *\n * If the state is `Closed`, this call simply updates state and returns.\n *\n * If the state is `Closing`, this call waits for completion before it\n * updates the state and returns.\n */\n async open() {\n if (this.isClosing) {\n await this.close();\n }\n this._state = types_1.BackgroundProcessManagerState.Open;\n }\n}\nexports.BackgroundProcessManager = BackgroundProcessManager;\n"],"names":[],"mappings":";;AACA;AACA;A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E;AACzB,YAAY,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,OAAO;AACvE,YAAY,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACrD,gBAAgB,IAAI;AACpB,oBAAoB,GAAG,CAAC,SAAS,EAAE;AACnC;AACA,gBAAgB,OAAO,KAAK,EAAE;AAC9B;AACA;AACA;AACA;AACA,oBAAoB,OAAO,CAAC,IAAI,CAAC,CAAC,iDAAiD,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC;AAC1G;AACA;AACA;AACA;AACA,YAAY,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChG,YAAY,MAAM,IAAI,CAAC,eAAe;AACtC,YAAY,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,MAAM;AACtE;AACA,QAAQ,OAAO,IAAI,CAAC,eAAe;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE;AAC5B,YAAY,MAAM,IAAI,CAAC,KAAK,EAAE;AAC9B;AACA,QAAQ,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,IAAI;AAChE;AACA;AACA,OAAO,CAAC,wBAAwB,GAAG,wBAAwB;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConsoleLogger.js","sources":["../../../src/Logger/ConsoleLogger.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ConsoleLogger = void 0;\nconst constants_1 = require(\"../constants\");\nconst types_1 = require(\"./types\");\nconst LOG_LEVELS = {\n VERBOSE: 1,\n DEBUG: 2,\n INFO: 3,\n WARN: 4,\n ERROR: 5,\n NONE: 6,\n};\n/**\n * Write logs\n * @class Logger\n */\nclass ConsoleLogger {\n /**\n * @constructor\n * @param {string} name - Name of the logger\n */\n constructor(name, level = types_1.LogType.WARN) {\n this.name = name;\n this.level = level;\n this._pluggables = [];\n }\n _padding(n) {\n return n < 10 ? '0' + n : '' + n;\n }\n _ts() {\n const dt = new Date();\n return ([this._padding(dt.getMinutes()), this._padding(dt.getSeconds())].join(':') +\n '.' +\n dt.getMilliseconds());\n }\n configure(config) {\n if (!config)\n return this._config;\n this._config = config;\n return this._config;\n }\n /**\n * Write log\n * @method\n * @memeberof Logger\n * @param {LogType|string} type - log type, default INFO\n * @param {string|object} msg - Logging message or object\n */\n _log(type, ...msg) {\n let loggerLevelName = this.level;\n if (ConsoleLogger.LOG_LEVEL) {\n loggerLevelName = ConsoleLogger.LOG_LEVEL;\n }\n if (typeof window !== 'undefined' && window.LOG_LEVEL) {\n loggerLevelName = window.LOG_LEVEL;\n }\n const loggerLevel = LOG_LEVELS[loggerLevelName];\n const typeLevel = LOG_LEVELS[type];\n if (!(typeLevel >= loggerLevel)) {\n // Do nothing if type is not greater than or equal to logger level (handle undefined)\n return;\n }\n let log = console.log.bind(console);\n if (type === types_1.LogType.ERROR && console.error) {\n log = console.error.bind(console);\n }\n if (type === types_1.LogType.WARN && console.warn) {\n log = console.warn.bind(console);\n }\n if (ConsoleLogger.BIND_ALL_LOG_LEVELS) {\n if (type === types_1.LogType.INFO && console.info) {\n log = console.info.bind(console);\n }\n if (type === types_1.LogType.DEBUG && console.debug) {\n log = console.debug.bind(console);\n }\n }\n const prefix = `[${type}] ${this._ts()} ${this.name}`;\n let message = '';\n if (msg.length === 1 && typeof msg[0] === 'string') {\n message = `${prefix} - ${msg[0]}`;\n log(message);\n }\n else if (msg.length === 1) {\n message = `${prefix} ${msg[0]}`;\n log(prefix, msg[0]);\n }\n else if (typeof msg[0] === 'string') {\n let obj = msg.slice(1);\n if (obj.length === 1) {\n obj = obj[0];\n }\n message = `${prefix} - ${msg[0]} ${obj}`;\n log(`${prefix} - ${msg[0]}`, obj);\n }\n else {\n message = `${prefix} ${msg}`;\n log(prefix, msg);\n }\n for (const plugin of this._pluggables) {\n const logEvent = { message, timestamp: Date.now() };\n plugin.pushLogs([logEvent]);\n }\n }\n /**\n * Write General log. Default to INFO\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n log(...msg) {\n this._log(types_1.LogType.INFO, ...msg);\n }\n /**\n * Write INFO log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n info(...msg) {\n this._log(types_1.LogType.INFO, ...msg);\n }\n /**\n * Write WARN log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n warn(...msg) {\n this._log(types_1.LogType.WARN, ...msg);\n }\n /**\n * Write ERROR log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n error(...msg) {\n this._log(types_1.LogType.ERROR, ...msg);\n }\n /**\n * Write DEBUG log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n debug(...msg) {\n this._log(types_1.LogType.DEBUG, ...msg);\n }\n /**\n * Write VERBOSE log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n verbose(...msg) {\n this._log(types_1.LogType.VERBOSE, ...msg);\n }\n addPluggable(pluggable) {\n if (pluggable && pluggable.getCategoryName() === constants_1.AWS_CLOUDWATCH_CATEGORY) {\n this._pluggables.push(pluggable);\n pluggable.configure(this._config);\n }\n }\n listPluggables() {\n return this._pluggables;\n }\n}\nexports.ConsoleLogger = ConsoleLogger;\nConsoleLogger.LOG_LEVEL = null;\nConsoleLogger.BIND_ALL_LOG_LEVELS = false;\n"],"names":[],"mappings":";;AACA;AACA;AAC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K,CAAC,GAAG,GAAG,EAAE;AAClB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,CAAC,GAAG,GAAG,EAAE;AACpB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC;AAClD;AACA,IAAI,YAAY,CAAC,SAAS,EAAE;AAC5B,QAAQ,IAAI,SAAS,IAAI,SAAS,CAAC,eAAe,EAAE,KAAK,WAAW,CAAC,uBAAuB,EAAE;AAC9F,YAAY,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;AAC5C,YAAY,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;AAC7C;AACA;AACA,IAAI,cAAc,GAAG;AACrB,QAAQ,OAAO,IAAI,CAAC,WAAW;AAC/B;AACA;AACA,OAAO,CAAC,aAAa,GAAG,aAAa;AACrC,aAAa,CAAC,SAAS,GAAG,IAAI;AAC9B,aAAa,CAAC,mBAAmB,GAAG,KAAK;;"}
|
|
1
|
+
{"version":3,"file":"ConsoleLogger.js","sources":["../../../src/Logger/ConsoleLogger.ts"],"sourcesContent":["\"use strict\";\n/* eslint-disable no-console */\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ConsoleLogger = void 0;\nconst constants_1 = require(\"../constants\");\nconst types_1 = require(\"./types\");\nconst LOG_LEVELS = {\n VERBOSE: 1,\n DEBUG: 2,\n INFO: 3,\n WARN: 4,\n ERROR: 5,\n NONE: 6,\n};\n/**\n * Write logs\n * @class Logger\n */\nclass ConsoleLogger {\n /**\n * @constructor\n * @param {string} name - Name of the logger\n */\n constructor(name, level = types_1.LogType.WARN) {\n this.name = name;\n this.level = level;\n this._pluggables = [];\n }\n _padding(n) {\n return n < 10 ? '0' + n : '' + n;\n }\n _ts() {\n const dt = new Date();\n return ([this._padding(dt.getMinutes()), this._padding(dt.getSeconds())].join(':') +\n '.' +\n dt.getMilliseconds());\n }\n configure(config) {\n if (!config)\n return this._config;\n this._config = config;\n return this._config;\n }\n /**\n * Write log\n * @method\n * @memeberof Logger\n * @param {LogType|string} type - log type, default INFO\n * @param {string|object} msg - Logging message or object\n */\n _log(type, ...msg) {\n let loggerLevelName = this.level;\n if (ConsoleLogger.LOG_LEVEL) {\n loggerLevelName = ConsoleLogger.LOG_LEVEL;\n }\n if (typeof window !== 'undefined' && window.LOG_LEVEL) {\n loggerLevelName = window.LOG_LEVEL;\n }\n const loggerLevel = LOG_LEVELS[loggerLevelName];\n const typeLevel = LOG_LEVELS[type];\n if (!(typeLevel >= loggerLevel)) {\n // Do nothing if type is not greater than or equal to logger level (handle undefined)\n return;\n }\n let log = console.log.bind(console);\n if (type === types_1.LogType.ERROR && console.error) {\n log = console.error.bind(console);\n }\n if (type === types_1.LogType.WARN && console.warn) {\n log = console.warn.bind(console);\n }\n if (ConsoleLogger.BIND_ALL_LOG_LEVELS) {\n if (type === types_1.LogType.INFO && console.info) {\n log = console.info.bind(console);\n }\n if (type === types_1.LogType.DEBUG && console.debug) {\n log = console.debug.bind(console);\n }\n }\n const prefix = `[${type}] ${this._ts()} ${this.name}`;\n let message = '';\n if (msg.length === 1 && typeof msg[0] === 'string') {\n message = `${prefix} - ${msg[0]}`;\n log(message);\n }\n else if (msg.length === 1) {\n message = `${prefix} ${msg[0]}`;\n log(prefix, msg[0]);\n }\n else if (typeof msg[0] === 'string') {\n let obj = msg.slice(1);\n if (obj.length === 1) {\n obj = obj[0];\n }\n message = `${prefix} - ${msg[0]} ${obj}`;\n log(`${prefix} - ${msg[0]}`, obj);\n }\n else {\n message = `${prefix} ${msg}`;\n log(prefix, msg);\n }\n for (const plugin of this._pluggables) {\n const logEvent = { message, timestamp: Date.now() };\n plugin.pushLogs([logEvent]);\n }\n }\n /**\n * Write General log. Default to INFO\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n log(...msg) {\n this._log(types_1.LogType.INFO, ...msg);\n }\n /**\n * Write INFO log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n info(...msg) {\n this._log(types_1.LogType.INFO, ...msg);\n }\n /**\n * Write WARN log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n warn(...msg) {\n this._log(types_1.LogType.WARN, ...msg);\n }\n /**\n * Write ERROR log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n error(...msg) {\n this._log(types_1.LogType.ERROR, ...msg);\n }\n /**\n * Write DEBUG log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n debug(...msg) {\n this._log(types_1.LogType.DEBUG, ...msg);\n }\n /**\n * Write VERBOSE log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n verbose(...msg) {\n this._log(types_1.LogType.VERBOSE, ...msg);\n }\n addPluggable(pluggable) {\n if (pluggable && pluggable.getCategoryName() === constants_1.AWS_CLOUDWATCH_CATEGORY) {\n this._pluggables.push(pluggable);\n pluggable.configure(this._config);\n }\n }\n listPluggables() {\n return this._pluggables;\n }\n}\nexports.ConsoleLogger = ConsoleLogger;\nConsoleLogger.LOG_LEVEL = null;\nConsoleLogger.BIND_ALL_LOG_LEVELS = false;\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,aAAa,GAAG,MAAM;AAC9B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;AAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAClC,MAAM,UAAU,GAAG;AACnB,IAAI,OAAO,EAAE,CAAC;AACd,IAAI,K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D;AACA,IAAI,YAAY,CAAC,SAAS,EAAE;AAC5B,QAAQ,IAAI,SAAS,IAAI,SAAS,CAAC,eAAe,EAAE,KAAK,WAAW,CAAC,uBAAuB,EAAE;AAC9F,YAAY,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;AAC5C,YAAY,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;AAC7C;AACA;AACA,IAAI,cAAc,GAAG;AACrB,QAAQ,OAAO,IAAI,CAAC,WAAW;AAC/B;AACA;AACA,OAAO,CAAC,aAAa,GAAG,aAAa;AACrC,aAAa,CAAC,SAAS,GAAG,IAAI;AAC9B,aAAa,CAAC,mBAAmB,GAAG,KAAK;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../../../src/Platform/version.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.version = void 0;\n// generated by genversion\nexports.version = '6.13.6
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../../../src/Platform/version.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.version = void 0;\n// generated by genversion\nexports.version = '6.13.6';\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,OAAO,GAAG,MAAM;AACxB;AACA,OAAO,CAAC,OAAO,GAAG,QAAQ;;"}
|
|
@@ -248,6 +248,7 @@ class BackgroundProcessManager {
|
|
|
248
248
|
// Due to potential races with a job's natural completion, it's
|
|
249
249
|
// reasonable to expect the termination call to fail. Hence,
|
|
250
250
|
// not logging as an error.
|
|
251
|
+
// eslint-disable-next-line no-console
|
|
251
252
|
console.warn(`Failed to send termination signal to job. Error: ${error.message}`, job);
|
|
252
253
|
}
|
|
253
254
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackgroundProcessManager.mjs","sources":["../../../src/BackgroundProcessManager/BackgroundProcessManager.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BackgroundManagerNotOpenError } from './BackgroundManagerNotOpenError';\nimport { BackgroundProcessManagerState } from './types';\n/**\n * @private For internal Amplify use.\n *\n * Creates a new scope for promises, observables, and other types of work or\n * processes that may be running in the background. This manager provides\n * an singular entrypoint to request termination and await completion.\n *\n * As work completes on its own prior to close, the manager removes them\n * from the registry to avoid holding references to completed jobs.\n */\nexport class BackgroundProcessManager {\n constructor() {\n /**\n * A string indicating whether the manager is accepting new work (\"Open\"),\n * waiting for work to complete (\"Closing\"), or fully done with all\n * submitted work and *not* accepting new jobs (\"Closed\").\n */\n this._state = BackgroundProcessManagerState.Open;\n /**\n * The list of outstanding jobs we'll need to wait for upon `close()`\n */\n this.jobs = new Set();\n }\n add(jobOrDescription, optionalDescription) {\n let job;\n let description;\n if (typeof jobOrDescription === 'string') {\n job = undefined;\n description = jobOrDescription;\n }\n else {\n job = jobOrDescription;\n description = optionalDescription;\n }\n const error = this.closedFailure(description);\n if (error)\n return error;\n if (job === undefined) {\n return this.addHook(description);\n }\n else if (typeof job === 'function') {\n return this.addFunction(job, description);\n }\n else if (job instanceof BackgroundProcessManager) {\n this.addManager(job, description);\n }\n else {\n throw new Error('If `job` is provided, it must be an Observable, Function, or BackgroundProcessManager.');\n }\n }\n /**\n * Adds a **cleaner** function that doesn't immediately get executed.\n * Instead, the caller gets a **terminate** function back. The *cleaner* is\n * invoked only once the mananger *closes* or the returned **terminate**\n * function is called.\n *\n * @param clean The cleanup function.\n * @param description Optional description to help identify pending jobs.\n * @returns A terminate function.\n */\n addCleaner(clean, description) {\n const { resolve, onTerminate } = this.addHook(description);\n const proxy = async () => {\n await clean();\n resolve();\n };\n onTerminate.then(proxy);\n return proxy;\n }\n addFunction(job, description) {\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n // finally! start the job.\n const jobResult = job(onTerminate);\n // depending on what the job gives back, register the result\n // so we can monitor for completion.\n if (typeof jobResult?.then === 'function') {\n this.registerPromise(jobResult, terminate, description);\n }\n // At the end of the day, or you know, method call, it doesn't matter\n // what the return value is at all; we just pass it through to the\n // caller.\n return jobResult;\n }\n addManager(manager, description) {\n this.addCleaner(async () => manager.close(), description);\n }\n /**\n * Creates and registers a fabricated job for processes that need to operate\n * with callbacks/hooks. The returned `resolve` and `reject`\n * functions can be used to signal the job is done successfully or not.\n * The returned `onTerminate` is a promise that will resolve when the\n * manager is requesting the termination of the job.\n *\n * @param description Optional description to help identify pending jobs.\n * @returns `{ resolve, reject, onTerminate }`\n */\n addHook(description) {\n // the resolve/reject functions we'll provide to the caller to signal\n // the state of the job.\n let promiseResolve;\n let promiseReject;\n // the underlying promise we'll use to manage it, pretty much like\n // any other promise.\n const promise = new Promise((resolve, reject) => {\n promiseResolve = resolve;\n promiseReject = reject;\n });\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n this.registerPromise(promise, terminate, description);\n return {\n resolve: promiseResolve,\n reject: promiseReject,\n onTerminate,\n };\n }\n /**\n * Adds a Promise based job to the list of jobs for monitoring and listens\n * for either a success or failure, upon which the job is considered \"done\"\n * and removed from the registry.\n *\n * @param promise A promise that is on its way to being returned to a\n * caller, which needs to be tracked as a background job.\n * @param terminate The termination function to register, which can be\n * invoked to request the job stop.\n * @param description Optional description to help identify pending jobs.\n */\n registerPromise(promise, terminate, description) {\n const jobEntry = { promise, terminate, description };\n this.jobs.add(jobEntry);\n // in all of my testing, it is safe to multi-subscribe to a promise.\n // so, rather than create another layer of promising, we're just going\n // to hook into the promise we already have, and when it's done\n // (successfully or not), we no longer need to wait for it upon close.\n //\n // sorry this is a bit hand-wavy:\n //\n // i believe we use `.then` and `.catch` instead of `.finally` because\n // `.finally` is invoked in a different order in the sequence, and this\n // breaks assumptions throughout and causes failures.\n promise\n .then(() => {\n this.jobs.delete(jobEntry);\n })\n .catch(() => {\n this.jobs.delete(jobEntry);\n });\n }\n /**\n * The number of jobs being waited on.\n *\n * We don't use this for anything. It's just informational for the caller,\n * and can be used in logging and testing.\n *\n * @returns the number of jobs.\n */\n get length() {\n return this.jobs.size;\n }\n /**\n * The execution state of the manager. One of:\n *\n * 1. \"Open\" -> Accepting new jobs\n * 1. \"Closing\" -> Not accepting new work. Waiting for jobs to complete.\n * 1. \"Closed\" -> Not accepting new work. All submitted jobs are complete.\n */\n get state() {\n return this._state;\n }\n /**\n * The registered `description` of all still-pending jobs.\n *\n * @returns descriptions as an array.\n */\n get pending() {\n return Array.from(this.jobs).map(job => job.description);\n }\n /**\n * Whether the manager is accepting new jobs.\n */\n get isOpen() {\n return this._state === BackgroundProcessManagerState.Open;\n }\n /**\n * Whether the manager is rejecting new work, but still waiting for\n * submitted work to complete.\n */\n get isClosing() {\n return this._state === BackgroundProcessManagerState.Closing;\n }\n /**\n * Whether the manager is rejecting work and done waiting for submitted\n * work to complete.\n */\n get isClosed() {\n return this._state === BackgroundProcessManagerState.Closed;\n }\n closedFailure(description) {\n if (!this.isOpen) {\n return Promise.reject(new BackgroundManagerNotOpenError([\n `The manager is ${this.state}.`,\n `You tried to add \"${description}\".`,\n `Pending jobs: [\\n${this.pending\n .map(t => ' ' + t)\n .join(',\\n')}\\n]`,\n ].join('\\n')));\n }\n }\n /**\n * Signals jobs to stop (for those that accept interruptions) and waits\n * for confirmation that jobs have stopped.\n *\n * This immediately puts the manager into a closing state and just begins\n * to reject new work. After all work in the manager is complete, the\n * manager goes into a `Completed` state and `close()` returns.\n *\n * This call is idempotent.\n *\n * If the manager is already closing or closed, `finalCleaup` is not executed.\n *\n * @param onClosed\n * @returns The settled results of each still-running job's promise. If the\n * manager is already closed, this will contain the results as of when the\n * manager's `close()` was called in an `Open` state.\n */\n async close() {\n if (this.isOpen) {\n this._state = BackgroundProcessManagerState.Closing;\n for (const job of Array.from(this.jobs)) {\n try {\n job.terminate();\n }\n catch (error) {\n // Due to potential races with a job's natural completion, it's\n // reasonable to expect the termination call to fail. Hence,\n // not logging as an error.\n console.warn(`Failed to send termination signal to job. Error: ${error.message}`, job);\n }\n }\n // Use `allSettled()` because we want to wait for all to finish. We do\n // not want to stop waiting if there is a failure.\n this._closingPromise = Promise.allSettled(Array.from(this.jobs).map(j => j.promise));\n await this._closingPromise;\n this._state = BackgroundProcessManagerState.Closed;\n }\n return this._closingPromise;\n }\n /**\n * Signals the manager to start accepting work (again) and returns once\n * the manager is ready to do so.\n *\n * If the state is already `Open`, this call is a no-op.\n *\n * If the state is `Closed`, this call simply updates state and returns.\n *\n * If the state is `Closing`, this call waits for completion before it\n * updates the state and returns.\n */\n async open() {\n if (this.isClosing) {\n await this.close();\n }\n this._state = BackgroundProcessManagerState.Open;\n }\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,wBAAwB,CAAC;AACtC,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA,QAAQ,IAAI,CAAC,MAAM,GAAG,6BAA6B,CAAC,IAAI;AACxD;AACA;AACA;AACA,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE;AAC7B;AACA,IAAI,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,EAAE;AAC/C,QAAQ,IAAI,GAAG;AACf,QAAQ,IAAI,WAAW;AACvB,QAAQ,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE;AAClD,YAAY,GAAG,GAAG,SAAS;AAC3B,YAAY,WAAW,GAAG,gBAAgB;AAC1C;AACA,aAAa;AACb,YAAY,GAAG,GAAG,gBAAgB;AAClC,YAAY,WAAW,GAAG,mBAAmB;AAC7C;AACA,QAAQ,MAAM,KAAK,G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,IAAI,CAAC,MAAM,GAAG,6BAA6B,CAAC,IAAI;AACxD;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"BackgroundProcessManager.mjs","sources":["../../../src/BackgroundProcessManager/BackgroundProcessManager.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BackgroundManagerNotOpenError } from './BackgroundManagerNotOpenError';\nimport { BackgroundProcessManagerState } from './types';\n/**\n * @private For internal Amplify use.\n *\n * Creates a new scope for promises, observables, and other types of work or\n * processes that may be running in the background. This manager provides\n * an singular entrypoint to request termination and await completion.\n *\n * As work completes on its own prior to close, the manager removes them\n * from the registry to avoid holding references to completed jobs.\n */\nexport class BackgroundProcessManager {\n constructor() {\n /**\n * A string indicating whether the manager is accepting new work (\"Open\"),\n * waiting for work to complete (\"Closing\"), or fully done with all\n * submitted work and *not* accepting new jobs (\"Closed\").\n */\n this._state = BackgroundProcessManagerState.Open;\n /**\n * The list of outstanding jobs we'll need to wait for upon `close()`\n */\n this.jobs = new Set();\n }\n add(jobOrDescription, optionalDescription) {\n let job;\n let description;\n if (typeof jobOrDescription === 'string') {\n job = undefined;\n description = jobOrDescription;\n }\n else {\n job = jobOrDescription;\n description = optionalDescription;\n }\n const error = this.closedFailure(description);\n if (error)\n return error;\n if (job === undefined) {\n return this.addHook(description);\n }\n else if (typeof job === 'function') {\n return this.addFunction(job, description);\n }\n else if (job instanceof BackgroundProcessManager) {\n this.addManager(job, description);\n }\n else {\n throw new Error('If `job` is provided, it must be an Observable, Function, or BackgroundProcessManager.');\n }\n }\n /**\n * Adds a **cleaner** function that doesn't immediately get executed.\n * Instead, the caller gets a **terminate** function back. The *cleaner* is\n * invoked only once the mananger *closes* or the returned **terminate**\n * function is called.\n *\n * @param clean The cleanup function.\n * @param description Optional description to help identify pending jobs.\n * @returns A terminate function.\n */\n addCleaner(clean, description) {\n const { resolve, onTerminate } = this.addHook(description);\n const proxy = async () => {\n await clean();\n resolve();\n };\n onTerminate.then(proxy);\n return proxy;\n }\n addFunction(job, description) {\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n // finally! start the job.\n const jobResult = job(onTerminate);\n // depending on what the job gives back, register the result\n // so we can monitor for completion.\n if (typeof jobResult?.then === 'function') {\n this.registerPromise(jobResult, terminate, description);\n }\n // At the end of the day, or you know, method call, it doesn't matter\n // what the return value is at all; we just pass it through to the\n // caller.\n return jobResult;\n }\n addManager(manager, description) {\n this.addCleaner(async () => manager.close(), description);\n }\n /**\n * Creates and registers a fabricated job for processes that need to operate\n * with callbacks/hooks. The returned `resolve` and `reject`\n * functions can be used to signal the job is done successfully or not.\n * The returned `onTerminate` is a promise that will resolve when the\n * manager is requesting the termination of the job.\n *\n * @param description Optional description to help identify pending jobs.\n * @returns `{ resolve, reject, onTerminate }`\n */\n addHook(description) {\n // the resolve/reject functions we'll provide to the caller to signal\n // the state of the job.\n let promiseResolve;\n let promiseReject;\n // the underlying promise we'll use to manage it, pretty much like\n // any other promise.\n const promise = new Promise((resolve, reject) => {\n promiseResolve = resolve;\n promiseReject = reject;\n });\n // the function we call when we want to try to terminate this job.\n let terminate;\n // the promise the job can opt into listening to for termination.\n const onTerminate = new Promise(resolve => {\n terminate = resolve;\n });\n this.registerPromise(promise, terminate, description);\n return {\n resolve: promiseResolve,\n reject: promiseReject,\n onTerminate,\n };\n }\n /**\n * Adds a Promise based job to the list of jobs for monitoring and listens\n * for either a success or failure, upon which the job is considered \"done\"\n * and removed from the registry.\n *\n * @param promise A promise that is on its way to being returned to a\n * caller, which needs to be tracked as a background job.\n * @param terminate The termination function to register, which can be\n * invoked to request the job stop.\n * @param description Optional description to help identify pending jobs.\n */\n registerPromise(promise, terminate, description) {\n const jobEntry = { promise, terminate, description };\n this.jobs.add(jobEntry);\n // in all of my testing, it is safe to multi-subscribe to a promise.\n // so, rather than create another layer of promising, we're just going\n // to hook into the promise we already have, and when it's done\n // (successfully or not), we no longer need to wait for it upon close.\n //\n // sorry this is a bit hand-wavy:\n //\n // i believe we use `.then` and `.catch` instead of `.finally` because\n // `.finally` is invoked in a different order in the sequence, and this\n // breaks assumptions throughout and causes failures.\n promise\n .then(() => {\n this.jobs.delete(jobEntry);\n })\n .catch(() => {\n this.jobs.delete(jobEntry);\n });\n }\n /**\n * The number of jobs being waited on.\n *\n * We don't use this for anything. It's just informational for the caller,\n * and can be used in logging and testing.\n *\n * @returns the number of jobs.\n */\n get length() {\n return this.jobs.size;\n }\n /**\n * The execution state of the manager. One of:\n *\n * 1. \"Open\" -> Accepting new jobs\n * 1. \"Closing\" -> Not accepting new work. Waiting for jobs to complete.\n * 1. \"Closed\" -> Not accepting new work. All submitted jobs are complete.\n */\n get state() {\n return this._state;\n }\n /**\n * The registered `description` of all still-pending jobs.\n *\n * @returns descriptions as an array.\n */\n get pending() {\n return Array.from(this.jobs).map(job => job.description);\n }\n /**\n * Whether the manager is accepting new jobs.\n */\n get isOpen() {\n return this._state === BackgroundProcessManagerState.Open;\n }\n /**\n * Whether the manager is rejecting new work, but still waiting for\n * submitted work to complete.\n */\n get isClosing() {\n return this._state === BackgroundProcessManagerState.Closing;\n }\n /**\n * Whether the manager is rejecting work and done waiting for submitted\n * work to complete.\n */\n get isClosed() {\n return this._state === BackgroundProcessManagerState.Closed;\n }\n closedFailure(description) {\n if (!this.isOpen) {\n return Promise.reject(new BackgroundManagerNotOpenError([\n `The manager is ${this.state}.`,\n `You tried to add \"${description}\".`,\n `Pending jobs: [\\n${this.pending\n .map(t => ' ' + t)\n .join(',\\n')}\\n]`,\n ].join('\\n')));\n }\n }\n /**\n * Signals jobs to stop (for those that accept interruptions) and waits\n * for confirmation that jobs have stopped.\n *\n * This immediately puts the manager into a closing state and just begins\n * to reject new work. After all work in the manager is complete, the\n * manager goes into a `Completed` state and `close()` returns.\n *\n * This call is idempotent.\n *\n * If the manager is already closing or closed, `finalCleaup` is not executed.\n *\n * @param onClosed\n * @returns The settled results of each still-running job's promise. If the\n * manager is already closed, this will contain the results as of when the\n * manager's `close()` was called in an `Open` state.\n */\n async close() {\n if (this.isOpen) {\n this._state = BackgroundProcessManagerState.Closing;\n for (const job of Array.from(this.jobs)) {\n try {\n job.terminate();\n }\n catch (error) {\n // Due to potential races with a job's natural completion, it's\n // reasonable to expect the termination call to fail. Hence,\n // not logging as an error.\n // eslint-disable-next-line no-console\n console.warn(`Failed to send termination signal to job. Error: ${error.message}`, job);\n }\n }\n // Use `allSettled()` because we want to wait for all to finish. We do\n // not want to stop waiting if there is a failure.\n this._closingPromise = Promise.allSettled(Array.from(this.jobs).map(j => j.promise));\n await this._closingPromise;\n this._state = BackgroundProcessManagerState.Closed;\n }\n return this._closingPromise;\n }\n /**\n * Signals the manager to start accepting work (again) and returns once\n * the manager is ready to do so.\n *\n * If the state is already `Open`, this call is a no-op.\n *\n * If the state is `Closed`, this call simply updates state and returns.\n *\n * If the state is `Closing`, this call waits for completion before it\n * updates the state and returns.\n */\n async open() {\n if (this.isClosing) {\n await this.close();\n }\n this._state = BackgroundProcessManagerState.Open;\n }\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,wBAAwB,CAAC;AACtC,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA,QAAQ,IAAI,CAAC,MAAM,GAAG,6BAA6B,CAAC,IAAI;AACxD;AACA;AACA;AACA,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE;AAC7B;AACA,IAAI,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,EAAE;AAC/C,QAAQ,IAAI,GAAG;AACf,QAAQ,IAAI,WAAW;AACvB,QAAQ,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE;AAClD,YAAY,GAAG,GAAG,SAAS;AAC3B,YAAY,WAAW,GAAG,gBAAgB;AAC1C;AACA,aAAa;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jB,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE;AAC5B,YAAY,MAAM,IAAI,CAAC,KAAK,EAAE;AAC9B;AACA,QAAQ,IAAI,CAAC,MAAM,GAAG,6BAA6B,CAAC,IAAI;AACxD;AACA;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AWS_CLOUDWATCH_CATEGORY } from '../constants.mjs';
|
|
2
2
|
import { LogType } from './types.mjs';
|
|
3
3
|
|
|
4
|
+
/* eslint-disable no-console */
|
|
4
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
7
|
const LOG_LEVELS = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConsoleLogger.mjs","sources":["../../../src/Logger/ConsoleLogger.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AWS_CLOUDWATCH_CATEGORY } from '../constants';\nimport { LogType } from './types';\nconst LOG_LEVELS = {\n VERBOSE: 1,\n DEBUG: 2,\n INFO: 3,\n WARN: 4,\n ERROR: 5,\n NONE: 6,\n};\n/**\n * Write logs\n * @class Logger\n */\nexport class ConsoleLogger {\n /**\n * @constructor\n * @param {string} name - Name of the logger\n */\n constructor(name, level = LogType.WARN) {\n this.name = name;\n this.level = level;\n this._pluggables = [];\n }\n _padding(n) {\n return n < 10 ? '0' + n : '' + n;\n }\n _ts() {\n const dt = new Date();\n return ([this._padding(dt.getMinutes()), this._padding(dt.getSeconds())].join(':') +\n '.' +\n dt.getMilliseconds());\n }\n configure(config) {\n if (!config)\n return this._config;\n this._config = config;\n return this._config;\n }\n /**\n * Write log\n * @method\n * @memeberof Logger\n * @param {LogType|string} type - log type, default INFO\n * @param {string|object} msg - Logging message or object\n */\n _log(type, ...msg) {\n let loggerLevelName = this.level;\n if (ConsoleLogger.LOG_LEVEL) {\n loggerLevelName = ConsoleLogger.LOG_LEVEL;\n }\n if (typeof window !== 'undefined' && window.LOG_LEVEL) {\n loggerLevelName = window.LOG_LEVEL;\n }\n const loggerLevel = LOG_LEVELS[loggerLevelName];\n const typeLevel = LOG_LEVELS[type];\n if (!(typeLevel >= loggerLevel)) {\n // Do nothing if type is not greater than or equal to logger level (handle undefined)\n return;\n }\n let log = console.log.bind(console);\n if (type === LogType.ERROR && console.error) {\n log = console.error.bind(console);\n }\n if (type === LogType.WARN && console.warn) {\n log = console.warn.bind(console);\n }\n if (ConsoleLogger.BIND_ALL_LOG_LEVELS) {\n if (type === LogType.INFO && console.info) {\n log = console.info.bind(console);\n }\n if (type === LogType.DEBUG && console.debug) {\n log = console.debug.bind(console);\n }\n }\n const prefix = `[${type}] ${this._ts()} ${this.name}`;\n let message = '';\n if (msg.length === 1 && typeof msg[0] === 'string') {\n message = `${prefix} - ${msg[0]}`;\n log(message);\n }\n else if (msg.length === 1) {\n message = `${prefix} ${msg[0]}`;\n log(prefix, msg[0]);\n }\n else if (typeof msg[0] === 'string') {\n let obj = msg.slice(1);\n if (obj.length === 1) {\n obj = obj[0];\n }\n message = `${prefix} - ${msg[0]} ${obj}`;\n log(`${prefix} - ${msg[0]}`, obj);\n }\n else {\n message = `${prefix} ${msg}`;\n log(prefix, msg);\n }\n for (const plugin of this._pluggables) {\n const logEvent = { message, timestamp: Date.now() };\n plugin.pushLogs([logEvent]);\n }\n }\n /**\n * Write General log. Default to INFO\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n log(...msg) {\n this._log(LogType.INFO, ...msg);\n }\n /**\n * Write INFO log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n info(...msg) {\n this._log(LogType.INFO, ...msg);\n }\n /**\n * Write WARN log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n warn(...msg) {\n this._log(LogType.WARN, ...msg);\n }\n /**\n * Write ERROR log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n error(...msg) {\n this._log(LogType.ERROR, ...msg);\n }\n /**\n * Write DEBUG log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n debug(...msg) {\n this._log(LogType.DEBUG, ...msg);\n }\n /**\n * Write VERBOSE log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n verbose(...msg) {\n this._log(LogType.VERBOSE, ...msg);\n }\n addPluggable(pluggable) {\n if (pluggable && pluggable.getCategoryName() === AWS_CLOUDWATCH_CATEGORY) {\n this._pluggables.push(pluggable);\n pluggable.configure(this._config);\n }\n }\n listPluggables() {\n return this._pluggables;\n }\n}\nConsoleLogger.LOG_LEVEL = null;\nConsoleLogger.BIND_ALL_LOG_LEVELS = false;\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA,MAAM,UAAU,GAAG;AACnB,IAAI,OAAO,EAAE,CAAC;AACd,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,EAAE,CAAC;AACX,CAAC;AACD;AACA;AACA;AACA;AACO,MAAM,aAAa,CAAC;AAC3B;AACA;AACA;AACA;AACA,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE;AAC5C,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI;AACxB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK;AAC1B,QAAQ,IAAI,CAAC,WAAW,GAAG,EAAE;AAC7B;AACA,IAAI,QAAQ,CAAC,CAAC,EAAE;AAChB,QAAQ,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;AACxC;AACA,IAAI,GAAG,GAAG;AACV,QAAQ,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE;AAC7B,QAAQ,QAAQ,CAAC,IAAI,CAAC,QAAQ,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IAAI,KAAK,CAAC,GAAG,GAAG,EAAE;AAClB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,GAAG,GAAG,EAAE;AAClB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,CAAC,GAAG,GAAG,EAAE;AACpB,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC;AAC1C;AACA,IAAI,YAAY,CAAC,SAAS,EAAE;AAC5B,QAAQ,IAAI,SAAS,IAAI,SAAS,CAAC,eAAe,EAAE,KAAK,uBAAuB,EAAE;AAClF,YAAY,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;AAC5C,YAAY,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;AAC7C;AACA;AACA,IAAI,cAAc,GAAG;AACrB,QAAQ,OAAO,IAAI,CAAC,WAAW;AAC/B;AACA;AACA,aAAa,CAAC,SAAS,GAAG,IAAI;AAC9B,aAAa,CAAC,mBAAmB,GAAG,KAAK;;;;"}
|
|
1
|
+
{"version":3,"file":"ConsoleLogger.mjs","sources":["../../../src/Logger/ConsoleLogger.ts"],"sourcesContent":["/* eslint-disable no-console */\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AWS_CLOUDWATCH_CATEGORY } from '../constants';\nimport { LogType } from './types';\nconst LOG_LEVELS = {\n VERBOSE: 1,\n DEBUG: 2,\n INFO: 3,\n WARN: 4,\n ERROR: 5,\n NONE: 6,\n};\n/**\n * Write logs\n * @class Logger\n */\nexport class ConsoleLogger {\n /**\n * @constructor\n * @param {string} name - Name of the logger\n */\n constructor(name, level = LogType.WARN) {\n this.name = name;\n this.level = level;\n this._pluggables = [];\n }\n _padding(n) {\n return n < 10 ? '0' + n : '' + n;\n }\n _ts() {\n const dt = new Date();\n return ([this._padding(dt.getMinutes()), this._padding(dt.getSeconds())].join(':') +\n '.' +\n dt.getMilliseconds());\n }\n configure(config) {\n if (!config)\n return this._config;\n this._config = config;\n return this._config;\n }\n /**\n * Write log\n * @method\n * @memeberof Logger\n * @param {LogType|string} type - log type, default INFO\n * @param {string|object} msg - Logging message or object\n */\n _log(type, ...msg) {\n let loggerLevelName = this.level;\n if (ConsoleLogger.LOG_LEVEL) {\n loggerLevelName = ConsoleLogger.LOG_LEVEL;\n }\n if (typeof window !== 'undefined' && window.LOG_LEVEL) {\n loggerLevelName = window.LOG_LEVEL;\n }\n const loggerLevel = LOG_LEVELS[loggerLevelName];\n const typeLevel = LOG_LEVELS[type];\n if (!(typeLevel >= loggerLevel)) {\n // Do nothing if type is not greater than or equal to logger level (handle undefined)\n return;\n }\n let log = console.log.bind(console);\n if (type === LogType.ERROR && console.error) {\n log = console.error.bind(console);\n }\n if (type === LogType.WARN && console.warn) {\n log = console.warn.bind(console);\n }\n if (ConsoleLogger.BIND_ALL_LOG_LEVELS) {\n if (type === LogType.INFO && console.info) {\n log = console.info.bind(console);\n }\n if (type === LogType.DEBUG && console.debug) {\n log = console.debug.bind(console);\n }\n }\n const prefix = `[${type}] ${this._ts()} ${this.name}`;\n let message = '';\n if (msg.length === 1 && typeof msg[0] === 'string') {\n message = `${prefix} - ${msg[0]}`;\n log(message);\n }\n else if (msg.length === 1) {\n message = `${prefix} ${msg[0]}`;\n log(prefix, msg[0]);\n }\n else if (typeof msg[0] === 'string') {\n let obj = msg.slice(1);\n if (obj.length === 1) {\n obj = obj[0];\n }\n message = `${prefix} - ${msg[0]} ${obj}`;\n log(`${prefix} - ${msg[0]}`, obj);\n }\n else {\n message = `${prefix} ${msg}`;\n log(prefix, msg);\n }\n for (const plugin of this._pluggables) {\n const logEvent = { message, timestamp: Date.now() };\n plugin.pushLogs([logEvent]);\n }\n }\n /**\n * Write General log. Default to INFO\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n log(...msg) {\n this._log(LogType.INFO, ...msg);\n }\n /**\n * Write INFO log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n info(...msg) {\n this._log(LogType.INFO, ...msg);\n }\n /**\n * Write WARN log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n warn(...msg) {\n this._log(LogType.WARN, ...msg);\n }\n /**\n * Write ERROR log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n error(...msg) {\n this._log(LogType.ERROR, ...msg);\n }\n /**\n * Write DEBUG log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n debug(...msg) {\n this._log(LogType.DEBUG, ...msg);\n }\n /**\n * Write VERBOSE log\n * @method\n * @memeberof Logger\n * @param {string|object} msg - Logging message or object\n */\n verbose(...msg) {\n this._log(LogType.VERBOSE, ...msg);\n }\n addPluggable(pluggable) {\n if (pluggable && pluggable.getCategoryName() === AWS_CLOUDWATCH_CATEGORY) {\n this._pluggables.push(pluggable);\n pluggable.configure(this._config);\n }\n }\n listPluggables() {\n return this._pluggables;\n }\n}\nConsoleLogger.LOG_LEVEL = null;\nConsoleLogger.BIND_ALL_LOG_LEVELS = false;\n"],"names":[],"mappings":";;;AAAA;AACA;AACA;AAGA,MAAM,UAAU,GAAG;AACnB,IAAI,OAAO,EAAE,CAAC;AACd,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,KAAK,EAAE,CAAC;AACZ,IAAI,IAAI,EAAE,CAAC;AACX,CAAC;AACD;AACA;AACA;AACA;AACO,MAAM,aAAa,CAAC;AAC3B;AACA;AACA;AACA;AACA,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CA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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "6.13.6
|
|
1
|
+
export declare const version = "6.13.6";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","sources":["../../../src/Platform/version.ts"],"sourcesContent":["// generated by genversion\nexport const version = '6.13.6
|
|
1
|
+
{"version":3,"file":"version.mjs","sources":["../../../src/Platform/version.ts"],"sourcesContent":["// generated by genversion\nexport const version = '6.13.6';\n"],"names":[],"mappings":"AAAA;AACY,MAAC,OAAO,GAAG;;;;"}
|
|
@@ -10,12 +10,10 @@ export interface AmplifyErrorParams<ErrorCode extends string = string> {
|
|
|
10
10
|
recoverySuggestion?: string;
|
|
11
11
|
underlyingError?: Error | unknown;
|
|
12
12
|
}
|
|
13
|
-
export type AmplifyErrorMap<ErrorCode extends string = string> = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
};
|
|
13
|
+
export type AmplifyErrorMap<ErrorCode extends string = string> = Record<ErrorCode, {
|
|
14
|
+
message: string;
|
|
15
|
+
recoverySuggestion?: string;
|
|
16
|
+
}>;
|
|
19
17
|
export interface ServiceError {
|
|
20
18
|
name: string;
|
|
21
19
|
message: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/core",
|
|
3
|
-
"version": "6.10.6
|
|
3
|
+
"version": "6.10.6",
|
|
4
4
|
"description": "Core category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"uuid": "^9.0.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@aws-amplify/react-native": "1.1.
|
|
63
|
+
"@aws-amplify/react-native": "1.1.7",
|
|
64
64
|
"@types/js-cookie": "3.0.2",
|
|
65
65
|
"genversion": "^2.2.0",
|
|
66
66
|
"typescript": "5.0.2"
|
|
@@ -192,5 +192,5 @@
|
|
|
192
192
|
]
|
|
193
193
|
}
|
|
194
194
|
},
|
|
195
|
-
"gitHead": "
|
|
195
|
+
"gitHead": "52d159e1d01615d17689ca4710110759e2bb82c8"
|
|
196
196
|
}
|
|
@@ -373,6 +373,7 @@ export class BackgroundProcessManager {
|
|
|
373
373
|
// Due to potential races with a job's natural completion, it's
|
|
374
374
|
// reasonable to expect the termination call to fail. Hence,
|
|
375
375
|
// not logging as an error.
|
|
376
|
+
// eslint-disable-next-line no-console
|
|
376
377
|
console.warn(
|
|
377
378
|
`Failed to send termination signal to job. Error: ${
|
|
378
379
|
(error as Error).message
|
package/src/Platform/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '6.13.6
|
|
2
|
+
export const version = '6.13.6';
|
package/src/types/errors.ts
CHANGED
|
@@ -15,12 +15,13 @@ export interface AmplifyErrorParams<ErrorCode extends string = string> {
|
|
|
15
15
|
underlyingError?: Error | unknown;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export type AmplifyErrorMap<ErrorCode extends string = string> =
|
|
19
|
-
|
|
18
|
+
export type AmplifyErrorMap<ErrorCode extends string = string> = Record<
|
|
19
|
+
ErrorCode,
|
|
20
|
+
{
|
|
20
21
|
message: string;
|
|
21
22
|
recoverySuggestion?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
23
|
+
}
|
|
24
|
+
>;
|
|
24
25
|
|
|
25
26
|
export interface ServiceError {
|
|
26
27
|
name: string;
|