fix: 修复配额说明重复和undefined问题
- 在editStorageForm中初始化oss_storage_quota_value和oss_quota_unit - 删除重复的旧配额说明块,保留新的当前配额设置显示 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
175
backend/node_modules/@aws/lambda-invoke-store/LICENSE
generated
vendored
Normal file
175
backend/node_modules/@aws/lambda-invoke-store/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
198
backend/node_modules/@aws/lambda-invoke-store/README.md
generated
vendored
Normal file
198
backend/node_modules/@aws/lambda-invoke-store/README.md
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
# Node.js Invoke Store for AWS Lambda
|
||||
|
||||
`@aws/lambda-invoke-store` provides a generic, per-invocation context store for
|
||||
AWS Lambda Node.js Runtime Environment. It enables storing and retrieving data
|
||||
within the scope of a single Lambda invocation, with proper isolation between
|
||||
concurrent executions.
|
||||
|
||||
## Features
|
||||
|
||||
- **Invocation Isolation**: Safely store and retrieve data within a single Lambda invocation.
|
||||
- **Protected Lambda Context**: Built-in protection for Lambda execution metadata (requestId, [traceId](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces))
|
||||
- **Custom Data Storage**: Store any custom data within the invocation context
|
||||
- **Async/Await Support**: Full support for asynchronous operations with context preservation
|
||||
- **Type Safety**: Complete TypeScript type definitions
|
||||
- **Singleton Pattern**: Ensures a single shared instance across all imports
|
||||
- **Global Namespace Integration**: Integrates with the Lambda runtime global namespace
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install @aws/lambda-invoke-store
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
> **Note**: In the AWS Lambda environment, the Runtime Interface Client (RIC) automatically initializes the InvokeStore context at the beginning of each invocation. Lambda function developers typically don't need to call `InvokeStore.run()` directly.
|
||||
|
||||
```typescript
|
||||
import { InvokeStore } from "@aws/lambda-invoke-store";
|
||||
|
||||
// Lambda handler with invoke store
|
||||
export const handler = async (event, context) => {
|
||||
// The RIC has already initialized the InvokeStore with requestId and X-Ray traceId
|
||||
|
||||
// Access Lambda context data
|
||||
const invokeStore = await InvokeStore.getInstanceAsync();
|
||||
console.log(`Processing request: ${invokeStore.getRequestId()}`);
|
||||
|
||||
// Store custom data
|
||||
invokeStore.set("userId", event.userId);
|
||||
|
||||
// Data persists across async operations
|
||||
await processData(event);
|
||||
|
||||
// Retrieve custom data
|
||||
const userId = invokeStore.get("userId");
|
||||
|
||||
return {
|
||||
requestId: invokeStore.getRequestId(),
|
||||
userId,
|
||||
};
|
||||
};
|
||||
|
||||
// Context is preserved in async operations
|
||||
async function processData(event) {
|
||||
// Still has access to the same invoke context
|
||||
const invokeStore = await InvokeStore.getInstanceAsync();
|
||||
console.log(`Processing in same context: ${invokeStore.getRequestId()}`);
|
||||
|
||||
// Can set additional data
|
||||
invokeStore.set("processedData", { result: "success" });
|
||||
}
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### InvokeStore.getInstanceAsync()
|
||||
First, get an instance of the InvokeStore:
|
||||
```typescript
|
||||
const invokeStore = await InvokeStore.getInstanceAsync();
|
||||
```
|
||||
|
||||
### invokeStore.getContext()
|
||||
|
||||
Returns the complete current context or `undefined` if outside a context.
|
||||
|
||||
```typescript
|
||||
const context = invokeStore.getContext();
|
||||
```
|
||||
|
||||
### invokeStore.get(key)
|
||||
|
||||
Gets a value from the current context.
|
||||
|
||||
```typescript
|
||||
const requestId = invokeStore.get(InvokeStoreBase.PROTECTED_KEYS.REQUEST_ID);
|
||||
const customValue = invokeStore.get("customKey");
|
||||
```
|
||||
|
||||
### invokeStore.set(key, value)
|
||||
|
||||
Sets a custom value in the current context. Protected Lambda fields cannot be modified.
|
||||
|
||||
```typescript
|
||||
invokeStore.set("userId", "user-123");
|
||||
invokeStore.set("timestamp", Date.now());
|
||||
|
||||
// This will throw an error:
|
||||
// invokeStore.set(InvokeStoreBase.PROTECTED_KEYS.REQUEST_ID, 'new-id');
|
||||
```
|
||||
|
||||
### invokeStore.getRequestId()
|
||||
|
||||
Convenience method to get the current request ID.
|
||||
|
||||
```typescript
|
||||
const requestId = invokeStore.getRequestId(); // Returns '-' if outside context
|
||||
```
|
||||
|
||||
### invokeStore.getTenantId()
|
||||
|
||||
Convenience method to get the tenant ID.
|
||||
|
||||
```typescript
|
||||
const requestId = invokeStore.getTenantId();
|
||||
```
|
||||
|
||||
### invokeStore.getXRayTraceId()
|
||||
|
||||
Convenience method to get the current [X-Ray trace ID](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces). This ID is used for distributed tracing across AWS services.
|
||||
|
||||
```typescript
|
||||
const traceId = invokeStore.getXRayTraceId(); // Returns undefined if not set or outside context
|
||||
```
|
||||
|
||||
### invokeStore.hasContext()
|
||||
|
||||
Checks if code is currently running within an invoke context.
|
||||
|
||||
```typescript
|
||||
if (invokeStore.hasContext()) {
|
||||
// We're inside an invoke context
|
||||
}
|
||||
```
|
||||
|
||||
### invokeStore.run(context, fn)
|
||||
|
||||
> **Note**: This method is primarily used by the Lambda Runtime Interface Client (RIC) to initialize the context for each invocation. Lambda function developers typically don't need to call this method directly.
|
||||
|
||||
Runs a function within an invoke context.
|
||||
|
||||
```typescript
|
||||
invokeStore.run(
|
||||
{
|
||||
[InvokeStoreBase.PROTECTED_KEYS.REQUEST_ID]: "request-123",
|
||||
[InvokeStoreBase.PROTECTED_KEYS.X_RAY_TRACE_ID]: "trace-456", // Optional X-Ray trace ID
|
||||
customField: "value", // Optional custom fields
|
||||
},
|
||||
() => {
|
||||
// Function to execute within context
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
## Integration with AWS Lambda Runtime
|
||||
|
||||
The `@aws/lambda-invoke-store` package is designed to be integrated with the AWS Lambda Node.js Runtime Interface Client (RIC). The RIC automatically:
|
||||
|
||||
1. Initializes the InvokeStore context at the beginning of each Lambda invocation
|
||||
2. Sets the `requestId` and [X-Ray `traceId`](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces) in the context
|
||||
3. Ensures proper context isolation between concurrent invocations
|
||||
4. Cleans up the context after the invocation completes
|
||||
|
||||
Lambda function developers can focus on using the context without worrying about initialization or cleanup.
|
||||
|
||||
## Global Namespace and Singleton Pattern
|
||||
|
||||
The InvokeStore uses a singleton pattern to ensure that all imports of the module use the same instance, which is critical for maintaining proper context isolation across different parts of your application.
|
||||
|
||||
### Global Namespace Integration
|
||||
|
||||
The InvokeStore integrates with the Lambda runtime's global namespace:
|
||||
|
||||
```typescript
|
||||
// The InvokeStore is available globally
|
||||
const globalInstance = globalThis.awslambda.InvokeStore;
|
||||
```
|
||||
|
||||
This enables seamless integration between the Lambda Runtime Interface Client (RIC), AWS SDK, and your function code, ensuring they all share the same context.
|
||||
|
||||
### Environment Variable Opt-Out
|
||||
|
||||
If you prefer not to modify the global namespace, you can opt out by setting the environment variable:
|
||||
|
||||
```bash
|
||||
# Disable global namespace modification
|
||||
AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA=1
|
||||
```
|
||||
|
||||
When this environment variable is set, the InvokeStore will still function correctly, but it won't be stored in the global namespace.
|
||||
|
||||
## Security
|
||||
|
||||
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the Apache-2.0 License.
|
||||
119
backend/node_modules/@aws/lambda-invoke-store/dist-cjs/invoke-store.js
generated
vendored
Normal file
119
backend/node_modules/@aws/lambda-invoke-store/dist-cjs/invoke-store.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
'use strict';
|
||||
|
||||
const PROTECTED_KEYS = {
|
||||
REQUEST_ID: Symbol.for("_AWS_LAMBDA_REQUEST_ID"),
|
||||
X_RAY_TRACE_ID: Symbol.for("_AWS_LAMBDA_X_RAY_TRACE_ID"),
|
||||
TENANT_ID: Symbol.for("_AWS_LAMBDA_TENANT_ID"),
|
||||
};
|
||||
const NO_GLOBAL_AWS_LAMBDA = ["true", "1"].includes(process.env?.AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA ?? "");
|
||||
if (!NO_GLOBAL_AWS_LAMBDA) {
|
||||
globalThis.awslambda = globalThis.awslambda || {};
|
||||
}
|
||||
class InvokeStoreBase {
|
||||
static PROTECTED_KEYS = PROTECTED_KEYS;
|
||||
isProtectedKey(key) {
|
||||
return Object.values(PROTECTED_KEYS).includes(key);
|
||||
}
|
||||
getRequestId() {
|
||||
return this.get(PROTECTED_KEYS.REQUEST_ID) ?? "-";
|
||||
}
|
||||
getXRayTraceId() {
|
||||
return this.get(PROTECTED_KEYS.X_RAY_TRACE_ID);
|
||||
}
|
||||
getTenantId() {
|
||||
return this.get(PROTECTED_KEYS.TENANT_ID);
|
||||
}
|
||||
}
|
||||
class InvokeStoreSingle extends InvokeStoreBase {
|
||||
currentContext;
|
||||
getContext() {
|
||||
return this.currentContext;
|
||||
}
|
||||
hasContext() {
|
||||
return this.currentContext !== undefined;
|
||||
}
|
||||
get(key) {
|
||||
return this.currentContext?.[key];
|
||||
}
|
||||
set(key, value) {
|
||||
if (this.isProtectedKey(key)) {
|
||||
throw new Error(`Cannot modify protected Lambda context field: ${String(key)}`);
|
||||
}
|
||||
this.currentContext = this.currentContext || {};
|
||||
this.currentContext[key] = value;
|
||||
}
|
||||
run(context, fn) {
|
||||
this.currentContext = context;
|
||||
return fn();
|
||||
}
|
||||
}
|
||||
class InvokeStoreMulti extends InvokeStoreBase {
|
||||
als;
|
||||
static async create() {
|
||||
const instance = new InvokeStoreMulti();
|
||||
const asyncHooks = await import('node:async_hooks');
|
||||
instance.als = new asyncHooks.AsyncLocalStorage();
|
||||
return instance;
|
||||
}
|
||||
getContext() {
|
||||
return this.als.getStore();
|
||||
}
|
||||
hasContext() {
|
||||
return this.als.getStore() !== undefined;
|
||||
}
|
||||
get(key) {
|
||||
return this.als.getStore()?.[key];
|
||||
}
|
||||
set(key, value) {
|
||||
if (this.isProtectedKey(key)) {
|
||||
throw new Error(`Cannot modify protected Lambda context field: ${String(key)}`);
|
||||
}
|
||||
const store = this.als.getStore();
|
||||
if (!store) {
|
||||
throw new Error("No context available");
|
||||
}
|
||||
store[key] = value;
|
||||
}
|
||||
run(context, fn) {
|
||||
return this.als.run(context, fn);
|
||||
}
|
||||
}
|
||||
exports.InvokeStore = void 0;
|
||||
(function (InvokeStore) {
|
||||
let instance = null;
|
||||
async function getInstanceAsync() {
|
||||
if (!instance) {
|
||||
instance = (async () => {
|
||||
const isMulti = "AWS_LAMBDA_MAX_CONCURRENCY" in process.env;
|
||||
const newInstance = isMulti
|
||||
? await InvokeStoreMulti.create()
|
||||
: new InvokeStoreSingle();
|
||||
if (!NO_GLOBAL_AWS_LAMBDA && globalThis.awslambda?.InvokeStore) {
|
||||
return globalThis.awslambda.InvokeStore;
|
||||
}
|
||||
else if (!NO_GLOBAL_AWS_LAMBDA && globalThis.awslambda) {
|
||||
globalThis.awslambda.InvokeStore = newInstance;
|
||||
return newInstance;
|
||||
}
|
||||
else {
|
||||
return newInstance;
|
||||
}
|
||||
})();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
InvokeStore.getInstanceAsync = getInstanceAsync;
|
||||
InvokeStore._testing = process.env.AWS_LAMBDA_BENCHMARK_MODE === "1"
|
||||
? {
|
||||
reset: () => {
|
||||
instance = null;
|
||||
if (globalThis.awslambda?.InvokeStore) {
|
||||
delete globalThis.awslambda.InvokeStore;
|
||||
}
|
||||
globalThis.awslambda = { InvokeStore: undefined };
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
})(exports.InvokeStore || (exports.InvokeStore = {}));
|
||||
|
||||
exports.InvokeStoreBase = InvokeStoreBase;
|
||||
117
backend/node_modules/@aws/lambda-invoke-store/dist-es/invoke-store.js
generated
vendored
Normal file
117
backend/node_modules/@aws/lambda-invoke-store/dist-es/invoke-store.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
const PROTECTED_KEYS = {
|
||||
REQUEST_ID: Symbol.for("_AWS_LAMBDA_REQUEST_ID"),
|
||||
X_RAY_TRACE_ID: Symbol.for("_AWS_LAMBDA_X_RAY_TRACE_ID"),
|
||||
TENANT_ID: Symbol.for("_AWS_LAMBDA_TENANT_ID"),
|
||||
};
|
||||
const NO_GLOBAL_AWS_LAMBDA = ["true", "1"].includes(process.env?.AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA ?? "");
|
||||
if (!NO_GLOBAL_AWS_LAMBDA) {
|
||||
globalThis.awslambda = globalThis.awslambda || {};
|
||||
}
|
||||
class InvokeStoreBase {
|
||||
static PROTECTED_KEYS = PROTECTED_KEYS;
|
||||
isProtectedKey(key) {
|
||||
return Object.values(PROTECTED_KEYS).includes(key);
|
||||
}
|
||||
getRequestId() {
|
||||
return this.get(PROTECTED_KEYS.REQUEST_ID) ?? "-";
|
||||
}
|
||||
getXRayTraceId() {
|
||||
return this.get(PROTECTED_KEYS.X_RAY_TRACE_ID);
|
||||
}
|
||||
getTenantId() {
|
||||
return this.get(PROTECTED_KEYS.TENANT_ID);
|
||||
}
|
||||
}
|
||||
class InvokeStoreSingle extends InvokeStoreBase {
|
||||
currentContext;
|
||||
getContext() {
|
||||
return this.currentContext;
|
||||
}
|
||||
hasContext() {
|
||||
return this.currentContext !== undefined;
|
||||
}
|
||||
get(key) {
|
||||
return this.currentContext?.[key];
|
||||
}
|
||||
set(key, value) {
|
||||
if (this.isProtectedKey(key)) {
|
||||
throw new Error(`Cannot modify protected Lambda context field: ${String(key)}`);
|
||||
}
|
||||
this.currentContext = this.currentContext || {};
|
||||
this.currentContext[key] = value;
|
||||
}
|
||||
run(context, fn) {
|
||||
this.currentContext = context;
|
||||
return fn();
|
||||
}
|
||||
}
|
||||
class InvokeStoreMulti extends InvokeStoreBase {
|
||||
als;
|
||||
static async create() {
|
||||
const instance = new InvokeStoreMulti();
|
||||
const asyncHooks = await import('node:async_hooks');
|
||||
instance.als = new asyncHooks.AsyncLocalStorage();
|
||||
return instance;
|
||||
}
|
||||
getContext() {
|
||||
return this.als.getStore();
|
||||
}
|
||||
hasContext() {
|
||||
return this.als.getStore() !== undefined;
|
||||
}
|
||||
get(key) {
|
||||
return this.als.getStore()?.[key];
|
||||
}
|
||||
set(key, value) {
|
||||
if (this.isProtectedKey(key)) {
|
||||
throw new Error(`Cannot modify protected Lambda context field: ${String(key)}`);
|
||||
}
|
||||
const store = this.als.getStore();
|
||||
if (!store) {
|
||||
throw new Error("No context available");
|
||||
}
|
||||
store[key] = value;
|
||||
}
|
||||
run(context, fn) {
|
||||
return this.als.run(context, fn);
|
||||
}
|
||||
}
|
||||
var InvokeStore;
|
||||
(function (InvokeStore) {
|
||||
let instance = null;
|
||||
async function getInstanceAsync() {
|
||||
if (!instance) {
|
||||
instance = (async () => {
|
||||
const isMulti = "AWS_LAMBDA_MAX_CONCURRENCY" in process.env;
|
||||
const newInstance = isMulti
|
||||
? await InvokeStoreMulti.create()
|
||||
: new InvokeStoreSingle();
|
||||
if (!NO_GLOBAL_AWS_LAMBDA && globalThis.awslambda?.InvokeStore) {
|
||||
return globalThis.awslambda.InvokeStore;
|
||||
}
|
||||
else if (!NO_GLOBAL_AWS_LAMBDA && globalThis.awslambda) {
|
||||
globalThis.awslambda.InvokeStore = newInstance;
|
||||
return newInstance;
|
||||
}
|
||||
else {
|
||||
return newInstance;
|
||||
}
|
||||
})();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
InvokeStore.getInstanceAsync = getInstanceAsync;
|
||||
InvokeStore._testing = process.env.AWS_LAMBDA_BENCHMARK_MODE === "1"
|
||||
? {
|
||||
reset: () => {
|
||||
instance = null;
|
||||
if (globalThis.awslambda?.InvokeStore) {
|
||||
delete globalThis.awslambda.InvokeStore;
|
||||
}
|
||||
globalThis.awslambda = { InvokeStore: undefined };
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
})(InvokeStore || (InvokeStore = {}));
|
||||
|
||||
export { InvokeStore, InvokeStoreBase };
|
||||
1
backend/node_modules/@aws/lambda-invoke-store/dist-types/invoke-store.benchmark.d.ts
generated
vendored
Normal file
1
backend/node_modules/@aws/lambda-invoke-store/dist-types/invoke-store.benchmark.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
49
backend/node_modules/@aws/lambda-invoke-store/dist-types/invoke-store.d.ts
generated
vendored
Normal file
49
backend/node_modules/@aws/lambda-invoke-store/dist-types/invoke-store.d.ts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
interface Context {
|
||||
[key: string]: unknown;
|
||||
[key: symbol]: unknown;
|
||||
}
|
||||
declare global {
|
||||
namespace awslambda {
|
||||
let InvokeStore: InvokeStoreBase | undefined;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Base class for AWS Lambda context storage implementations.
|
||||
* Provides core functionality for managing Lambda execution context.
|
||||
*
|
||||
* Implementations handle either single-context (InvokeStoreSingle) or
|
||||
* multi-context (InvokeStoreMulti) scenarios based on Lambda's execution environment.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare abstract class InvokeStoreBase {
|
||||
static readonly PROTECTED_KEYS: {
|
||||
readonly REQUEST_ID: symbol;
|
||||
readonly X_RAY_TRACE_ID: symbol;
|
||||
readonly TENANT_ID: symbol;
|
||||
};
|
||||
abstract getContext(): Context | undefined;
|
||||
abstract hasContext(): boolean;
|
||||
abstract get<T = unknown>(key: string | symbol): T | undefined;
|
||||
abstract set<T = unknown>(key: string | symbol, value: T): void;
|
||||
abstract run<T>(context: Context, fn: () => T): T;
|
||||
protected isProtectedKey(key: string | symbol): boolean;
|
||||
getRequestId(): string;
|
||||
getXRayTraceId(): string | undefined;
|
||||
getTenantId(): string | undefined;
|
||||
}
|
||||
/**
|
||||
* Provides access to AWS Lambda execution context storage.
|
||||
* Supports both single-context and multi-context environments through different implementations.
|
||||
*
|
||||
* The store manages protected Lambda context fields and allows storing/retrieving custom values
|
||||
* within the execution context.
|
||||
* @public
|
||||
*/
|
||||
export declare namespace InvokeStore {
|
||||
function getInstanceAsync(): Promise<InvokeStoreBase>;
|
||||
const _testing: {
|
||||
reset: () => void;
|
||||
} | undefined;
|
||||
}
|
||||
export {};
|
||||
55
backend/node_modules/@aws/lambda-invoke-store/package.json
generated
vendored
Normal file
55
backend/node_modules/@aws/lambda-invoke-store/package.json
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "@aws/lambda-invoke-store",
|
||||
"version": "0.2.3",
|
||||
"description": "Invoke scoped data storage for AWS Lambda Node.js Runtime Environment",
|
||||
"homepage": "https://github.com/awslabs/aws-lambda-invoke-store",
|
||||
"main": "./dist-cjs/invoke-store.js",
|
||||
"types": "./dist-types/invoke-store.d.ts",
|
||||
"module": "./dist-es/invoke-store.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist-types/invoke-store.d.ts",
|
||||
"module": "./dist-es/invoke-store.js",
|
||||
"node": "./dist-cjs/invoke-store.js",
|
||||
"import": "./dist-es/invoke-store.js",
|
||||
"require": "./dist-cjs/invoke-store.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist-es",
|
||||
"dist-cjs",
|
||||
"dist-types"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/awslabs/aws-lambda-invoke-store.git"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"author": {
|
||||
"name": "Amazon Web Services",
|
||||
"url": "http://aws.amazon.com"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn clean && yarn build:types && node ./scripts/build-rollup.js",
|
||||
"build:types": "tsc -p tsconfig.types.json",
|
||||
"clean": "rm -rf dist-types dist-cjs dist-es",
|
||||
"test": "vitest run --reporter verbose",
|
||||
"test:watch": "vitest watch",
|
||||
"release": "yarn build && changeset publish"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.29.6",
|
||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||
"@rollup/plugin-typescript": "^12.3.0",
|
||||
"@tsconfig/node18": "^18.2.4",
|
||||
"@types/node": "^18.19.130",
|
||||
"rollup": "^4.52.5",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^3.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
"packageManager": "yarn@4.9.4"
|
||||
}
|
||||
Reference in New Issue
Block a user