Gramex 1.78 supports TypeScript, Time series models, CORS with auth, and more.
FileHandler can compile TypeScript.
The default FileHandler compiles any .ts
file into JS. For example, this typescript.ts
file:
type WindowStates = "open" | "closed" | "minimized";
function getLength(obj: WindowStates | WindowStates[]) {
return obj.length;
}
function getLength(obj) {
return obj.length;
}
//# sourceMappingURL=typescript.ts?map
See typescript.ts
To enable this in your FileHandler, add:
kwargs:
...
ts: '*.ts' # Compile .ts files into JS
MLHandler supports time series forecasting.
This now lets MLHandler perform 3 distinct tasks:
To specify a time series model, use class: SARIMAX
. This uses the
SARIMAX
algorithm in statsmodels
.
mlhandler/forecast:
pattern: /$YAMLURL/forecast
handler: MLHandler
kwargs:
data:
url: $YAMLPATH/inflation.csv # Inflation dataset
model:
index_col: index # Use index column as timestamps
target_col: R
class: SARIMAX
params:
order:
[7, 1, 0] # Creates ARIMA estimator with (p,d,q)=(7,1,0)
# Add other parameters similarly
When one server sends a request to another server via browser JavaScript, we need to enable Cross-Origin Resource Sharing (CORS).
This release makes CORS easy. Just add cors: true
to the URL’s kwargs
to enable CORS.
For example, this page returns session information to pages from any server:
url:
deploy-cors:
pattern: /$YAMLURL/cors
handler: FunctionHandler
kwargs:
function: handler.session
cors: true # Enable CORS
You can restrict CORS to specific domains or HTTP methods. Read more about CORS.
To authorize the user for some HTTP methods (e.g. POST
, PUT
, DELETE
) but not others (e.g.
GET
), use this:
url:
public-read:
pattern: /$YAMLURL/public-read
handler: FunctionHandler
kwargs:
function: f'Method = $${handler.request.method}, User = $${handler.current_user}'
auth:
methods: [POST, PUT, DELETE]
Any GET
, OPTIONS
or other HTTP requests to /public-read
can be made by anyone. But POST
,
PUT
, DELETE
can only be made by logged-in users.
Auth HTTP methods
FileHandler supports ○a ?@import=path/to/filename.sass
to import SASS
files dynamically into other SASS files. The import file path must be relative to the requested
SASS file or the directory Gramex is running in.
Gramex 1.78 is backward compatible with previous releases unless the release notes say otherwise. Automated builds test this.
Every Gramex release is tested for security vulnerabilities using the following tools.
The Gramex code base has: