@openfn/language-mysql 2.1.5 → 2.2.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.
package/ast.json CHANGED
@@ -925,6 +925,60 @@
925
925
  ]
926
926
  },
927
927
  "valid": false
928
+ },
929
+ {
930
+ "name": "as",
931
+ "params": [
932
+ "key",
933
+ "operation"
934
+ ],
935
+ "docs": {
936
+ "description": "Run an operation and save the result to a custom key in state instead of overwriting state.data.",
937
+ "tags": [
938
+ {
939
+ "title": "public",
940
+ "description": null,
941
+ "type": null
942
+ },
943
+ {
944
+ "title": "function",
945
+ "description": null,
946
+ "name": null
947
+ },
948
+ {
949
+ "title": "example",
950
+ "description": "as('cceData', collections.get('cce-data-dhis2', { key: `*:*:${$.syncedAt}*` }));",
951
+ "caption": "Fetch cce-data from collections and store them under state.cceData"
952
+ },
953
+ {
954
+ "title": "param",
955
+ "description": "The state key to assign the result of the operation to.",
956
+ "type": {
957
+ "type": "NameExpression",
958
+ "name": "string"
959
+ },
960
+ "name": "key"
961
+ },
962
+ {
963
+ "title": "param",
964
+ "description": " An operation that returns a new state object with a `data` property",
965
+ "type": {
966
+ "type": "NameExpression",
967
+ "name": "function"
968
+ },
969
+ "name": "operation"
970
+ },
971
+ {
972
+ "title": "returns",
973
+ "description": null,
974
+ "type": {
975
+ "type": "NameExpression",
976
+ "name": "Operation"
977
+ }
978
+ }
979
+ ]
980
+ },
981
+ "valid": true
928
982
  }
929
983
  ]
930
984
  }
package/dist/index.cjs CHANGED
@@ -27,6 +27,7 @@ var src_exports = {};
27
27
  __export(src_exports, {
28
28
  alterState: () => import_language_common2.alterState,
29
29
  arrayToString: () => import_language_common2.arrayToString,
30
+ as: () => import_language_common2.as,
30
31
  combine: () => import_language_common2.combine,
31
32
  cursor: () => import_language_common2.cursor,
32
33
  dataPath: () => import_language_common2.dataPath,
@@ -56,6 +57,7 @@ var Adaptor_exports = {};
56
57
  __export(Adaptor_exports, {
57
58
  alterState: () => import_language_common2.alterState,
58
59
  arrayToString: () => import_language_common2.arrayToString,
60
+ as: () => import_language_common2.as,
59
61
  combine: () => import_language_common2.combine,
60
62
  cursor: () => import_language_common2.cursor,
61
63
  dataPath: () => import_language_common2.dataPath,
@@ -78,6 +80,7 @@ __export(Adaptor_exports, {
78
80
  upsertMany: () => upsertMany
79
81
  });
80
82
  var import_language_common = require("@openfn/language-common");
83
+ var import_util = require("@openfn/language-common/util");
81
84
  var import_mysql = __toESM(require("mysql"), 1);
82
85
  var import_squel = __toESM(require("squel"), 1);
83
86
  var import_language_common2 = require("@openfn/language-common");
@@ -119,7 +122,7 @@ function cleanupState(state) {
119
122
  function insert(table, fields2) {
120
123
  return (state) => {
121
124
  let { connection } = state;
122
- const valuesObj = (0, import_language_common.expandReferences)(fields2)(state);
125
+ const [valuesObj] = (0, import_util.expandReferences)(state, fields2);
123
126
  const squelMysql = import_squel.default.useFlavour("mysql");
124
127
  var sqlParams = squelMysql.insert({
125
128
  autoQuoteFieldNames: true
@@ -150,7 +153,7 @@ function insert(table, fields2) {
150
153
  function upsert(table, fields2) {
151
154
  return (state) => {
152
155
  let { connection } = state;
153
- const valuesObj = (0, import_language_common.expandReferences)(fields2)(state);
156
+ const [valuesObj] = (0, import_util.expandReferences)(state, fields2);
154
157
  const squelMysql = import_squel.default.useFlavour("mysql");
155
158
  var insertParams = squelMysql.insert({
156
159
  autoQuoteFieldNames: true
@@ -188,7 +191,7 @@ function upsert(table, fields2) {
188
191
  function upsertMany(table, data) {
189
192
  return function(state) {
190
193
  return new Promise(function(resolve, reject) {
191
- const rows = (0, import_language_common.expandReferences)(data)(state);
194
+ const [rows] = (0, import_util.expandReferences)(state, data);
192
195
  if (!rows || rows.length === 0) {
193
196
  console.log("No records provided; skipping upsert.");
194
197
  resolve(state);
@@ -222,7 +225,7 @@ function upsertMany(table, data) {
222
225
  function query(options) {
223
226
  return (state) => {
224
227
  let { connection } = state;
225
- const opts = (0, import_language_common.expandReferences)(options)(state);
228
+ const [opts] = (0, import_util.expandReferences)(state, options);
226
229
  console.log(
227
230
  "Executing MySQL statement with options: " + JSON.stringify(opts, 2, null)
228
231
  );
@@ -256,6 +259,7 @@ var src_default = Adaptor_exports;
256
259
  0 && (module.exports = {
257
260
  alterState,
258
261
  arrayToString,
262
+ as,
259
263
  combine,
260
264
  cursor,
261
265
  dataPath,
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ var Adaptor_exports = {};
9
9
  __export(Adaptor_exports, {
10
10
  alterState: () => alterState,
11
11
  arrayToString: () => arrayToString,
12
+ as: () => as,
12
13
  combine: () => combine,
13
14
  cursor: () => cursor,
14
15
  dataPath: () => dataPath,
@@ -30,10 +31,8 @@ __export(Adaptor_exports, {
30
31
  upsert: () => upsert,
31
32
  upsertMany: () => upsertMany
32
33
  });
33
- import {
34
- execute as commonExecute,
35
- expandReferences
36
- } from "@openfn/language-common";
34
+ import { execute as commonExecute } from "@openfn/language-common";
35
+ import { expandReferences } from "@openfn/language-common/util";
37
36
  import mysql from "mysql";
38
37
  import squel from "squel";
39
38
  import {
@@ -52,7 +51,8 @@ import {
52
51
  alterState,
53
52
  sourceValue,
54
53
  arrayToString,
55
- lastReferenceValue
54
+ lastReferenceValue,
55
+ as
56
56
  } from "@openfn/language-common";
57
57
  function execute(...operations) {
58
58
  const initialState = {
@@ -92,7 +92,7 @@ function cleanupState(state) {
92
92
  function insert(table, fields2) {
93
93
  return (state) => {
94
94
  let { connection } = state;
95
- const valuesObj = expandReferences(fields2)(state);
95
+ const [valuesObj] = expandReferences(state, fields2);
96
96
  const squelMysql = squel.useFlavour("mysql");
97
97
  var sqlParams = squelMysql.insert({
98
98
  autoQuoteFieldNames: true
@@ -123,7 +123,7 @@ function insert(table, fields2) {
123
123
  function upsert(table, fields2) {
124
124
  return (state) => {
125
125
  let { connection } = state;
126
- const valuesObj = expandReferences(fields2)(state);
126
+ const [valuesObj] = expandReferences(state, fields2);
127
127
  const squelMysql = squel.useFlavour("mysql");
128
128
  var insertParams = squelMysql.insert({
129
129
  autoQuoteFieldNames: true
@@ -161,7 +161,7 @@ function upsert(table, fields2) {
161
161
  function upsertMany(table, data) {
162
162
  return function(state) {
163
163
  return new Promise(function(resolve, reject) {
164
- const rows = expandReferences(data)(state);
164
+ const [rows] = expandReferences(state, data);
165
165
  if (!rows || rows.length === 0) {
166
166
  console.log("No records provided; skipping upsert.");
167
167
  resolve(state);
@@ -195,7 +195,7 @@ function upsertMany(table, data) {
195
195
  function query(options) {
196
196
  return (state) => {
197
197
  let { connection } = state;
198
- const opts = expandReferences(options)(state);
198
+ const [opts] = expandReferences(state, options);
199
199
  console.log(
200
200
  "Executing MySQL statement with options: " + JSON.stringify(opts, 2, null)
201
201
  );
@@ -228,6 +228,7 @@ var src_default = Adaptor_exports;
228
228
  export {
229
229
  alterState,
230
230
  arrayToString,
231
+ as,
231
232
  combine,
232
233
  cursor,
233
234
  dataPath,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfn/language-mysql",
3
3
  "label": "MySQL",
4
- "version": "2.1.5",
4
+ "version": "2.2.1",
5
5
  "description": "A MySQL Language Pack for OpenFn",
6
6
  "homepage": "https://docs.openfn.org",
7
7
  "main": "dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  "mysql": "^2.13.0",
23
23
  "squel": "^5.8.0",
24
24
  "string-escape": "^0.3.0",
25
- "@openfn/language-common": "2.5.0"
25
+ "@openfn/language-common": "3.0.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "assertion-error": "^1.0.1",
@@ -66,4 +66,4 @@ export function query(options: object): Operation;
66
66
  * @returns {Operation}
67
67
  */
68
68
  export function sqlString(queryString: string): Operation;
69
- export { fn, fnIf, each, http, merge, field, fields, cursor, dateFns, combine, dataPath, dataValue, alterState, sourceValue, arrayToString, lastReferenceValue } from "@openfn/language-common";
69
+ export { fn, fnIf, each, http, merge, field, fields, cursor, dateFns, combine, dataPath, dataValue, alterState, sourceValue, arrayToString, lastReferenceValue, as } from "@openfn/language-common";