@astrojs/db 0.4.0 → 0.5.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.
Files changed (57) hide show
  1. package/dist/core/cli/commands/execute/index.d.ts +8 -0
  2. package/dist/core/cli/commands/execute/index.js +32 -0
  3. package/dist/core/cli/commands/gen/index.d.ts +4 -2
  4. package/dist/core/cli/commands/gen/index.js +17 -9
  5. package/dist/core/cli/commands/link/index.d.ts +20 -8
  6. package/dist/core/cli/commands/link/index.js +191 -31
  7. package/dist/core/cli/commands/login/index.d.ts +4 -2
  8. package/dist/core/cli/commands/login/index.js +31 -22
  9. package/dist/core/cli/commands/logout/index.d.ts +1 -6
  10. package/dist/core/cli/commands/logout/index.js +1 -1
  11. package/dist/core/cli/commands/push/index.d.ts +4 -2
  12. package/dist/core/cli/commands/push/index.js +25 -77
  13. package/dist/core/cli/commands/shell/index.d.ts +4 -2
  14. package/dist/core/cli/commands/shell/index.js +3 -1
  15. package/dist/core/cli/commands/verify/index.d.ts +4 -2
  16. package/dist/core/cli/commands/verify/index.js +10 -6
  17. package/dist/core/cli/index.d.ts +1 -1
  18. package/dist/core/cli/index.js +19 -13
  19. package/dist/core/cli/migration-queries.d.ts +1 -1
  20. package/dist/core/cli/migration-queries.js +6 -6
  21. package/dist/core/cli/migrations.d.ts +12 -9
  22. package/dist/core/cli/migrations.js +27 -21
  23. package/dist/core/consts.d.ts +2 -0
  24. package/dist/core/consts.js +4 -0
  25. package/dist/core/errors.d.ts +7 -4
  26. package/dist/core/errors.js +38 -31
  27. package/dist/core/integration/file-url.js +1 -1
  28. package/dist/core/integration/index.js +56 -117
  29. package/dist/core/integration/typegen.js +1 -13
  30. package/dist/core/integration/vite-plugin-db.d.ts +10 -6
  31. package/dist/core/integration/vite-plugin-db.js +68 -23
  32. package/dist/core/integration/vite-plugin-inject-env-ts.d.ts +1 -1
  33. package/dist/core/load-file.d.ts +31 -0
  34. package/dist/core/load-file.js +98 -0
  35. package/dist/core/tokens.js +1 -1
  36. package/dist/core/types.d.ts +832 -5306
  37. package/dist/core/types.js +16 -84
  38. package/dist/core/utils.d.ts +2 -0
  39. package/dist/core/utils.js +8 -0
  40. package/dist/index.d.ts +2 -3
  41. package/dist/index.js +3 -5
  42. package/dist/runtime/config.d.ts +138 -0
  43. package/dist/runtime/config.js +42 -0
  44. package/dist/runtime/db-client.d.ts +2 -9
  45. package/dist/runtime/db-client.js +8 -39
  46. package/dist/runtime/index.d.ts +5 -4
  47. package/dist/runtime/index.js +12 -10
  48. package/dist/{core → runtime}/queries.d.ts +15 -17
  49. package/dist/{core → runtime}/queries.js +64 -80
  50. package/dist/runtime/types.d.ts +3 -3
  51. package/dist/utils.d.ts +1 -0
  52. package/dist/utils.js +4 -0
  53. package/index.d.ts +5 -3
  54. package/package.json +18 -3
  55. package/config-augment.d.ts +0 -4
  56. package/dist/core/integration/load-astro-config.d.ts +0 -6
  57. package/dist/core/integration/load-astro-config.js +0 -79
@@ -1,9 +1,8 @@
1
+ import { SQL } from "drizzle-orm";
1
2
  import { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core";
2
- import { collectionToTable } from "../runtime/index.js";
3
3
  import { z } from "zod";
4
- import { SQL } from "drizzle-orm";
5
- import { errorMap } from "./integration/error-map.js";
6
4
  import { SERIALIZED_SQL_KEY } from "../runtime/types.js";
5
+ import { errorMap } from "./integration/error-map.js";
7
6
  const sqlite = new SQLiteAsyncDialect();
8
7
  const sqlSchema = z.instanceof(SQL).transform(
9
8
  (sqlObj) => ({
@@ -17,6 +16,7 @@ const baseColumnSchema = z.object({
17
16
  unique: z.boolean().optional().default(false),
18
17
  // Defined when `defineReadableTable()` is called
19
18
  name: z.string().optional(),
19
+ // TODO: rename to `tableName`. Breaking schema change
20
20
  collection: z.string().optional()
21
21
  });
22
22
  const booleanColumnSchema = z.object({
@@ -112,98 +112,30 @@ const foreignKeysSchema = z.object({
112
112
  columns: z.string().or(z.array(z.string())),
113
113
  references: z.function().returns(z.lazy(() => referenceableColumnSchema.or(z.array(referenceableColumnSchema)))).transform((fn) => fn())
114
114
  });
115
- const baseCollectionSchema = z.object({
115
+ const tableSchema = z.object({
116
116
  columns: columnsSchema,
117
117
  indexes: z.record(indexSchema).optional(),
118
118
  foreignKeys: z.array(foreignKeysSchema).optional()
119
119
  });
120
- const readableCollectionSchema = baseCollectionSchema.extend({
121
- writable: z.literal(false)
122
- });
123
- const writableCollectionSchema = baseCollectionSchema.extend({
124
- writable: z.literal(true)
125
- });
126
- const collectionSchema = z.union([readableCollectionSchema, writableCollectionSchema]);
127
- const tablesSchema = z.preprocess((rawCollections) => {
128
- const tables = z.record(z.any()).parse(rawCollections, { errorMap });
129
- for (const [collectionName, collection] of Object.entries(tables)) {
130
- collection.table = collectionToTable(
131
- collectionName,
132
- collectionSchema.parse(collection, { errorMap })
133
- );
134
- const { columns } = z.object({ columns: z.record(z.any()) }).parse(collection, { errorMap });
135
- for (const [columnName, column2] of Object.entries(columns)) {
136
- column2.schema.name = columnName;
137
- column2.schema.collection = collectionName;
120
+ const tablesSchema = z.preprocess((rawTables) => {
121
+ const tables = z.record(z.any()).parse(rawTables, { errorMap });
122
+ for (const [tableName, table] of Object.entries(tables)) {
123
+ const { columns } = z.object({ columns: z.record(z.any()) }).parse(table, { errorMap });
124
+ for (const [columnName, column] of Object.entries(columns)) {
125
+ column.schema.name = columnName;
126
+ column.schema.collection = tableName;
138
127
  }
139
128
  }
140
- return rawCollections;
141
- }, z.record(collectionSchema));
142
- function defineData(fn) {
143
- return fn;
144
- }
145
- const dbDataFn = z.function().returns(z.union([z.void(), z.promise(z.void())]));
129
+ return rawTables;
130
+ }, z.record(tableSchema));
146
131
  const dbConfigSchema = z.object({
147
- studio: z.boolean().optional(),
148
- tables: tablesSchema.optional(),
149
- data: z.union([dbDataFn, z.array(dbDataFn)]).optional(),
150
- unsafeWritable: z.boolean().optional().default(false)
151
- });
152
- const astroConfigWithDbSchema = z.object({
153
- db: dbConfigSchema.optional()
132
+ tables: tablesSchema.optional()
154
133
  });
155
- function baseDefineCollection(userConfig, writable) {
156
- return {
157
- ...userConfig,
158
- writable,
159
- // set at runtime to get the table name
160
- table: null
161
- };
162
- }
163
- function defineReadableTable(userConfig) {
164
- return baseDefineCollection(userConfig, false);
165
- }
166
- function defineWritableTable(userConfig) {
167
- return baseDefineCollection(userConfig, true);
168
- }
169
- function createColumn(type, schema) {
170
- return {
171
- type,
172
- /**
173
- * @internal
174
- */
175
- schema
176
- };
177
- }
178
- const column = {
179
- number: (opts = {}) => {
180
- return createColumn("number", opts);
181
- },
182
- boolean: (opts = {}) => {
183
- return createColumn("boolean", opts);
184
- },
185
- text: (opts = {}) => {
186
- return createColumn("text", opts);
187
- },
188
- date(opts = {}) {
189
- return createColumn("date", opts);
190
- },
191
- json(opts = {}) {
192
- return createColumn("json", opts);
193
- }
194
- };
195
134
  export {
196
- astroConfigWithDbSchema,
197
- collectionSchema,
198
- column,
199
135
  columnSchema,
200
136
  dbConfigSchema,
201
- defineData,
202
- defineReadableTable,
203
- defineWritableTable,
204
137
  indexSchema,
205
- readableCollectionSchema,
206
138
  referenceableColumnSchema,
207
- tablesSchema,
208
- writableCollectionSchema
139
+ tableSchema,
140
+ tablesSchema
209
141
  };
@@ -3,3 +3,5 @@ export type VitePlugin = Required<AstroConfig['vite']>['plugins'][number];
3
3
  export declare function getAstroStudioEnv(envMode?: string): Record<`ASTRO_STUDIO_${string}`, string>;
4
4
  export declare function getRemoteDatabaseUrl(): string;
5
5
  export declare function getAstroStudioUrl(): string;
6
+ export declare function getDbDirectoryUrl(root: URL | string): URL;
7
+ export declare function getMigrationsDirectoryUrl(root: URL | string): URL;
@@ -11,8 +11,16 @@ function getAstroStudioUrl() {
11
11
  const env = getAstroStudioEnv();
12
12
  return env.ASTRO_STUDIO_URL || "https://stardate.astro.build";
13
13
  }
14
+ function getDbDirectoryUrl(root) {
15
+ return new URL("db/", root);
16
+ }
17
+ function getMigrationsDirectoryUrl(root) {
18
+ return new URL("migrations/", getDbDirectoryUrl(root));
19
+ }
14
20
  export {
15
21
  getAstroStudioEnv,
16
22
  getAstroStudioUrl,
23
+ getDbDirectoryUrl,
24
+ getMigrationsDirectoryUrl,
17
25
  getRemoteDatabaseUrl
18
26
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export { defineReadableTable, defineWritableTable, defineData, column } from './core/types.js';
2
- export type { ResolvedCollectionConfig, DBDataContext } from './core/types.js';
1
+ export type { ResolvedCollectionConfig, TableConfig } from './core/types.js';
3
2
  export { cli } from './core/cli/index.js';
4
3
  export { integration as default } from './core/integration/index.js';
5
- export { sql, NOW, TRUE, FALSE } from './runtime/index.js';
4
+ export { sql, NOW, TRUE, FALSE, defineDB, defineTable, column } from './runtime/config.js';
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
- import { defineReadableTable, defineWritableTable, defineData, column } from "./core/types.js";
2
1
  import { cli } from "./core/cli/index.js";
3
2
  import { integration } from "./core/integration/index.js";
4
- import { sql, NOW, TRUE, FALSE } from "./runtime/index.js";
3
+ import { sql, NOW, TRUE, FALSE, defineDB, defineTable, column } from "./runtime/config.js";
5
4
  export {
6
5
  FALSE,
7
6
  NOW,
@@ -9,8 +8,7 @@ export {
9
8
  cli,
10
9
  column,
11
10
  integration as default,
12
- defineData,
13
- defineReadableTable,
14
- defineWritableTable,
11
+ defineDB,
12
+ defineTable,
15
13
  sql
16
14
  };
@@ -0,0 +1,138 @@
1
+ import type { ColumnsConfig, DBConfigInput, TableConfig } from '../core/types.js';
2
+ export declare const column: {
3
+ number: <T extends ({
4
+ name?: string | undefined;
5
+ label?: string | undefined;
6
+ unique?: boolean | undefined;
7
+ collection?: string | undefined;
8
+ } & ({
9
+ primaryKey?: false | undefined;
10
+ optional?: boolean | undefined;
11
+ default?: number | import("drizzle-orm").SQL<any> | undefined;
12
+ } | {
13
+ primaryKey: true;
14
+ optional?: false | undefined;
15
+ default?: undefined;
16
+ })) & {
17
+ references?: (() => {
18
+ type: "number";
19
+ schema: ({
20
+ name?: string | undefined;
21
+ label?: string | undefined;
22
+ unique?: boolean | undefined;
23
+ collection?: string | undefined;
24
+ } & {
25
+ primaryKey?: false | undefined;
26
+ optional?: boolean | undefined;
27
+ default?: number | import("drizzle-orm").SQL<any> | undefined;
28
+ } & any) | ({
29
+ name?: string | undefined;
30
+ label?: string | undefined;
31
+ unique?: boolean | undefined;
32
+ collection?: string | undefined;
33
+ } & {
34
+ primaryKey: true;
35
+ optional?: false | undefined;
36
+ default?: undefined;
37
+ } & any);
38
+ }) | undefined;
39
+ }>(opts?: T) => {
40
+ type: "number";
41
+ /**
42
+ * @internal
43
+ */
44
+ schema: T;
45
+ };
46
+ boolean: <T_1 extends {
47
+ name?: string | undefined;
48
+ label?: string | undefined;
49
+ optional?: boolean | undefined;
50
+ unique?: boolean | undefined;
51
+ collection?: string | undefined;
52
+ default?: boolean | import("drizzle-orm").SQL<any> | undefined;
53
+ }>(opts?: T_1) => {
54
+ type: "boolean";
55
+ /**
56
+ * @internal
57
+ */
58
+ schema: T_1;
59
+ };
60
+ text: <T_2 extends ({
61
+ name?: string | undefined;
62
+ label?: string | undefined;
63
+ unique?: boolean | undefined;
64
+ collection?: string | undefined;
65
+ default?: string | import("drizzle-orm").SQL<any> | undefined;
66
+ multiline?: boolean | undefined;
67
+ } & ({
68
+ primaryKey?: false | undefined;
69
+ optional?: boolean | undefined;
70
+ } | {
71
+ primaryKey: true;
72
+ optional?: false | undefined;
73
+ })) & {
74
+ references?: (() => {
75
+ type: "text";
76
+ schema: ({
77
+ name?: string | undefined;
78
+ label?: string | undefined;
79
+ unique?: boolean | undefined;
80
+ collection?: string | undefined;
81
+ default?: string | import("drizzle-orm").SQL<any> | undefined;
82
+ multiline?: boolean | undefined;
83
+ } & {
84
+ primaryKey?: false | undefined;
85
+ optional?: boolean | undefined;
86
+ } & any) | ({
87
+ name?: string | undefined;
88
+ label?: string | undefined;
89
+ unique?: boolean | undefined;
90
+ collection?: string | undefined;
91
+ default?: string | import("drizzle-orm").SQL<any> | undefined;
92
+ multiline?: boolean | undefined;
93
+ } & {
94
+ primaryKey: true;
95
+ optional?: false | undefined;
96
+ } & any);
97
+ }) | undefined;
98
+ }>(opts?: T_2) => {
99
+ type: "text";
100
+ /**
101
+ * @internal
102
+ */
103
+ schema: T_2;
104
+ };
105
+ date<T_3 extends {
106
+ name?: string | undefined;
107
+ label?: string | undefined;
108
+ optional?: boolean | undefined;
109
+ unique?: boolean | undefined;
110
+ collection?: string | undefined;
111
+ default?: Date | import("drizzle-orm").SQL<any> | undefined;
112
+ }>(opts?: T_3): {
113
+ type: "date";
114
+ /**
115
+ * @internal
116
+ */
117
+ schema: T_3;
118
+ };
119
+ json<T_4 extends {
120
+ name?: string | undefined;
121
+ label?: string | undefined;
122
+ optional?: boolean | undefined;
123
+ unique?: boolean | undefined;
124
+ collection?: string | undefined;
125
+ default?: unknown;
126
+ }>(opts?: T_4): {
127
+ type: "json";
128
+ /**
129
+ * @internal
130
+ */
131
+ schema: T_4;
132
+ };
133
+ };
134
+ export declare function defineTable<TColumns extends ColumnsConfig>(userConfig: TableConfig<TColumns>): TableConfig<TColumns>;
135
+ export declare function defineDB(userConfig: DBConfigInput): {
136
+ tables?: unknown;
137
+ };
138
+ export { sql, NOW, TRUE, FALSE } from './index.js';
@@ -0,0 +1,42 @@
1
+ function createColumn(type, schema) {
2
+ return {
3
+ type,
4
+ /**
5
+ * @internal
6
+ */
7
+ schema
8
+ };
9
+ }
10
+ const column = {
11
+ number: (opts = {}) => {
12
+ return createColumn("number", opts);
13
+ },
14
+ boolean: (opts = {}) => {
15
+ return createColumn("boolean", opts);
16
+ },
17
+ text: (opts = {}) => {
18
+ return createColumn("text", opts);
19
+ },
20
+ date(opts = {}) {
21
+ return createColumn("date", opts);
22
+ },
23
+ json(opts = {}) {
24
+ return createColumn("json", opts);
25
+ }
26
+ };
27
+ function defineTable(userConfig) {
28
+ return userConfig;
29
+ }
30
+ function defineDB(userConfig) {
31
+ return userConfig;
32
+ }
33
+ import { sql, NOW, TRUE, FALSE } from "./index.js";
34
+ export {
35
+ FALSE,
36
+ NOW,
37
+ TRUE,
38
+ column,
39
+ defineDB,
40
+ defineTable,
41
+ sql
42
+ };
@@ -1,12 +1,5 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { type DBTables } from '../core/types.js';
3
1
  import type { LibSQLDatabase } from 'drizzle-orm/libsql';
4
- interface LocalDatabaseClient extends LibSQLDatabase, Disposable {
5
- }
6
- export declare function createLocalDatabaseClient({ tables, dbUrl, seeding, }: {
2
+ export declare function createLocalDatabaseClient({ dbUrl }: {
7
3
  dbUrl: string;
8
- tables: DBTables;
9
- seeding: boolean;
10
- }): Promise<LocalDatabaseClient>;
4
+ }): LibSQLDatabase;
11
5
  export declare function createRemoteDatabaseClient(appToken: string, remoteDbURL: string): import("drizzle-orm/sqlite-proxy").SqliteRemoteDatabase<Record<string, never>>;
12
- export {};
@@ -1,53 +1,19 @@
1
1
  import { createClient } from "@libsql/client";
2
- import {} from "../core/types.js";
3
2
  import { drizzle as drizzleLibsql } from "drizzle-orm/libsql";
4
3
  import { drizzle as drizzleProxy } from "drizzle-orm/sqlite-proxy";
5
- import {} from "drizzle-orm/sqlite-core";
6
4
  import { z } from "zod";
7
- import { getTableName } from "drizzle-orm";
8
5
  const isWebContainer = !!process.versions?.webcontainer;
9
- async function createLocalDatabaseClient({
10
- tables,
11
- dbUrl,
12
- seeding
13
- }) {
6
+ function createLocalDatabaseClient({ dbUrl }) {
14
7
  const url = isWebContainer ? "file:content.db" : dbUrl;
15
- const client = createClient({ url });
16
- const db = Object.assign(drizzleLibsql(client), {
17
- [Symbol.dispose || Symbol.for("Symbol.dispose")]() {
18
- client.close();
19
- }
20
- });
21
- if (seeding)
22
- return db;
23
- const { insert: drizzleInsert, update: drizzleUpdate, delete: drizzleDelete } = db;
24
- return Object.assign(db, {
25
- insert(Table) {
26
- checkIfModificationIsAllowed(tables, Table);
27
- return drizzleInsert.call(this, Table);
28
- },
29
- update(Table) {
30
- checkIfModificationIsAllowed(tables, Table);
31
- return drizzleUpdate.call(this, Table);
32
- },
33
- delete(Table) {
34
- checkIfModificationIsAllowed(tables, Table);
35
- return drizzleDelete.call(this, Table);
36
- }
37
- });
38
- }
39
- function checkIfModificationIsAllowed(tables, Table) {
40
- const tableName = getTableName(Table);
41
- const collection = tables[tableName];
42
- if (!collection.writable) {
43
- throw new Error(`The [${tableName}] collection is read-only.`);
44
- }
8
+ console.log("memory", process.env.TEST_IN_MEMORY_DB);
9
+ const client = createClient({ url: process.env.TEST_IN_MEMORY_DB ? ":memory:" : url });
10
+ const db = drizzleLibsql(client);
11
+ return db;
45
12
  }
46
13
  function createRemoteDatabaseClient(appToken, remoteDbURL) {
47
14
  const url = new URL("/db/query", remoteDbURL);
48
15
  const db = drizzleProxy(async (sql, parameters, method) => {
49
16
  const requestBody = { sql, args: parameters };
50
- console.info(JSON.stringify(requestBody));
51
17
  const res = await fetch(url, {
52
18
  method: "POST",
53
19
  headers: {
@@ -88,6 +54,9 @@ Full error: Unexpected JSON response. ${e instanceof Error ? e.message : String(
88
54
  }
89
55
  return { rows: rowValues };
90
56
  });
57
+ db.batch = (_drizzleQueries) => {
58
+ throw new Error("db.batch() is not currently supported.");
59
+ };
91
60
  return db;
92
61
  }
93
62
  export {
@@ -1,15 +1,16 @@
1
- import type { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
2
- import { type DBTable, type DBColumn } from '../core/types.js';
3
1
  import { type ColumnDataType, sql } from 'drizzle-orm';
2
+ import type { LibSQLDatabase } from 'drizzle-orm/libsql';
3
+ import { type DBColumn, type DBTable } from '../core/types.js';
4
4
  export { sql };
5
- export type SqliteDB = SqliteRemoteDatabase;
5
+ export type SqliteDB = LibSQLDatabase;
6
6
  export type { Table } from './types.js';
7
7
  export { createRemoteDatabaseClient, createLocalDatabaseClient } from './db-client.js';
8
+ export { seedLocal } from './queries.js';
8
9
  export declare function hasPrimaryKey(column: DBColumn): boolean;
9
10
  export declare const NOW: import("drizzle-orm").SQL<unknown>;
10
11
  export declare const TRUE: import("drizzle-orm").SQL<unknown>;
11
12
  export declare const FALSE: import("drizzle-orm").SQL<unknown>;
12
- export declare function collectionToTable(name: string, collection: DBTable): import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
13
+ export declare function asDrizzleTable(name: string, table: DBTable): import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
13
14
  name: string;
14
15
  schema: undefined;
15
16
  columns: {
@@ -1,14 +1,15 @@
1
- import {} from "../core/types.js";
2
1
  import { sql } from "drizzle-orm";
3
2
  import {
4
3
  customType,
4
+ index,
5
5
  integer,
6
6
  sqliteTable,
7
- text,
8
- index
7
+ text
9
8
  } from "drizzle-orm/sqlite-core";
9
+ import {} from "../core/types.js";
10
10
  import { isSerializedSQL } from "./types.js";
11
11
  import { createRemoteDatabaseClient, createLocalDatabaseClient } from "./db-client.js";
12
+ import { seedLocal } from "./queries.js";
12
13
  function hasPrimaryKey(column) {
13
14
  return "primaryKey" in column.schema && !!column.schema.primaryKey;
14
15
  }
@@ -37,17 +38,17 @@ const jsonType = customType({
37
38
  return JSON.parse(value);
38
39
  }
39
40
  });
40
- function collectionToTable(name, collection) {
41
+ function asDrizzleTable(name, table) {
41
42
  const columns = {};
42
- if (!Object.entries(collection.columns).some(([, column]) => hasPrimaryKey(column))) {
43
+ if (!Object.entries(table.columns).some(([, column]) => hasPrimaryKey(column))) {
43
44
  columns["_id"] = integer("_id").primaryKey();
44
45
  }
45
- for (const [columnName, column] of Object.entries(collection.columns)) {
46
+ for (const [columnName, column] of Object.entries(table.columns)) {
46
47
  columns[columnName] = columnMapper(columnName, column);
47
48
  }
48
- const table = sqliteTable(name, columns, (ormTable) => {
49
+ const drizzleTable = sqliteTable(name, columns, (ormTable) => {
49
50
  const indexes = {};
50
- for (const [indexName, indexProps] of Object.entries(collection.indexes ?? {})) {
51
+ for (const [indexName, indexProps] of Object.entries(table.indexes ?? {})) {
51
52
  const onColNames = Array.isArray(indexProps.on) ? indexProps.on : [indexProps.on];
52
53
  const onCols = onColNames.map((colName) => ormTable[colName]);
53
54
  if (!atLeastOne(onCols))
@@ -56,7 +57,7 @@ function collectionToTable(name, collection) {
56
57
  }
57
58
  return indexes;
58
59
  });
59
- return table;
60
+ return drizzleTable;
60
61
  }
61
62
  function atLeastOne(arr) {
62
63
  return arr.length > 0;
@@ -116,9 +117,10 @@ export {
116
117
  FALSE,
117
118
  NOW,
118
119
  TRUE,
119
- collectionToTable,
120
+ asDrizzleTable,
120
121
  createLocalDatabaseClient,
121
122
  createRemoteDatabaseClient,
122
123
  hasPrimaryKey,
124
+ seedLocal,
123
125
  sql
124
126
  };
@@ -1,20 +1,18 @@
1
- import type { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
2
- import { type BooleanColumn, type DBTable, type DBTables, type DBColumn, type DateColumn, type ColumnType, type JsonColumn, type NumberColumn, type TextColumn } from '../core/types.js';
3
- import type { AstroIntegrationLogger } from 'astro';
4
- import type { DBUserConfig } from '../core/types.js';
5
- export declare function recreateTables({ db, tables, }: {
6
- db: SqliteRemoteDatabase;
1
+ import type { BooleanColumn, ColumnType, DBColumn, DBTable, DBTables, DateColumn, JsonColumn, NumberColumn, TextColumn } from '../core/types.js';
2
+ import { type SqliteDB } from './index.js';
3
+ export declare const SEED_DEV_FILE_NAME: string[];
4
+ export declare function seedLocal({ db, tables, fileGlob, }: {
5
+ db: SqliteDB;
7
6
  tables: DBTables;
7
+ fileGlob: Record<string, () => Promise<void>>;
8
8
  }): Promise<void>;
9
- export declare function seedData({ db, data, logger, mode, }: {
10
- db: SqliteRemoteDatabase;
11
- data: DBUserConfig['data'];
12
- logger?: AstroIntegrationLogger;
13
- mode: 'dev' | 'build';
9
+ export declare function recreateTables({ db, tables }: {
10
+ db: SqliteDB;
11
+ tables: DBTables;
14
12
  }): Promise<void>;
15
- export declare function getCreateTableQuery(collectionName: string, collection: DBTable): string;
16
- export declare function getCreateIndexQueries(collectionName: string, collection: Pick<DBTable, 'indexes'>): string[];
17
- export declare function getCreateForeignKeyQueries(collectionName: string, collection: DBTable): string[];
13
+ export declare function getCreateTableQuery(tableName: string, table: DBTable): string;
14
+ export declare function getCreateIndexQueries(tableName: string, table: Pick<DBTable, 'indexes'>): string[];
15
+ export declare function getCreateForeignKeyQueries(tableName: string, table: DBTable): string[];
18
16
  export declare function schemaTypeToSqlType(type: ColumnType): 'text' | 'integer';
19
17
  export declare function getModifiers(columnName: string, column: DBColumn): string;
20
18
  export declare function getReferencesConfig(column: DBColumn): {
@@ -27,7 +25,7 @@ export declare function getReferencesConfig(column: DBColumn): {
27
25
  } & {
28
26
  optional: boolean;
29
27
  primaryKey: false;
30
- default?: number | import("../runtime/types.js").SerializedSQL | undefined;
28
+ default?: number | import("./types.js").SerializedSQL | undefined;
31
29
  } & {
32
30
  references?: any | undefined;
33
31
  }) | ({
@@ -49,7 +47,7 @@ export declare function getReferencesConfig(column: DBColumn): {
49
47
  name?: string | undefined;
50
48
  label?: string | undefined;
51
49
  collection?: string | undefined;
52
- default?: string | import("../runtime/types.js").SerializedSQL | undefined;
50
+ default?: string | import("./types.js").SerializedSQL | undefined;
53
51
  multiline?: boolean | undefined;
54
52
  } & {
55
53
  optional: boolean;
@@ -61,7 +59,7 @@ export declare function getReferencesConfig(column: DBColumn): {
61
59
  name?: string | undefined;
62
60
  label?: string | undefined;
63
61
  collection?: string | undefined;
64
- default?: string | import("../runtime/types.js").SerializedSQL | undefined;
62
+ default?: string | import("./types.js").SerializedSQL | undefined;
65
63
  multiline?: boolean | undefined;
66
64
  } & {
67
65
  primaryKey: true;