@technicity/data-service-generator 0.13.26 → 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.
@@ -1,30 +1,7 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.typeCastMSSQL = void 0;
27
- const mssql = __importStar(require("mssql"));
4
+ const mssql = require("mssql");
28
5
  // TODO: see https://github.com/tediousjs/node-mssql/pull/1171
29
6
  function typeCastMSSQL(customTypeCast) {
30
7
  return function (result, meta) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.13.26",
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,112 +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 runTransforms_1 = require("./runTransforms");
9
- (0, globals_1.describe)("runTransforms", () => {
10
- (0, globals_1.test)("should work", () => {
11
- const fields = [
12
- "id",
13
- {
14
- name: "business",
15
- as: "mainBusiness",
16
- fields: ["id", "name"],
17
- transform: (x) => {
18
- x.name = `TRANSFORMED_BUSINESS_NAME ${x.id}`;
19
- return x;
20
- }
21
- },
22
- {
23
- name: "sessionList",
24
- as: "mainSession",
25
- fields: [
26
- "id",
27
- {
28
- name: "deepNestedList",
29
- fields: ["id"],
30
- transform: (xs) => {
31
- return xs.map((x) => (x == null ? x : { ...x, id: x.id + 100 }));
32
- }
33
- },
34
- {
35
- name: "deepNestedList2",
36
- fields: ["id"],
37
- transform: (xs) => {
38
- return xs[0] ?? null;
39
- }
40
- }
41
- ],
42
- args: {
43
- $where: { valid: true, archived: false },
44
- $orderBy: { id: "desc" }
45
- },
46
- transform: (x) => {
47
- return x[0] ?? null;
48
- }
49
- },
50
- "name"
51
- ];
52
- const data = [
53
- {
54
- id: 1,
55
- mainBusiness: { id: 1, name: "My Business Name 1" },
56
- mainSession: [
57
- {
58
- id: 1,
59
- deepNestedList: [{ id: 1 }, null, { id: 2 }],
60
- deepNestedList2: [{ id: 1 }, null, { id: 2 }]
61
- },
62
- {
63
- id: 2,
64
- deepNestedList: [{ id: 1 }, null, { id: 2 }],
65
- deepNestedList2: [{ id: 1 }, null, { id: 2 }]
66
- }
67
- ],
68
- name: "FOO"
69
- },
70
- {
71
- id: 2,
72
- mainBusiness: { id: 2, name: "My Business Name 2" },
73
- mainSession: [
74
- {
75
- id: 1,
76
- deepNestedList: [{ id: 1 }, null, { id: 2 }],
77
- deepNestedList2: [{ id: 1 }, null, { id: 2 }]
78
- },
79
- {
80
- id: 2,
81
- deepNestedList: [{ id: 1 }, null, { id: 2 }],
82
- deepNestedList2: [{ id: 1 }, null, { id: 2 }]
83
- }
84
- ],
85
- name: "BAR"
86
- }
87
- ];
88
- (0, runTransforms_1.runTransforms)(data, fields);
89
- strict_1.default.deepEqual(data, [
90
- {
91
- id: 1,
92
- mainBusiness: { id: 1, name: "TRANSFORMED_BUSINESS_NAME 1" },
93
- mainSession: {
94
- id: 1,
95
- deepNestedList: [{ id: 101 }, null, { id: 102 }],
96
- deepNestedList2: { id: 1 }
97
- },
98
- name: "FOO"
99
- },
100
- {
101
- id: 2,
102
- mainBusiness: { id: 2, name: "TRANSFORMED_BUSINESS_NAME 2" },
103
- mainSession: {
104
- id: 1,
105
- deepNestedList: [{ id: 101 }, null, { id: 102 }],
106
- deepNestedList2: { id: 1 }
107
- },
108
- name: "BAR"
109
- }
110
- ]);
111
- });
112
- });
@@ -1 +0,0 @@
1
- export {};