@fibery/expression-utils 9.3.0 → 9.4.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/package.json CHANGED
@@ -1,27 +1,25 @@
1
1
  {
2
2
  "name": "@fibery/expression-utils",
3
- "version": "9.3.0",
3
+ "version": "9.4.0",
4
4
  "description": "utils for working with fibery api expressions",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "files": [
8
+ "./lib"
9
+ ],
5
10
  "exports": {
6
- ".": "./lib/expression-utils.js",
7
- "./contextVariables": "./lib/contextVariables.js",
8
- "./utils": "./lib/utils.js",
9
- "./visitors": "./lib/visitors.js",
10
- "./paramsPlaceholders": "./lib/paramsPlaceholders.js"
11
+ ".": {
12
+ "types": "./lib/index.d.ts",
13
+ "default": "./lib/index.js"
14
+ }
11
15
  },
12
- "types": "./types.d.ts",
13
16
  "fiberyDevExports": {
14
- ".": "./index.js",
15
- "./contextVariables": "./contextVariables.js",
16
- "./utils": "./utils.js",
17
- "./visitors": "./visitors.js",
18
- "./paramsPlaceholders": "./paramsPlaceholders.js"
17
+ ".": "./index.ts",
18
+ "./src/utils": "./src/utils.ts",
19
+ "./src/visitors": "./src/visitors.ts",
20
+ "./src/params-placeholders": "./src/params-placeholders.ts",
21
+ "./src/context-variables": "./src/context-variables.ts"
19
22
  },
20
- "main": "./lib/expression-utils.js",
21
- "files": [
22
- "/lib",
23
- "types.d.ts"
24
- ],
25
23
  "private": false,
26
24
  "dependencies": {
27
25
  "lodash": "4.17.21",
@@ -30,11 +28,13 @@
30
28
  },
31
29
  "devDependencies": {
32
30
  "@babel/core": "7.23.9",
31
+ "@types/lodash": "4.14.172",
33
32
  "@swc/jest": "0.2.29",
34
33
  "jest": "27.5.1",
35
34
  "jest-junit": "13.0.0",
36
- "microbundle": "0.15.1",
35
+ "typescript": "5.8.3",
37
36
  "@fibery/babel-preset": "7.4.0",
37
+ "@fibery/schema": "10.2.8",
38
38
  "@fibery/eslint-config": "8.6.1"
39
39
  },
40
40
  "peerDependencies": {
@@ -79,10 +79,10 @@
79
79
  "testURL": "http://localhost"
80
80
  },
81
81
  "scripts": {
82
- "build": "rm -rf lib && microbundle paramsPlaceholders.js utils.js visitors.js contextVariables.js index.js -o lib -f cjs --no-compress --target node --sourcemap false --generateTypes false",
83
- "test": "node scripts/test.js",
84
- "test:ci": "pnpm run test --reporters=default --reporters=jest-junit",
85
- "test:coverage": "pnpm run test --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/expression-utils --reporters=default --reporters=jest-junit",
82
+ "build": "rm -rf lib && pnpm exec tsc --project tsconfig.build.json",
83
+ "test": "jest",
84
+ "test:ci": "jest --reporters=default --reporters=jest-junit",
85
+ "test:coverage": "jest --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/formulas --reporters=default --reporters=jest-junit",
86
86
  "lint": "eslint ."
87
87
  }
88
88
  }
@@ -1,106 +0,0 @@
1
- var _ = require('lodash');
2
-
3
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
4
-
5
- var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
6
-
7
- const getAutomationButtonContextVariables = (typeId, typeName, fiberySchema) => {
8
- if (!fiberySchema) {
9
- return [];
10
- }
11
- const userTypeObject = fiberySchema.typeObjectsByName["fibery/user"];
12
- const typeObject = fiberySchema.typeObjectsById[typeId];
13
- return [{
14
- id: "triggeredEntity",
15
- title: `Step 1 ${typeName}`,
16
- typeObject,
17
- description: `The ${typeName} for which the Button was clicked`
18
- }, {
19
- id: "currentUser",
20
- title: `User who clicked Button`,
21
- typeObject: userTypeObject,
22
- description: `The User who triggered this automation by clicking a Button.`
23
- }];
24
- };
25
- const getTriggerCollectionFieldObject = (typeId, collectionFieldId, fiberySchema) => {
26
- if (!fiberySchema) {
27
- return undefined;
28
- }
29
- if (!Object.hasOwn(fiberySchema.typeObjectsById, typeId)) {
30
- return undefined;
31
- }
32
- if (!Object.hasOwn(fiberySchema.typeObjectsById[typeId].fieldObjectsById, collectionFieldId)) {
33
- return undefined;
34
- }
35
- return fiberySchema.typeObjectsById[typeId].fieldObjectsById[collectionFieldId];
36
- };
37
- const getTriggerContextVariables = (trigger, typeId, fiberySchema) => {
38
- if (!fiberySchema) {
39
- return [];
40
- }
41
- const typeObject = fiberySchema.typeObjectsById[typeId];
42
- const userTypeObject = fiberySchema.typeObjectsByName["fibery/user"];
43
- const triggeredEntityVar = {
44
- id: "triggeredEntity",
45
- title: `Step 1 ${typeObject.title}`,
46
- typeObject,
47
- description: `The ${typeObject.title} from step 1 of this Rule`
48
- };
49
- const currentUserVar = {
50
- id: "currentUser",
51
- title: `User who triggered Rule`,
52
- typeObject: userTypeObject,
53
- description: `The User who made the change which triggered this automation. Empty in case the change was made by a formula or an integration.`
54
- };
55
- if (trigger.trigger === "time-based") {
56
- return [triggeredEntityVar];
57
- } else if (trigger.trigger === "created") {
58
- return typeObject.syncSource !== null ? [triggeredEntityVar] : [triggeredEntityVar, currentUserVar];
59
- } else if (trigger.trigger === "updated") {
60
- const disableCurrentUserVar = trigger.args.updatedField && ___default["default"].isArray(trigger.args.updatedField) && trigger.args.updatedField.some(fieldId => {
61
- if (!Object.hasOwn(typeObject.fieldObjectsById, fieldId)) {
62
- return false;
63
- }
64
- const fieldObject = typeObject.fieldObjectsById[fieldId];
65
- return (fieldObject == null ? void 0 : fieldObject.isReadOnly) || (fieldObject == null ? void 0 : fieldObject.type) === "Collaboration~Documents/Document";
66
- });
67
- return disableCurrentUserVar ? [triggeredEntityVar] : [triggeredEntityVar, currentUserVar];
68
- } else if (trigger.trigger === "collection-item-added" || trigger.trigger === "collection-item-removed") {
69
- const collectionItemFieldObject = getTriggerCollectionFieldObject(typeId, trigger.args.changedCollectionField, fiberySchema);
70
- const collectionItemTypeObject = collectionItemFieldObject == null ? void 0 : collectionItemFieldObject.typeObject;
71
- const variables = [triggeredEntityVar];
72
- collectionItemTypeObject && variables.push({
73
- id: "triggered-collection-item",
74
- title: `Step 1 ${trigger.trigger === "collection-item-added" ? "linked" : "unlinked"} ${collectionItemTypeObject.title}`,
75
- typeObject: collectionItemTypeObject,
76
- description: `The ${collectionItemTypeObject.title} from step 1 of this Rule`
77
- });
78
- const disableCurrentUserVar = collectionItemFieldObject == null ? void 0 : collectionItemFieldObject.isReadOnly;
79
- !disableCurrentUserVar && variables.push(currentUserVar);
80
- return variables;
81
- } else {
82
- return [];
83
- }
84
- };
85
- const getAutomationTriggersContextVariables = (triggers, typeId, fiberySchema) => {
86
- return ___default["default"].uniqBy(___default["default"].flatten(triggers.map(trigger => {
87
- return getTriggerContextVariables(trigger, typeId, fiberySchema);
88
- })), variable => `${variable.id}_${variable.typeObject.id}`);
89
- };
90
- const getEntityQueryVariables = schema => {
91
- const grouped = ___default["default"].groupBy(schema.typeObjects.filter(x => x.isDomain), typeObject => typeObject.pluralTitle);
92
- return ___default["default"].flatten(Object.values(grouped).map(group => {
93
- return group.map(typeObject => ({
94
- typeObject,
95
- id: `entityQuery_${typeObject.id}`,
96
- title: group.length > 1 ? `${typeObject.pluralTitle} (${typeObject.nameParts.namespace})` : typeObject.pluralTitle,
97
- isCollection: true,
98
- description: `All Entities from "${typeObject.title}" Database`
99
- }));
100
- }));
101
- };
102
-
103
- exports.getAutomationButtonContextVariables = getAutomationButtonContextVariables;
104
- exports.getAutomationTriggersContextVariables = getAutomationTriggersContextVariables;
105
- exports.getEntityQueryVariables = getEntityQueryVariables;
106
- exports.getTriggerCollectionFieldObject = getTriggerCollectionFieldObject;