@astrojs/db 0.1.16 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import type { SQLiteInsertValue } from 'drizzle-orm/sqlite-core';
2
2
  import type { SqliteDB, Table } from './internal.js';
3
3
  import type { MaybeArray, collectionSchema } from './types.js';
4
- import { type BooleanField, type DBFieldInput, type DateFieldInput, type JsonField, type NumberField, type TextField, type MaybePromise } from './types.js';
4
+ import { type BooleanField, type DBFieldInput, type DateFieldInput, type JsonField, type NumberField, type TextField, type indexSchema, type MaybePromise } from './types.js';
5
5
  import { z } from 'zod';
6
- export type DBFieldsConfig = z.input<typeof collectionSchema>['fields'];
7
6
  export type DBDataContext = {
8
7
  db: SqliteDB;
9
- seed<TFields extends DBFieldsConfig>(collection: ResolvedCollectionConfig<TFields>, data: MaybeArray<SQLiteInsertValue<Table<string,
10
- /** TODO: true type inference */ Record<Extract<keyof TFields, string>, DBFieldsConfig[number]>>>>): Promise<any> /** TODO: type output */;
8
+ seed<TFields extends FieldsConfig>(collection: ResolvedCollectionConfig<TFields>, data: MaybeArray<SQLiteInsertValue<Table<string,
9
+ /** TODO: true type inference */ Record<Extract<keyof TFields, string>, FieldsConfig[number]>>>>): Promise<any> /** TODO: type output */;
11
10
  mode: 'dev' | 'build';
12
11
  };
13
12
  export declare const dbConfigSchema: z.ZodObject<{
@@ -113,9 +112,19 @@ export declare const dbConfigSchema: z.ZodObject<{
113
112
  unique?: boolean | undefined;
114
113
  default?: unknown;
115
114
  }>]>>;
116
- writable: z.ZodLiteral<false>;
115
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
116
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
117
+ unique: z.ZodOptional<z.ZodBoolean>;
118
+ }, "strip", z.ZodTypeAny, {
119
+ on: (string | string[]) & (string | string[] | undefined);
120
+ unique?: boolean | undefined;
121
+ }, {
122
+ on: (string | string[]) & (string | string[] | undefined);
123
+ unique?: boolean | undefined;
124
+ }>>>;
117
125
  table: z.ZodAny;
118
126
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
127
+ writable: z.ZodLiteral<false>;
119
128
  }, "strip", z.ZodTypeAny, {
120
129
  fields: Record<string, {
121
130
  type: "boolean";
@@ -152,6 +161,10 @@ export declare const dbConfigSchema: z.ZodObject<{
152
161
  default?: unknown;
153
162
  }>;
154
163
  writable: false;
164
+ indexes?: Record<string, {
165
+ on: (string | string[]) & (string | string[] | undefined);
166
+ unique?: boolean | undefined;
167
+ }> | undefined;
155
168
  table?: any;
156
169
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
157
170
  }, {
@@ -190,6 +203,10 @@ export declare const dbConfigSchema: z.ZodObject<{
190
203
  default?: unknown;
191
204
  }>;
192
205
  writable: false;
206
+ indexes?: Record<string, {
207
+ on: (string | string[]) & (string | string[] | undefined);
208
+ unique?: boolean | undefined;
209
+ }> | undefined;
193
210
  table?: any;
194
211
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
195
212
  }>, z.ZodObject<{
@@ -293,9 +310,19 @@ export declare const dbConfigSchema: z.ZodObject<{
293
310
  unique?: boolean | undefined;
294
311
  default?: unknown;
295
312
  }>]>>;
296
- writable: z.ZodLiteral<true>;
313
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
314
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
315
+ unique: z.ZodOptional<z.ZodBoolean>;
316
+ }, "strip", z.ZodTypeAny, {
317
+ on: (string | string[]) & (string | string[] | undefined);
318
+ unique?: boolean | undefined;
319
+ }, {
320
+ on: (string | string[]) & (string | string[] | undefined);
321
+ unique?: boolean | undefined;
322
+ }>>>;
297
323
  table: z.ZodAny;
298
324
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
325
+ writable: z.ZodLiteral<true>;
299
326
  }, "strip", z.ZodTypeAny, {
300
327
  fields: Record<string, {
301
328
  type: "boolean";
@@ -332,6 +359,10 @@ export declare const dbConfigSchema: z.ZodObject<{
332
359
  default?: unknown;
333
360
  }>;
334
361
  writable: true;
362
+ indexes?: Record<string, {
363
+ on: (string | string[]) & (string | string[] | undefined);
364
+ unique?: boolean | undefined;
365
+ }> | undefined;
335
366
  table?: any;
336
367
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
337
368
  }, {
@@ -370,6 +401,10 @@ export declare const dbConfigSchema: z.ZodObject<{
370
401
  default?: unknown;
371
402
  }>;
372
403
  writable: true;
404
+ indexes?: Record<string, {
405
+ on: (string | string[]) & (string | string[] | undefined);
406
+ unique?: boolean | undefined;
407
+ }> | undefined;
373
408
  table?: any;
374
409
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
375
410
  }>]>>>;
@@ -412,6 +447,10 @@ export declare const dbConfigSchema: z.ZodObject<{
412
447
  default?: unknown;
413
448
  }>;
414
449
  writable: false;
450
+ indexes?: Record<string, {
451
+ on: (string | string[]) & (string | string[] | undefined);
452
+ unique?: boolean | undefined;
453
+ }> | undefined;
415
454
  table?: any;
416
455
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
417
456
  } | {
@@ -450,6 +489,10 @@ export declare const dbConfigSchema: z.ZodObject<{
450
489
  default?: unknown;
451
490
  }>;
452
491
  writable: true;
492
+ indexes?: Record<string, {
493
+ on: (string | string[]) & (string | string[] | undefined);
494
+ unique?: boolean | undefined;
495
+ }> | undefined;
453
496
  table?: any;
454
497
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
455
498
  }> | undefined;
@@ -492,6 +535,10 @@ export declare const dbConfigSchema: z.ZodObject<{
492
535
  default?: unknown;
493
536
  }>;
494
537
  writable: false;
538
+ indexes?: Record<string, {
539
+ on: (string | string[]) & (string | string[] | undefined);
540
+ unique?: boolean | undefined;
541
+ }> | undefined;
495
542
  table?: any;
496
543
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
497
544
  } | {
@@ -530,6 +577,10 @@ export declare const dbConfigSchema: z.ZodObject<{
530
577
  default?: unknown;
531
578
  }>;
532
579
  writable: true;
580
+ indexes?: Record<string, {
581
+ on: (string | string[]) & (string | string[] | undefined);
582
+ unique?: boolean | undefined;
583
+ }> | undefined;
533
584
  table?: any;
534
585
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
535
586
  }> | undefined;
@@ -642,9 +693,19 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
642
693
  unique?: boolean | undefined;
643
694
  default?: unknown;
644
695
  }>]>>;
645
- writable: z.ZodLiteral<false>;
696
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
697
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
698
+ unique: z.ZodOptional<z.ZodBoolean>;
699
+ }, "strip", z.ZodTypeAny, {
700
+ on: (string | string[]) & (string | string[] | undefined);
701
+ unique?: boolean | undefined;
702
+ }, {
703
+ on: (string | string[]) & (string | string[] | undefined);
704
+ unique?: boolean | undefined;
705
+ }>>>;
646
706
  table: z.ZodAny;
647
707
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
708
+ writable: z.ZodLiteral<false>;
648
709
  }, "strip", z.ZodTypeAny, {
649
710
  fields: Record<string, {
650
711
  type: "boolean";
@@ -681,6 +742,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
681
742
  default?: unknown;
682
743
  }>;
683
744
  writable: false;
745
+ indexes?: Record<string, {
746
+ on: (string | string[]) & (string | string[] | undefined);
747
+ unique?: boolean | undefined;
748
+ }> | undefined;
684
749
  table?: any;
685
750
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
686
751
  }, {
@@ -719,6 +784,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
719
784
  default?: unknown;
720
785
  }>;
721
786
  writable: false;
787
+ indexes?: Record<string, {
788
+ on: (string | string[]) & (string | string[] | undefined);
789
+ unique?: boolean | undefined;
790
+ }> | undefined;
722
791
  table?: any;
723
792
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
724
793
  }>, z.ZodObject<{
@@ -822,9 +891,19 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
822
891
  unique?: boolean | undefined;
823
892
  default?: unknown;
824
893
  }>]>>;
825
- writable: z.ZodLiteral<true>;
894
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
895
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
896
+ unique: z.ZodOptional<z.ZodBoolean>;
897
+ }, "strip", z.ZodTypeAny, {
898
+ on: (string | string[]) & (string | string[] | undefined);
899
+ unique?: boolean | undefined;
900
+ }, {
901
+ on: (string | string[]) & (string | string[] | undefined);
902
+ unique?: boolean | undefined;
903
+ }>>>;
826
904
  table: z.ZodAny;
827
905
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
906
+ writable: z.ZodLiteral<true>;
828
907
  }, "strip", z.ZodTypeAny, {
829
908
  fields: Record<string, {
830
909
  type: "boolean";
@@ -861,6 +940,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
861
940
  default?: unknown;
862
941
  }>;
863
942
  writable: true;
943
+ indexes?: Record<string, {
944
+ on: (string | string[]) & (string | string[] | undefined);
945
+ unique?: boolean | undefined;
946
+ }> | undefined;
864
947
  table?: any;
865
948
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
866
949
  }, {
@@ -899,6 +982,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
899
982
  default?: unknown;
900
983
  }>;
901
984
  writable: true;
985
+ indexes?: Record<string, {
986
+ on: (string | string[]) & (string | string[] | undefined);
987
+ unique?: boolean | undefined;
988
+ }> | undefined;
902
989
  table?: any;
903
990
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
904
991
  }>]>>>;
@@ -941,6 +1028,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
941
1028
  default?: unknown;
942
1029
  }>;
943
1030
  writable: false;
1031
+ indexes?: Record<string, {
1032
+ on: (string | string[]) & (string | string[] | undefined);
1033
+ unique?: boolean | undefined;
1034
+ }> | undefined;
944
1035
  table?: any;
945
1036
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
946
1037
  } | {
@@ -979,6 +1070,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
979
1070
  default?: unknown;
980
1071
  }>;
981
1072
  writable: true;
1073
+ indexes?: Record<string, {
1074
+ on: (string | string[]) & (string | string[] | undefined);
1075
+ unique?: boolean | undefined;
1076
+ }> | undefined;
982
1077
  table?: any;
983
1078
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
984
1079
  }> | undefined;
@@ -1021,6 +1116,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1021
1116
  default?: unknown;
1022
1117
  }>;
1023
1118
  writable: false;
1119
+ indexes?: Record<string, {
1120
+ on: (string | string[]) & (string | string[] | undefined);
1121
+ unique?: boolean | undefined;
1122
+ }> | undefined;
1024
1123
  table?: any;
1025
1124
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1026
1125
  } | {
@@ -1059,6 +1158,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1059
1158
  default?: unknown;
1060
1159
  }>;
1061
1160
  writable: true;
1161
+ indexes?: Record<string, {
1162
+ on: (string | string[]) & (string | string[] | undefined);
1163
+ unique?: boolean | undefined;
1164
+ }> | undefined;
1062
1165
  table?: any;
1063
1166
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1064
1167
  }> | undefined;
@@ -1103,6 +1206,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1103
1206
  default?: unknown;
1104
1207
  }>;
1105
1208
  writable: false;
1209
+ indexes?: Record<string, {
1210
+ on: (string | string[]) & (string | string[] | undefined);
1211
+ unique?: boolean | undefined;
1212
+ }> | undefined;
1106
1213
  table?: any;
1107
1214
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1108
1215
  } | {
@@ -1141,6 +1248,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1141
1248
  default?: unknown;
1142
1249
  }>;
1143
1250
  writable: true;
1251
+ indexes?: Record<string, {
1252
+ on: (string | string[]) & (string | string[] | undefined);
1253
+ unique?: boolean | undefined;
1254
+ }> | undefined;
1144
1255
  table?: any;
1145
1256
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1146
1257
  }> | undefined;
@@ -1185,6 +1296,10 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1185
1296
  default?: unknown;
1186
1297
  }>;
1187
1298
  writable: false;
1299
+ indexes?: Record<string, {
1300
+ on: (string | string[]) & (string | string[] | undefined);
1301
+ unique?: boolean | undefined;
1302
+ }> | undefined;
1188
1303
  table?: any;
1189
1304
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1190
1305
  } | {
@@ -1223,21 +1338,30 @@ export declare const astroConfigWithDbSchema: z.ZodObject<{
1223
1338
  default?: unknown;
1224
1339
  }>;
1225
1340
  writable: true;
1341
+ indexes?: Record<string, {
1342
+ on: (string | string[]) & (string | string[] | undefined);
1343
+ unique?: boolean | undefined;
1344
+ }> | undefined;
1226
1345
  table?: any;
1227
1346
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1228
1347
  }> | undefined;
1229
1348
  data?: ((...args: unknown[]) => void | Promise<void>) | undefined;
1230
1349
  } | undefined;
1231
1350
  }>;
1232
- type CollectionConfig<TFields extends DBFieldsConfig> = {
1351
+ export type FieldsConfig = z.input<typeof collectionSchema>['fields'];
1352
+ interface CollectionConfig<TFields extends FieldsConfig> extends Pick<z.input<typeof collectionSchema>, 'fields' | 'indexes'> {
1233
1353
  fields: TFields;
1234
- };
1235
- export type ResolvedCollectionConfig<TFields extends DBFieldsConfig = DBFieldsConfig, Writable extends boolean = boolean> = CollectionConfig<TFields> & {
1354
+ indexes?: Record<string, IndexConfig<TFields>>;
1355
+ }
1356
+ interface IndexConfig<TFields extends FieldsConfig> extends z.input<typeof indexSchema> {
1357
+ on: MaybeArray<Extract<keyof TFields, string>>;
1358
+ }
1359
+ export type ResolvedCollectionConfig<TFields extends FieldsConfig = FieldsConfig, Writable extends boolean = boolean> = CollectionConfig<TFields> & {
1236
1360
  writable: Writable;
1237
1361
  table: Table<string, TFields>;
1238
1362
  };
1239
- export declare function defineCollection<TFields extends DBFieldsConfig>(userConfig: CollectionConfig<TFields>): ResolvedCollectionConfig<TFields, false>;
1240
- export declare function defineWritableCollection<TFields extends DBFieldsConfig>(userConfig: CollectionConfig<TFields>): ResolvedCollectionConfig<TFields, true>;
1363
+ export declare function defineCollection<TFields extends FieldsConfig>(userConfig: CollectionConfig<TFields>): ResolvedCollectionConfig<TFields, false>;
1364
+ export declare function defineWritableCollection<TFields extends FieldsConfig>(userConfig: CollectionConfig<TFields>): ResolvedCollectionConfig<TFields, true>;
1241
1365
  export type AstroConfigWithDB = z.infer<typeof astroConfigWithDbSchema>;
1242
1366
  type FieldOpts<T extends DBFieldInput> = Omit<T, 'type'>;
1243
1367
  export declare const field: {
@@ -0,0 +1,2 @@
1
+ import type { AstroIntegration } from 'astro';
2
+ export declare function fileURLIntegration(): AstroIntegration;
@@ -0,0 +1,71 @@
1
+ import fs from "node:fs";
2
+ import { pathToFileURL } from "node:url";
3
+ import path from "node:path";
4
+ async function copyFile(toDir, fromUrl, toUrl) {
5
+ await fs.promises.mkdir(toDir, { recursive: true });
6
+ await fs.promises.rename(fromUrl, toUrl);
7
+ }
8
+ function fileURLIntegration() {
9
+ const fileNames = [];
10
+ function createVitePlugin(command) {
11
+ const referenceIds = [];
12
+ return {
13
+ name: "@astrojs/db/file-url",
14
+ enforce: "pre",
15
+ async load(id) {
16
+ if (id.endsWith("?fileurl")) {
17
+ const filePath = id.slice(0, id.indexOf("?"));
18
+ if (command === "build") {
19
+ const data = await fs.promises.readFile(filePath);
20
+ const name = path.basename(filePath);
21
+ const referenceId = this.emitFile({
22
+ name,
23
+ source: data,
24
+ type: "asset"
25
+ });
26
+ referenceIds.push(referenceId);
27
+ return `export default import.meta.ROLLUP_FILE_URL_${referenceId};`;
28
+ } else {
29
+ return `export default new URL(${JSON.stringify(pathToFileURL(filePath).toString())})`;
30
+ }
31
+ }
32
+ },
33
+ generateBundle() {
34
+ for (const referenceId of referenceIds) {
35
+ fileNames.push(this.getFileName(referenceId));
36
+ }
37
+ }
38
+ };
39
+ }
40
+ let config;
41
+ return {
42
+ name: "@astrojs/db/file-url",
43
+ hooks: {
44
+ "astro:config:setup"({ updateConfig, command }) {
45
+ updateConfig({
46
+ vite: {
47
+ plugins: [createVitePlugin(command)]
48
+ }
49
+ });
50
+ },
51
+ "astro:config:done": ({ config: _config }) => {
52
+ config = _config;
53
+ },
54
+ async "astro:build:done"() {
55
+ if (config.output !== "static") {
56
+ const moves = [];
57
+ for (const fileName of fileNames) {
58
+ const fromUrl = new URL(fileName, config.build.client);
59
+ const toUrl = new URL(fileName, config.build.server);
60
+ const toDir = new URL("./", toUrl);
61
+ moves.push(copyFile(toDir, fromUrl, toUrl));
62
+ }
63
+ await Promise.all(moves);
64
+ }
65
+ }
66
+ }
67
+ };
68
+ }
69
+ export {
70
+ fileURLIntegration
71
+ };
@@ -1,2 +1,2 @@
1
1
  import type { AstroIntegration } from 'astro';
2
- export declare function integration(): AstroIntegration;
2
+ export declare function integration(): AstroIntegration[];
@@ -12,7 +12,8 @@ import { errorMap } from "./error-map.js";
12
12
  import { dirname } from "path";
13
13
  import { fileURLToPath } from "url";
14
14
  import { bold } from "kleur/colors";
15
- function integration() {
15
+ import { fileURLIntegration } from "./file-url-integration.js";
16
+ function astroDBIntegration() {
16
17
  return {
17
18
  name: "astro:db",
18
19
  hooks: {
@@ -39,7 +40,8 @@ function integration() {
39
40
  dbPlugin = vitePluginDb({
40
41
  connectToStudio: true,
41
42
  collections,
42
- appToken
43
+ appToken,
44
+ output: config.output
43
45
  });
44
46
  } else {
45
47
  const dbUrl = getLocalDbUrl(config.root);
@@ -61,12 +63,25 @@ function integration() {
61
63
  mode: command === "dev" ? "dev" : "build"
62
64
  });
63
65
  logger.info("Collections set up \u{1F680}");
64
- dbPlugin = vitePluginDb({ connectToStudio: false, collections, dbUrl: dbUrl.href });
66
+ dbPlugin = vitePluginDb({
67
+ connectToStudio: false,
68
+ collections
69
+ });
65
70
  }
66
71
  updateConfig({
67
72
  vite: {
68
73
  assetsInclude: [DB_PATH],
69
- plugins: [dbPlugin, vitePluginInjectEnvTs(config)]
74
+ plugins: [dbPlugin, vitePluginInjectEnvTs(config), {
75
+ name: "my-plugin",
76
+ resolveId(id) {
77
+ if (id.endsWith("?server-path")) {
78
+ }
79
+ },
80
+ load(id) {
81
+ if (id.endsWith("?server-path")) {
82
+ }
83
+ }
84
+ }]
70
85
  }
71
86
  });
72
87
  await typegen({ collections, root: config.root });
@@ -74,6 +89,9 @@ function integration() {
74
89
  }
75
90
  };
76
91
  }
92
+ function integration() {
93
+ return [astroDBIntegration(), fileURLIntegration()];
94
+ }
77
95
  export {
78
96
  integration
79
97
  };
@@ -1,18 +1,17 @@
1
1
  import type { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
2
2
  import { type BooleanField, type DBCollection, type DBCollections, type DBField, type DateField, type FieldType, type JsonField, type NumberField, type TextField } from './types.js';
3
- import { type LibSQLDatabase } from 'drizzle-orm/libsql';
4
- import { type ColumnDataType } from 'drizzle-orm';
3
+ import { type SQL, type ColumnDataType } from 'drizzle-orm';
5
4
  import type { AstroIntegrationLogger } from 'astro';
6
5
  import type { DBUserConfig } from './config.js';
7
6
  export type SqliteDB = SqliteRemoteDatabase;
8
7
  export type { Table } from './types.js';
9
- export { createRemoteDatabaseClient, findLocalDatabase } from './utils-runtime.js';
8
+ export { createRemoteDatabaseClient } from './utils-runtime.js';
10
9
  export declare function hasPrimaryKey(field: DBField): boolean;
11
10
  export declare function createLocalDatabaseClient({ collections, dbUrl, seeding, }: {
12
11
  dbUrl: string;
13
12
  collections: DBCollections;
14
13
  seeding: boolean;
15
- }): Promise<LibSQLDatabase<Record<string, never>>>;
14
+ }): Promise<import("drizzle-orm/libsql").LibSQLDatabase<Record<string, never>>>;
16
15
  export declare function setupDbTables({ db, data, collections, logger, mode, }: {
17
16
  db: SqliteRemoteDatabase;
18
17
  data?: DBUserConfig['data'];
@@ -21,6 +20,7 @@ export declare function setupDbTables({ db, data, collections, logger, mode, }:
21
20
  mode: 'dev' | 'build';
22
21
  }): Promise<void>;
23
22
  export declare function getCreateTableQuery(collectionName: string, collection: DBCollection): string;
23
+ export declare function getTableIndexQueries(collectionName: string, collection: DBCollection): SQL<unknown>[];
24
24
  export declare function schemaTypeToSqlType(type: FieldType): 'text' | 'integer';
25
25
  export declare function getModifiers(fieldName: string, field: DBField): string;
26
26
  type WithDefaultDefined<T extends DBField> = T & Required<Pick<T, 'default'>>;
package/dist/internal.js CHANGED
@@ -12,10 +12,11 @@ import {
12
12
  customType,
13
13
  integer,
14
14
  sqliteTable,
15
- text
15
+ text,
16
+ index
16
17
  } from "drizzle-orm/sqlite-core";
17
18
  import { z } from "zod";
18
- import { createRemoteDatabaseClient, findLocalDatabase } from "./utils-runtime.js";
19
+ import { createRemoteDatabaseClient } from "./utils-runtime.js";
19
20
  const sqlite = new SQLiteAsyncDialect();
20
21
  function hasPrimaryKey(field) {
21
22
  return "primaryKey" in field && !!field.primaryKey;
@@ -63,7 +64,8 @@ async function setupDbTables({
63
64
  for (const [name, collection] of Object.entries(collections)) {
64
65
  const dropQuery = sql.raw(`DROP TABLE IF EXISTS ${name}`);
65
66
  const createQuery = sql.raw(getCreateTableQuery(name, collection));
66
- setupQueries.push(dropQuery, createQuery);
67
+ const indexQueries = getTableIndexQueries(name, collection);
68
+ setupQueries.push(dropQuery, createQuery, ...indexQueries);
67
69
  }
68
70
  for (const q of setupQueries) {
69
71
  await db.run(q);
@@ -112,6 +114,21 @@ function getCreateTableQuery(collectionName, collection) {
112
114
  query += colQueries.join(", ") + ")";
113
115
  return query;
114
116
  }
117
+ function getTableIndexQueries(collectionName, collection) {
118
+ let queries = [];
119
+ for (const [indexName, indexProps] of Object.entries(collection.indexes ?? {})) {
120
+ const onColNames = Array.isArray(indexProps.on) ? indexProps.on : [indexProps.on];
121
+ const onCols = onColNames.map((colName) => sqlite.escapeName(colName));
122
+ const unique = indexProps.unique ? "UNIQUE " : "";
123
+ const indexQuery = sql.raw(
124
+ `CREATE ${unique}INDEX ${sqlite.escapeName(indexName)} ON ${sqlite.escapeName(
125
+ collectionName
126
+ )} (${onCols.join(", ")})`
127
+ );
128
+ queries.push(indexQuery);
129
+ }
130
+ return queries;
131
+ }
115
132
  function schemaTypeToSqlType(type) {
116
133
  switch (type) {
117
134
  case "date":
@@ -204,9 +221,22 @@ function collectionToTable(name, collection, isJsonSerializable = true) {
204
221
  for (const [fieldName, field] of Object.entries(collection.fields)) {
205
222
  columns[fieldName] = columnMapper(fieldName, field, isJsonSerializable);
206
223
  }
207
- const table = sqliteTable(name, columns);
224
+ const table = sqliteTable(name, columns, (ormTable) => {
225
+ const indexes = {};
226
+ for (const [indexName, indexProps] of Object.entries(collection.indexes ?? {})) {
227
+ const onColNames = Array.isArray(indexProps.on) ? indexProps.on : [indexProps.on];
228
+ const onCols = onColNames.map((colName) => ormTable[colName]);
229
+ if (!atLeastOne(onCols))
230
+ continue;
231
+ indexes[indexName] = index(indexName).on(...onCols);
232
+ }
233
+ return indexes;
234
+ });
208
235
  return table;
209
236
  }
237
+ function atLeastOne(arr) {
238
+ return arr.length > 0;
239
+ }
210
240
  function columnMapper(fieldName, field, isJsonSerializable) {
211
241
  let c;
212
242
  switch (field.type) {
@@ -268,9 +298,9 @@ export {
268
298
  collectionToTable,
269
299
  createLocalDatabaseClient,
270
300
  createRemoteDatabaseClient,
271
- findLocalDatabase,
272
301
  getCreateTableQuery,
273
302
  getModifiers,
303
+ getTableIndexQueries,
274
304
  hasDefault,
275
305
  hasPrimaryKey,
276
306
  schemaTypeToSqlType,
package/dist/root.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { AstroConfig } from 'astro';
2
+ export declare function findRoot(): URL;
3
+ export declare function findLocalDatabase(localDbURL: string, output: AstroConfig['output']): string;
package/dist/types.d.ts CHANGED
@@ -305,6 +305,16 @@ declare const fieldsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
305
305
  unique?: boolean | undefined;
306
306
  default?: unknown;
307
307
  }>]>>;
308
+ export declare const indexSchema: z.ZodObject<{
309
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
310
+ unique: z.ZodOptional<z.ZodBoolean>;
311
+ }, "strip", z.ZodTypeAny, {
312
+ on: (string | string[]) & (string | string[] | undefined);
313
+ unique?: boolean | undefined;
314
+ }, {
315
+ on: (string | string[]) & (string | string[] | undefined);
316
+ unique?: boolean | undefined;
317
+ }>;
308
318
  export declare const readableCollectionSchema: z.ZodObject<{
309
319
  fields: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
310
320
  label: z.ZodOptional<z.ZodString>;
@@ -406,9 +416,19 @@ export declare const readableCollectionSchema: z.ZodObject<{
406
416
  unique?: boolean | undefined;
407
417
  default?: unknown;
408
418
  }>]>>;
409
- writable: z.ZodLiteral<false>;
419
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
420
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
421
+ unique: z.ZodOptional<z.ZodBoolean>;
422
+ }, "strip", z.ZodTypeAny, {
423
+ on: (string | string[]) & (string | string[] | undefined);
424
+ unique?: boolean | undefined;
425
+ }, {
426
+ on: (string | string[]) & (string | string[] | undefined);
427
+ unique?: boolean | undefined;
428
+ }>>>;
410
429
  table: z.ZodAny;
411
430
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
431
+ writable: z.ZodLiteral<false>;
412
432
  }, "strip", z.ZodTypeAny, {
413
433
  fields: Record<string, {
414
434
  type: "boolean";
@@ -445,6 +465,10 @@ export declare const readableCollectionSchema: z.ZodObject<{
445
465
  default?: unknown;
446
466
  }>;
447
467
  writable: false;
468
+ indexes?: Record<string, {
469
+ on: (string | string[]) & (string | string[] | undefined);
470
+ unique?: boolean | undefined;
471
+ }> | undefined;
448
472
  table?: any;
449
473
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
450
474
  }, {
@@ -483,6 +507,10 @@ export declare const readableCollectionSchema: z.ZodObject<{
483
507
  default?: unknown;
484
508
  }>;
485
509
  writable: false;
510
+ indexes?: Record<string, {
511
+ on: (string | string[]) & (string | string[] | undefined);
512
+ unique?: boolean | undefined;
513
+ }> | undefined;
486
514
  table?: any;
487
515
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
488
516
  }>;
@@ -587,9 +615,19 @@ export declare const writableCollectionSchema: z.ZodObject<{
587
615
  unique?: boolean | undefined;
588
616
  default?: unknown;
589
617
  }>]>>;
590
- writable: z.ZodLiteral<true>;
618
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
619
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
620
+ unique: z.ZodOptional<z.ZodBoolean>;
621
+ }, "strip", z.ZodTypeAny, {
622
+ on: (string | string[]) & (string | string[] | undefined);
623
+ unique?: boolean | undefined;
624
+ }, {
625
+ on: (string | string[]) & (string | string[] | undefined);
626
+ unique?: boolean | undefined;
627
+ }>>>;
591
628
  table: z.ZodAny;
592
629
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
630
+ writable: z.ZodLiteral<true>;
593
631
  }, "strip", z.ZodTypeAny, {
594
632
  fields: Record<string, {
595
633
  type: "boolean";
@@ -626,6 +664,10 @@ export declare const writableCollectionSchema: z.ZodObject<{
626
664
  default?: unknown;
627
665
  }>;
628
666
  writable: true;
667
+ indexes?: Record<string, {
668
+ on: (string | string[]) & (string | string[] | undefined);
669
+ unique?: boolean | undefined;
670
+ }> | undefined;
629
671
  table?: any;
630
672
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
631
673
  }, {
@@ -664,6 +706,10 @@ export declare const writableCollectionSchema: z.ZodObject<{
664
706
  default?: unknown;
665
707
  }>;
666
708
  writable: true;
709
+ indexes?: Record<string, {
710
+ on: (string | string[]) & (string | string[] | undefined);
711
+ unique?: boolean | undefined;
712
+ }> | undefined;
667
713
  table?: any;
668
714
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
669
715
  }>;
@@ -768,9 +814,19 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
768
814
  unique?: boolean | undefined;
769
815
  default?: unknown;
770
816
  }>]>>;
771
- writable: z.ZodLiteral<false>;
817
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
818
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
819
+ unique: z.ZodOptional<z.ZodBoolean>;
820
+ }, "strip", z.ZodTypeAny, {
821
+ on: (string | string[]) & (string | string[] | undefined);
822
+ unique?: boolean | undefined;
823
+ }, {
824
+ on: (string | string[]) & (string | string[] | undefined);
825
+ unique?: boolean | undefined;
826
+ }>>>;
772
827
  table: z.ZodAny;
773
828
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
829
+ writable: z.ZodLiteral<false>;
774
830
  }, "strip", z.ZodTypeAny, {
775
831
  fields: Record<string, {
776
832
  type: "boolean";
@@ -807,6 +863,10 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
807
863
  default?: unknown;
808
864
  }>;
809
865
  writable: false;
866
+ indexes?: Record<string, {
867
+ on: (string | string[]) & (string | string[] | undefined);
868
+ unique?: boolean | undefined;
869
+ }> | undefined;
810
870
  table?: any;
811
871
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
812
872
  }, {
@@ -845,6 +905,10 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
845
905
  default?: unknown;
846
906
  }>;
847
907
  writable: false;
908
+ indexes?: Record<string, {
909
+ on: (string | string[]) & (string | string[] | undefined);
910
+ unique?: boolean | undefined;
911
+ }> | undefined;
848
912
  table?: any;
849
913
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
850
914
  }>, z.ZodObject<{
@@ -948,9 +1012,19 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
948
1012
  unique?: boolean | undefined;
949
1013
  default?: unknown;
950
1014
  }>]>>;
951
- writable: z.ZodLiteral<true>;
1015
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
1016
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
1017
+ unique: z.ZodOptional<z.ZodBoolean>;
1018
+ }, "strip", z.ZodTypeAny, {
1019
+ on: (string | string[]) & (string | string[] | undefined);
1020
+ unique?: boolean | undefined;
1021
+ }, {
1022
+ on: (string | string[]) & (string | string[] | undefined);
1023
+ unique?: boolean | undefined;
1024
+ }>>>;
952
1025
  table: z.ZodAny;
953
1026
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
1027
+ writable: z.ZodLiteral<true>;
954
1028
  }, "strip", z.ZodTypeAny, {
955
1029
  fields: Record<string, {
956
1030
  type: "boolean";
@@ -987,6 +1061,10 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
987
1061
  default?: unknown;
988
1062
  }>;
989
1063
  writable: true;
1064
+ indexes?: Record<string, {
1065
+ on: (string | string[]) & (string | string[] | undefined);
1066
+ unique?: boolean | undefined;
1067
+ }> | undefined;
990
1068
  table?: any;
991
1069
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
992
1070
  }, {
@@ -1025,6 +1103,10 @@ export declare const collectionSchema: z.ZodUnion<[z.ZodObject<{
1025
1103
  default?: unknown;
1026
1104
  }>;
1027
1105
  writable: true;
1106
+ indexes?: Record<string, {
1107
+ on: (string | string[]) & (string | string[] | undefined);
1108
+ unique?: boolean | undefined;
1109
+ }> | undefined;
1028
1110
  table?: any;
1029
1111
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1030
1112
  }>]>;
@@ -1129,9 +1211,19 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1129
1211
  unique?: boolean | undefined;
1130
1212
  default?: unknown;
1131
1213
  }>]>>;
1132
- writable: z.ZodLiteral<false>;
1214
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
1215
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
1216
+ unique: z.ZodOptional<z.ZodBoolean>;
1217
+ }, "strip", z.ZodTypeAny, {
1218
+ on: (string | string[]) & (string | string[] | undefined);
1219
+ unique?: boolean | undefined;
1220
+ }, {
1221
+ on: (string | string[]) & (string | string[] | undefined);
1222
+ unique?: boolean | undefined;
1223
+ }>>>;
1133
1224
  table: z.ZodAny;
1134
1225
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
1226
+ writable: z.ZodLiteral<false>;
1135
1227
  }, "strip", z.ZodTypeAny, {
1136
1228
  fields: Record<string, {
1137
1229
  type: "boolean";
@@ -1168,6 +1260,10 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1168
1260
  default?: unknown;
1169
1261
  }>;
1170
1262
  writable: false;
1263
+ indexes?: Record<string, {
1264
+ on: (string | string[]) & (string | string[] | undefined);
1265
+ unique?: boolean | undefined;
1266
+ }> | undefined;
1171
1267
  table?: any;
1172
1268
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1173
1269
  }, {
@@ -1206,6 +1302,10 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1206
1302
  default?: unknown;
1207
1303
  }>;
1208
1304
  writable: false;
1305
+ indexes?: Record<string, {
1306
+ on: (string | string[]) & (string | string[] | undefined);
1307
+ unique?: boolean | undefined;
1308
+ }> | undefined;
1209
1309
  table?: any;
1210
1310
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1211
1311
  }>, z.ZodObject<{
@@ -1309,9 +1409,19 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1309
1409
  unique?: boolean | undefined;
1310
1410
  default?: unknown;
1311
1411
  }>]>>;
1312
- writable: z.ZodLiteral<true>;
1412
+ indexes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
1413
+ on: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
1414
+ unique: z.ZodOptional<z.ZodBoolean>;
1415
+ }, "strip", z.ZodTypeAny, {
1416
+ on: (string | string[]) & (string | string[] | undefined);
1417
+ unique?: boolean | undefined;
1418
+ }, {
1419
+ on: (string | string[]) & (string | string[] | undefined);
1420
+ unique?: boolean | undefined;
1421
+ }>>>;
1313
1422
  table: z.ZodAny;
1314
1423
  _setMeta: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
1424
+ writable: z.ZodLiteral<true>;
1315
1425
  }, "strip", z.ZodTypeAny, {
1316
1426
  fields: Record<string, {
1317
1427
  type: "boolean";
@@ -1348,6 +1458,10 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1348
1458
  default?: unknown;
1349
1459
  }>;
1350
1460
  writable: true;
1461
+ indexes?: Record<string, {
1462
+ on: (string | string[]) & (string | string[] | undefined);
1463
+ unique?: boolean | undefined;
1464
+ }> | undefined;
1351
1465
  table?: any;
1352
1466
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1353
1467
  }, {
@@ -1386,6 +1500,10 @@ export declare const collectionsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.Z
1386
1500
  default?: unknown;
1387
1501
  }>;
1388
1502
  writable: true;
1503
+ indexes?: Record<string, {
1504
+ on: (string | string[]) & (string | string[] | undefined);
1505
+ unique?: boolean | undefined;
1506
+ }> | undefined;
1389
1507
  table?: any;
1390
1508
  _setMeta?: ((...args: unknown[]) => unknown) | undefined;
1391
1509
  }>]>>;
package/dist/types.js CHANGED
@@ -40,23 +40,29 @@ const fieldSchema = z.union([
40
40
  jsonFieldSchema
41
41
  ]);
42
42
  const fieldsSchema = z.record(fieldSchema);
43
- const readableCollectionSchema = z.object({
44
- fields: fieldsSchema,
45
- writable: z.literal(false),
46
- table: z.any(),
47
- _setMeta: z.function().optional()
43
+ const indexSchema = z.object({
44
+ on: z.string().or(z.array(z.string())),
45
+ unique: z.boolean().optional()
48
46
  });
49
- const writableCollectionSchema = z.object({
47
+ const indexesSchema = z.record(indexSchema);
48
+ const baseCollectionSchema = z.object({
50
49
  fields: fieldsSchema,
51
- writable: z.literal(true),
50
+ indexes: indexesSchema.optional(),
52
51
  table: z.any(),
53
52
  _setMeta: z.function().optional()
54
53
  });
54
+ const readableCollectionSchema = baseCollectionSchema.extend({
55
+ writable: z.literal(false)
56
+ });
57
+ const writableCollectionSchema = baseCollectionSchema.extend({
58
+ writable: z.literal(true)
59
+ });
55
60
  const collectionSchema = z.union([readableCollectionSchema, writableCollectionSchema]);
56
61
  const collectionsSchema = z.record(collectionSchema);
57
62
  export {
58
63
  collectionSchema,
59
64
  collectionsSchema,
65
+ indexSchema,
60
66
  readableCollectionSchema,
61
67
  writableCollectionSchema
62
68
  };
@@ -1,2 +1 @@
1
- export declare function findLocalDatabase(localDbURL: string): string;
2
1
  export declare function createRemoteDatabaseClient(appToken: string, remoteDbURL: string): import("drizzle-orm/sqlite-proxy").SqliteRemoteDatabase<Record<string, never>>;
@@ -1,15 +1,5 @@
1
1
  import { drizzle } from "drizzle-orm/sqlite-proxy";
2
2
  import { z } from "zod";
3
- import { DB_PATH } from "./consts.js";
4
- function findLocalDatabase(localDbURL) {
5
- let dbURL = void 0;
6
- if (process.env.VERCEL) {
7
- dbURL = new URL(DB_PATH, "file://" + process.cwd() + "/vercel/path0/");
8
- } else {
9
- dbURL = new URL(localDbURL);
10
- }
11
- return dbURL.toString();
12
- }
13
3
  function createRemoteDatabaseClient(appToken, remoteDbURL) {
14
4
  const url = new URL("./db/query/", remoteDbURL);
15
5
  const db = drizzle(async (sql, parameters, method) => {
@@ -58,6 +48,5 @@ Full error: Unexpected JSON response. ${e instanceof Error ? e.message : String(
58
48
  return db;
59
49
  }
60
50
  export {
61
- createRemoteDatabaseClient,
62
- findLocalDatabase
51
+ createRemoteDatabaseClient
63
52
  };
@@ -1,17 +1,17 @@
1
+ import type { AstroConfig } from 'astro';
1
2
  import type { DBCollections } from './types.js';
2
3
  import type { VitePlugin } from './utils.js';
3
4
  export declare function vitePluginDb(params: {
4
5
  connectToStudio: false;
5
6
  collections: DBCollections;
6
- dbUrl: string;
7
7
  } | {
8
+ output: AstroConfig['output'];
8
9
  connectToStudio: true;
9
10
  collections: DBCollections;
10
11
  appToken: string;
11
12
  }): VitePlugin;
12
- export declare function getVirtualModContents({ collections, dbUrl, }: {
13
+ export declare function getVirtualModContents({ collections, }: {
13
14
  collections: DBCollections;
14
- dbUrl: string;
15
15
  }): string;
16
16
  export declare function getStudioVirtualModContents({ collections, appToken, }: {
17
17
  collections: DBCollections;
@@ -1,5 +1,4 @@
1
1
  import { DRIZZLE_MOD_IMPORT, INTERNAL_MOD_IMPORT, VIRTUAL_MODULE_ID, DB_PATH } from "./consts.js";
2
- import fs from "node:fs";
3
2
  const resolvedVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
4
3
  function vitePluginDb(params) {
5
4
  return {
@@ -17,27 +16,15 @@ function vitePluginDb(params) {
17
16
  return getStudioVirtualModContents(params);
18
17
  }
19
18
  return getVirtualModContents(params);
20
- },
21
- async buildEnd() {
22
- if ("dbUrl" in params) {
23
- const data = await fs.promises.readFile(new URL(params.dbUrl));
24
- this.emitFile({
25
- fileName: "content.db",
26
- source: data,
27
- type: "asset"
28
- });
29
- }
30
19
  }
31
20
  };
32
21
  }
33
22
  function getVirtualModContents({
34
- collections,
35
- dbUrl
23
+ collections
36
24
  }) {
37
25
  return `
38
- import { collectionToTable, createLocalDatabaseClient, findLocalDatabase } from ${INTERNAL_MOD_IMPORT};
39
-
40
- export const dbUrl = findLocalDatabase(${JSON.stringify(dbUrl)});
26
+ import { collectionToTable, createLocalDatabaseClient } from ${INTERNAL_MOD_IMPORT};
27
+ import dbUrl from './.astro/content.db?fileurl';
41
28
 
42
29
  const params = ${JSON.stringify({
43
30
  collections,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/db",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",