fetch-appwrite-types
Advanced tools
Comparing version 2.0.2-2 to 2.1.1
@@ -23,23 +23,29 @@ import { create, emit, DeclarationFlags } from 'dts-dom'; | ||
}; | ||
try { | ||
import.meta.resolve('node-appwrite'); | ||
packagesInstalled.server = true; | ||
} | ||
catch (e) { | ||
consola.warn('"node-appwrite" package is not installed. Trying to use the client package"'); | ||
if (process.env.NODE_ENV !== 'test') { | ||
try { | ||
import.meta.resolve('appwrite'); | ||
consola.warn('"appwrite" package is installed. Using it instead'); | ||
packagesInstalled.client = true; | ||
import.meta.resolve('node-appwrite'); | ||
packagesInstalled.server = true; | ||
} | ||
catch (e) { | ||
consola.error('"appwrite" package is not installed. Please install it to continue'); | ||
throw new Error('"appwrite" or "node-appwrite" packages are not installed. Please install one to continue'); | ||
consola.warn('"node-appwrite" package is not installed. Trying to use the client package"'); | ||
try { | ||
import.meta.resolve('appwrite'); | ||
consola.warn('"appwrite" package is installed. Using it instead'); | ||
packagesInstalled.client = true; | ||
} | ||
catch (e) { | ||
consola.error('"appwrite" package is not installed. Please install it to continue'); | ||
throw new Error('"appwrite" or "node-appwrite" packages are not installed. Please install one to continue'); | ||
} | ||
} | ||
} | ||
// Empty the file | ||
const writeStream = createWriteStream(`${outDir}/${outFileName}.ts`); | ||
writeStream.write(`import type { Models } from '${packagesInstalled.server ? 'node-appwrite' : 'appwrite'}';\n\n`); | ||
const writeStreamNull = createWriteStream(`${outDir}/${outFileName}.ts`); | ||
await new Promise((resolve) => { | ||
writeStreamNull.write(`import type { Models } from '${packagesInstalled.server ? 'node-appwrite' : 'appwrite'}';\n\n`, () => resolve()); | ||
}); | ||
writeStreamNull.end(); | ||
const writeStream = createWriteStream(`${outDir}/${outFileName}.ts`, { flags: 'a' }); | ||
if (hardTypes) { | ||
CreateHardFieldsTypes(writeStream); | ||
await CreateHardFieldsTypes(writeStream); | ||
} | ||
@@ -64,7 +70,8 @@ const { databases } = await databasesClient.list(); | ||
// Push attribute to interface | ||
typeIntf.members.push(await GenerateType(attr, outDir, typeIntfName, hardTypes, includeDBName, databaseName, databaseId, (params) => relationships.push(params))); | ||
typeIntf.members.push(await GenerateType(attr, writeStream, typeIntfName, hardTypes, includeDBName, databaseName, databaseId, (params) => relationships.push(params))); | ||
} | ||
// Write type interface to file | ||
const writeStream = createWriteStream(`${outDir}/${outFileName}.ts`, { flags: 'a' }); | ||
writeStream.write(emit(typeIntf)); | ||
await new Promise((resolve) => { | ||
writeStream.write(emit(typeIntf), () => resolve()); | ||
}); | ||
// Create document interface | ||
@@ -78,3 +85,6 @@ const documentIntfName = `${collectionName}Document `; | ||
// Write document interface to file | ||
writeStream.write(emit(documentIntf)); | ||
await new Promise((resolve) => { | ||
writeStream.write(emit(documentIntf), () => resolve()); | ||
}); | ||
writeStreamNull.end(); | ||
consola.success(`Types for collection "${col.name}" fetched successfully`); | ||
@@ -81,0 +91,0 @@ } |
import { Client, Databases } from 'node-appwrite'; | ||
import { config } from 'dotenv'; | ||
config(); | ||
const client = new Client() | ||
.setEndpoint(process.env.APPWRITE_ENDPOINT) | ||
.setProject(process.env.APPWRITE_PROJECT_ID) | ||
.setKey(process.env.APPWRITE_API_KEY); | ||
const client = new Client(); | ||
client.setEndpoint(process.env.APPWRITE_ENDPOINT); | ||
client.setProject(process.env.APPWRITE_PROJECT_ID); | ||
client.setKey(process.env.APPWRITE_API_KEY); | ||
const databasesClient = new Databases(client); | ||
export { databasesClient }; |
import type { WriteStream } from "fs"; | ||
declare const CreateHardFieldsTypes: (writeStream: WriteStream) => void; | ||
declare const CreateHardFieldsTypes: (writeStream: WriteStream) => Promise<void>; | ||
export default CreateHardFieldsTypes; |
import { create, DeclarationFlags, emit } from "dts-dom"; | ||
const CreateHardFieldsTypes = (writeStream) => { | ||
const CreateHardFieldsTypes = async (writeStream) => { | ||
const types = [ | ||
@@ -7,7 +7,9 @@ create.alias('Email', create.namedTypeReference('`${string}@${string}.${string}`')), | ||
]; | ||
types.forEach(type => { | ||
for (const type of types) { | ||
type.flags = DeclarationFlags.Export; | ||
writeStream.write(emit(type)); | ||
}); | ||
await new Promise((resolve) => { | ||
writeStream.write(emit(type), () => resolve()); | ||
}); | ||
} | ||
}; | ||
export default CreateHardFieldsTypes; |
import { ArrayTypeReference, NamedTypeReference } from 'dts-dom'; | ||
import type { Attribute } from '../types/index.js'; | ||
import { WriteStream } from "fs"; | ||
/** | ||
@@ -17,3 +18,3 @@ * | ||
} | ||
declare const GenerateType: (attribute: Attribute, outDir: string, typeIntfName: string, hardTypes: boolean, includeDBName: boolean, dbName: string, dbId: string, registerRelationship: registerRelationship) => Promise<import("dts-dom").PropertyDeclaration>; | ||
declare const GenerateType: (attribute: Attribute, writeStream: WriteStream, typeIntfName: string, hardTypes: boolean, includeDBName: boolean, dbName: string, dbId: string, registerRelationship: registerRelationship) => Promise<import("dts-dom").PropertyDeclaration>; | ||
export default GenerateType; |
import { create, DeclarationFlags, emit, type } from 'dts-dom'; | ||
import { createWriteStream } from "fs"; | ||
import { databasesClient } from "../utils/appwrite.js"; | ||
import FormatCollectionName from './FormatCollectionName.js'; | ||
const GenerateType = async (attribute, outDir, typeIntfName, hardTypes, includeDBName, dbName, dbId, registerRelationship) => { | ||
const writeStream = createWriteStream(`${outDir}/appwrite.ts`, { flags: 'a' }); | ||
const GenerateType = async (attribute, writeStream, typeIntfName, hardTypes, includeDBName, dbName, dbId, registerRelationship) => { | ||
// handle null values | ||
@@ -8,0 +6,0 @@ if (attribute.type === null) { |
{ | ||
"name": "fetch-appwrite-types", | ||
"version": "2.0.2-2", | ||
"version": "2.1.1", | ||
"description": "Appwrite types file maker", | ||
@@ -9,18 +9,2 @@ "author": "Etienne Moureton", | ||
"type": "module", | ||
"scripts": { | ||
"deploy": "npm run prepare && np", | ||
"dev": "npm run prepare && node dist/bin/index.js", | ||
"build": "tsc", | ||
"lint": "eslint . --ext .ts", | ||
"lint:fix": "npm run lint -- --fix", | ||
"test": "", | ||
"prepare": "npm run lint && npm run build && npm run test", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"preversion": "npm run lint", | ||
"version": "git add -A src", | ||
"postversion": "git push && git push --tags", | ||
"check-updates": "npx npm-check-updates", | ||
"check-updates:minor": "npx npm-check-updates --target minor", | ||
"check-updates:patch": "npx npm-check-updates --target patch" | ||
}, | ||
"bin": "dist/bin/index.js", | ||
@@ -53,5 +37,5 @@ "repository": { | ||
"eslint-plugin-promise": "^6.1.1", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.1.2", | ||
"typescript": "^4.9.5" | ||
"typescript": "^4.9.5", | ||
"vite": "^5.4.11", | ||
"vitest": "^2.1.4" | ||
}, | ||
@@ -64,3 +48,17 @@ "dependencies": { | ||
"ts-node": "^10.9.2" | ||
}, | ||
"scripts": { | ||
"deploy": "pnpm run prepare && np", | ||
"dev": "pnpm run prepare && node dist/bin/index.js", | ||
"build": "tsc", | ||
"lint": "eslint . --ext .ts", | ||
"lint:fix": "pnpm run lint -- --fix", | ||
"test": "vitest run", | ||
"preversion": "pnpm run lint", | ||
"version": "git add -A src", | ||
"postversion": "git push && git push --tags", | ||
"check-updates": "npx npm-check-updates", | ||
"check-updates:minor": "npx npm-check-updates --target minor", | ||
"check-updates:patch": "npx npm-check-updates --target patch" | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23348
366
1