@b9g/zen 0.1.1 → 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.
- package/CHANGELOG.md +39 -0
- package/README.md +240 -125
- package/package.json +12 -3
- package/{chunk-W7JTNEM4.js → src/_chunks/chunk-2C6KOX4F.js} +1 -1
- package/{chunk-CHF7L5PC.js → src/_chunks/chunk-2R6FDKLS.js} +1 -1
- package/{chunk-XHXMCOSW.js → src/_chunks/chunk-DKLSJISE.js} +40 -0
- package/{ddl-2A2UFUR3.js → src/_chunks/ddl-32B7E53E.js} +2 -2
- package/src/bun.js +4 -4
- package/src/impl/builtins.d.ts +52 -0
- package/src/impl/database.d.ts +495 -0
- package/src/impl/ddl.d.ts +34 -0
- package/src/impl/errors.d.ts +195 -0
- package/src/impl/query.d.ts +249 -0
- package/src/impl/sql.d.ts +47 -0
- package/src/impl/table.d.ts +961 -0
- package/src/impl/template.d.ts +75 -0
- package/src/mysql.js +3 -3
- package/src/postgres.js +3 -3
- package/src/sqlite.js +3 -3
- package/src/zen.d.ts +6 -7
- package/src/zen.js +5 -2
|
@@ -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 "
|
|
5
|
+
} from "./_chunks/chunk-2C6KOX4F.js";
|
|
6
6
|
import {
|
|
7
7
|
generateColumnDDL,
|
|
8
8
|
generateDDL,
|
|
9
9
|
generateViewDDL
|
|
10
|
-
} from "
|
|
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 "
|
|
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 "
|
|
5
|
+
} from "./_chunks/chunk-2C6KOX4F.js";
|
|
6
6
|
import {
|
|
7
7
|
generateColumnDDL,
|
|
8
8
|
generateDDL,
|
|
9
9
|
generateViewDDL
|
|
10
|
-
} from "
|
|
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 "
|
|
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 "
|
|
5
|
+
} from "./_chunks/chunk-2C6KOX4F.js";
|
|
6
6
|
import {
|
|
7
7
|
generateColumnDDL,
|
|
8
8
|
generateDDL,
|
|
9
9
|
generateViewDDL
|
|
10
|
-
} from "
|
|
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 "
|
|
17
|
+
} from "./_chunks/chunk-DKLSJISE.js";
|
|
18
18
|
|
|
19
19
|
// src/sqlite.ts
|
|
20
20
|
import {
|
package/src/zen.d.ts
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { z as zod } from "zod";
|
|
7
7
|
export { zod as z };
|
|
8
|
-
export { table, view, type Table, type View, type Queryable, type TableOptions, type Row, type Insert, type Update, type FieldMeta, type FieldType, type Relation,
|
|
9
|
-
export { Database, Transaction, DatabaseUpgradeEvent, type Driver, } from "./impl/database.js";
|
|
10
|
-
export {
|
|
11
|
-
export { ident, isSQLIdentifier, } from "./impl/template.js";
|
|
12
|
-
export { type
|
|
13
|
-
export { type
|
|
14
|
-
export { DatabaseError, ValidationError, TableDefinitionError, MigrationError, MigrationLockError, QueryError, NotFoundError, AlreadyExistsError, ConstraintViolationError, ConnectionError, TransactionError, EnsureError, SchemaDriftError, ConstraintPreflightError, isDatabaseError, hasErrorCode, type DatabaseErrorCode, type EnsureOperation, } from "./impl/errors.js";
|
|
8
|
+
export { table, view, extendZod, isTable, isView, getViewMeta, type Table, type PartialTable, type DerivedTable, type View, type Queryable, type TableOptions, type Row, type Insert, type Update, type SetValues, type FieldMeta, type FieldType, type FieldDBMeta, type Relation, type ReferenceInfo, type CompoundReference, type ViewMeta, } from "./impl/table.js";
|
|
9
|
+
export { Database, Transaction, DatabaseUpgradeEvent, type Driver, type TaggedQuery, type EnsureResult, } from "./impl/database.js";
|
|
10
|
+
export { NOW, TODAY, CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIME, isSQLBuiltin, } from "./impl/database.js";
|
|
11
|
+
export { ident, isSQLIdentifier, type SQLTemplate, isSQLTemplate, } from "./impl/template.js";
|
|
12
|
+
export { type SQLDialect } from "./impl/sql.js";
|
|
13
|
+
export { DatabaseError, isDatabaseError, hasErrorCode, ValidationError, TableDefinitionError, QueryError, NotFoundError, AlreadyExistsError, ConstraintViolationError, MigrationError, MigrationLockError, EnsureError, SchemaDriftError, ConstraintPreflightError, ConnectionError, TransactionError, type DatabaseErrorCode, type EnsureOperation, } from "./impl/errors.js";
|
package/src/zen.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="./zen.d.ts" />
|
|
2
|
-
import "
|
|
2
|
+
import "./_chunks/chunk-2C6KOX4F.js";
|
|
3
3
|
import {
|
|
4
4
|
AlreadyExistsError,
|
|
5
5
|
CURRENT_DATE,
|
|
@@ -32,13 +32,14 @@ import {
|
|
|
32
32
|
isSQLBuiltin,
|
|
33
33
|
isSQLIdentifier,
|
|
34
34
|
isSQLTemplate,
|
|
35
|
+
isTable,
|
|
35
36
|
isView,
|
|
36
37
|
makeTemplate,
|
|
37
38
|
resolveSQLBuiltin,
|
|
38
39
|
table,
|
|
39
40
|
validateWithStandardSchema,
|
|
40
41
|
view
|
|
41
|
-
} from "
|
|
42
|
+
} from "./_chunks/chunk-DKLSJISE.js";
|
|
42
43
|
|
|
43
44
|
// src/zen.ts
|
|
44
45
|
import { z as zod } from "zod";
|
|
@@ -2270,6 +2271,7 @@ export {
|
|
|
2270
2271
|
Transaction,
|
|
2271
2272
|
TransactionError,
|
|
2272
2273
|
ValidationError,
|
|
2274
|
+
extendZod,
|
|
2273
2275
|
getViewMeta,
|
|
2274
2276
|
hasErrorCode,
|
|
2275
2277
|
ident,
|
|
@@ -2277,6 +2279,7 @@ export {
|
|
|
2277
2279
|
isSQLBuiltin,
|
|
2278
2280
|
isSQLIdentifier,
|
|
2279
2281
|
isSQLTemplate,
|
|
2282
|
+
isTable,
|
|
2280
2283
|
isView,
|
|
2281
2284
|
table,
|
|
2282
2285
|
view,
|