You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-26Lines changed: 20 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
6
6
(updated to support Notion's new formula API!)
7
7
8
-
F.R.A.N.C.I.S. (Formula Readability And Notion Compilation Improvement Stack) is a somewhat complicated but powerful and programmer friendly way of getting around the difficulty of writing large formulas in Notion.
8
+
F.R.A.N.C.I.S. (Formula Readability And Notion Compilation Improvement Stack) is a somewhat complicated but powerful and programmer friendly way of getting around the difficulty of writing large formulas in Notion.
9
9
10
10
With this tool you can simply write thoroughly compile/type checked typescript logic (with all of Notion's builtin functions) and have it translated to a formula quick and easy!
11
11
@@ -23,8 +23,9 @@ It does so through these steps:
23
23
8. Return the completed formula
24
24
25
25
## Usage
26
-
### NPM
26
+
This guide assumes basic programming proficiency. You don't really need to be a typescript expert but you should be familiar with the concepts of basic logic and polymorphism
27
27
28
+
### With npm
28
29
Generate a new typescript project:
29
30
30
31
cd path/to/project
@@ -40,7 +41,7 @@ Then create a MyFirstFormula.ts file that looks something like this:
40
41
41
42
// fill in your formula function here:
42
43
formula() {
43
-
if (this.myProperty.value) {
44
+
if (this.myProperty) {
44
45
return 1;
45
46
}
46
47
return 0;
@@ -51,10 +52,7 @@ Then create a MyFirstFormula.ts file that looks something like this:
51
52
return 0;
52
53
}
53
54
54
-
/**
55
-
* If you want to use helper functions, define them here like this
56
-
* @returns
57
-
*/
55
+
// If you want to use helper functions, define them here like this
@@ -65,11 +63,13 @@ Then create a MyFirstFormula.ts file that looks something like this:
65
63
const formula = new MyFirstFormula();
66
64
console.log('result: ');
67
65
console.log(formula.compile());
68
-
and add your formula and parameters
66
+
Then just add your formula and parameters and you can run
67
+
68
+
ts-node MyFirstFormula.ts
69
+
Easy peasy!
69
70
70
-
### Cloning the repo (Recommended):
71
+
### with the whole repo (Recommended):
71
72
Because the process for generating formulas is somewhat confusing, it's helpful to have the whole repo at your disposale to view the examples.
72
-
This guide assumes basic programming proficiency. You don't really need to be a typescript expert but you should be familiar with the concepts of basic logic and polymorphism
73
73
74
74
git clone https://github.com/CharliePalm/Francis
75
75
cd Francis
@@ -80,9 +80,10 @@ Open the provided myFirstFormula file, and run
80
80
you should see the result:
81
81
82
82
if(prop("myProperty name"),1,0)
83
-
Now that you've confirmed that everything is running smoothly, you can start creating your own formula. You can check out the example file at example.ts for a complicated formula example that uses all the functionality of the compiler, or just fill in the myFirstFormula.ts file with all the functionality you need.
83
+
Now that you've confirmed that everything is running smoothly, you can start creating your own formula. You can check out the example file at example.ts for a complicated formula example that uses all the functionality of the compiler, or just fill in the MyFirstFormula.ts file with all the functionality you need.
84
84
85
-
DB properties should be defined as they are in the example file. It doesn't matter what you name the variable, but the string you pass in to the constructor MUST be the name of the property. That is to say, in the following example code:
85
+
### General Guidelines
86
+
DB properties should be defined as they are in the example. It doesn't matter what you name the variable, but the string you pass in to the constructor MUST be the name of the property. That is to say, in the following example code:
86
87
87
88
class Formula extends NotionFormulaGenerator {
88
89
public test = new Model.Number('test2')
@@ -102,9 +103,9 @@ Aside from these exceptions, if typescript compiles you should be good to go.
102
103
103
104
Note that when adding functions you must create a mapping function to communicate to the compiler what functions to replace with what code. The parent class itself cannot effectively bind each method of the child class at compile time so it's necessary to add this yourself. See the examples in myFirstFormula.ts or example.ts.
104
105
105
-
You are allowed to reference other functions within helper functions, but cannot use recursion or call to the formula() method. This includes multi method recursion; the chain of method calls cannot contain a cycle.
106
+
You are allowed to reference other functions within helper functions, but cannot use recursion or call to the formula() method. This includes multi method recursion; the chain of method calls cannot contain a cycle, and the compiler will let you know if it encounters one.
106
107
107
-
If you want to wrap logic in a function call, just execute the logic in a helper function and call it within the function you want to use as the wrapper.
108
+
If you want to wrap logic in a function call (i.e. rounding the result of a calculation), just execute the logic in a helper function and call it within the function you want to use as the wrapper.
108
109
For example:
109
110
110
111
formula() {
@@ -128,18 +129,11 @@ Alternatively, you can use ternary operators to the same effect:
128
129
}
129
130
Which will lead to the same result, just with ternaries instead of the notion if() function.
130
131
131
-
132
132
Above all, this isn't a full complier and shouldn't be treated as such, as the capabilities of Notion formulas are fairly limited. It would be wonderful if the API allowed loops over rollups or dynamic variable definition, it's just not currently possible, and thus I don't see any use cases for things like loops or non-constant variables.
133
133
134
-
# New in v2.0
135
-
136
-
Francis has been updated to support Notion's new formula API. This means that you can now utilize object references, callback functions, and update your formulas to be supported by the newest version. Using object references is simple, though does change some ways that Francis needs to be used.
137
-
138
-
Because DB properties are now treated as objects, if you wish to do any primitive operations, you need to use the .value field on the object (being either a DB property or the return from a function). Otherwise, you can use the object itself as input for things like functions parameters.
139
-
140
-
Notion also changed some minor things about its builtins - for example: e and pi are now function calls instead of constants, lists have their own functions, concat takes lists, etc.
134
+
# New in v2.0.1
141
135
142
-
Since they now allow new lines, comments, and other such conveniences, the main purpose of this tool has transitioned into more of a complexity manager. Things like helper function and constant declaration will make writing exceptionally complex formulas much simpler and lead to significant readability improvements. See example.ts for my task scheduler algorithm - it uses two sigmoid functions that are contained in function calls.
136
+
Francis is now npm ready! Happy formulating!
143
137
144
138
## FAQ
145
139
@@ -161,11 +155,11 @@ You sure can :)\
161
155
162
156
## Contributing
163
157
164
-
Submit a pull request (with unit test coverage please) and I'll happily review it. Otherwise you're free to fork and use as you will for your own PERSONAL purposes. If you use a formula generated by this tool for something that isn't exclusively for yourself please, at the bare minimum give it a shout-out :)
158
+
Submit a pull request (with unit test coverage please) and I'll happily review it. Otherwise you're free to fork and use as you will for your own PERSONAL purposes. If you use a formula generated by this tool for something that isn't exclusively for yourself please, at the bare minimum give francis a shout-out :)
165
159
166
160
## Known Bugs
167
161
168
-
As of 8/5/2023 there are no known bugs.
162
+
As of 9/6/2024 there are no known bugs and 100% unit test coverage.
169
163
170
164
## Reporting Bugs
171
165
@@ -178,4 +172,4 @@ contains a value field that has its primitive type (if applicable) for primitive
178
172
This brings into question how type safety will be properly enforced and how primitive operations can be carried out, which I don't have a solution for right now, but would like to work more on.
0 commit comments