@astrojs/db 0.9.11 → 0.10.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.
@@ -27,7 +27,7 @@ function printHelp({
27
27
  message.push(
28
28
  linebreak(),
29
29
  ` ${bgGreen(black(` ${commandName} `))} ${green(
30
- `v${"0.9.11"}`
30
+ `v${"0.10.1"}`
31
31
  )} ${headline}`
32
32
  );
33
33
  }
@@ -1,6 +1,6 @@
1
1
  export declare const PACKAGE_NAME: any;
2
2
  export declare const RUNTIME_IMPORT: string;
3
- export declare const RUNTIME_CONFIG_IMPORT: string;
3
+ export declare const RUNTIME_VIRTUAL_IMPORT: string;
4
4
  export declare const DB_TYPES_FILE = "db-types.d.ts";
5
5
  export declare const VIRTUAL_MODULE_ID = "astro:db";
6
6
  export declare const DB_PATH = ".astro/content.db";
@@ -3,7 +3,7 @@ const PACKAGE_NAME = JSON.parse(
3
3
  readFileSync(new URL("../../package.json", import.meta.url), "utf8")
4
4
  ).name;
5
5
  const RUNTIME_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime`);
6
- const RUNTIME_CONFIG_IMPORT = JSON.stringify(`${PACKAGE_NAME}/dist/runtime/config.js`);
6
+ const RUNTIME_VIRTUAL_IMPORT = JSON.stringify(`${PACKAGE_NAME}/dist/runtime/virtual.js`);
7
7
  const DB_TYPES_FILE = "db-types.d.ts";
8
8
  const VIRTUAL_MODULE_ID = "astro:db";
9
9
  const DB_PATH = ".astro/content.db";
@@ -15,7 +15,7 @@ export {
15
15
  DB_TYPES_FILE,
16
16
  MIGRATION_VERSION,
17
17
  PACKAGE_NAME,
18
- RUNTIME_CONFIG_IMPORT,
19
18
  RUNTIME_IMPORT,
19
+ RUNTIME_VIRTUAL_IMPORT,
20
20
  VIRTUAL_MODULE_ID
21
21
  };
@@ -1,7 +1,7 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  import { normalizePath } from "vite";
3
3
  import { SEED_DEV_FILE_NAME } from "../../runtime/queries.js";
4
- import { DB_PATH, RUNTIME_CONFIG_IMPORT, RUNTIME_IMPORT, VIRTUAL_MODULE_ID } from "../consts.js";
4
+ import { DB_PATH, RUNTIME_IMPORT, RUNTIME_VIRTUAL_IMPORT, VIRTUAL_MODULE_ID } from "../consts.js";
5
5
  import { getDbDirectoryUrl, getRemoteDatabaseUrl } from "../utils.js";
6
6
  const WITH_SEED_VIRTUAL_MODULE_ID = "astro:db:seed";
7
7
  const resolved = {
@@ -51,7 +51,7 @@ function vitePluginDb(params) {
51
51
  };
52
52
  }
53
53
  function getConfigVirtualModContents() {
54
- return `export * from ${RUNTIME_CONFIG_IMPORT}`;
54
+ return `export * from ${RUNTIME_VIRTUAL_IMPORT}`;
55
55
  }
56
56
  function getLocalVirtualModContents({
57
57
  tables,
@@ -89,7 +89,7 @@ ${shouldSeed ? `await seedLocal({
89
89
  integrationSeedFunctions: [${integrationSeedImportNames.join(",")}],
90
90
  });` : ""}
91
91
 
92
- export * from ${RUNTIME_CONFIG_IMPORT};
92
+ export * from ${RUNTIME_VIRTUAL_IMPORT};
93
93
 
94
94
  ${getStringifiedTableExports(tables)}`;
95
95
  }
@@ -119,7 +119,7 @@ import {asDrizzleTable, createRemoteDatabaseClient} from ${RUNTIME_IMPORT};
119
119
 
120
120
  export const db = await createRemoteDatabaseClient(${appTokenArg()}, ${dbUrlArg()});
121
121
 
122
- export * from ${RUNTIME_CONFIG_IMPORT};
122
+ export * from ${RUNTIME_VIRTUAL_IMPORT};
123
123
 
124
124
  ${getStringifiedTableExports(tables)}
125
125
  `;
@@ -1,4 +1,3 @@
1
- import { pathToFileURL } from "url";
2
1
  import { sql } from "drizzle-orm";
3
2
  import {
4
3
  customType,
@@ -9,6 +8,7 @@ import {
9
8
  } from "drizzle-orm/sqlite-core";
10
9
  import {} from "../core/types.js";
11
10
  import { isSerializedSQL } from "./types.js";
11
+ import { pathToFileURL } from "./utils.js";
12
12
  import { createRemoteDatabaseClient, createLocalDatabaseClient } from "./db-client.js";
13
13
  import { seedLocal } from "./seed-local.js";
14
14
  function hasPrimaryKey(column) {
@@ -6,3 +6,5 @@ export declare function safeFetch(url: Parameters<typeof fetch>[0], options?: Pa
6
6
  export declare class AstroDbError extends AstroError {
7
7
  name: string;
8
8
  }
9
+ export default function slash(path: string): string;
10
+ export declare function pathToFileURL(path: string): URL;
@@ -1,4 +1,5 @@
1
1
  import { AstroError } from "astro/errors";
2
+ const isWindows = process?.platform === "win32";
2
3
  async function safeFetch(url, options = {}, onNotOK = () => {
3
4
  throw new Error(`Request to ${url} returned a non-OK status code.`);
4
5
  }) {
@@ -11,7 +12,26 @@ async function safeFetch(url, options = {}, onNotOK = () => {
11
12
  class AstroDbError extends AstroError {
12
13
  name = "Astro DB Error";
13
14
  }
15
+ function slash(path) {
16
+ const isExtendedLengthPath = path.startsWith("\\\\?\\");
17
+ if (isExtendedLengthPath) {
18
+ return path;
19
+ }
20
+ return path.replace(/\\/g, "/");
21
+ }
22
+ function pathToFileURL(path) {
23
+ if (isWindows) {
24
+ let slashed = slash(path);
25
+ if (!slashed.startsWith("/")) {
26
+ slashed = "/" + slashed;
27
+ }
28
+ return new URL("file://" + slashed);
29
+ }
30
+ return new URL("file://" + path);
31
+ }
14
32
  export {
15
33
  AstroDbError,
34
+ slash as default,
35
+ pathToFileURL,
16
36
  safeFetch
17
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/db",
3
- "version": "0.9.11",
3
+ "version": "0.10.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,8 +20,8 @@
20
20
  "types": "./dist/runtime/index.d.ts",
21
21
  "import": "./dist/runtime/index.js"
22
22
  },
23
- "./dist/runtime/config.js": {
24
- "import": "./dist/runtime/config.js"
23
+ "./dist/runtime/virtual.js": {
24
+ "import": "./dist/runtime/virtual.js"
25
25
  },
26
26
  "./types": {
27
27
  "types": "./dist/core/types.d.ts",
@@ -81,12 +81,12 @@
81
81
  "mocha": "^10.2.0",
82
82
  "typescript": "^5.2.2",
83
83
  "vite": "^5.1.4",
84
- "astro": "4.5.14",
84
+ "astro": "4.5.16",
85
85
  "astro-scripts": "0.0.14"
86
86
  },
87
87
  "scripts": {
88
- "types:config": "tsc -p ./tsconfig.config-types.json",
89
- "build": "astro-scripts build \"src/**/*.ts\" && tsc && pnpm types:config",
88
+ "types:virtual": "tsc -p ./tsconfig.virtual.json",
89
+ "build": "astro-scripts build \"src/**/*.ts\" && tsc && pnpm types:virtual",
90
90
  "build:ci": "astro-scripts build \"src/**/*.ts\"",
91
91
  "dev": "astro-scripts dev \"src/**/*.ts\"",
92
92
  "test": "mocha --exit --timeout 20000 \"test/*.js\" \"test/unit/**/*.js\"",
package/virtual.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  declare module 'astro:db' {
2
- type RuntimeConfig = typeof import('./dist/_internal/runtime/config.js');
2
+ type RuntimeConfig = typeof import('./dist/_internal/runtime/virtual.js');
3
3
 
4
- export const db: import('./dist/_internal/runtime/config.js').Database;
4
+ export const db: import('./dist/_internal/runtime/virtual.js').Database;
5
5
  export const dbUrl: string;
6
6
 
7
7
  export const sql: RuntimeConfig['sql'];
File without changes