@contentrain/nuxt
Advanced tools
Comparing version
@@ -11,2 +11,3 @@ import * as _nuxt_schema from '@nuxt/schema'; | ||
}; | ||
bundleDatabase?: boolean; | ||
} | ||
@@ -13,0 +14,0 @@ declare module '@nuxt/schema' { |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"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 = getSDK(config); | ||
const sdk = await 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 = getSDK(config); | ||
const result = await sdk.load(model); | ||
const sdk = await getSDK(config); | ||
const result = sdk.load(model); | ||
return result; | ||
}); |
@@ -1,3 +0,3 @@ | ||
import type { IDBRecord, QueryResult } from '@contentrain/query'; | ||
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<QueryResult<IDBRecord>>>; | ||
import type { IDBRecord } from '@contentrain/query'; | ||
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("@contentrain/query").QueryResult<IDBRecord>>>; | ||
export default _default; |
@@ -142,3 +142,3 @@ import { useRuntimeConfig } from "#imports"; | ||
validateQueryBody(body); | ||
const sdk = getSDK(config); | ||
const sdk = await 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): SQLiteLoader; | ||
export declare function getSDK(config: RuntimeConfig): Promise<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; | ||
export function getSDK(config) { | ||
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) { | ||
if (!config.contentrain) { | ||
@@ -14,9 +32,10 @@ throw new Error("Contentrain config is missing"); | ||
} | ||
const dbPath = resolve(process.cwd(), config.contentrain.databasePath); | ||
const dbExists = existsSync(dbPath); | ||
console.log("Contentrain DB Path:", dbPath); | ||
const dbPath = await resolveAssetPath(config.contentrain.databasePath); | ||
const absolutePath = resolve(process.cwd(), dbPath); | ||
const dbExists = existsSync(absolutePath); | ||
console.log("Contentrain DB Path:", absolutePath); | ||
console.log("DB File Exists:", dbExists); | ||
console.log("Current Working Directory:", process.cwd()); | ||
const loader = new SQLiteLoaderImpl({ | ||
databasePath: dbPath, | ||
databasePath: absolutePath, | ||
cache: config.contentrain.cache !== false, | ||
@@ -23,0 +42,0 @@ maxCacheSize: config.contentrain.maxCacheSize || 100 |
{ | ||
"name": "@contentrain/nuxt", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"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
26592
5.81%581
6.22%1
Infinity%