@technicity/data-service-generator 0.14.0 → 0.14.1

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.
Files changed (34) hide show
  1. package/dist/generation/generate.d.ts +0 -1
  2. package/dist/generation/generate.js +309 -917
  3. package/dist/ksql.d.ts +15 -0
  4. package/dist/ksql.js +55 -0
  5. package/dist/runtime/Cache.js +3 -6
  6. package/dist/runtime/IRuntime.d.ts +17 -46
  7. package/dist/runtime/RuntimeKSQL.d.ts +19 -0
  8. package/dist/runtime/RuntimeKSQL.js +446 -0
  9. package/dist/runtime/RuntimeMSSQL.d.ts +1 -7
  10. package/dist/runtime/RuntimeMSSQL.js +4 -4
  11. package/dist/runtime/RuntimeMySQL.d.ts +1 -3
  12. package/dist/runtime/RuntimeMySQL.js +7 -33
  13. package/dist/runtime/lib/MSSQL.d.ts +1 -2
  14. package/dist/runtime/lib/MSSQL.js +8 -36
  15. package/dist/runtime/lib/MySQL.d.ts +1 -1
  16. package/dist/runtime/lib/MySQL.js +2 -15
  17. package/dist/runtime/lib/getSqlAst.js +121 -158
  18. package/dist/runtime/lib/runTransforms.d.ts +2 -0
  19. package/dist/runtime/lib/runTransforms.js +36 -0
  20. package/dist/runtime/lib/shared.d.ts +2 -1
  21. package/dist/runtime/lib/shared.js +71 -180
  22. package/dist/runtime/lib/stringifyWhere.js +12 -39
  23. package/dist/runtime/lib/typeCastMSSQL.js +1 -24
  24. package/dist/traverseFieldArgs.d.ts +2 -2
  25. package/dist/traverseFieldArgs.js +3 -8
  26. package/package.json +4 -1
  27. package/dist/runtime/RuntimeSQLite.d.ts +0 -38
  28. package/dist/runtime/RuntimeSQLite.js +0 -135
  29. package/dist/runtime/lib/addNullFallbacks.test.d.ts +0 -1
  30. package/dist/runtime/lib/addNullFallbacks.test.js +0 -206
  31. package/dist/runtime/lib/stringifyWhere.test.d.ts +0 -1
  32. package/dist/runtime/lib/stringifyWhere.test.js +0 -236
  33. package/dist/traverseFieldArgs.test.d.ts +0 -1
  34. package/dist/traverseFieldArgs.test.js +0 -56
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -48,5 +48,8 @@
48
48
  "sinon": "12.0.1",
49
49
  "testcontainers": "^9.1.3",
50
50
  "typescript": "4.6.4"
51
+ },
52
+ "resolutions": {
53
+ "xml2js": "0.5.0"
51
54
  }
52
55
  }
@@ -1,38 +0,0 @@
1
- import Database from "better-sqlite3";
2
- import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, ISupplementClientOpts } from "./IRuntime";
3
- import { MiddlewareHandler } from "./lib/shared";
4
- declare type TClientOpts = {
5
- filename: string;
6
- } & Parameters<typeof Database>[1];
7
- export declare class RuntimeSQLite implements IRuntime {
8
- #private;
9
- __middlewareHandler: MiddlewareHandler<TMiddleware>;
10
- constructor(clientOpts: TClientOpts, otherOpts: {
11
- createTablesString?: string;
12
- seedString?: string;
13
- supplementClientOpts?: ISupplementClientOpts;
14
- }, artifacts: IArtifacts);
15
- resolve(input: TResolveParams): Promise<any>;
16
- $queryRaw(sql: string, values?: any[]): Promise<any[] | {
17
- insertId: number | bigint;
18
- }>;
19
- $use(middleware: TMiddleware): Promise<void>;
20
- $whereNeedsProcessing(where: any): boolean;
21
- $prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
22
- $shutdown(): Promise<void>;
23
- $startTransaction(input?: {
24
- isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
25
- }): Promise<{
26
- commit: () => Promise<void>;
27
- rollback: () => Promise<void>;
28
- dbCall: (q: string) => Promise<any[] | {
29
- insertId: number | bigint;
30
- }>;
31
- }>;
32
- private dbCall;
33
- private formatQuery;
34
- private dbCallTransaction;
35
- private commit;
36
- private rollback;
37
- }
38
- export {};
@@ -1,135 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
- if (kind === "m") throw new TypeError("Private method is not writable");
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
28
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
29
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
30
- };
31
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
32
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
33
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
34
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
- };
36
- var __importDefault = (this && this.__importDefault) || function (mod) {
37
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
- };
39
- var _RuntimeSQLite_dialect, _RuntimeSQLite_db;
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.RuntimeSQLite = void 0;
42
- const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
43
- // @ts-expect-error
44
- const SqliteString = __importStar(require("sqlstring-sqlite"));
45
- const shared_1 = require("./lib/shared");
46
- class RuntimeSQLite {
47
- constructor(clientOpts, otherOpts, artifacts) {
48
- _RuntimeSQLite_dialect.set(this, "sqlite");
49
- _RuntimeSQLite_db.set(this, void 0);
50
- const { filename, ...restOpts } = clientOpts;
51
- this.__middlewareHandler = new shared_1.MiddlewareHandler();
52
- __classPrivateFieldSet(this, _RuntimeSQLite_db, new better_sqlite3_1.default(filename, restOpts), "f");
53
- if (clientOpts.filename === ":memory:") {
54
- if (!otherOpts.createTablesString) {
55
- throw new Error(`\`createTablesString\` must be supplied when filename is \`:memory:\`.`);
56
- }
57
- __classPrivateFieldGet(this, _RuntimeSQLite_db, "f").exec(otherOpts.createTablesString);
58
- if (otherOpts.seedString) {
59
- __classPrivateFieldGet(this, _RuntimeSQLite_db, "f").exec(otherOpts.seedString);
60
- }
61
- }
62
- }
63
- async resolve(input) {
64
- return (0, shared_1.resolve)(input, input.dbCall ?? this.dbCall.bind(this), this.formatQuery.bind(this), this.$startTransaction.bind(this), __classPrivateFieldGet(this, _RuntimeSQLite_dialect, "f"), this.__middlewareHandler, input.context ?? {});
65
- }
66
- async $queryRaw(sql, values) {
67
- return this.dbCall(this.formatQuery(sql, values ?? []));
68
- }
69
- async $use(middleware) {
70
- this.__middlewareHandler.register(middleware);
71
- }
72
- $whereNeedsProcessing(where) {
73
- return (0, shared_1.whereNeedsProcessing)(where);
74
- }
75
- async $prepareWhere(artifacts, table, data) {
76
- return (0, shared_1._prepareWhere)(artifacts, table, data, this.dbCall.bind(this), this.formatQuery.bind(this));
77
- }
78
- async $shutdown() {
79
- __classPrivateFieldGet(this, _RuntimeSQLite_db, "f").close();
80
- }
81
- async $startTransaction(input) {
82
- const isolationLevel = input?.isolationLevel;
83
- if (isolationLevel != null) {
84
- if (isolationLevel !== "READ UNCOMMITTED" &&
85
- isolationLevel !== "READ COMMITTED" &&
86
- isolationLevel !== "REPEATABLE READ" &&
87
- isolationLevel !== "SERIALIZABLE") {
88
- throw new Error(`Invalid isolationLevel: ${isolationLevel}`);
89
- }
90
- }
91
- __classPrivateFieldGet(this, _RuntimeSQLite_db, "f").prepare("BEGIN TRANSACTION").run();
92
- return {
93
- commit: this.commit.bind(this),
94
- rollback: this.rollback.bind(this),
95
- dbCall: this.dbCallTransaction.bind(this)
96
- };
97
- }
98
- async dbCall(q) {
99
- const statement = __classPrivateFieldGet(this, _RuntimeSQLite_db, "f").prepare(q);
100
- if (q.startsWith("INSERT") || q.startsWith("UPDATE") || q.startsWith("DELETE")) {
101
- const result = statement.run();
102
- return { insertId: result.lastInsertRowid };
103
- }
104
- // TODO: use statement.raw instead of typeCastSqlite? That would stop
105
- // working if we start joining instead of batching, though.
106
- // https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#rawtogglestate---this
107
- return statement.all();
108
- }
109
- formatQuery(q, values) {
110
- return SqliteString.format(q, values);
111
- }
112
- async dbCallTransaction(...args) {
113
- try {
114
- return await this.dbCall(...args);
115
- }
116
- catch (err) {
117
- __classPrivateFieldGet(this, _RuntimeSQLite_db, "f").prepare("ROLLBACK").run();
118
- throw err;
119
- }
120
- }
121
- async commit() {
122
- try {
123
- __classPrivateFieldGet(this, _RuntimeSQLite_db, "f").prepare("COMMIT").run();
124
- }
125
- catch (err) {
126
- __classPrivateFieldGet(this, _RuntimeSQLite_db, "f").prepare("ROLLBACK").run();
127
- throw err;
128
- }
129
- }
130
- async rollback() {
131
- __classPrivateFieldGet(this, _RuntimeSQLite_db, "f").prepare("ROLLBACK").run();
132
- }
133
- }
134
- exports.RuntimeSQLite = RuntimeSQLite;
135
- _RuntimeSQLite_dialect = new WeakMap(), _RuntimeSQLite_db = new WeakMap();
@@ -1 +0,0 @@
1
- export {};
@@ -1,206 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const globals_1 = require("@jest/globals");
7
- const strict_1 = __importDefault(require("node:assert/strict"));
8
- const addNullFallbacks_1 = require("./addNullFallbacks");
9
- (0, globals_1.describe)("addNullFallbacks", () => {
10
- // The actual AST has other fields like `args` that
11
- // aren't relevant to the function
12
- const sqlAST = {
13
- type: "table",
14
- name: "Session",
15
- as: "Session",
16
- fieldName: "session",
17
- grabMany: false,
18
- children: [
19
- {
20
- type: "column",
21
- name: "id",
22
- fieldName: "id",
23
- as: "a"
24
- },
25
- {
26
- type: "table",
27
- name: "SessionPlan",
28
- as: "SessionPlan",
29
- fieldName: "sessionPlan",
30
- grabMany: false,
31
- children: [
32
- {
33
- type: "column",
34
- name: "id",
35
- fieldName: "id",
36
- as: "a"
37
- },
38
- {
39
- type: "column",
40
- name: "uuid",
41
- fieldName: "uuid",
42
- as: "c"
43
- },
44
- {
45
- type: "column",
46
- name: "id",
47
- fieldName: "id",
48
- as: "a"
49
- }
50
- ]
51
- }
52
- ]
53
- };
54
- (0, globals_1.test)("should work for object", () => {
55
- const data = {
56
- id: 1,
57
- sessionPlanId: null,
58
- sessionPlan: undefined
59
- };
60
- (0, addNullFallbacks_1.addNullFallbacks)(sqlAST, data);
61
- strict_1.default.deepEqual(data, {
62
- id: 1,
63
- sessionPlanId: null,
64
- sessionPlan: null
65
- });
66
- });
67
- (0, globals_1.test)("should work for array", () => {
68
- const data = [
69
- {
70
- id: 1,
71
- sessionPlanId: null,
72
- sessionPlan: undefined
73
- },
74
- {
75
- id: 2,
76
- sessionPlanId: null,
77
- sessionPlan: undefined
78
- }
79
- ];
80
- (0, addNullFallbacks_1.addNullFallbacks)(sqlAST, data);
81
- strict_1.default.deepEqual(data, [
82
- {
83
- id: 1,
84
- sessionPlanId: null,
85
- sessionPlan: null
86
- },
87
- {
88
- id: 2,
89
- sessionPlanId: null,
90
- sessionPlan: null
91
- }
92
- ]);
93
- });
94
- (0, globals_1.test)("should work for nested array", () => {
95
- const sqlAST = {
96
- type: "table",
97
- name: "Session",
98
- as: "Session",
99
- fieldName: "session",
100
- grabMany: false,
101
- children: [
102
- {
103
- type: "column",
104
- name: "id",
105
- fieldName: "id",
106
- as: "a"
107
- },
108
- {
109
- type: "table",
110
- name: "SessionPlan",
111
- as: "SessionPlan",
112
- fieldName: "sessionPlan",
113
- grabMany: false,
114
- children: [
115
- {
116
- type: "column",
117
- name: "id",
118
- fieldName: "id",
119
- as: "a"
120
- },
121
- {
122
- type: "column",
123
- name: "uuid",
124
- fieldName: "uuid",
125
- as: "c"
126
- },
127
- {
128
- type: "column",
129
- name: "id",
130
- fieldName: "id",
131
- as: "a"
132
- },
133
- {
134
- type: "table",
135
- name: "SessionPlan",
136
- as: "SessionPlan",
137
- fieldName: "sessionPlan",
138
- grabMany: false,
139
- children: [
140
- {
141
- type: "column",
142
- name: "id",
143
- fieldName: "id",
144
- as: "a"
145
- },
146
- {
147
- type: "column",
148
- name: "uuid",
149
- fieldName: "uuid",
150
- as: "c"
151
- },
152
- {
153
- type: "column",
154
- name: "id",
155
- fieldName: "id",
156
- as: "a"
157
- }
158
- ]
159
- }
160
- ]
161
- }
162
- ]
163
- };
164
- const data = [
165
- {
166
- id: 1,
167
- sessionPlanId: 1,
168
- sessionPlan: {
169
- id: 1,
170
- uuid: "stub",
171
- sessionPlan: undefined
172
- }
173
- },
174
- {
175
- id: 2,
176
- sessionPlanId: 2,
177
- sessionPlan: {
178
- id: 2,
179
- uuid: "stub",
180
- sessionPlan: undefined
181
- }
182
- }
183
- ];
184
- (0, addNullFallbacks_1.addNullFallbacks)(sqlAST, data);
185
- strict_1.default.deepEqual(data, [
186
- {
187
- id: 1,
188
- sessionPlanId: 1,
189
- sessionPlan: {
190
- id: 1,
191
- uuid: "stub",
192
- sessionPlan: null
193
- }
194
- },
195
- {
196
- id: 2,
197
- sessionPlanId: 2,
198
- sessionPlan: {
199
- id: 2,
200
- uuid: "stub",
201
- sessionPlan: null
202
- }
203
- }
204
- ]);
205
- });
206
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,236 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const globals_1 = require("@jest/globals");
7
- const strict_1 = __importDefault(require("node:assert/strict"));
8
- const stringifyWhere_1 = require("./stringifyWhere");
9
- (0, globals_1.describe)("stringifyWhere", () => {
10
- const table = "Usr";
11
- const dialect = "mysql";
12
- const args = {};
13
- (0, globals_1.test)("should work", () => {
14
- const result = (0, stringifyWhere_1.stringifyWhere)({
15
- where: { userId: 2, text: "foo" },
16
- table,
17
- dialect,
18
- args
19
- });
20
- strict_1.default.deepEqual(result, "Usr.`userId` = 2 AND Usr.`text` = 'foo'");
21
- });
22
- (0, globals_1.test)("should handle empty object", () => {
23
- const result = (0, stringifyWhere_1.stringifyWhere)({ where: {}, table, dialect, args });
24
- strict_1.default.deepEqual(result, "");
25
- });
26
- (0, globals_1.test)("should handle $and", () => {
27
- const result = (0, stringifyWhere_1.stringifyWhere)({
28
- where: { $and: [{ valid: true }, { text: "foo" }] },
29
- table,
30
- dialect,
31
- args
32
- });
33
- strict_1.default.deepEqual(result, "(Usr.`valid` = 1 AND Usr.`text` = 'foo')");
34
- });
35
- (0, globals_1.test)("should handle $or", () => {
36
- const result = (0, stringifyWhere_1.stringifyWhere)({
37
- where: { $or: [{ valid: true }, { text: "foo" }] },
38
- table,
39
- dialect,
40
- args
41
- });
42
- strict_1.default.deepEqual(result, "(Usr.`valid` = 1 OR Usr.`text` = 'foo')");
43
- });
44
- (0, globals_1.test)("should handle null", () => {
45
- const result = (0, stringifyWhere_1.stringifyWhere)({
46
- where: { userId: null },
47
- table,
48
- dialect,
49
- args
50
- });
51
- strict_1.default.deepEqual(result, "Usr.`userId` IS NULL");
52
- });
53
- (0, globals_1.test)("should handle $neq", () => {
54
- const result = (0, stringifyWhere_1.stringifyWhere)({
55
- where: { userId: { $neq: 2 }, text: "foo" },
56
- table,
57
- dialect,
58
- args
59
- });
60
- strict_1.default.deepEqual(result, "Usr.`userId` != 2 AND Usr.`text` = 'foo'");
61
- });
62
- (0, globals_1.test)("should handle $gt", () => {
63
- const result = (0, stringifyWhere_1.stringifyWhere)({
64
- where: { userId: { $gt: 2 }, text: "foo" },
65
- table,
66
- dialect,
67
- args
68
- });
69
- strict_1.default.deepEqual(result, "Usr.`userId` > 2 AND Usr.`text` = 'foo'");
70
- });
71
- (0, globals_1.test)("should handle $gte", () => {
72
- const result = (0, stringifyWhere_1.stringifyWhere)({
73
- where: { userId: { $gte: 2 }, text: "foo" },
74
- table,
75
- dialect,
76
- args
77
- });
78
- strict_1.default.deepEqual(result, "Usr.`userId` >= 2 AND Usr.`text` = 'foo'");
79
- });
80
- (0, globals_1.test)("should handle $lt", () => {
81
- const result = (0, stringifyWhere_1.stringifyWhere)({
82
- where: { userId: { $lt: 2 }, text: "foo" },
83
- table,
84
- dialect,
85
- args
86
- });
87
- strict_1.default.deepEqual(result, "Usr.`userId` < 2 AND Usr.`text` = 'foo'");
88
- });
89
- (0, globals_1.test)("should handle $lte", () => {
90
- const result = (0, stringifyWhere_1.stringifyWhere)({
91
- where: { userId: { $lte: 2 }, text: "foo" },
92
- table,
93
- dialect,
94
- args
95
- });
96
- strict_1.default.deepEqual(result, "Usr.`userId` <= 2 AND Usr.`text` = 'foo'");
97
- });
98
- (0, globals_1.test)("should handle $like", () => {
99
- const result = (0, stringifyWhere_1.stringifyWhere)({
100
- where: { text: { $like: "%foo%" } },
101
- table,
102
- dialect,
103
- args
104
- });
105
- strict_1.default.deepEqual(result, "Usr.`text` LIKE '%foo%'");
106
- });
107
- (0, globals_1.test)("should handle $nlike", () => {
108
- const result = (0, stringifyWhere_1.stringifyWhere)({
109
- where: { text: { $nlike: "%foo%" } },
110
- table,
111
- dialect,
112
- args
113
- });
114
- strict_1.default.deepEqual(result, "Usr.`text` NOT LIKE '%foo%'");
115
- });
116
- (0, globals_1.test)("should handle $in", () => {
117
- const result = (0, stringifyWhere_1.stringifyWhere)({
118
- where: { userId: { $in: [1, 2] }, text: "foo" },
119
- table,
120
- dialect,
121
- args
122
- });
123
- strict_1.default.deepEqual(result, "Usr.`userId` IN (1,2) AND Usr.`text` = 'foo'");
124
- });
125
- (0, globals_1.test)("should handle empty $in", () => {
126
- const result = (0, stringifyWhere_1.stringifyWhere)({
127
- where: { userId: { $in: [] }, text: "foo" },
128
- table,
129
- dialect,
130
- args
131
- });
132
- strict_1.default.deepEqual(result, "(1=0) AND Usr.`text` = 'foo'");
133
- });
134
- (0, globals_1.test)("should handle $nin", () => {
135
- const result = (0, stringifyWhere_1.stringifyWhere)({
136
- where: { userId: { $nin: [1, 2] }, text: "foo" },
137
- table,
138
- dialect,
139
- args
140
- });
141
- strict_1.default.deepEqual(result, "Usr.`userId` NOT IN (1,2) AND Usr.`text` = 'foo'");
142
- });
143
- (0, globals_1.test)("should handle empty $nin", () => {
144
- const result = (0, stringifyWhere_1.stringifyWhere)({
145
- where: { userId: { $nin: [] }, text: "foo" },
146
- table,
147
- dialect,
148
- args
149
- });
150
- strict_1.default.deepEqual(result, "(1=1) AND Usr.`text` = 'foo'");
151
- });
152
- (0, globals_1.test)("should handle $btwn", () => {
153
- const result = (0, stringifyWhere_1.stringifyWhere)({
154
- where: { userId: { $btwn: [1, 20] }, text: "foo" },
155
- table,
156
- dialect,
157
- args
158
- });
159
- strict_1.default.deepEqual(result, "Usr.`userId` BETWEEN 1 AND 20 AND Usr.`text` = 'foo'");
160
- });
161
- (0, globals_1.test)("should handle $nbtwn", () => {
162
- const result = (0, stringifyWhere_1.stringifyWhere)({
163
- where: { userId: { $nbtwn: [1, 20] }, text: "foo" },
164
- table,
165
- dialect,
166
- args
167
- });
168
- strict_1.default.deepEqual(result, "Usr.`userId` NOT BETWEEN 1 AND 20 AND Usr.`text` = 'foo'");
169
- });
170
- (0, globals_1.test)("should handle nested $and and $or", () => {
171
- const result = (0, stringifyWhere_1.stringifyWhere)({
172
- where: {
173
- $and: [
174
- { userId: { $gt: 2 } },
175
- { $or: [{ text: { $like: "foo" } }, { text: { $like: "bar" } }] },
176
- { $and: [{ lala: "lala" }, { oioi: "oioi" }] }
177
- ]
178
- },
179
- table,
180
- dialect,
181
- args
182
- });
183
- strict_1.default.deepEqual(result, "(Usr.`userId` > 2 AND (Usr.`text` LIKE 'foo' OR Usr.`text` LIKE 'bar') AND (Usr.`lala` = 'lala' AND Usr.`oioi` = 'oioi'))");
184
- });
185
- (0, globals_1.test)("should throw on invalid operator", () => {
186
- strict_1.default.throws(() => (0, stringifyWhere_1.stringifyWhere)({
187
- where: { foo: { $foo: 3 } },
188
- table,
189
- dialect,
190
- args
191
- }), (error) => {
192
- (0, strict_1.default)(error instanceof Error);
193
- (0, strict_1.default)(error.message.startsWith("Invalid operator:"));
194
- return true;
195
- });
196
- });
197
- (0, globals_1.test)("should throw on more than 1 key for $and", () => {
198
- strict_1.default.throws(() => (0, stringifyWhere_1.stringifyWhere)({
199
- where: { $and: [{ foo: "bar" }, { bar: "baz" }], foo: "bar" },
200
- table,
201
- dialect,
202
- args
203
- }), (error) => {
204
- (0, strict_1.default)(error instanceof Error);
205
- (0, strict_1.default)(error.message.startsWith("Must have 1 key:"));
206
- return true;
207
- });
208
- });
209
- (0, globals_1.test)("ignores undefined values", () => {
210
- const result = (0, stringifyWhere_1.stringifyWhere)({
211
- where: { $or: [{ foo: "bar" }, { bar: null }, { baz: undefined }] },
212
- table,
213
- dialect,
214
- args
215
- });
216
- strict_1.default.deepEqual(result, "(Usr.`foo` = 'bar' OR Usr.`bar` IS NULL)");
217
- });
218
- (0, globals_1.test)("handles empty $and", () => {
219
- const result = (0, stringifyWhere_1.stringifyWhere)({
220
- where: { $and: [] },
221
- table,
222
- dialect,
223
- args
224
- });
225
- strict_1.default.deepEqual(result, "");
226
- });
227
- (0, globals_1.test)("handles empty $or", () => {
228
- const result = (0, stringifyWhere_1.stringifyWhere)({
229
- where: { $or: [] },
230
- table,
231
- dialect,
232
- args
233
- });
234
- strict_1.default.deepEqual(result, "");
235
- });
236
- });
@@ -1 +0,0 @@
1
- export {};