@b9g/zen 0.1.2 → 0.1.3

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,75 @@
1
+ /**
2
+ * Template utilities for building SQL templates.
3
+ *
4
+ * This module provides the core primitives for the monadic template approach:
5
+ * - Templates are branded tuples: [strings, values]
6
+ * - Templates compose by merging (no string parsing)
7
+ * - Identifiers use ident() markers for deferred quoting
8
+ * - Rendering happens in drivers only
9
+ */
10
+ declare const SQL_TEMPLATE: unique symbol;
11
+ /**
12
+ * A SQL template as a branded tuple: [strings, ...values]
13
+ *
14
+ * Maintains invariant: strings.length === values.length + 1
15
+ *
16
+ * Access: template[0] for strings, template.slice(1) for values
17
+ * The strings array preserves .raw for TemplateStringsArray compatibility.
18
+ *
19
+ * This structure matches template tag function parameters, allowing templates
20
+ * to be directly applied to functions that accept (strings, ...values).
21
+ *
22
+ * Branded with symbol for injection protection - prevents user-crafted
23
+ * objects from being interpolated as raw SQL.
24
+ */
25
+ export type SQLTemplate = readonly [TemplateStringsArray, ...unknown[]] & {
26
+ readonly [SQL_TEMPLATE]: true;
27
+ };
28
+ /**
29
+ * Create a SQL template from strings and values.
30
+ *
31
+ * @param strings - TemplateStringsArray (preserves .raw)
32
+ * @param values - Template values (identifiers, parameters, nested templates)
33
+ */
34
+ export declare function createTemplate(strings: TemplateStringsArray, values?: readonly unknown[]): SQLTemplate;
35
+ /**
36
+ * Check if a value is a SQL template.
37
+ */
38
+ export declare function isSQLTemplate(value: unknown): value is SQLTemplate;
39
+ declare const SQL_IDENT: unique symbol;
40
+ /**
41
+ * SQL identifier (table name, column name) to be quoted by drivers.
42
+ *
43
+ * Identifiers flow through template composition unchanged.
44
+ * Quoting happens in drivers based on dialect:
45
+ * - MySQL: backticks (`name`)
46
+ * - PostgreSQL/SQLite: double quotes ("name")
47
+ */
48
+ export interface SQLIdentifier {
49
+ readonly [SQL_IDENT]: true;
50
+ readonly name: string;
51
+ }
52
+ /**
53
+ * Create an SQL identifier marker.
54
+ * Drivers will quote this appropriately for their dialect.
55
+ */
56
+ export declare function ident(name: string): SQLIdentifier;
57
+ /**
58
+ * Check if a value is an SQL identifier marker.
59
+ */
60
+ export declare function isSQLIdentifier(value: unknown): value is SQLIdentifier;
61
+ /**
62
+ * Build a TemplateStringsArray from string parts.
63
+ * Used to construct templates programmatically while preserving the .raw property.
64
+ */
65
+ export declare function makeTemplate(parts: string[]): TemplateStringsArray;
66
+ /**
67
+ * Merge a template into an accumulator.
68
+ * Mutates the strings and values arrays in place.
69
+ *
70
+ * @param strings - Accumulator strings array (mutated)
71
+ * @param values - Accumulator values array (mutated)
72
+ * @param template - Template to merge (tuple format)
73
+ */
74
+ export declare function mergeTemplate(strings: string[], values: unknown[], template: SQLTemplate): void;
75
+ export {};
package/src/mysql.js CHANGED
@@ -2,19 +2,19 @@
2
2
  import {
3
3
  quoteIdent,
4
4
  renderDDL
5
- } from "../chunk-NBXBBEMA.js";
5
+ } from "./_chunks/chunk-2C6KOX4F.js";
6
6
  import {
7
7
  generateColumnDDL,
8
8
  generateDDL,
9
9
  generateViewDDL
10
- } from "../chunk-ARUUB3H4.js";
10
+ } from "./_chunks/chunk-2R6FDKLS.js";
11
11
  import {
12
12
  ConstraintPreflightError,
13
13
  EnsureError,
14
14
  SchemaDriftError,
15
15
  getTableMeta,
16
16
  resolveSQLBuiltin
17
- } from "../chunk-BEX6VPES.js";
17
+ } from "./_chunks/chunk-DKLSJISE.js";
18
18
 
19
19
  // src/mysql.ts
20
20
  import {
package/src/postgres.js CHANGED
@@ -2,19 +2,19 @@
2
2
  import {
3
3
  quoteIdent,
4
4
  renderDDL
5
- } from "../chunk-NBXBBEMA.js";
5
+ } from "./_chunks/chunk-2C6KOX4F.js";
6
6
  import {
7
7
  generateColumnDDL,
8
8
  generateDDL,
9
9
  generateViewDDL
10
- } from "../chunk-ARUUB3H4.js";
10
+ } from "./_chunks/chunk-2R6FDKLS.js";
11
11
  import {
12
12
  ConstraintPreflightError,
13
13
  EnsureError,
14
14
  SchemaDriftError,
15
15
  getTableMeta,
16
16
  resolveSQLBuiltin
17
- } from "../chunk-BEX6VPES.js";
17
+ } from "./_chunks/chunk-DKLSJISE.js";
18
18
 
19
19
  // src/postgres.ts
20
20
  import {
package/src/sqlite.js CHANGED
@@ -2,19 +2,19 @@
2
2
  import {
3
3
  quoteIdent,
4
4
  renderDDL
5
- } from "../chunk-NBXBBEMA.js";
5
+ } from "./_chunks/chunk-2C6KOX4F.js";
6
6
  import {
7
7
  generateColumnDDL,
8
8
  generateDDL,
9
9
  generateViewDDL
10
- } from "../chunk-ARUUB3H4.js";
10
+ } from "./_chunks/chunk-2R6FDKLS.js";
11
11
  import {
12
12
  ConstraintPreflightError,
13
13
  EnsureError,
14
14
  SchemaDriftError,
15
15
  getTableMeta,
16
16
  resolveSQLBuiltin
17
- } from "../chunk-BEX6VPES.js";
17
+ } from "./_chunks/chunk-DKLSJISE.js";
18
18
 
19
19
  // src/sqlite.ts
20
20
  import {
package/src/zen.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="./zen.d.ts" />
2
- import "../chunk-NBXBBEMA.js";
2
+ import "./_chunks/chunk-2C6KOX4F.js";
3
3
  import {
4
4
  AlreadyExistsError,
5
5
  CURRENT_DATE,
@@ -39,7 +39,7 @@ import {
39
39
  table,
40
40
  validateWithStandardSchema,
41
41
  view
42
- } from "../chunk-BEX6VPES.js";
42
+ } from "./_chunks/chunk-DKLSJISE.js";
43
43
 
44
44
  // src/zen.ts
45
45
  import { z as zod } from "zod";