Skip to content

Commit a2ccdad

Browse files
committed
Clean up backend dev story
1 parent 37b456c commit a2ccdad

19 files changed

Lines changed: 196 additions & 620 deletions

.github/workflows/deno-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127

128128
- name: Check generation/deploy/mod.ts
129129
if: always()
130-
run: time deno check --allow-import=cdn.skypack.dev,deno.land generation/deploy/mod.ts
130+
run: time deno check generation/deploy/mod.ts
131131

132132
validate-codegen:
133133
runs-on: ubuntu-latest

deno.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
2+
"tasks": {
3+
"deploy:dev": "deno run --watch --allow-env --allow-sys --allow-read --allow-net='[::]:8000,otel.devmode.cloud,api.github.com,raw.githubusercontent.com' generation/deploy/mod.ts"
4+
},
25
"workspace": [
36
"./generation",
47
"./lib"
58
],
69
"imports": {
7-
"@std/assert": "jsr:@std/assert@^1.0.14"
10+
"@std/assert": "jsr:@std/assert@^1"
811
}
912
}

deno.lock

Lines changed: 63 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generation/deno.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
{}
1+
{
2+
"imports": {
3+
"@cloudydeno/jmespath": "jsr:@cloudydeno/jmespath@^1.0.1",
4+
"@cloudydeno/opentelemetry": "jsr:@cloudydeno/opentelemetry@^0.10",
5+
"@std/cache": "jsr:@std/cache@^0.2.0",
6+
"@std/csv": "jsr:@std/csv@^1.0.6",
7+
"@std/html": "jsr:@std/html@^1.0.4",
8+
"@std/path": "jsr:@std/path@^1.1.2"
9+
}
10+
}

generation/deploy/cache-s3.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

generation/deploy/cache.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
// import { S3 } from "./s3-api.ts";
2-
// import { ApiFactory } from "../../lib/client/mod.ts";
3-
import { AsyncTracer, Span } from "./tracer.ts";
1+
import { LogicTracer, Span } from "./tracer.ts";
42

5-
// can maybe replace this whole dep with deno edge cache once it's out of beta
63
import type { Cache } from "./httpcache/mod.ts";
74
import { inMemoryCache } from "./httpcache/in_memory.ts";
8-
// import { s3Cache } from "./cache-s3.ts";
9-
import { platformCache } from "./cache-platform.ts";
10-
11-
// const s3Api = new ApiFactory({
12-
// region: Deno.env.get('HTTPCACHE_S3_REGION') || 'us-east-2',
13-
// }).makeNew(S3);
5+
import { platformCache } from "./httpcache/platform.ts";
146

157
const caches: Array<Cache> = [
168
inMemoryCache(40),
179
await platformCache(),
18-
// s3Cache(s3Api, Deno.env.get('HTTPCACHE_S3_BUCKET') || 'deno-httpcache'),
1910
];
2011
const cacheLabels = ['in-memory', 'platform', 's3'];
2112

22-
const tracer = new AsyncTracer('cached-fetch');
13+
const tracer = new LogicTracer({
14+
name: 'cached-fetch',
15+
});
2316

2417
export async function cachedFetch(mode: 'immutable' | 'mutable', label: string, url: string) {
25-
return await tracer.runAsyncSpan(`fetch ${label}`, {
26-
'cache.label': label,
27-
'cache.mode': mode,
28-
}, span => cachedFetchInner(mode, label, url, span));
18+
return await tracer.asyncSpan(`fetch ${label}`, {
19+
attributes: {
20+
'cache.label': label,
21+
'cache.mode': mode,
22+
},
23+
}, span => cachedFetchInner(mode, url, span!));
2924
}
30-
async function cachedFetchInner(mode: 'immutable' | 'mutable', label: string, url: string, span: Span) {
25+
async function cachedFetchInner(mode: 'immutable' | 'mutable', url: string, span: Span) {
3126

3227
for (const [cacheIdx, cache] of caches.entries()) {
3328
const cached = await cache.match(url).catch(err => {

generation/deploy/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type RouteHandler = (context: {
55
headers: Headers,
66
}) => Response | Promise<Response>;
77

8-
import { escape } from "https://deno.land/x/html_escape@v1.1.5/escape.ts";
8+
import { escape } from "@std/html/entities";
99
export { escape };
1010
export function escapeTemplate(strings: TemplateStringsArray, ...inputs: string[]) {
1111
return String.raw(strings, ...inputs.map(escape));

generation/deploy/httpcache/in_memory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Downloaded from https://deno.land/x/httpcache@0.1.2/in_memory.ts
22

3-
import { LRU } from "https://deno.land/x/lru@1.0.2/mod.ts";
3+
import { LruCache } from "@std/cache/lru-cache";
44
import { Cache, CachedResponse } from "./mod.ts";
55
export { Cache };
66

77
export function inMemoryCache(capacity: number): Cache {
8-
const lru = new LRU<CachedResponse>(capacity);
8+
const lru = new LruCache<string,CachedResponse>(capacity);
99
return new Cache({
1010
get(url) {
1111
return Promise.resolve(lru.get(url));
@@ -15,7 +15,7 @@ export function inMemoryCache(capacity: number): Cache {
1515
return Promise.resolve();
1616
},
1717
delete(url) {
18-
lru.remove(url);
18+
lru.delete(url);
1919
return Promise.resolve();
2020
},
2121
close() {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Cache } from "./httpcache/mod.ts";
2-
import { trace } from "./tracer.ts";
1+
import { trace } from "@cloudydeno/opentelemetry/pkg/api";
2+
import { Cache } from "./mod.ts";
33

44
// https://docs.deno.com/deploy/manual/edge-cache
55

generation/deploy/routes/service-module.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,23 @@ function generateApiModule(opts: {
226226
`No ${opts.apiId} actions matched the given filter ${opts.options.get('actions')}`);
227227
}
228228

229+
headerChunks.push('//');
230+
headerChunks.push(`// Originally served at ${opts.selfUrl}`);
231+
232+
const moduleText = opts.generation.buildApi({
233+
className: opts.module.name,
234+
options: opts.options,
235+
apiSpecs: {
236+
api: opts.spec.normal,
237+
pagers: opts.spec.paginators,
238+
waiters: opts.spec.waiters2,
239+
},
240+
});
241+
242+
headerChunks.unshift(moduleText.slice(0, moduleText.indexOf('\n')));
229243
return [
230244
headerChunks.join('\n'),
231-
`// Originally served at ${opts.selfUrl}`,
232-
opts.generation.buildApi({
233-
className: opts.module.name,
234-
options: opts.options,
235-
apiSpecs: {
236-
api: opts.spec.normal,
237-
pagers: opts.spec.paginators,
238-
waiters: opts.spec.waiters2,
239-
},
240-
}),
245+
moduleText.slice(moduleText.indexOf('\n')+1),
241246
].join('\n\n');
242247
}
243248

0 commit comments

Comments
 (0)