@hedystia/db 2.0.0 → 2.0.1

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 (146) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +13 -0
  2. package/dist/_virtual/_rolldown/runtime.mjs +17 -0
  3. package/dist/cache/manager.cjs +137 -0
  4. package/dist/cache/manager.cjs.map +1 -0
  5. package/dist/cache/manager.d.cts +72 -0
  6. package/dist/cache/manager.d.mts +72 -0
  7. package/dist/cache/manager.mjs +140 -0
  8. package/dist/cache/manager.mjs.map +1 -0
  9. package/dist/cache/memory-store.cjs +122 -0
  10. package/dist/cache/memory-store.cjs.map +1 -0
  11. package/dist/cache/memory-store.mjs +122 -0
  12. package/dist/cache/memory-store.mjs.map +1 -0
  13. package/dist/cli/commands/migration.cjs +22 -0
  14. package/dist/cli/commands/migration.cjs.map +1 -0
  15. package/dist/cli/commands/migration.mjs +32 -0
  16. package/dist/cli/commands/migration.mjs.map +1 -0
  17. package/dist/cli/commands/schema.cjs +21 -0
  18. package/dist/cli/commands/schema.cjs.map +1 -0
  19. package/dist/cli/commands/schema.mjs +30 -0
  20. package/dist/cli/commands/schema.mjs.map +1 -0
  21. package/dist/cli.cjs +50 -0
  22. package/dist/cli.cjs.map +1 -0
  23. package/dist/cli.d.cts +1 -0
  24. package/dist/cli.d.mts +1 -0
  25. package/dist/cli.mjs +57 -0
  26. package/dist/cli.mjs.map +1 -0
  27. package/dist/constants.cjs +16 -0
  28. package/dist/constants.cjs.map +1 -0
  29. package/dist/constants.mjs +16 -0
  30. package/dist/constants.mjs.map +1 -0
  31. package/dist/core/database.cjs +158 -0
  32. package/dist/core/database.cjs.map +1 -0
  33. package/dist/core/database.d.cts +74 -0
  34. package/dist/core/database.d.mts +74 -0
  35. package/dist/core/database.mjs +159 -0
  36. package/dist/core/database.mjs.map +1 -0
  37. package/dist/core/repository.cjs +362 -0
  38. package/dist/core/repository.cjs.map +1 -0
  39. package/dist/core/repository.d.cts +100 -0
  40. package/dist/core/repository.d.mts +100 -0
  41. package/dist/core/repository.mjs +362 -0
  42. package/dist/core/repository.mjs.map +1 -0
  43. package/dist/drivers/driver.cjs +11 -0
  44. package/dist/drivers/driver.cjs.map +1 -0
  45. package/dist/drivers/driver.mjs +11 -0
  46. package/dist/drivers/driver.mjs.map +1 -0
  47. package/dist/drivers/file.cjs +336 -0
  48. package/dist/drivers/file.cjs.map +1 -0
  49. package/dist/drivers/file.mjs +337 -0
  50. package/dist/drivers/file.mjs.map +1 -0
  51. package/dist/drivers/index.cjs +28 -0
  52. package/dist/drivers/index.cjs.map +1 -0
  53. package/dist/drivers/index.d.cts +14 -0
  54. package/dist/drivers/index.d.mts +14 -0
  55. package/dist/drivers/index.mjs +28 -0
  56. package/dist/drivers/index.mjs.map +1 -0
  57. package/dist/drivers/mysql.cjs +272 -0
  58. package/dist/drivers/mysql.cjs.map +1 -0
  59. package/dist/drivers/mysql.mjs +272 -0
  60. package/dist/drivers/mysql.mjs.map +1 -0
  61. package/dist/drivers/sql-compiler.cjs +284 -0
  62. package/dist/drivers/sql-compiler.cjs.map +1 -0
  63. package/dist/drivers/sql-compiler.d.cts +66 -0
  64. package/dist/drivers/sql-compiler.d.mts +66 -0
  65. package/dist/drivers/sql-compiler.mjs +276 -0
  66. package/dist/drivers/sql-compiler.mjs.map +1 -0
  67. package/dist/drivers/sqlite.cjs +262 -0
  68. package/dist/drivers/sqlite.cjs.map +1 -0
  69. package/dist/drivers/sqlite.mjs +262 -0
  70. package/dist/drivers/sqlite.mjs.map +1 -0
  71. package/dist/errors.cjs +74 -0
  72. package/dist/errors.cjs.map +1 -0
  73. package/dist/errors.d.cts +46 -0
  74. package/dist/errors.d.mts +46 -0
  75. package/dist/errors.mjs +68 -0
  76. package/dist/errors.mjs.map +1 -0
  77. package/dist/index.cjs +55 -0
  78. package/dist/index.cjs.map +1 -0
  79. package/dist/index.d.cts +15 -0
  80. package/dist/index.d.mts +15 -0
  81. package/dist/index.mjs +21 -0
  82. package/dist/index.mjs.map +1 -0
  83. package/dist/migrations/definition.cjs +20 -0
  84. package/dist/migrations/definition.cjs.map +1 -0
  85. package/dist/migrations/definition.d.cts +18 -0
  86. package/dist/migrations/definition.d.mts +18 -0
  87. package/dist/migrations/definition.mjs +23 -0
  88. package/dist/migrations/definition.mjs.map +1 -0
  89. package/dist/migrations/index.mjs +12 -0
  90. package/dist/migrations/index.mjs.map +1 -0
  91. package/dist/migrations/templates.cjs +39 -0
  92. package/dist/migrations/templates.cjs.map +1 -0
  93. package/dist/migrations/templates.d.cts +16 -0
  94. package/dist/migrations/templates.d.mts +16 -0
  95. package/dist/migrations/templates.mjs +41 -0
  96. package/dist/migrations/templates.mjs.map +1 -0
  97. package/dist/schema/column.cjs +129 -0
  98. package/dist/schema/column.cjs.map +1 -0
  99. package/dist/schema/column.d.cts +96 -0
  100. package/dist/schema/column.d.mts +96 -0
  101. package/dist/schema/column.mjs +129 -0
  102. package/dist/schema/column.mjs.map +1 -0
  103. package/dist/schema/columns/index.cjs +110 -0
  104. package/dist/schema/columns/index.cjs.map +1 -0
  105. package/dist/schema/columns/index.d.cts +91 -0
  106. package/dist/schema/columns/index.d.mts +91 -0
  107. package/dist/schema/columns/index.mjs +104 -0
  108. package/dist/schema/columns/index.mjs.map +1 -0
  109. package/dist/schema/registry.cjs +101 -0
  110. package/dist/schema/registry.cjs.map +1 -0
  111. package/dist/schema/registry.d.cts +52 -0
  112. package/dist/schema/registry.d.mts +52 -0
  113. package/dist/schema/registry.mjs +101 -0
  114. package/dist/schema/registry.mjs.map +1 -0
  115. package/dist/schema/table.cjs +36 -0
  116. package/dist/schema/table.cjs.map +1 -0
  117. package/dist/schema/table.d.cts +17 -0
  118. package/dist/schema/table.d.mts +17 -0
  119. package/dist/schema/table.mjs +36 -0
  120. package/dist/schema/table.mjs.map +1 -0
  121. package/dist/sync/synchronizer.cjs +43 -0
  122. package/dist/sync/synchronizer.cjs.map +1 -0
  123. package/dist/sync/synchronizer.d.cts +22 -0
  124. package/dist/sync/synchronizer.d.mts +22 -0
  125. package/dist/sync/synchronizer.mjs +43 -0
  126. package/dist/sync/synchronizer.mjs.map +1 -0
  127. package/dist/types.d.cts +227 -0
  128. package/dist/types.d.mts +227 -0
  129. package/dist/utils/fs.cjs +24 -0
  130. package/dist/utils/fs.cjs.map +1 -0
  131. package/dist/utils/fs.mjs +26 -0
  132. package/dist/utils/fs.mjs.map +1 -0
  133. package/dist/utils/index.mjs +14 -0
  134. package/dist/utils/index.mjs.map +1 -0
  135. package/dist/utils/naming.cjs +13 -0
  136. package/dist/utils/naming.cjs.map +1 -0
  137. package/dist/utils/naming.mjs +16 -0
  138. package/dist/utils/naming.mjs.map +1 -0
  139. package/dist/utils/stable-stringify.cjs +19 -0
  140. package/dist/utils/stable-stringify.cjs.map +1 -0
  141. package/dist/utils/stable-stringify.mjs +22 -0
  142. package/dist/utils/stable-stringify.mjs.map +1 -0
  143. package/package.json +64 -27
  144. package/readme.md +86 -106
  145. package/index.d.ts +0 -65
  146. package/index.js +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { CacheManager } from \"./cache\";\nimport { database } from \"./core/database\";\nimport { TableRepository } from \"./core/repository\";\nimport { createDriver } from \"./drivers\";\nimport {\n compileColumnDef,\n compileCreateTable,\n compileDelete,\n compileInsert,\n compileSelect,\n compileUpdate,\n compileWhere,\n} from \"./drivers/sql-compiler\";\nimport { migration } from \"./migrations/definition\";\nimport { generateMigrationTemplate, generateSchemaTemplate } from \"./migrations/templates\";\nimport { ColumnBuilder } from \"./schema/column\";\nimport * as columns from \"./schema/columns\";\nimport { d } from \"./schema/columns\";\nimport { SchemaRegistry } from \"./schema/registry\";\nimport { table } from \"./schema/table\";\nimport { Synchronizer } from \"./sync/synchronizer\";\n\nexport {\n CacheError,\n DatabaseError,\n DriverError,\n MigrationError,\n QueryError,\n SchemaError,\n SyncError,\n} from \"./errors\";\n\nexport type {\n CacheConfig,\n ColumnDataType,\n ColumnMetadata,\n ConnectionConfig,\n DatabaseConfig,\n DatabaseDriver,\n DatabaseType,\n DeferredRefMeta,\n DeleteOptions,\n FileConnectionConfig,\n InferInsert,\n InferRow,\n InferUpdate,\n MigrationContext,\n MigrationDefinition,\n MySQLConnectionConfig,\n QueryOptions,\n ReferenceAction,\n RelationQueryMap,\n RelationsFor,\n Repository,\n ResolveResult,\n SQLiteConnectionConfig,\n TableDefinition,\n TableMetadata,\n UpdateOptions,\n WhereClause,\n WhereCondition,\n} from \"./types\";\nexport {\n CacheManager,\n ColumnBuilder,\n columns,\n compileColumnDef,\n compileCreateTable,\n compileDelete,\n compileInsert,\n compileSelect,\n compileUpdate,\n compileWhere,\n createDriver,\n d,\n database,\n generateMigrationTemplate,\n generateSchemaTemplate,\n migration,\n SchemaRegistry,\n Synchronizer,\n TableRepository,\n table,\n};\n\nexport default database;\n"],"mappings":";;;;;;;;;;;;;;iBAaoD;gBACuC;AAuE3F,IAAA,cAAe"}
@@ -0,0 +1,20 @@
1
+ //#region src/migrations/definition.ts
2
+ /**
3
+ * Define a database migration
4
+ * @param {string} name - Migration name (should match the file name)
5
+ * @param {object} actions - Migration actions
6
+ * @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration
7
+ * @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration
8
+ * @returns {MigrationDefinition} The migration definition
9
+ */
10
+ function migration(name, actions) {
11
+ return {
12
+ name,
13
+ up: actions.up,
14
+ down: actions.down
15
+ };
16
+ }
17
+ //#endregion
18
+ exports.migration = migration;
19
+
20
+ //# sourceMappingURL=definition.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition.cjs","names":[],"sources":["../../src/migrations/definition.ts"],"sourcesContent":["import type { MigrationContext, MigrationDefinition } from \"../types\";\n\n/**\n * Define a database migration\n * @param {string} name - Migration name (should match the file name)\n * @param {object} actions - Migration actions\n * @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration\n * @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration\n * @returns {MigrationDefinition} The migration definition\n */\nexport function migration(\n name: string,\n actions: {\n up: (ctx: MigrationContext) => Promise<void>;\n down: (ctx: MigrationContext) => Promise<void>;\n },\n): MigrationDefinition {\n return {\n name,\n up: actions.up,\n down: actions.down,\n };\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,UACd,MACA,SAIqB;AACrB,QAAO;EACL;EACA,IAAI,QAAQ;EACZ,MAAM,QAAQ;EACf"}
@@ -0,0 +1,18 @@
1
+ import { MigrationContext, MigrationDefinition } from "../types.cjs";
2
+
3
+ //#region src/migrations/definition.d.ts
4
+ /**
5
+ * Define a database migration
6
+ * @param {string} name - Migration name (should match the file name)
7
+ * @param {object} actions - Migration actions
8
+ * @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration
9
+ * @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration
10
+ * @returns {MigrationDefinition} The migration definition
11
+ */
12
+ declare function migration(name: string, actions: {
13
+ up: (ctx: MigrationContext) => Promise<void>;
14
+ down: (ctx: MigrationContext) => Promise<void>;
15
+ }): MigrationDefinition;
16
+ //#endregion
17
+ export { migration };
18
+ //# sourceMappingURL=definition.d.cts.map
@@ -0,0 +1,18 @@
1
+ import { MigrationContext, MigrationDefinition } from "../types.mjs";
2
+
3
+ //#region src/migrations/definition.d.ts
4
+ /**
5
+ * Define a database migration
6
+ * @param {string} name - Migration name (should match the file name)
7
+ * @param {object} actions - Migration actions
8
+ * @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration
9
+ * @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration
10
+ * @returns {MigrationDefinition} The migration definition
11
+ */
12
+ declare function migration(name: string, actions: {
13
+ up: (ctx: MigrationContext) => Promise<void>;
14
+ down: (ctx: MigrationContext) => Promise<void>;
15
+ }): MigrationDefinition;
16
+ //#endregion
17
+ export { migration };
18
+ //# sourceMappingURL=definition.d.mts.map
@@ -0,0 +1,23 @@
1
+ import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
2
+ //#region src/migrations/definition.ts
3
+ /**
4
+ * Define a database migration
5
+ * @param {string} name - Migration name (should match the file name)
6
+ * @param {object} actions - Migration actions
7
+ * @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration
8
+ * @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration
9
+ * @returns {MigrationDefinition} The migration definition
10
+ */
11
+ function migration(name, actions) {
12
+ return {
13
+ name,
14
+ up: actions.up,
15
+ down: actions.down
16
+ };
17
+ }
18
+ var init_definition = __esmMin((() => {}));
19
+ //#endregion
20
+ init_definition();
21
+ export { init_definition, migration };
22
+
23
+ //# sourceMappingURL=definition.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition.mjs","names":[],"sources":["../../src/migrations/definition.ts"],"sourcesContent":["import type { MigrationContext, MigrationDefinition } from \"../types\";\n\n/**\n * Define a database migration\n * @param {string} name - Migration name (should match the file name)\n * @param {object} actions - Migration actions\n * @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration\n * @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration\n * @returns {MigrationDefinition} The migration definition\n */\nexport function migration(\n name: string,\n actions: {\n up: (ctx: MigrationContext) => Promise<void>;\n down: (ctx: MigrationContext) => Promise<void>;\n },\n): MigrationDefinition {\n return {\n name,\n up: actions.up,\n down: actions.down,\n };\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,UACd,MACA,SAIqB;AACrB,QAAO;EACL;EACA,IAAI,QAAQ;EACZ,MAAM,QAAQ;EACf"}
@@ -0,0 +1,12 @@
1
+ import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
2
+ import "./definition.mjs";
3
+ import { init_templates } from "./templates.mjs";
4
+ //#region src/migrations/index.ts
5
+ var init_migrations = __esmMin((() => {
6
+ init_templates();
7
+ }));
8
+ //#endregion
9
+ init_migrations();
10
+ export { init_migrations };
11
+
12
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/migrations/index.ts"],"sourcesContent":["export { migration } from \"./definition\";\nexport { generateMigrationTemplate, generateSchemaTemplate } from \"./templates\";\n"],"mappings":";;;;;iBACgF"}
@@ -0,0 +1,39 @@
1
+ //#region src/migrations/templates.ts
2
+ /**
3
+ * Generate a migration file template
4
+ * @param {string} name - Migration name
5
+ * @returns {string} Migration file content
6
+ */
7
+ function generateMigrationTemplate(name) {
8
+ return `import { migration } from "@hedystia/db";
9
+
10
+ export default migration("${name}", {
11
+ async up({ schema, sql }) {
12
+ // Add your migration logic here
13
+ },
14
+ async down({ schema, sql }) {
15
+ // Add your rollback logic here
16
+ },
17
+ });
18
+ `;
19
+ }
20
+ /**
21
+ * Generate a schema file template
22
+ * @param {string} name - Table name
23
+ * @returns {string} Schema file content
24
+ */
25
+ function generateSchemaTemplate(name) {
26
+ return `import { table, d } from "@hedystia/db";
27
+
28
+ export const ${name} = table("${name}", {
29
+ id: d.integer().primaryKey().autoIncrement(),
30
+ createdAt: d.datetime().default(new Date()),
31
+ updatedAt: d.datetime().default(new Date()),
32
+ });
33
+ `;
34
+ }
35
+ //#endregion
36
+ exports.generateMigrationTemplate = generateMigrationTemplate;
37
+ exports.generateSchemaTemplate = generateSchemaTemplate;
38
+
39
+ //# sourceMappingURL=templates.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.cjs","names":[],"sources":["../../src/migrations/templates.ts"],"sourcesContent":["/**\n * Generate a migration file template\n * @param {string} name - Migration name\n * @returns {string} Migration file content\n */\nexport function generateMigrationTemplate(name: string): string {\n return `import { migration } from \"@hedystia/db\";\n\nexport default migration(\"${name}\", {\n async up({ schema, sql }) {\n // Add your migration logic here\n },\n async down({ schema, sql }) {\n // Add your rollback logic here\n },\n});\n`;\n}\n\n/**\n * Generate a schema file template\n * @param {string} name - Table name\n * @returns {string} Schema file content\n */\nexport function generateSchemaTemplate(name: string): string {\n return `import { table, d } from \"@hedystia/db\";\n\nexport const ${name} = table(\"${name}\", {\n id: d.integer().primaryKey().autoIncrement(),\n createdAt: d.datetime().default(new Date()),\n updatedAt: d.datetime().default(new Date()),\n});\n`;\n}\n"],"mappings":";;;;;;AAKA,SAAgB,0BAA0B,MAAsB;AAC9D,QAAO;;4BAEmB,KAAK;;;;;;;;;;;;;;;AAgBjC,SAAgB,uBAAuB,MAAsB;AAC3D,QAAO;;eAEM,KAAK,YAAY,KAAK"}
@@ -0,0 +1,16 @@
1
+ //#region src/migrations/templates.d.ts
2
+ /**
3
+ * Generate a migration file template
4
+ * @param {string} name - Migration name
5
+ * @returns {string} Migration file content
6
+ */
7
+ declare function generateMigrationTemplate(name: string): string;
8
+ /**
9
+ * Generate a schema file template
10
+ * @param {string} name - Table name
11
+ * @returns {string} Schema file content
12
+ */
13
+ declare function generateSchemaTemplate(name: string): string;
14
+ //#endregion
15
+ export { generateMigrationTemplate, generateSchemaTemplate };
16
+ //# sourceMappingURL=templates.d.cts.map
@@ -0,0 +1,16 @@
1
+ //#region src/migrations/templates.d.ts
2
+ /**
3
+ * Generate a migration file template
4
+ * @param {string} name - Migration name
5
+ * @returns {string} Migration file content
6
+ */
7
+ declare function generateMigrationTemplate(name: string): string;
8
+ /**
9
+ * Generate a schema file template
10
+ * @param {string} name - Table name
11
+ * @returns {string} Schema file content
12
+ */
13
+ declare function generateSchemaTemplate(name: string): string;
14
+ //#endregion
15
+ export { generateMigrationTemplate, generateSchemaTemplate };
16
+ //# sourceMappingURL=templates.d.mts.map
@@ -0,0 +1,41 @@
1
+ import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
2
+ //#region src/migrations/templates.ts
3
+ /**
4
+ * Generate a migration file template
5
+ * @param {string} name - Migration name
6
+ * @returns {string} Migration file content
7
+ */
8
+ function generateMigrationTemplate(name) {
9
+ return `import { migration } from "@hedystia/db";
10
+
11
+ export default migration("${name}", {
12
+ async up({ schema, sql }) {
13
+ // Add your migration logic here
14
+ },
15
+ async down({ schema, sql }) {
16
+ // Add your rollback logic here
17
+ },
18
+ });
19
+ `;
20
+ }
21
+ /**
22
+ * Generate a schema file template
23
+ * @param {string} name - Table name
24
+ * @returns {string} Schema file content
25
+ */
26
+ function generateSchemaTemplate(name) {
27
+ return `import { table, d } from "@hedystia/db";
28
+
29
+ export const ${name} = table("${name}", {
30
+ id: d.integer().primaryKey().autoIncrement(),
31
+ createdAt: d.datetime().default(new Date()),
32
+ updatedAt: d.datetime().default(new Date()),
33
+ });
34
+ `;
35
+ }
36
+ var init_templates = __esmMin((() => {}));
37
+ //#endregion
38
+ init_templates();
39
+ export { generateMigrationTemplate, generateSchemaTemplate, init_templates };
40
+
41
+ //# sourceMappingURL=templates.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.mjs","names":[],"sources":["../../src/migrations/templates.ts"],"sourcesContent":["/**\n * Generate a migration file template\n * @param {string} name - Migration name\n * @returns {string} Migration file content\n */\nexport function generateMigrationTemplate(name: string): string {\n return `import { migration } from \"@hedystia/db\";\n\nexport default migration(\"${name}\", {\n async up({ schema, sql }) {\n // Add your migration logic here\n },\n async down({ schema, sql }) {\n // Add your rollback logic here\n },\n});\n`;\n}\n\n/**\n * Generate a schema file template\n * @param {string} name - Table name\n * @returns {string} Schema file content\n */\nexport function generateSchemaTemplate(name: string): string {\n return `import { table, d } from \"@hedystia/db\";\n\nexport const ${name} = table(\"${name}\", {\n id: d.integer().primaryKey().autoIncrement(),\n createdAt: d.datetime().default(new Date()),\n updatedAt: d.datetime().default(new Date()),\n});\n`;\n}\n"],"mappings":";;;;;;;AAKA,SAAgB,0BAA0B,MAAsB;AAC9D,QAAO;;4BAEmB,KAAK;;;;;;;;;;;;;;;AAgBjC,SAAgB,uBAAuB,MAAsB;AAC3D,QAAO;;eAEM,KAAK,YAAY,KAAK"}
@@ -0,0 +1,129 @@
1
+ //#region src/schema/column.ts
2
+ /**
3
+ * Base column builder with chainable methods for defining column properties
4
+ * @template T - The TypeScript type this column resolves to
5
+ * @template TN - The table name this column belongs to (set by table())
6
+ * @template CN - The column name (set by table())
7
+ * @template Ref - The deferred reference metadata (set by references())
8
+ */
9
+ var ColumnBuilder = class {
10
+ _type;
11
+ _primaryKey = false;
12
+ _autoIncrement = false;
13
+ _notNull = false;
14
+ _unique = false;
15
+ _defaultValue = void 0;
16
+ _length;
17
+ _precision;
18
+ _scale;
19
+ _references;
20
+ constructor(type, length, precision, scale) {
21
+ this._type = type;
22
+ this._length = length;
23
+ this._precision = precision;
24
+ this._scale = scale;
25
+ }
26
+ /**
27
+ * Mark this column as a primary key
28
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
29
+ */
30
+ primaryKey() {
31
+ this._primaryKey = true;
32
+ return this;
33
+ }
34
+ /**
35
+ * Mark this column as auto-incrementing
36
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
37
+ */
38
+ autoIncrement() {
39
+ this._autoIncrement = true;
40
+ return this;
41
+ }
42
+ /**
43
+ * Mark this column as NOT NULL
44
+ * @returns {ColumnBuilder<NonNullable<T>, TN, CN, Ref>} The column builder for chaining
45
+ */
46
+ notNull() {
47
+ this._notNull = true;
48
+ return this;
49
+ }
50
+ /**
51
+ * Mark this column as nullable
52
+ * @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining
53
+ */
54
+ nullable() {
55
+ this._notNull = false;
56
+ return this;
57
+ }
58
+ /**
59
+ * Set a default value for this column
60
+ * @param {T} value - The default value
61
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
62
+ */
63
+ default(value) {
64
+ this._defaultValue = value;
65
+ return this;
66
+ }
67
+ /**
68
+ * Mark this column as having a unique constraint
69
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
70
+ */
71
+ unique() {
72
+ this._unique = true;
73
+ return this;
74
+ }
75
+ /**
76
+ * Add a foreign key reference to another table's column
77
+ * @param {() => ColumnBuilder<any>} ref - A function returning the referenced column
78
+ * @param {object} [options] - Reference options
79
+ * @param {ReferenceAction} [options.onDelete] - Action on delete
80
+ * @param {ReferenceAction} [options.onUpdate] - Action on update
81
+ * @param {string} [options.relationName] - Name for the relation
82
+ * @returns {ColumnBuilder<T>} The column builder for chaining
83
+ */
84
+ references(ref, options) {
85
+ this._references = {
86
+ resolve: () => {
87
+ const col = ref();
88
+ return {
89
+ table: col.__tableName ?? "",
90
+ column: col.__columnName ?? ""
91
+ };
92
+ },
93
+ onDelete: options?.onDelete,
94
+ onUpdate: options?.onUpdate,
95
+ relationName: options?.relationName
96
+ };
97
+ return this;
98
+ }
99
+ /**
100
+ * Build the column metadata from the builder configuration
101
+ * @param {string} name - The column name
102
+ * @returns {ColumnMetadata} The built column metadata
103
+ */
104
+ __build(name) {
105
+ return {
106
+ name,
107
+ type: this._type,
108
+ primaryKey: this._primaryKey,
109
+ autoIncrement: this._autoIncrement,
110
+ notNull: this._notNull || this._primaryKey,
111
+ unique: this._unique || this._primaryKey,
112
+ defaultValue: this._defaultValue,
113
+ length: this._length,
114
+ precision: this._precision,
115
+ scale: this._scale
116
+ };
117
+ }
118
+ /**
119
+ * Get deferred reference data if this column has a foreign key reference
120
+ * @returns {object | null} The deferred reference data or null
121
+ */
122
+ __getDeferredRef() {
123
+ return this._references ?? null;
124
+ }
125
+ };
126
+ //#endregion
127
+ exports.ColumnBuilder = ColumnBuilder;
128
+
129
+ //# sourceMappingURL=column.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.cjs","names":[],"sources":["../../src/schema/column.ts"],"sourcesContent":["import type {\n ColumnDataType,\n ColumnMetadata,\n DeferredRefMeta,\n ReferenceAction,\n} from \"../types\";\n\n/**\n * Base column builder with chainable methods for defining column properties\n * @template T - The TypeScript type this column resolves to\n * @template TN - The table name this column belongs to (set by table())\n * @template CN - The column name (set by table())\n * @template Ref - The deferred reference metadata (set by references())\n */\nexport class ColumnBuilder<\n T = unknown,\n TN extends string = string,\n CN extends string = string,\n Ref extends DeferredRefMeta = never,\n> {\n declare readonly __type: T;\n declare readonly __tableName: TN;\n declare readonly __columnName: CN;\n declare readonly __ref: Ref;\n private _type: ColumnDataType;\n private _primaryKey = false;\n private _autoIncrement = false;\n private _notNull = false;\n private _unique = false;\n private _defaultValue: unknown = undefined;\n private _length?: number;\n private _precision?: number;\n private _scale?: number;\n private _references?: {\n resolve: () => { table: string; column: string };\n onDelete?: ReferenceAction;\n onUpdate?: ReferenceAction;\n relationName?: string;\n };\n\n constructor(type: ColumnDataType, length?: number, precision?: number, scale?: number) {\n this._type = type;\n this._length = length;\n this._precision = precision;\n this._scale = scale;\n }\n\n /**\n * Mark this column as a primary key\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n primaryKey(): ColumnBuilder<T, TN, CN, Ref> {\n this._primaryKey = true;\n return this;\n }\n\n /**\n * Mark this column as auto-incrementing\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n autoIncrement(): ColumnBuilder<T, TN, CN, Ref> {\n this._autoIncrement = true;\n return this;\n }\n\n /**\n * Mark this column as NOT NULL\n * @returns {ColumnBuilder<NonNullable<T>, TN, CN, Ref>} The column builder for chaining\n */\n notNull(): ColumnBuilder<NonNullable<T>, TN, CN, Ref> {\n this._notNull = true;\n return this as unknown as ColumnBuilder<NonNullable<T>, TN, CN, Ref>;\n }\n\n /**\n * Mark this column as nullable\n * @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining\n */\n nullable(): ColumnBuilder<T | null, TN, CN, Ref> {\n this._notNull = false;\n return this as unknown as ColumnBuilder<T | null, TN, CN, Ref>;\n }\n\n /**\n * Set a default value for this column\n * @param {T} value - The default value\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n default(value: T): ColumnBuilder<T, TN, CN, Ref> {\n this._defaultValue = value;\n return this;\n }\n\n /**\n * Mark this column as having a unique constraint\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n unique(): ColumnBuilder<T, TN, CN, Ref> {\n this._unique = true;\n return this;\n }\n\n /**\n * Add a foreign key reference to another table's column\n * @param {() => ColumnBuilder<any>} ref - A function returning the referenced column\n * @param {object} [options] - Reference options\n * @param {ReferenceAction} [options.onDelete] - Action on delete\n * @param {ReferenceAction} [options.onUpdate] - Action on update\n * @param {string} [options.relationName] - Name for the relation\n * @returns {ColumnBuilder<T>} The column builder for chaining\n */\n references<\n R extends ColumnBuilder<any, string, string, any>,\n O extends {\n onDelete?: ReferenceAction;\n onUpdate?: ReferenceAction;\n relationName?: string;\n } = never,\n >(\n ref: () => R,\n options?: O,\n ): ColumnBuilder<\n T,\n TN,\n CN,\n DeferredRefMeta<\n CN,\n R[\"__tableName\"],\n R[\"__columnName\"],\n O extends { relationName: infer N extends string } ? N : undefined\n >\n > {\n this._references = {\n resolve: () => {\n const col = ref();\n return {\n table: (col as any).__tableName ?? \"\",\n column: (col as any).__columnName ?? \"\",\n };\n },\n onDelete: options?.onDelete,\n onUpdate: options?.onUpdate,\n relationName: options?.relationName,\n };\n return this as any;\n }\n\n /**\n * Build the column metadata from the builder configuration\n * @param {string} name - The column name\n * @returns {ColumnMetadata} The built column metadata\n */\n __build(name: string): ColumnMetadata {\n return {\n name,\n type: this._type,\n primaryKey: this._primaryKey,\n autoIncrement: this._autoIncrement,\n notNull: this._notNull || this._primaryKey,\n unique: this._unique || this._primaryKey,\n defaultValue: this._defaultValue,\n length: this._length,\n precision: this._precision,\n scale: this._scale,\n };\n }\n\n /**\n * Get deferred reference data if this column has a foreign key reference\n * @returns {object | null} The deferred reference data or null\n */\n __getDeferredRef(): {\n resolve: () => { table: string; column: string };\n onDelete?: ReferenceAction;\n onUpdate?: ReferenceAction;\n relationName?: string;\n } | null {\n return this._references ?? null;\n }\n}\n"],"mappings":";;;;;;;;AAcA,IAAa,gBAAb,MAKE;CAKA;CACA,cAAsB;CACtB,iBAAyB;CACzB,WAAmB;CACnB,UAAkB;CAClB,gBAAiC,KAAA;CACjC;CACA;CACA;CACA;CAOA,YAAY,MAAsB,QAAiB,WAAoB,OAAgB;AACrF,OAAK,QAAQ;AACb,OAAK,UAAU;AACf,OAAK,aAAa;AAClB,OAAK,SAAS;;;;;;CAOhB,aAA4C;AAC1C,OAAK,cAAc;AACnB,SAAO;;;;;;CAOT,gBAA+C;AAC7C,OAAK,iBAAiB;AACtB,SAAO;;;;;;CAOT,UAAsD;AACpD,OAAK,WAAW;AAChB,SAAO;;;;;;CAOT,WAAiD;AAC/C,OAAK,WAAW;AAChB,SAAO;;;;;;;CAQT,QAAQ,OAAyC;AAC/C,OAAK,gBAAgB;AACrB,SAAO;;;;;;CAOT,SAAwC;AACtC,OAAK,UAAU;AACf,SAAO;;;;;;;;;;;CAYT,WAQE,KACA,SAWA;AACA,OAAK,cAAc;GACjB,eAAe;IACb,MAAM,MAAM,KAAK;AACjB,WAAO;KACL,OAAQ,IAAY,eAAe;KACnC,QAAS,IAAY,gBAAgB;KACtC;;GAEH,UAAU,SAAS;GACnB,UAAU,SAAS;GACnB,cAAc,SAAS;GACxB;AACD,SAAO;;;;;;;CAQT,QAAQ,MAA8B;AACpC,SAAO;GACL;GACA,MAAM,KAAK;GACX,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,SAAS,KAAK,YAAY,KAAK;GAC/B,QAAQ,KAAK,WAAW,KAAK;GAC7B,cAAc,KAAK;GACnB,QAAQ,KAAK;GACb,WAAW,KAAK;GAChB,OAAO,KAAK;GACb;;;;;;CAOH,mBAKS;AACP,SAAO,KAAK,eAAe"}
@@ -0,0 +1,96 @@
1
+ import { ColumnDataType, ColumnMetadata, DeferredRefMeta, ReferenceAction } from "../types.cjs";
2
+
3
+ //#region src/schema/column.d.ts
4
+ /**
5
+ * Base column builder with chainable methods for defining column properties
6
+ * @template T - The TypeScript type this column resolves to
7
+ * @template TN - The table name this column belongs to (set by table())
8
+ * @template CN - The column name (set by table())
9
+ * @template Ref - The deferred reference metadata (set by references())
10
+ */
11
+ declare class ColumnBuilder<T = unknown, TN extends string = string, CN extends string = string, Ref extends DeferredRefMeta = never> {
12
+ readonly __type: T;
13
+ readonly __tableName: TN;
14
+ readonly __columnName: CN;
15
+ readonly __ref: Ref;
16
+ private _type;
17
+ private _primaryKey;
18
+ private _autoIncrement;
19
+ private _notNull;
20
+ private _unique;
21
+ private _defaultValue;
22
+ private _length?;
23
+ private _precision?;
24
+ private _scale?;
25
+ private _references?;
26
+ constructor(type: ColumnDataType, length?: number, precision?: number, scale?: number);
27
+ /**
28
+ * Mark this column as a primary key
29
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
30
+ */
31
+ primaryKey(): ColumnBuilder<T, TN, CN, Ref>;
32
+ /**
33
+ * Mark this column as auto-incrementing
34
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
35
+ */
36
+ autoIncrement(): ColumnBuilder<T, TN, CN, Ref>;
37
+ /**
38
+ * Mark this column as NOT NULL
39
+ * @returns {ColumnBuilder<NonNullable<T>, TN, CN, Ref>} The column builder for chaining
40
+ */
41
+ notNull(): ColumnBuilder<NonNullable<T>, TN, CN, Ref>;
42
+ /**
43
+ * Mark this column as nullable
44
+ * @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining
45
+ */
46
+ nullable(): ColumnBuilder<T | null, TN, CN, Ref>;
47
+ /**
48
+ * Set a default value for this column
49
+ * @param {T} value - The default value
50
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
51
+ */
52
+ default(value: T): ColumnBuilder<T, TN, CN, Ref>;
53
+ /**
54
+ * Mark this column as having a unique constraint
55
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
56
+ */
57
+ unique(): ColumnBuilder<T, TN, CN, Ref>;
58
+ /**
59
+ * Add a foreign key reference to another table's column
60
+ * @param {() => ColumnBuilder<any>} ref - A function returning the referenced column
61
+ * @param {object} [options] - Reference options
62
+ * @param {ReferenceAction} [options.onDelete] - Action on delete
63
+ * @param {ReferenceAction} [options.onUpdate] - Action on update
64
+ * @param {string} [options.relationName] - Name for the relation
65
+ * @returns {ColumnBuilder<T>} The column builder for chaining
66
+ */
67
+ references<R extends ColumnBuilder<any, string, string, any>, O extends {
68
+ onDelete?: ReferenceAction;
69
+ onUpdate?: ReferenceAction;
70
+ relationName?: string;
71
+ } = never>(ref: () => R, options?: O): ColumnBuilder<T, TN, CN, DeferredRefMeta<CN, R["__tableName"], R["__columnName"], O extends {
72
+ relationName: infer N extends string;
73
+ } ? N : undefined>>;
74
+ /**
75
+ * Build the column metadata from the builder configuration
76
+ * @param {string} name - The column name
77
+ * @returns {ColumnMetadata} The built column metadata
78
+ */
79
+ __build(name: string): ColumnMetadata;
80
+ /**
81
+ * Get deferred reference data if this column has a foreign key reference
82
+ * @returns {object | null} The deferred reference data or null
83
+ */
84
+ __getDeferredRef(): {
85
+ resolve: () => {
86
+ table: string;
87
+ column: string;
88
+ };
89
+ onDelete?: ReferenceAction;
90
+ onUpdate?: ReferenceAction;
91
+ relationName?: string;
92
+ } | null;
93
+ }
94
+ //#endregion
95
+ export { ColumnBuilder };
96
+ //# sourceMappingURL=column.d.cts.map
@@ -0,0 +1,96 @@
1
+ import { ColumnDataType, ColumnMetadata, DeferredRefMeta, ReferenceAction } from "../types.mjs";
2
+
3
+ //#region src/schema/column.d.ts
4
+ /**
5
+ * Base column builder with chainable methods for defining column properties
6
+ * @template T - The TypeScript type this column resolves to
7
+ * @template TN - The table name this column belongs to (set by table())
8
+ * @template CN - The column name (set by table())
9
+ * @template Ref - The deferred reference metadata (set by references())
10
+ */
11
+ declare class ColumnBuilder<T = unknown, TN extends string = string, CN extends string = string, Ref extends DeferredRefMeta = never> {
12
+ readonly __type: T;
13
+ readonly __tableName: TN;
14
+ readonly __columnName: CN;
15
+ readonly __ref: Ref;
16
+ private _type;
17
+ private _primaryKey;
18
+ private _autoIncrement;
19
+ private _notNull;
20
+ private _unique;
21
+ private _defaultValue;
22
+ private _length?;
23
+ private _precision?;
24
+ private _scale?;
25
+ private _references?;
26
+ constructor(type: ColumnDataType, length?: number, precision?: number, scale?: number);
27
+ /**
28
+ * Mark this column as a primary key
29
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
30
+ */
31
+ primaryKey(): ColumnBuilder<T, TN, CN, Ref>;
32
+ /**
33
+ * Mark this column as auto-incrementing
34
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
35
+ */
36
+ autoIncrement(): ColumnBuilder<T, TN, CN, Ref>;
37
+ /**
38
+ * Mark this column as NOT NULL
39
+ * @returns {ColumnBuilder<NonNullable<T>, TN, CN, Ref>} The column builder for chaining
40
+ */
41
+ notNull(): ColumnBuilder<NonNullable<T>, TN, CN, Ref>;
42
+ /**
43
+ * Mark this column as nullable
44
+ * @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining
45
+ */
46
+ nullable(): ColumnBuilder<T | null, TN, CN, Ref>;
47
+ /**
48
+ * Set a default value for this column
49
+ * @param {T} value - The default value
50
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
51
+ */
52
+ default(value: T): ColumnBuilder<T, TN, CN, Ref>;
53
+ /**
54
+ * Mark this column as having a unique constraint
55
+ * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
56
+ */
57
+ unique(): ColumnBuilder<T, TN, CN, Ref>;
58
+ /**
59
+ * Add a foreign key reference to another table's column
60
+ * @param {() => ColumnBuilder<any>} ref - A function returning the referenced column
61
+ * @param {object} [options] - Reference options
62
+ * @param {ReferenceAction} [options.onDelete] - Action on delete
63
+ * @param {ReferenceAction} [options.onUpdate] - Action on update
64
+ * @param {string} [options.relationName] - Name for the relation
65
+ * @returns {ColumnBuilder<T>} The column builder for chaining
66
+ */
67
+ references<R extends ColumnBuilder<any, string, string, any>, O extends {
68
+ onDelete?: ReferenceAction;
69
+ onUpdate?: ReferenceAction;
70
+ relationName?: string;
71
+ } = never>(ref: () => R, options?: O): ColumnBuilder<T, TN, CN, DeferredRefMeta<CN, R["__tableName"], R["__columnName"], O extends {
72
+ relationName: infer N extends string;
73
+ } ? N : undefined>>;
74
+ /**
75
+ * Build the column metadata from the builder configuration
76
+ * @param {string} name - The column name
77
+ * @returns {ColumnMetadata} The built column metadata
78
+ */
79
+ __build(name: string): ColumnMetadata;
80
+ /**
81
+ * Get deferred reference data if this column has a foreign key reference
82
+ * @returns {object | null} The deferred reference data or null
83
+ */
84
+ __getDeferredRef(): {
85
+ resolve: () => {
86
+ table: string;
87
+ column: string;
88
+ };
89
+ onDelete?: ReferenceAction;
90
+ onUpdate?: ReferenceAction;
91
+ relationName?: string;
92
+ } | null;
93
+ }
94
+ //#endregion
95
+ export { ColumnBuilder };
96
+ //# sourceMappingURL=column.d.mts.map