forge-sql-orm 1.0.22 → 1.0.24

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.
@@ -19,6 +19,16 @@ export interface ForgeSqlOperation extends QueryBuilderForgeSql {
19
19
  fetch(): SchemaSqlForgeSql;
20
20
  }
21
21
 
22
+ /**
23
+ * Options for configuring ForgeSQL ORM behavior.
24
+ */
25
+ export interface ForgeSqlOrmOptions {
26
+ /**
27
+ * Enables logging of raw SQL queries in the Atlassian Forge Developer Console.
28
+ */
29
+ logRawSqlQuery?: boolean;
30
+ }
31
+
22
32
  /**
23
33
  * Interface for schema-level SQL operations.
24
34
  */
@@ -96,5 +106,10 @@ export interface QueryBuilderForgeSql {
96
106
  loggerContext?: LoggingOptions,
97
107
  ): QueryBuilder<Entity, RootAlias>;
98
108
 
109
+ /**
110
+ * Provides access to the underlying Knex instance for building complex query parts.
111
+ * enabling advanced query customization and performance tuning.
112
+ * @returns The Knex instance, which can be used for query building.
113
+ */
99
114
  getKnex(): Knex<any, any[]>;
100
115
  }
@@ -1,9 +1,15 @@
1
1
  import { sql, UpdateQueryResponse } from "@forge/sql";
2
2
  import type { EntitySchema } from "@mikro-orm/core/metadata/EntitySchema";
3
3
  import { parseDateTime } from "../utils/sqlUtils";
4
- import { SchemaSqlForgeSql } from "./ForgeSQLQueryBuilder";
4
+ import { ForgeSqlOrmOptions, SchemaSqlForgeSql } from "./ForgeSQLQueryBuilder";
5
5
 
6
6
  export class ForgeSQLSelectOperations implements SchemaSqlForgeSql {
7
+ private readonly options: ForgeSqlOrmOptions;
8
+
9
+ constructor(options: ForgeSqlOrmOptions) {
10
+ this.options = options;
11
+ }
12
+
7
13
  /**
8
14
  * Executes a schema-based SQL query and maps the result to the entity schema.
9
15
  * @param query - The SQL query to execute.
@@ -23,7 +29,7 @@ export class ForgeSQLSelectOperations implements SchemaSqlForgeSql {
23
29
  .forEach((p) => {
24
30
  const fieldName = p.name;
25
31
  const fieldNames = p.fieldNames;
26
- const rawFieldName = fieldNames && Array.isArray(fieldNames)? fieldNames[0]: p.name;
32
+ const rawFieldName = fieldNames && Array.isArray(fieldNames) ? fieldNames[0] : p.name;
27
33
 
28
34
  switch (p.type) {
29
35
  case "datetime":
@@ -52,9 +58,10 @@ export class ForgeSQLSelectOperations implements SchemaSqlForgeSql {
52
58
  * @returns A list of results as objects.
53
59
  */
54
60
  async executeRawSQL<T extends object | unknown>(query: string): Promise<T[]> {
55
- console.debug("Executing raw SQL: " + query);
61
+ if (this.options.logRawSqlQuery) {
62
+ console.debug("Executing raw SQL: " + query);
63
+ }
56
64
  const sqlStatement = await sql.prepare<T>(query).execute();
57
- console.debug("Query result: " + JSON.stringify(sqlStatement));
58
65
  return sqlStatement.rows as T[];
59
66
  }
60
67
 
@@ -64,7 +71,9 @@ export class ForgeSQLSelectOperations implements SchemaSqlForgeSql {
64
71
  * @returns The update response containing affected rows.
65
72
  */
66
73
  async executeRawUpdateSQL(query: string): Promise<UpdateQueryResponse> {
67
- console.debug("Executing update SQL: " + query);
74
+ if (this.options.logRawSqlQuery) {
75
+ console.debug("Executing update SQL: " + query);
76
+ }
68
77
  const sqlStatement = sql.prepare<UpdateQueryResponse>(query);
69
78
  const updateQueryResponseResults = await sqlStatement.execute();
70
79
  return updateQueryResponseResults.rows;
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";let argv=process.argv.slice(2);if(argv.includes("-h")||argv.includes("--help")){let e="";e+=`
3
- Usage
4
- $ tsm [options] -- <command>
5
- `,e+=`
6
- Options`,e+=`
7
- --tsmconfig Configuration file path (default: tsm.js)`,e+=`
8
- --quiet Silence all terminal messages`,e+=`
9
- --version Displays current version`,e+=`
10
- --help Displays this message
11
- `,e+=`
12
- Examples`,e+=`
13
- $ tsm server.ts`,e+=`
14
- $ node -r tsm input.jsx`,e+=`
15
- $ node --loader tsm input.jsx`,e+=`
16
- $ NO_COLOR=1 tsm input.jsx --trace-warnings`,e+=`
17
- $ tsm server.tsx --tsmconfig tsm.mjs
18
- `,console.log(e),process.exit(0)}(argv.includes("-v")||argv.includes("--version"))&&(console.log("tsm, v2.3.0"),process.exit(0));let{URL,pathToFileURL}=require("url");argv=["--enable-source-maps","--loader",new URL("loader.mjs",pathToFileURL(__filename)).href,...argv],require("child_process").spawn("node",argv,{stdio:"inherit"}).on("exit",process.exit);
@@ -1,22 +0,0 @@
1
- import type { Loader, TransformOptions } from 'esbuild';
2
-
3
- export type Extension = `.${string}`;
4
- export type Options = TransformOptions;
5
-
6
- export type Config = {
7
- [extn: Extension]: Options;
8
- }
9
-
10
- export type ConfigFile =
11
- | { common?: Options; config?: Config; loaders?: never; [extn: Extension]: never }
12
- | { common?: Options; loaders?: Loaders; config?: never; [extn: Extension]: never }
13
- | { common?: Options; config?: never; loaders?: never; [extn: Extension]: Options }
14
-
15
- export type Loaders = {
16
- [extn: Extension]: Loader;
17
- }
18
-
19
- /**
20
- * TypeScript helper for writing `tsm.js` contents.
21
- */
22
- export function define(contents: ConfigFile): ConfigFile;
@@ -1 +0,0 @@
1
- exports.define=c=>c;
@@ -1,9 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1 +0,0 @@
1
- "use strict";import{existsSync as j,promises as S}from"fs";import{fileURLToPath as d,URL as h}from"url";import*as y from"./utils.js";let u,m,c=y.$defaults("esm"),T=c.file&&import("file:///"+c.file);async function x(){let t=await T;return t=t&&t.default||t,y.$finalize(c,t)}const w=/\.\w+(?=\?|$)/,b=/\.[mc]?tsx?(?=\?|$)/;async function p(t){u=u||await x();let[r]=w.exec(t)||[];return u[r]}function g(t){let r=d(t);if(j(r))return t}const C={".js":[".ts",".tsx",".jsx"],".jsx":[".tsx"],".mjs":[".mts"],".cjs":[".cts"]},R=new h("file:///"+process.cwd()+"/");export const resolve=async function(t,r,o){if(/^\w+\:?/.test(t))return o(t,r,o);let e=new h(t,r.parentURL||R),s,n,l,i,a=0,f;if(i=w.exec(e.href)){if(s=i[0],!r.parentURL||b.test(s))return{url:e.href,shortCircuit:!0};if(n=g(e.href))return{url:n,shortCircuit:!0};if(l=C[s]){for(f=e.href.substring(0,i.index);a<l.length;a++)if(n=g(f+l[a]))return a=i.index+s.length,{shortCircuit:!0,url:a>e.href.length?f+e.href.substring(a):n}}return o(t,r,o)}u=u||await x();for(s in u)if(n=g(e.href+s),n)return{url:n,shortCircuit:!0};return o(t,r,o)},load=async function(t,r,o){let e=await p(t);if(e==null)return o(t,r,o);let s=e.format==="cjs"?"commonjs":"module",n=d(t),l=await S.readFile(n);m=m||await import("esbuild");let i=await m.transform(l.toString(),{...e,sourcefile:n,format:s==="module"?"esm":"cjs"});return{format:s,source:i.code,shortCircuit:!0}},getFormat=async function(t,r,o){let e=await p(t);return e==null?o(t,r,o):{format:e.format==="cjs"?"commonjs":"module"}},transformSource=async function(t,r,o){let e=await p(r.url);return e==null?o(t,r,o):(m=m||await import("esbuild"),{source:(await m.transform(t.toString(),{...e,sourcefile:r.url,format:r.format==="module"?"esm":"cjs"})).code})};
@@ -1,51 +0,0 @@
1
- {
2
- "name": "tsm",
3
- "version": "2.3.0",
4
- "repository": "lukeed/tsm",
5
- "description": "TypeScript Module Loader",
6
- "license": "MIT",
7
- "bin": "bin.js",
8
- "author": {
9
- "name": "Luke Edwards",
10
- "email": "luke.edwards05@gmail.com",
11
- "url": "https://lukeed.com"
12
- },
13
- "exports": {
14
- ".": {
15
- "import": "./loader.mjs",
16
- "require": "./require.js"
17
- },
18
- "./config": "./config/index.js",
19
- "./package.json": "./package.json"
20
- },
21
- "files": [
22
- "bin.js",
23
- "utils.js",
24
- "require.js",
25
- "loader.mjs",
26
- "config"
27
- ],
28
- "engines": {
29
- "node": ">=12"
30
- },
31
- "scripts": {
32
- "build": "node build",
33
- "types": "tsc --skipLibCheck"
34
- },
35
- "dependencies": {
36
- "esbuild": "^0.15.16"
37
- },
38
- "devDependencies": {
39
- "@types/node": "16.11.6",
40
- "@types/react": "17.0.33",
41
- "typescript": "4.9.3"
42
- },
43
- "keywords": [
44
- "esm",
45
- "loader",
46
- "typescript",
47
- "loader hook",
48
- "require hook",
49
- "experimental-loader"
50
- ]
51
- }
@@ -1,62 +0,0 @@
1
- <div align="center">
2
- <img src="logo.png" alt="tsm" width="200" />
3
- </div>
4
-
5
- <div align="center">
6
- <a href="https://npmjs.org/package/tsm">
7
- <img src="https://badgen.net/npm/v/tsm" alt="version" />
8
- </a>
9
- <a href="https://github.com/lukeed/tsm/actions">
10
- <img src="https://github.com/lukeed/tsm/workflows/CI/badge.svg" alt="CI" />
11
- </a>
12
- <a href="https://npmjs.org/package/tsm">
13
- <img src="https://badgen.net/npm/dm/tsm" alt="downloads" />
14
- </a>
15
- <a href="https://packagephobia.now.sh/result?p=tsm">
16
- <img src="https://badgen.net/packagephobia/publish/tsm" alt="publish size" />
17
- </a>
18
- </div>
19
-
20
- <div align="center">TypeScript Module Loader</div>
21
-
22
- ## Features
23
-
24
- * Supports `node <file>` usage
25
- * Supports [ESM `--loader`](https://nodejs.org/api/esm.html#esm_loaders) usage<sup>†</sup>
26
- * Supports [`--require` hook](https://nodejs.org/api/cli.html#cli_r_require_module) usage
27
- * Optional [configuration](/docs/configuration.md) file for per-extension customization
28
-
29
- > <sup>†</sup> The ESM Loader API is still **experimental** and will change in the future.
30
-
31
- ## Install
32
-
33
- ```sh
34
- # install as project dependency
35
- $ npm install --save-dev tsm
36
-
37
- # or install globally
38
- $ npm install --global tsm
39
- ```
40
-
41
- ## Usage
42
-
43
- > **Note:** Refer to [`/docs/usage.md`](/docs/usage.md) for more information.
44
-
45
- ```sh
46
- # use as `node` replacement
47
- $ tsm server.ts
48
-
49
- # forwards any `node` ENV or flags
50
- $ NO_COLOR=1 tsm server.ts --trace-warnings
51
-
52
- # use as `--require` hook
53
- $ node --require tsm server.tsx
54
- $ node -r tsm server.tsx
55
-
56
- # use as `--loader` hook
57
- $ node --loader tsm main.jsx
58
- ```
59
-
60
- ## License
61
-
62
- MIT © [Luke Edwards](https://lukeed.com)
@@ -1 +0,0 @@
1
- "use strict";const{readFileSync}=require("fs"),{extname}=require("path"),tsm=require("./utils"),loadJS=require.extensions[".js"];let esbuild,env=tsm.$defaults("cjs"),uconf=env.file&&require(env.file),config=tsm.$finalize(env,uconf);const tsrequire='var $$req=require("module").createRequire(__filename);require=('+function(){let{existsSync:t}=$$req("fs"),r=$$req("url");return new Proxy(require,{apply(l,n,o){let[e]=o;if(!e)return l.apply(n||$$req,o);if(/^\w+\:?/.test(e))return $$req(e);let u=/\.([mc])?[tj]sx?(?=\?|$)/.exec(e);if(u==null)return $$req(e);let f=r.pathToFileURL(__filename),s=r.fileURLToPath(new r.URL(e,f));if(t(s))return $$req(e);let p=u[0],a=new RegExp(p+"$"),i=s.replace(a,p.replace("js","ts"));return t(i)||p===".js"&&(i=s.replace(a,".tsx"),t(i)||(i=s.replace(a,".jsx"),t(i)))?$$req(i):$$req(e)}})}+")();";function transform(t,r){return esbuild=esbuild||require("esbuild"),esbuild.transformSync(t,r).code}function loader(t,r){let l=extname(r),n=config[l]||{},o=t._compile.bind(t);n.sourcefile=r,/\.[mc]?[tj]sx?$/.test(l)&&(n.banner=tsrequire+(n.banner||""),n.supported=n.supported||{},n.supported["dynamic-import"]=!1),config[l]!=null&&(t._compile=e=>{let u=transform(e,n);return o(u,r)});try{return loadJS(t,r)}catch(e){if((e&&e.code)!=="ERR_REQUIRE_ESM")throw e;let f=readFileSync(r,"utf8"),s=transform(f,{...n,format:"cjs"});return o(s,r)}}for(let t in config)require.extensions[t]=loader;config[".js"]==null&&(require.extensions[".js"]=loader);
@@ -1 +0,0 @@
1
- "use strict";const{resolve}=require("path"),{existsSync}=require("fs");exports.$defaults=function(l){let{FORCE_COLOR:e,NO_COLOR:s,NODE_DISABLE_COLORS:o,TERM:t}=process.env,i=process.argv.slice(2),n=new Set(i),f=n.has("-q")||n.has("--quiet"),d=!o&&s==null&&t!=="dumb"&&(e!=null&&e!=="0"||process.stdout.isTTY),r=n.has("--tsmconfig")?i.indexOf("--tsmconfig"):-1,a=resolve(".",!!~r&&i[++r]||"tsm.js");return{file:existsSync(a)&&a,isESM:l==="esm",options:{format:l,charset:"utf8",sourcemap:"inline",target:"node"+process.versions.node,logLevel:f?"silent":"warning",color:d}}},exports.$finalize=function(l,e){let s=l.options;e&&e.common&&(Object.assign(s,e.common),delete e.common);let o={".mts":{...s,loader:"ts"},".jsx":{...s,loader:"jsx"},".tsx":{...s,loader:"tsx"},".cts":{...s,loader:"ts"},".ts":{...s,loader:"ts"}};l.isESM?o[".json"]={...s,loader:"json"}:o[".mjs"]={...s,loader:"js"};let t;if(e&&e.loaders)for(t in e.loaders)o[t]={...s,loader:e.loaders[t]};else if(e){let i=e.config||e;for(t in i)o[t]={...s,...i[t]}}return o};