arkormx 2.0.1 → 2.0.3

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 CHANGED
@@ -3,9 +3,10 @@
3
3
  [![NPM Downloads](https://img.shields.io/npm/dt/arkormx.svg)](https://www.npmjs.com/package/arkormx)
4
4
  [![npm version](https://img.shields.io/npm/v/arkormx.svg)](https://www.npmjs.com/package/arkormx)
5
5
  [![License](https://img.shields.io/npm/l/arkormx.svg)](https://github.com/arkstack-hq/arkormx/blob/main/LICENSE)
6
+ [![codecov](https://codecov.io/gh/arkstack-hq/arkormx/graph/badge.svg?token=ls1VVoFkYh)](https://codecov.io/gh/arkstack-hq/arkormx)
6
7
  [![CI](https://github.com/arkstack-hq/arkormx/actions/workflows/ci.yml/badge.svg)](https://github.com/arkstack-hq/arkormx/actions/workflows/ci.yml)
7
8
  [![Deploy Documentation](https://github.com/arkstack-hq/arkormx/actions/workflows/deploy-docs.yml/badge.svg)](https://github.com/arkstack-hq/arkormx/actions/workflows/deploy-docs.yml)
8
- [![codecov](https://codecov.io/gh/arkstack-hq/arkormx/graph/badge.svg?token=ls1VVoFkYh)](https://codecov.io/gh/arkstack-hq/arkormx)
9
+ [![Publish to NPM](https://github.com/arkstack-hq/arkormx/actions/workflows/publish.yml/badge.svg)](https://github.com/arkstack-hq/arkormx/actions/workflows/publish.yml)
9
10
 
10
11
  Arkormˣ is a framework-agnostic ORM designed to run anywhere Node.js runs. It brings a familiar model layer and fluent query builder on top of adapter-backed execution, with Prisma compatibility available as an optional 2.x compatibility path.
11
12
 
package/dist/index.cjs CHANGED
@@ -3073,9 +3073,42 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
3073
3073
  if (value instanceof Date) return `'${value.toISOString().replace(/'/g, "''")}'`;
3074
3074
  return `'${String(value).replace(/'/g, "''")}'`;
3075
3075
  }
3076
+ interpolateRawSql(sourceSql, bindings = []) {
3077
+ if (bindings.length === 0) return sourceSql;
3078
+ let bindingIndex = 0;
3079
+ return sourceSql.replace(/\?/g, () => {
3080
+ const value = bindings[bindingIndex];
3081
+ bindingIndex += 1;
3082
+ return this.quoteLiteral(value);
3083
+ });
3084
+ }
3076
3085
  async executeRawStatement(statement, executor = this.db) {
3077
3086
  await kysely.sql.raw(statement).execute(executor);
3078
3087
  }
3088
+ async rawQuery(spec) {
3089
+ const statement = this.interpolateRawSql(spec.sql, spec.bindings);
3090
+ try {
3091
+ return (await kysely.sql.raw(statement).execute(this.db)).rows ?? [];
3092
+ } catch (error) {
3093
+ throw new QueryExecutionException("Raw query execution failed for the Kysely adapter.", {
3094
+ code: "QUERY_EXECUTION_FAILED",
3095
+ operation: "adapter.rawQuery",
3096
+ delegate: "raw",
3097
+ inspection: this.tryInspectRawQuery(statement),
3098
+ meta: { sql: statement },
3099
+ cause: error
3100
+ });
3101
+ }
3102
+ }
3103
+ tryInspectRawQuery(statement) {
3104
+ return {
3105
+ adapter: "kysely",
3106
+ operation: "select",
3107
+ target: "raw",
3108
+ sql: statement,
3109
+ parameters: []
3110
+ };
3111
+ }
3079
3112
  resolveSchemaColumnName(columnName, columns = []) {
3080
3113
  return columns.find((column) => column.name === columnName)?.map ?? columnName;
3081
3114
  }
@@ -6411,45 +6444,6 @@ const defineFactory = (model, definition) => {
6411
6444
  return new InlineFactory(model, definition);
6412
6445
  };
6413
6446
 
6414
- //#endregion
6415
- //#region src/helpers/runtime-compatibility.ts
6416
- const isObjectLike = (value) => {
6417
- return Boolean(value) && typeof value === "object";
6418
- };
6419
- const isCompatibilityClient = (value) => {
6420
- return Boolean(value) && typeof value === "object";
6421
- };
6422
- const getCompatibilitySources = (preferredClient) => {
6423
- const activeTransactionClient = getActiveTransactionClient();
6424
- const runtimeClient = getRuntimeClient();
6425
- return activeTransactionClient ? [
6426
- activeTransactionClient,
6427
- preferredClient,
6428
- runtimeClient
6429
- ] : [preferredClient, runtimeClient];
6430
- };
6431
- const getRuntimeCompatibilityAdapter = (preferredClient) => {
6432
- const client = getCompatibilitySources(preferredClient).find((source) => isCompatibilityClient(source));
6433
- if (!client) return void 0;
6434
- return createPrismaCompatibilityAdapter(client);
6435
- };
6436
- const resolveRuntimeCompatibilityQuerySchema = (candidates, preferredClient) => {
6437
- return getCompatibilitySources(preferredClient).flatMap((source) => {
6438
- if (!isObjectLike(source)) return [];
6439
- return candidates.map((candidate) => source[candidate]);
6440
- }).find((candidate) => isQuerySchemaLike(candidate));
6441
- };
6442
- const resolveRuntimeCompatibilityQuerySchemaOrThrow = (key, candidates, modelName, preferredClient) => {
6443
- const resolved = resolveRuntimeCompatibilityQuerySchema(candidates, preferredClient);
6444
- if (!resolved) throw new MissingDelegateException(`Database delegate [${key}] is not configured.`, {
6445
- operation: "getDelegate",
6446
- model: modelName,
6447
- delegate: key,
6448
- meta: { candidates }
6449
- });
6450
- return resolved;
6451
- };
6452
-
6453
6447
  //#endregion
6454
6448
  //#region src/URLDriver.ts
6455
6449
  /**
@@ -9044,6 +9038,45 @@ var QueryBuilder = class QueryBuilder {
9044
9038
  }
9045
9039
  };
9046
9040
 
9041
+ //#endregion
9042
+ //#region src/helpers/runtime-compatibility.ts
9043
+ const isObjectLike = (value) => {
9044
+ return Boolean(value) && typeof value === "object";
9045
+ };
9046
+ const isCompatibilityClient = (value) => {
9047
+ return Boolean(value) && typeof value === "object";
9048
+ };
9049
+ const getCompatibilitySources = (preferredClient) => {
9050
+ const activeTransactionClient = getActiveTransactionClient();
9051
+ const runtimeClient = getRuntimeClient();
9052
+ return activeTransactionClient ? [
9053
+ activeTransactionClient,
9054
+ preferredClient,
9055
+ runtimeClient
9056
+ ] : [preferredClient, runtimeClient];
9057
+ };
9058
+ const getRuntimeCompatibilityAdapter = (preferredClient) => {
9059
+ const client = getCompatibilitySources(preferredClient).find((source) => isCompatibilityClient(source));
9060
+ if (!client) return void 0;
9061
+ return createPrismaCompatibilityAdapter(client);
9062
+ };
9063
+ const resolveRuntimeCompatibilityQuerySchema = (candidates, preferredClient) => {
9064
+ return getCompatibilitySources(preferredClient).flatMap((source) => {
9065
+ if (!isObjectLike(source)) return [];
9066
+ return candidates.map((candidate) => source[candidate]);
9067
+ }).find((candidate) => isQuerySchemaLike(candidate));
9068
+ };
9069
+ const resolveRuntimeCompatibilityQuerySchemaOrThrow = (key, candidates, modelName, preferredClient) => {
9070
+ const resolved = resolveRuntimeCompatibilityQuerySchema(candidates, preferredClient);
9071
+ if (!resolved) throw new MissingDelegateException(`Database delegate [${key}] is not configured.`, {
9072
+ operation: "getDelegate",
9073
+ model: modelName,
9074
+ delegate: key,
9075
+ meta: { candidates }
9076
+ });
9077
+ return resolved;
9078
+ };
9079
+
9047
9080
  //#endregion
9048
9081
  //#region src/DB.ts
9049
9082
  const defaultSoftDeleteConfig = {
@@ -9074,6 +9107,25 @@ var DB = class DB {
9074
9107
  table(table, options = {}) {
9075
9108
  return DB.createTableModel(table, options, this.getAdapter()).query();
9076
9109
  }
9110
+ static async raw(sql, bindings = []) {
9111
+ return await new DB().raw(sql, bindings);
9112
+ }
9113
+ async raw(sql, bindings = []) {
9114
+ const adapter = this.getAdapter();
9115
+ if (!adapter) throw new ArkormException("Raw queries require a configured database adapter.", {
9116
+ code: "ADAPTER_NOT_CONFIGURED",
9117
+ operation: "db.raw"
9118
+ });
9119
+ if (!adapter.rawQuery) throw new UnsupportedAdapterFeatureException("Raw queries are not supported by the current adapter.", {
9120
+ operation: "db.raw",
9121
+ meta: { feature: "rawQuery" }
9122
+ });
9123
+ const rows = await adapter.rawQuery({
9124
+ sql,
9125
+ bindings
9126
+ });
9127
+ return ArkormCollection.make(rows);
9128
+ }
9077
9129
  static async transaction(callback, context) {
9078
9130
  return await new DB().transaction(callback, context);
9079
9131
  }