@getstrata/core 3.0.4 → 3.0.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @getstrata/core changelog
2
2
 
3
+ ## 3.0.5
4
+
5
+ - Fixed SQLite queries returning no rows when SQL begins with comments, including VALUES, PRAGMA, EXPLAIN, and compact RETURNING statements.
6
+ - Aligned memory and Redis cache expiration. Added put and forever to ordinary, tagged, and execution-scoped caches. Zero or negative TTLs now remove entries; invalid numeric TTLs are rejected before effects.
7
+ - Fixed stale cache loaders overwriting newer writes and empty cache keys bypassing memory limits.
8
+ - Fixed internal redirect validation bypasses and preserved repeated query parameters.
9
+ - Fixed malformed intended-URL and flash cookies throwing errors.
10
+ - Fixed CI package dry-runs failing when the package version was already published.
11
+
12
+ **Migration:** Replace Redis TTL 0 used for permanent storage with forever(). For a permanent configured default, use . TTL units remain milliseconds.
13
+
14
+ ## Unreleased
15
+
16
+ Align array and Redis expiration semantics: positive safe-integer millisecond TTLs expire; zero/negative TTLs remove entries and fence pending fills; omitted TTLs use the configured default. Add `put` and `forever` to repositories, tagged caches and execution-scoped caches. Explicit low-level `null` means forever. Redis callers using TTL zero for persistence must switch to `forever` (or a null configured default). Invalid numeric TTLs reject before effects.
17
+
18
+ Reject control characters that can turn internal redirects into external destinations and preserve repeated query parameters. Prevent malformed intended-URL and flash cookies from throwing by using the shared cookie reader, including Bun's native cookie-map path. Fence old memory-cache fills after explicit writes, enforce capacity for empty keys, and reject invalid per-call TTLs before mutation or loader execution.
19
+
20
+ Fix SQLite row detection using native prepared-statement column metadata. Leading comments no longer discard SELECT, CTE, PRAGMA or EXPLAIN results; VALUES and compact RETURNING forms also return their rows. Non-returning mutations still execute once and return an empty result.
21
+
3
22
  ## 3.0.4
4
23
 
5
24
  Restore workspace-based npm publication and remove custom archive packing/recovery. Skip confirmed existing versions, stop on registry lookup failures, and accept successful npm uploads without requiring immediate registry visibility. Retain release quality gates, pinned npm, provenance and publication dry-runs. The v3.0.3 attempt published only @getstrata/core before its visibility check failed.
@@ -3,7 +3,7 @@ import type { CacheStore } from "./store";
3
3
  type CacheDriver = "array" | "redis";
4
4
  interface CreateCacheStoreOptions {
5
5
  driver: CacheDriver;
6
- ttlMs: number;
6
+ ttlMs: number | null;
7
7
  maxEntries: number;
8
8
  redisUrl?: string;
9
9
  redis?: Readonly<RedisCacheOptions>;
@@ -0,0 +1,2 @@
1
+ /** null explicitly means forever; undefined selects the configured default. */
2
+ export declare function resolveCacheTtl(ttlMs: unknown, defaultTtlMs: number | null): number | null;
@@ -1,2 +1,2 @@
1
- declare const CACHE_SCRIPT = "\nlocal expected = {'hash', 'zset', 'zset', 'hash', 'zset'}\nfor i, key in ipairs(KEYS) do\n local kind = redis.call('TYPE', key).ok\n if kind ~= 'none' and kind ~= expected[i] then return redis.error_reply('Unexpected cache key type') end\nend\n-- Redis eviction can remove one container without its companions. Never read\n-- orphaned values or leases after losing the expiry/order/generation indexes.\nlocal entries = redis.call('HLEN', KEYS[1])\nlocal order = redis.call('ZCARD', KEYS[3])\nif redis.call('ZCARD', KEYS[2]) ~= order or entries ~= (order > 0 and order + 1 or 0) then\n redis.call('DEL', KEYS[1], KEYS[2], KEYS[3])\nend\nif redis.call('HLEN', KEYS[4]) ~= redis.call('ZCARD', KEYS[5]) then\n redis.call('DEL', KEYS[4], KEYS[5])\nend\nlocal r = cjson.decode(ARGV[1])\nlocal time = redis.call('TIME')\nlocal now = tonumber(time[1]) * 1000 + tonumber(time[2]) / 1000\nlocal function removeEntry(key)\n local removed = redis.call('HDEL', KEYS[1], 'e:' .. key)\n redis.call('ZREM', KEYS[2], key)\n redis.call('ZREM', KEYS[3], key)\n return removed\nend\nlocal function removeMeta(field)\n redis.call('HDEL', KEYS[4], field)\n redis.call('ZREM', KEYS[5], field)\nend\nfor _, key in ipairs(redis.call('ZRANGEBYSCORE', KEYS[2], '-inf', now, 'LIMIT', 0, r.capacity)) do removeEntry(key) end\nfor _, field in ipairs(redis.call('ZRANGEBYSCORE', KEYS[5], '-inf', now, 'LIMIT', 0, r.metadataLimit)) do removeMeta(field) end\nlocal function expireContainers()\n local last = redis.call('ZREVRANGE', KEYS[2], 0, 0, 'WITHSCORES')\n if #last == 0 then\n redis.call('DEL', KEYS[1], KEYS[2], KEYS[3])\n elseif last[2] == 'inf' then\n for i = 1, 3 do redis.call('PERSIST', KEYS[i]) end\n else\n local ttl = math.max(1, math.ceil(tonumber(last[2]) - now))\n for i = 1, 3 do redis.call('PEXPIRE', KEYS[i], ttl) end\n end\n for i = 4, 5 do redis.call('PEXPIRE', KEYS[i], r.metadataTtlMs) end\nend\nlocal function response(value)\n expireContainers()\n return cjson.encode(value)\nend\nlocal function addTags(existing, added)\n local seen = {}\n local result = {}\n for _, tags in ipairs({existing, added}) do\n for _, tag in ipairs(tags) do\n if not seen[tag] then seen[tag] = true; table.insert(result, tag) end\n end\n end\n if #result > 32 then error('Cache entries support at most 32 tags') end\n return result\nend\nlocal function touch(key)\n local sequence = redis.call('HINCRBY', KEYS[1], '_sequence', 1)\n redis.call('ZADD', KEYS[3], sequence, key)\nend\nlocal function read(key, tags)\n local raw = redis.call('HGET', KEYS[1], 'e:' .. key)\n if not raw then return nil end\n local entry = cjson.decode(raw)\n if #tags > 0 then\n entry.tags = addTags(entry.tags, tags)\n redis.call('HSET', KEYS[1], 'e:' .. key, cjson.encode(entry))\n end\n touch(key)\n return entry.payload\nend\nlocal function write(key, payload, tags)\n local entry = {payload=payload, tags=tags}\n redis.call('HSET', KEYS[1], 'e:' .. key, cjson.encode(entry))\n redis.call('ZADD', KEYS[2], r.ttlMs == 0 and '+inf' or now + r.ttlMs, key)\n touch(key)\n local overflow = redis.call('ZCARD', KEYS[3]) - r.capacity\n if overflow > 0 then\n for _, victim in ipairs(redis.call('ZRANGE', KEYS[3], 0, overflow - 1)) do removeEntry(victim) end\n end\nend\nlocal leaseField = 'l:' .. r.key\nlocal function lease()\n local raw = redis.call('HGET', KEYS[4], leaseField)\n if not raw then return nil end\n local value = cjson.decode(raw)\n if value.expires <= now or value.deadline <= now then removeMeta(leaseField); return nil end\n return value\nend\nlocal function metadataSpace(count)\n if redis.call('HLEN', KEYS[4]) + count > r.metadataLimit then\n -- Pressure sheds generation/lease state. Every old owner is fenced; cached\n -- entries remain valid because invalidation removes matching entries atomically.\n redis.call('DEL', KEYS[4], KEYS[5])\n end\nend\nlocal function putMeta(field, value, expires)\n redis.call('HSET', KEYS[4], field, value)\n redis.call('ZADD', KEYS[5], expires, field)\nend\nlocal function scopes()\n local fields = {}\n for _, tag in ipairs(r.tags) do table.insert(fields, 'g:tag:' .. tag) end\n for _, prefix in ipairs(r.prefixes) do table.insert(fields, 'g:prefix:' .. prefix) end\n return fields\nend\nlocal function matches(key, tags)\n if r.op == 'invalidate' then return key == r.key end\n if r.op == 'prefix' then return key == r.key or string.sub(key, 1, #r.key + 1) == r.key .. '?' end\n if r.op == 'tags' then\n for _, existing in ipairs(tags) do\n for _, wanted in ipairs(r.tags) do if wanted == existing then return true end end\n end\n end\n return false\nend\nif r.op == 'clear' then\n redis.call('DEL', unpack(KEYS))\n return cjson.encode({removed=0})\nelseif r.op == 'get' then\n local payload = read(r.key, r.tags)\n return response(payload and {kind='value', payload=payload} or {kind='missing'})\nelseif r.op == 'set' then\n local old = redis.call('HGET', KEYS[1], 'e:' .. r.key)\n local tags = old and cjson.decode(old).tags or {}\n write(r.key, r.payload, tags)\n removeMeta(leaseField)\n return response({written=true})\nelseif r.op == 'attach' then\n read(r.key, r.tags)\n return response({written=true})\nelseif r.op == 'size' then\n return response({size=redis.call('ZCARD', KEYS[3])})\nelseif r.op == 'tags' or r.op == 'prefix' or r.op == 'invalidate' then\n local generationFields = {}\n if r.op == 'tags' then\n for _, tag in ipairs(r.tags) do table.insert(generationFields, 'g:tag:' .. tag) end\n elseif r.op == 'prefix' then table.insert(generationFields, 'g:prefix:' .. r.key) end\n metadataSpace(#generationFields)\n for _, field in ipairs(generationFields) do putMeta(field, r.owner, now + r.metadataTtlMs) end\n local removed = 0\n for _, key in ipairs(redis.call('ZRANGE', KEYS[3], 0, -1)) do\n local raw = redis.call('HGET', KEYS[1], 'e:' .. key)\n if raw and matches(key, cjson.decode(raw).tags) then removed = removed + removeEntry(key) end\n end\n for _, field in ipairs(redis.call('HKEYS', KEYS[4])) do\n if string.sub(field, 1, 2) == 'l:' then\n local value = cjson.decode(redis.call('HGET', KEYS[4], field))\n if matches(string.sub(field, 3), value.tags) then removeMeta(field) end\n end\n end\n return response({removed=removed})\nelseif r.op == 'claim' then\n local payload = read(r.key, r.tags)\n if payload then return response({kind='value', payload=payload}) end\n local current = lease()\n if current then\n local shared = addTags(current.tags, r.tags)\n if #shared == #current.tags then return response({kind='wait'}) end\n -- A newly requested tag must not inherit a fill started before that tag's\n -- invalidation. Restart with the union of tags and a new owner.\n r.tags = shared\n removeMeta(leaseField)\n end\n local active = 0\n for _, field in ipairs(redis.call('HKEYS', KEYS[4])) do if string.sub(field, 1, 2) == 'l:' then active = active + 1 end end\n if active >= r.capacity then return response({kind='wait'}) end\n local fields = scopes()\n metadataSpace(#fields + 1)\n local generations = {}\n for _, field in ipairs(fields) do\n local token = redis.call('HGET', KEYS[4], field) or r.owner\n putMeta(field, token, now + r.metadataTtlMs)\n generations[field] = token\n end\n local value = {owner=r.owner, tags=r.tags, generations=generations, deadline=now + r.fillTimeoutMs, expires=now + r.leaseMs}\n putMeta(leaseField, cjson.encode(value), value.expires)\n return response({kind='owner'})\nelseif r.op == 'renew' or r.op == 'publish' or r.op == 'release' then\n local current = lease()\n if not current or current.owner ~= r.owner then return response({owned=false}) end\n if r.op == 'release' then removeMeta(leaseField); return response({owned=true}) end\n for field, token in pairs(current.generations) do\n if redis.call('HGET', KEYS[4], field) ~= token then removeMeta(leaseField); return response({owned=false}) end\n end\n if r.op == 'renew' then\n current.expires = math.min(current.deadline, now + r.leaseMs)\n putMeta(leaseField, cjson.encode(current), current.expires)\n else\n write(r.key, r.payload, current.tags)\n removeMeta(leaseField)\n end\n return response({owned=true})\nend\nreturn redis.error_reply('Unknown cache operation')\n";
1
+ declare const CACHE_SCRIPT = "\nlocal expected = {'hash', 'zset', 'zset', 'hash', 'zset'}\nfor i, key in ipairs(KEYS) do\n local kind = redis.call('TYPE', key).ok\n if kind ~= 'none' and kind ~= expected[i] then return redis.error_reply('Unexpected cache key type') end\nend\n-- Redis eviction can remove one container without its companions. Never read\n-- orphaned values or leases after losing the expiry/order/generation indexes.\nlocal entries = redis.call('HLEN', KEYS[1])\nlocal order = redis.call('ZCARD', KEYS[3])\nif redis.call('ZCARD', KEYS[2]) ~= order or entries ~= (order > 0 and order + 1 or 0) then\n redis.call('DEL', KEYS[1], KEYS[2], KEYS[3])\nend\nif redis.call('HLEN', KEYS[4]) ~= redis.call('ZCARD', KEYS[5]) then\n redis.call('DEL', KEYS[4], KEYS[5])\nend\nlocal r = cjson.decode(ARGV[1])\nlocal time = redis.call('TIME')\nlocal now = tonumber(time[1]) * 1000 + tonumber(time[2]) / 1000\nlocal function removeEntry(key)\n local removed = redis.call('HDEL', KEYS[1], 'e:' .. key)\n redis.call('ZREM', KEYS[2], key)\n redis.call('ZREM', KEYS[3], key)\n return removed\nend\nlocal function removeMeta(field)\n redis.call('HDEL', KEYS[4], field)\n redis.call('ZREM', KEYS[5], field)\nend\nfor _, key in ipairs(redis.call('ZRANGEBYSCORE', KEYS[2], '-inf', now, 'LIMIT', 0, r.capacity)) do removeEntry(key) end\nfor _, field in ipairs(redis.call('ZRANGEBYSCORE', KEYS[5], '-inf', now, 'LIMIT', 0, r.metadataLimit)) do removeMeta(field) end\nlocal function expireContainers()\n local last = redis.call('ZREVRANGE', KEYS[2], 0, 0, 'WITHSCORES')\n if #last == 0 then\n redis.call('DEL', KEYS[1], KEYS[2], KEYS[3])\n elseif last[2] == 'inf' then\n for i = 1, 3 do redis.call('PERSIST', KEYS[i]) end\n else\n local ttl = math.max(1, math.ceil(tonumber(last[2]) - now))\n for i = 1, 3 do redis.call('PEXPIRE', KEYS[i], ttl) end\n end\n for i = 4, 5 do redis.call('PEXPIRE', KEYS[i], r.metadataTtlMs) end\nend\nlocal function response(value)\n expireContainers()\n return cjson.encode(value)\nend\nlocal function addTags(existing, added)\n local seen = {}\n local result = {}\n for _, tags in ipairs({existing, added}) do\n for _, tag in ipairs(tags) do\n if not seen[tag] then seen[tag] = true; table.insert(result, tag) end\n end\n end\n if #result > 32 then error('Cache entries support at most 32 tags') end\n return result\nend\nlocal function touch(key)\n local sequence = redis.call('HINCRBY', KEYS[1], '_sequence', 1)\n redis.call('ZADD', KEYS[3], sequence, key)\nend\nlocal function read(key, tags)\n local raw = redis.call('HGET', KEYS[1], 'e:' .. key)\n if not raw then return nil end\n local entry = cjson.decode(raw)\n if #tags > 0 then\n entry.tags = addTags(entry.tags, tags)\n redis.call('HSET', KEYS[1], 'e:' .. key, cjson.encode(entry))\n end\n touch(key)\n return entry.payload\nend\nlocal function write(key, payload, tags)\n if not r.forever and r.ttlMs <= 0 then removeEntry(key); return end\n local entry = {payload=payload, tags=tags}\n redis.call('HSET', KEYS[1], 'e:' .. key, cjson.encode(entry))\n redis.call('ZADD', KEYS[2], r.forever and '+inf' or now + r.ttlMs, key)\n touch(key)\n local overflow = redis.call('ZCARD', KEYS[3]) - r.capacity\n if overflow > 0 then\n for _, victim in ipairs(redis.call('ZRANGE', KEYS[3], 0, overflow - 1)) do removeEntry(victim) end\n end\nend\nlocal leaseField = 'l:' .. r.key\nlocal function lease()\n local raw = redis.call('HGET', KEYS[4], leaseField)\n if not raw then return nil end\n local value = cjson.decode(raw)\n if value.expires <= now or value.deadline <= now then removeMeta(leaseField); return nil end\n return value\nend\nlocal function metadataSpace(count)\n if redis.call('HLEN', KEYS[4]) + count > r.metadataLimit then\n -- Pressure sheds generation/lease state. Every old owner is fenced; cached\n -- entries remain valid because invalidation removes matching entries atomically.\n redis.call('DEL', KEYS[4], KEYS[5])\n end\nend\nlocal function putMeta(field, value, expires)\n redis.call('HSET', KEYS[4], field, value)\n redis.call('ZADD', KEYS[5], expires, field)\nend\nlocal function scopes()\n local fields = {}\n for _, tag in ipairs(r.tags) do table.insert(fields, 'g:tag:' .. tag) end\n for _, prefix in ipairs(r.prefixes) do table.insert(fields, 'g:prefix:' .. prefix) end\n return fields\nend\nlocal function matches(key, tags)\n if r.op == 'invalidate' then return key == r.key end\n if r.op == 'prefix' then return key == r.key or string.sub(key, 1, #r.key + 1) == r.key .. '?' end\n if r.op == 'tags' then\n for _, existing in ipairs(tags) do\n for _, wanted in ipairs(r.tags) do if wanted == existing then return true end end\n end\n end\n return false\nend\nif r.op == 'clear' then\n redis.call('DEL', unpack(KEYS))\n return cjson.encode({removed=0})\nelseif r.op == 'get' then\n local payload = read(r.key, r.tags)\n return response(payload and {kind='value', payload=payload} or {kind='missing'})\nelseif r.op == 'set' then\n local old = redis.call('HGET', KEYS[1], 'e:' .. r.key)\n local tags = addTags(old and cjson.decode(old).tags or {}, r.tags)\n write(r.key, r.payload, tags)\n removeMeta(leaseField)\n return response({written=true})\nelseif r.op == 'attach' then\n read(r.key, r.tags)\n return response({written=true})\nelseif r.op == 'size' then\n return response({size=redis.call('ZCARD', KEYS[3])})\nelseif r.op == 'tags' or r.op == 'prefix' or r.op == 'invalidate' then\n local generationFields = {}\n if r.op == 'tags' then\n for _, tag in ipairs(r.tags) do table.insert(generationFields, 'g:tag:' .. tag) end\n elseif r.op == 'prefix' then table.insert(generationFields, 'g:prefix:' .. r.key) end\n metadataSpace(#generationFields)\n for _, field in ipairs(generationFields) do putMeta(field, r.owner, now + r.metadataTtlMs) end\n local removed = 0\n for _, key in ipairs(redis.call('ZRANGE', KEYS[3], 0, -1)) do\n local raw = redis.call('HGET', KEYS[1], 'e:' .. key)\n if raw and matches(key, cjson.decode(raw).tags) then removed = removed + removeEntry(key) end\n end\n for _, field in ipairs(redis.call('HKEYS', KEYS[4])) do\n if string.sub(field, 1, 2) == 'l:' then\n local value = cjson.decode(redis.call('HGET', KEYS[4], field))\n if matches(string.sub(field, 3), value.tags) then removeMeta(field) end\n end\n end\n return response({removed=removed})\nelseif r.op == 'claim' then\n local payload = read(r.key, r.tags)\n if payload then return response({kind='value', payload=payload}) end\n local current = lease()\n if current then\n local shared = addTags(current.tags, r.tags)\n if #shared == #current.tags then return response({kind='wait'}) end\n -- A newly requested tag must not inherit a fill started before that tag's\n -- invalidation. Restart with the union of tags and a new owner.\n r.tags = shared\n removeMeta(leaseField)\n end\n local active = 0\n for _, field in ipairs(redis.call('HKEYS', KEYS[4])) do if string.sub(field, 1, 2) == 'l:' then active = active + 1 end end\n if active >= r.capacity then return response({kind='wait'}) end\n local fields = scopes()\n metadataSpace(#fields + 1)\n local generations = {}\n for _, field in ipairs(fields) do\n local token = redis.call('HGET', KEYS[4], field) or r.owner\n putMeta(field, token, now + r.metadataTtlMs)\n generations[field] = token\n end\n local value = {owner=r.owner, tags=r.tags, generations=generations, deadline=now + r.fillTimeoutMs, expires=now + r.leaseMs}\n putMeta(leaseField, cjson.encode(value), value.expires)\n return response({kind='owner'})\nelseif r.op == 'renew' or r.op == 'publish' or r.op == 'release' then\n local current = lease()\n if not current or current.owner ~= r.owner then return response({owned=false}) end\n if r.op == 'release' then removeMeta(leaseField); return response({owned=true}) end\n for field, token in pairs(current.generations) do\n if redis.call('HGET', KEYS[4], field) ~= token then removeMeta(leaseField); return response({owned=false}) end\n end\n if r.op == 'renew' then\n current.expires = math.min(current.deadline, now + r.leaseMs)\n putMeta(leaseField, cjson.encode(current), current.expires)\n else\n write(r.key, r.payload, current.tags)\n removeMeta(leaseField)\n end\n return response({owned=true})\nend\nreturn redis.error_reply('Unknown cache operation')\n";
2
2
  export { CACHE_SCRIPT };
@@ -10,7 +10,7 @@ type RedisCacheOptions = {
10
10
  };
11
11
  declare const DEFAULT_CACHE_NAMESPACE = "strata:cache:v3:";
12
12
  declare function validateCacheNamespace(namespace: string): void;
13
- declare function normalizeRedisCacheOptions(ttlMs: number, maxEntries: number, options?: Readonly<RedisCacheOptions>): Readonly<Required<RedisCacheOptions>>;
13
+ declare function normalizeRedisCacheOptions(ttlMs: number | null, maxEntries: number, options?: Readonly<RedisCacheOptions>): Readonly<Required<RedisCacheOptions>>;
14
14
  declare class RedisCacheStore implements CacheStore {
15
15
  private readonly redisUrl;
16
16
  private readonly ttlMs;
@@ -20,13 +20,13 @@ declare class RedisCacheStore implements CacheStore {
20
20
  private readonly options;
21
21
  private readonly fills;
22
22
  private closed;
23
- constructor(redisUrl: string, ttlMs: number, maxEntries: number, options?: RedisCacheOptions, namespace?: string);
23
+ constructor(redisUrl: string, ttlMs: number | null, maxEntries: number, options?: RedisCacheOptions, namespace?: string);
24
24
  private createClient;
25
25
  close(): void;
26
26
  get<T>(key: string): Promise<T | undefined>;
27
- set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
28
- getOrSet<T>(key: string, loader: (signal?: AbortSignal) => Promise<T>, ttlMs?: number): Promise<T>;
29
- getOrSetTagged<T>(key: string, loader: (signal?: AbortSignal) => Promise<T>, tags: string[], ttlMs?: number): Promise<T>;
27
+ set<T>(key: string, value: T, ttlMs?: number | null, tags?: string[]): Promise<void>;
28
+ getOrSet<T>(key: string, loader: (signal?: AbortSignal) => Promise<T>, ttlMs?: number | null): Promise<T>;
29
+ getOrSetTagged<T>(key: string, loader: (signal?: AbortSignal) => Promise<T>, tags: string[], ttlMs?: number | null): Promise<T>;
30
30
  attachTags(key: string, tags: string[]): Promise<void>;
31
31
  flushTags(tags: string[]): Promise<number>;
32
32
  invalidate(key: string): Promise<boolean>;
@@ -7,6 +7,8 @@ declare class CacheRepository {
7
7
  constructor(store: CacheStore);
8
8
  close(): Promise<void>;
9
9
  get<T>(key: string): Promise<T | undefined>;
10
+ put<T>(key: string, value: T, ttlMs?: number): Promise<void>;
11
+ forever<T>(key: string, value: T): Promise<void>;
10
12
  remember<T>(key: string, callback: (signal?: AbortSignal) => Promise<T>, ttlMs?: number): Promise<T>;
11
13
  forget(key: string): Promise<boolean>;
12
14
  flush(): Promise<void>;
@@ -1,4 +1,4 @@
1
- declare function validateSimpleCacheOptions(ttlMs: number, maxEntries: number): void;
1
+ declare function validateSimpleCacheOptions(ttlMs: number | null, maxEntries: number): void;
2
2
  declare class SimpleCache {
3
3
  private readonly ttlMs;
4
4
  private readonly maxEntries;
@@ -6,11 +6,11 @@ declare class SimpleCache {
6
6
  private readonly inflight;
7
7
  private readonly tagIndex;
8
8
  private readonly keyTags;
9
- constructor(ttlMs?: number, maxEntries?: number);
9
+ constructor(ttlMs?: number | null, maxEntries?: number);
10
10
  get<T>(key: string): T | undefined;
11
- set<T>(key: string, value: T, ttlMs?: number): void;
12
- getOrSet<T>(key: string, loader: () => Promise<T>, ttlMs?: number): Promise<T>;
13
- getOrSetTagged<T>(key: string, loader: () => Promise<T>, tags: string[], ttlMs?: number): Promise<T>;
11
+ set<T>(key: string, value: T, ttlMs?: number | null, tags?: string[]): void;
12
+ getOrSet<T>(key: string, loader: () => Promise<T>, ttlMs?: number | null): Promise<T>;
13
+ getOrSetTagged<T>(key: string, loader: () => Promise<T>, tags: string[], ttlMs?: number | null): Promise<T>;
14
14
  attachTags(key: string, tags: string[]): void;
15
15
  flushTags(tags: string[]): number;
16
16
  invalidate(key: string): boolean;
@@ -4,9 +4,9 @@ declare class SimpleCacheStore implements CacheStore {
4
4
  private readonly cache;
5
5
  constructor(cache: SimpleCache);
6
6
  get<T>(key: string): Promise<T | undefined>;
7
- set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
8
- getOrSet<T>(key: string, loader: () => Promise<T>, ttlMs?: number): Promise<T>;
9
- getOrSetTagged<T>(key: string, loader: () => Promise<T>, tags: string[], ttlMs?: number): Promise<T>;
7
+ set<T>(key: string, value: T, ttlMs?: number | null, tags?: string[]): Promise<void>;
8
+ getOrSet<T>(key: string, loader: () => Promise<T>, ttlMs?: number | null): Promise<T>;
9
+ getOrSetTagged<T>(key: string, loader: () => Promise<T>, tags: string[], ttlMs?: number | null): Promise<T>;
10
10
  attachTags(key: string, tags: string[]): Promise<void>;
11
11
  flushTags(tags: string[]): Promise<number>;
12
12
  invalidate(key: string): Promise<boolean>;
@@ -1,10 +1,11 @@
1
1
  interface CacheStore {
2
2
  close?(): void | Promise<void>;
3
3
  get<T>(key: string): Promise<T | undefined>;
4
- set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
5
- getOrSet<T>(key: string, loader: (signal?: AbortSignal) => Promise<T>, ttlMs?: number): Promise<T>;
4
+ /** null is forever; nonpositive TTLs remove the key and fence pending fills. */
5
+ set<T>(key: string, value: T, ttlMs?: number | null, tags?: string[]): Promise<void>;
6
+ getOrSet<T>(key: string, loader: (signal?: AbortSignal) => Promise<T>, ttlMs?: number | null): Promise<T>;
6
7
  /** Shared stores can bind tags before starting a fill. */
7
- getOrSetTagged?<T>(key: string, loader: (signal?: AbortSignal) => Promise<T>, tags: string[], ttlMs?: number): Promise<T>;
8
+ getOrSetTagged?<T>(key: string, loader: (signal?: AbortSignal) => Promise<T>, tags: string[], ttlMs?: number | null): Promise<T>;
8
9
  attachTags(key: string, tags: string[]): Promise<void>;
9
10
  flushTags(tags: string[]): Promise<number>;
10
11
  invalidate(key: string): Promise<boolean>;
@@ -3,6 +3,8 @@ declare class TaggedCache {
3
3
  private readonly store;
4
4
  private readonly tags;
5
5
  constructor(store: CacheStore, tags: string[]);
6
+ put<T>(key: string, value: T, ttlMs?: number): Promise<void>;
7
+ forever<T>(key: string, value: T): Promise<void>;
6
8
  remember<T>(key: string, callback: (signal?: AbortSignal) => Promise<T>, ttlMs?: number): Promise<T>;
7
9
  flush(): Promise<number>;
8
10
  }
@@ -1,8 +1,43 @@
1
1
  // @bun
2
+ // ../../src/core/http/cookies.ts
3
+ function readRequestCookie(request, name) {
4
+ const cookies = request.cookies;
5
+ if (cookies && typeof cookies.get === "function") {
6
+ const value = cookies.get(name);
7
+ if (value) {
8
+ return value;
9
+ }
10
+ }
11
+ const header = request.headers.get("cookie");
12
+ if (!header) {
13
+ return null;
14
+ }
15
+ for (const part of header.split(";")) {
16
+ const idx = part.indexOf("=");
17
+ if (idx === -1)
18
+ continue;
19
+ const cookieName = part.slice(0, idx).trim();
20
+ if (cookieName !== name)
21
+ continue;
22
+ try {
23
+ return decodeURIComponent(part.slice(idx + 1).trim());
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+ function readBunRequestCookie(request, name) {
31
+ return request.cookies.get(name) ?? readRequestCookie(request, name);
32
+ }
33
+
2
34
  // ../../src/core/http/safeInternalPath.ts
3
35
  var NESTED_REDIRECT_KEYS = new Set(["redirect", "next", "return", "returnTo", "return_to"]);
4
36
  function looksLikeExternalTarget(value) {
5
37
  const trimmed = value.trim();
38
+ if (/[\t\r\n]/.test(trimmed)) {
39
+ return true;
40
+ }
6
41
  if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("\\")) {
7
42
  return true;
8
43
  }
@@ -28,13 +63,13 @@ function sanitizeNestedQuery(search) {
28
63
  for (const [key, value] of params.entries()) {
29
64
  if (NESTED_REDIRECT_KEYS.has(key)) {
30
65
  const sanitized = sanitizeInternalPath(value, "/");
31
- next.set(key, sanitized);
66
+ next.append(key, sanitized);
32
67
  continue;
33
68
  }
34
69
  if (looksLikeExternalTarget(value) && value.includes("://")) {
35
70
  continue;
36
71
  }
37
- next.set(key, value);
72
+ next.append(key, value);
38
73
  }
39
74
  const serialized = next.toString();
40
75
  return serialized ? `?${serialized}` : "";
@@ -163,19 +198,6 @@ function isStashableIntendedPath(path) {
163
198
  }
164
199
  return true;
165
200
  }
166
- function readCookieValue(request, cookieName) {
167
- const cookieHeader = request.headers.get("cookie");
168
- if (!cookieHeader) {
169
- return null;
170
- }
171
- for (const part of cookieHeader.split(";")) {
172
- const [name, ...rest] = part.trim().split("=");
173
- if (name === cookieName) {
174
- return decodeURIComponent(rest.join("="));
175
- }
176
- }
177
- return null;
178
- }
179
201
  function createIntendedUrlCookie(path, options) {
180
202
  const sanitized = sanitizeInternalPath(path, "");
181
203
  if (!sanitized || !isStashableIntendedPath(sanitized)) {
@@ -190,7 +212,7 @@ function createIntendedUrlCookieFromRequest(request, options) {
190
212
  return createIntendedUrlCookie(safeInternalRedirectPath(request, ""), options);
191
213
  }
192
214
  function readIntendedUrl(request, options) {
193
- const cookieValue = readCookieValue(request, options.cookieName);
215
+ const cookieValue = readRequestCookie(request, options.cookieName);
194
216
  if (!cookieValue) {
195
217
  return null;
196
218
  }
@@ -54,6 +54,15 @@ function copyApplicationConfig(value, ancestors = new Set) {
54
54
  // ../../src/core/cache/redisCacheStore.ts
55
55
  var {RedisClient } = globalThis.Bun;
56
56
 
57
+ // ../../src/core/cache/expiration.ts
58
+ function resolveCacheTtl(ttlMs, defaultTtlMs) {
59
+ const resolved = ttlMs === undefined ? defaultTtlMs : ttlMs;
60
+ if (resolved !== null && (typeof resolved !== "number" || !Number.isSafeInteger(resolved))) {
61
+ throw new RangeError("ttlMs must be a safe integer number of milliseconds, or null for forever.");
62
+ }
63
+ return resolved;
64
+ }
65
+
57
66
  // ../../src/core/cache/redisCacheScript.ts
58
67
  var CACHE_SCRIPT = `
59
68
  local expected = {'hash', 'zset', 'zset', 'hash', 'zset'}
@@ -129,9 +138,10 @@ local function read(key, tags)
129
138
  return entry.payload
130
139
  end
131
140
  local function write(key, payload, tags)
141
+ if not r.forever and r.ttlMs <= 0 then removeEntry(key); return end
132
142
  local entry = {payload=payload, tags=tags}
133
143
  redis.call('HSET', KEYS[1], 'e:' .. key, cjson.encode(entry))
134
- redis.call('ZADD', KEYS[2], r.ttlMs == 0 and '+inf' or now + r.ttlMs, key)
144
+ redis.call('ZADD', KEYS[2], r.forever and '+inf' or now + r.ttlMs, key)
135
145
  touch(key)
136
146
  local overflow = redis.call('ZCARD', KEYS[3]) - r.capacity
137
147
  if overflow > 0 then
@@ -181,7 +191,7 @@ elseif r.op == 'get' then
181
191
  return response(payload and {kind='value', payload=payload} or {kind='missing'})
182
192
  elseif r.op == 'set' then
183
193
  local old = redis.call('HGET', KEYS[1], 'e:' .. r.key)
184
- local tags = old and cjson.decode(old).tags or {}
194
+ local tags = addTags(old and cjson.decode(old).tags or {}, r.tags)
185
195
  write(r.key, r.payload, tags)
186
196
  removeMeta(leaseField)
187
197
  return response({written=true})
@@ -261,8 +271,7 @@ function validateCacheNamespace(namespace) {
261
271
  throw new TypeError("Cache namespace must be a nonempty string.");
262
272
  }
263
273
  function normalizeRedisCacheOptions(ttlMs, maxEntries, options = {}) {
264
- if (!Number.isSafeInteger(ttlMs) || ttlMs < 0)
265
- throw new RangeError("ttlMs must be a non-negative safe integer.");
274
+ resolveCacheTtl(ttlMs, ttlMs);
266
275
  if (!Number.isInteger(maxEntries) || maxEntries < 1 || maxEntries > 1e4)
267
276
  throw new RangeError("maxEntries must be between 1 and 10000.");
268
277
  const copied = copyApplicationConfig(options);
@@ -322,8 +331,13 @@ class RedisCacheStore {
322
331
  const result = await this.execute("get", key);
323
332
  return result.kind === "value" ? JSON.parse(result.payload ?? "null") : undefined;
324
333
  }
325
- async set(key, value, ttlMs) {
326
- await this.execute("set", key, { payload: this.serialize(value), ttlMs: ttlMs ?? this.ttlMs });
334
+ async set(key, value, ttlMs, tags = []) {
335
+ const resolved = resolveCacheTtl(ttlMs, this.ttlMs);
336
+ await this.execute("set", key, {
337
+ payload: resolved !== null && resolved <= 0 ? "null" : this.serialize(value),
338
+ ttlMs: resolved,
339
+ tags
340
+ });
327
341
  }
328
342
  async getOrSet(key, loader, ttlMs) {
329
343
  return this.getOrSetTagged(key, loader, [], ttlMs);
@@ -332,7 +346,11 @@ class RedisCacheStore {
332
346
  const owner = crypto.randomUUID();
333
347
  const end = performance.now() + this.options.waitTimeoutMs;
334
348
  while (!this.closed) {
335
- const claim = await this.execute("claim", key, { owner, tags, ttlMs: ttlMs ?? this.ttlMs });
349
+ const claim = await this.execute("claim", key, {
350
+ owner,
351
+ tags,
352
+ ttlMs: resolveCacheTtl(ttlMs, this.ttlMs)
353
+ });
336
354
  if (claim.kind === "value")
337
355
  return JSON.parse(claim.payload ?? "null");
338
356
  if (claim.kind === "owner")
@@ -398,10 +416,11 @@ class RedisCacheStore {
398
416
  controller.signal.throwIfAborted();
399
417
  done = true;
400
418
  clearInterval(renew);
419
+ const resolved = resolveCacheTtl(ttlMs, this.ttlMs);
401
420
  await this.execute("publish", key, {
402
421
  owner,
403
- payload: this.serialize(value),
404
- ttlMs: ttlMs ?? this.ttlMs
422
+ payload: resolved !== null && resolved <= 0 ? "null" : this.serialize(value),
423
+ ttlMs: resolved
405
424
  });
406
425
  return value;
407
426
  } finally {
@@ -434,9 +453,7 @@ class RedisCacheStore {
434
453
  prefixes.push(key.slice(0, i));
435
454
  if (prefixes.length > 33)
436
455
  throw new RangeError("Redis cache identities support at most 32 query separators.");
437
- const ttlMs = extra.ttlMs ?? this.ttlMs;
438
- if (typeof ttlMs !== "number" || !Number.isSafeInteger(ttlMs) || ttlMs < 0)
439
- throw new RangeError("ttlMs must be a non-negative safe integer.");
456
+ const ttlMs = resolveCacheTtl(extra.ttlMs, this.ttlMs);
440
457
  if (!this.client)
441
458
  this.client = this.createClient();
442
459
  const client = this.client;
@@ -471,7 +488,8 @@ class RedisCacheStore {
471
488
  ...extra,
472
489
  tags,
473
490
  prefixes,
474
- ttlMs
491
+ ttlMs,
492
+ forever: ttlMs === null
475
493
  })
476
494
  ]),
477
495
  timeout
@@ -492,9 +510,7 @@ var redisCacheStore_default = RedisCacheStore;
492
510
 
493
511
  // ../../src/core/cache/simpleCache.ts
494
512
  function validateSimpleCacheOptions(ttlMs, maxEntries) {
495
- if (!Number.isFinite(ttlMs) || ttlMs < 0) {
496
- throw new RangeError("ttlMs must be a non-negative number.");
497
- }
513
+ resolveCacheTtl(ttlMs, ttlMs);
498
514
  if (!Number.isInteger(maxEntries) || maxEntries < 1) {
499
515
  throw new RangeError("maxEntries must be a positive integer.");
500
516
  }
@@ -515,20 +531,27 @@ class SimpleCache {
515
531
  get(key) {
516
532
  return this.getFreshEntry(key)?.value;
517
533
  }
518
- set(key, value, ttlMs) {
534
+ set(key, value, ttlMs, tags = []) {
519
535
  const now = Date.now();
520
- const resolvedTtlMs = ttlMs ?? this.ttlMs;
536
+ const resolvedTtlMs = resolveCacheTtl(ttlMs, this.ttlMs);
537
+ if (resolvedTtlMs !== null && resolvedTtlMs <= 0) {
538
+ this.invalidate(key);
539
+ return;
540
+ }
541
+ this.inflight.delete(key);
521
542
  this.cache.set(key, {
522
543
  value,
523
- expiresAt: now + resolvedTtlMs,
544
+ expiresAt: resolvedTtlMs === null ? Infinity : now + resolvedTtlMs,
524
545
  lastAccessedAt: now
525
546
  });
547
+ this.attachTags(key, tags);
526
548
  this.evictOverflow();
527
549
  }
528
550
  async getOrSet(key, loader, ttlMs) {
529
551
  return this.getOrSetTagged(key, loader, [], ttlMs);
530
552
  }
531
553
  async getOrSetTagged(key, loader, tags, ttlMs) {
554
+ resolveCacheTtl(ttlMs, this.ttlMs);
532
555
  this.pruneExpired();
533
556
  const cachedEntry = this.getFreshEntry(key);
534
557
  if (cachedEntry) {
@@ -670,7 +693,7 @@ class SimpleCache {
670
693
  oldestKey = key;
671
694
  }
672
695
  }
673
- if (!oldestKey) {
696
+ if (oldestKey === undefined) {
674
697
  return;
675
698
  }
676
699
  this.invalidate(oldestKey);
@@ -688,9 +711,8 @@ class SimpleCacheStore {
688
711
  get(key) {
689
712
  return Promise.resolve(this.cache.get(key));
690
713
  }
691
- set(key, value, ttlMs) {
692
- this.cache.set(key, value, ttlMs);
693
- return Promise.resolve();
714
+ async set(key, value, ttlMs, tags = []) {
715
+ this.cache.set(key, value, ttlMs, tags);
694
716
  }
695
717
  getOrSet(key, loader, ttlMs) {
696
718
  return this.cache.getOrSet(key, loader, ttlMs);
@@ -7,6 +7,12 @@ class TaggedCache {
7
7
  this.store = store;
8
8
  this.tags = tags;
9
9
  }
10
+ async put(key, value, ttlMs) {
11
+ await this.store.set(key, value, ttlMs, this.tags);
12
+ }
13
+ async forever(key, value) {
14
+ await this.store.set(key, value, null, this.tags);
15
+ }
10
16
  async remember(key, callback, ttlMs) {
11
17
  if (this.store.getOrSetTagged)
12
18
  return this.store.getOrSetTagged(key, callback, this.tags, ttlMs);
@@ -32,6 +38,12 @@ class CacheRepository {
32
38
  async get(key) {
33
39
  return this.store.get(key);
34
40
  }
41
+ async put(key, value, ttlMs) {
42
+ await this.store.set(key, value, ttlMs);
43
+ }
44
+ async forever(key, value) {
45
+ await this.store.set(key, value, null);
46
+ }
35
47
  async remember(key, callback, ttlMs) {
36
48
  return this.store.getOrSet(key, callback, ttlMs);
37
49
  }
@@ -65,6 +77,8 @@ function createGuardedCache(backend, operations) {
65
77
  const forget = (key) => operations.operation(() => backend.forget(key));
66
78
  const flush = () => operations.operation(() => backend.flush());
67
79
  return Object.freeze({
80
+ put: (key, value, ttlMs) => operations.operation(() => backend.put(key, value, ttlMs)),
81
+ forever: (key, value) => operations.operation(() => backend.forever(key, value)),
68
82
  get: (key) => operations.operation(() => backend.get(key)),
69
83
  remember,
70
84
  forget,
@@ -73,6 +87,8 @@ function createGuardedCache(backend, operations) {
73
87
  operations.assertActive();
74
88
  const tags = [...names];
75
89
  return Object.freeze({
90
+ put: (key, value, ttlMs) => operations.operation(() => backend.tags(...tags).put(key, value, ttlMs)),
91
+ forever: (key, value) => operations.operation(() => backend.tags(...tags).forever(key, value)),
76
92
  remember: (key, loader, ttlMs) => operations.operation(() => backend.tags(...tags).remember(key, (signal) => operations.operation(() => loader(signal)), ttlMs)),
77
93
  flush: () => operations.operation(() => backend.tags(...tags).flush())
78
94
  });
@@ -1,9 +1,16 @@
1
1
  // @bun
2
+ // ../../src/core/cache/expiration.ts
3
+ function resolveCacheTtl(ttlMs, defaultTtlMs) {
4
+ const resolved = ttlMs === undefined ? defaultTtlMs : ttlMs;
5
+ if (resolved !== null && (typeof resolved !== "number" || !Number.isSafeInteger(resolved))) {
6
+ throw new RangeError("ttlMs must be a safe integer number of milliseconds, or null for forever.");
7
+ }
8
+ return resolved;
9
+ }
10
+
2
11
  // ../../src/core/cache/simpleCache.ts
3
12
  function validateSimpleCacheOptions(ttlMs, maxEntries) {
4
- if (!Number.isFinite(ttlMs) || ttlMs < 0) {
5
- throw new RangeError("ttlMs must be a non-negative number.");
6
- }
13
+ resolveCacheTtl(ttlMs, ttlMs);
7
14
  if (!Number.isInteger(maxEntries) || maxEntries < 1) {
8
15
  throw new RangeError("maxEntries must be a positive integer.");
9
16
  }
@@ -24,20 +31,27 @@ class SimpleCache {
24
31
  get(key) {
25
32
  return this.getFreshEntry(key)?.value;
26
33
  }
27
- set(key, value, ttlMs) {
34
+ set(key, value, ttlMs, tags = []) {
28
35
  const now = Date.now();
29
- const resolvedTtlMs = ttlMs ?? this.ttlMs;
36
+ const resolvedTtlMs = resolveCacheTtl(ttlMs, this.ttlMs);
37
+ if (resolvedTtlMs !== null && resolvedTtlMs <= 0) {
38
+ this.invalidate(key);
39
+ return;
40
+ }
41
+ this.inflight.delete(key);
30
42
  this.cache.set(key, {
31
43
  value,
32
- expiresAt: now + resolvedTtlMs,
44
+ expiresAt: resolvedTtlMs === null ? Infinity : now + resolvedTtlMs,
33
45
  lastAccessedAt: now
34
46
  });
47
+ this.attachTags(key, tags);
35
48
  this.evictOverflow();
36
49
  }
37
50
  async getOrSet(key, loader, ttlMs) {
38
51
  return this.getOrSetTagged(key, loader, [], ttlMs);
39
52
  }
40
53
  async getOrSetTagged(key, loader, tags, ttlMs) {
54
+ resolveCacheTtl(ttlMs, this.ttlMs);
41
55
  this.pruneExpired();
42
56
  const cachedEntry = this.getFreshEntry(key);
43
57
  if (cachedEntry) {
@@ -179,7 +193,7 @@ class SimpleCache {
179
193
  oldestKey = key;
180
194
  }
181
195
  }
182
- if (!oldestKey) {
196
+ if (oldestKey === undefined) {
183
197
  return;
184
198
  }
185
199
  this.invalidate(oldestKey);
@@ -8,9 +8,8 @@ class SimpleCacheStore {
8
8
  get(key) {
9
9
  return Promise.resolve(this.cache.get(key));
10
10
  }
11
- set(key, value, ttlMs) {
12
- this.cache.set(key, value, ttlMs);
13
- return Promise.resolve();
11
+ async set(key, value, ttlMs, tags = []) {
12
+ this.cache.set(key, value, ttlMs, tags);
14
13
  }
15
14
  getOrSet(key, loader, ttlMs) {
16
15
  return this.cache.getOrSet(key, loader, ttlMs);
@@ -1201,10 +1201,6 @@ function sqliteFilename(filename) {
1201
1201
  throw new Error("SQLite path is not configured. Pass a filename or :memory:.");
1202
1202
  return filename === ":memory:" ? filename : resolve(filename);
1203
1203
  }
1204
- function isRowReturning(sql) {
1205
- const upper = sql.replace(/\s+/g, " ").trim().toUpperCase();
1206
- return upper.includes(" RETURNING ") || upper.startsWith("SELECT") || upper.startsWith("WITH") || upper.startsWith("PRAGMA") || upper.startsWith("EXPLAIN");
1207
- }
1208
1204
  function openRawSqlitePool(options) {
1209
1205
  let filename;
1210
1206
  try {
@@ -1248,7 +1244,7 @@ function openRawSqlitePool(options) {
1248
1244
  check();
1249
1245
  const query = db.query(statement.text);
1250
1246
  const params = statement.params.map((value) => value instanceof Date ? value.toISOString() : value);
1251
- if (isRowReturning(statement.text))
1247
+ if (query.columnNames.length > 0)
1252
1248
  return Promise.resolve(query.all(...params));
1253
1249
  query.run(...params);
1254
1250
  return Promise.resolve([]);
@@ -538,10 +538,6 @@ function sqliteFilename(filename) {
538
538
  throw new Error("SQLite path is not configured. Pass a filename or :memory:.");
539
539
  return filename === ":memory:" ? filename : resolve(filename);
540
540
  }
541
- function isRowReturning(sql) {
542
- const upper = sql.replace(/\s+/g, " ").trim().toUpperCase();
543
- return upper.includes(" RETURNING ") || upper.startsWith("SELECT") || upper.startsWith("WITH") || upper.startsWith("PRAGMA") || upper.startsWith("EXPLAIN");
544
- }
545
541
  function openRawSqlitePool(options) {
546
542
  let filename;
547
543
  try {
@@ -585,7 +581,7 @@ function openRawSqlitePool(options) {
585
581
  check();
586
582
  const query = db.query(statement.text);
587
583
  const params = statement.params.map((value) => value instanceof Date ? value.toISOString() : value);
588
- if (isRowReturning(statement.text))
584
+ if (query.columnNames.length > 0)
589
585
  return Promise.resolve(query.all(...params));
590
586
  query.run(...params);
591
587
  return Promise.resolve([]);
@@ -487,10 +487,6 @@ function sqliteFilename(filename) {
487
487
  throw new Error("SQLite path is not configured. Pass a filename or :memory:.");
488
488
  return filename === ":memory:" ? filename : resolve(filename);
489
489
  }
490
- function isRowReturning(sql) {
491
- const upper = sql.replace(/\s+/g, " ").trim().toUpperCase();
492
- return upper.includes(" RETURNING ") || upper.startsWith("SELECT") || upper.startsWith("WITH") || upper.startsWith("PRAGMA") || upper.startsWith("EXPLAIN");
493
- }
494
490
  function openRawSqlitePool(options) {
495
491
  let filename;
496
492
  try {
@@ -534,7 +530,7 @@ function openRawSqlitePool(options) {
534
530
  check();
535
531
  const query = db.query(statement.text);
536
532
  const params = statement.params.map((value) => value instanceof Date ? value.toISOString() : value);
537
- if (isRowReturning(statement.text))
533
+ if (query.columnNames.length > 0)
538
534
  return Promise.resolve(query.all(...params));
539
535
  query.run(...params);
540
536
  return Promise.resolve([]);
@@ -56,6 +56,38 @@ function otelServiceName(env = process.env) {
56
56
  return env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix(env)}-api`;
57
57
  }
58
58
 
59
+ // ../../src/core/http/cookies.ts
60
+ function readRequestCookie(request, name) {
61
+ const cookies = request.cookies;
62
+ if (cookies && typeof cookies.get === "function") {
63
+ const value = cookies.get(name);
64
+ if (value) {
65
+ return value;
66
+ }
67
+ }
68
+ const header = request.headers.get("cookie");
69
+ if (!header) {
70
+ return null;
71
+ }
72
+ for (const part of header.split(";")) {
73
+ const idx = part.indexOf("=");
74
+ if (idx === -1)
75
+ continue;
76
+ const cookieName = part.slice(0, idx).trim();
77
+ if (cookieName !== name)
78
+ continue;
79
+ try {
80
+ return decodeURIComponent(part.slice(idx + 1).trim());
81
+ } catch {
82
+ return null;
83
+ }
84
+ }
85
+ return null;
86
+ }
87
+ function readBunRequestCookie(request, name) {
88
+ return request.cookies.get(name) ?? readRequestCookie(request, name);
89
+ }
90
+
59
91
  // ../../src/core/http/flashSession.ts
60
92
  var FLASH_COOKIE = "strata_flash";
61
93
  var FLASH_TTL_MS = 60 * 1000;
@@ -73,19 +105,6 @@ function signFlashPayload(payload, issuedAt, options) {
73
105
  const signature = createHmac("sha256", options.secret).update(`${payload}.${issuedAt}`).digest("hex");
74
106
  return `${payload}.${issuedAt}.${signature}`;
75
107
  }
76
- function readFlashCookie(request, options) {
77
- const cookieHeader = request.headers.get("cookie");
78
- if (!cookieHeader) {
79
- return null;
80
- }
81
- for (const part of cookieHeader.split(";")) {
82
- const [name, ...rest] = part.trim().split("=");
83
- if (name === options.cookieName) {
84
- return decodeURIComponent(rest.join("="));
85
- }
86
- }
87
- return null;
88
- }
89
108
  function parseFlashCookie(cookieValue, options) {
90
109
  const parts = cookieValue.split(".");
91
110
  if (parts.length < 3) {
@@ -138,7 +157,7 @@ function clearFlashCookie(options) {
138
157
  return `${options.cookieName}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0${secure}`;
139
158
  }
140
159
  function pullFlash(request, options) {
141
- const cookieValue = readFlashCookie(request, options);
160
+ const cookieValue = readRequestCookie(request, options.cookieName);
142
161
  if (!cookieValue) {
143
162
  return null;
144
163
  }
@@ -56,6 +56,38 @@ function otelServiceName(env = process.env) {
56
56
  return env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix(env)}-api`;
57
57
  }
58
58
 
59
+ // ../../src/core/http/cookies.ts
60
+ function readRequestCookie(request, name) {
61
+ const cookies = request.cookies;
62
+ if (cookies && typeof cookies.get === "function") {
63
+ const value = cookies.get(name);
64
+ if (value) {
65
+ return value;
66
+ }
67
+ }
68
+ const header = request.headers.get("cookie");
69
+ if (!header) {
70
+ return null;
71
+ }
72
+ for (const part of header.split(";")) {
73
+ const idx = part.indexOf("=");
74
+ if (idx === -1)
75
+ continue;
76
+ const cookieName = part.slice(0, idx).trim();
77
+ if (cookieName !== name)
78
+ continue;
79
+ try {
80
+ return decodeURIComponent(part.slice(idx + 1).trim());
81
+ } catch {
82
+ return null;
83
+ }
84
+ }
85
+ return null;
86
+ }
87
+ function readBunRequestCookie(request, name) {
88
+ return request.cookies.get(name) ?? readRequestCookie(request, name);
89
+ }
90
+
59
91
  // ../../src/core/http/flashSession.ts
60
92
  var FLASH_COOKIE = "strata_flash";
61
93
  var FLASH_TTL_MS = 60 * 1000;
@@ -73,19 +105,6 @@ function signFlashPayload(payload, issuedAt, options) {
73
105
  const signature = createHmac("sha256", options.secret).update(`${payload}.${issuedAt}`).digest("hex");
74
106
  return `${payload}.${issuedAt}.${signature}`;
75
107
  }
76
- function readFlashCookie(request, options) {
77
- const cookieHeader = request.headers.get("cookie");
78
- if (!cookieHeader) {
79
- return null;
80
- }
81
- for (const part of cookieHeader.split(";")) {
82
- const [name, ...rest] = part.trim().split("=");
83
- if (name === options.cookieName) {
84
- return decodeURIComponent(rest.join("="));
85
- }
86
- }
87
- return null;
88
- }
89
108
  function parseFlashCookie(cookieValue, options) {
90
109
  const parts = cookieValue.split(".");
91
110
  if (parts.length < 3) {
@@ -138,7 +157,7 @@ function clearFlashCookie(options) {
138
157
  return `${options.cookieName}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0${secure}`;
139
158
  }
140
159
  function pullFlash(request, options) {
141
- const cookieValue = readFlashCookie(request, options);
160
+ const cookieValue = readRequestCookie(request, options.cookieName);
142
161
  if (!cookieValue) {
143
162
  return null;
144
163
  }
@@ -131,6 +131,9 @@ import { currentRequestMeta as currentRequestMeta3 } from "@getstrata/core/http/
131
131
  var NESTED_REDIRECT_KEYS = new Set(["redirect", "next", "return", "returnTo", "return_to"]);
132
132
  function looksLikeExternalTarget(value) {
133
133
  const trimmed = value.trim();
134
+ if (/[\t\r\n]/.test(trimmed)) {
135
+ return true;
136
+ }
134
137
  if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("\\")) {
135
138
  return true;
136
139
  }
@@ -156,13 +159,13 @@ function sanitizeNestedQuery(search) {
156
159
  for (const [key, value] of params.entries()) {
157
160
  if (NESTED_REDIRECT_KEYS.has(key)) {
158
161
  const sanitized = sanitizeInternalPath(value, "/");
159
- next.set(key, sanitized);
162
+ next.append(key, sanitized);
160
163
  continue;
161
164
  }
162
165
  if (looksLikeExternalTarget(value) && value.includes("://")) {
163
166
  continue;
164
167
  }
165
- next.set(key, value);
168
+ next.append(key, value);
166
169
  }
167
170
  const serialized = next.toString();
168
171
  return serialized ? `?${serialized}` : "";
@@ -69,6 +69,9 @@ function currentRequestMeta() {
69
69
  var NESTED_REDIRECT_KEYS = new Set(["redirect", "next", "return", "returnTo", "return_to"]);
70
70
  function looksLikeExternalTarget(value) {
71
71
  const trimmed = value.trim();
72
+ if (/[\t\r\n]/.test(trimmed)) {
73
+ return true;
74
+ }
72
75
  if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("\\")) {
73
76
  return true;
74
77
  }
@@ -94,13 +97,13 @@ function sanitizeNestedQuery(search) {
94
97
  for (const [key, value] of params.entries()) {
95
98
  if (NESTED_REDIRECT_KEYS.has(key)) {
96
99
  const sanitized = sanitizeInternalPath(value, "/");
97
- next.set(key, sanitized);
100
+ next.append(key, sanitized);
98
101
  continue;
99
102
  }
100
103
  if (looksLikeExternalTarget(value) && value.includes("://")) {
101
104
  continue;
102
105
  }
103
- next.set(key, value);
106
+ next.append(key, value);
104
107
  }
105
108
  const serialized = next.toString();
106
109
  return serialized ? `?${serialized}` : "";
@@ -39,6 +39,9 @@ function requestPrefersJson(request) {
39
39
  var NESTED_REDIRECT_KEYS = new Set(["redirect", "next", "return", "returnTo", "return_to"]);
40
40
  function looksLikeExternalTarget(value) {
41
41
  const trimmed = value.trim();
42
+ if (/[\t\r\n]/.test(trimmed)) {
43
+ return true;
44
+ }
42
45
  if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("\\")) {
43
46
  return true;
44
47
  }
@@ -64,13 +67,13 @@ function sanitizeNestedQuery(search) {
64
67
  for (const [key, value] of params.entries()) {
65
68
  if (NESTED_REDIRECT_KEYS.has(key)) {
66
69
  const sanitized = sanitizeInternalPath(value, "/");
67
- next.set(key, sanitized);
70
+ next.append(key, sanitized);
68
71
  continue;
69
72
  }
70
73
  if (looksLikeExternalTarget(value) && value.includes("://")) {
71
74
  continue;
72
75
  }
73
- next.set(key, value);
76
+ next.append(key, value);
74
77
  }
75
78
  const serialized = next.toString();
76
79
  return serialized ? `?${serialized}` : "";
@@ -3,6 +3,9 @@
3
3
  var NESTED_REDIRECT_KEYS = new Set(["redirect", "next", "return", "returnTo", "return_to"]);
4
4
  function looksLikeExternalTarget(value) {
5
5
  const trimmed = value.trim();
6
+ if (/[\t\r\n]/.test(trimmed)) {
7
+ return true;
8
+ }
6
9
  if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("\\")) {
7
10
  return true;
8
11
  }
@@ -28,13 +31,13 @@ function sanitizeNestedQuery(search) {
28
31
  for (const [key, value] of params.entries()) {
29
32
  if (NESTED_REDIRECT_KEYS.has(key)) {
30
33
  const sanitized = sanitizeInternalPath(value, "/");
31
- next.set(key, sanitized);
34
+ next.append(key, sanitized);
32
35
  continue;
33
36
  }
34
37
  if (looksLikeExternalTarget(value) && value.includes("://")) {
35
38
  continue;
36
39
  }
37
- next.set(key, value);
40
+ next.append(key, value);
38
41
  }
39
42
  const serialized = next.toString();
40
43
  return serialized ? `?${serialized}` : "";
@@ -134,6 +134,9 @@ import { currentRequestMeta as currentRequestMeta3 } from "@getstrata/core/http/
134
134
  var NESTED_REDIRECT_KEYS = new Set(["redirect", "next", "return", "returnTo", "return_to"]);
135
135
  function looksLikeExternalTarget(value) {
136
136
  const trimmed = value.trim();
137
+ if (/[\t\r\n]/.test(trimmed)) {
138
+ return true;
139
+ }
137
140
  if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("\\")) {
138
141
  return true;
139
142
  }
@@ -159,13 +162,13 @@ function sanitizeNestedQuery(search) {
159
162
  for (const [key, value] of params.entries()) {
160
163
  if (NESTED_REDIRECT_KEYS.has(key)) {
161
164
  const sanitized = sanitizeInternalPath(value, "/");
162
- next.set(key, sanitized);
165
+ next.append(key, sanitized);
163
166
  continue;
164
167
  }
165
168
  if (looksLikeExternalTarget(value) && value.includes("://")) {
166
169
  continue;
167
170
  }
168
- next.set(key, value);
171
+ next.append(key, value);
169
172
  }
170
173
  const serialized = next.toString();
171
174
  return serialized ? `?${serialized}` : "";
@@ -70,6 +70,9 @@ import { currentRequestMeta as currentRequestMeta3 } from "@getstrata/core/http/
70
70
  var NESTED_REDIRECT_KEYS = new Set(["redirect", "next", "return", "returnTo", "return_to"]);
71
71
  function looksLikeExternalTarget(value) {
72
72
  const trimmed = value.trim();
73
+ if (/[\t\r\n]/.test(trimmed)) {
74
+ return true;
75
+ }
73
76
  if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("\\")) {
74
77
  return true;
75
78
  }
@@ -95,13 +98,13 @@ function sanitizeNestedQuery(search) {
95
98
  for (const [key, value] of params.entries()) {
96
99
  if (NESTED_REDIRECT_KEYS.has(key)) {
97
100
  const sanitized = sanitizeInternalPath(value, "/");
98
- next.set(key, sanitized);
101
+ next.append(key, sanitized);
99
102
  continue;
100
103
  }
101
104
  if (looksLikeExternalTarget(value) && value.includes("://")) {
102
105
  continue;
103
106
  }
104
- next.set(key, value);
107
+ next.append(key, value);
105
108
  }
106
109
  const serialized = next.toString();
107
110
  return serialized ? `?${serialized}` : "";
package/dist/index.js CHANGED
@@ -2227,6 +2227,15 @@ function copyApplicationConfig(value, ancestors = new Set) {
2227
2227
  // ../../src/core/cache/redisCacheStore.ts
2228
2228
  var {RedisClient } = globalThis.Bun;
2229
2229
 
2230
+ // ../../src/core/cache/expiration.ts
2231
+ function resolveCacheTtl(ttlMs, defaultTtlMs) {
2232
+ const resolved = ttlMs === undefined ? defaultTtlMs : ttlMs;
2233
+ if (resolved !== null && (typeof resolved !== "number" || !Number.isSafeInteger(resolved))) {
2234
+ throw new RangeError("ttlMs must be a safe integer number of milliseconds, or null for forever.");
2235
+ }
2236
+ return resolved;
2237
+ }
2238
+
2230
2239
  // ../../src/core/cache/redisCacheScript.ts
2231
2240
  var CACHE_SCRIPT = `
2232
2241
  local expected = {'hash', 'zset', 'zset', 'hash', 'zset'}
@@ -2302,9 +2311,10 @@ local function read(key, tags)
2302
2311
  return entry.payload
2303
2312
  end
2304
2313
  local function write(key, payload, tags)
2314
+ if not r.forever and r.ttlMs <= 0 then removeEntry(key); return end
2305
2315
  local entry = {payload=payload, tags=tags}
2306
2316
  redis.call('HSET', KEYS[1], 'e:' .. key, cjson.encode(entry))
2307
- redis.call('ZADD', KEYS[2], r.ttlMs == 0 and '+inf' or now + r.ttlMs, key)
2317
+ redis.call('ZADD', KEYS[2], r.forever and '+inf' or now + r.ttlMs, key)
2308
2318
  touch(key)
2309
2319
  local overflow = redis.call('ZCARD', KEYS[3]) - r.capacity
2310
2320
  if overflow > 0 then
@@ -2354,7 +2364,7 @@ elseif r.op == 'get' then
2354
2364
  return response(payload and {kind='value', payload=payload} or {kind='missing'})
2355
2365
  elseif r.op == 'set' then
2356
2366
  local old = redis.call('HGET', KEYS[1], 'e:' .. r.key)
2357
- local tags = old and cjson.decode(old).tags or {}
2367
+ local tags = addTags(old and cjson.decode(old).tags or {}, r.tags)
2358
2368
  write(r.key, r.payload, tags)
2359
2369
  removeMeta(leaseField)
2360
2370
  return response({written=true})
@@ -2434,8 +2444,7 @@ function validateCacheNamespace(namespace) {
2434
2444
  throw new TypeError("Cache namespace must be a nonempty string.");
2435
2445
  }
2436
2446
  function normalizeRedisCacheOptions(ttlMs, maxEntries, options = {}) {
2437
- if (!Number.isSafeInteger(ttlMs) || ttlMs < 0)
2438
- throw new RangeError("ttlMs must be a non-negative safe integer.");
2447
+ resolveCacheTtl(ttlMs, ttlMs);
2439
2448
  if (!Number.isInteger(maxEntries) || maxEntries < 1 || maxEntries > 1e4)
2440
2449
  throw new RangeError("maxEntries must be between 1 and 10000.");
2441
2450
  const copied = copyApplicationConfig(options);
@@ -2495,8 +2504,13 @@ class RedisCacheStore {
2495
2504
  const result = await this.execute("get", key);
2496
2505
  return result.kind === "value" ? JSON.parse(result.payload ?? "null") : undefined;
2497
2506
  }
2498
- async set(key, value, ttlMs) {
2499
- await this.execute("set", key, { payload: this.serialize(value), ttlMs: ttlMs ?? this.ttlMs });
2507
+ async set(key, value, ttlMs, tags = []) {
2508
+ const resolved = resolveCacheTtl(ttlMs, this.ttlMs);
2509
+ await this.execute("set", key, {
2510
+ payload: resolved !== null && resolved <= 0 ? "null" : this.serialize(value),
2511
+ ttlMs: resolved,
2512
+ tags
2513
+ });
2500
2514
  }
2501
2515
  async getOrSet(key, loader, ttlMs) {
2502
2516
  return this.getOrSetTagged(key, loader, [], ttlMs);
@@ -2505,7 +2519,11 @@ class RedisCacheStore {
2505
2519
  const owner = crypto.randomUUID();
2506
2520
  const end = performance.now() + this.options.waitTimeoutMs;
2507
2521
  while (!this.closed) {
2508
- const claim = await this.execute("claim", key, { owner, tags, ttlMs: ttlMs ?? this.ttlMs });
2522
+ const claim = await this.execute("claim", key, {
2523
+ owner,
2524
+ tags,
2525
+ ttlMs: resolveCacheTtl(ttlMs, this.ttlMs)
2526
+ });
2509
2527
  if (claim.kind === "value")
2510
2528
  return JSON.parse(claim.payload ?? "null");
2511
2529
  if (claim.kind === "owner")
@@ -2571,10 +2589,11 @@ class RedisCacheStore {
2571
2589
  controller.signal.throwIfAborted();
2572
2590
  done = true;
2573
2591
  clearInterval(renew);
2592
+ const resolved = resolveCacheTtl(ttlMs, this.ttlMs);
2574
2593
  await this.execute("publish", key, {
2575
2594
  owner,
2576
- payload: this.serialize(value),
2577
- ttlMs: ttlMs ?? this.ttlMs
2595
+ payload: resolved !== null && resolved <= 0 ? "null" : this.serialize(value),
2596
+ ttlMs: resolved
2578
2597
  });
2579
2598
  return value;
2580
2599
  } finally {
@@ -2607,9 +2626,7 @@ class RedisCacheStore {
2607
2626
  prefixes.push(key.slice(0, i));
2608
2627
  if (prefixes.length > 33)
2609
2628
  throw new RangeError("Redis cache identities support at most 32 query separators.");
2610
- const ttlMs = extra.ttlMs ?? this.ttlMs;
2611
- if (typeof ttlMs !== "number" || !Number.isSafeInteger(ttlMs) || ttlMs < 0)
2612
- throw new RangeError("ttlMs must be a non-negative safe integer.");
2629
+ const ttlMs = resolveCacheTtl(extra.ttlMs, this.ttlMs);
2613
2630
  if (!this.client)
2614
2631
  this.client = this.createClient();
2615
2632
  const client = this.client;
@@ -2644,7 +2661,8 @@ class RedisCacheStore {
2644
2661
  ...extra,
2645
2662
  tags,
2646
2663
  prefixes,
2647
- ttlMs
2664
+ ttlMs,
2665
+ forever: ttlMs === null
2648
2666
  })
2649
2667
  ]),
2650
2668
  timeout
@@ -2665,9 +2683,7 @@ var redisCacheStore_default = RedisCacheStore;
2665
2683
 
2666
2684
  // ../../src/core/cache/simpleCache.ts
2667
2685
  function validateSimpleCacheOptions(ttlMs, maxEntries) {
2668
- if (!Number.isFinite(ttlMs) || ttlMs < 0) {
2669
- throw new RangeError("ttlMs must be a non-negative number.");
2670
- }
2686
+ resolveCacheTtl(ttlMs, ttlMs);
2671
2687
  if (!Number.isInteger(maxEntries) || maxEntries < 1) {
2672
2688
  throw new RangeError("maxEntries must be a positive integer.");
2673
2689
  }
@@ -2688,20 +2704,27 @@ class SimpleCache {
2688
2704
  get(key) {
2689
2705
  return this.getFreshEntry(key)?.value;
2690
2706
  }
2691
- set(key, value, ttlMs) {
2707
+ set(key, value, ttlMs, tags = []) {
2692
2708
  const now = Date.now();
2693
- const resolvedTtlMs = ttlMs ?? this.ttlMs;
2709
+ const resolvedTtlMs = resolveCacheTtl(ttlMs, this.ttlMs);
2710
+ if (resolvedTtlMs !== null && resolvedTtlMs <= 0) {
2711
+ this.invalidate(key);
2712
+ return;
2713
+ }
2714
+ this.inflight.delete(key);
2694
2715
  this.cache.set(key, {
2695
2716
  value,
2696
- expiresAt: now + resolvedTtlMs,
2717
+ expiresAt: resolvedTtlMs === null ? Infinity : now + resolvedTtlMs,
2697
2718
  lastAccessedAt: now
2698
2719
  });
2720
+ this.attachTags(key, tags);
2699
2721
  this.evictOverflow();
2700
2722
  }
2701
2723
  async getOrSet(key, loader, ttlMs) {
2702
2724
  return this.getOrSetTagged(key, loader, [], ttlMs);
2703
2725
  }
2704
2726
  async getOrSetTagged(key, loader, tags, ttlMs) {
2727
+ resolveCacheTtl(ttlMs, this.ttlMs);
2705
2728
  this.pruneExpired();
2706
2729
  const cachedEntry = this.getFreshEntry(key);
2707
2730
  if (cachedEntry) {
@@ -2843,7 +2866,7 @@ class SimpleCache {
2843
2866
  oldestKey = key;
2844
2867
  }
2845
2868
  }
2846
- if (!oldestKey) {
2869
+ if (oldestKey === undefined) {
2847
2870
  return;
2848
2871
  }
2849
2872
  this.invalidate(oldestKey);
@@ -2861,9 +2884,8 @@ class SimpleCacheStore {
2861
2884
  get(key) {
2862
2885
  return Promise.resolve(this.cache.get(key));
2863
2886
  }
2864
- set(key, value, ttlMs) {
2865
- this.cache.set(key, value, ttlMs);
2866
- return Promise.resolve();
2887
+ async set(key, value, ttlMs, tags = []) {
2888
+ this.cache.set(key, value, ttlMs, tags);
2867
2889
  }
2868
2890
  getOrSet(key, loader, ttlMs) {
2869
2891
  return this.cache.getOrSet(key, loader, ttlMs);
@@ -2937,6 +2959,12 @@ class TaggedCache {
2937
2959
  this.store = store;
2938
2960
  this.tags = tags;
2939
2961
  }
2962
+ async put(key, value, ttlMs) {
2963
+ await this.store.set(key, value, ttlMs, this.tags);
2964
+ }
2965
+ async forever(key, value) {
2966
+ await this.store.set(key, value, null, this.tags);
2967
+ }
2940
2968
  async remember(key, callback, ttlMs) {
2941
2969
  if (this.store.getOrSetTagged)
2942
2970
  return this.store.getOrSetTagged(key, callback, this.tags, ttlMs);
@@ -2962,6 +2990,12 @@ class CacheRepository {
2962
2990
  async get(key) {
2963
2991
  return this.store.get(key);
2964
2992
  }
2993
+ async put(key, value, ttlMs) {
2994
+ await this.store.set(key, value, ttlMs);
2995
+ }
2996
+ async forever(key, value) {
2997
+ await this.store.set(key, value, null);
2998
+ }
2965
2999
  async remember(key, callback, ttlMs) {
2966
3000
  return this.store.getOrSet(key, callback, ttlMs);
2967
3001
  }
@@ -5162,10 +5196,6 @@ function sqliteFilename(filename) {
5162
5196
  throw new Error("SQLite path is not configured. Pass a filename or :memory:.");
5163
5197
  return filename === ":memory:" ? filename : resolve(filename);
5164
5198
  }
5165
- function isRowReturning(sql) {
5166
- const upper = sql.replace(/\s+/g, " ").trim().toUpperCase();
5167
- return upper.includes(" RETURNING ") || upper.startsWith("SELECT") || upper.startsWith("WITH") || upper.startsWith("PRAGMA") || upper.startsWith("EXPLAIN");
5168
- }
5169
5199
  function openRawSqlitePool(options) {
5170
5200
  let filename;
5171
5201
  try {
@@ -5209,7 +5239,7 @@ function openRawSqlitePool(options) {
5209
5239
  check();
5210
5240
  const query = db.query(statement.text);
5211
5241
  const params = statement.params.map((value) => value instanceof Date ? value.toISOString() : value);
5212
- if (isRowReturning(statement.text))
5242
+ if (query.columnNames.length > 0)
5213
5243
  return Promise.resolve(query.all(...params));
5214
5244
  query.run(...params);
5215
5245
  return Promise.resolve([]);
@@ -10135,6 +10165,9 @@ function resolveRequestId(request) {
10135
10165
  var NESTED_REDIRECT_KEYS = new Set(["redirect", "next", "return", "returnTo", "return_to"]);
10136
10166
  function looksLikeExternalTarget(value) {
10137
10167
  const trimmed = value.trim();
10168
+ if (/[\t\r\n]/.test(trimmed)) {
10169
+ return true;
10170
+ }
10138
10171
  if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("\\")) {
10139
10172
  return true;
10140
10173
  }
@@ -10160,13 +10193,13 @@ function sanitizeNestedQuery(search) {
10160
10193
  for (const [key, value] of params.entries()) {
10161
10194
  if (NESTED_REDIRECT_KEYS.has(key)) {
10162
10195
  const sanitized = sanitizeInternalPath(value, "/");
10163
- next.set(key, sanitized);
10196
+ next.append(key, sanitized);
10164
10197
  continue;
10165
10198
  }
10166
10199
  if (looksLikeExternalTarget(value) && value.includes("://")) {
10167
10200
  continue;
10168
10201
  }
10169
- next.set(key, value);
10202
+ next.append(key, value);
10170
10203
  }
10171
10204
  const serialized = next.toString();
10172
10205
  return serialized ? `?${serialized}` : "";
@@ -11220,19 +11253,6 @@ function signFlashPayload(payload, issuedAt, options) {
11220
11253
  const signature = createHmac4("sha256", options.secret).update(`${payload}.${issuedAt}`).digest("hex");
11221
11254
  return `${payload}.${issuedAt}.${signature}`;
11222
11255
  }
11223
- function readFlashCookie(request, options) {
11224
- const cookieHeader = request.headers.get("cookie");
11225
- if (!cookieHeader) {
11226
- return null;
11227
- }
11228
- for (const part of cookieHeader.split(";")) {
11229
- const [name, ...rest] = part.trim().split("=");
11230
- if (name === options.cookieName) {
11231
- return decodeURIComponent(rest.join("="));
11232
- }
11233
- }
11234
- return null;
11235
- }
11236
11256
  function parseFlashCookie(cookieValue, options) {
11237
11257
  const parts = cookieValue.split(".");
11238
11258
  if (parts.length < 3) {
@@ -11278,7 +11298,7 @@ function clearFlashCookie(options) {
11278
11298
  return `${options.cookieName}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0${secure}`;
11279
11299
  }
11280
11300
  function pullFlash(request, options) {
11281
- const cookieValue = readFlashCookie(request, options);
11301
+ const cookieValue = readRequestCookie(request, options.cookieName);
11282
11302
  if (!cookieValue) {
11283
11303
  return null;
11284
11304
  }
@@ -1,9 +1,13 @@
1
1
  interface CacheLike {
2
+ put<T>(key: string, value: T, ttlMs?: number): Promise<void>;
3
+ forever<T>(key: string, value: T): Promise<void>;
2
4
  get<T>(key: string): Promise<T | undefined>;
3
5
  remember<T>(key: string, callback: (signal?: AbortSignal) => Promise<T>, ttlMs?: number): Promise<T>;
4
6
  forget(key: string): Promise<boolean>;
5
7
  flush(): Promise<void>;
6
8
  tags(...names: string[]): {
9
+ put<T>(key: string, value: T, ttlMs?: number): Promise<void>;
10
+ forever<T>(key: string, value: T): Promise<void>;
7
11
  remember<T>(key: string, callback: (signal?: AbortSignal) => Promise<T>, ttlMs?: number): Promise<T>;
8
12
  flush(): Promise<number>;
9
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/core",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "Strata Bun framework public API",
5
5
  "type": "module",
6
6
  "license": "MIT",