skillet 0.5.3

Skillet: micro expression language (arithmetic, logical, functions, arrays, conditionals, excel formulas) made in Rust bin cli and server
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
openapi: 3.0.3
info:
  title: Skillet HTTP Server API
  description: |
    A high-performance mathematical and logical expression evaluation server with JavaScript function management capabilities.
    
    ## Features
    - Expression evaluation with variables and arguments
    - Custom JavaScript function management
    - Expression caching for performance
    - Thread-based concurrent processing
    - Optional token-based authentication
    
    ## Authentication
    - **Eval Token**: Optional authentication for expression evaluation endpoints
    - **Admin Token**: Required authentication for JavaScript function management endpoints
    
    Tokens are passed via the `Authorization` header.
  version: 0.4.1
  contact:
    name: Skillet Lang
  license:
    name: MIT
servers:
  - url: http://127.0.0.1:5074
    description: Local development server
  - url: http://localhost:5074
    description: Local server
tags:
  - name: evaluation
    description: Expression evaluation operations
  - name: health
    description: Server health and monitoring
  - name: javascript
    description: JavaScript function management
  - name: cache
    description: Cache management operations

paths:
  /:
    get:
      tags: [health]
      summary: Get API documentation
      description: Returns HTML documentation page with API endpoints and examples
      responses:
        '200':
          description: HTML documentation page
          content:
            text/html:
              schema:
                type: string
                example: "<!DOCTYPE html><html>..."

  /health:
    get:
      tags: [health]
      summary: Health check
      description: Get server health status, statistics, and cache performance metrics
      security:
        - evalToken: []
        - {}
      responses:
        '200':
          description: Server health information
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HealthResponse'
              example:
                status: "healthy"
                version: "0.4.1"
                requests_processed: 1542
                avg_execution_time_ms: 2.34
                cache_stats:
                  hits: 856
                  misses: 686
                  hit_rate: 0.555
                  entries: 150
                  evictions: 12
                  total_saved_time_ms: 1248.67

  /eval:
    post:
      tags: [evaluation]
      summary: Evaluate expression (JSON)
      description: |
        Evaluate mathematical and logical expressions with optional variables and arguments.
        
        ## Expression Format
        - Expressions can start with `=` (optional)
        - Variables are prefixed with `:` (e.g., `:x`, `:total`)
        - Supports arithmetic, logical, and comparison operations
        - Custom JavaScript functions available
        
        ## Examples
        - `=2 + 3 * 4` → 14
        - `:x + :y` with arguments `{"x": 10, "y": 20}` → 30
        - `MX_ISR(21000, "semanal")` → Custom JS function call
      security:
        - evalToken: []
        - {}
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EvalRequest'
            examples:
              simple:
                summary: Simple arithmetic
                value:
                  expression: "=2 + 3 * 4"
              with_variables:
                summary: Expression with variables
                value:
                  expression: ":x + :y * 2"
                  arguments:
                    x: 10
                    y: 5
                  output_json: true
              selective_variables:
                summary: Return specific variables only
                value:
                  expression: ":a := 10; :b := 20; :c := :a + :b"
                  include_variables: ":a,:b"
      responses:
        '200':
          description: Expression evaluation result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EvalResponse'
              examples:
                success:
                  summary: Successful evaluation
                  value:
                    success: true
                    result: 14
                    execution_time_ms: 1.23
                    request_id: 42
                with_variables:
                  summary: Result with variables
                  value:
                    success: true
                    result: 30
                    variables:
                      x: 10
                      y: 20
                    execution_time_ms: 2.15
                    request_id: 43
        '400':
          description: Invalid expression or request format
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '413':
          description: Request payload too large (>1MB)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'

    get:
      tags: [evaluation]
      summary: Evaluate expression (URL parameters)
      description: |
        Evaluate expressions using URL query parameters. Useful for simple expressions and browser testing.
        
        ## Query Parameters
        - `expr` or `expression`: The expression to evaluate
        - `output_json`: Set to "true" for JSON output format
        - Variable arguments: `x=10&y=20` etc.
      security:
        - evalToken: []
        - {}
      parameters:
        - name: expr
          in: query
          required: true
          description: The expression to evaluate
          schema:
            type: string
          example: "2 + 3 * 4"
        - name: expression
          in: query
          required: false
          description: Alternative parameter name for expression
          schema:
            type: string
        - name: output_json
          in: query
          required: false
          description: Return result in JSON format
          schema:
            type: string
            enum: ["true", "false"]
        - name: include_variables
          in: query
          required: false
          description: Include variables in response (true/false or comma-separated list)
          schema:
            type: string
          example: "true"
      responses:
        '200':
          description: Expression evaluation result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EvalResponse'
            text/plain:
              schema:
                type: string
                example: "14"
        '400':
          description: Missing or invalid expression
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'

  /upload-js:
    post:
      tags: [javascript]
      summary: Upload JavaScript function
      description: |
        Upload and validate a new JavaScript function. Supports both JSON and multipart form-data uploads.
        
        ## JavaScript Function Format
        Functions must include metadata comments:
        ```javascript
        // @name: FUNCTION_NAME
        // @description: Function description
        // @example: FUNCTION_NAME(5, 10) returns 15
        // @min_args: 2
        // @max_args: 2
        
        function execute(args) {
            return args[0] + args[1];
        }
        ```
        
        ## Upload Methods
        1. **JSON**: Send `js_code` field with function content
        2. **Multipart**: Upload file with `filename` and `file` fields
      security:
        - adminToken: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UploadJSRequest'
            example:
              filename: "add_numbers.js"
              js_code: "// @name: ADD_NUMBERS\n// @description: Adds two numbers\n// @example: ADD_NUMBERS(5, 3) returns 8\n// @min_args: 2\n// @max_args: 2\n\nfunction execute(args) {\n    return args[0] + args[1];\n}"
          multipart/form-data:
            schema:
              type: object
              properties:
                filename:
                  type: string
                  description: Name of the JavaScript file (must end with .js)
                  example: "add_numbers.js"
                js_code:
                  type: string
                  description: JavaScript function code (alternative to file upload)
                file:
                  type: string
                  format: binary
                  description: JavaScript file upload (alternative to js_code)
              required:
                - filename
      responses:
        '200':
          description: Function uploaded and validated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UploadJSResponse'
              example:
                success: true
                message: "JavaScript function 'ADD_NUMBERS' uploaded and validated successfully"
                function_name: "ADD_NUMBERS"
                validation_results:
                  syntax_valid: true
                  structure_valid: true
                  example_test_passed: true
                  example_result: "Expected: 8, Got: 8 ✓"
        '400':
          description: Invalid function or validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UploadJSResponse'
        '401':
          description: Admin authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'

  /update-js:
    put:
      tags: [javascript]
      summary: Update existing JavaScript function
      description: |
        Update an existing JavaScript function. The file must already exist.
        Supports both JSON and multipart form-data formats.
      security:
        - adminToken: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateJSRequest'
          multipart/form-data:
            schema:
              type: object
              properties:
                filename:
                  type: string
                  description: Name of the JavaScript file to update
                js_code:
                  type: string
                  description: Updated JavaScript function code
                file:
                  type: string
                  format: binary
                  description: Updated JavaScript file upload
              required:
                - filename
      responses:
        '200':
          description: Function updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpdateJSResponse'
        '400':
          description: Invalid function or validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpdateJSResponse'
        '404':
          description: Function file not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpdateJSResponse'

  /delete-js:
    delete:
      tags: [javascript]
      summary: Delete JavaScript function
      description: Delete an existing JavaScript function file from the hooks directory
      security:
        - adminToken: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DeleteJSRequest'
            example:
              filename: "old_function.js"
      responses:
        '200':
          description: Function deleted successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeleteJSResponse'
        '400':
          description: Invalid filename
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeleteJSResponse'
        '404':
          description: Function file not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeleteJSResponse'

  /list-js:
    get:
      tags: [javascript]
      summary: List JavaScript functions
      description: |
        List all JavaScript functions in the hooks directory with detailed metadata,
        including validation status, function signatures, and file information.
      security:
        - adminToken: []
      responses:
        '200':
          description: List of JavaScript functions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListJSResponse'
              example:
                success: true
                total_count: 2
                functions:
                  - filename: "mx_isr.js"
                    function_name: "MX_ISR"
                    description: "Calculates ISR tax in mexico based on the monto and period"
                    example: "MX_ISR(21000, \"semanal\") returns 2817.603008"
                    min_args: 1
                    max_args: 2
                    file_size: 3682
                    last_modified: "2024-09-06 23:03:15 UTC"
                    is_valid: true
                  - filename: "add_numbers.js"
                    function_name: "ADD_NUMBERS"
                    description: "Adds two numbers together"
                    example: "ADD_NUMBERS(5, 3) returns 8"
                    min_args: 2
                    max_args: 2
                    file_size: 245
                    last_modified: "2024-09-07 08:15:32 UTC"
                    is_valid: true
        '401':
          description: Admin authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'

  /reload-hooks:
    post:
      tags: [javascript]
      summary: Reload JavaScript functions
      description: |
        Reload all JavaScript functions from the hooks directory.
        This refreshes the function registry without restarting the server.
      security:
        - adminToken: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              example: {}
      responses:
        '200':
          description: Functions reloaded successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReloadHooksResponse'
              example:
                success: true
                message: "Successfully reloaded 3 JavaScript function(s)"
                functions_loaded: 3

  /cache:
    delete:
      tags: [cache]
      summary: Clear expression cache
      description: |
        Clear the expression evaluation cache to force re-evaluation of all expressions.
        Useful for development and testing scenarios.
      security:
        - adminToken: []
      responses:
        '200':
          description: Cache cleared successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                example:
                  success: true
                  message: "Expression cache cleared successfully"

components:
  securitySchemes:
    evalToken:
      type: apiKey
      in: header
      name: Authorization
      description: Token for expression evaluation endpoints (if enabled)
    adminToken:
      type: apiKey
      in: header
      name: Authorization
      description: Admin token for JavaScript function management endpoints

  schemas:
    EvalRequest:
      type: object
      properties:
        expression:
          type: string
          description: The expression to evaluate (can be string or array of strings)
          example: ":x + :y * 2"
        arguments:
          type: object
          description: Variables to use in the expression
          additionalProperties: true
          example:
            x: 10
            y: 20
        output_json:
          type: boolean
          description: Whether to return result in JSON format
          default: false
        include_variables:
          oneOf:
            - type: boolean
            - type: string
          description: |
            Include variables in response:
            - `true`: Include all variables
            - `false`: No variables
            - `"var1,var2"`: Specific variables only
          example: true
      required:
        - expression

    EvalResponse:
      type: object
      properties:
        success:
          type: boolean
          description: Whether the evaluation succeeded
        result:
          description: The evaluation result
          example: 42
        variables:
          type: object
          description: Variables from the expression (if requested)
          additionalProperties: true
        error:
          type: string
          description: Error message if evaluation failed
        execution_time_ms:
          type: number
          description: Time taken to evaluate in milliseconds
        request_id:
          type: integer
          description: Unique request identifier
      required:
        - success
        - execution_time_ms
        - request_id

    HealthResponse:
      type: object
      properties:
        status:
          type: string
          enum: [healthy]
        version:
          type: string
          description: Server version
        requests_processed:
          type: integer
          description: Total number of requests processed
        avg_execution_time_ms:
          type: number
          description: Average execution time across all requests
        cache_stats:
          $ref: '#/components/schemas/CacheStatsResponse'
      required:
        - status
        - version
        - requests_processed
        - avg_execution_time_ms

    CacheStatsResponse:
      type: object
      properties:
        hits:
          type: integer
          description: Number of cache hits
        misses:
          type: integer
          description: Number of cache misses
        hit_rate:
          type: number
          description: Cache hit rate (0.0 to 1.0)
        entries:
          type: integer
          description: Current number of cached entries
        evictions:
          type: integer
          description: Number of cache evictions
        total_saved_time_ms:
          type: number
          description: Total time saved by caching

    UploadJSRequest:
      type: object
      properties:
        filename:
          type: string
          description: JavaScript filename (must end with .js)
          example: "my_function.js"
        js_code:
          type: string
          description: JavaScript function code
        file_content:
          type: string
          description: File content (for multipart uploads)
      required:
        - filename

    UploadJSResponse:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
        function_name:
          type: string
          description: Extracted function name
        validation_results:
          $ref: '#/components/schemas/ValidationResults'
        error:
          type: string
      required:
        - success
        - message

    UpdateJSRequest:
      type: object
      properties:
        filename:
          type: string
          description: JavaScript filename to update
        js_code:
          type: string
          description: Updated JavaScript function code
        file_content:
          type: string
          description: Updated file content (for multipart uploads)
      required:
        - filename

    UpdateJSResponse:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
        function_name:
          type: string
        validation_results:
          $ref: '#/components/schemas/ValidationResults'
        error:
          type: string
      required:
        - success
        - message

    DeleteJSRequest:
      type: object
      properties:
        filename:
          type: string
          description: JavaScript filename to delete
      required:
        - filename

    DeleteJSResponse:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
        error:
          type: string
      required:
        - success
        - message

    ListJSResponse:
      type: object
      properties:
        success:
          type: boolean
        functions:
          type: array
          items:
            $ref: '#/components/schemas/JSFunctionInfo'
        total_count:
          type: integer
        error:
          type: string
      required:
        - success
        - functions
        - total_count

    JSFunctionInfo:
      type: object
      properties:
        filename:
          type: string
        function_name:
          type: string
        description:
          type: string
        example:
          type: string
        min_args:
          type: integer
        max_args:
          type: integer
        file_size:
          type: integer
        last_modified:
          type: string
        is_valid:
          type: boolean
        validation_error:
          type: string
      required:
        - filename
        - file_size
        - last_modified
        - is_valid

    ReloadHooksResponse:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
        functions_loaded:
          type: integer
        error:
          type: string
      required:
        - success
        - message
        - functions_loaded

    ValidationResults:
      type: object
      properties:
        syntax_valid:
          type: boolean
        structure_valid:
          type: boolean
        example_test_passed:
          type: boolean
        example_result:
          type: string
        example_error:
          type: string
      required:
        - syntax_valid
        - structure_valid
        - example_test_passed

    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          enum: [false]
        error:
          type: string
          description: Error message
      required:
        - success
        - error
      example:
        success: false
        error: "Invalid expression syntax"