Skip to content

Release: common@3 #1179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
295712f
feat: remove old expandreferences and use the new implementation
hunterachieng Apr 24, 2025
91116c8
update http to request
hunterachieng Apr 25, 2025
0f4f47e
Revert "update http to request"
hunterachieng Apr 25, 2025
6d97964
feat: update expandreference destructure
hunterachieng Apr 25, 2025
9cf7d7c
fix: failing tests
hunterachieng Apr 28, 2025
afa4c48
fix: update expandReferences
hunterachieng Apr 28, 2025
7c0a679
fix: update common test
hunterachieng Apr 28, 2025
3e32729
fix: update common version
hunterachieng Apr 28, 2025
13b22fa
fix: update lock.yaml
hunterachieng Apr 28, 2025
20fc025
fix: update common export and progres post()
hunterachieng Apr 28, 2025
23ac8e8
fix: rename newExpandreferences to expandReferences
hunterachieng Apr 28, 2025
c302646
fix: Remove skip from `progres` tests
hunterachieng Apr 28, 2025
ea85695
feat: add changeset
hunterachieng Apr 28, 2025
bc409de
rapidpro: migrate from deprecated `common-http` to `fetch` (#1166)
hunterachieng Apr 29, 2025
1a2404c
fix: update common changeset
hunterachieng Apr 29, 2025
c4625fa
fix: add path changeset
hunterachieng Apr 29, 2025
b6c110e
Merge branch 'feature/1120-common-migration' of github.com:OpenFn/ada…
hunterachieng Apr 29, 2025
87b4f2e
progres: migrate from deprecated `common-http` to `common-request` (#…
hunterachieng Apr 29, 2025
04afd9d
Merge branch 'main' of github.com:OpenFn/adaptors into feature/1120-c…
hunterachieng Apr 29, 2025
2a55a3c
Merge branch 'feature/1120-common-migration' of github.com:OpenFn/ada…
hunterachieng Apr 29, 2025
07b84ae
Merge pull request #1160 from OpenFn/feature/1120-common-migration
hunterachieng Apr 29, 2025
a4f3740
common: remove map (#1172)
josephjclark May 1, 2025
8cef333
remove salesforce changelog
josephjclark May 1, 2025
cd6e72d
Merge branch 'main' into epic/common-3
josephjclark May 1, 2025
c822afb
remove curry import
josephjclark May 2, 2025
664a65f
Bump undici from 5.28.5 to 5.29.0
dependabot[bot] May 30, 2025
731fea1
Merge branch 'main' into epic/common-3
josephjclark Jun 6, 2025
cdd5263
Merge branch 'epic/common-3' of github.com:OpenFn/adaptors into depen…
hunterachieng Jun 9, 2025
c98cc0c
Merge pull request #1196 from OpenFn/dependabot/npm_and_yarn/undici-5…
josephjclark Jun 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/beige-penguins-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/language-common': major
---

Remove `map()`
7 changes: 7 additions & 0 deletions .changeset/cold-lions-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@openfn/language-progres': major
---

- Migrate from `common.http` to `common.request`.
- Remove `axios` and `nock` from progres.
- Remove exportation of `http` from `common`, and the exportation of `axios`.
5 changes: 5 additions & 0 deletions .changeset/eleven-meals-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/language-common': major
---

- Delete deprecated `expandReferences` from common and use `expandReferences` from `common.util`
19 changes: 19 additions & 0 deletions .changeset/nasty-geckos-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@openfn/language-googlehealthcare': patch
'@openfn/language-khanacademy': patch
'@openfn/language-medicmobile': patch
'@openfn/language-resourcemap': patch
'@openfn/language-salesforce': patch
'@openfn/language-surveycto': patch
'@openfn/language-telerivet': patch
'@openfn/language-dynamics': patch
'@openfn/language-facebook': patch
'@openfn/language-rapidpro': patch
'@openfn/language-beyonic': patch
'@openfn/language-cartodb': patch
'@openfn/language-mailgun': patch
'@openfn/language-mongodb': patch
---

- Migrate from the deprecated `expandReferences` in `common` to the new `expandReferences` from common.util
- Use `workspace:*` common version.
5 changes: 5 additions & 0 deletions .changeset/silver-pets-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/language-mogli': minor
---

Removed map() function, exported from common
8 changes: 8 additions & 0 deletions .changeset/six-crabs-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@openfn/language-rapidpro': major
---

- Update `rapidPro` to not use deprecated `common-http`.
- Remove support and export of `axios`
- Remove export of `http` namesepace from `common`

12 changes: 5 additions & 7 deletions packages/beyonic/src/Adaptor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {
execute as commonExecute,
expandReferences,
} from '@openfn/language-common';
import { execute as commonExecute } from '@openfn/language-common';
import { post } from './Client';
import { resolve as resolveUrl } from 'url';
import { expandReferences } from '@openfn/language-common/util';

/**
* Execute a sequence of operations.
Expand Down Expand Up @@ -34,7 +32,7 @@ export function execute(...operations) {
*/
export function createPayment(data) {
return state => {
const body = expandReferences(data)(state);
const [body] = expandReferences(state, data);

const { apiUrl, apiToken } = state.configuration;

Expand All @@ -61,7 +59,7 @@ export function createPayment(data) {
*/
export function createContact(data) {
return state => {
const body = expandReferences(data)(state);
const [body] = expandReferences(state, data);

const { apiUrl, apiToken } = state.configuration;

Expand All @@ -88,7 +86,7 @@ export function createContact(data) {
*/
export function createCollectionRequest(data) {
return state => {
const body = expandReferences(data)(state);
const [body] = expandReferences(state, data);

const { apiUrl, apiToken } = state.configuration;

Expand Down
8 changes: 3 additions & 5 deletions packages/cartodb/src/Adaptor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
execute as commonExecute,
expandReferences,
} from '@openfn/language-common';
import { execute as commonExecute } from '@openfn/language-common';
import { expandReferences } from '@openfn/language-common/util';
import { post } from './Client';
import jsonSqlPkg from 'json-sql';

Expand Down Expand Up @@ -65,7 +63,7 @@ export function sql(sqlQuery) {
*/
export function addRow(table, rowData) {
return state => {
const dataObject = expandReferences(rowData)(state);
const [dataObject] = expandReferences(state, rowData);

const sql = jsonSql.build({
type: 'insert',
Expand Down
63 changes: 0 additions & 63 deletions packages/common/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -1694,69 +1694,6 @@
]
},
"valid": true
},
{
"name": "map",
"params": [
"path",
"operation",
"state"
],
"docs": {
"description": "Scopes an array of data based on a JSONPath.\nUseful when the source data has `n` items you would like to map to\nan operation.\nThe operation will receive a slice of the data based of each item\nof the JSONPath provided.",
"tags": [
{
"title": "public",
"description": null,
"type": null
},
{
"title": "function",
"description": null,
"name": null
},
{
"title": "example",
"description": "map(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
},
{
"title": "param",
"description": "JSONPath referencing a point in `state.data`.",
"type": {
"type": "NameExpression",
"name": "string"
},
"name": "path"
},
{
"title": "param",
"description": "The operation needed to be repeated.",
"type": {
"type": "NameExpression",
"name": "function"
},
"name": "operation"
},
{
"title": "param",
"description": "Runtime state.",
"type": {
"type": "NameExpression",
"name": "State"
},
"name": "state"
},
{
"title": "returns",
"description": null,
"type": {
"type": "NameExpression",
"name": "State"
}
}
]
},
"valid": true
}
],
"exports": [],
Expand Down
86 changes: 11 additions & 75 deletions packages/common/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Readable } from 'node:stream';
import { request } from 'undici';
import dateFns from 'date-fns';

import { expandReferences as newExpandReferences, parseDate } from './util';
import { expandReferences, parseDate } from './util';

const schemaCache = {};

Expand Down Expand Up @@ -78,7 +78,7 @@ export function fn(func) {
*/
export function fnIf(condition, operation) {
return state => {
const [resolvedCondition] = newExpandReferences(state, condition);
const [resolvedCondition] = expandReferences(state, condition);

return resolvedCondition ? operation(state) : state;
};
Expand Down Expand Up @@ -196,41 +196,6 @@ export function lastReferenceValue(path) {
return sourceValue(lastReferencePath);
}

/**
* Scopes an array of data based on a JSONPath.
* Useful when the source data has `n` items you would like to map to
* an operation.
* The operation will receive a slice of the data based of each item
* of the JSONPath provided.
* @public
* @function
* @example
* map("$.[*]",
* create("SObject",
* field("FirstName", sourceValue("$.firstName"))
* )
* )
* @param {string} path - JSONPath referencing a point in `state.data`.
* @param {function} operation - The operation needed to be repeated.
* @param {State} state - Runtime state.
* @returns {State}
*/
export const map = curry(function (path, operation, state) {
switch (typeof path) {
case 'string':
source(path)(state).map(function (data) {
return operation({ data, references: state.references });
});
return state;

case 'object':
path.map(function (data) {
return operation({ data, references: state.references });
});
return state;
}
});

/**
* Simple switcher allowing other expressions to use either a JSONPath or
* object literals as a data source.
Expand Down Expand Up @@ -356,35 +321,6 @@ export function join(targetPath, sourcePath, targetKey) {
};
}

/**
* Recursively resolves objects that have resolvable values (functions).
* @public
* @function
* @param {object} value - data
* @param {Function} [skipFilter] - a function which returns true if a value should be skipped
* @returns {Operation}
*/
export function expandReferences(value, skipFilter) {
return state => {
if (skipFilter && skipFilter(value)) return value;

if (Array.isArray(value)) {
return value.map(v => expandReferences(v)(state));
}

if (typeof value == 'object' && !!value) {
return Object.keys(value).reduce((acc, key) => {
return { ...acc, [key]: expandReferences(value[key])(state) };
}, {});
}

if (typeof value == 'function') {
return expandReferences(value(state))(state);
}
return value;
};
}

/**
* Returns a key, value pair in an array.
* @public
Expand Down Expand Up @@ -431,7 +367,7 @@ export function fields(...fields) {
export function merge(dataSource, fields) {
return state => {
const initialData = source(dataSource)(state);
const additionalData = expandReferences(fields)(state);
const [additionalData] = expandReferences(state, fields);

return initialData.reduce((acc, dataItem) => {
return [...acc, { ...dataItem, ...additionalData }];
Expand Down Expand Up @@ -460,7 +396,7 @@ export function merge(dataSource, fields) {
*/
export function group(arrayOfObjects, keyPath, callback = s => s) {
return state => {
const [resolvedArray, resolvedKeyPath] = newExpandReferences(
const [resolvedArray, resolvedKeyPath] = expandReferences(
state,
arrayOfObjects,
keyPath
Expand Down Expand Up @@ -677,7 +613,7 @@ export function parseCsv(csvData, parsingOptions = {}, callback) {
};

return async state => {
const [resolvedCsvData, resolvedParsingOptions] = newExpandReferences(
const [resolvedCsvData, resolvedParsingOptions] = expandReferences(
state,
csvData,
parsingOptions
Expand Down Expand Up @@ -798,7 +734,7 @@ export function validate(schema = 'schema', data = 'data') {
// Schema can be a url, jsonpath or object; or a function resolving to any of these
async function resolveSchema() {
// TODO hmm, I don't really want to expand schema if it's an object
const [schemaOrUrl] = newExpandReferences(state, schema);
const [schemaOrUrl] = expandReferences(state, schema);

if (typeof schemaOrUrl === 'string') {
try {
Expand All @@ -823,7 +759,7 @@ export function validate(schema = 'schema', data = 'data') {

// data can be a jsonpath or object; or function resolving to any of these
function resolveData() {
const [d] = newExpandReferences(state, data);
const [d] = expandReferences(state, data);

if (typeof d === 'string') {
return JSONPath({ path: d, json: state })[0];
Expand Down Expand Up @@ -860,7 +796,7 @@ let cursorKey = 'cursor';
export function cursor(value, options = {}) {
return state => {
const { format, ...optionsWithoutFormat } = options;
const [resolvedValue, resolvedOptions] = newExpandReferences(
const [resolvedValue, resolvedOptions] = expandReferences(
state,
value,
optionsWithoutFormat
Expand Down Expand Up @@ -916,7 +852,7 @@ export function cursor(value, options = {}) {
*/
export function assert(expression, errorMessage) {
return state => {
const [resolvedValue, resolvedErrorMessage] = newExpandReferences(
const [resolvedValue, resolvedErrorMessage] = expandReferences(
state,
expression,
errorMessage
Expand Down Expand Up @@ -949,7 +885,7 @@ export function assert(expression, errorMessage) {
*/
export function log(...args) {
return state => {
const [resolvedArgs] = newExpandReferences(state, args);
const [resolvedArgs] = expandReferences(state, args);
console.log(...resolvedArgs);
return state;
};
Expand All @@ -972,7 +908,7 @@ export function log(...args) {
*/
export function debug(...args) {
return state => {
const [resolvedArgs] = newExpandReferences(state, args);
const [resolvedArgs] = expandReferences(state, args);
console.debug(...resolvedArgs);
return state;
};
Expand Down
Loading