arkormx 2.0.0 → 2.0.2
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/README.md +2 -1
- package/dist/index.cjs +91 -39
- package/dist/index.d.cts +403 -393
- package/dist/index.d.mts +403 -393
- package/dist/index.mjs +91 -39
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -3044,9 +3044,42 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
3044
3044
|
if (value instanceof Date) return `'${value.toISOString().replace(/'/g, "''")}'`;
|
|
3045
3045
|
return `'${String(value).replace(/'/g, "''")}'`;
|
|
3046
3046
|
}
|
|
3047
|
+
interpolateRawSql(sourceSql, bindings = []) {
|
|
3048
|
+
if (bindings.length === 0) return sourceSql;
|
|
3049
|
+
let bindingIndex = 0;
|
|
3050
|
+
return sourceSql.replace(/\?/g, () => {
|
|
3051
|
+
const value = bindings[bindingIndex];
|
|
3052
|
+
bindingIndex += 1;
|
|
3053
|
+
return this.quoteLiteral(value);
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3047
3056
|
async executeRawStatement(statement, executor = this.db) {
|
|
3048
3057
|
await sql.raw(statement).execute(executor);
|
|
3049
3058
|
}
|
|
3059
|
+
async rawQuery(spec) {
|
|
3060
|
+
const statement = this.interpolateRawSql(spec.sql, spec.bindings);
|
|
3061
|
+
try {
|
|
3062
|
+
return (await sql.raw(statement).execute(this.db)).rows ?? [];
|
|
3063
|
+
} catch (error) {
|
|
3064
|
+
throw new QueryExecutionException("Raw query execution failed for the Kysely adapter.", {
|
|
3065
|
+
code: "QUERY_EXECUTION_FAILED",
|
|
3066
|
+
operation: "adapter.rawQuery",
|
|
3067
|
+
delegate: "raw",
|
|
3068
|
+
inspection: this.tryInspectRawQuery(statement),
|
|
3069
|
+
meta: { sql: statement },
|
|
3070
|
+
cause: error
|
|
3071
|
+
});
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
tryInspectRawQuery(statement) {
|
|
3075
|
+
return {
|
|
3076
|
+
adapter: "kysely",
|
|
3077
|
+
operation: "select",
|
|
3078
|
+
target: "raw",
|
|
3079
|
+
sql: statement,
|
|
3080
|
+
parameters: []
|
|
3081
|
+
};
|
|
3082
|
+
}
|
|
3050
3083
|
resolveSchemaColumnName(columnName, columns = []) {
|
|
3051
3084
|
return columns.find((column) => column.name === columnName)?.map ?? columnName;
|
|
3052
3085
|
}
|
|
@@ -6382,45 +6415,6 @@ const defineFactory = (model, definition) => {
|
|
|
6382
6415
|
return new InlineFactory(model, definition);
|
|
6383
6416
|
};
|
|
6384
6417
|
|
|
6385
|
-
//#endregion
|
|
6386
|
-
//#region src/helpers/runtime-compatibility.ts
|
|
6387
|
-
const isObjectLike = (value) => {
|
|
6388
|
-
return Boolean(value) && typeof value === "object";
|
|
6389
|
-
};
|
|
6390
|
-
const isCompatibilityClient = (value) => {
|
|
6391
|
-
return Boolean(value) && typeof value === "object";
|
|
6392
|
-
};
|
|
6393
|
-
const getCompatibilitySources = (preferredClient) => {
|
|
6394
|
-
const activeTransactionClient = getActiveTransactionClient();
|
|
6395
|
-
const runtimeClient = getRuntimeClient();
|
|
6396
|
-
return activeTransactionClient ? [
|
|
6397
|
-
activeTransactionClient,
|
|
6398
|
-
preferredClient,
|
|
6399
|
-
runtimeClient
|
|
6400
|
-
] : [preferredClient, runtimeClient];
|
|
6401
|
-
};
|
|
6402
|
-
const getRuntimeCompatibilityAdapter = (preferredClient) => {
|
|
6403
|
-
const client = getCompatibilitySources(preferredClient).find((source) => isCompatibilityClient(source));
|
|
6404
|
-
if (!client) return void 0;
|
|
6405
|
-
return createPrismaCompatibilityAdapter(client);
|
|
6406
|
-
};
|
|
6407
|
-
const resolveRuntimeCompatibilityQuerySchema = (candidates, preferredClient) => {
|
|
6408
|
-
return getCompatibilitySources(preferredClient).flatMap((source) => {
|
|
6409
|
-
if (!isObjectLike(source)) return [];
|
|
6410
|
-
return candidates.map((candidate) => source[candidate]);
|
|
6411
|
-
}).find((candidate) => isQuerySchemaLike(candidate));
|
|
6412
|
-
};
|
|
6413
|
-
const resolveRuntimeCompatibilityQuerySchemaOrThrow = (key, candidates, modelName, preferredClient) => {
|
|
6414
|
-
const resolved = resolveRuntimeCompatibilityQuerySchema(candidates, preferredClient);
|
|
6415
|
-
if (!resolved) throw new MissingDelegateException(`Database delegate [${key}] is not configured.`, {
|
|
6416
|
-
operation: "getDelegate",
|
|
6417
|
-
model: modelName,
|
|
6418
|
-
delegate: key,
|
|
6419
|
-
meta: { candidates }
|
|
6420
|
-
});
|
|
6421
|
-
return resolved;
|
|
6422
|
-
};
|
|
6423
|
-
|
|
6424
6418
|
//#endregion
|
|
6425
6419
|
//#region src/URLDriver.ts
|
|
6426
6420
|
/**
|
|
@@ -9015,6 +9009,45 @@ var QueryBuilder = class QueryBuilder {
|
|
|
9015
9009
|
}
|
|
9016
9010
|
};
|
|
9017
9011
|
|
|
9012
|
+
//#endregion
|
|
9013
|
+
//#region src/helpers/runtime-compatibility.ts
|
|
9014
|
+
const isObjectLike = (value) => {
|
|
9015
|
+
return Boolean(value) && typeof value === "object";
|
|
9016
|
+
};
|
|
9017
|
+
const isCompatibilityClient = (value) => {
|
|
9018
|
+
return Boolean(value) && typeof value === "object";
|
|
9019
|
+
};
|
|
9020
|
+
const getCompatibilitySources = (preferredClient) => {
|
|
9021
|
+
const activeTransactionClient = getActiveTransactionClient();
|
|
9022
|
+
const runtimeClient = getRuntimeClient();
|
|
9023
|
+
return activeTransactionClient ? [
|
|
9024
|
+
activeTransactionClient,
|
|
9025
|
+
preferredClient,
|
|
9026
|
+
runtimeClient
|
|
9027
|
+
] : [preferredClient, runtimeClient];
|
|
9028
|
+
};
|
|
9029
|
+
const getRuntimeCompatibilityAdapter = (preferredClient) => {
|
|
9030
|
+
const client = getCompatibilitySources(preferredClient).find((source) => isCompatibilityClient(source));
|
|
9031
|
+
if (!client) return void 0;
|
|
9032
|
+
return createPrismaCompatibilityAdapter(client);
|
|
9033
|
+
};
|
|
9034
|
+
const resolveRuntimeCompatibilityQuerySchema = (candidates, preferredClient) => {
|
|
9035
|
+
return getCompatibilitySources(preferredClient).flatMap((source) => {
|
|
9036
|
+
if (!isObjectLike(source)) return [];
|
|
9037
|
+
return candidates.map((candidate) => source[candidate]);
|
|
9038
|
+
}).find((candidate) => isQuerySchemaLike(candidate));
|
|
9039
|
+
};
|
|
9040
|
+
const resolveRuntimeCompatibilityQuerySchemaOrThrow = (key, candidates, modelName, preferredClient) => {
|
|
9041
|
+
const resolved = resolveRuntimeCompatibilityQuerySchema(candidates, preferredClient);
|
|
9042
|
+
if (!resolved) throw new MissingDelegateException(`Database delegate [${key}] is not configured.`, {
|
|
9043
|
+
operation: "getDelegate",
|
|
9044
|
+
model: modelName,
|
|
9045
|
+
delegate: key,
|
|
9046
|
+
meta: { candidates }
|
|
9047
|
+
});
|
|
9048
|
+
return resolved;
|
|
9049
|
+
};
|
|
9050
|
+
|
|
9018
9051
|
//#endregion
|
|
9019
9052
|
//#region src/DB.ts
|
|
9020
9053
|
const defaultSoftDeleteConfig = {
|
|
@@ -9045,6 +9078,25 @@ var DB = class DB {
|
|
|
9045
9078
|
table(table, options = {}) {
|
|
9046
9079
|
return DB.createTableModel(table, options, this.getAdapter()).query();
|
|
9047
9080
|
}
|
|
9081
|
+
static async raw(sql, bindings = []) {
|
|
9082
|
+
return await new DB().raw(sql, bindings);
|
|
9083
|
+
}
|
|
9084
|
+
async raw(sql, bindings = []) {
|
|
9085
|
+
const adapter = this.getAdapter();
|
|
9086
|
+
if (!adapter) throw new ArkormException("Raw queries require a configured database adapter.", {
|
|
9087
|
+
code: "ADAPTER_NOT_CONFIGURED",
|
|
9088
|
+
operation: "db.raw"
|
|
9089
|
+
});
|
|
9090
|
+
if (!adapter.rawQuery) throw new UnsupportedAdapterFeatureException("Raw queries are not supported by the current adapter.", {
|
|
9091
|
+
operation: "db.raw",
|
|
9092
|
+
meta: { feature: "rawQuery" }
|
|
9093
|
+
});
|
|
9094
|
+
const rows = await adapter.rawQuery({
|
|
9095
|
+
sql,
|
|
9096
|
+
bindings
|
|
9097
|
+
});
|
|
9098
|
+
return ArkormCollection.make(rows);
|
|
9099
|
+
}
|
|
9048
9100
|
static async transaction(callback, context) {
|
|
9049
9101
|
return await new DB().transaction(callback, context);
|
|
9050
9102
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arkormx",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Modern TypeScript-first ORM for Node.js.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"orm",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@types/express": "^4.17.21",
|
|
53
53
|
"@types/node": "^20.10.6",
|
|
54
54
|
"@types/pg": "^8.15.5",
|
|
55
|
-
"@vitest/coverage-v8": "4.1.
|
|
55
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
56
56
|
"barrelize": "^1.7.3",
|
|
57
57
|
"eslint": "^10.0.0",
|
|
58
58
|
"prisma": "^7.6.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"typescript-eslint": "^8.56.0",
|
|
63
63
|
"vite-tsconfig-paths": "^6.1.1",
|
|
64
64
|
"vitepress": "2.0.0-alpha.16",
|
|
65
|
-
"vitest": "^4.1.
|
|
65
|
+
"vitest": "^4.1.5"
|
|
66
66
|
},
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=20.0.0"
|