@contentrain/nuxt
Advanced tools
Comparing version
@@ -11,3 +11,2 @@ import * as _nuxt_schema from '@nuxt/schema'; | ||
}; | ||
bundleDatabase?: boolean; | ||
} | ||
@@ -14,0 +13,0 @@ declare module '@nuxt/schema' { |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"builder": { | ||
@@ -10,0 +10,0 @@ "@nuxt/module-builder": "0.8.4", |
@@ -17,3 +17,3 @@ import { useRuntimeConfig } from "#imports"; | ||
const body = await readBody(event); | ||
const sdk = await getSDK(config); | ||
const sdk = getSDK(config); | ||
if (body.model) { | ||
@@ -20,0 +20,0 @@ await sdk.refreshCache(body.model); |
@@ -7,5 +7,5 @@ import { defineEventHandler, readBody, useRuntimeConfig } from "#imports"; | ||
const { model } = body; | ||
const sdk = await getSDK(config); | ||
const result = sdk.load(model); | ||
const sdk = getSDK(config); | ||
const result = await sdk.load(model); | ||
return result; | ||
}); |
@@ -1,3 +0,3 @@ | ||
import type { IDBRecord } from '@contentrain/query'; | ||
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("@contentrain/query").QueryResult<IDBRecord>>>; | ||
import type { IDBRecord, QueryResult } from '@contentrain/query'; | ||
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<QueryResult<IDBRecord>>>; | ||
export default _default; |
@@ -142,3 +142,3 @@ import { useRuntimeConfig } from "#imports"; | ||
validateQueryBody(body); | ||
const sdk = await getSDK(config); | ||
const sdk = getSDK(config); | ||
const query = QueryFactory.createSQLiteBuilder(body.model, sdk); | ||
@@ -145,0 +145,0 @@ if (body.where) { |
import type { SQLiteLoader } from '@contentrain/query'; | ||
import type { RuntimeConfig } from '@nuxt/schema'; | ||
export declare function getSDK(config: RuntimeConfig): Promise<SQLiteLoader>; | ||
export declare function getSDK(config: RuntimeConfig): SQLiteLoader; |
import { existsSync } from "node:fs"; | ||
import { resolve } from "node:path"; | ||
import process from "node:process"; | ||
import { useStorage } from "#imports"; | ||
import { QueryFactory, SQLiteLoader as SQLiteLoaderImpl } from "@contentrain/query"; | ||
let _sdk = null; | ||
async function resolveAssetPath(path) { | ||
if (path.startsWith("assets:")) { | ||
const storage = useStorage(); | ||
const assetPath = path.replace("assets:", ""); | ||
const tempDir = process.env.NETLIFY ? "/tmp/contentrain" : "/tmp/contentrain"; | ||
await storage.setItem(`${tempDir}/.exists`, "1"); | ||
const asset = await storage.getItem(assetPath); | ||
if (!asset) { | ||
throw new Error(`Asset not found: ${assetPath}`); | ||
} | ||
const tempPath = `${tempDir}/${assetPath.split("/").pop()}`; | ||
await storage.setItem(tempPath, asset); | ||
console.log("Asset copied to temp path:", tempPath); | ||
return tempPath; | ||
} | ||
return path; | ||
} | ||
export async function getSDK(config) { | ||
export function getSDK(config) { | ||
if (!config.contentrain) { | ||
@@ -32,10 +14,9 @@ throw new Error("Contentrain config is missing"); | ||
} | ||
const dbPath = await resolveAssetPath(config.contentrain.databasePath); | ||
const absolutePath = resolve(process.cwd(), dbPath); | ||
const dbExists = existsSync(absolutePath); | ||
console.log("Contentrain DB Path:", absolutePath); | ||
const dbPath = resolve(process.cwd(), config.contentrain.databasePath); | ||
const dbExists = existsSync(dbPath); | ||
console.log("Contentrain DB Path:", dbPath); | ||
console.log("DB File Exists:", dbExists); | ||
console.log("Current Working Directory:", process.cwd()); | ||
const loader = new SQLiteLoaderImpl({ | ||
databasePath: absolutePath, | ||
databasePath: dbPath, | ||
cache: config.contentrain.cache !== false, | ||
@@ -42,0 +23,0 @@ maxCacheSize: config.contentrain.maxCacheSize || 100 |
{ | ||
"name": "@contentrain/nuxt", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Official Nuxt module for Contentrain SDK, providing seamless integration with Contentrain CMS", | ||
@@ -5,0 +5,0 @@ "author": "Contentrain Inc.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
0
-100%25131
-5.49%547
-5.85%