@dreamtree-org/korm-js 1.0.53 → 1.0.54

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/helpers/files.js CHANGED
@@ -1 +1 @@
1
- const fs=require("fs"),path=require("path"),{S3Client:S3Client,PutObjectCommand:PutObjectCommand}=require("@aws-sdk/client-s3"),logger=require("../Logger");class Files{s3Client=null;config=null;validateConfig(e){let t=[];if(e.region||t.push("Region as config.region"),e.endpoint||e.host||t.push("Endpoint as config.endpoint or Host as config.host"),e.accessKeyId||t.push("Access key ID as config.accessKeyId"),e.secretAccessKey||t.push("Secret access key as config.secretAccessKey"),e.bucketName||t.push("Bucket name as config.bucketName"),t.length>0)throw new Error(`Missing config: ${t.join(", ")}. Please set the config in the config file.`)}setConfig(e){this.validateConfig(e),this.config=e;let t={region:e.region,endpoint:e.endpoint||`https://${e.region}.${e.host}`,credentials:{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey}};this.s3Client=new S3Client(t)}async upload2Spaces(e){const{fileBuffer:t,originalName:i,mimeType:s}=e;logger.debug("Uploading file to Spaces",{fileBuffer:t,originalName:i,mimeType:s},e);const n=i.split(".").pop(),r=this.config.bucketName,a=`${this.config.folderName||"uploads"}/${`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}-${i}.${n}`,c={Bucket:r,Key:a,Body:t,ContentType:s,ACL:"public-read",CacheControl:"max-age=31536000"};try{const e=new PutObjectCommand(c);await this.s3Client.send(e);const t=`https://${r}.${this.config.region}.cdn.digitaloceanspaces.com/${a}`;return logger.info(`File uploaded to Spaces key: ${a}`),{key:a,url:t}}catch(e){throw logger.error("DigitalOcean Spaces Upload Error:",e),new Error(`Spaces upload failed: ${e.message}`)}}needSync(e,t){let i=this.readJSON(e),s=this.checkFileUpdatedAt(e),n=this.readFile(t);return n&&(n=new Date(+n)),{needSync:n&&n<s||!n,syncSchema:i,lastSyncedAt:s.getTime().toString()}}writeFromTemplate(e,t,i){const s=__dirname,n=fs.readFileSync(`${s}/${t}`,"utf8").replace(/{{(.*?)}}/g,(e,t)=>i[t]||e);this.createDirectory(path.dirname(e)),fs.writeFileSync(e,n)}writeModel(e,t){this.exists(e)?logger.debug("File already exists",e):(logger.debug("Writing model to",e),this.writeFromTemplate(e,"../templates/model.template",t))}checkFileUpdatedAt(e){return this.exists(e)?fs.statSync(e).mtime:null}isLatestFile(e,t=1e3){let i=Date.now(),s=this.checkFileUpdatedAt(e);return!!s&&i-new Date(s).getTime()<t}createDirectory(e){this.exists(e)||fs.mkdirSync(e,{recursive:!0})}deleteDirectory(e){this.exists(e)&&fs.rmSync(e,{recursive:!0,force:!0})}exists(e){return fs.existsSync(e)}rename(e,t){this.exists(e)&&fs.renameSync(e,t)}deleteFile(e){this.exists(e)&&fs.unlinkSync(e)}readFile(e,t="utf8"){return this.exists(e)?fs.readFileSync(e,t):null}writeFile(e,t,i="utf8"){fs.writeFileSync(e,t,i)}appendFile(e,t,i="utf8"){fs.appendFileSync(e,t,i)}readJSON(e){return JSON.parse(this.readFile(e))}writeJSON(e,t){this.writeFile(e,JSON.stringify(t,null,2))}readJSONL(e){return this.readFile(e).trim().split("\n").map(e=>JSON.parse(e))}writeJSONL(e,t){const i=t.map(e=>JSON.stringify(e)).join("\n");this.writeFile(e,i)}appendJSONL(e,t){const i=t.map(e=>JSON.stringify(e)).join("\n");this.appendFile(e,"\n"+i)}escapeCSV(e){if(null==e)return"";const t=String(e);return t.includes('"')||t.includes(",")||t.includes("\n")?`"${t.replace(/"/g,'""')}"`:t}writeCSV(e,t){if(!Array.isArray(t)||0===t.length)throw new Error("Data must be a non-empty array");const i=Object.keys(t[0]),s=[i.join(","),...t.map(e=>i.map(t=>this.escapeCSV(e[t])).join(","))];this.writeFile(e,s.join("\n"))}readCSV(e){return this.readFile(e).trim().split("\n").map(e=>e.split(","))}appendCSV(e,t){if(!Array.isArray(t)||0===t.length)return;const[i]=this.readFile(e).split("\n"),s=i.split(","),n=t.map(e=>s.map(t=>this.escapeCSV(e[t])).join(","));this.appendFile(e,"\n"+n.join("\n"))}}module.exports=Files;
1
+ const fs=require("fs"),path=require("path"),{S3Client:S3Client,PutObjectCommand:PutObjectCommand}=require("@aws-sdk/client-s3"),logger=require("../Logger");class Files{s3Client=null;config=null;validateConfig(e){const t=[];if(e.region||t.push("Region as config.region"),e.endpoint||e.host||t.push("Endpoint as config.endpoint or Host as config.host"),e.accessKeyId||t.push("Access key ID as config.accessKeyId"),e.secretAccessKey||t.push("Secret access key as config.secretAccessKey"),e.bucketName||t.push("Bucket name as config.bucketName"),t.length>0)throw new Error(`Missing config: ${t.join(", ")}. Please set the config in the config file.`)}setConfig(e){this.validateConfig(e),this.config=e;const t={region:e.region,endpoint:e.endpoint||`https://${e.region}.${e.host}`,credentials:{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey}};this.s3Client=new S3Client(t)}async upload2Spaces(e){const{fileBuffer:t,originalName:i,mimeType:s}=e;logger.debug("Uploading file to Spaces",{fileBuffer:t,originalName:i,mimeType:s},e);const n=i.split(".").pop(),r=this.config.bucketName,a=`${this.config.folderName||"uploads"}/${`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}-${i}.${n}`,c={Bucket:r,Key:a,Body:t,ContentType:s,ACL:"public-read",CacheControl:"max-age=31536000"};try{const e=new PutObjectCommand(c);await this.s3Client.send(e);const t=`https://${r}.${this.config.region}.cdn.digitaloceanspaces.com/${a}`;return logger.info(`File uploaded to Spaces key: ${a}`),{key:a,url:t}}catch(e){throw logger.error("DigitalOcean Spaces Upload Error:",e),new Error(`Spaces upload failed: ${e.message}`)}}needSync(e,t){const i=this.readJSON(e),s=this.checkFileUpdatedAt(e);let n=this.readFile(t);return n&&(n=new Date(+n)),{needSync:n&&n<s||!n,syncSchema:i,lastSyncedAt:s.getTime().toString()}}writeFromTemplate(e,t,i){const s=__dirname,n=fs.readFileSync(`${s}/${t}`,"utf8").replace(/{{(.*?)}}/g,(e,t)=>i[t]||e);this.createDirectory(path.dirname(e)),fs.writeFileSync(e,n)}writeModel(e,t){this.exists(e)?logger.debug("File already exists",e):(logger.debug("Writing model to",e),this.writeFromTemplate(e,"../templates/model.template",t))}checkFileUpdatedAt(e){return this.exists(e)?fs.statSync(e).mtime:null}isLatestFile(e,t=1e3){const i=Date.now(),s=this.checkFileUpdatedAt(e);if(!s)return!1;return i-new Date(s).getTime()<t}createDirectory(e){this.exists(e)||fs.mkdirSync(e,{recursive:!0})}deleteDirectory(e){this.exists(e)&&fs.rmSync(e,{recursive:!0,force:!0})}exists(e){return fs.existsSync(e)}rename(e,t){this.exists(e)&&fs.renameSync(e,t)}deleteFile(e){this.exists(e)&&fs.unlinkSync(e)}readFile(e,t="utf8"){return this.exists(e)?fs.readFileSync(e,t):null}writeFile(e,t,i="utf8"){fs.writeFileSync(e,t,i)}appendFile(e,t,i="utf8"){fs.appendFileSync(e,t,i)}readJSON(e){return JSON.parse(this.readFile(e))}writeJSON(e,t){this.writeFile(e,JSON.stringify(t,null,2))}readJSONL(e){return this.readFile(e).trim().split("\n").map(e=>JSON.parse(e))}writeJSONL(e,t){const i=t.map(e=>JSON.stringify(e)).join("\n");this.writeFile(e,i)}appendJSONL(e,t){const i=t.map(e=>JSON.stringify(e)).join("\n");this.appendFile(e,"\n"+i)}escapeCSV(e){if(null==e)return"";const t=String(e);return t.includes('"')||t.includes(",")||t.includes("\n")?`"${t.replace(/"/g,'""')}"`:t}writeCSV(e,t){if(!Array.isArray(t)||0===t.length)throw new Error("Data must be a non-empty array");const i=Object.keys(t[0]),s=[i.join(","),...t.map(e=>i.map(t=>this.escapeCSV(e[t])).join(","))];this.writeFile(e,s.join("\n"))}readCSV(e){return this.readFile(e).trim().split("\n").map(e=>e.split(","))}appendCSV(e,t){if(!Array.isArray(t)||0===t.length)return;const[i]=this.readFile(e).split("\n"),s=i.split(","),n=t.map(e=>s.map(t=>this.escapeCSV(e[t])).join(","));this.appendFile(e,"\n"+n.join("\n"))}}module.exports=Files;
package/jest.config.js CHANGED
@@ -1 +1 @@
1
- module.exports={testEnvironment:"node",testMatch:["**/test/**/*.test.js","**/test/**/*.spec.js","**/__tests__/**/*.js"],collectCoverage:!0,coverageDirectory:"coverage",coverageReporters:["text","lcov","html"],collectCoverageFrom:["**/*.js","!**/node_modules/**","!**/test/**","!**/coverage/**","!jest.config.js","!**/dist/**","!build.js","!version-manager.js"],testTimeout:1e4,clearMocks:!0,verbose:!0};
1
+ module.exports={testEnvironment:"node",testMatch:["**/test/**/*.test.js","**/test/**/*.spec.js","**/__tests__/**/*.js"],testPathIgnorePatterns:["/node_modules/","<rootDir>/test/mysql/","<rootDir>/test/postgres/","<rootDir>/test/sqlite/sqlite-crud.test.js","<rootDir>/test/sqlite/sqlite-sync-all-tables.test.js","<rootDir>/test/sqlite/sqlite-table-sync.test.js","<rootDir>/test/sqlite/sqlite.test.js","<rootDir>/test/sqlite/crud-operations-coverage.test.js"],collectCoverage:!0,coverageDirectory:"coverage",coverageReporters:["text","lcov","html"],collectCoverageFrom:["**/*.js","!**/node_modules/**","!**/test/**","!**/coverage/**","!jest.config.js","!**/dist/**","!build.js","!version-manager.js"],testTimeout:1e4,clearMocks:!0,verbose:!0};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamtree-org/korm-js",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "description": "Knowledge Object-Relational Mapping - A powerful, modular ORM system for Node.js with dynamic database operations, complex queries, relationships, and nested requests",
5
5
  "author": {
6
6
  "name": "Partha Preetham Krishna",
@@ -9,20 +9,25 @@
9
9
  },
10
10
  "main": "index.js",
11
11
  "types": "index.d.ts",
12
+ "bin": {
13
+ "korm-js": "./cli.js"
14
+ },
12
15
  "scripts": {
13
16
  "test": "jest",
14
17
  "test:watch": "jest --watch",
15
18
  "test:coverage": "jest --coverage",
16
19
  "test:all": "jest --coverage --verbose",
20
+ "lint": "eslint . --max-warnings=0",
21
+ "lint:fix": "eslint . --fix",
22
+ "format": "prettier --write .",
23
+ "format:check": "prettier --check .",
24
+ "build:release": "npm run clean && npm run minify",
17
25
  "version:show": "node version-manager.js show",
18
26
  "version:current": "node version-manager.js current",
19
27
  "version:next": "node version-manager.js next",
20
28
  "version:auto": "node version-manager.js auto",
21
29
  "version:smart": "node version-manager.js smart",
22
30
  "version:update": "node version-manager.js update",
23
- "publish:patch": "npm run version:update patch && npm run build && npm publish",
24
- "publish:minor": "npm run version:update minor && npm run build && npm publish",
25
- "publish:major": "npm run version:update major && npm run build && npm publish",
26
31
  "docs": "echo \"Documentation available in doc/ directory\""
27
32
  },
28
33
  "keywords": [