From c46ab2a6c691211b2f93d9ecd5dbd85860672554 Mon Sep 17 00:00:00 2001 From: Phil Gale Date: Sun, 24 Sep 2023 11:18:43 +0100 Subject: [PATCH 1/6] first patches --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8630802c6..e4c1682b6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "objection", + "name": "objection-edge", "version": "3.1.1", - "description": "An SQL-friendly ORM for Node.js", + "description": "An SQL-friendly ORM for Node.js, with edge runtime patches", "main": "lib/objection.js", "license": "MIT", "scripts": { From f94df22b5144b5c5e732e87e840522db947ade95 Mon Sep 17 00:00:00 2001 From: Phil Gale Date: Sun, 24 Sep 2023 11:27:21 +0100 Subject: [PATCH 2/6] tweaks --- lib/utils/resolveModel.js | 67 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/lib/utils/resolveModel.js b/lib/utils/resolveModel.js index 3e7d17876..301cd94cd 100644 --- a/lib/utils/resolveModel.js +++ b/lib/utils/resolveModel.js @@ -1,10 +1,69 @@ 'use strict'; -const path = require('path'); const { isString, isFunction } = require('../utils/objectUtils'); class ResolveError extends Error {} +function customResolve() { + const parts = Array.from(arguments); + let resolvedPath = ''; + + for (let i = 0; i < parts.length; i++) { + const part = parts[i]; + + if (typeof part !== 'string') { + throw new TypeError('Arguments to customResolve must be strings'); + } + + if (i === 0) { + // Handle the first part separately to preserve any leading '/' + resolvedPath += part; + } else { + // Join path parts with '/' + resolvedPath += '/' + part; + } + } + + // Normalize the resolved path by removing redundant slashes + return resolvedPath.replace(/\/{2,}/g, '/'); +} +function customPathNormalize(inputPath) { + const separator = process.platform === 'win32' ? '\\' : '/'; + + // Split the inputPath into segments using the appropriate separator + const segments = inputPath.split(/[/\\]/); + + // Initialize an array to store the normalized path segments + const normalizedSegments = []; + + for (const segment of segments) { + if (segment === '..') { + // Handle '..' to go up one directory level + if (normalizedSegments.length > 0 && normalizedSegments[normalizedSegments.length - 1] !== '..') { + normalizedSegments.pop(); + } else { + normalizedSegments.push('..'); + } + } else if (segment !== '.') { + // Skip '.' segments + normalizedSegments.push(segment); + } + } + + // Join the normalized segments back together with the appropriate separator + return normalizedSegments.join(separator); +} +function customPathJoin() { + let separator = '/'; + const segments = Array.from(arguments); + + // Normalize backslashes to slashes if on Windows + if (process.platform === 'win32') { + separator = '\\'; + } + + return segments.join(separator); +} function resolveModel(modelRef, modelPaths, errorPrefix) { try { if (isString(modelRef)) { @@ -40,7 +99,7 @@ function requireUsingModelPaths(modelRef, modelPaths) { for (const modelPath of modelPaths) { try { - return requireModel(path.join(modelPath, modelRef)); + return requireModel(customPathJoin(modelPath, modelRef)); } catch (err) { if (firstError === null) { firstError = err; @@ -62,7 +121,7 @@ function requireModel(modelPath) { * in webpack builds. * @link https://github.com/webpack/webpack/issues/196 */ - let mod = require(`${path.resolve(modelPath)}`); + let mod = require(`${customResolve(modelPath)}`); let modelClass = null; if (isModelClass(mod)) { @@ -94,7 +153,7 @@ function requireModel(modelPath) { } function isAbsolutePath(pth) { - return path.normalize(pth + '/') === path.normalize(path.resolve(pth) + '/'); + return customPathNormalize(pth + '/') === customPathNormalize(customResolve(pth) + '/'); } function isModelClass(maybeModel) { From c944d80171042ab7013dc4d0b53fb0d75ace02df Mon Sep 17 00:00:00 2001 From: Phil Gale Date: Sun, 24 Sep 2023 11:41:04 +0100 Subject: [PATCH 3/6] linty --- lib/utils/resolveModel.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/utils/resolveModel.js b/lib/utils/resolveModel.js index 301cd94cd..b69f27a3c 100644 --- a/lib/utils/resolveModel.js +++ b/lib/utils/resolveModel.js @@ -39,7 +39,10 @@ function customPathNormalize(inputPath) { for (const segment of segments) { if (segment === '..') { // Handle '..' to go up one directory level - if (normalizedSegments.length > 0 && normalizedSegments[normalizedSegments.length - 1] !== '..') { + if ( + normalizedSegments.length > 0 && + normalizedSegments[normalizedSegments.length - 1] !== '..' + ) { normalizedSegments.pop(); } else { normalizedSegments.push('..'); From 4e2f85e79298578554c29154dd700b2c0492d7cd Mon Sep 17 00:00:00 2001 From: Phil Gale Date: Sun, 24 Sep 2023 11:43:33 +0100 Subject: [PATCH 4/6] tweaked ver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e4c1682b6..5271e1624 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "objection-edge", - "version": "3.1.1", + "version": "4.0.0", "description": "An SQL-friendly ORM for Node.js, with edge runtime patches", "main": "lib/objection.js", "license": "MIT", From 6af0e33c512392d2bc9a16a867dcb73c0594f098 Mon Sep 17 00:00:00 2001 From: Phil Gale Date: Sun, 24 Sep 2023 11:47:30 +0100 Subject: [PATCH 5/6] package tweaks --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5271e1624..4ee881d6d 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ "tag": "latest" }, "author": { - "name": "Sami Koskimäki", - "email": "sami@jakso.me", - "url": "https://github.com/koskimas" + "name": "Phil Gale", + "email": "phil.gale92@gmail.com", + "url": "https://github.com/philgale92" }, "contributors": [ "Sami Koskimäki (https://github.com/koskimas)", From 8fc5a6370f35f403d4f884a1c6ed1b78e85d783e Mon Sep 17 00:00:00 2001 From: Phil Gale Date: Sun, 8 Oct 2023 18:23:52 +0100 Subject: [PATCH 6/6] tweaked name of package --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4ee881d6d..cf9c7b5f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "objection-edge", - "version": "4.0.0", + "name": "objection-edgeruntime", + "version": "3.0.0", "description": "An SQL-friendly ORM for Node.js, with edge runtime patches", "main": "lib/objection.js", "license": "MIT",