@hasna/economy 0.2.41 → 0.2.43

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.
@@ -0,0 +1,31 @@
1
+ // @bun
2
+ // src/db/pg-sync-worker.ts
3
+ import { parentPort, workerData } from "worker_threads";
4
+ import pg from "pg";
5
+ pg.types.setTypeParser(20, (v) => v === null ? null : Number(v));
6
+ pg.types.setTypeParser(1700, (v) => v === null ? null : Number(v));
7
+ var dsn = workerData?.dsn;
8
+ var ssl = dsn && (dsn.includes("sslmode=require") || dsn.includes("ssl=true")) ? { rejectUnauthorized: false } : undefined;
9
+ var pool = new pg.Pool({
10
+ connectionString: dsn,
11
+ ssl,
12
+ max: Number(process.env["ECONOMY_PG_POOL_MAX"] ?? "5"),
13
+ connectionTimeoutMillis: 1e4
14
+ });
15
+ pool.on("error", (err) => {
16
+ console.error(JSON.stringify({ evt: "pg_worker_pool_error", message: err.message }));
17
+ });
18
+ var replyPort = null;
19
+ parentPort?.on("message", (msg) => {
20
+ if (msg.type === "init") {
21
+ replyPort = msg.port;
22
+ return;
23
+ }
24
+ const { id, sql, params, signal } = msg;
25
+ const sig = new Int32Array(signal);
26
+ pool.query(sql, params).then((res) => ({ id, ok: true, rows: res.rows, rowCount: res.rowCount ?? 0 })).catch((err) => ({ id, ok: false, error: err instanceof Error ? err.message : String(err) })).then((response) => {
27
+ replyPort?.postMessage(response);
28
+ Atomics.store(sig, 0, 1);
29
+ Atomics.notify(sig, 0);
30
+ });
31
+ });
@@ -1,4 +1,23 @@
1
1
  import type { SqliteAdapter as Database } from '@hasna/cloud';
2
+ /** The serve OpenAPI document (source of the generated SDK), version-synced. */
3
+ export declare function openApiDocument(): Record<string, unknown>;
4
+ /**
5
+ * Framework-agnostic API-key verifier shape (matches `@hasna/contracts/auth`
6
+ * `ApiKeyVerifier`). Kept structural so serve.ts has no hard dependency on the
7
+ * auth package; the entry point injects the real verifier.
8
+ */
9
+ export interface ApiAuthenticator {
10
+ authenticate(headers: Headers, context?: {
11
+ method?: string | null;
12
+ path?: string | null;
13
+ requiredScopes?: readonly string[];
14
+ }): Promise<{
15
+ ok: boolean;
16
+ status: number;
17
+ reason?: string;
18
+ message?: string;
19
+ }>;
20
+ }
2
21
  interface StartServerOptions {
3
22
  db?: Database;
4
23
  dashboardDir?: string;
@@ -6,7 +25,18 @@ interface StartServerOptions {
6
25
  log?: (message: string) => void;
7
26
  }
8
27
  export declare function createServerFetch(apiHandler: (req: Request) => Promise<Response>, dashboardDir?: string): (req: Request) => Promise<Response>;
9
- export declare function createHandler(db: Database): (req: Request) => Promise<Response>;
28
+ export interface HandlerOptions {
29
+ /** API-key verifier (from `@hasna/contracts/auth`). When present, every
30
+ * request outside the open foundation probes must present a valid
31
+ * `economy:*` scoped key. This is the internet-facing auth path. */
32
+ authenticator?: ApiAuthenticator;
33
+ /** Readiness probe proving storage is reachable + migrated. */
34
+ readyCheck?: () => Promise<{
35
+ ready: boolean;
36
+ detail?: string;
37
+ }>;
38
+ }
39
+ export declare function createHandler(db: Database, options?: HandlerOptions): (req: Request) => Promise<Response>;
10
40
  export declare function startServer(port?: number, options?: StartServerOptions): ReturnType<typeof Bun.serve>;
11
41
  export {};
12
42
  //# sourceMappingURL=serve.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/server/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAA;AAuC7D,UAAU,kBAAkB;IAC1B,EAAE,CAAC,EAAE,QAAQ,CAAA;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAChC;AAqED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ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