symmetria 1.0.0

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,12 @@
1
+ //#region src/schema/binding.ts
2
+ /** Rebind compiled schema metadata without evaluating declaration callbacks again. */
3
+ const SCHEMA_BIND = Symbol("symmetria.schema.bind");
4
+ /** Bind a reusable schema to a driver, retaining its inferred query API and scopes. */
5
+ const createDatabase = ({ schema: model, driver }) => {
6
+ if (!model || typeof model[SCHEMA_BIND] !== "function") throw new Error("symmetria: createDatabase() expects a schema() declaration");
7
+ return model[SCHEMA_BIND](driver);
8
+ };
9
+ //#endregion
10
+ export { createDatabase as n, SCHEMA_BIND as t };
11
+
12
+ //# sourceMappingURL=binding-CD-0xNaB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding-CD-0xNaB.js","names":[],"sources":["../src/schema/binding.ts"],"sourcesContent":["import type { Driver } from \"../query/plan/types\";\n\n/** Rebind compiled schema metadata without evaluating declaration callbacks again. */\nexport const SCHEMA_BIND = Symbol(\"symmetria.schema.bind\");\nexport type BindableSchema = {\n readonly [SCHEMA_BIND]: (driver: Driver) => unknown;\n};\n\nexport type DatabaseOptions<Model extends BindableSchema> = {\n readonly schema: Model;\n readonly driver: Driver;\n};\n\n/** Bind a reusable schema to a driver, retaining its inferred query API and scopes. */\nexport const createDatabase = <Model extends BindableSchema>({\n schema: model,\n driver,\n}: DatabaseOptions<Model>): ReturnType<Model[typeof SCHEMA_BIND]> => {\n if (!model || typeof model[SCHEMA_BIND] !== \"function\") {\n throw new Error(\n \"symmetria: createDatabase() expects a schema() declaration\",\n );\n }\n\n return model[SCHEMA_BIND](driver) as ReturnType<Model[typeof SCHEMA_BIND]>;\n};\n"],"mappings":";;AAGA,MAAa,cAAc,OAAO,uBAAuB;;AAWzD,MAAa,kBAAgD,EAC3D,QAAQ,OACR,aACmE;CACnE,IAAI,CAAC,SAAS,OAAO,MAAM,iBAAiB,YAC1C,MAAM,IAAI,MACR,4DACF;CAGF,OAAO,MAAM,YAAY,CAAC,MAAM;AAClC"}
package/dist/bun.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { K as SCHEMA_BIND, W as BindableSchema, c as SessionDriver, l as TransactionDriver, r as Driver } from "./types-BNSyrEFw.js";
2
+ import { r as QueryProfiler } from "./profiling-CRd3epfk.js";
3
+ import { t as PostgresDriver } from "./pool-UBdmZPmu.js";
4
+ import { SQL } from "bun";
5
+ //#region src/driver/bun.d.ts
6
+ type PostgresOptions = Omit<SQL.PostgresOrMySQLOptions, "adapter" | "bigint"> & {
7
+ readonly profiler?: QueryProfiler | undefined;
8
+ };
9
+ export declare const postgres: (connection: string | PostgresOptions) => PostgresDriver;
10
+ //#endregion
11
+ export { type BindableSchema, type Driver, type PostgresDriver, type PostgresOptions, SCHEMA_BIND, type SessionDriver, type TransactionDriver };
12
+ //# sourceMappingURL=bun.d.ts.map
package/dist/bun.js ADDED
@@ -0,0 +1,64 @@
1
+ import { t as SCHEMA_BIND } from "./binding-CD-0xNaB.js";
2
+ import { n as postgresParameters, t as createPostgresDriver } from "./pool-OKiwLiBZ.js";
3
+ import { SQL } from "bun";
4
+ //#region src/driver/bun.ts
5
+ /** Bun reports socket-level failures with ERR_POSTGRES_* codes; server errors carry SQLSTATE codes. */
6
+ const transportFailure = (error) => {
7
+ const code = error.code;
8
+ return typeof code === "string" && code.startsWith("ERR_");
9
+ };
10
+ const postgres = (connection) => {
11
+ const { profiler, ...options } = typeof connection === "string" ? { url: connection } : connection;
12
+ const client = new SQL({
13
+ ...options,
14
+ adapter: "postgres",
15
+ bigint: true
16
+ });
17
+ let cancellation;
18
+ const execute = async (connection, query) => {
19
+ const result = await connection.unsafe(query.sql, postgresParameters(query.parameters));
20
+ return {
21
+ rows: Array.from(result),
22
+ affectedRows: result.count ?? result.length
23
+ };
24
+ };
25
+ return createPostgresDriver({
26
+ execute: (query) => execute(client, query),
27
+ connect: async () => {
28
+ const reserved = await client.reserve();
29
+ let released = false;
30
+ return {
31
+ execute: (query) => execute(reserved, query),
32
+ release: (error) => {
33
+ if (released) return;
34
+ released = true;
35
+ if (!error || transportFailure(error)) {
36
+ reserved.release();
37
+ return;
38
+ }
39
+ reserved.unsafe("ROLLBACK").catch(() => {}).finally(() => reserved.release());
40
+ }
41
+ };
42
+ },
43
+ cancel: async (pid) => {
44
+ cancellation ??= new SQL({
45
+ ...options,
46
+ adapter: "postgres",
47
+ bigint: true,
48
+ max: 1
49
+ });
50
+ await cancellation.unsafe("SELECT pg_cancel_backend($1)", [pid]);
51
+ },
52
+ close: async () => {
53
+ try {
54
+ await client.close();
55
+ } finally {
56
+ await cancellation?.close();
57
+ }
58
+ }
59
+ }, profiler);
60
+ };
61
+ //#endregion
62
+ export { SCHEMA_BIND, postgres };
63
+
64
+ //# sourceMappingURL=bun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun.js","names":[],"sources":["../src/driver/bun.ts"],"sourcesContent":["import { SQL } from \"bun\";\nimport { createPostgresDriver, type PostgresDriver } from \"./pool\";\nimport { postgresParameters } from \"./parameters\";\nimport type { CompiledQuery, ExecutionResult } from \"../query/plan/types\";\nimport type { QueryProfiler } from \"../observability/profiling\";\n\nexport type PostgresOptions = Omit<\n SQL.PostgresOrMySQLOptions,\n \"adapter\" | \"bigint\"\n> & { readonly profiler?: QueryProfiler | undefined };\nexport type { PostgresDriver } from \"./pool\";\n\n/** Bun reports socket-level failures with ERR_POSTGRES_* codes; server errors carry SQLSTATE codes. */\nconst transportFailure = (error: Error): boolean => {\n const code: unknown = (error as { code?: unknown }).code;\n\n return typeof code === \"string\" && code.startsWith(\"ERR_\");\n};\n\nexport const postgres = (\n connection: string | PostgresOptions,\n): PostgresDriver => {\n const { profiler, ...options } =\n typeof connection === \"string\" ? { url: connection } : connection;\n const client = new SQL({ ...options, adapter: \"postgres\", bigint: true });\n let cancellation: SQL | undefined;\n\n const execute = async (\n connection: SQL,\n query: CompiledQuery,\n ): Promise<ExecutionResult> => {\n const result = await connection.unsafe<Record<string, unknown>[]>(\n query.sql,\n postgresParameters(query.parameters),\n );\n\n return {\n rows: Array.from(result),\n affectedRows: (result as { count?: number }).count ?? result.length,\n };\n };\n\n return createPostgresDriver(\n {\n execute: (query) => execute(client, query),\n connect: async () => {\n const reserved = await client.reserve();\n let released = false;\n\n return {\n execute: (query) => execute(reserved, query),\n release: (error) => {\n if (released) {\n return;\n }\n\n released = true;\n\n if (!error || transportFailure(error)) {\n reserved.release();\n\n return;\n }\n\n void reserved\n .unsafe(\"ROLLBACK\")\n .catch(() => {})\n .finally(() => reserved.release());\n },\n };\n },\n cancel: async (pid) => {\n cancellation ??= new SQL({\n ...options,\n adapter: \"postgres\",\n bigint: true,\n max: 1,\n });\n\n await cancellation.unsafe(\"SELECT pg_cancel_backend($1)\", [pid]);\n },\n close: async () => {\n try {\n await client.close();\n } finally {\n await cancellation?.close();\n }\n },\n },\n profiler,\n );\n};\n"],"mappings":";;;;;AAaA,MAAM,oBAAoB,UAA0B;CAClD,MAAM,OAAiB,MAA6B;CAEpD,OAAO,OAAO,SAAS,YAAY,KAAK,WAAW,MAAM;AAC3D;AAEA,MAAa,YACX,eACmB;CACnB,MAAM,EAAE,UAAU,GAAG,YACnB,OAAO,eAAe,WAAW,EAAE,KAAK,WAAW,IAAI;CACzD,MAAM,SAAS,IAAI,IAAI;EAAE,GAAG;EAAS,SAAS;EAAY,QAAQ;CAAK,CAAC;CACxE,IAAI;CAEJ,MAAM,UAAU,OACd,YACA,UAC6B;EAC7B,MAAM,SAAS,MAAM,WAAW,OAC9B,MAAM,KACN,mBAAmB,MAAM,UAAU,CACrC;EAEA,OAAO;GACL,MAAM,MAAM,KAAK,MAAM;GACvB,cAAe,OAA8B,SAAS,OAAO;EAC/D;CACF;CAEA,OAAO,qBACL;EACE,UAAU,UAAU,QAAQ,QAAQ,KAAK;EACzC,SAAS,YAAY;GACnB,MAAM,WAAW,MAAM,OAAO,QAAQ;GACtC,IAAI,WAAW;GAEf,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