MCPcopy Create free account
hub / github.com/anomalyco/console / createSourcemapCache

Function createSourcemapCache

packages/core/src/log/index.ts:97–202  ·  view source on GitHub ↗
(input: {
  config: StageCredentials;
  logGroup?: string;
  key: string;
})

Source from the content-addressed store, hash-verified

95export type Processor = ReturnType<typeof createProcessor>;
96
97export function createSourcemapCache(input: {
98 config: StageCredentials;
99 logGroup?: string;
100 key: string;
101}) {
102 const s3bootstrap = new S3Client({
103 ...input.config,
104 retryStrategy: RETRY_STRATEGY,
105 });
106 const sourcemapCache = new Map<string, any>();
107
108 const getBootstrap = lazy(() => AWS.Account.bootstrap(input.config));
109 const getBootstrapV3 = lazy(() => AWS.Account.bootstrapIon(input.config));
110 const sourcemapsMeta = lazy(async () => {
111 const results = [] as {
112 bucket: string;
113 key: string;
114 created: number;
115 }[];
116 const bootstrap = await getBootstrap();
117 if (bootstrap) {
118 const result = await s3bootstrap
119 .send(
120 new ListObjectsV2Command({
121 Bucket: bootstrap.bucket,
122 Prefix: `sourcemap/${input.config.app}/${input.config.stage}/${input.key}`,
123 }),
124 )
125 .catch(() => {});
126 if (result) {
127 const maps = (result.Contents || []).map((item) => ({
128 bucket: bootstrap.bucket,
129 key: item.Key!,
130 created: item.LastModified!.getTime(),
131 }));
132 results.push(...maps);
133 }
134 }
135
136 const bootstrapV3 = await getBootstrapV3();
137 if (bootstrapV3 && input.logGroup) {
138 const result = await s3bootstrap
139 .send(
140 new ListObjectsV2Command({
141 Bucket: bootstrapV3.asset,
142 Prefix: `sourcemap/` + input.logGroup,
143 }),
144 )
145 .catch(() => {});
146 if (result) {
147 const maps = (result.Contents || []).map((item) => ({
148 bucket: bootstrapV3.asset,
149 key: item.Key!,
150 created: item.LastModified!.getTime(),
151 }));
152 results.push(...maps);
153 }
154 }

Callers 1

createProcessorFunction · 0.70

Calls 1

lazyFunction · 0.90

Tested by

no test coverage detected