@openfn/language-mssql 5.1.0 → 5.2.0
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/ast.json +54 -0
- package/dist/index.cjs +17 -12
- package/dist/index.js +19 -17
- package/package.json +2 -2
- package/types/Adaptor.d.ts +1 -1
package/ast.json
CHANGED
|
@@ -1273,6 +1273,60 @@
|
|
|
1273
1273
|
]
|
|
1274
1274
|
},
|
|
1275
1275
|
"valid": false
|
|
1276
|
+
},
|
|
1277
|
+
{
|
|
1278
|
+
"name": "as",
|
|
1279
|
+
"params": [
|
|
1280
|
+
"key",
|
|
1281
|
+
"operation"
|
|
1282
|
+
],
|
|
1283
|
+
"docs": {
|
|
1284
|
+
"description": "Run an operation and save the result to a custom key in state instead of overwriting state.data.",
|
|
1285
|
+
"tags": [
|
|
1286
|
+
{
|
|
1287
|
+
"title": "public",
|
|
1288
|
+
"description": null,
|
|
1289
|
+
"type": null
|
|
1290
|
+
},
|
|
1291
|
+
{
|
|
1292
|
+
"title": "function",
|
|
1293
|
+
"description": null,
|
|
1294
|
+
"name": null
|
|
1295
|
+
},
|
|
1296
|
+
{
|
|
1297
|
+
"title": "example",
|
|
1298
|
+
"description": "as('cceData', collections.get('cce-data-dhis2', { key: `*:*:${$.syncedAt}*` }));",
|
|
1299
|
+
"caption": "Fetch cce-data from collections and store them under state.cceData"
|
|
1300
|
+
},
|
|
1301
|
+
{
|
|
1302
|
+
"title": "param",
|
|
1303
|
+
"description": "The state key to assign the result of the operation to.",
|
|
1304
|
+
"type": {
|
|
1305
|
+
"type": "NameExpression",
|
|
1306
|
+
"name": "string"
|
|
1307
|
+
},
|
|
1308
|
+
"name": "key"
|
|
1309
|
+
},
|
|
1310
|
+
{
|
|
1311
|
+
"title": "param",
|
|
1312
|
+
"description": " An operation that returns a new state object with a `data` property",
|
|
1313
|
+
"type": {
|
|
1314
|
+
"type": "NameExpression",
|
|
1315
|
+
"name": "function"
|
|
1316
|
+
},
|
|
1317
|
+
"name": "operation"
|
|
1318
|
+
},
|
|
1319
|
+
{
|
|
1320
|
+
"title": "returns",
|
|
1321
|
+
"description": null,
|
|
1322
|
+
"type": {
|
|
1323
|
+
"type": "NameExpression",
|
|
1324
|
+
"name": "Operation"
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
]
|
|
1328
|
+
},
|
|
1329
|
+
"valid": true
|
|
1276
1330
|
}
|
|
1277
1331
|
]
|
|
1278
1332
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var src_exports = {};
|
|
21
21
|
__export(src_exports, {
|
|
22
22
|
alterState: () => import_language_common2.alterState,
|
|
23
|
+
as: () => import_language_common2.as,
|
|
23
24
|
combine: () => import_language_common2.combine,
|
|
24
25
|
cursor: () => import_language_common2.cursor,
|
|
25
26
|
dataPath: () => import_language_common2.dataPath,
|
|
@@ -54,6 +55,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
54
55
|
var Adaptor_exports = {};
|
|
55
56
|
__export(Adaptor_exports, {
|
|
56
57
|
alterState: () => import_language_common2.alterState,
|
|
58
|
+
as: () => import_language_common2.as,
|
|
57
59
|
combine: () => import_language_common2.combine,
|
|
58
60
|
cursor: () => import_language_common2.cursor,
|
|
59
61
|
dataPath: () => import_language_common2.dataPath,
|
|
@@ -81,6 +83,7 @@ __export(Adaptor_exports, {
|
|
|
81
83
|
upsertMany: () => upsertMany
|
|
82
84
|
});
|
|
83
85
|
var import_language_common = require("@openfn/language-common");
|
|
86
|
+
var import_util = require("@openfn/language-common/util");
|
|
84
87
|
|
|
85
88
|
// src/util.js
|
|
86
89
|
var util_exports = {};
|
|
@@ -214,7 +217,8 @@ function sql(params) {
|
|
|
214
217
|
return (state) => {
|
|
215
218
|
const { connection } = state;
|
|
216
219
|
try {
|
|
217
|
-
const
|
|
220
|
+
const [resolvedParams] = (0, import_util.expandReferences)(state, params);
|
|
221
|
+
const { query, options } = resolvedParams;
|
|
218
222
|
console.log(`Preparing to execute sql statement: ${query}`);
|
|
219
223
|
return queryHandler(state, query, composeNextState, options);
|
|
220
224
|
} catch (e) {
|
|
@@ -252,8 +256,8 @@ function findValue(filter) {
|
|
|
252
256
|
return (state) => {
|
|
253
257
|
const { connection } = state;
|
|
254
258
|
const { uuid, relation, where, operator } = filter;
|
|
255
|
-
const whereData = (0,
|
|
256
|
-
const operatorData = (0,
|
|
259
|
+
const [whereData] = (0, import_util.expandReferences)(state, where);
|
|
260
|
+
const [operatorData] = (0, import_util.expandReferences)(state, operator);
|
|
257
261
|
let conditionsArray = [];
|
|
258
262
|
for (let key in whereData) {
|
|
259
263
|
const escapedValue = escape(whereData[key]);
|
|
@@ -295,7 +299,7 @@ function insert(table, record, options) {
|
|
|
295
299
|
return (state) => {
|
|
296
300
|
const { connection } = state;
|
|
297
301
|
try {
|
|
298
|
-
const recordData = (0,
|
|
302
|
+
const [recordData] = (0, import_util.expandReferences)(state, record);
|
|
299
303
|
const columns = Object.keys(recordData).sort();
|
|
300
304
|
const values = columns.map((key) => escape(recordData[key])).join("', '");
|
|
301
305
|
const query = handleValues(
|
|
@@ -320,7 +324,7 @@ function insertMany(table, records, options) {
|
|
|
320
324
|
return (state) => {
|
|
321
325
|
const { connection } = state;
|
|
322
326
|
try {
|
|
323
|
-
const recordData = (0,
|
|
327
|
+
const [recordData] = (0, import_util.expandReferences)(state, records);
|
|
324
328
|
const columns = Object.keys(recordData[0]);
|
|
325
329
|
const valueSets = recordData.map(
|
|
326
330
|
(x) => `('${escape(Object.values(x)).join("', '")}')`
|
|
@@ -349,7 +353,7 @@ function upsert(table, uuid, record, options) {
|
|
|
349
353
|
return (state) => {
|
|
350
354
|
const { connection } = state;
|
|
351
355
|
try {
|
|
352
|
-
const recordData = (0,
|
|
356
|
+
const [recordData] = (0, import_util.expandReferences)(state, record);
|
|
353
357
|
const columns = Object.keys(recordData).sort();
|
|
354
358
|
const selectValues = columns.map((key) => `'${escape(recordData[key])}' AS ${key}`).join(", ");
|
|
355
359
|
const updateValues = columns.map((key) => `[Target].${key}='${escape(recordData[key])}'`).join(", ");
|
|
@@ -395,9 +399,9 @@ function upsertIf(logical, table, uuid, record, options) {
|
|
|
395
399
|
return (state) => {
|
|
396
400
|
const { connection } = state;
|
|
397
401
|
try {
|
|
398
|
-
const recordData = (0,
|
|
402
|
+
const [recordData] = (0, import_util.expandReferences)(state, record);
|
|
399
403
|
const columns = Object.keys(recordData).sort();
|
|
400
|
-
const logicalData = (0,
|
|
404
|
+
const [logicalData] = (0, import_util.expandReferences)(state, logical);
|
|
401
405
|
return new Promise((resolve, reject) => {
|
|
402
406
|
if (!logicalData) {
|
|
403
407
|
console.log(`Skipping upsert for ${uuid}.`);
|
|
@@ -447,7 +451,7 @@ function upsertMany(table, uuid, records, options) {
|
|
|
447
451
|
return (state) => {
|
|
448
452
|
const { connection } = state;
|
|
449
453
|
try {
|
|
450
|
-
const recordData = (0,
|
|
454
|
+
const [recordData] = (0, import_util.expandReferences)(state, records);
|
|
451
455
|
return new Promise((resolve, reject) => {
|
|
452
456
|
if (!recordData || recordData.length === 0) {
|
|
453
457
|
console.log("No records provided; skipping upsert.");
|
|
@@ -498,7 +502,7 @@ function upsertMany(table, uuid, records, options) {
|
|
|
498
502
|
function describeTable(tableName, options) {
|
|
499
503
|
return (state) => {
|
|
500
504
|
const { connection } = state;
|
|
501
|
-
const name = (0,
|
|
505
|
+
const [name] = (0, import_util.expandReferences)(state, tableName);
|
|
502
506
|
try {
|
|
503
507
|
const query = `SELECT column_name
|
|
504
508
|
FROM information_schema.columns
|
|
@@ -516,7 +520,7 @@ function insertTable(tableName, columns, options) {
|
|
|
516
520
|
return (state) => {
|
|
517
521
|
const { connection } = state;
|
|
518
522
|
try {
|
|
519
|
-
const data = (0,
|
|
523
|
+
const [data] = (0, import_util.expandReferences)(state, columns);
|
|
520
524
|
return new Promise((resolve, reject) => {
|
|
521
525
|
if (!data || data.length === 0) {
|
|
522
526
|
console.log("No columns provided; skipping table creation.");
|
|
@@ -542,7 +546,7 @@ function modifyTable(tableName, columns, options) {
|
|
|
542
546
|
return (state) => {
|
|
543
547
|
const { connection } = state;
|
|
544
548
|
try {
|
|
545
|
-
const data = (0,
|
|
549
|
+
const [data] = (0, import_util.expandReferences)(state, columns);
|
|
546
550
|
return new Promise((resolve, reject) => {
|
|
547
551
|
if (!data || data.length === 0) {
|
|
548
552
|
console.log("No columns provided; skipping table modification.");
|
|
@@ -568,6 +572,7 @@ var src_default = Adaptor_exports;
|
|
|
568
572
|
// Annotate the CommonJS export names for ESM import in node:
|
|
569
573
|
0 && (module.exports = {
|
|
570
574
|
alterState,
|
|
575
|
+
as,
|
|
571
576
|
combine,
|
|
572
577
|
cursor,
|
|
573
578
|
dataPath,
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
var Adaptor_exports = {};
|
|
9
9
|
__export(Adaptor_exports, {
|
|
10
10
|
alterState: () => alterState,
|
|
11
|
+
as: () => as,
|
|
11
12
|
combine: () => combine,
|
|
12
13
|
cursor: () => cursor,
|
|
13
14
|
dataPath: () => dataPath,
|
|
@@ -34,10 +35,8 @@ __export(Adaptor_exports, {
|
|
|
34
35
|
upsertIf: () => upsertIf,
|
|
35
36
|
upsertMany: () => upsertMany
|
|
36
37
|
});
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
expandReferences
|
|
40
|
-
} from "@openfn/language-common";
|
|
38
|
+
import { execute as commonExecute } from "@openfn/language-common";
|
|
39
|
+
import { expandReferences } from "@openfn/language-common/util";
|
|
41
40
|
|
|
42
41
|
// src/util.js
|
|
43
42
|
var util_exports = {};
|
|
@@ -70,7 +69,8 @@ import {
|
|
|
70
69
|
lastReferenceValue,
|
|
71
70
|
cursor,
|
|
72
71
|
merge,
|
|
73
|
-
sourceValue
|
|
72
|
+
sourceValue,
|
|
73
|
+
as
|
|
74
74
|
} from "@openfn/language-common";
|
|
75
75
|
function createConnection(state) {
|
|
76
76
|
const {
|
|
@@ -187,7 +187,8 @@ function sql(params) {
|
|
|
187
187
|
return (state) => {
|
|
188
188
|
const { connection } = state;
|
|
189
189
|
try {
|
|
190
|
-
const
|
|
190
|
+
const [resolvedParams] = expandReferences(state, params);
|
|
191
|
+
const { query, options } = resolvedParams;
|
|
191
192
|
console.log(`Preparing to execute sql statement: ${query}`);
|
|
192
193
|
return queryHandler(state, query, composeNextState, options);
|
|
193
194
|
} catch (e) {
|
|
@@ -225,8 +226,8 @@ function findValue(filter) {
|
|
|
225
226
|
return (state) => {
|
|
226
227
|
const { connection } = state;
|
|
227
228
|
const { uuid, relation, where, operator } = filter;
|
|
228
|
-
const whereData = expandReferences(where)
|
|
229
|
-
const operatorData = expandReferences(operator)
|
|
229
|
+
const [whereData] = expandReferences(state, where);
|
|
230
|
+
const [operatorData] = expandReferences(state, operator);
|
|
230
231
|
let conditionsArray = [];
|
|
231
232
|
for (let key in whereData) {
|
|
232
233
|
const escapedValue = escape(whereData[key]);
|
|
@@ -268,7 +269,7 @@ function insert(table, record, options) {
|
|
|
268
269
|
return (state) => {
|
|
269
270
|
const { connection } = state;
|
|
270
271
|
try {
|
|
271
|
-
const recordData = expandReferences(record)
|
|
272
|
+
const [recordData] = expandReferences(state, record);
|
|
272
273
|
const columns = Object.keys(recordData).sort();
|
|
273
274
|
const values = columns.map((key) => escape(recordData[key])).join("', '");
|
|
274
275
|
const query = handleValues(
|
|
@@ -293,7 +294,7 @@ function insertMany(table, records, options) {
|
|
|
293
294
|
return (state) => {
|
|
294
295
|
const { connection } = state;
|
|
295
296
|
try {
|
|
296
|
-
const recordData = expandReferences(records)
|
|
297
|
+
const [recordData] = expandReferences(state, records);
|
|
297
298
|
const columns = Object.keys(recordData[0]);
|
|
298
299
|
const valueSets = recordData.map(
|
|
299
300
|
(x) => `('${escape(Object.values(x)).join("', '")}')`
|
|
@@ -322,7 +323,7 @@ function upsert(table, uuid, record, options) {
|
|
|
322
323
|
return (state) => {
|
|
323
324
|
const { connection } = state;
|
|
324
325
|
try {
|
|
325
|
-
const recordData = expandReferences(record)
|
|
326
|
+
const [recordData] = expandReferences(state, record);
|
|
326
327
|
const columns = Object.keys(recordData).sort();
|
|
327
328
|
const selectValues = columns.map((key) => `'${escape(recordData[key])}' AS ${key}`).join(", ");
|
|
328
329
|
const updateValues = columns.map((key) => `[Target].${key}='${escape(recordData[key])}'`).join(", ");
|
|
@@ -368,9 +369,9 @@ function upsertIf(logical, table, uuid, record, options) {
|
|
|
368
369
|
return (state) => {
|
|
369
370
|
const { connection } = state;
|
|
370
371
|
try {
|
|
371
|
-
const recordData = expandReferences(record)
|
|
372
|
+
const [recordData] = expandReferences(state, record);
|
|
372
373
|
const columns = Object.keys(recordData).sort();
|
|
373
|
-
const logicalData = expandReferences(logical)
|
|
374
|
+
const [logicalData] = expandReferences(state, logical);
|
|
374
375
|
return new Promise((resolve, reject) => {
|
|
375
376
|
if (!logicalData) {
|
|
376
377
|
console.log(`Skipping upsert for ${uuid}.`);
|
|
@@ -420,7 +421,7 @@ function upsertMany(table, uuid, records, options) {
|
|
|
420
421
|
return (state) => {
|
|
421
422
|
const { connection } = state;
|
|
422
423
|
try {
|
|
423
|
-
const recordData = expandReferences(records)
|
|
424
|
+
const [recordData] = expandReferences(state, records);
|
|
424
425
|
return new Promise((resolve, reject) => {
|
|
425
426
|
if (!recordData || recordData.length === 0) {
|
|
426
427
|
console.log("No records provided; skipping upsert.");
|
|
@@ -471,7 +472,7 @@ function upsertMany(table, uuid, records, options) {
|
|
|
471
472
|
function describeTable(tableName, options) {
|
|
472
473
|
return (state) => {
|
|
473
474
|
const { connection } = state;
|
|
474
|
-
const name = expandReferences(tableName)
|
|
475
|
+
const [name] = expandReferences(state, tableName);
|
|
475
476
|
try {
|
|
476
477
|
const query = `SELECT column_name
|
|
477
478
|
FROM information_schema.columns
|
|
@@ -489,7 +490,7 @@ function insertTable(tableName, columns, options) {
|
|
|
489
490
|
return (state) => {
|
|
490
491
|
const { connection } = state;
|
|
491
492
|
try {
|
|
492
|
-
const data = expandReferences(columns)
|
|
493
|
+
const [data] = expandReferences(state, columns);
|
|
493
494
|
return new Promise((resolve, reject) => {
|
|
494
495
|
if (!data || data.length === 0) {
|
|
495
496
|
console.log("No columns provided; skipping table creation.");
|
|
@@ -515,7 +516,7 @@ function modifyTable(tableName, columns, options) {
|
|
|
515
516
|
return (state) => {
|
|
516
517
|
const { connection } = state;
|
|
517
518
|
try {
|
|
518
|
-
const data = expandReferences(columns)
|
|
519
|
+
const [data] = expandReferences(state, columns);
|
|
519
520
|
return new Promise((resolve, reject) => {
|
|
520
521
|
if (!data || data.length === 0) {
|
|
521
522
|
console.log("No columns provided; skipping table modification.");
|
|
@@ -540,6 +541,7 @@ function modifyTable(tableName, columns, options) {
|
|
|
540
541
|
var src_default = Adaptor_exports;
|
|
541
542
|
export {
|
|
542
543
|
alterState,
|
|
544
|
+
as,
|
|
543
545
|
combine,
|
|
544
546
|
cursor,
|
|
545
547
|
dataPath,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-mssql",
|
|
3
3
|
"label": "MSSQL",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.2.0",
|
|
5
5
|
"description": "A Microsoft SQL language pack for OpenFn",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"tedious": "18.6.1",
|
|
29
|
-
"@openfn/language-common": "
|
|
29
|
+
"@openfn/language-common": "3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"assertion-error": "2.0.0",
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -170,4 +170,4 @@ export function insertTable(tableName: string, columns: any[], options: object):
|
|
|
170
170
|
* @returns {Operation}
|
|
171
171
|
*/
|
|
172
172
|
export function modifyTable(tableName: string, columns: any[], options: object): Operation;
|
|
173
|
-
export { alterState, combine, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, http, lastReferenceValue, cursor, merge, sourceValue } from "@openfn/language-common";
|
|
173
|
+
export { alterState, combine, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, http, lastReferenceValue, cursor, merge, sourceValue, as } from "@openfn/language-common";
|