@trufnetwork/sdk-js 0.2.0 → 0.2.2
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/dist/cjs/client/client.cjs +4 -2
- package/dist/cjs/client/client.cjs.map +2 -2
- package/dist/cjs/contracts/composed_stream_template_unix.json +2122 -0
- package/dist/cjs/contracts/contractsContent.cjs +13 -1
- package/dist/cjs/contracts/contractsContent.cjs.map +3 -3
- package/dist/cjs/contracts/primitive_stream_template_unix.json +1173 -0
- package/dist/cjs/contracts-api/composedStream.cjs.map +2 -2
- package/dist/cjs/contracts-api/deployStream.cjs +4 -4
- package/dist/cjs/contracts-api/deployStream.cjs.map +2 -2
- package/dist/cjs/contracts-api/primitiveStream.cjs.map +1 -1
- package/dist/cjs/contracts-api/stream.cjs +25 -0
- package/dist/cjs/contracts-api/stream.cjs.map +2 -2
- package/dist/esm/client/client.mjs +4 -2
- package/dist/esm/client/client.mjs.map +2 -2
- package/dist/esm/contracts/composed_stream_template_unix.json +2122 -0
- package/dist/esm/contracts/contractsContent.mjs +13 -1
- package/dist/esm/contracts/contractsContent.mjs.map +2 -2
- package/dist/esm/contracts/primitive_stream_template_unix.json +1173 -0
- package/dist/esm/contracts-api/composedStream.mjs.map +2 -2
- package/dist/esm/contracts-api/deployStream.mjs +7 -5
- package/dist/esm/contracts-api/deployStream.mjs.map +2 -2
- package/dist/esm/contracts-api/primitiveStream.mjs.map +1 -1
- package/dist/esm/contracts-api/stream.mjs +25 -0
- package/dist/esm/contracts-api/stream.mjs.map +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/client/client.d.ts +2 -1
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/contracts/contractsContent.d.ts +3 -1
- package/dist/types/contracts/contractsContent.d.ts.map +1 -1
- package/dist/types/contracts-api/composedStream.d.ts +1 -1
- package/dist/types/contracts-api/composedStream.d.ts.map +1 -1
- package/dist/types/contracts-api/deployStream.d.ts +1 -0
- package/dist/types/contracts-api/deployStream.d.ts.map +1 -1
- package/dist/types/contracts-api/primitiveStream.d.ts +1 -1
- package/dist/types/contracts-api/primitiveStream.d.ts.map +1 -1
- package/dist/types/contracts-api/stream.d.ts +13 -6
- package/dist/types/contracts-api/stream.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,2122 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "composed_stream_db_name",
|
|
3
|
+
"owner": "",
|
|
4
|
+
"extensions": null,
|
|
5
|
+
"tables": [
|
|
6
|
+
{
|
|
7
|
+
"name": "taxonomies",
|
|
8
|
+
"columns": [
|
|
9
|
+
{
|
|
10
|
+
"name": "taxonomy_id",
|
|
11
|
+
"type": {
|
|
12
|
+
"name": "uuid",
|
|
13
|
+
"is_array": false,
|
|
14
|
+
"metadata": [
|
|
15
|
+
0,
|
|
16
|
+
0
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"attributes": [
|
|
20
|
+
{
|
|
21
|
+
"type": "PRIMARY_KEY",
|
|
22
|
+
"value": ""
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"type": "NOT_NULL",
|
|
26
|
+
"value": ""
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "child_stream_id",
|
|
32
|
+
"type": {
|
|
33
|
+
"name": "text",
|
|
34
|
+
"is_array": false,
|
|
35
|
+
"metadata": [
|
|
36
|
+
0,
|
|
37
|
+
0
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"attributes": [
|
|
41
|
+
{
|
|
42
|
+
"type": "NOT_NULL",
|
|
43
|
+
"value": ""
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"name": "child_data_provider",
|
|
49
|
+
"type": {
|
|
50
|
+
"name": "text",
|
|
51
|
+
"is_array": false,
|
|
52
|
+
"metadata": [
|
|
53
|
+
0,
|
|
54
|
+
0
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
"attributes": [
|
|
58
|
+
{
|
|
59
|
+
"type": "NOT_NULL",
|
|
60
|
+
"value": ""
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "weight",
|
|
66
|
+
"type": {
|
|
67
|
+
"name": "decimal",
|
|
68
|
+
"is_array": false,
|
|
69
|
+
"metadata": [
|
|
70
|
+
36,
|
|
71
|
+
18
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"attributes": [
|
|
75
|
+
{
|
|
76
|
+
"type": "NOT_NULL",
|
|
77
|
+
"value": ""
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "created_at",
|
|
83
|
+
"type": {
|
|
84
|
+
"name": "int",
|
|
85
|
+
"is_array": false,
|
|
86
|
+
"metadata": [
|
|
87
|
+
0,
|
|
88
|
+
0
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
"attributes": [
|
|
92
|
+
{
|
|
93
|
+
"type": "NOT_NULL",
|
|
94
|
+
"value": ""
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "disabled_at",
|
|
100
|
+
"type": {
|
|
101
|
+
"name": "int",
|
|
102
|
+
"is_array": false,
|
|
103
|
+
"metadata": [
|
|
104
|
+
0,
|
|
105
|
+
0
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
"attributes": null
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "version",
|
|
112
|
+
"type": {
|
|
113
|
+
"name": "int",
|
|
114
|
+
"is_array": false,
|
|
115
|
+
"metadata": [
|
|
116
|
+
0,
|
|
117
|
+
0
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
"attributes": [
|
|
121
|
+
{
|
|
122
|
+
"type": "NOT_NULL",
|
|
123
|
+
"value": ""
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"name": "start_date",
|
|
129
|
+
"type": {
|
|
130
|
+
"name": "int",
|
|
131
|
+
"is_array": false,
|
|
132
|
+
"metadata": [
|
|
133
|
+
0,
|
|
134
|
+
0
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
"attributes": null
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
"indexes": null,
|
|
141
|
+
"foreign_keys": null
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name": "metadata",
|
|
145
|
+
"columns": [
|
|
146
|
+
{
|
|
147
|
+
"name": "row_id",
|
|
148
|
+
"type": {
|
|
149
|
+
"name": "uuid",
|
|
150
|
+
"is_array": false,
|
|
151
|
+
"metadata": [
|
|
152
|
+
0,
|
|
153
|
+
0
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
"attributes": [
|
|
157
|
+
{
|
|
158
|
+
"type": "PRIMARY_KEY",
|
|
159
|
+
"value": ""
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"type": "NOT_NULL",
|
|
163
|
+
"value": ""
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"name": "metadata_key",
|
|
169
|
+
"type": {
|
|
170
|
+
"name": "text",
|
|
171
|
+
"is_array": false,
|
|
172
|
+
"metadata": [
|
|
173
|
+
0,
|
|
174
|
+
0
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
"attributes": [
|
|
178
|
+
{
|
|
179
|
+
"type": "NOT_NULL",
|
|
180
|
+
"value": ""
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"name": "value_i",
|
|
186
|
+
"type": {
|
|
187
|
+
"name": "int",
|
|
188
|
+
"is_array": false,
|
|
189
|
+
"metadata": [
|
|
190
|
+
0,
|
|
191
|
+
0
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
"attributes": null
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"name": "value_f",
|
|
198
|
+
"type": {
|
|
199
|
+
"name": "decimal",
|
|
200
|
+
"is_array": false,
|
|
201
|
+
"metadata": [
|
|
202
|
+
36,
|
|
203
|
+
18
|
|
204
|
+
]
|
|
205
|
+
},
|
|
206
|
+
"attributes": null
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"name": "value_b",
|
|
210
|
+
"type": {
|
|
211
|
+
"name": "bool",
|
|
212
|
+
"is_array": false,
|
|
213
|
+
"metadata": [
|
|
214
|
+
0,
|
|
215
|
+
0
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
"attributes": null
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"name": "value_s",
|
|
222
|
+
"type": {
|
|
223
|
+
"name": "text",
|
|
224
|
+
"is_array": false,
|
|
225
|
+
"metadata": [
|
|
226
|
+
0,
|
|
227
|
+
0
|
|
228
|
+
]
|
|
229
|
+
},
|
|
230
|
+
"attributes": null
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"name": "value_ref",
|
|
234
|
+
"type": {
|
|
235
|
+
"name": "text",
|
|
236
|
+
"is_array": false,
|
|
237
|
+
"metadata": [
|
|
238
|
+
0,
|
|
239
|
+
0
|
|
240
|
+
]
|
|
241
|
+
},
|
|
242
|
+
"attributes": null
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"name": "created_at",
|
|
246
|
+
"type": {
|
|
247
|
+
"name": "int",
|
|
248
|
+
"is_array": false,
|
|
249
|
+
"metadata": [
|
|
250
|
+
0,
|
|
251
|
+
0
|
|
252
|
+
]
|
|
253
|
+
},
|
|
254
|
+
"attributes": [
|
|
255
|
+
{
|
|
256
|
+
"type": "NOT_NULL",
|
|
257
|
+
"value": ""
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"name": "disabled_at",
|
|
263
|
+
"type": {
|
|
264
|
+
"name": "int",
|
|
265
|
+
"is_array": false,
|
|
266
|
+
"metadata": [
|
|
267
|
+
0,
|
|
268
|
+
0
|
|
269
|
+
]
|
|
270
|
+
},
|
|
271
|
+
"attributes": null
|
|
272
|
+
}
|
|
273
|
+
],
|
|
274
|
+
"indexes": [
|
|
275
|
+
{
|
|
276
|
+
"name": "key_idx",
|
|
277
|
+
"columns": [
|
|
278
|
+
"metadata_key"
|
|
279
|
+
],
|
|
280
|
+
"type": "BTREE"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"name": "ref_idx",
|
|
284
|
+
"columns": [
|
|
285
|
+
"value_ref"
|
|
286
|
+
],
|
|
287
|
+
"type": "BTREE"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"name": "created_idx",
|
|
291
|
+
"columns": [
|
|
292
|
+
"created_at"
|
|
293
|
+
],
|
|
294
|
+
"type": "BTREE"
|
|
295
|
+
}
|
|
296
|
+
],
|
|
297
|
+
"foreign_keys": null
|
|
298
|
+
}
|
|
299
|
+
],
|
|
300
|
+
"actions": null,
|
|
301
|
+
"procedures": [
|
|
302
|
+
{
|
|
303
|
+
"name": "stream_exists",
|
|
304
|
+
"parameters": [
|
|
305
|
+
{
|
|
306
|
+
"name": "$data_provider",
|
|
307
|
+
"type": {
|
|
308
|
+
"name": "text",
|
|
309
|
+
"is_array": false,
|
|
310
|
+
"metadata": [
|
|
311
|
+
0,
|
|
312
|
+
0
|
|
313
|
+
]
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
"name": "$stream_id",
|
|
318
|
+
"type": {
|
|
319
|
+
"name": "text",
|
|
320
|
+
"is_array": false,
|
|
321
|
+
"metadata": [
|
|
322
|
+
0,
|
|
323
|
+
0
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
],
|
|
328
|
+
"public": true,
|
|
329
|
+
"modifiers": [
|
|
330
|
+
"VIEW"
|
|
331
|
+
],
|
|
332
|
+
"body": "$dbid text := get_dbid($data_provider, $stream_id);\n\n for $row in SELECT * FROM get_metadata('type', true, null) {\n return true;\n }\n\n return false;",
|
|
333
|
+
"return_types": {
|
|
334
|
+
"is_table": false,
|
|
335
|
+
"fields": [
|
|
336
|
+
{
|
|
337
|
+
"name": "result",
|
|
338
|
+
"type": {
|
|
339
|
+
"name": "bool",
|
|
340
|
+
"is_array": false,
|
|
341
|
+
"metadata": [
|
|
342
|
+
0,
|
|
343
|
+
0
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
},
|
|
349
|
+
"annotations": null
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
"name": "get_dbid",
|
|
353
|
+
"parameters": [
|
|
354
|
+
{
|
|
355
|
+
"name": "$data_provider",
|
|
356
|
+
"type": {
|
|
357
|
+
"name": "text",
|
|
358
|
+
"is_array": false,
|
|
359
|
+
"metadata": [
|
|
360
|
+
0,
|
|
361
|
+
0
|
|
362
|
+
]
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
"name": "$stream_id",
|
|
367
|
+
"type": {
|
|
368
|
+
"name": "text",
|
|
369
|
+
"is_array": false,
|
|
370
|
+
"metadata": [
|
|
371
|
+
0,
|
|
372
|
+
0
|
|
373
|
+
]
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
],
|
|
377
|
+
"public": false,
|
|
378
|
+
"modifiers": [
|
|
379
|
+
"VIEW"
|
|
380
|
+
],
|
|
381
|
+
"body": "$starts_with_0x bool := false;\n for $row in SELECT $data_provider LIKE '0x%' as a {\n $starts_with_0x := $row.a;\n }\n\n $data_provider_without_0x text;\n\n if $starts_with_0x == true {\n $data_provider_without_0x := substring($data_provider, 3);\n } else {\n $data_provider_without_0x := $data_provider;\n }\n\n return generate_dbid($stream_id, decode($data_provider_without_0x, 'hex'));",
|
|
382
|
+
"return_types": {
|
|
383
|
+
"is_table": false,
|
|
384
|
+
"fields": [
|
|
385
|
+
{
|
|
386
|
+
"name": "result",
|
|
387
|
+
"type": {
|
|
388
|
+
"name": "text",
|
|
389
|
+
"is_array": false,
|
|
390
|
+
"metadata": [
|
|
391
|
+
0,
|
|
392
|
+
0
|
|
393
|
+
]
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
]
|
|
397
|
+
},
|
|
398
|
+
"annotations": null
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
"name": "get_raw_record",
|
|
402
|
+
"parameters": [
|
|
403
|
+
{
|
|
404
|
+
"name": "$date_from",
|
|
405
|
+
"type": {
|
|
406
|
+
"name": "int",
|
|
407
|
+
"is_array": false,
|
|
408
|
+
"metadata": [
|
|
409
|
+
0,
|
|
410
|
+
0
|
|
411
|
+
]
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
"name": "$date_to",
|
|
416
|
+
"type": {
|
|
417
|
+
"name": "int",
|
|
418
|
+
"is_array": false,
|
|
419
|
+
"metadata": [
|
|
420
|
+
0,
|
|
421
|
+
0
|
|
422
|
+
]
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
"name": "$frozen_at",
|
|
427
|
+
"type": {
|
|
428
|
+
"name": "int",
|
|
429
|
+
"is_array": false,
|
|
430
|
+
"metadata": [
|
|
431
|
+
0,
|
|
432
|
+
0
|
|
433
|
+
]
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
"name": "$child_data_providers",
|
|
438
|
+
"type": {
|
|
439
|
+
"name": "text",
|
|
440
|
+
"is_array": true,
|
|
441
|
+
"metadata": [
|
|
442
|
+
0,
|
|
443
|
+
0
|
|
444
|
+
]
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
"name": "$child_stream_ids",
|
|
449
|
+
"type": {
|
|
450
|
+
"name": "text",
|
|
451
|
+
"is_array": true,
|
|
452
|
+
"metadata": [
|
|
453
|
+
0,
|
|
454
|
+
0
|
|
455
|
+
]
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
],
|
|
459
|
+
"public": false,
|
|
460
|
+
"modifiers": [
|
|
461
|
+
"VIEW"
|
|
462
|
+
],
|
|
463
|
+
"body": "if is_wallet_allowed_to_read(@caller) == false {\n error('wallet not allowed to read');\n }\n // check if the stream is allowed to compose\n is_stream_allowed_to_compose(@foreign_caller);\n\n // check if the child_data_providers and child_stream_id are the same length\n if array_length($child_data_providers) != array_length($child_stream_ids) {\n error('child_data_providers and child_stream_id must be the same length');\n }\n\n if array_length($child_data_providers) \u003e 0 {\n // arrays are 1-indexed, so we match that\n for $taxonomy_index in 1..array_length($child_data_providers) {\n $dbid text := get_dbid($child_data_providers[$taxonomy_index], $child_stream_ids[$taxonomy_index]);\n for $row3 in SELECT * FROM ext_get_record[$dbid, 'get_record']($date_from, $date_to, $frozen_at) {\n return next $row3.date_value, $row3.value, $taxonomy_index;\n }\n }\n }",
|
|
464
|
+
"return_types": {
|
|
465
|
+
"is_table": true,
|
|
466
|
+
"fields": [
|
|
467
|
+
{
|
|
468
|
+
"name": "date_value",
|
|
469
|
+
"type": {
|
|
470
|
+
"name": "int",
|
|
471
|
+
"is_array": false,
|
|
472
|
+
"metadata": [
|
|
473
|
+
0,
|
|
474
|
+
0
|
|
475
|
+
]
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
"name": "value",
|
|
480
|
+
"type": {
|
|
481
|
+
"name": "decimal",
|
|
482
|
+
"is_array": false,
|
|
483
|
+
"metadata": [
|
|
484
|
+
36,
|
|
485
|
+
18
|
|
486
|
+
]
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
"name": "taxonomy_index",
|
|
491
|
+
"type": {
|
|
492
|
+
"name": "int",
|
|
493
|
+
"is_array": false,
|
|
494
|
+
"metadata": [
|
|
495
|
+
0,
|
|
496
|
+
0
|
|
497
|
+
]
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
]
|
|
501
|
+
},
|
|
502
|
+
"annotations": null
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
"name": "get_raw_index",
|
|
506
|
+
"parameters": [
|
|
507
|
+
{
|
|
508
|
+
"name": "$date_from",
|
|
509
|
+
"type": {
|
|
510
|
+
"name": "int",
|
|
511
|
+
"is_array": false,
|
|
512
|
+
"metadata": [
|
|
513
|
+
0,
|
|
514
|
+
0
|
|
515
|
+
]
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
"name": "$date_to",
|
|
520
|
+
"type": {
|
|
521
|
+
"name": "int",
|
|
522
|
+
"is_array": false,
|
|
523
|
+
"metadata": [
|
|
524
|
+
0,
|
|
525
|
+
0
|
|
526
|
+
]
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
"name": "$frozen_at",
|
|
531
|
+
"type": {
|
|
532
|
+
"name": "int",
|
|
533
|
+
"is_array": false,
|
|
534
|
+
"metadata": [
|
|
535
|
+
0,
|
|
536
|
+
0
|
|
537
|
+
]
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
"name": "$child_data_providers",
|
|
542
|
+
"type": {
|
|
543
|
+
"name": "text",
|
|
544
|
+
"is_array": true,
|
|
545
|
+
"metadata": [
|
|
546
|
+
0,
|
|
547
|
+
0
|
|
548
|
+
]
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
"name": "$child_stream_ids",
|
|
553
|
+
"type": {
|
|
554
|
+
"name": "text",
|
|
555
|
+
"is_array": true,
|
|
556
|
+
"metadata": [
|
|
557
|
+
0,
|
|
558
|
+
0
|
|
559
|
+
]
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
"name": "$base_date",
|
|
564
|
+
"type": {
|
|
565
|
+
"name": "int",
|
|
566
|
+
"is_array": false,
|
|
567
|
+
"metadata": [
|
|
568
|
+
0,
|
|
569
|
+
0
|
|
570
|
+
]
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
],
|
|
574
|
+
"public": false,
|
|
575
|
+
"modifiers": [
|
|
576
|
+
"VIEW"
|
|
577
|
+
],
|
|
578
|
+
"body": "if is_wallet_allowed_to_read(@caller) == false {\n error('wallet not allowed to read');\n }\n // check if the stream is allowed to compose\n is_stream_allowed_to_compose(@foreign_caller);\n\n // check if the child_data_providers and child_stream_id are the same length\n if array_length($child_data_providers) != array_length($child_stream_ids) {\n error('child_data_providers and child_stream_id must be the same length');\n }\n\n if array_length($child_data_providers) \u003e 0 {\n // arrays are 1-indexed, so we match that\n for $taxonomy_index in 1..array_length($child_data_providers) {\n $dbid text := get_dbid($child_data_providers[$taxonomy_index], $child_stream_ids[$taxonomy_index]);\n for $row in SELECT * FROM ext_get_index[$dbid, 'get_index']($date_from, $date_to, $frozen_at, $base_date) {\n return next $row.date_value, $row.value, $taxonomy_index;\n }\n }\n }",
|
|
579
|
+
"return_types": {
|
|
580
|
+
"is_table": true,
|
|
581
|
+
"fields": [
|
|
582
|
+
{
|
|
583
|
+
"name": "date_value",
|
|
584
|
+
"type": {
|
|
585
|
+
"name": "int",
|
|
586
|
+
"is_array": false,
|
|
587
|
+
"metadata": [
|
|
588
|
+
0,
|
|
589
|
+
0
|
|
590
|
+
]
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
"name": "value",
|
|
595
|
+
"type": {
|
|
596
|
+
"name": "decimal",
|
|
597
|
+
"is_array": false,
|
|
598
|
+
"metadata": [
|
|
599
|
+
36,
|
|
600
|
+
18
|
|
601
|
+
]
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
"name": "taxonomy_index",
|
|
606
|
+
"type": {
|
|
607
|
+
"name": "int",
|
|
608
|
+
"is_array": false,
|
|
609
|
+
"metadata": [
|
|
610
|
+
0,
|
|
611
|
+
0
|
|
612
|
+
]
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
]
|
|
616
|
+
},
|
|
617
|
+
"annotations": null
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
"name": "get_record_filled",
|
|
621
|
+
"parameters": [
|
|
622
|
+
{
|
|
623
|
+
"name": "$date_from",
|
|
624
|
+
"type": {
|
|
625
|
+
"name": "int",
|
|
626
|
+
"is_array": false,
|
|
627
|
+
"metadata": [
|
|
628
|
+
0,
|
|
629
|
+
0
|
|
630
|
+
]
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
"name": "$date_to",
|
|
635
|
+
"type": {
|
|
636
|
+
"name": "int",
|
|
637
|
+
"is_array": false,
|
|
638
|
+
"metadata": [
|
|
639
|
+
0,
|
|
640
|
+
0
|
|
641
|
+
]
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
"name": "$frozen_at",
|
|
646
|
+
"type": {
|
|
647
|
+
"name": "int",
|
|
648
|
+
"is_array": false,
|
|
649
|
+
"metadata": [
|
|
650
|
+
0,
|
|
651
|
+
0
|
|
652
|
+
]
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
],
|
|
656
|
+
"public": false,
|
|
657
|
+
"modifiers": [
|
|
658
|
+
"VIEW"
|
|
659
|
+
],
|
|
660
|
+
"body": "$base_taxonomy_list int[];\n\n // Initialize taxonomy variables\n $taxonomy_count int := 0;\n $last_values decimal(36,18)[];\n $child_data_providers text[];\n $child_stream_id text[];\n\n // Fetch taxonomy details\n for $row in SELECT * FROM describe_taxonomies(true) {\n $taxonomy_count := $taxonomy_count + 1;\n $base_taxonomy_list := array_append($base_taxonomy_list, $taxonomy_count);\n $last_values := array_append($last_values, null::decimal(36,18));\n $child_data_providers := array_append($child_data_providers, $row.child_data_provider);\n $child_stream_id := array_append($child_stream_id, $row.child_stream_id);\n }\n\n $unemitted_taxonomies_for_date int[] := $base_taxonomy_list;\n $removed_elements_count int := 0;\n $prev_date int := 0;\n $current_date int := 0;\n\n // what could make this process easier:\n // - use a map to store the last values, so we can easily check if a value is null\n // - better manipulation of tables as objects, then we could modify a table to\n // fill forward without needing to return immediately on each loop\n\n // Fetch raw records and emit values with dynamic weights\n for $row_raw in SELECT * FROM get_raw_record($date_from, $date_to, $frozen_at, $child_data_providers, $child_stream_id) ORDER BY date_value, taxonomy_index {\n $current_date := $row_raw.date_value;\n\n // Fetch the dynamic weight based on the current date\n $dynamic_weight decimal(36,18) := get_dynamic_weight($child_stream_id[$row_raw.taxonomy_index], $current_date);\n\n // Emit filled values for previous date if date has changed\n if $current_date != $prev_date {\n if $prev_date != 0 {\n for $unemitted_taxonomy in $unemitted_taxonomies_for_date {\n // TODO: remove this when we have slices or include if we have just index assignment\n // if $unemitted_taxonomy is distinct from null {\n\n if $last_values[$unemitted_taxonomy] is distinct from null {\n // Use the stored dynamic weight from the previous date\n $dynamic_weight_prev := get_dynamic_weight($child_stream_id[$unemitted_taxonomy], $prev_date);\n return next $prev_date, $last_values[$unemitted_taxonomy] * $dynamic_weight_prev, $dynamic_weight_prev;\n }\n }\n // Clear unemitted taxonomies for the new date\n $unemitted_taxonomies_for_date := $base_taxonomy_list;\n $removed_elements_count := 0;\n }\n }\n\n // TODO: uncomment when we have index assignment\n // $last_values[$row_raw.taxonomy_index] := $row_raw.value;\n\n // Update the last values for the current date\n $last_values := array_update_element($last_values, $row_raw.taxonomy_index, $row_raw.value);\n\n // Emit current value with the dynamic weight\n return next $current_date, $row_raw.value * $dynamic_weight, $dynamic_weight;\n\n // Remove emitted taxonomy from the unemitted list\n // we need to subtract the removed_elements_count because the array is shrinking\n // TODO: we can improve it when we either can remove elements, or with array element assignment\n $unemitted_taxonomies_for_date := remove_array_element($unemitted_taxonomies_for_date, $row_raw.taxonomy_index - $removed_elements_count);\n $removed_elements_count := $removed_elements_count + 1;\n // remove elements is not performant without slices. Then let's make the elements null for now\n // $unemitted_taxonomies_for_date[$row_raw.taxonomy_index] := null;\n\n $prev_date := $current_date;\n }\n\n // Emit filled values for the last date\n if $prev_date != 0 {\n if $taxonomy_count \u003e 0 {\n for $unemitted_taxonomy2 in $unemitted_taxonomies_for_date {\n if $last_values[$unemitted_taxonomy2] is distinct from null {\n // Fetch the correct dynamic weight for the last date\n $dynamic_weight_last := get_dynamic_weight($child_stream_id[$unemitted_taxonomy2], $prev_date);\n return next $prev_date, $last_values[$unemitted_taxonomy2] * $dynamic_weight_last, $dynamic_weight_last;\n }\n }\n }\n }",
|
|
661
|
+
"return_types": {
|
|
662
|
+
"is_table": true,
|
|
663
|
+
"fields": [
|
|
664
|
+
{
|
|
665
|
+
"name": "date_value",
|
|
666
|
+
"type": {
|
|
667
|
+
"name": "int",
|
|
668
|
+
"is_array": false,
|
|
669
|
+
"metadata": [
|
|
670
|
+
0,
|
|
671
|
+
0
|
|
672
|
+
]
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
"name": "value_with_weight",
|
|
677
|
+
"type": {
|
|
678
|
+
"name": "decimal",
|
|
679
|
+
"is_array": false,
|
|
680
|
+
"metadata": [
|
|
681
|
+
36,
|
|
682
|
+
18
|
|
683
|
+
]
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
"name": "weight",
|
|
688
|
+
"type": {
|
|
689
|
+
"name": "decimal",
|
|
690
|
+
"is_array": false,
|
|
691
|
+
"metadata": [
|
|
692
|
+
36,
|
|
693
|
+
18
|
|
694
|
+
]
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
]
|
|
698
|
+
},
|
|
699
|
+
"annotations": null
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
"name": "get_index_filled",
|
|
703
|
+
"parameters": [
|
|
704
|
+
{
|
|
705
|
+
"name": "$date_from",
|
|
706
|
+
"type": {
|
|
707
|
+
"name": "int",
|
|
708
|
+
"is_array": false,
|
|
709
|
+
"metadata": [
|
|
710
|
+
0,
|
|
711
|
+
0
|
|
712
|
+
]
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
"name": "$date_to",
|
|
717
|
+
"type": {
|
|
718
|
+
"name": "int",
|
|
719
|
+
"is_array": false,
|
|
720
|
+
"metadata": [
|
|
721
|
+
0,
|
|
722
|
+
0
|
|
723
|
+
]
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
"name": "$frozen_at",
|
|
728
|
+
"type": {
|
|
729
|
+
"name": "int",
|
|
730
|
+
"is_array": false,
|
|
731
|
+
"metadata": [
|
|
732
|
+
0,
|
|
733
|
+
0
|
|
734
|
+
]
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
"name": "$base_date",
|
|
739
|
+
"type": {
|
|
740
|
+
"name": "int",
|
|
741
|
+
"is_array": false,
|
|
742
|
+
"metadata": [
|
|
743
|
+
0,
|
|
744
|
+
0
|
|
745
|
+
]
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
],
|
|
749
|
+
"public": false,
|
|
750
|
+
"modifiers": [
|
|
751
|
+
"VIEW"
|
|
752
|
+
],
|
|
753
|
+
"body": "$base_taxonomy_list int[];\n\n // Initialize taxonomy variables\n $taxonomy_count int := 0;\n $last_values decimal(36,18)[];\n $child_data_providers text[];\n $child_stream_id text[];\n\n // Fetch taxonomy details\n for $row in SELECT * FROM describe_taxonomies(true) {\n $taxonomy_count := $taxonomy_count + 1;\n $base_taxonomy_list := array_append($base_taxonomy_list, $taxonomy_count);\n $last_values := array_append($last_values, null::decimal(36,18));\n $child_data_providers := array_append($child_data_providers, $row.child_data_provider);\n $child_stream_id := array_append($child_stream_id, $row.child_stream_id);\n }\n\n $unemitted_taxonomies_for_date int[] := $base_taxonomy_list;\n $removed_elements_count int := 0;\n $prev_date int := 0;\n $current_date int := 0;\n\n // what could make this process easier:\n // - use a map to store the last values, so we can easily check if a value is null\n // - better manipulation of tables as objects, then we could modify a table to\n // fill forward without needing to return immediately on each loop\n\n for $row_raw in SELECT * FROM get_raw_index($date_from, $date_to, $frozen_at, $child_data_providers, $child_stream_id, $base_date) ORDER BY date_value, taxonomy_index {\n $current_date := $row_raw.date_value;\n\n // Fetch the dynamic weight based on the current date\n $dynamic_weight decimal(36,18) := get_dynamic_weight($child_stream_id[$row_raw.taxonomy_index], $current_date);\n\n // Emit filled values for the previous date if the date has changed\n if $current_date != $prev_date {\n if $prev_date != 0 {\n for $unemitted_taxonomy in $unemitted_taxonomies_for_date {\n if $last_values[$unemitted_taxonomy] is distinct from null {\n // TODO: remove this when we have slices or include if we have just index assignment\n // if $unemitted_taxonomy is distinct from null {\n\n // Use the stored dynamic weight from the previous date\n $dynamic_weight_prev := get_dynamic_weight($child_stream_id[$unemitted_taxonomy], $prev_date);\n return next $prev_date, $last_values[$unemitted_taxonomy] * $dynamic_weight_prev, $dynamic_weight_prev;\n }\n }\n }\n // Clear unemitted taxonomies for the new date\n $unemitted_taxonomies_for_date := $base_taxonomy_list;\n $removed_elements_count := 0;\n }\n\n // TODO: uncomment when we have index assignment\n // $last_values[$row_raw.taxonomy_index] := $row_raw.value;\n\n // Update the last values for the current date\n $last_values := array_update_element($last_values, $row_raw.taxonomy_index, $row_raw.value);\n\n // Emit the current value with the dynamic weight\n return next $current_date, $row_raw.value * $dynamic_weight, $dynamic_weight;\n\n // Remove emitted taxonomy from the unemitted list\n // TODO: we can improve it when we either can remove elements, or with array element assignment\n $unemitted_taxonomies_for_date := remove_array_element($unemitted_taxonomies_for_date, $row_raw.taxonomy_index - $removed_elements_count);\n $removed_elements_count := $removed_elements_count + 1;\n\n // remove elements is not performant without slices. Then let's make the elements null for now\n // $unemitted_taxonomies_for_date[$row_raw.taxonomy_index] := null;\n\n $prev_date := $current_date;\n }\n\n // Emit filled values for the last date\n if $prev_date != 0 {\n if $taxonomy_count \u003e 0 {\n for $unemitted_taxonomy2 in $unemitted_taxonomies_for_date {\n if $last_values[$unemitted_taxonomy2] is distinct from null {\n // Fetch the correct dynamic weight for the last date\n $dynamic_weight_last := get_dynamic_weight($child_stream_id[$unemitted_taxonomy2], $prev_date);\n return next $prev_date, $last_values[$unemitted_taxonomy2] * $dynamic_weight_last, $dynamic_weight_last;\n }\n }\n }\n }",
|
|
754
|
+
"return_types": {
|
|
755
|
+
"is_table": true,
|
|
756
|
+
"fields": [
|
|
757
|
+
{
|
|
758
|
+
"name": "date_value",
|
|
759
|
+
"type": {
|
|
760
|
+
"name": "int",
|
|
761
|
+
"is_array": false,
|
|
762
|
+
"metadata": [
|
|
763
|
+
0,
|
|
764
|
+
0
|
|
765
|
+
]
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
"name": "value_with_weight",
|
|
770
|
+
"type": {
|
|
771
|
+
"name": "decimal",
|
|
772
|
+
"is_array": false,
|
|
773
|
+
"metadata": [
|
|
774
|
+
36,
|
|
775
|
+
18
|
|
776
|
+
]
|
|
777
|
+
}
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
"name": "weight",
|
|
781
|
+
"type": {
|
|
782
|
+
"name": "decimal",
|
|
783
|
+
"is_array": false,
|
|
784
|
+
"metadata": [
|
|
785
|
+
36,
|
|
786
|
+
18
|
|
787
|
+
]
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
]
|
|
791
|
+
},
|
|
792
|
+
"annotations": null
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
"name": "get_record",
|
|
796
|
+
"parameters": [
|
|
797
|
+
{
|
|
798
|
+
"name": "$date_from",
|
|
799
|
+
"type": {
|
|
800
|
+
"name": "int",
|
|
801
|
+
"is_array": false,
|
|
802
|
+
"metadata": [
|
|
803
|
+
0,
|
|
804
|
+
0
|
|
805
|
+
]
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
"name": "$date_to",
|
|
810
|
+
"type": {
|
|
811
|
+
"name": "int",
|
|
812
|
+
"is_array": false,
|
|
813
|
+
"metadata": [
|
|
814
|
+
0,
|
|
815
|
+
0
|
|
816
|
+
]
|
|
817
|
+
}
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
"name": "$frozen_at",
|
|
821
|
+
"type": {
|
|
822
|
+
"name": "int",
|
|
823
|
+
"is_array": false,
|
|
824
|
+
"metadata": [
|
|
825
|
+
0,
|
|
826
|
+
0
|
|
827
|
+
]
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
],
|
|
831
|
+
"public": true,
|
|
832
|
+
"modifiers": [
|
|
833
|
+
"VIEW"
|
|
834
|
+
],
|
|
835
|
+
"body": "$in_range bool := false;\n $last_date int;\n $last_value decimal(36,18);\n // here, we sum all of the records that were found by aggregating on the date_valie\n for $row in SELECT date_value, total_value_with_weight / total_weight as value FROM\n (SELECT\n date_value,\n SUM(value_with_weight)::decimal(36,18) AS total_value_with_weight,\n SUM(weight)::decimal(36,18) AS total_weight\n FROM get_record_filled($date_from, $date_to, $frozen_at) group by date_value) as r {\n // when we arrive in the range, we start emitting. If there was a previous value, we emit it\n if $in_range == false {\n if $row.date_value \u003e= $date_from {\n $in_range := true;\n if ($last_date is distinct from null) AND $row.date_value != $date_from {\n return next $last_date, $last_value;\n }\n }\n\n $last_date := $row.date_value;\n $last_value := $row.value;\n }\n // we check again, because it might just have entered the range\n if $in_range == true {\n return next $row.date_value, $row.value;\n }\n }\n\n // if we finished the loop and we never entered the range, we emit the last value\n if $in_range == false AND $last_date is distinct from null {\n return next $last_date, $last_value;\n }",
|
|
836
|
+
"return_types": {
|
|
837
|
+
"is_table": true,
|
|
838
|
+
"fields": [
|
|
839
|
+
{
|
|
840
|
+
"name": "date_value",
|
|
841
|
+
"type": {
|
|
842
|
+
"name": "int",
|
|
843
|
+
"is_array": false,
|
|
844
|
+
"metadata": [
|
|
845
|
+
0,
|
|
846
|
+
0
|
|
847
|
+
]
|
|
848
|
+
}
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
"name": "value",
|
|
852
|
+
"type": {
|
|
853
|
+
"name": "decimal",
|
|
854
|
+
"is_array": false,
|
|
855
|
+
"metadata": [
|
|
856
|
+
36,
|
|
857
|
+
18
|
|
858
|
+
]
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
]
|
|
862
|
+
},
|
|
863
|
+
"annotations": null
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
"name": "get_index",
|
|
867
|
+
"parameters": [
|
|
868
|
+
{
|
|
869
|
+
"name": "$date_from",
|
|
870
|
+
"type": {
|
|
871
|
+
"name": "int",
|
|
872
|
+
"is_array": false,
|
|
873
|
+
"metadata": [
|
|
874
|
+
0,
|
|
875
|
+
0
|
|
876
|
+
]
|
|
877
|
+
}
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
"name": "$date_to",
|
|
881
|
+
"type": {
|
|
882
|
+
"name": "int",
|
|
883
|
+
"is_array": false,
|
|
884
|
+
"metadata": [
|
|
885
|
+
0,
|
|
886
|
+
0
|
|
887
|
+
]
|
|
888
|
+
}
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
"name": "$frozen_at",
|
|
892
|
+
"type": {
|
|
893
|
+
"name": "int",
|
|
894
|
+
"is_array": false,
|
|
895
|
+
"metadata": [
|
|
896
|
+
0,
|
|
897
|
+
0
|
|
898
|
+
]
|
|
899
|
+
}
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
"name": "$base_date",
|
|
903
|
+
"type": {
|
|
904
|
+
"name": "int",
|
|
905
|
+
"is_array": false,
|
|
906
|
+
"metadata": [
|
|
907
|
+
0,
|
|
908
|
+
0
|
|
909
|
+
]
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
],
|
|
913
|
+
"public": true,
|
|
914
|
+
"modifiers": [
|
|
915
|
+
"VIEW"
|
|
916
|
+
],
|
|
917
|
+
"body": "$in_range bool := false;\n $last_date int;\n $last_value decimal(36,18);\n $effective_base_date int := $base_date;\n\n if $effective_base_date is null OR $effective_base_date == 0 {\n for $v_row in SELECT * FROM get_metadata('default_base_date', true, null) ORDER BY created_at DESC LIMIT 1 {\n $effective_base_date := $v_row.value_i;\n }\n }\n\n // here, we sum all of the indexes that were found by aggregating on the date_value\n for $row in SELECT date_value, total_value_with_weight / total_weight as value FROM\n (SELECT\n date_value,\n SUM(value_with_weight)::decimal(36,18) AS total_value_with_weight,\n SUM(weight)::decimal(36,18) AS total_weight\n FROM get_index_filled($date_from, $date_to, $frozen_at, $effective_base_date) group by date_value) as r {\n // when we arrive in the range, we start emitting. If there was a previous value, we emit it\n if $in_range == false {\n if $row.date_value \u003e= $date_from {\n $in_range := true;\n if ($last_date is distinct from null) AND $row.date_value != $date_from {\n return next $last_date, $last_value;\n }\n }\n\n $last_date := $row.date_value;\n $last_value := $row.value;\n }\n // we check again, because it might just have entered the range\n if $in_range == true {\n return next $row.date_value, $row.value;\n }\n }\n\n // if we finished the loop and we never entered the range, we emit the last value\n if $in_range == false AND $last_date is distinct from null {\n return next $last_date, $last_value;\n }",
|
|
918
|
+
"return_types": {
|
|
919
|
+
"is_table": true,
|
|
920
|
+
"fields": [
|
|
921
|
+
{
|
|
922
|
+
"name": "date_value",
|
|
923
|
+
"type": {
|
|
924
|
+
"name": "int",
|
|
925
|
+
"is_array": false,
|
|
926
|
+
"metadata": [
|
|
927
|
+
0,
|
|
928
|
+
0
|
|
929
|
+
]
|
|
930
|
+
}
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
"name": "value",
|
|
934
|
+
"type": {
|
|
935
|
+
"name": "decimal",
|
|
936
|
+
"is_array": false,
|
|
937
|
+
"metadata": [
|
|
938
|
+
36,
|
|
939
|
+
18
|
|
940
|
+
]
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
]
|
|
944
|
+
},
|
|
945
|
+
"annotations": null
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
"name": "get_first_record",
|
|
949
|
+
"parameters": [
|
|
950
|
+
{
|
|
951
|
+
"name": "$after_date",
|
|
952
|
+
"type": {
|
|
953
|
+
"name": "int",
|
|
954
|
+
"is_array": false,
|
|
955
|
+
"metadata": [
|
|
956
|
+
0,
|
|
957
|
+
0
|
|
958
|
+
]
|
|
959
|
+
}
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
"name": "$frozen_at",
|
|
963
|
+
"type": {
|
|
964
|
+
"name": "int",
|
|
965
|
+
"is_array": false,
|
|
966
|
+
"metadata": [
|
|
967
|
+
0,
|
|
968
|
+
0
|
|
969
|
+
]
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
],
|
|
973
|
+
"public": true,
|
|
974
|
+
"modifiers": [
|
|
975
|
+
"VIEW"
|
|
976
|
+
],
|
|
977
|
+
"body": "if is_wallet_allowed_to_read(@caller) == false {\n error('wallet not allowed to read');\n }\n\n // check compose access\n is_stream_allowed_to_compose(@foreign_caller);\n\n // let's coalesce null with ''\n // then, if it's empty, it will always be the first value\n if $after_date is null {\n $after_date := 0;\n }\n\n // 1. figure the earliest date possible after the after_date\n $earliest_date int := 0;\n for $taxonomy_row in SELECT * FROM describe_taxonomies(true) {\n $dbid := get_dbid($taxonomy_row.child_data_provider, $taxonomy_row.child_stream_id);\n for $record_row in SELECT * FROM ext_get_first_record[$dbid, 'get_first_record']($after_date, $frozen_at) {\n if $earliest_date == 0 OR $record_row.date_value \u003c $earliest_date {\n $earliest_date := $record_row.date_value;\n }\n }\n }\n\n // 2. get_record with the earliest date if it exists\n if $earliest_date != 0 {\n for $row in SELECT date_value, value FROM get_record($earliest_date, $earliest_date, $frozen_at) {\n return next $row.date_value, $row.value;\n }\n }",
|
|
978
|
+
"return_types": {
|
|
979
|
+
"is_table": true,
|
|
980
|
+
"fields": [
|
|
981
|
+
{
|
|
982
|
+
"name": "date_value",
|
|
983
|
+
"type": {
|
|
984
|
+
"name": "int",
|
|
985
|
+
"is_array": false,
|
|
986
|
+
"metadata": [
|
|
987
|
+
0,
|
|
988
|
+
0
|
|
989
|
+
]
|
|
990
|
+
}
|
|
991
|
+
},
|
|
992
|
+
{
|
|
993
|
+
"name": "value",
|
|
994
|
+
"type": {
|
|
995
|
+
"name": "decimal",
|
|
996
|
+
"is_array": false,
|
|
997
|
+
"metadata": [
|
|
998
|
+
36,
|
|
999
|
+
18
|
|
1000
|
+
]
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
]
|
|
1004
|
+
},
|
|
1005
|
+
"annotations": null
|
|
1006
|
+
},
|
|
1007
|
+
{
|
|
1008
|
+
"name": "is_initiated",
|
|
1009
|
+
"parameters": null,
|
|
1010
|
+
"public": false,
|
|
1011
|
+
"modifiers": [
|
|
1012
|
+
"VIEW"
|
|
1013
|
+
],
|
|
1014
|
+
"body": "for $row in SELECT * FROM metadata WHERE metadata_key = 'type' LIMIT 1 {\n return true;\n }\n\n return false;",
|
|
1015
|
+
"return_types": {
|
|
1016
|
+
"is_table": false,
|
|
1017
|
+
"fields": [
|
|
1018
|
+
{
|
|
1019
|
+
"name": "result",
|
|
1020
|
+
"type": {
|
|
1021
|
+
"name": "bool",
|
|
1022
|
+
"is_array": false,
|
|
1023
|
+
"metadata": [
|
|
1024
|
+
0,
|
|
1025
|
+
0
|
|
1026
|
+
]
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
]
|
|
1030
|
+
},
|
|
1031
|
+
"annotations": null
|
|
1032
|
+
},
|
|
1033
|
+
{
|
|
1034
|
+
"name": "is_stream_owner",
|
|
1035
|
+
"parameters": [
|
|
1036
|
+
{
|
|
1037
|
+
"name": "$wallet",
|
|
1038
|
+
"type": {
|
|
1039
|
+
"name": "text",
|
|
1040
|
+
"is_array": false,
|
|
1041
|
+
"metadata": [
|
|
1042
|
+
0,
|
|
1043
|
+
0
|
|
1044
|
+
]
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
],
|
|
1048
|
+
"public": true,
|
|
1049
|
+
"modifiers": [
|
|
1050
|
+
"VIEW"
|
|
1051
|
+
],
|
|
1052
|
+
"body": "for $row in SELECT * FROM metadata WHERE metadata_key = 'stream_owner' AND value_ref = LOWER($wallet) LIMIT 1 {\n return true;\n }\n return false;",
|
|
1053
|
+
"return_types": {
|
|
1054
|
+
"is_table": false,
|
|
1055
|
+
"fields": [
|
|
1056
|
+
{
|
|
1057
|
+
"name": "result",
|
|
1058
|
+
"type": {
|
|
1059
|
+
"name": "bool",
|
|
1060
|
+
"is_array": false,
|
|
1061
|
+
"metadata": [
|
|
1062
|
+
0,
|
|
1063
|
+
0
|
|
1064
|
+
]
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
]
|
|
1068
|
+
},
|
|
1069
|
+
"annotations": null
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
"name": "is_wallet_allowed_to_read",
|
|
1073
|
+
"parameters": [
|
|
1074
|
+
{
|
|
1075
|
+
"name": "$wallet",
|
|
1076
|
+
"type": {
|
|
1077
|
+
"name": "text",
|
|
1078
|
+
"is_array": false,
|
|
1079
|
+
"metadata": [
|
|
1080
|
+
0,
|
|
1081
|
+
0
|
|
1082
|
+
]
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
],
|
|
1086
|
+
"public": true,
|
|
1087
|
+
"modifiers": [
|
|
1088
|
+
"VIEW"
|
|
1089
|
+
],
|
|
1090
|
+
"body": "$visibility int := 0;\n for $v_row in SELECT * FROM get_metadata('read_visibility', true, null) {\n $visibility := $v_row.value_i;\n }\n\n if $visibility == 0 {\n return true;\n }\n\n // if it's the owner, it's permitted\n if is_stream_owner($wallet) {\n return true;\n }\n\n // if there's metadata allow_read_wallet -\u003e \u003cwallet\u003e, then its permitted\n for $row in SELECT * FROM get_metadata('allow_read_wallet', false, $wallet) {\n return true;\n }\n\n return false;",
|
|
1091
|
+
"return_types": {
|
|
1092
|
+
"is_table": false,
|
|
1093
|
+
"fields": [
|
|
1094
|
+
{
|
|
1095
|
+
"name": "value",
|
|
1096
|
+
"type": {
|
|
1097
|
+
"name": "bool",
|
|
1098
|
+
"is_array": false,
|
|
1099
|
+
"metadata": [
|
|
1100
|
+
0,
|
|
1101
|
+
0
|
|
1102
|
+
]
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
]
|
|
1106
|
+
},
|
|
1107
|
+
"annotations": null
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
"name": "stream_owner_only",
|
|
1111
|
+
"parameters": null,
|
|
1112
|
+
"public": false,
|
|
1113
|
+
"modifiers": [
|
|
1114
|
+
"VIEW"
|
|
1115
|
+
],
|
|
1116
|
+
"body": "if is_stream_owner(@caller) == false {\n error('Stream owner only procedure');\n }",
|
|
1117
|
+
"return_types": null,
|
|
1118
|
+
"annotations": null
|
|
1119
|
+
},
|
|
1120
|
+
{
|
|
1121
|
+
"name": "init",
|
|
1122
|
+
"parameters": null,
|
|
1123
|
+
"public": true,
|
|
1124
|
+
"modifiers": [
|
|
1125
|
+
"OWNER"
|
|
1126
|
+
],
|
|
1127
|
+
"body": "if is_initiated() {\n error('this contract was already initialized');\n }\n\n // check if caller is empty\n // this happens can happen in tests, but we should also protect for that on production\n if @caller == '' {\n error('caller is empty');\n }\n\n $current_block int := @height;\n\n // uuid's namespaces are any random generated uuid from https://www.uuidtools.com/v5\n // but each usage should be different to maintain determinism, so we reuse the previous result\n $current_uuid uuid := uuid_generate_v5('41fea9f0-179f-11ef-8838-325096b39f47'::uuid, @txid);\n\n // type = composed\n $current_uuid := uuid_generate_v5($current_uuid, @txid);\n INSERT INTO metadata (row_id, metadata_key, value_s, created_at)\n VALUES ($current_uuid, 'type', 'composed', $current_block);\n\n // stream_owner = @caller\n $current_uuid := uuid_generate_v5($current_uuid, @txid);\n INSERT INTO metadata (row_id, metadata_key, value_ref, created_at)\n VALUES ($current_uuid, 'stream_owner', LOWER(@caller), 1);\n\n // compose_visibility = 0 (public)\n $current_uuid := uuid_generate_v5($current_uuid, @txid);\n INSERT INTO metadata (row_id, metadata_key, value_i, created_at)\n VALUES ($current_uuid, 'compose_visibility', 0, $current_block);\n\n // read_visibility = 0 (public)\n $current_uuid := uuid_generate_v5($current_uuid, @txid);\n INSERT INTO metadata (row_id, metadata_key, value_i, created_at)\n VALUES ($current_uuid, 'read_visibility', 0, $current_block);\n\n $readonly_keys text[] := [\n 'type',\n 'stream_owner',\n 'readonly_key',\n 'taxonomy_version'\n ];\n\n for $key in $readonly_keys {\n $current_uuid := uuid_generate_v5($current_uuid, @txid);\n INSERT INTO metadata (row_id, metadata_key, value_s, created_at)\n VALUES ($current_uuid, 'readonly_key', $key, $current_block);\n }",
|
|
1128
|
+
"return_types": null,
|
|
1129
|
+
"annotations": null
|
|
1130
|
+
},
|
|
1131
|
+
{
|
|
1132
|
+
"name": "insert_metadata",
|
|
1133
|
+
"parameters": [
|
|
1134
|
+
{
|
|
1135
|
+
"name": "$key",
|
|
1136
|
+
"type": {
|
|
1137
|
+
"name": "text",
|
|
1138
|
+
"is_array": false,
|
|
1139
|
+
"metadata": [
|
|
1140
|
+
0,
|
|
1141
|
+
0
|
|
1142
|
+
]
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
{
|
|
1146
|
+
"name": "$value",
|
|
1147
|
+
"type": {
|
|
1148
|
+
"name": "text",
|
|
1149
|
+
"is_array": false,
|
|
1150
|
+
"metadata": [
|
|
1151
|
+
0,
|
|
1152
|
+
0
|
|
1153
|
+
]
|
|
1154
|
+
}
|
|
1155
|
+
},
|
|
1156
|
+
{
|
|
1157
|
+
"name": "$val_type",
|
|
1158
|
+
"type": {
|
|
1159
|
+
"name": "text",
|
|
1160
|
+
"is_array": false,
|
|
1161
|
+
"metadata": [
|
|
1162
|
+
0,
|
|
1163
|
+
0
|
|
1164
|
+
]
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
],
|
|
1168
|
+
"public": true,
|
|
1169
|
+
"modifiers": null,
|
|
1170
|
+
"body": "$value_i int;\n $value_s text;\n $value_f decimal(36,18);\n $value_b bool;\n $value_ref text;\n\n if $val_type == 'int' {\n $value_i := $value::int;\n } elseif $val_type == 'string' {\n $value_s := $value;\n } elseif $val_type == 'bool' {\n $value_b := $value::bool;\n } elseif $val_type == 'ref' {\n $value_ref := $value;\n } elseif $val_type == 'float' {\n $value_f := $value::decimal(36,18);\n } else {\n error(format('unknown type used \"%s\". valid types = \"float\" | \"bool\" | \"int\" | \"ref\" | \"string\"', $val_type));\n }\n\n stream_owner_only();\n\n if is_initiated() == false {\n error('contract must be initiated');\n }\n\n // check if it's read-only\n for $row in SELECT * FROM metadata WHERE metadata_key = 'readonly_key' AND value_s = $key LIMIT 1 {\n error('Cannot insert metadata for read-only key');\n }\n\n // we create one deterministic uuid for each metadata record\n // we can't use just @txid because a single transaction can insert multiple metadata records.\n // the result will be idempotency here too.\n $uuid_key := @txid || $key || $value;\n\n $uuid uuid := uuid_generate_v5('1361df5d-0230-47b3-b2c1-37950cf51fe9'::uuid, $uuid_key);\n $current_block int := @height;\n\n // insert data\n INSERT INTO metadata (row_id, metadata_key, value_i, value_f, value_s, value_b, value_ref, created_at)\n VALUES ($uuid, $key, $value_i, $value_f, $value_s, $value_b, LOWER($value_ref), $current_block);",
|
|
1171
|
+
"return_types": null,
|
|
1172
|
+
"annotations": null
|
|
1173
|
+
},
|
|
1174
|
+
{
|
|
1175
|
+
"name": "get_metadata",
|
|
1176
|
+
"parameters": [
|
|
1177
|
+
{
|
|
1178
|
+
"name": "$key",
|
|
1179
|
+
"type": {
|
|
1180
|
+
"name": "text",
|
|
1181
|
+
"is_array": false,
|
|
1182
|
+
"metadata": [
|
|
1183
|
+
0,
|
|
1184
|
+
0
|
|
1185
|
+
]
|
|
1186
|
+
}
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
"name": "$only_latest",
|
|
1190
|
+
"type": {
|
|
1191
|
+
"name": "bool",
|
|
1192
|
+
"is_array": false,
|
|
1193
|
+
"metadata": [
|
|
1194
|
+
0,
|
|
1195
|
+
0
|
|
1196
|
+
]
|
|
1197
|
+
}
|
|
1198
|
+
},
|
|
1199
|
+
{
|
|
1200
|
+
"name": "$ref",
|
|
1201
|
+
"type": {
|
|
1202
|
+
"name": "text",
|
|
1203
|
+
"is_array": false,
|
|
1204
|
+
"metadata": [
|
|
1205
|
+
0,
|
|
1206
|
+
0
|
|
1207
|
+
]
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
],
|
|
1211
|
+
"public": true,
|
|
1212
|
+
"modifiers": [
|
|
1213
|
+
"VIEW"
|
|
1214
|
+
],
|
|
1215
|
+
"body": "if $only_latest == true {\n if $ref is distinct from null {\n return SELECT\n row_id,\n null::int as value_i,\n null::decimal(36,18) as value_f,\n null::bool as value_b,\n null::text as value_s,\n value_ref,\n created_at\n FROM metadata\n WHERE metadata_key = $key AND disabled_at IS NULL AND value_ref = LOWER($ref)\n ORDER BY created_at DESC\n LIMIT 1;\n } else {\n return SELECT\n row_id,\n value_i,\n value_f,\n value_b,\n value_s,\n value_ref,\n created_at\n FROM metadata\n WHERE metadata_key = $key AND disabled_at IS NULL\n ORDER BY created_at DESC\n LIMIT 1;\n }\n } else {\n // SHOULD BE THE EXACT CODE AS ABOVE, BUT WITHOUT LIMIT\n if $ref is distinct from null {\n return SELECT\n row_id,\n null::int as value_i,\n null::decimal(36,18) as value_f,\n null::bool as value_b,\n null::text as value_s,\n value_ref,\n created_at\n FROM metadata\n WHERE metadata_key = $key AND disabled_at IS NULL AND value_ref = LOWER($ref)\n ORDER BY created_at DESC;\n } else {\n return SELECT\n row_id,\n value_i,\n value_f,\n value_b,\n value_s,\n value_ref,\n created_at\n FROM metadata\n WHERE metadata_key = $key AND disabled_at IS NULL\n ORDER BY created_at DESC;\n }\n }",
|
|
1216
|
+
"return_types": {
|
|
1217
|
+
"is_table": true,
|
|
1218
|
+
"fields": [
|
|
1219
|
+
{
|
|
1220
|
+
"name": "row_id",
|
|
1221
|
+
"type": {
|
|
1222
|
+
"name": "uuid",
|
|
1223
|
+
"is_array": false,
|
|
1224
|
+
"metadata": [
|
|
1225
|
+
0,
|
|
1226
|
+
0
|
|
1227
|
+
]
|
|
1228
|
+
}
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
"name": "value_i",
|
|
1232
|
+
"type": {
|
|
1233
|
+
"name": "int",
|
|
1234
|
+
"is_array": false,
|
|
1235
|
+
"metadata": [
|
|
1236
|
+
0,
|
|
1237
|
+
0
|
|
1238
|
+
]
|
|
1239
|
+
}
|
|
1240
|
+
},
|
|
1241
|
+
{
|
|
1242
|
+
"name": "value_f",
|
|
1243
|
+
"type": {
|
|
1244
|
+
"name": "decimal",
|
|
1245
|
+
"is_array": false,
|
|
1246
|
+
"metadata": [
|
|
1247
|
+
36,
|
|
1248
|
+
18
|
|
1249
|
+
]
|
|
1250
|
+
}
|
|
1251
|
+
},
|
|
1252
|
+
{
|
|
1253
|
+
"name": "value_b",
|
|
1254
|
+
"type": {
|
|
1255
|
+
"name": "bool",
|
|
1256
|
+
"is_array": false,
|
|
1257
|
+
"metadata": [
|
|
1258
|
+
0,
|
|
1259
|
+
0
|
|
1260
|
+
]
|
|
1261
|
+
}
|
|
1262
|
+
},
|
|
1263
|
+
{
|
|
1264
|
+
"name": "value_s",
|
|
1265
|
+
"type": {
|
|
1266
|
+
"name": "text",
|
|
1267
|
+
"is_array": false,
|
|
1268
|
+
"metadata": [
|
|
1269
|
+
0,
|
|
1270
|
+
0
|
|
1271
|
+
]
|
|
1272
|
+
}
|
|
1273
|
+
},
|
|
1274
|
+
{
|
|
1275
|
+
"name": "value_ref",
|
|
1276
|
+
"type": {
|
|
1277
|
+
"name": "text",
|
|
1278
|
+
"is_array": false,
|
|
1279
|
+
"metadata": [
|
|
1280
|
+
0,
|
|
1281
|
+
0
|
|
1282
|
+
]
|
|
1283
|
+
}
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
"name": "created_at",
|
|
1287
|
+
"type": {
|
|
1288
|
+
"name": "int",
|
|
1289
|
+
"is_array": false,
|
|
1290
|
+
"metadata": [
|
|
1291
|
+
0,
|
|
1292
|
+
0
|
|
1293
|
+
]
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
]
|
|
1297
|
+
},
|
|
1298
|
+
"annotations": null
|
|
1299
|
+
},
|
|
1300
|
+
{
|
|
1301
|
+
"name": "disable_metadata",
|
|
1302
|
+
"parameters": [
|
|
1303
|
+
{
|
|
1304
|
+
"name": "$row_id",
|
|
1305
|
+
"type": {
|
|
1306
|
+
"name": "uuid",
|
|
1307
|
+
"is_array": false,
|
|
1308
|
+
"metadata": [
|
|
1309
|
+
0,
|
|
1310
|
+
0
|
|
1311
|
+
]
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
],
|
|
1315
|
+
"public": true,
|
|
1316
|
+
"modifiers": null,
|
|
1317
|
+
"body": "stream_owner_only();\n\n $current_block int := @height;\n\n $found bool := false;\n\n // Check if the metadata is not read-only\n for $metadata_row in\n SELECT metadata_key\n FROM metadata\n WHERE row_id = $row_id AND disabled_at IS NULL\n LIMIT 1 {\n $found := true;\n $row_key text := $metadata_row.metadata_key;\n\n for $readonly_row in SELECT row_id FROM metadata WHERE metadata_key = 'readonly_key' AND value_s = $row_key LIMIT 1 {\n error('Cannot disable read-only metadata');\n }\n\n UPDATE metadata SET disabled_at = $current_block\n WHERE row_id = $row_id;\n }\n\n if $found == false {\n error('metadata record not found');\n }",
|
|
1318
|
+
"return_types": null,
|
|
1319
|
+
"annotations": null
|
|
1320
|
+
},
|
|
1321
|
+
{
|
|
1322
|
+
"name": "transfer_stream_ownership",
|
|
1323
|
+
"parameters": [
|
|
1324
|
+
{
|
|
1325
|
+
"name": "$new_owner",
|
|
1326
|
+
"type": {
|
|
1327
|
+
"name": "text",
|
|
1328
|
+
"is_array": false,
|
|
1329
|
+
"metadata": [
|
|
1330
|
+
0,
|
|
1331
|
+
0
|
|
1332
|
+
]
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
],
|
|
1336
|
+
"public": true,
|
|
1337
|
+
"modifiers": null,
|
|
1338
|
+
"body": "stream_owner_only();\n\n // fail if not a valid address\n check_eth_address($new_owner);\n\n UPDATE metadata SET value_ref = LOWER($new_owner)\n WHERE metadata_key = 'stream_owner';",
|
|
1339
|
+
"return_types": null,
|
|
1340
|
+
"annotations": null
|
|
1341
|
+
},
|
|
1342
|
+
{
|
|
1343
|
+
"name": "check_eth_address",
|
|
1344
|
+
"parameters": [
|
|
1345
|
+
{
|
|
1346
|
+
"name": "$address",
|
|
1347
|
+
"type": {
|
|
1348
|
+
"name": "text",
|
|
1349
|
+
"is_array": false,
|
|
1350
|
+
"metadata": [
|
|
1351
|
+
0,
|
|
1352
|
+
0
|
|
1353
|
+
]
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
],
|
|
1357
|
+
"public": false,
|
|
1358
|
+
"modifiers": null,
|
|
1359
|
+
"body": "if (length($address) != 42) {\n error('invalid address length');\n }\n\n // check if starts with 0x\n for $row in SELECT $address LIKE '0x%' as a {\n if $row.a == false {\n error('address does not start with 0x');\n }\n }",
|
|
1360
|
+
"return_types": null,
|
|
1361
|
+
"annotations": null
|
|
1362
|
+
},
|
|
1363
|
+
{
|
|
1364
|
+
"name": "get_current_version",
|
|
1365
|
+
"parameters": [
|
|
1366
|
+
{
|
|
1367
|
+
"name": "$show_disabled",
|
|
1368
|
+
"type": {
|
|
1369
|
+
"name": "bool",
|
|
1370
|
+
"is_array": false,
|
|
1371
|
+
"metadata": [
|
|
1372
|
+
0,
|
|
1373
|
+
0
|
|
1374
|
+
]
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
],
|
|
1378
|
+
"public": false,
|
|
1379
|
+
"modifiers": [
|
|
1380
|
+
"VIEW"
|
|
1381
|
+
],
|
|
1382
|
+
"body": "if $show_disabled == false {\n for $row in SELECT version FROM taxonomies WHERE disabled_at IS NULL ORDER BY version DESC LIMIT 1 {\n return $row.version;\n }\n } else {\n for $row2 in SELECT version FROM taxonomies ORDER BY version DESC LIMIT 1 {\n return $row2.version;\n }\n }\n\n return 0;",
|
|
1383
|
+
"return_types": {
|
|
1384
|
+
"is_table": false,
|
|
1385
|
+
"fields": [
|
|
1386
|
+
{
|
|
1387
|
+
"name": "result",
|
|
1388
|
+
"type": {
|
|
1389
|
+
"name": "int",
|
|
1390
|
+
"is_array": false,
|
|
1391
|
+
"metadata": [
|
|
1392
|
+
0,
|
|
1393
|
+
0
|
|
1394
|
+
]
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
]
|
|
1398
|
+
},
|
|
1399
|
+
"annotations": null
|
|
1400
|
+
},
|
|
1401
|
+
{
|
|
1402
|
+
"name": "set_taxonomy",
|
|
1403
|
+
"parameters": [
|
|
1404
|
+
{
|
|
1405
|
+
"name": "$data_providers",
|
|
1406
|
+
"type": {
|
|
1407
|
+
"name": "text",
|
|
1408
|
+
"is_array": true,
|
|
1409
|
+
"metadata": [
|
|
1410
|
+
0,
|
|
1411
|
+
0
|
|
1412
|
+
]
|
|
1413
|
+
}
|
|
1414
|
+
},
|
|
1415
|
+
{
|
|
1416
|
+
"name": "$stream_ids",
|
|
1417
|
+
"type": {
|
|
1418
|
+
"name": "text",
|
|
1419
|
+
"is_array": true,
|
|
1420
|
+
"metadata": [
|
|
1421
|
+
0,
|
|
1422
|
+
0
|
|
1423
|
+
]
|
|
1424
|
+
}
|
|
1425
|
+
},
|
|
1426
|
+
{
|
|
1427
|
+
"name": "$weights",
|
|
1428
|
+
"type": {
|
|
1429
|
+
"name": "decimal",
|
|
1430
|
+
"is_array": true,
|
|
1431
|
+
"metadata": [
|
|
1432
|
+
36,
|
|
1433
|
+
18
|
|
1434
|
+
]
|
|
1435
|
+
}
|
|
1436
|
+
},
|
|
1437
|
+
{
|
|
1438
|
+
"name": "$start_date",
|
|
1439
|
+
"type": {
|
|
1440
|
+
"name": "int",
|
|
1441
|
+
"is_array": false,
|
|
1442
|
+
"metadata": [
|
|
1443
|
+
0,
|
|
1444
|
+
0
|
|
1445
|
+
]
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
],
|
|
1449
|
+
"public": true,
|
|
1450
|
+
"modifiers": null,
|
|
1451
|
+
"body": "stream_owner_only();\n\n $next_version int := get_current_version(true) + 1;\n $block_height int := @height;\n $current_uuid uuid := uuid_generate_v5('e92064da-19c5-11ef-9bc0-325096b39f47'::uuid, @txid);\n\n $length int := array_length($data_providers);\n\n // check lengths\n if $length != array_length($stream_ids) {\n error('data_providers and stream_ids must have the same length');\n }\n if $length != array_length($weights) {\n error('data_providers and weights must have the same length');\n }\n\n for $i in 1..$length {\n $current_uuid := uuid_generate_v5($current_uuid, @txid);\n\n INSERT INTO taxonomies (taxonomy_id, child_stream_id, child_data_provider, weight, created_at, version, start_date)\n VALUES ($current_uuid, $stream_ids[$i], $data_providers[$i], $weights[$i], $block_height, $next_version, $start_date);\n }",
|
|
1452
|
+
"return_types": null,
|
|
1453
|
+
"annotations": null
|
|
1454
|
+
},
|
|
1455
|
+
{
|
|
1456
|
+
"name": "describe_taxonomies",
|
|
1457
|
+
"parameters": [
|
|
1458
|
+
{
|
|
1459
|
+
"name": "$latest_version",
|
|
1460
|
+
"type": {
|
|
1461
|
+
"name": "bool",
|
|
1462
|
+
"is_array": false,
|
|
1463
|
+
"metadata": [
|
|
1464
|
+
0,
|
|
1465
|
+
0
|
|
1466
|
+
]
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
],
|
|
1470
|
+
"public": true,
|
|
1471
|
+
"modifiers": [
|
|
1472
|
+
"VIEW"
|
|
1473
|
+
],
|
|
1474
|
+
"body": "if $latest_version == true {\n // just the latest enabled version should be returned\n return SELECT\n child_stream_id,\n child_data_provider,\n weight,\n created_at,\n version,\n start_date\n FROM taxonomies\n WHERE version = get_current_version(false) AND disabled_at IS NULL\n ORDER BY created_at DESC;\n } else {\n return SELECT\n child_stream_id,\n child_data_provider,\n weight,\n created_at,\n version,\n start_date\n FROM taxonomies\n WHERE disabled_at IS NULL\n ORDER BY version DESC;\n }",
|
|
1475
|
+
"return_types": {
|
|
1476
|
+
"is_table": true,
|
|
1477
|
+
"fields": [
|
|
1478
|
+
{
|
|
1479
|
+
"name": "child_stream_id",
|
|
1480
|
+
"type": {
|
|
1481
|
+
"name": "text",
|
|
1482
|
+
"is_array": false,
|
|
1483
|
+
"metadata": [
|
|
1484
|
+
0,
|
|
1485
|
+
0
|
|
1486
|
+
]
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
{
|
|
1490
|
+
"name": "child_data_provider",
|
|
1491
|
+
"type": {
|
|
1492
|
+
"name": "text",
|
|
1493
|
+
"is_array": false,
|
|
1494
|
+
"metadata": [
|
|
1495
|
+
0,
|
|
1496
|
+
0
|
|
1497
|
+
]
|
|
1498
|
+
}
|
|
1499
|
+
},
|
|
1500
|
+
{
|
|
1501
|
+
"name": "weight",
|
|
1502
|
+
"type": {
|
|
1503
|
+
"name": "decimal",
|
|
1504
|
+
"is_array": false,
|
|
1505
|
+
"metadata": [
|
|
1506
|
+
36,
|
|
1507
|
+
18
|
|
1508
|
+
]
|
|
1509
|
+
}
|
|
1510
|
+
},
|
|
1511
|
+
{
|
|
1512
|
+
"name": "created_at",
|
|
1513
|
+
"type": {
|
|
1514
|
+
"name": "int",
|
|
1515
|
+
"is_array": false,
|
|
1516
|
+
"metadata": [
|
|
1517
|
+
0,
|
|
1518
|
+
0
|
|
1519
|
+
]
|
|
1520
|
+
}
|
|
1521
|
+
},
|
|
1522
|
+
{
|
|
1523
|
+
"name": "version",
|
|
1524
|
+
"type": {
|
|
1525
|
+
"name": "int",
|
|
1526
|
+
"is_array": false,
|
|
1527
|
+
"metadata": [
|
|
1528
|
+
0,
|
|
1529
|
+
0
|
|
1530
|
+
]
|
|
1531
|
+
}
|
|
1532
|
+
},
|
|
1533
|
+
{
|
|
1534
|
+
"name": "start_date",
|
|
1535
|
+
"type": {
|
|
1536
|
+
"name": "int",
|
|
1537
|
+
"is_array": false,
|
|
1538
|
+
"metadata": [
|
|
1539
|
+
0,
|
|
1540
|
+
0
|
|
1541
|
+
]
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
]
|
|
1545
|
+
},
|
|
1546
|
+
"annotations": null
|
|
1547
|
+
},
|
|
1548
|
+
{
|
|
1549
|
+
"name": "disable_taxonomy",
|
|
1550
|
+
"parameters": [
|
|
1551
|
+
{
|
|
1552
|
+
"name": "$version",
|
|
1553
|
+
"type": {
|
|
1554
|
+
"name": "int",
|
|
1555
|
+
"is_array": false,
|
|
1556
|
+
"metadata": [
|
|
1557
|
+
0,
|
|
1558
|
+
0
|
|
1559
|
+
]
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
],
|
|
1563
|
+
"public": true,
|
|
1564
|
+
"modifiers": null,
|
|
1565
|
+
"body": "stream_owner_only();\n\n $current_block int := @height;\n\n $found bool := false;\n\n // Check if the taxonomies with the given version exist and disable them\n for $row in SELECT child_stream_id FROM taxonomies WHERE version = $version AND disabled_at IS NULL {\n $found := true;\n UPDATE taxonomies SET disabled_at = $current_block\n WHERE version = $version AND disabled_at IS NULL;\n }\n\n if $found == false {\n error('No taxonomies found for the given version');\n }",
|
|
1566
|
+
"return_types": null,
|
|
1567
|
+
"annotations": null
|
|
1568
|
+
},
|
|
1569
|
+
{
|
|
1570
|
+
"name": "is_stream_allowed_to_compose",
|
|
1571
|
+
"parameters": [
|
|
1572
|
+
{
|
|
1573
|
+
"name": "$foreign_caller",
|
|
1574
|
+
"type": {
|
|
1575
|
+
"name": "text",
|
|
1576
|
+
"is_array": false,
|
|
1577
|
+
"metadata": [
|
|
1578
|
+
0,
|
|
1579
|
+
0
|
|
1580
|
+
]
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
],
|
|
1584
|
+
"public": true,
|
|
1585
|
+
"modifiers": [
|
|
1586
|
+
"VIEW"
|
|
1587
|
+
],
|
|
1588
|
+
"body": "if $foreign_caller == '' {\n return true;\n }\n\n // if public, anyone can always read\n // If there's no visibility metadata, it's public.\n $visibility int := 0;\n for $v_row in SELECT * FROM get_metadata('compose_visibility', true, null) {\n $visibility := $v_row.value_i;\n }\n\n if $visibility == 0 {\n return true;\n }\n\n // if there's metadata allow_compose_stream -\u003e \u003cforeign_caller\u003e, then its permitted\n for $row in SELECT * FROM get_metadata('allow_compose_stream', true, $foreign_caller) LIMIT 1 {\n return true;\n }\n\n error('Stream not allowed to compose');",
|
|
1589
|
+
"return_types": {
|
|
1590
|
+
"is_table": false,
|
|
1591
|
+
"fields": [
|
|
1592
|
+
{
|
|
1593
|
+
"name": "value",
|
|
1594
|
+
"type": {
|
|
1595
|
+
"name": "bool",
|
|
1596
|
+
"is_array": false,
|
|
1597
|
+
"metadata": [
|
|
1598
|
+
0,
|
|
1599
|
+
0
|
|
1600
|
+
]
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
]
|
|
1604
|
+
},
|
|
1605
|
+
"annotations": null
|
|
1606
|
+
},
|
|
1607
|
+
{
|
|
1608
|
+
"name": "get_index_change",
|
|
1609
|
+
"parameters": [
|
|
1610
|
+
{
|
|
1611
|
+
"name": "$date_from",
|
|
1612
|
+
"type": {
|
|
1613
|
+
"name": "int",
|
|
1614
|
+
"is_array": false,
|
|
1615
|
+
"metadata": [
|
|
1616
|
+
0,
|
|
1617
|
+
0
|
|
1618
|
+
]
|
|
1619
|
+
}
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
"name": "$date_to",
|
|
1623
|
+
"type": {
|
|
1624
|
+
"name": "int",
|
|
1625
|
+
"is_array": false,
|
|
1626
|
+
"metadata": [
|
|
1627
|
+
0,
|
|
1628
|
+
0
|
|
1629
|
+
]
|
|
1630
|
+
}
|
|
1631
|
+
},
|
|
1632
|
+
{
|
|
1633
|
+
"name": "$frozen_at",
|
|
1634
|
+
"type": {
|
|
1635
|
+
"name": "int",
|
|
1636
|
+
"is_array": false,
|
|
1637
|
+
"metadata": [
|
|
1638
|
+
0,
|
|
1639
|
+
0
|
|
1640
|
+
]
|
|
1641
|
+
}
|
|
1642
|
+
},
|
|
1643
|
+
{
|
|
1644
|
+
"name": "$base_date",
|
|
1645
|
+
"type": {
|
|
1646
|
+
"name": "int",
|
|
1647
|
+
"is_array": false,
|
|
1648
|
+
"metadata": [
|
|
1649
|
+
0,
|
|
1650
|
+
0
|
|
1651
|
+
]
|
|
1652
|
+
}
|
|
1653
|
+
},
|
|
1654
|
+
{
|
|
1655
|
+
"name": "$days_interval",
|
|
1656
|
+
"type": {
|
|
1657
|
+
"name": "int",
|
|
1658
|
+
"is_array": false,
|
|
1659
|
+
"metadata": [
|
|
1660
|
+
0,
|
|
1661
|
+
0
|
|
1662
|
+
]
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
],
|
|
1666
|
+
"public": true,
|
|
1667
|
+
"modifiers": [
|
|
1668
|
+
"VIEW"
|
|
1669
|
+
],
|
|
1670
|
+
"body": "if $frozen_at == null {\n $frozen_at := 0;\n }\n\n if $days_interval == null {\n error('days_interval is required');\n }\n\n $current_values decimal(36,18)[];\n // example: [01-2001, 05-2001, 09-2001, 10-2001]\n $current_dates int[];\n // example: [01-2000, 05-2000, 09-2000, 10-2000]\n $expected_prev_dates int[];\n\n for $row_current in SELECT * FROM get_index($date_from, $date_to, $frozen_at, $base_date) {\n $prev_date := $row_current.date_value - ($days_interval * 86400);\n $expected_prev_dates := array_append($expected_prev_dates, $prev_date);\n $current_values := array_append($current_values, $row_current.value);\n $current_dates := array_append($current_dates, $row_current.date_value);\n }\n\n // example: 01-2000]\n $earliest_prev_date := $expected_prev_dates[1];\n // example: 09-2000\n $latest_prev_date := $expected_prev_dates[array_length($expected_prev_dates)];\n\n // real previous values doesn't match the same length as expected previous dates\n // because the interval can have much more values than the expected dates\n $real_prev_values decimal(36,18)[];\n $real_prev_dates int[];\n\n // now we query the prev dates\n for $row_prev in SELECT * FROM get_index($earliest_prev_date, $latest_prev_date, $frozen_at, $base_date) {\n $real_prev_values := array_append($real_prev_values, $row_prev.value);\n $real_prev_dates := array_append($real_prev_dates, $row_prev.date_value);\n }\n\n // now we calculate the matching dates for the real prev values\n $result_prev_dates int[];\n $result_prev_values decimal(36,18)[];\n\n $real_prev_date_idx int := 1;\n\n // for each expected prev date, we find the matching real prev date\n if array_length($expected_prev_dates) \u003e 0 {\n for $expected_prev_date_idx in 1..array_length($expected_prev_dates) {\n // we start from the last index of real prev dates. we don't need to check previous values\n for $selector in $real_prev_date_idx..array_length($real_prev_dates) {\n // if next real prev date is greater than expected prev date (or null), then we need to use the current real value\n if $real_prev_dates[$selector + 1] \u003e $expected_prev_dates[$expected_prev_date_idx] OR $real_prev_dates[$selector + 1] IS NULL {\n // if the current real prev date is already greater than expected prev date\n // we use NULL. We're probably before the first real prev date here\n if $real_prev_dates[$selector] \u003e $expected_prev_dates[$expected_prev_date_idx] {\n $result_prev_dates := array_append($result_prev_dates, null::int);\n $result_prev_values := array_append($result_prev_values, null::decimal(36,18));\n } else {\n $result_prev_dates := array_append($result_prev_dates, $real_prev_dates[$selector]);\n $result_prev_values := array_append($result_prev_values, $real_prev_values[$selector]);\n }\n // we already appended one for current $real_prev_date_idx, then we need to go to next\n $real_prev_date_idx := $selector;\n break;\n }\n }\n }\n }\n\n // check if we have the same number of values and dates\n if array_length($current_dates) != array_length($result_prev_dates) {\n error('we have different number of dates and values');\n }\n if array_length($current_values) != array_length($result_prev_values) {\n error('we have different number of dates and values');\n }\n\n // calculate the index change\n if array_length($result_prev_dates) \u003e 0 {\n for $row_result in 1..array_length($result_prev_dates) {\n // if the expected_prev_date is null, then we don't have a real prev date\n if $result_prev_dates[$row_result] IS DISTINCT FROM NULL {\n return next $current_dates[$row_result], ($current_values[$row_result] - $result_prev_values[$row_result]) * 100.00::decimal(36,18) / $result_prev_values[$row_result];\n }\n }\n }",
|
|
1671
|
+
"return_types": {
|
|
1672
|
+
"is_table": true,
|
|
1673
|
+
"fields": [
|
|
1674
|
+
{
|
|
1675
|
+
"name": "date_value",
|
|
1676
|
+
"type": {
|
|
1677
|
+
"name": "int",
|
|
1678
|
+
"is_array": false,
|
|
1679
|
+
"metadata": [
|
|
1680
|
+
0,
|
|
1681
|
+
0
|
|
1682
|
+
]
|
|
1683
|
+
}
|
|
1684
|
+
},
|
|
1685
|
+
{
|
|
1686
|
+
"name": "value",
|
|
1687
|
+
"type": {
|
|
1688
|
+
"name": "decimal",
|
|
1689
|
+
"is_array": false,
|
|
1690
|
+
"metadata": [
|
|
1691
|
+
36,
|
|
1692
|
+
18
|
|
1693
|
+
]
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
]
|
|
1697
|
+
},
|
|
1698
|
+
"annotations": null
|
|
1699
|
+
},
|
|
1700
|
+
{
|
|
1701
|
+
"name": "emit_values_if",
|
|
1702
|
+
"parameters": [
|
|
1703
|
+
{
|
|
1704
|
+
"name": "$condition",
|
|
1705
|
+
"type": {
|
|
1706
|
+
"name": "bool",
|
|
1707
|
+
"is_array": false,
|
|
1708
|
+
"metadata": [
|
|
1709
|
+
0,
|
|
1710
|
+
0
|
|
1711
|
+
]
|
|
1712
|
+
}
|
|
1713
|
+
},
|
|
1714
|
+
{
|
|
1715
|
+
"name": "$date_value",
|
|
1716
|
+
"type": {
|
|
1717
|
+
"name": "int",
|
|
1718
|
+
"is_array": false,
|
|
1719
|
+
"metadata": [
|
|
1720
|
+
0,
|
|
1721
|
+
0
|
|
1722
|
+
]
|
|
1723
|
+
}
|
|
1724
|
+
},
|
|
1725
|
+
{
|
|
1726
|
+
"name": "$values",
|
|
1727
|
+
"type": {
|
|
1728
|
+
"name": "decimal",
|
|
1729
|
+
"is_array": true,
|
|
1730
|
+
"metadata": [
|
|
1731
|
+
36,
|
|
1732
|
+
18
|
|
1733
|
+
]
|
|
1734
|
+
}
|
|
1735
|
+
},
|
|
1736
|
+
{
|
|
1737
|
+
"name": "$weights",
|
|
1738
|
+
"type": {
|
|
1739
|
+
"name": "decimal",
|
|
1740
|
+
"is_array": true,
|
|
1741
|
+
"metadata": [
|
|
1742
|
+
36,
|
|
1743
|
+
18
|
|
1744
|
+
]
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
],
|
|
1748
|
+
"public": false,
|
|
1749
|
+
"modifiers": [
|
|
1750
|
+
"VIEW"
|
|
1751
|
+
],
|
|
1752
|
+
"body": "if $condition == true {\n if array_length($values) \u003e 0 {\n for $i in 1..array_length($values) {\n return next $date_value, $values[$i], $weights[$i];\n }\n }\n }",
|
|
1753
|
+
"return_types": {
|
|
1754
|
+
"is_table": true,
|
|
1755
|
+
"fields": [
|
|
1756
|
+
{
|
|
1757
|
+
"name": "date_value",
|
|
1758
|
+
"type": {
|
|
1759
|
+
"name": "int",
|
|
1760
|
+
"is_array": false,
|
|
1761
|
+
"metadata": [
|
|
1762
|
+
0,
|
|
1763
|
+
0
|
|
1764
|
+
]
|
|
1765
|
+
}
|
|
1766
|
+
},
|
|
1767
|
+
{
|
|
1768
|
+
"name": "value",
|
|
1769
|
+
"type": {
|
|
1770
|
+
"name": "decimal",
|
|
1771
|
+
"is_array": false,
|
|
1772
|
+
"metadata": [
|
|
1773
|
+
36,
|
|
1774
|
+
18
|
|
1775
|
+
]
|
|
1776
|
+
}
|
|
1777
|
+
},
|
|
1778
|
+
{
|
|
1779
|
+
"name": "weight",
|
|
1780
|
+
"type": {
|
|
1781
|
+
"name": "decimal",
|
|
1782
|
+
"is_array": false,
|
|
1783
|
+
"metadata": [
|
|
1784
|
+
36,
|
|
1785
|
+
18
|
|
1786
|
+
]
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
]
|
|
1790
|
+
},
|
|
1791
|
+
"annotations": null
|
|
1792
|
+
},
|
|
1793
|
+
{
|
|
1794
|
+
"name": "remove_array_element",
|
|
1795
|
+
"parameters": [
|
|
1796
|
+
{
|
|
1797
|
+
"name": "$array",
|
|
1798
|
+
"type": {
|
|
1799
|
+
"name": "int",
|
|
1800
|
+
"is_array": true,
|
|
1801
|
+
"metadata": [
|
|
1802
|
+
0,
|
|
1803
|
+
0
|
|
1804
|
+
]
|
|
1805
|
+
}
|
|
1806
|
+
},
|
|
1807
|
+
{
|
|
1808
|
+
"name": "$index",
|
|
1809
|
+
"type": {
|
|
1810
|
+
"name": "int",
|
|
1811
|
+
"is_array": false,
|
|
1812
|
+
"metadata": [
|
|
1813
|
+
0,
|
|
1814
|
+
0
|
|
1815
|
+
]
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
],
|
|
1819
|
+
"public": false,
|
|
1820
|
+
"modifiers": [
|
|
1821
|
+
"VIEW"
|
|
1822
|
+
],
|
|
1823
|
+
"body": "$new_array int[];\n for $i in 1..array_length($array) {\n if $i != $index {\n $new_array := array_append($new_array, $array[$i]);\n }\n }\n\n return $new_array;",
|
|
1824
|
+
"return_types": {
|
|
1825
|
+
"is_table": false,
|
|
1826
|
+
"fields": [
|
|
1827
|
+
{
|
|
1828
|
+
"name": "result",
|
|
1829
|
+
"type": {
|
|
1830
|
+
"name": "int",
|
|
1831
|
+
"is_array": true,
|
|
1832
|
+
"metadata": [
|
|
1833
|
+
0,
|
|
1834
|
+
0
|
|
1835
|
+
]
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
]
|
|
1839
|
+
},
|
|
1840
|
+
"annotations": null
|
|
1841
|
+
},
|
|
1842
|
+
{
|
|
1843
|
+
"name": "array_update_element",
|
|
1844
|
+
"parameters": [
|
|
1845
|
+
{
|
|
1846
|
+
"name": "$array",
|
|
1847
|
+
"type": {
|
|
1848
|
+
"name": "decimal",
|
|
1849
|
+
"is_array": true,
|
|
1850
|
+
"metadata": [
|
|
1851
|
+
36,
|
|
1852
|
+
18
|
|
1853
|
+
]
|
|
1854
|
+
}
|
|
1855
|
+
},
|
|
1856
|
+
{
|
|
1857
|
+
"name": "$index",
|
|
1858
|
+
"type": {
|
|
1859
|
+
"name": "int",
|
|
1860
|
+
"is_array": false,
|
|
1861
|
+
"metadata": [
|
|
1862
|
+
0,
|
|
1863
|
+
0
|
|
1864
|
+
]
|
|
1865
|
+
}
|
|
1866
|
+
},
|
|
1867
|
+
{
|
|
1868
|
+
"name": "$value",
|
|
1869
|
+
"type": {
|
|
1870
|
+
"name": "decimal",
|
|
1871
|
+
"is_array": false,
|
|
1872
|
+
"metadata": [
|
|
1873
|
+
36,
|
|
1874
|
+
18
|
|
1875
|
+
]
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
],
|
|
1879
|
+
"public": false,
|
|
1880
|
+
"modifiers": [
|
|
1881
|
+
"VIEW"
|
|
1882
|
+
],
|
|
1883
|
+
"body": "$new_array decimal(36,18)[];\n for $i in 1..array_length($array) {\n if $i == $index {\n $new_array := array_append($new_array, $value);\n } else {\n $new_array := array_append($new_array, $array[$i]);\n }\n }\n return $new_array;",
|
|
1884
|
+
"return_types": {
|
|
1885
|
+
"is_table": false,
|
|
1886
|
+
"fields": [
|
|
1887
|
+
{
|
|
1888
|
+
"name": "result",
|
|
1889
|
+
"type": {
|
|
1890
|
+
"name": "decimal",
|
|
1891
|
+
"is_array": true,
|
|
1892
|
+
"metadata": [
|
|
1893
|
+
36,
|
|
1894
|
+
18
|
|
1895
|
+
]
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
]
|
|
1899
|
+
},
|
|
1900
|
+
"annotations": null
|
|
1901
|
+
},
|
|
1902
|
+
{
|
|
1903
|
+
"name": "get_dynamic_weight",
|
|
1904
|
+
"parameters": [
|
|
1905
|
+
{
|
|
1906
|
+
"name": "$stream_id",
|
|
1907
|
+
"type": {
|
|
1908
|
+
"name": "text",
|
|
1909
|
+
"is_array": false,
|
|
1910
|
+
"metadata": [
|
|
1911
|
+
0,
|
|
1912
|
+
0
|
|
1913
|
+
]
|
|
1914
|
+
}
|
|
1915
|
+
},
|
|
1916
|
+
{
|
|
1917
|
+
"name": "$date_value",
|
|
1918
|
+
"type": {
|
|
1919
|
+
"name": "int",
|
|
1920
|
+
"is_array": false,
|
|
1921
|
+
"metadata": [
|
|
1922
|
+
0,
|
|
1923
|
+
0
|
|
1924
|
+
]
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
],
|
|
1928
|
+
"public": false,
|
|
1929
|
+
"modifiers": [
|
|
1930
|
+
"VIEW"
|
|
1931
|
+
],
|
|
1932
|
+
"body": "for $row in SELECT weight\n FROM taxonomies\n WHERE child_stream_id = $stream_id\n AND (start_date IS NULL OR start_date = 0 OR start_date \u003c= $date_value)\n ORDER BY start_date DESC\n LIMIT 1 {\n return $row.weight;\n }\n\n // If no weight is found, we return the earliest weight available, this to ensure that we always have a weight\n // for the given date even if it's before the first weight's start_date\n // Would be better if COALESCE was supported\n for $row2 in SELECT weight\n FROM taxonomies\n WHERE child_stream_id = $stream_id\n ORDER BY start_date ASC\n LIMIT 1 {\n return $row2.weight;\n }",
|
|
1933
|
+
"return_types": {
|
|
1934
|
+
"is_table": false,
|
|
1935
|
+
"fields": [
|
|
1936
|
+
{
|
|
1937
|
+
"name": "weight",
|
|
1938
|
+
"type": {
|
|
1939
|
+
"name": "decimal",
|
|
1940
|
+
"is_array": false,
|
|
1941
|
+
"metadata": [
|
|
1942
|
+
36,
|
|
1943
|
+
18
|
|
1944
|
+
]
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
]
|
|
1948
|
+
},
|
|
1949
|
+
"annotations": null
|
|
1950
|
+
}
|
|
1951
|
+
],
|
|
1952
|
+
"foreign_calls": [
|
|
1953
|
+
{
|
|
1954
|
+
"name": "ext_get_record",
|
|
1955
|
+
"parameters": [
|
|
1956
|
+
{
|
|
1957
|
+
"name": "int",
|
|
1958
|
+
"is_array": false,
|
|
1959
|
+
"metadata": [
|
|
1960
|
+
0,
|
|
1961
|
+
0
|
|
1962
|
+
]
|
|
1963
|
+
},
|
|
1964
|
+
{
|
|
1965
|
+
"name": "int",
|
|
1966
|
+
"is_array": false,
|
|
1967
|
+
"metadata": [
|
|
1968
|
+
0,
|
|
1969
|
+
0
|
|
1970
|
+
]
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
"name": "int",
|
|
1974
|
+
"is_array": false,
|
|
1975
|
+
"metadata": [
|
|
1976
|
+
0,
|
|
1977
|
+
0
|
|
1978
|
+
]
|
|
1979
|
+
}
|
|
1980
|
+
],
|
|
1981
|
+
"return_types": {
|
|
1982
|
+
"is_table": true,
|
|
1983
|
+
"fields": [
|
|
1984
|
+
{
|
|
1985
|
+
"name": "date_value",
|
|
1986
|
+
"type": {
|
|
1987
|
+
"name": "int",
|
|
1988
|
+
"is_array": false,
|
|
1989
|
+
"metadata": [
|
|
1990
|
+
0,
|
|
1991
|
+
0
|
|
1992
|
+
]
|
|
1993
|
+
}
|
|
1994
|
+
},
|
|
1995
|
+
{
|
|
1996
|
+
"name": "value",
|
|
1997
|
+
"type": {
|
|
1998
|
+
"name": "decimal",
|
|
1999
|
+
"is_array": false,
|
|
2000
|
+
"metadata": [
|
|
2001
|
+
36,
|
|
2002
|
+
18
|
|
2003
|
+
]
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
]
|
|
2007
|
+
}
|
|
2008
|
+
},
|
|
2009
|
+
{
|
|
2010
|
+
"name": "ext_get_index",
|
|
2011
|
+
"parameters": [
|
|
2012
|
+
{
|
|
2013
|
+
"name": "int",
|
|
2014
|
+
"is_array": false,
|
|
2015
|
+
"metadata": [
|
|
2016
|
+
0,
|
|
2017
|
+
0
|
|
2018
|
+
]
|
|
2019
|
+
},
|
|
2020
|
+
{
|
|
2021
|
+
"name": "int",
|
|
2022
|
+
"is_array": false,
|
|
2023
|
+
"metadata": [
|
|
2024
|
+
0,
|
|
2025
|
+
0
|
|
2026
|
+
]
|
|
2027
|
+
},
|
|
2028
|
+
{
|
|
2029
|
+
"name": "int",
|
|
2030
|
+
"is_array": false,
|
|
2031
|
+
"metadata": [
|
|
2032
|
+
0,
|
|
2033
|
+
0
|
|
2034
|
+
]
|
|
2035
|
+
},
|
|
2036
|
+
{
|
|
2037
|
+
"name": "int",
|
|
2038
|
+
"is_array": false,
|
|
2039
|
+
"metadata": [
|
|
2040
|
+
0,
|
|
2041
|
+
0
|
|
2042
|
+
]
|
|
2043
|
+
}
|
|
2044
|
+
],
|
|
2045
|
+
"return_types": {
|
|
2046
|
+
"is_table": true,
|
|
2047
|
+
"fields": [
|
|
2048
|
+
{
|
|
2049
|
+
"name": "date_value",
|
|
2050
|
+
"type": {
|
|
2051
|
+
"name": "int",
|
|
2052
|
+
"is_array": false,
|
|
2053
|
+
"metadata": [
|
|
2054
|
+
0,
|
|
2055
|
+
0
|
|
2056
|
+
]
|
|
2057
|
+
}
|
|
2058
|
+
},
|
|
2059
|
+
{
|
|
2060
|
+
"name": "value",
|
|
2061
|
+
"type": {
|
|
2062
|
+
"name": "decimal",
|
|
2063
|
+
"is_array": false,
|
|
2064
|
+
"metadata": [
|
|
2065
|
+
36,
|
|
2066
|
+
18
|
|
2067
|
+
]
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
]
|
|
2071
|
+
}
|
|
2072
|
+
},
|
|
2073
|
+
{
|
|
2074
|
+
"name": "ext_get_first_record",
|
|
2075
|
+
"parameters": [
|
|
2076
|
+
{
|
|
2077
|
+
"name": "int",
|
|
2078
|
+
"is_array": false,
|
|
2079
|
+
"metadata": [
|
|
2080
|
+
0,
|
|
2081
|
+
0
|
|
2082
|
+
]
|
|
2083
|
+
},
|
|
2084
|
+
{
|
|
2085
|
+
"name": "int",
|
|
2086
|
+
"is_array": false,
|
|
2087
|
+
"metadata": [
|
|
2088
|
+
0,
|
|
2089
|
+
0
|
|
2090
|
+
]
|
|
2091
|
+
}
|
|
2092
|
+
],
|
|
2093
|
+
"return_types": {
|
|
2094
|
+
"is_table": true,
|
|
2095
|
+
"fields": [
|
|
2096
|
+
{
|
|
2097
|
+
"name": "date_value",
|
|
2098
|
+
"type": {
|
|
2099
|
+
"name": "int",
|
|
2100
|
+
"is_array": false,
|
|
2101
|
+
"metadata": [
|
|
2102
|
+
0,
|
|
2103
|
+
0
|
|
2104
|
+
]
|
|
2105
|
+
}
|
|
2106
|
+
},
|
|
2107
|
+
{
|
|
2108
|
+
"name": "value",
|
|
2109
|
+
"type": {
|
|
2110
|
+
"name": "decimal",
|
|
2111
|
+
"is_array": false,
|
|
2112
|
+
"metadata": [
|
|
2113
|
+
36,
|
|
2114
|
+
18
|
|
2115
|
+
]
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
]
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
]
|
|
2122
|
+
}
|