Skip to content

Commit

Permalink
apply wasm encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
imcotton committed Nov 21, 2024
1 parent d20fac1 commit bba6c87
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
12 changes: 8 additions & 4 deletions app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { bodyLimit } from 'hono/body-limit';
import { validator } from 'hono/validator';
import { HTTPException } from 'hono/http-exception';

import type { Encoder } from './encoder/index.ts';
import type { AdapterGen } from './adapter/index.ts';

import { layout, Create, SigningPane, Go } from './components/index.tsx';
import { Show, scriptSrc } from './components/show.tsx';

import { collection } from './assets.ts';

import { noop, csp, cached, register, gen_fnv1a_hash,
import { noop, csp, cached, register,
parser, v_create, v_id_slugify, v_optional_signing_back, read_var,
UUIDv4, UUIDv5_URL, compose_signing_url, calc_fingerprint,
nmap, nothing, slugify, exception, challenge_, duration,
Expand All @@ -25,10 +26,14 @@ import { noop, csp, cached, register, gen_fnv1a_hash,



export async function create_app <E extends Env> (storage: AdapterGen, {
export async function create_app <E extends Env> (

hash: Encoder,
storage: AdapterGen,

{

auth = noop,
encoding = gen_fnv1a_hash(),
cache_name = 'assets-v1',
ttl_in_ms = nothing<number>(),
signing_nav = false,
Expand All @@ -38,7 +43,6 @@ export async function create_app <E extends Env> (storage: AdapterGen, {
} = {}) {

const db = await storage();
const hash = await encoding();

const extend = register(collection);

Expand Down
16 changes: 8 additions & 8 deletions deploy/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { MiddlewareHandler } from 'hono/types';

import { create_app } from '../app.tsx';
import { gen_deno_kv } from '../adapter/deno-kv.ts';
import { gen_fnv1a_hash } from '../utils.ts';
import { gen_fnv1a_hash } from '../encoder/jsr-std-wasm.ts';



Expand All @@ -26,19 +26,19 @@ export function make ({

} = {}): Promise<Deno.ServeDefaultExport> {

return create_app(gen_deno_kv(kv_path), {
const hash = gen_fnv1a_hash({
key: hash_seed,
large: hash_enlarge,
});

const storage = gen_deno_kv(kv_path);

return create_app(hash, storage, {
auth,
cache_name,
ttl_in_ms,
signing_nav,
signing_site,

encoding: gen_fnv1a_hash({
key: hash_seed,
large: hash_enlarge,
}),

});

}
Expand Down
21 changes: 12 additions & 9 deletions specs/smoking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import { Hono } from 'hono';
import { testClient } from 'hono/testing';

import { create_app } from '../app.tsx';
import { gen_fnv1a_hash } from '../encoder/jsr-std-wasm.ts';
import { gen_deno_kv } from '../adapter/deno-kv.ts';
import { make_ttl_cache } from '../adapter/ttl-cache.ts';
import { make_map_object } from '../adapter/map-object.ts';
import { calc_fingerprint, gen_fnv1a_hash,
import { calc_fingerprint,
HMAC_SHA256, signingAuth, UUIDv4, webcrypto, challenge_, duration,
} from '../utils.ts';




const hashing = gen_fnv1a_hash();

const app = await create_app(gen_deno_kv(':memory:'), {
const app = await create_app(hashing, gen_deno_kv(':memory:'), {
insecure: true,
signing_nav: true,
});
Expand Down Expand Up @@ -137,8 +139,9 @@ Deno.test('throw on same code twice', async function () {

Deno.test('advanced config', async function () {

const other = await create_app(make_map_object, {
encoding: gen_fnv1a_hash({ large: true, key: 'ayb' }),
const hashing_local = gen_fnv1a_hash({ large: true, key: 'ayb' });

const other = await create_app(hashing_local, make_map_object, {
insecure: true,
});

Expand Down Expand Up @@ -194,7 +197,7 @@ Deno.test('advanced config', async function () {

Deno.test('default app', async function () {

await create_app(make_map_object);
await create_app(hashing, make_map_object);

});

Expand Down Expand Up @@ -305,7 +308,7 @@ Deno.test('signingAuth', async function () {

{ // ok on show page

const client = testClient(await create_app(make_map_object, {
const client = testClient(await create_app(hashing, make_map_object, {
auth: signingAuth([ fingerprint ]),
insecure: true,
}));
Expand All @@ -324,7 +327,7 @@ Deno.test('signingAuth', async function () {

const fingerprint_lookup = spy(() => true);

const client = testClient(await create_app(make_map_object, {
const client = testClient(await create_app(hashing, make_map_object, {
auth: signingAuth(fingerprint_lookup),
insecure: true,
}));
Expand Down Expand Up @@ -443,7 +446,7 @@ Deno.test('cache with TTL', async function () {
const url = 'https://example.com';
const code = 'foobar';

const app = await create_app(make_ttl_cache, {
const app = await create_app(hashing, make_ttl_cache, {
ttl_in_ms,
insecure: true,
});
Expand Down Expand Up @@ -502,7 +505,7 @@ Deno.test('take TTL from ctx.var', async function () {

using time = new FakeTime();

const app_local = await create_app(make_ttl_cache, {
const app_local = await create_app(hashing, make_ttl_cache, {
insecure: true,
ttl_in_ms: 500,
async auth (ctx, next) {
Expand Down

0 comments on commit bba6c87

Please sign in to comment.