@formata/stof 0.9.15 → 0.9.17
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/README.md +102 -54
- package/dist/doc.d.ts +3 -14
- package/dist/doc.d.ts.map +1 -1
- package/dist/doc.js +37 -47
- package/dist/doc.js.map +1 -1
- package/dist/pkg/stof.d.ts +13 -13
- package/dist/pkg/stof.js +30 -26
- package/dist/pkg/stof_bg.wasm +0 -0
- package/dist/pkg/stof_bg.wasm.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,61 +19,51 @@
|
|
|
19
19
|
<br/>
|
|
20
20
|
|
|
21
21
|
## Overview
|
|
22
|
+
|
|
22
23
|
Data and logic have always been separate. That makes things hard. Stof puts them together.
|
|
23
24
|
|
|
24
|
-
A portable document format where validation, functions, and behavior live alongside the data they belong to
|
|
25
|
+
A portable document format where validation, functions, and behavior live alongside the data they belong to — in one document, across any service, language, or runtime.
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
- **Superset of JSON** — valid JSON is always valid Stof. Works with YAML, TOML, and more out of the box.
|
|
28
|
+
- **Sandboxed execution** — logic runs in a secure, isolated runtime. Safe to execute untrusted code from external sources.
|
|
29
|
+
- **Built in Rust, runs everywhere** — native crate, WebAssembly for JS/TS (Node, Deno, Bun, browser), and Python bindings via PyPI.
|
|
27
30
|
|
|
28
|
-
>
|
|
31
|
+
> Used in production: [Limitr](https://limitr.dev)'s pricing policy engine — plans, credits, limits, validation logic — runs entirely on Stof.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## Data That Does Things
|
|
35
|
+
|
|
36
|
+
Stof starts where JSON ends. Add functions right next to the data they operate on.
|
|
29
37
|
|
|
30
|
-
## Define Data and Logic Together - Combine/Split as Needed
|
|
31
|
-
`npm i @formata/stof`
|
|
32
38
|
```typescript
|
|
33
39
|
import { stofAsync } from '@formata/stof';
|
|
34
40
|
|
|
35
|
-
const doc = await stofAsync`
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
const doc = await stofAsync`
|
|
42
|
+
name: "Alice"
|
|
43
|
+
age: 30
|
|
38
44
|
|
|
39
|
-
fn
|
|
40
|
-
|
|
41
|
-
parse(self.json, policy, 'json');
|
|
42
|
-
|
|
43
|
-
policy.plans.pro.price.amount = 50;
|
|
44
|
-
const entitlements = policy.plans.pro.entitlements;
|
|
45
|
-
entitlements.ai_chat.limit.value *= 2;
|
|
46
|
-
|
|
47
|
-
self.yaml = stringify('yaml', policy);
|
|
48
|
-
Std.pln(self.yaml);
|
|
45
|
+
fn greet() -> str {
|
|
46
|
+
'Hello, ' + self.name + '!'
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
|
|
49
|
+
fn can_rent_car() -> bool {
|
|
50
|
+
self.age >= 25
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
52
53
|
|
|
53
|
-
await doc.call('
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
bun run transform.ts
|
|
57
|
-
plans:
|
|
58
|
-
pro:
|
|
59
|
-
label: Pro
|
|
60
|
-
price:
|
|
61
|
-
amount: 50
|
|
62
|
-
entitlements:
|
|
63
|
-
ai_chat:
|
|
64
|
-
description: AI Chat Feature
|
|
65
|
-
limit:
|
|
66
|
-
credit: chat-token
|
|
67
|
-
value: 200000
|
|
68
|
-
resets: true
|
|
69
|
-
reset_inc: 1.0
|
|
54
|
+
console.log(await doc.call('greet')); // Hello, Alice!
|
|
55
|
+
console.log(await doc.call('can_rent_car')); // true
|
|
70
56
|
```
|
|
71
57
|
|
|
58
|
+
No separate schema file. No external validator. The data knows its own rules.
|
|
59
|
+
|
|
60
|
+
|
|
72
61
|
## Units & Types
|
|
73
|
-
|
|
62
|
+
|
|
63
|
+
Rich type system with automatic unit conversions — time, distance, memory, temperature, and more.
|
|
74
64
|
|
|
75
65
|
```typescript
|
|
76
|
-
import { stofAsync } from '
|
|
66
|
+
import { stofAsync } from '@formata/stof';
|
|
77
67
|
|
|
78
68
|
const doc = await stofAsync`
|
|
79
69
|
#[type]
|
|
@@ -102,10 +92,56 @@ const dist = await doc.call('distance', '{ "x": 3, "y": 4 }');
|
|
|
102
92
|
console.log(dist); // 170.52
|
|
103
93
|
```
|
|
104
94
|
|
|
95
|
+
|
|
96
|
+
## Format Interop
|
|
97
|
+
|
|
98
|
+
Combine JSON, YAML, TOML, and Stof in a single document. Parse one format, transform it, export as another.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { stofAsync } from '@formata/stof';
|
|
102
|
+
|
|
103
|
+
const doc = await stofAsync`{
|
|
104
|
+
json: '{"plans":{"pro":{"label":"Pro","price":{"amount":20},"entitlements":{"ai_chat":{"description":"AI Chat Feature","limit":{"credit":"chat-token","value":100000,"resets":true,"reset_inc":1.0}}}}}}'
|
|
105
|
+
yaml: ''
|
|
106
|
+
|
|
107
|
+
fn transform() {
|
|
108
|
+
const policy = new {};
|
|
109
|
+
parse(self.json, policy, 'json');
|
|
110
|
+
|
|
111
|
+
policy.plans.pro.price.amount = 50;
|
|
112
|
+
const entitlements = policy.plans.pro.entitlements;
|
|
113
|
+
entitlements.ai_chat.limit.value *= 2;
|
|
114
|
+
|
|
115
|
+
self.yaml = stringify('yaml', policy);
|
|
116
|
+
Std.pln(self.yaml);
|
|
117
|
+
}
|
|
118
|
+
}`;
|
|
119
|
+
doc.lib('Std', 'pln', (...args: unknown[])=>console.log(...args));
|
|
120
|
+
|
|
121
|
+
await doc.call('transform');
|
|
122
|
+
```
|
|
123
|
+
```
|
|
124
|
+
plans:
|
|
125
|
+
pro:
|
|
126
|
+
label: Pro
|
|
127
|
+
price:
|
|
128
|
+
amount: 50
|
|
129
|
+
entitlements:
|
|
130
|
+
ai_chat:
|
|
131
|
+
description: AI Chat Feature
|
|
132
|
+
limit:
|
|
133
|
+
credit: chat-token
|
|
134
|
+
value: 200000
|
|
135
|
+
resets: true
|
|
136
|
+
reset_inc: 1.0
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
|
|
105
140
|
## Self-Expanding Contexts
|
|
106
|
-
Documents evolve over time. Stof can even parse itself for immediate use in the same call.
|
|
107
141
|
|
|
108
|
-
|
|
142
|
+
This is the capability that changes everything.
|
|
143
|
+
|
|
144
|
+
Stof documents can parse new Stof into themselves at runtime — receiving code over the network and immediately executing it. The program grows while it runs, always sandboxed.
|
|
109
145
|
|
|
110
146
|
```typescript
|
|
111
147
|
import { stofAsync } from '@formata/stof';
|
|
@@ -114,9 +150,10 @@ const doc = await stofAsync`
|
|
|
114
150
|
api: {}
|
|
115
151
|
|
|
116
152
|
fn load_api(stof: str) {
|
|
117
|
-
parse(stof, self.api);
|
|
153
|
+
parse(stof, self.api);
|
|
118
154
|
}`;
|
|
119
155
|
|
|
156
|
+
// Imagine this arriving over HTTP, from another service, or from an agent
|
|
120
157
|
const api = `
|
|
121
158
|
name: 'Stof'
|
|
122
159
|
fn message() -> str { 'Hello, ' + self.name ?? 'World' + '!!' }
|
|
@@ -128,12 +165,14 @@ fn main() {
|
|
|
128
165
|
|
|
129
166
|
doc.lib('Std', 'pln', (...args: unknown[])=>console.log(...args));
|
|
130
167
|
await doc.call('load_api', api);
|
|
131
|
-
await doc.run(); // calls #[main] funcs
|
|
168
|
+
await doc.run(); // calls #[main] funcs
|
|
132
169
|
|
|
133
170
|
// Hello, Stof
|
|
134
171
|
```
|
|
135
172
|
|
|
173
|
+
|
|
136
174
|
## CLI
|
|
175
|
+
|
|
137
176
|
See [installation docs](https://docs.stof.dev/book/installation) for CLI instructions and more information.
|
|
138
177
|
|
|
139
178
|
```rust
|
|
@@ -147,11 +186,14 @@ fn say_hi() {
|
|
|
147
186
|
Hello, world!
|
|
148
187
|
```
|
|
149
188
|
|
|
189
|
+
|
|
150
190
|
## Embedded
|
|
191
|
+
|
|
151
192
|
Stof is written in Rust, but use it where you work. Join the project [Discord](https://discord.gg/Up5kxdeXZt) to contribute.
|
|
152
193
|
|
|
153
194
|
### Rust
|
|
154
|
-
|
|
195
|
+
|
|
196
|
+
```toml
|
|
155
197
|
[dependencies]
|
|
156
198
|
stof = "0.9.*"
|
|
157
199
|
```
|
|
@@ -176,6 +218,7 @@ fn main() {
|
|
|
176
218
|
```
|
|
177
219
|
|
|
178
220
|
### Python
|
|
221
|
+
|
|
179
222
|
`pip install stof`
|
|
180
223
|
|
|
181
224
|
```python
|
|
@@ -206,9 +249,11 @@ if __name__ == "__main__":
|
|
|
206
249
|
```
|
|
207
250
|
|
|
208
251
|
### JavaScript/TypeScript
|
|
252
|
+
|
|
209
253
|
`npm i @formata/stof`
|
|
210
254
|
|
|
211
255
|
#### Initialization
|
|
256
|
+
|
|
212
257
|
Stof uses WebAssembly, so make sure to initialize it once.
|
|
213
258
|
|
|
214
259
|
```typescript
|
|
@@ -226,39 +271,39 @@ import { initStof } from '@formata/stof';
|
|
|
226
271
|
import stofWasm from '@formata/stof/wasm';
|
|
227
272
|
await initStof(await stofWasm());
|
|
228
273
|
```
|
|
274
|
+
|
|
275
|
+
#### Usage
|
|
276
|
+
|
|
229
277
|
```typescript
|
|
230
278
|
import { initStof, StofDoc } from '@formata/stof';
|
|
231
279
|
|
|
232
|
-
// Initialize wasm once at startup
|
|
233
280
|
await initStof();
|
|
234
281
|
|
|
235
|
-
// Create and parse documents
|
|
236
282
|
const doc = new StofDoc();
|
|
237
283
|
doc.parse(`
|
|
238
284
|
name: "Alice"
|
|
239
285
|
age: 30
|
|
240
|
-
fn greet() ->
|
|
241
|
-
|
|
286
|
+
fn greet() -> str {
|
|
287
|
+
'Hello, ' + self.name
|
|
242
288
|
}
|
|
243
289
|
`);
|
|
244
290
|
|
|
245
|
-
// Call functions and access values
|
|
246
291
|
const greeting = await doc.call('greet');
|
|
247
292
|
console.log(greeting); // "Hello, Alice"
|
|
248
293
|
console.log(doc.get('age')); // 30
|
|
249
294
|
```
|
|
250
295
|
|
|
251
296
|
#### JavaScript Interop
|
|
297
|
+
|
|
252
298
|
```typescript
|
|
253
299
|
await initStof();
|
|
254
300
|
const doc = new StofDoc();
|
|
255
301
|
|
|
256
|
-
// Register JS functions
|
|
257
302
|
doc.lib('console', 'log', (...args: unknown[]) => console.log(...args));
|
|
258
303
|
doc.lib('fetch', 'get', async (url: string) => {
|
|
259
304
|
const res = await fetch(url);
|
|
260
305
|
return await res.json();
|
|
261
|
-
}, true); // true = async function
|
|
306
|
+
}, true); // true = async function
|
|
262
307
|
|
|
263
308
|
doc.parse(`
|
|
264
309
|
fn main() {
|
|
@@ -271,21 +316,24 @@ await doc.call('main');
|
|
|
271
316
|
```
|
|
272
317
|
|
|
273
318
|
#### Parse & Export
|
|
319
|
+
|
|
274
320
|
```typescript
|
|
275
|
-
// Parse from JSON
|
|
276
321
|
doc.parse({ name: "Bob", age: 25 });
|
|
277
322
|
|
|
278
|
-
// Export to different formats
|
|
279
323
|
const json = doc.stringify('json');
|
|
280
|
-
const obj = doc.record();
|
|
324
|
+
const obj = doc.record();
|
|
281
325
|
```
|
|
282
326
|
|
|
283
327
|
**Supports**: Node.js, Browser, Deno, Bun, Edge runtimes
|
|
284
328
|
|
|
329
|
+
|
|
285
330
|
## License
|
|
331
|
+
|
|
286
332
|
Apache 2.0. See LICENSE for details.
|
|
287
333
|
|
|
334
|
+
|
|
288
335
|
## Feedback & Community
|
|
336
|
+
|
|
289
337
|
- Open issues or discussions on [GitHub](https://github.com/dev-formata-io/stof)
|
|
290
338
|
- Chat with us on [Discord](https://discord.gg/Up5kxdeXZt)
|
|
291
339
|
- Star the project to support future development!
|
package/dist/doc.d.ts
CHANGED
|
@@ -22,9 +22,9 @@ export declare function stofAsync(strings: TemplateStringsArray, ...values: unkn
|
|
|
22
22
|
* Stof document.
|
|
23
23
|
*/
|
|
24
24
|
export declare class StofDoc {
|
|
25
|
-
static readonly VERSION = "0.9.
|
|
25
|
+
static readonly VERSION = "0.9.17";
|
|
26
26
|
private static initialized?;
|
|
27
|
-
private static
|
|
27
|
+
private static wasmMutex;
|
|
28
28
|
stof: Stof;
|
|
29
29
|
/**
|
|
30
30
|
* Initialize Stof WASM.
|
|
@@ -39,7 +39,7 @@ export declare class StofDoc {
|
|
|
39
39
|
/**
|
|
40
40
|
* Ensure stof is initialized before creating a new instance.
|
|
41
41
|
*/
|
|
42
|
-
static new(): Promise<StofDoc>;
|
|
42
|
+
static new(src?: string | Record<string, unknown> | Uint8Array, format?: string, profile?: 'prod' | 'test'): Promise<StofDoc>;
|
|
43
43
|
/**
|
|
44
44
|
* Parse a JS object into a StofDoc.
|
|
45
45
|
*/
|
|
@@ -107,16 +107,5 @@ export declare class StofDoc {
|
|
|
107
107
|
* Create a deep copy of this document.
|
|
108
108
|
*/
|
|
109
109
|
clone(): Promise<StofDoc>;
|
|
110
|
-
/*****************************************************************************
|
|
111
|
-
* Network.
|
|
112
|
-
*****************************************************************************/
|
|
113
|
-
/**
|
|
114
|
-
* Send Stof doc string body as an HTTP request.
|
|
115
|
-
*/
|
|
116
|
-
static send(url: string, stof: string, method?: string, bearer?: string, headers?: Record<string, string>): Promise<Response>;
|
|
117
|
-
/**
|
|
118
|
-
* Send this document ('bstf' format) as an HTTP request.
|
|
119
|
-
*/
|
|
120
|
-
send(url: string, method?: string, bearer?: string, headers?: Record<string, string>): Promise<Response>;
|
|
121
110
|
}
|
|
122
111
|
//# sourceMappingURL=doc.d.ts.map
|
package/dist/doc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../doc.ts"],"names":[],"mappings":"AAiBA,OAAa,EAAE,IAAI,EAAY,MAAM,eAAe,CAAC;AAErD,cAAc,eAAe,CAAC;AAG9B;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CA4DnF;AAGD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAGD;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,oBAAoB,EAAE,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G,OAAO;IAM9E;;OAEG;IACH,SAAS,CAAC,MAAM,GAAE,MAAe,EAAE,IAAI,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM;IAKtE;;OAEG;IACH,OAAO,CAAC,MAAM,GAAE,MAAe,EAAE,IAAI,GAAE,MAAM,GAAG,IAAW,GAAG,UAAU;IAKxE;;OAEG;IACH,MAAM,CAAC,IAAI,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAK3D;;;OAGG;IACH,OAAO,IAAI,IAAI;IAOf;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;CAMlC"}
|
package/dist/doc.js
CHANGED
|
@@ -119,17 +119,31 @@ export async function stofAsync(strings, ...values) {
|
|
|
119
119
|
return doc;
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
|
-
* Internal
|
|
122
|
+
* Internal mutex for single linear WASM.
|
|
123
123
|
* Prevents race conditions and memory issues.
|
|
124
124
|
*/
|
|
125
|
-
class
|
|
125
|
+
class WasmMutex {
|
|
126
126
|
constructor() {
|
|
127
|
-
this.
|
|
127
|
+
this.locked = false;
|
|
128
|
+
this.waiters = [];
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
acquire() {
|
|
131
|
+
if (!this.locked) {
|
|
132
|
+
this.locked = true;
|
|
133
|
+
return Promise.resolve();
|
|
134
|
+
}
|
|
135
|
+
return new Promise((resolve) => {
|
|
136
|
+
this.waiters.push(resolve);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
release() {
|
|
140
|
+
if (this.waiters.length > 0) {
|
|
141
|
+
const next = this.waiters.shift();
|
|
142
|
+
setTimeout(next, 0); // Resolve on next so frame completes
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.locked = false;
|
|
146
|
+
}
|
|
133
147
|
}
|
|
134
148
|
}
|
|
135
149
|
/**
|
|
@@ -162,9 +176,12 @@ export class StofDoc {
|
|
|
162
176
|
/**
|
|
163
177
|
* Ensure stof is initialized before creating a new instance.
|
|
164
178
|
*/
|
|
165
|
-
static async new() {
|
|
179
|
+
static async new(src, format = "stof", profile = 'prod') {
|
|
166
180
|
await initStof();
|
|
167
|
-
|
|
181
|
+
const doc = new StofDoc();
|
|
182
|
+
if (src)
|
|
183
|
+
doc.parse(src, format, undefined, profile);
|
|
184
|
+
return doc;
|
|
168
185
|
}
|
|
169
186
|
/**
|
|
170
187
|
* Parse a JS object into a StofDoc.
|
|
@@ -199,16 +216,19 @@ export class StofDoc {
|
|
|
199
216
|
* Add JS library function.
|
|
200
217
|
*/
|
|
201
218
|
// deno-lint-ignore ban-types
|
|
202
|
-
lib(library, name, func, is_async
|
|
219
|
+
lib(library, name, func, is_async) {
|
|
203
220
|
const docid = this.stof.docid();
|
|
204
|
-
|
|
221
|
+
const async_fn = is_async ?? func.constructor.name === "AsyncFunction";
|
|
222
|
+
this.stof.js_library_function(new StofFunc(docid, library, name, func, async_fn));
|
|
205
223
|
}
|
|
206
224
|
/**
|
|
207
225
|
* Run this document with a given set of Stof attributes.
|
|
208
226
|
* Will run all #[main] functions by default.
|
|
209
227
|
*/
|
|
210
228
|
async run(attr = 'main') {
|
|
211
|
-
|
|
229
|
+
const acquire = () => StofDoc.wasmMutex.acquire();
|
|
230
|
+
const release = () => StofDoc.wasmMutex.release();
|
|
231
|
+
return await this.stof.run_with_gate(attr, acquire, release);
|
|
212
232
|
}
|
|
213
233
|
/**
|
|
214
234
|
* Run this document with a given set of Stof attributes (synchronously).
|
|
@@ -224,7 +244,9 @@ export class StofDoc {
|
|
|
224
244
|
async call(path, ...args) {
|
|
225
245
|
if (!path.includes('.'))
|
|
226
246
|
path = 'root.' + path; // assume root node if not specified
|
|
227
|
-
|
|
247
|
+
const acquire = () => StofDoc.wasmMutex.acquire();
|
|
248
|
+
const release = () => StofDoc.wasmMutex.release();
|
|
249
|
+
return await this.stof.call_with_gate(path, args, acquire, release);
|
|
228
250
|
}
|
|
229
251
|
/**
|
|
230
252
|
* Call a specific Stof function by path/name.
|
|
@@ -288,39 +310,7 @@ export class StofDoc {
|
|
|
288
310
|
doc.stof.binaryImport(serialized, 'bstf', null, 'prod');
|
|
289
311
|
return doc;
|
|
290
312
|
}
|
|
291
|
-
/*****************************************************************************
|
|
292
|
-
* Network.
|
|
293
|
-
*****************************************************************************/
|
|
294
|
-
/**
|
|
295
|
-
* Send Stof doc string body as an HTTP request.
|
|
296
|
-
*/
|
|
297
|
-
static async send(url, stof, method = 'POST', bearer, headers = {}) {
|
|
298
|
-
headers['Content-Type'] = 'application/stof';
|
|
299
|
-
if (bearer !== undefined)
|
|
300
|
-
headers['Authorization'] = `Bearer ${bearer}`;
|
|
301
|
-
return await fetch(url, {
|
|
302
|
-
method,
|
|
303
|
-
headers: headers,
|
|
304
|
-
body: stof
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Send this document ('bstf' format) as an HTTP request.
|
|
309
|
-
*/
|
|
310
|
-
async send(url, method = 'POST', bearer, headers = {}) {
|
|
311
|
-
return await StofDoc.wasmGate.run(async () => {
|
|
312
|
-
headers['Content-Type'] = 'application/bstf';
|
|
313
|
-
if (bearer !== undefined)
|
|
314
|
-
headers['Authorization'] = `Bearer ${bearer}`;
|
|
315
|
-
const body = this.stof.binaryExport('bstf', null); // Uint8Array
|
|
316
|
-
return await fetch(url, {
|
|
317
|
-
method,
|
|
318
|
-
headers: headers,
|
|
319
|
-
body
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
313
|
}
|
|
324
|
-
StofDoc.VERSION = '0.9.
|
|
325
|
-
StofDoc.
|
|
314
|
+
StofDoc.VERSION = '0.9.17';
|
|
315
|
+
StofDoc.wasmMutex = new WasmMutex();
|
|
326
316
|
//# sourceMappingURL=doc.js.map
|
package/dist/doc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc.js","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
* Import a JS object value.
|
|
19
19
|
*/
|
|
20
20
|
objImport(js_obj: any, node: any): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Run functions with the given attribute(s) in this document.
|
|
23
|
+
* Attributes defaults to #[main] functions if null or undefined.
|
|
24
|
+
*/
|
|
25
|
+
run_with_gate(attributes: any, acquire: Function, release: Function): Promise<string>;
|
|
21
26
|
/**
|
|
22
27
|
* String export, using a format of choice.
|
|
23
28
|
*/
|
|
@@ -26,6 +31,12 @@ export class Stof {
|
|
|
26
31
|
* String import, using a format of choice (including stof).
|
|
27
32
|
*/
|
|
28
33
|
stringImport(src: string, format: string, node: any, profile: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Call a singular function in the document (by path).
|
|
36
|
+
* If no arguments, pass undefined as args.
|
|
37
|
+
* Otherwise, pass an array of arguments as args.
|
|
38
|
+
*/
|
|
39
|
+
call_with_gate(path: string, args: any, acquire: Function, release: Function): Promise<any>;
|
|
29
40
|
/**
|
|
30
41
|
* Insert a JS function as a library function, available in Stof.
|
|
31
42
|
*/
|
|
@@ -38,21 +49,10 @@ export class Stof {
|
|
|
38
49
|
* Construct a new document.
|
|
39
50
|
*/
|
|
40
51
|
constructor();
|
|
41
|
-
/**
|
|
42
|
-
* Run functions with the given attribute(s) in this document.
|
|
43
|
-
* Attributes defaults to #[main] functions if null or undefined.
|
|
44
|
-
*/
|
|
45
|
-
run(attributes: any): Promise<string>;
|
|
46
52
|
/**
|
|
47
53
|
* Set a value onto this graph using the Stof runtime.
|
|
48
54
|
*/
|
|
49
55
|
set(path: string, value: any, start: any): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Call a singular function in the document (by path).
|
|
52
|
-
* If no arguments, pass undefined as args.
|
|
53
|
-
* Otherwise, pass an array of arguments as args.
|
|
54
|
-
*/
|
|
55
|
-
call(path: string, args: any): Promise<any>;
|
|
56
56
|
/**
|
|
57
57
|
* Get the ID of this document as a string.
|
|
58
58
|
*/
|
|
@@ -100,14 +100,14 @@ export interface InitOutput {
|
|
|
100
100
|
readonly start: () => void;
|
|
101
101
|
readonly stof_binaryExport: (a: number, b: number, c: number, d: any) => [number, number, number];
|
|
102
102
|
readonly stof_binaryImport: (a: number, b: any, c: number, d: number, e: any, f: number, g: number) => [number, number, number];
|
|
103
|
-
readonly
|
|
103
|
+
readonly stof_call_with_gate: (a: number, b: number, c: number, d: any, e: any, f: any) => any;
|
|
104
104
|
readonly stof_docid: (a: number) => [number, number];
|
|
105
105
|
readonly stof_get: (a: number, b: number, c: number, d: any) => any;
|
|
106
106
|
readonly stof_js_library_function: (a: number, b: number) => void;
|
|
107
107
|
readonly stof_new: () => number;
|
|
108
108
|
readonly stof_objImport: (a: number, b: any, c: any) => [number, number, number];
|
|
109
109
|
readonly stof_parse: (a: number, b: number, c: number, d: any, e: number, f: number) => [number, number, number];
|
|
110
|
-
readonly
|
|
110
|
+
readonly stof_run_with_gate: (a: number, b: any, c: any, d: any) => any;
|
|
111
111
|
readonly stof_set: (a: number, b: number, c: number, d: any, e: any) => number;
|
|
112
112
|
readonly stof_stringExport: (a: number, b: number, c: number, d: any) => [number, number, number, number];
|
|
113
113
|
readonly stof_stringImport: (a: number, b: number, c: number, d: number, e: number, f: any, g: number, h: number) => [number, number, number];
|
package/dist/pkg/stof.js
CHANGED
|
@@ -300,6 +300,18 @@ export class Stof {
|
|
|
300
300
|
}
|
|
301
301
|
return ret[0] !== 0;
|
|
302
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Run functions with the given attribute(s) in this document.
|
|
305
|
+
* Attributes defaults to #[main] functions if null or undefined.
|
|
306
|
+
* @param {any} attributes
|
|
307
|
+
* @param {Function} acquire
|
|
308
|
+
* @param {Function} release
|
|
309
|
+
* @returns {Promise<string>}
|
|
310
|
+
*/
|
|
311
|
+
run_with_gate(attributes, acquire, release) {
|
|
312
|
+
const ret = wasm.stof_run_with_gate(this.__wbg_ptr, attributes, acquire, release);
|
|
313
|
+
return ret;
|
|
314
|
+
}
|
|
303
315
|
/**
|
|
304
316
|
* String export, using a format of choice.
|
|
305
317
|
* @param {string} format
|
|
@@ -347,6 +359,22 @@ export class Stof {
|
|
|
347
359
|
}
|
|
348
360
|
return ret[0] !== 0;
|
|
349
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Call a singular function in the document (by path).
|
|
364
|
+
* If no arguments, pass undefined as args.
|
|
365
|
+
* Otherwise, pass an array of arguments as args.
|
|
366
|
+
* @param {string} path
|
|
367
|
+
* @param {any} args
|
|
368
|
+
* @param {Function} acquire
|
|
369
|
+
* @param {Function} release
|
|
370
|
+
* @returns {Promise<any>}
|
|
371
|
+
*/
|
|
372
|
+
call_with_gate(path, args, acquire, release) {
|
|
373
|
+
const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
374
|
+
const len0 = WASM_VECTOR_LEN;
|
|
375
|
+
const ret = wasm.stof_call_with_gate(this.__wbg_ptr, ptr0, len0, args, acquire, release);
|
|
376
|
+
return ret;
|
|
377
|
+
}
|
|
350
378
|
/**
|
|
351
379
|
* Insert a JS function as a library function, available in Stof.
|
|
352
380
|
* @param {StofFunc} func
|
|
@@ -377,16 +405,6 @@ export class Stof {
|
|
|
377
405
|
StofFinalization.register(this, this.__wbg_ptr, this);
|
|
378
406
|
return this;
|
|
379
407
|
}
|
|
380
|
-
/**
|
|
381
|
-
* Run functions with the given attribute(s) in this document.
|
|
382
|
-
* Attributes defaults to #[main] functions if null or undefined.
|
|
383
|
-
* @param {any} attributes
|
|
384
|
-
* @returns {Promise<string>}
|
|
385
|
-
*/
|
|
386
|
-
run(attributes) {
|
|
387
|
-
const ret = wasm.stof_run(this.__wbg_ptr, attributes);
|
|
388
|
-
return ret;
|
|
389
|
-
}
|
|
390
408
|
/**
|
|
391
409
|
* Set a value onto this graph using the Stof runtime.
|
|
392
410
|
* @param {string} path
|
|
@@ -400,20 +418,6 @@ export class Stof {
|
|
|
400
418
|
const ret = wasm.stof_set(this.__wbg_ptr, ptr0, len0, value, start);
|
|
401
419
|
return ret !== 0;
|
|
402
420
|
}
|
|
403
|
-
/**
|
|
404
|
-
* Call a singular function in the document (by path).
|
|
405
|
-
* If no arguments, pass undefined as args.
|
|
406
|
-
* Otherwise, pass an array of arguments as args.
|
|
407
|
-
* @param {string} path
|
|
408
|
-
* @param {any} args
|
|
409
|
-
* @returns {Promise<any>}
|
|
410
|
-
*/
|
|
411
|
-
call(path, args) {
|
|
412
|
-
const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
413
|
-
const len0 = WASM_VECTOR_LEN;
|
|
414
|
-
const ret = wasm.stof_call(this.__wbg_ptr, ptr0, len0, args);
|
|
415
|
-
return ret;
|
|
416
|
-
}
|
|
417
421
|
/**
|
|
418
422
|
* Get the ID of this document as a string.
|
|
419
423
|
* @returns {string}
|
|
@@ -1015,8 +1019,8 @@ function __wbg_get_imports() {
|
|
|
1015
1019
|
const ret = BigInt.asUintN(64, arg0);
|
|
1016
1020
|
return ret;
|
|
1017
1021
|
};
|
|
1018
|
-
imports.wbg.
|
|
1019
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1022
|
+
imports.wbg.__wbindgen_cast_4f41d4709fd67779 = function(arg0, arg1) {
|
|
1023
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 7056, function: Function { arguments: [Externref], shim_idx: 7057, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1020
1024
|
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h72b14ab7db8750ca, wasm_bindgen__convert__closures_____invoke__h53d5cf04cab8438f);
|
|
1021
1025
|
return ret;
|
|
1022
1026
|
};
|
package/dist/pkg/stof_bg.wasm
CHANGED
|
Binary file
|
|
@@ -6,14 +6,14 @@ export const __wbg_stoffunc_free: (a: number, b: number) => void;
|
|
|
6
6
|
export const start: () => void;
|
|
7
7
|
export const stof_binaryExport: (a: number, b: number, c: number, d: any) => [number, number, number];
|
|
8
8
|
export const stof_binaryImport: (a: number, b: any, c: number, d: number, e: any, f: number, g: number) => [number, number, number];
|
|
9
|
-
export const
|
|
9
|
+
export const stof_call_with_gate: (a: number, b: number, c: number, d: any, e: any, f: any) => any;
|
|
10
10
|
export const stof_docid: (a: number) => [number, number];
|
|
11
11
|
export const stof_get: (a: number, b: number, c: number, d: any) => any;
|
|
12
12
|
export const stof_js_library_function: (a: number, b: number) => void;
|
|
13
13
|
export const stof_new: () => number;
|
|
14
14
|
export const stof_objImport: (a: number, b: any, c: any) => [number, number, number];
|
|
15
15
|
export const stof_parse: (a: number, b: number, c: number, d: any, e: number, f: number) => [number, number, number];
|
|
16
|
-
export const
|
|
16
|
+
export const stof_run_with_gate: (a: number, b: any, c: any, d: any) => any;
|
|
17
17
|
export const stof_set: (a: number, b: number, c: number, d: any, e: any) => number;
|
|
18
18
|
export const stof_stringExport: (a: number, b: number, c: number, d: any) => [number, number, number, number];
|
|
19
19
|
export const stof_stringImport: (a: number, b: number, c: number, d: number, e: number, f: any, g: number, h: number) => [number, number, number];
|