qubu 0.4.0 → 0.4.2

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.
Files changed (103) hide show
  1. package/dist/{canonical-BbnqavJm.mjs → canonical-BXUguqfo.mjs} +23 -23
  2. package/dist/codegen.d.mts +25 -33
  3. package/dist/codegen.mjs +38 -45
  4. package/dist/column-hqKr7-1I.mjs +620 -0
  5. package/dist/{complete-D5Djh-zo.mjs → complete-WYyVozgK.mjs} +50 -50
  6. package/dist/{complete-types-BavBtv8J.d.mts → complete-types-IjEn5VPN.d.mts} +56 -56
  7. package/dist/core.d.mts +2 -2
  8. package/dist/core.mjs +4 -4
  9. package/dist/ddl.d.mts +12 -12
  10. package/dist/ddl.mjs +13 -14
  11. package/dist/{dialect-b2-Z6uBF.mjs → dialect-wUKrnPMB.mjs} +2 -2
  12. package/dist/diff.d.mts +1 -1
  13. package/dist/diff.mjs +6 -7
  14. package/dist/{index-DH0qV6aS.d.mts → index-1DpA3mUh.d.mts} +20 -20
  15. package/dist/{index-D3ZOwPT-.d.mts → index-CPvfEheG.d.mts} +13 -15
  16. package/dist/index.d.mts +1 -1
  17. package/dist/index.mjs +94 -95
  18. package/dist/introspection.d.mts +8 -8
  19. package/dist/introspection.mjs +29 -30
  20. package/dist/{json-CUZlv4HT.mjs → json-Db7XRD91.mjs} +2 -2
  21. package/dist/migration.d.mts +20 -21
  22. package/dist/migration.mjs +5 -6
  23. package/dist/{mysql-CKEKGnj4.mjs → mysql-B_cYzzX2.mjs} +237 -7
  24. package/dist/mysql.d.mts +2 -2
  25. package/dist/mysql.mjs +3 -3
  26. package/dist/{on-conflict-4MOBl51J.mjs → on-conflict-hfPW0KmQ.mjs} +3 -4
  27. package/dist/postgres.d.mts +5 -5
  28. package/dist/postgres.mjs +6 -6
  29. package/dist/{registry-CXV8u7Pt.mjs → registry-BRMLYwDp.mjs} +26 -29
  30. package/dist/{relational-DuQ9IHSb.mjs → relational-BZ3WDPzC.mjs} +2 -2
  31. package/dist/schema.d.mts +1 -1
  32. package/dist/schema.mjs +5 -6
  33. package/dist/{snapshot-DJpfmxhQ.mjs → snapshot-C-W65HEd.mjs} +5 -5
  34. package/dist/snapshot.d.mts +3 -3
  35. package/dist/snapshot.mjs +5 -7
  36. package/dist/{source-DGO3DRgg.mjs → source-BcS2AsIg.mjs} +6 -8
  37. package/dist/{serialize-CFtYYAdk.mjs → sqlite-Cg0nwYEH.mjs} +326 -12
  38. package/dist/sqlite.d.mts +1 -1
  39. package/dist/sqlite.mjs +2 -2
  40. package/dist/{standard-BTVYKh_F.mjs → standard-DfcZEVOj.mjs} +1 -1
  41. package/dist/{table-D6rcs8SB.mjs → table-Bp5irMSj.mjs} +2 -3
  42. package/dist/{types-Deo_q43Y.d.mts → types-BK1COGZe.d.mts} +1113 -1128
  43. package/dist/{types-g-vVvj1B.mjs → types-JM3FcAnX.mjs} +7 -8
  44. package/dist/{types-CSNJTYaM.d.mts → types-JSZHpUEj.d.mts} +83 -84
  45. package/dist/{value-b6OFZXVS.mjs → value-Bi71Agyf.mjs} +1 -1
  46. package/dist/vite/ambient.d.ts +309 -340
  47. package/dist/vite.d.mts +5 -6
  48. package/dist/vite.mjs +3 -4
  49. package/docs/dialects-and-execution.md +45 -55
  50. package/docs/getting-started.md +4 -4
  51. package/docs/guides/better-auth.md +57 -0
  52. package/docs/guides/compose-queries.md +24 -67
  53. package/docs/guides/drizzle.md +23 -23
  54. package/docs/guides/extensions/dialects.md +4 -4
  55. package/docs/guides/extensions/sources-and-clauses.md +15 -15
  56. package/docs/guides/extensions/typed-expressions.md +13 -17
  57. package/docs/guides/extensions/unsafe-syntax.md +3 -3
  58. package/docs/guides/json.md +7 -7
  59. package/docs/guides/mutations.md +14 -21
  60. package/docs/guides/select/conditions.md +6 -8
  61. package/docs/guides/select/grouping-and-windows.md +4 -15
  62. package/docs/guides/select/ordering-and-pagination.md +6 -19
  63. package/docs/guides/select/overview.md +12 -26
  64. package/docs/guides/sql-templates.md +20 -24
  65. package/docs/guides/vite-plugin.md +9 -13
  66. package/docs/index.md +5 -7
  67. package/docs/query-model/fragments.md +4 -15
  68. package/docs/query-model/result-shapes.md +11 -14
  69. package/docs/query-model/source-scope.md +31 -49
  70. package/docs/reference/mysql-snapshot.md +2 -5
  71. package/docs/reference/postgres-snapshot.md +3 -3
  72. package/docs/reference/sqlite-snapshot.md +2 -5
  73. package/docs/reference/supported-surface.md +26 -26
  74. package/docs/schema/catalog-model.md +2 -5
  75. package/docs/schema/code-generation.md +18 -18
  76. package/docs/schema/columns-and-writes.md +17 -25
  77. package/docs/schema/constraints-and-indexes.md +36 -52
  78. package/docs/schema/ddl-emission.md +6 -6
  79. package/docs/schema/diff.md +5 -5
  80. package/docs/schema/introspection.md +7 -7
  81. package/docs/schema/migration-plans.md +9 -9
  82. package/docs/schema/snapshots.md +3 -3
  83. package/docs/schema/storage-and-schema-sql.md +11 -11
  84. package/docs/schema/tables-and-names.md +11 -14
  85. package/docs/sql-semantic-types.md +10 -10
  86. package/docs/troubleshooting.md +10 -10
  87. package/package.json +21 -33
  88. package/skills/qubu/agents/openai.yaml +3 -3
  89. package/dist/column-D-8OqGuV.mjs +0 -328
  90. package/dist/column-LV7oGQde.mjs +0 -296
  91. package/dist/drizzle-mysql.d.mts +0 -24
  92. package/dist/drizzle-mysql.mjs +0 -72
  93. package/dist/drizzle-postgres.d.mts +0 -24
  94. package/dist/drizzle-postgres.mjs +0 -73
  95. package/dist/drizzle-sqlite.d.mts +0 -57
  96. package/dist/drizzle-sqlite.mjs +0 -108
  97. package/dist/drizzle.d.mts +0 -13
  98. package/dist/drizzle.mjs +0 -2
  99. package/dist/errors-BGCoLe_r.mjs +0 -14
  100. package/dist/postgres-BK2APkKP.mjs +0 -236
  101. package/dist/runtime-Cn_Xgzta.mjs +0 -193
  102. package/dist/sqlite-CrsK0Fza.mjs +0 -320
  103. package/dist/types-DZsueVoI.d.mts +0 -45
@@ -1,72 +0,0 @@
1
- import { t as createMysqlSchemaSnapshot } from "./mysql-CKEKGnj4.mjs";
2
- import { i as stringExtension, n as extensionData, t as convertDrizzleSchema } from "./runtime-Cn_Xgzta.mjs";
3
- import { bigint, boolean, char, check, customType, date, datetime, decimal, foreignKey, index, int, json, mysqlSchema, mysqlTable, primaryKey, text, unique, uniqueIndex } from "drizzle-orm/mysql-core";
4
- //#region src/drizzle/mysql.ts
5
- const mysqlAdapter = {
6
- dialect: "mysql",
7
- createSnapshot: createMysqlSchemaSnapshot,
8
- createTableFactory(namespace) {
9
- return namespace === void 0 ? mysqlTable : mysqlSchema(namespace).table;
10
- },
11
- createStorageBuilder: createMysqlStorageBuilder,
12
- applyIdentity(builder, definition) {
13
- const extension = definition.identity?.dialect;
14
- return extension?.dialect === "mysql" && "autoIncrement" in extension && extension.autoIncrement === true && builder.autoincrement ? builder.autoincrement() : builder;
15
- },
16
- createPrimaryKey(name, columns) {
17
- return primaryKey({
18
- name,
19
- columns
20
- });
21
- },
22
- createUniqueConstraint(name, columns) {
23
- return unique(name).on(...columns);
24
- },
25
- createCheck: check,
26
- createForeignKey(name, columns, foreignColumns) {
27
- return foreignKey({
28
- name,
29
- columns,
30
- foreignColumns
31
- });
32
- },
33
- createIndex(indexDefinition, terms) {
34
- const data = extensionData(indexDefinition.dialect);
35
- let builder = (indexDefinition.unique ? uniqueIndex(indexDefinition.physicalName) : index(indexDefinition.physicalName)).on(...terms);
36
- const using = stringExtension(data, "using");
37
- const algorithm = stringExtension(data, "algorithm");
38
- const lock = stringExtension(data, "lock");
39
- if (using) builder = builder.using(using);
40
- if (algorithm) builder = builder.algorithm(algorithm);
41
- if (lock) builder = builder.lock(lock);
42
- return builder;
43
- }
44
- };
45
- /**
46
- * Convert a live Qubu schema registry into MySQL Drizzle table objects.
47
- *
48
- * @throws A snapshot validation error for invalid MySQL metadata, or a
49
- * DrizzleSchemaConversionError when Drizzle cannot represent required metadata.
50
- */
51
- function toMysqlDrizzleSchema(schema) {
52
- return convertDrizzleSchema(schema, mysqlAdapter);
53
- }
54
- function createMysqlStorageBuilder(type, name, declaration) {
55
- return (() => {
56
- switch (type) {
57
- case "integer": return int(name);
58
- case "numeric": return decimal(name, { mode: "number" });
59
- case "text": return text(name);
60
- case "boolean": return boolean(name);
61
- case "date": return date(name, { mode: "date" });
62
- case "timestamp": return datetime(name, { mode: "date" });
63
- case "uuid": return char(name, { length: 36 });
64
- case "json": return json(name);
65
- case "bigint": return bigint(name, { mode: "bigint" });
66
- case "binary": return customType({ dataType: () => declaration })(name);
67
- default: return customType({ dataType: () => declaration })(name);
68
- }
69
- })();
70
- }
71
- //#endregion
72
- export { toMysqlDrizzleSchema };
@@ -1,24 +0,0 @@
1
- import { Lt as AnyTable, ei as Schema, oi as SchemaTableRecord } from "./types-Deo_q43Y.mjs";
2
- import { r as DrizzleSchemaValidation, t as DrizzleColumnConfig } from "./types-DZsueVoI.mjs";
3
- import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core";
4
- //#region src/drizzle/postgres.d.ts
5
- type PostgresDrizzleColumn<TTableName extends string, TDefinition> = PgColumn<'custom', DrizzleColumnConfig<TTableName, TDefinition>>;
6
- type PostgresDrizzleColumns<TTable extends AnyTable> = { [TKey in keyof TTable['definitions']]: PostgresDrizzleColumn<TTable['tableName'], TTable['definitions'][TKey]>; };
7
- /** The Drizzle PostgreSQL table produced for one Qubu table. */
8
- type PostgresDrizzleTable<TTable extends AnyTable> = PgTableWithColumns<{
9
- name: TTable['tableName'];
10
- schema: string | undefined;
11
- columns: PostgresDrizzleColumns<TTable>;
12
- dialect: 'pg';
13
- }>;
14
- /** A PostgreSQL Drizzle table record retaining Qubu's logical table keys. */
15
- type PostgresDrizzleSchema<TSchema extends Schema<any>> = { readonly [TKey in keyof TSchema['tables']]: PostgresDrizzleTable<TSchema['tables'][TKey]>; };
16
- /**
17
- * Convert a live Qubu schema registry into PostgreSQL Drizzle table objects.
18
- *
19
- * @throws A snapshot validation error for invalid PostgreSQL metadata, or a
20
- * DrizzleSchemaConversionError when Drizzle cannot represent required metadata.
21
- */
22
- declare function toPostgresDrizzleSchema<const TTables extends SchemaTableRecord>(schema: Schema<TTables> & DrizzleSchemaValidation<TTables, 'postgresql'>): PostgresDrizzleSchema<Schema<TTables>>;
23
- //#endregion
24
- export { PostgresDrizzleSchema, PostgresDrizzleTable, toPostgresDrizzleSchema };
@@ -1,73 +0,0 @@
1
- import { t as createPostgresSchemaSnapshot } from "./postgres-BK2APkKP.mjs";
2
- import { i as stringExtension, n as extensionData, r as recordExtension, t as convertDrizzleSchema } from "./runtime-Cn_Xgzta.mjs";
3
- import { bigint, boolean, check, customType, date, foreignKey, index, integer, jsonb, numeric, pgSchema, pgTable, primaryKey, text, timestamp, unique, uniqueIndex, uuid } from "drizzle-orm/pg-core";
4
- //#region src/drizzle/postgres.ts
5
- const postgresAdapter = {
6
- dialect: "postgresql",
7
- createSnapshot: createPostgresSchemaSnapshot,
8
- createTableFactory(namespace) {
9
- return namespace === void 0 ? pgTable : pgSchema(namespace).table;
10
- },
11
- createStorageBuilder: createPostgresStorageBuilder,
12
- applyIdentity(builder, _definition, column) {
13
- const method = column.identity?.generation === "always" ? builder.generatedAlwaysAsIdentity : builder.generatedByDefaultAsIdentity;
14
- return method === void 0 ? builder : method.call(builder);
15
- },
16
- createPrimaryKey(name, columns) {
17
- return primaryKey({
18
- name,
19
- columns
20
- });
21
- },
22
- createUniqueConstraint(name, columns, nullsNotDistinct) {
23
- const builder = unique(name).on(...columns);
24
- return nullsNotDistinct ? builder.nullsNotDistinct() : builder;
25
- },
26
- createCheck: check,
27
- createForeignKey(name, columns, foreignColumns) {
28
- return foreignKey({
29
- name,
30
- columns,
31
- foreignColumns
32
- });
33
- },
34
- createIndex(indexDefinition, terms, predicate) {
35
- const data = extensionData(indexDefinition.dialect);
36
- const start = indexDefinition.unique ? uniqueIndex(indexDefinition.physicalName) : index(indexDefinition.physicalName);
37
- const method = stringExtension(data, "method");
38
- let builder = method ? start.using(method, ...terms) : start.on(...terms);
39
- if (data.concurrently === true) builder = builder.concurrently();
40
- const storageParameters = recordExtension(data, "storageParameters");
41
- if (storageParameters) builder = builder.with(storageParameters);
42
- if (predicate) builder = builder.where(predicate);
43
- return builder;
44
- }
45
- };
46
- /**
47
- * Convert a live Qubu schema registry into PostgreSQL Drizzle table objects.
48
- *
49
- * @throws A snapshot validation error for invalid PostgreSQL metadata, or a
50
- * DrizzleSchemaConversionError when Drizzle cannot represent required metadata.
51
- */
52
- function toPostgresDrizzleSchema(schema) {
53
- return convertDrizzleSchema(schema, postgresAdapter);
54
- }
55
- function createPostgresStorageBuilder(type, name, declaration) {
56
- return (() => {
57
- switch (type) {
58
- case "integer": return integer(name);
59
- case "numeric": return numeric(name, { mode: "number" });
60
- case "text": return text(name);
61
- case "boolean": return boolean(name);
62
- case "date": return date(name, { mode: "date" });
63
- case "timestamp": return timestamp(name, { mode: "date" });
64
- case "uuid": return uuid(name);
65
- case "json": return jsonb(name);
66
- case "bigint": return bigint(name, { mode: "bigint" });
67
- case "binary": return customType({ dataType: () => declaration })(name);
68
- default: return customType({ dataType: () => declaration })(name);
69
- }
70
- })();
71
- }
72
- //#endregion
73
- export { toPostgresDrizzleSchema };
@@ -1,57 +0,0 @@
1
- import { Lt as AnyTable, Uu as SqlTimestamp, ei as Schema, kc as ExternalDefaultDescriptor, oi as SchemaTableRecord, qs as NativeColumnStorage, ws as ColumnDefinition } from "./types-Deo_q43Y.mjs";
2
- import { r as DrizzleSchemaValidation, t as DrizzleColumnConfig } from "./types-DZsueVoI.mjs";
3
- import { SQLiteColumn, SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
4
- //#region src/drizzle/sqlite.d.ts
5
- type SqliteDrizzleColumn<TTableName extends string, TDefinition> = SQLiteColumn<DrizzleColumnConfig<TTableName, TDefinition>>;
6
- type SqliteDrizzleColumns<TTable extends AnyTable> = { [TKey in keyof TTable['definitions']]: SqliteDrizzleColumn<TTable['tableName'], TTable['definitions'][TKey]>; };
7
- /** Integer encoding used by Drizzle's SQLite timestamp column builder. */
8
- type SqliteTimestampMode = 'timestamp' | 'timestamp_ms';
9
- /** Runtime options for a Drizzle-compatible SQLite integer timestamp. */
10
- interface SqliteTimestampOptions {
11
- /** Store Unix seconds by default, or milliseconds with `timestamp_ms`. */
12
- readonly mode?: SqliteTimestampMode;
13
- readonly nullable?: boolean;
14
- readonly sqlName?: string;
15
- /** Supply an application value when a Drizzle insert omits this column. */
16
- readonly defaultFn?: () => Date;
17
- }
18
- type SqliteTimestampNullable<TOptions extends SqliteTimestampOptions> = TOptions extends {
19
- readonly nullable: true;
20
- } ? true : false;
21
- type SqliteTimestampHasDefault<TOptions extends SqliteTimestampOptions> = TOptions extends {
22
- readonly defaultFn: () => Date;
23
- } ? true : false;
24
- /** Qubu definition produced by {@link sqliteTimestamp}. */
25
- type SqliteTimestampColumn<TOptions extends SqliteTimestampOptions = {}> = ColumnDefinition<{
26
- readonly output: Date;
27
- readonly nullable: SqliteTimestampNullable<TOptions>;
28
- readonly hasDefault: SqliteTimestampHasDefault<TOptions>;
29
- readonly sqlType: SqlTimestamp;
30
- readonly storage: NativeColumnStorage<'sqlite', 'INTEGER'>;
31
- readonly default: SqliteTimestampHasDefault<TOptions> extends true ? ExternalDefaultDescriptor : undefined;
32
- }>;
33
- /**
34
- * Declare a SQLite `INTEGER` timestamp that retains Drizzle's Date codec.
35
- *
36
- * @remarks `defaultFn` is runtime-only. Snapshots and emitted DDL retain the
37
- * native `INTEGER` storage but do not serialize the callback.
38
- */
39
- declare function sqliteTimestamp<const TOptions extends SqliteTimestampOptions = {}>(options?: TOptions): SqliteTimestampColumn<TOptions>;
40
- /** The Drizzle SQLite table produced for one Qubu table. */
41
- type SqliteDrizzleTable<TTable extends AnyTable> = SQLiteTableWithColumns<{
42
- name: TTable['tableName'];
43
- schema: undefined;
44
- columns: SqliteDrizzleColumns<TTable>;
45
- dialect: 'sqlite';
46
- }>;
47
- /** A SQLite Drizzle table record retaining Qubu's logical table keys. */
48
- type SqliteDrizzleSchema<TSchema extends Schema<any>> = { readonly [TKey in keyof TSchema['tables']]: SqliteDrizzleTable<TSchema['tables'][TKey]>; };
49
- /**
50
- * Convert a live Qubu schema registry into SQLite Drizzle table objects.
51
- *
52
- * @throws A snapshot validation error for invalid SQLite metadata, or a
53
- * DrizzleSchemaConversionError when Drizzle cannot represent required metadata.
54
- */
55
- declare function toSqliteDrizzleSchema<const TTables extends SchemaTableRecord>(schema: Schema<TTables> & DrizzleSchemaValidation<TTables, 'sqlite'>): SqliteDrizzleSchema<Schema<TTables>>;
56
- //#endregion
57
- export { SqliteDrizzleSchema, SqliteDrizzleTable, SqliteTimestampColumn, SqliteTimestampMode, SqliteTimestampOptions, sqliteTimestamp, toSqliteDrizzleSchema };
@@ -1,108 +0,0 @@
1
- import { l as nativeColumn } from "./column-LV7oGQde.mjs";
2
- import { t as createSqliteSchemaSnapshot } from "./sqlite-CrsK0Fza.mjs";
3
- import { t as convertDrizzleSchema } from "./runtime-Cn_Xgzta.mjs";
4
- import { blob, check, customType, foreignKey, index, integer, primaryKey, sqliteTable, text, unique, uniqueIndex } from "drizzle-orm/sqlite-core";
5
- //#region src/drizzle/sqlite.ts
6
- const sqliteTimestampRuntime = /* @__PURE__ */ new WeakMap();
7
- /**
8
- * Declare a SQLite `INTEGER` timestamp that retains Drizzle's Date codec.
9
- *
10
- * @remarks `defaultFn` is runtime-only. Snapshots and emitted DDL retain the
11
- * native `INTEGER` storage but do not serialize the callback.
12
- */
13
- function sqliteTimestamp(options) {
14
- const definition = nativeColumn("sqlite", "INTEGER", {
15
- nullable: options?.nullable === true,
16
- hasDefault: options?.defaultFn !== void 0,
17
- sqlName: options?.sqlName
18
- }).$type();
19
- sqliteTimestampRuntime.set(definition, Object.freeze({
20
- mode: options?.mode ?? "timestamp",
21
- ...options?.defaultFn === void 0 ? {} : { defaultFn: options.defaultFn }
22
- }));
23
- return definition;
24
- }
25
- const sqliteAdapter = {
26
- dialect: "sqlite",
27
- createSnapshot: createSqliteSchemaSnapshot,
28
- createTableFactory() {
29
- return sqliteTable;
30
- },
31
- createStorageBuilder: createSqliteStorageBuilder,
32
- applyIdentity(builder, definition, column, table) {
33
- const extension = definition.identity?.dialect;
34
- const autoIncrement = extension?.dialect === "sqlite" && "autoIncrement" in extension && extension.autoIncrement === true;
35
- const isSingleColumnPrimaryKey = table.constraints.some((constraint) => constraint.kind === "primary-key" && constraint.columns.length === 1 && constraint.columns[0] === column.id);
36
- return autoIncrement && isSingleColumnPrimaryKey && builder.primaryKey ? builder.primaryKey({ autoIncrement: true }) : builder;
37
- },
38
- createPrimaryKey(name, columns) {
39
- return primaryKey({
40
- name,
41
- columns
42
- });
43
- },
44
- createUniqueConstraint(name, columns) {
45
- return unique(name).on(...columns);
46
- },
47
- createCheck: check,
48
- createForeignKey(name, columns, foreignColumns) {
49
- return foreignKey({
50
- name,
51
- columns,
52
- foreignColumns
53
- });
54
- },
55
- createIndex(indexDefinition, terms, predicate) {
56
- let builder = (indexDefinition.unique ? uniqueIndex(indexDefinition.physicalName) : index(indexDefinition.physicalName)).on(...terms);
57
- if (predicate) builder = builder.where(predicate);
58
- return builder;
59
- }
60
- };
61
- /**
62
- * Convert a live Qubu schema registry into SQLite Drizzle table objects.
63
- *
64
- * @throws A snapshot validation error for invalid SQLite metadata, or a
65
- * DrizzleSchemaConversionError when Drizzle cannot represent required metadata.
66
- */
67
- function toSqliteDrizzleSchema(schema) {
68
- return convertDrizzleSchema(schema, sqliteAdapter);
69
- }
70
- function createSqliteStorageBuilder(type, name, declaration, definition) {
71
- const timestampRuntime = sqliteTimestampRuntime.get(definition);
72
- if (timestampRuntime !== void 0) {
73
- let builder = integer(name, { mode: timestampRuntime.mode });
74
- if (timestampRuntime.defaultFn !== void 0) builder = builder.$defaultFn(timestampRuntime.defaultFn);
75
- return builder;
76
- }
77
- return (() => {
78
- switch (type) {
79
- case "integer": return integer(name);
80
- case "numeric": return customType({
81
- dataType: () => declaration,
82
- fromDriver: (value) => Number(value)
83
- })(name);
84
- case "text": return text(name);
85
- case "boolean": return integer(name, { mode: "boolean" });
86
- case "date": return customType({
87
- dataType: () => declaration,
88
- fromDriver: (value) => new Date(value),
89
- toDriver: (value) => value.toISOString().slice(0, 10)
90
- })(name);
91
- case "timestamp": return customType({
92
- dataType: () => declaration,
93
- fromDriver: (value) => new Date(value),
94
- toDriver: (value) => value.toISOString()
95
- })(name);
96
- case "uuid": return text(name);
97
- case "json": return text(name, { mode: "json" });
98
- case "bigint": return customType({
99
- dataType: () => declaration,
100
- fromDriver: (value) => BigInt(value)
101
- })(name);
102
- case "binary": return blob(name, { mode: "buffer" });
103
- default: return customType({ dataType: () => declaration })(name);
104
- }
105
- })();
106
- }
107
- //#endregion
108
- export { sqliteTimestamp, toSqliteDrizzleSchema };
@@ -1,13 +0,0 @@
1
- import { n as DrizzleDialect } from "./types-DZsueVoI.mjs";
2
- //#region src/drizzle/errors.d.ts
3
- /** Stable failure categories raised while building a Drizzle schema. */
4
- type DrizzleSchemaConversionErrorCode = 'missing-storage' | 'unsupported-metadata';
5
- /** A path-addressed failure raised when Drizzle cannot represent Qubu metadata. */
6
- declare class DrizzleSchemaConversionError extends TypeError {
7
- readonly name = "DrizzleSchemaConversionError";
8
- readonly code: DrizzleSchemaConversionErrorCode;
9
- readonly path: readonly (string | number)[];
10
- constructor(code: DrizzleSchemaConversionErrorCode, message: string, path: readonly (string | number)[]);
11
- }
12
- //#endregion
13
- export { type DrizzleDialect, DrizzleSchemaConversionError, type DrizzleSchemaConversionErrorCode };
package/dist/drizzle.mjs DELETED
@@ -1,2 +0,0 @@
1
- import { t as DrizzleSchemaConversionError } from "./errors-BGCoLe_r.mjs";
2
- export { DrizzleSchemaConversionError };
@@ -1,14 +0,0 @@
1
- //#region src/drizzle/errors.ts
2
- /** A path-addressed failure raised when Drizzle cannot represent Qubu metadata. */
3
- var DrizzleSchemaConversionError = class extends TypeError {
4
- name = "DrizzleSchemaConversionError";
5
- code;
6
- path;
7
- constructor(code, message, path) {
8
- super(message);
9
- this.code = code;
10
- this.path = Object.freeze([...path]);
11
- }
12
- };
13
- //#endregion
14
- export { DrizzleSchemaConversionError as t };
@@ -1,236 +0,0 @@
1
- import { d as isValidSchemaObjectName } from "./column-D-8OqGuV.mjs";
2
- import { _ as isUnsafeSchemaSql, m as validateConstraintDialect, w as validateIndexDialect, y as renderSchemaExpression } from "./registry-CXV8u7Pt.mjs";
3
- import { t as createSchemaDialect } from "./dialect-b2-Z6uBF.mjs";
4
- import { a as toSnapshotJsonValue } from "./canonical-BbnqavJm.mjs";
5
- import { n as createSchemaSnapshot, s as tryCreateSchemaSnapshot } from "./serialize-CFtYYAdk.mjs";
6
- import { postgresDialect } from "./postgres.mjs";
7
- //#region src/snapshot/postgres.ts
8
- /** PostgreSQL's v1 snapshot extension identity. */
9
- const postgresSnapshotDialect = Object.freeze({
10
- name: "postgresql",
11
- version: 1
12
- });
13
- var PostgresSnapshotDialectError = class extends TypeError {
14
- code = "dialect-mismatch";
15
- };
16
- const postgresStorageTypes = Object.freeze({
17
- integer: "INTEGER",
18
- numeric: "NUMERIC",
19
- text: "TEXT",
20
- boolean: "BOOLEAN",
21
- date: "DATE",
22
- timestamp: "TIMESTAMP",
23
- uuid: "UUID",
24
- json: "JSONB",
25
- bigint: "BIGINT",
26
- binary: "BYTEA"
27
- });
28
- /** PostgreSQL's query dialect plus its schema metadata behavior. */
29
- const postgresSchemaDialect = createSchemaDialect(postgresDialect(), {
30
- version: 1,
31
- validate: validatePostgresSchema,
32
- encodeStorage(storage, context) {
33
- return encodePostgresStorage(storage, context.dialect);
34
- },
35
- encodeExpression(expression, context) {
36
- return encodePostgresExpression(expression, context.mode, context.dialect);
37
- },
38
- encodeDialectExtension(extension, context) {
39
- return encodePostgresExtension(extension, context.dialect);
40
- }
41
- });
42
- /** Snapshot adapter retaining the historical adapter-shaped entry point. */
43
- const postgresSnapshotAdapter = Object.freeze({ dialect: postgresSchemaDialect });
44
- /** Create a canonical PostgreSQL schema snapshot. */
45
- function createPostgresSchemaSnapshot(schema, options = {}) {
46
- return createSchemaSnapshot(schema, {
47
- ...options,
48
- adapter: postgresSnapshotAdapter
49
- });
50
- }
51
- /** Return PostgreSQL capability diagnostics without throwing. */
52
- function tryCreatePostgresSchemaSnapshot(schema, options = {}) {
53
- return tryCreateSchemaSnapshot(schema, {
54
- ...options,
55
- adapter: postgresSnapshotAdapter
56
- });
57
- }
58
- function encodePostgresStorage(storage, dialect) {
59
- if (storage.kind === "native") {
60
- if (storage.dialect !== dialect.name) throw new TypeError(`PostgreSQL storage cannot encode a native declaration owned by "${storage.dialect}"`);
61
- if (storage.type.trim().length === 0) throw new TypeError("PostgreSQL native storage declarations cannot be empty");
62
- return {
63
- kind: "native",
64
- dialect: dialect.name,
65
- type: storage.type
66
- };
67
- }
68
- const type = postgresStorageTypes[storage.type];
69
- if (type === void 0) throw new TypeError(`Unsupported portable storage type for PostgreSQL: ${String(storage.type)}`);
70
- return {
71
- kind: "native",
72
- dialect: dialect.name,
73
- type
74
- };
75
- }
76
- function encodePostgresExpression(expression, mode, dialect) {
77
- if (isUnsafeSchemaSql(expression) && expression.schemaSqlDialect !== dialect.name) throw new PostgresSnapshotDialectError(`Schema SQL is tagged for "${expression.schemaSqlDialect}" but the PostgreSQL schema dialect is "${dialect.name}"`);
78
- const rendered = renderSchemaExpression(expression, {
79
- mode,
80
- dialect
81
- });
82
- if (rendered.parameters.length !== 0) throw new TypeError("PostgreSQL schema expressions must be parameter-free");
83
- return {
84
- kind: "expression",
85
- expressionKind: expression.expressionKind,
86
- sql: rendered.text,
87
- ...isUnsafeSchemaSql(expression) ? { dialect: dialect.name } : {}
88
- };
89
- }
90
- function encodePostgresExtension(extension, dialect) {
91
- if (extension.dialect !== dialect.name) throw new TypeError(`PostgreSQL schema extensions require dialect "${dialect.name}"`);
92
- const data = Object.fromEntries(Object.entries(extension).filter(([key]) => key !== "dialect").sort(([left], [right]) => left.localeCompare(right)));
93
- return {
94
- dialect: dialect.name,
95
- version: dialect.schema.version,
96
- data: sortSnapshotJson(toSnapshotJsonValue(data))
97
- };
98
- }
99
- function sortSnapshotJson(value) {
100
- if (Array.isArray(value)) return value.map(sortSnapshotJson);
101
- if (typeof value !== "object" || value === null) return value;
102
- return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortSnapshotJson(child)]));
103
- }
104
- function validatePostgresSchema(schema, context) {
105
- const diagnostics = [];
106
- const tableEntries = Object.entries(schema.registry).sort(([left], [right]) => compareIds(left, right));
107
- const relationNames = /* @__PURE__ */ new Map();
108
- if (schema.namespace !== void 0) validatePostgresName(schema.namespace, ["namespace"], "PostgreSQL namespace", diagnostics);
109
- for (const [id, entry] of tableEntries) {
110
- const tablePath = ["tables", id];
111
- validatePostgresName(entry.physicalName, [...tablePath, "physicalName"], "PostgreSQL table", diagnostics);
112
- addRelationName(relationNames, entry.physicalName, [...tablePath, "physicalName"], "table", diagnostics);
113
- }
114
- for (const [id, entry] of tableEntries) validatePostgresTable(id, entry, context, relationNames, diagnostics);
115
- return Object.freeze(diagnostics);
116
- }
117
- function validatePostgresTable(tableId, entry, context, relationNames, diagnostics) {
118
- const table = entry.table;
119
- const tablePath = ["tables", tableId];
120
- const definitions = table.definitions;
121
- for (const [columnId, definition] of Object.entries(definitions).sort(([left], [right]) => compareIds(left, right))) {
122
- validatePostgresName(table.sqlNames[columnId] ?? columnId, [
123
- ...tablePath,
124
- "columns",
125
- columnId,
126
- "physicalName"
127
- ], "PostgreSQL column", diagnostics);
128
- if (definition.onUpdate !== void 0) diagnostics.push({
129
- code: "unsupported-dialect-option",
130
- message: "MySQL ON UPDATE expressions are not supported by PostgreSQL",
131
- path: [
132
- ...tablePath,
133
- "columns",
134
- columnId,
135
- "onUpdate"
136
- ]
137
- });
138
- const generated = definition.generatedColumn;
139
- if (generated !== void 0 && generated.kind === "expression" && generated.mode === "virtual") diagnostics.push({
140
- code: "unsupported-dialect-option",
141
- message: "PostgreSQL v1 snapshots support stored generated columns only; virtual generated columns are not supported",
142
- path: [
143
- ...tablePath,
144
- "columns",
145
- columnId,
146
- "generatedColumn",
147
- "mode"
148
- ]
149
- });
150
- }
151
- const metadata = table;
152
- const constraintNames = /* @__PURE__ */ new Map();
153
- const constraints = Object.entries(metadata.constraints);
154
- for (const [constraintId, constraint] of constraints.sort(([left], [right]) => compareIds(left, right))) {
155
- const constraintPath = [
156
- ...tablePath,
157
- "constraints",
158
- constraintId
159
- ];
160
- const physicalName = constraint.physicalName ?? constraintId;
161
- validatePostgresName(physicalName, [...constraintPath, "physicalName"], "PostgreSQL constraint", diagnostics);
162
- addScopedName(constraintNames, physicalName, [...constraintPath, "physicalName"], "constraint", diagnostics);
163
- appendMetadataDiagnostics(diagnostics, validateConstraintDialect(constraint, context.dialect.name, constraintPath));
164
- if (constraint.kind === "check" && constraint.deferrable === true) diagnostics.push({
165
- code: "unsupported-dialect-option",
166
- message: "PostgreSQL CHECK constraints cannot be DEFERRABLE",
167
- path: [...constraintPath, "deferrable"]
168
- });
169
- if (constraint.kind === "foreign-key" && constraint.match === "partial") diagnostics.push({
170
- code: "unsupported-dialect-option",
171
- message: "PostgreSQL does not implement MATCH PARTIAL foreign keys",
172
- path: [...constraintPath, "match"]
173
- });
174
- if (constraint.kind === "unique-constraint" && constraint.nulls === "not-distinct") diagnostics.push({
175
- code: "unsupported-dialect-option",
176
- message: "PostgreSQL NULLS NOT DISTINCT requires a server-version policy; the v1 adapter does not assume PostgreSQL 15 or newer",
177
- path: [...constraintPath, "nulls"]
178
- });
179
- }
180
- const indexes = Object.entries(metadata.indexes);
181
- for (const [indexId, index] of indexes.sort(([left], [right]) => compareIds(left, right))) {
182
- const indexPath = [
183
- ...tablePath,
184
- "indexes",
185
- indexId
186
- ];
187
- const physicalName = index.physicalName ?? indexId;
188
- validatePostgresName(physicalName, [...indexPath, "physicalName"], "PostgreSQL index", diagnostics);
189
- addRelationName(relationNames, physicalName, [...indexPath, "physicalName"], "index", diagnostics);
190
- appendMetadataDiagnostics(diagnostics, validateIndexDialect(index, context.dialect.name, indexPath));
191
- }
192
- }
193
- function validatePostgresName(name, path, kind, diagnostics) {
194
- if (!isValidSchemaObjectName(name) || name.length === 0) diagnostics.push({
195
- code: "invalid-schema",
196
- message: `${kind} name "${name}" is not a valid unqualified identifier`,
197
- path
198
- });
199
- if (new TextEncoder().encode(name).length > 63) diagnostics.push({
200
- code: "unsupported-dialect-option",
201
- message: `${kind} name exceeds PostgreSQL's 63-byte identifier limit`,
202
- path
203
- });
204
- }
205
- function addRelationName(names, name, path, kind, diagnostics) {
206
- addScopedName(names, name, path, kind, diagnostics);
207
- }
208
- function addScopedName(names, name, path, kind, diagnostics) {
209
- const previousPath = names.get(name);
210
- if (previousPath !== void 0) {
211
- diagnostics.push({
212
- code: "invalid-schema",
213
- message: `PostgreSQL ${kind} name "${name}" collides with another relation or metadata object`,
214
- path,
215
- relatedPaths: [previousPath]
216
- });
217
- return;
218
- }
219
- names.set(name, path);
220
- }
221
- function appendMetadataDiagnostics(diagnostics, issues) {
222
- for (const issue of issues) {
223
- if (issue.code === "dialect-mismatch") continue;
224
- diagnostics.push({
225
- code: issue.code === "unsupported-dialect-option" ? "unsupported-dialect-option" : "invalid-schema",
226
- message: issue.message,
227
- path: issue.path,
228
- ...issue.relatedPaths === void 0 ? {} : { relatedPaths: issue.relatedPaths }
229
- });
230
- }
231
- }
232
- function compareIds(left, right) {
233
- return left < right ? -1 : left > right ? 1 : 0;
234
- }
235
- //#endregion
236
- export { tryCreatePostgresSchemaSnapshot as a, postgresSnapshotDialect as i, postgresSchemaDialect as n, postgresSnapshotAdapter as r, createPostgresSchemaSnapshot as t };