hyoo_sync_client 0.0.1
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/.nojekyll +0 -0
- package/README.md +28 -0
- package/node.audit.js +1 -0
- package/node.d.ts +1093 -0
- package/node.deps.json +1 -0
- package/node.js +4412 -0
- package/node.js.map +1 -0
- package/node.meta.tree +67 -0
- package/node.mjs +4413 -0
- package/node.mjs.map +1 -0
- package/node.test.js +8804 -0
- package/node.test.js.map +1 -0
- package/package.json +134 -0
- package/test.html +11 -0
- package/web.audit.js +1 -0
- package/web.css +1 -0
- package/web.css.map +1 -0
- package/web.d.ts +1025 -0
- package/web.deps.json +1 -0
- package/web.js +4099 -0
- package/web.js.map +1 -0
- package/web.meta.tree +67 -0
- package/web.mjs +4100 -0
- package/web.mjs.map +1 -0
- package/web.test.js +4087 -0
- package/web.test.js.map +1 -0
package/node.js
ADDED
|
@@ -0,0 +1,4412 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var exports = void 0;
|
|
3
|
+
|
|
4
|
+
var $node = $node || {}
|
|
5
|
+
void function( module ) { var exports = module.exports = this; function require( id ) { return $node[ id.replace( /^.\// , "../" ) ] };
|
|
6
|
+
;
|
|
7
|
+
"use strict";
|
|
8
|
+
Error.stackTraceLimit = 50;
|
|
9
|
+
var $;
|
|
10
|
+
(function ($) {
|
|
11
|
+
})($ || ($ = {}));
|
|
12
|
+
module.exports = $;
|
|
13
|
+
//mam.ts
|
|
14
|
+
;
|
|
15
|
+
|
|
16
|
+
$node[ "../mam.ts" ] = $node[ "../mam.ts" ] = module.exports }.call( {} , {} )
|
|
17
|
+
;
|
|
18
|
+
"use strict"
|
|
19
|
+
|
|
20
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
21
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
22
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
23
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
24
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
|
|
28
|
+
$.$$ = $
|
|
29
|
+
|
|
30
|
+
;
|
|
31
|
+
"use strict";
|
|
32
|
+
//hyoo/hyoo.ts
|
|
33
|
+
;
|
|
34
|
+
"use strict";
|
|
35
|
+
let $hyoo_sync_revision = "2431e7a";
|
|
36
|
+
//hyoo/sync/-meta.tree/revision.meta.tree.ts
|
|
37
|
+
;
|
|
38
|
+
"use strict";
|
|
39
|
+
var $;
|
|
40
|
+
(function ($) {
|
|
41
|
+
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
42
|
+
function $mol_ambient(overrides) {
|
|
43
|
+
return Object.setPrototypeOf(overrides, this || $);
|
|
44
|
+
}
|
|
45
|
+
$.$mol_ambient = $mol_ambient;
|
|
46
|
+
})($ || ($ = {}));
|
|
47
|
+
//mol/ambient/ambient.ts
|
|
48
|
+
;
|
|
49
|
+
"use strict";
|
|
50
|
+
var $;
|
|
51
|
+
(function ($) {
|
|
52
|
+
const instances = new WeakSet();
|
|
53
|
+
function $mol_delegate(proto, target) {
|
|
54
|
+
const proxy = new Proxy(proto, {
|
|
55
|
+
get: (_, field) => {
|
|
56
|
+
const obj = target();
|
|
57
|
+
let val = Reflect.get(obj, field);
|
|
58
|
+
if (typeof val === 'function') {
|
|
59
|
+
val = val.bind(obj);
|
|
60
|
+
}
|
|
61
|
+
return val;
|
|
62
|
+
},
|
|
63
|
+
has: (_, field) => Reflect.has(target(), field),
|
|
64
|
+
set: (_, field, value) => Reflect.set(target(), field, value),
|
|
65
|
+
getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
|
|
66
|
+
ownKeys: () => Reflect.ownKeys(target()),
|
|
67
|
+
getPrototypeOf: () => Reflect.getPrototypeOf(target()),
|
|
68
|
+
setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
|
|
69
|
+
isExtensible: () => Reflect.isExtensible(target()),
|
|
70
|
+
preventExtensions: () => Reflect.preventExtensions(target()),
|
|
71
|
+
apply: (_, self, args) => Reflect.apply(target(), self, args),
|
|
72
|
+
construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
|
|
73
|
+
defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
|
|
74
|
+
deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
|
|
75
|
+
});
|
|
76
|
+
instances.add(proxy);
|
|
77
|
+
return proxy;
|
|
78
|
+
}
|
|
79
|
+
$.$mol_delegate = $mol_delegate;
|
|
80
|
+
Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
|
|
81
|
+
value: (obj) => instances.has(obj),
|
|
82
|
+
});
|
|
83
|
+
})($ || ($ = {}));
|
|
84
|
+
//mol/delegate/delegate.ts
|
|
85
|
+
;
|
|
86
|
+
"use strict";
|
|
87
|
+
var $;
|
|
88
|
+
(function ($) {
|
|
89
|
+
$.$mol_owning_map = new WeakMap();
|
|
90
|
+
function $mol_owning_allow(having) {
|
|
91
|
+
try {
|
|
92
|
+
if (!having)
|
|
93
|
+
return false;
|
|
94
|
+
if (typeof having !== 'object')
|
|
95
|
+
return false;
|
|
96
|
+
if (having instanceof $mol_delegate)
|
|
97
|
+
return false;
|
|
98
|
+
if (typeof having['destructor'] !== 'function')
|
|
99
|
+
return false;
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
$.$mol_owning_allow = $mol_owning_allow;
|
|
107
|
+
function $mol_owning_get(having, Owner) {
|
|
108
|
+
if (!$mol_owning_allow(having))
|
|
109
|
+
return null;
|
|
110
|
+
while (true) {
|
|
111
|
+
const owner = $.$mol_owning_map.get(having);
|
|
112
|
+
if (!owner)
|
|
113
|
+
return owner;
|
|
114
|
+
if (!Owner)
|
|
115
|
+
return owner;
|
|
116
|
+
if (owner instanceof Owner)
|
|
117
|
+
return owner;
|
|
118
|
+
having = owner;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
$.$mol_owning_get = $mol_owning_get;
|
|
122
|
+
function $mol_owning_check(owner, having) {
|
|
123
|
+
if (!$mol_owning_allow(having))
|
|
124
|
+
return false;
|
|
125
|
+
if ($.$mol_owning_map.get(having) !== owner)
|
|
126
|
+
return false;
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
$.$mol_owning_check = $mol_owning_check;
|
|
130
|
+
function $mol_owning_catch(owner, having) {
|
|
131
|
+
if (!$mol_owning_allow(having))
|
|
132
|
+
return false;
|
|
133
|
+
if ($.$mol_owning_map.get(having))
|
|
134
|
+
return false;
|
|
135
|
+
$.$mol_owning_map.set(having, owner);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
$.$mol_owning_catch = $mol_owning_catch;
|
|
139
|
+
})($ || ($ = {}));
|
|
140
|
+
//mol/owning/owning.ts
|
|
141
|
+
;
|
|
142
|
+
"use strict";
|
|
143
|
+
var $;
|
|
144
|
+
(function ($) {
|
|
145
|
+
function $mol_fail(error) {
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
$.$mol_fail = $mol_fail;
|
|
149
|
+
})($ || ($ = {}));
|
|
150
|
+
//mol/fail/fail.ts
|
|
151
|
+
;
|
|
152
|
+
"use strict";
|
|
153
|
+
var $;
|
|
154
|
+
(function ($) {
|
|
155
|
+
function $mol_fail_hidden(error) {
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
$.$mol_fail_hidden = $mol_fail_hidden;
|
|
159
|
+
})($ || ($ = {}));
|
|
160
|
+
//mol/fail/hidden/hidden.ts
|
|
161
|
+
;
|
|
162
|
+
"use strict";
|
|
163
|
+
//mol/type/writable/writable.ts
|
|
164
|
+
;
|
|
165
|
+
"use strict";
|
|
166
|
+
var $;
|
|
167
|
+
(function ($) {
|
|
168
|
+
class $mol_object2 {
|
|
169
|
+
static $ = $;
|
|
170
|
+
[Symbol.toStringTag];
|
|
171
|
+
[$mol_ambient_ref] = null;
|
|
172
|
+
get $() {
|
|
173
|
+
if (this[$mol_ambient_ref])
|
|
174
|
+
return this[$mol_ambient_ref];
|
|
175
|
+
const owner = $mol_owning_get(this);
|
|
176
|
+
return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
|
|
177
|
+
}
|
|
178
|
+
set $(next) {
|
|
179
|
+
if (this[$mol_ambient_ref])
|
|
180
|
+
$mol_fail_hidden(new Error('Context already defined'));
|
|
181
|
+
this[$mol_ambient_ref] = next;
|
|
182
|
+
}
|
|
183
|
+
static create(init) {
|
|
184
|
+
const obj = new this;
|
|
185
|
+
if (init)
|
|
186
|
+
init(obj);
|
|
187
|
+
return obj;
|
|
188
|
+
}
|
|
189
|
+
static [Symbol.toPrimitive]() {
|
|
190
|
+
return this.toString();
|
|
191
|
+
}
|
|
192
|
+
static toString() {
|
|
193
|
+
if (Symbol.toStringTag in this)
|
|
194
|
+
return this[Symbol.toStringTag];
|
|
195
|
+
return this.name;
|
|
196
|
+
}
|
|
197
|
+
destructor() { }
|
|
198
|
+
toString() {
|
|
199
|
+
return this[Symbol.toStringTag] || this.constructor.name + '()';
|
|
200
|
+
}
|
|
201
|
+
toJSON() {
|
|
202
|
+
return this.toString();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
$.$mol_object2 = $mol_object2;
|
|
206
|
+
})($ || ($ = {}));
|
|
207
|
+
//mol/object2/object2.ts
|
|
208
|
+
;
|
|
209
|
+
"use strict";
|
|
210
|
+
var $;
|
|
211
|
+
(function ($) {
|
|
212
|
+
let $mol_wire_cursor;
|
|
213
|
+
(function ($mol_wire_cursor) {
|
|
214
|
+
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
215
|
+
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
216
|
+
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
217
|
+
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
218
|
+
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
219
|
+
})($ || ($ = {}));
|
|
220
|
+
//mol/wire/cursor/cursor.ts
|
|
221
|
+
;
|
|
222
|
+
"use strict";
|
|
223
|
+
var $;
|
|
224
|
+
(function ($) {
|
|
225
|
+
class $mol_wire_pub extends Object {
|
|
226
|
+
data = [];
|
|
227
|
+
static get [Symbol.species]() {
|
|
228
|
+
return Array;
|
|
229
|
+
}
|
|
230
|
+
sub_from = 0;
|
|
231
|
+
get sub_list() {
|
|
232
|
+
const res = [];
|
|
233
|
+
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
234
|
+
res.push(this.data[i]);
|
|
235
|
+
}
|
|
236
|
+
return res;
|
|
237
|
+
}
|
|
238
|
+
get sub_empty() {
|
|
239
|
+
return this.sub_from === this.data.length;
|
|
240
|
+
}
|
|
241
|
+
sub_on(sub, pub_pos) {
|
|
242
|
+
const pos = this.data.length;
|
|
243
|
+
this.data.push(sub, pub_pos);
|
|
244
|
+
return pos;
|
|
245
|
+
}
|
|
246
|
+
sub_off(sub_pos) {
|
|
247
|
+
if (!(sub_pos < this.data.length)) {
|
|
248
|
+
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
249
|
+
}
|
|
250
|
+
const end = this.data.length - 2;
|
|
251
|
+
if (sub_pos !== end) {
|
|
252
|
+
this.peer_move(end, sub_pos);
|
|
253
|
+
}
|
|
254
|
+
this.data.pop();
|
|
255
|
+
this.data.pop();
|
|
256
|
+
if (this.data.length === this.sub_from)
|
|
257
|
+
this.reap();
|
|
258
|
+
}
|
|
259
|
+
reap() { }
|
|
260
|
+
promote() {
|
|
261
|
+
$mol_wire_auto()?.track_next(this);
|
|
262
|
+
}
|
|
263
|
+
fresh() { }
|
|
264
|
+
complete() { }
|
|
265
|
+
emit(quant = $mol_wire_cursor.stale) {
|
|
266
|
+
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
267
|
+
;
|
|
268
|
+
this.data[i].absorb(quant);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
peer_move(from_pos, to_pos) {
|
|
272
|
+
const peer = this.data[from_pos];
|
|
273
|
+
const self_pos = this.data[from_pos + 1];
|
|
274
|
+
this.data[to_pos] = peer;
|
|
275
|
+
this.data[to_pos + 1] = self_pos;
|
|
276
|
+
peer.peer_repos(self_pos, to_pos);
|
|
277
|
+
}
|
|
278
|
+
peer_repos(peer_pos, self_pos) {
|
|
279
|
+
this.data[peer_pos + 1] = self_pos;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
$.$mol_wire_pub = $mol_wire_pub;
|
|
283
|
+
})($ || ($ = {}));
|
|
284
|
+
//mol/wire/pub/pub.ts
|
|
285
|
+
;
|
|
286
|
+
"use strict";
|
|
287
|
+
//mol/wire/sub/sub.ts
|
|
288
|
+
;
|
|
289
|
+
"use strict";
|
|
290
|
+
var $;
|
|
291
|
+
(function ($) {
|
|
292
|
+
$.$mol_wire_auto_sub = null;
|
|
293
|
+
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
294
|
+
return $.$mol_wire_auto_sub = next;
|
|
295
|
+
}
|
|
296
|
+
$.$mol_wire_auto = $mol_wire_auto;
|
|
297
|
+
$.$mol_wire_affected = [];
|
|
298
|
+
})($ || ($ = {}));
|
|
299
|
+
//mol/wire/wire.ts
|
|
300
|
+
;
|
|
301
|
+
"use strict";
|
|
302
|
+
var $;
|
|
303
|
+
(function ($) {
|
|
304
|
+
$['devtoolsFormatters'] ||= [];
|
|
305
|
+
function $mol_dev_format_register(config) {
|
|
306
|
+
$['devtoolsFormatters'].push(config);
|
|
307
|
+
}
|
|
308
|
+
$.$mol_dev_format_register = $mol_dev_format_register;
|
|
309
|
+
$.$mol_dev_format_head = Symbol('$mol_dev_format_head');
|
|
310
|
+
$.$mol_dev_format_body = Symbol('$mol_dev_format_body');
|
|
311
|
+
$mol_dev_format_register({
|
|
312
|
+
header: (val, config = false) => {
|
|
313
|
+
if (config)
|
|
314
|
+
return null;
|
|
315
|
+
if (!val)
|
|
316
|
+
return null;
|
|
317
|
+
if ($.$mol_dev_format_head in val) {
|
|
318
|
+
return val[$.$mol_dev_format_head]();
|
|
319
|
+
}
|
|
320
|
+
if (typeof val === 'function') {
|
|
321
|
+
return $mol_dev_format_native(val);
|
|
322
|
+
}
|
|
323
|
+
return null;
|
|
324
|
+
},
|
|
325
|
+
hasBody: val => val[$.$mol_dev_format_body],
|
|
326
|
+
body: val => val[$.$mol_dev_format_body](),
|
|
327
|
+
});
|
|
328
|
+
function $mol_dev_format_native(obj) {
|
|
329
|
+
if (typeof obj === 'undefined')
|
|
330
|
+
return $.$mol_dev_format_shade('undefined');
|
|
331
|
+
if (typeof obj !== 'object' && typeof obj !== 'function')
|
|
332
|
+
return obj;
|
|
333
|
+
return [
|
|
334
|
+
'object',
|
|
335
|
+
{
|
|
336
|
+
object: obj,
|
|
337
|
+
config: true,
|
|
338
|
+
},
|
|
339
|
+
];
|
|
340
|
+
}
|
|
341
|
+
$.$mol_dev_format_native = $mol_dev_format_native;
|
|
342
|
+
function $mol_dev_format_auto(obj) {
|
|
343
|
+
if (obj == null)
|
|
344
|
+
return $.$mol_dev_format_shade(String(obj));
|
|
345
|
+
if (typeof obj === 'object' && $.$mol_dev_format_head in obj) {
|
|
346
|
+
return obj[$.$mol_dev_format_head]();
|
|
347
|
+
}
|
|
348
|
+
return [
|
|
349
|
+
'object',
|
|
350
|
+
{
|
|
351
|
+
object: obj,
|
|
352
|
+
config: false,
|
|
353
|
+
},
|
|
354
|
+
];
|
|
355
|
+
}
|
|
356
|
+
$.$mol_dev_format_auto = $mol_dev_format_auto;
|
|
357
|
+
function $mol_dev_format_element(element, style, ...content) {
|
|
358
|
+
const styles = [];
|
|
359
|
+
for (let key in style)
|
|
360
|
+
styles.push(`${key} : ${style[key]}`);
|
|
361
|
+
return [
|
|
362
|
+
element,
|
|
363
|
+
{
|
|
364
|
+
style: styles.join(' ; '),
|
|
365
|
+
},
|
|
366
|
+
...content,
|
|
367
|
+
];
|
|
368
|
+
}
|
|
369
|
+
$.$mol_dev_format_element = $mol_dev_format_element;
|
|
370
|
+
function $mol_dev_format_span(style, ...content) {
|
|
371
|
+
return $mol_dev_format_element('span', {
|
|
372
|
+
'vertical-align': '8%',
|
|
373
|
+
...style,
|
|
374
|
+
}, ...content);
|
|
375
|
+
}
|
|
376
|
+
$.$mol_dev_format_span = $mol_dev_format_span;
|
|
377
|
+
$.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
|
|
378
|
+
$.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
|
|
379
|
+
$.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
|
|
380
|
+
$.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
|
|
381
|
+
$.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
|
|
382
|
+
$.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
|
|
383
|
+
$.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
|
|
384
|
+
'color': 'magenta',
|
|
385
|
+
});
|
|
386
|
+
$.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
|
|
387
|
+
'font-weight': 'bold',
|
|
388
|
+
});
|
|
389
|
+
$.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
|
|
390
|
+
'color': 'green',
|
|
391
|
+
});
|
|
392
|
+
$.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
|
|
393
|
+
'color': 'gray',
|
|
394
|
+
});
|
|
395
|
+
$.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
|
|
396
|
+
'margin-left': '13px'
|
|
397
|
+
});
|
|
398
|
+
})($ || ($ = {}));
|
|
399
|
+
//mol/dev/format/format.ts
|
|
400
|
+
;
|
|
401
|
+
"use strict";
|
|
402
|
+
var $;
|
|
403
|
+
(function ($) {
|
|
404
|
+
class $mol_wire_pub_sub extends $mol_wire_pub {
|
|
405
|
+
pub_from = 0;
|
|
406
|
+
cursor = $mol_wire_cursor.stale;
|
|
407
|
+
get temp() {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
get pub_list() {
|
|
411
|
+
const res = [];
|
|
412
|
+
const max = this.cursor >= 0 ? this.cursor : this.sub_from;
|
|
413
|
+
for (let i = this.pub_from; i < max; i += 2) {
|
|
414
|
+
if (this.data[i])
|
|
415
|
+
res.push(this.data[i]);
|
|
416
|
+
}
|
|
417
|
+
return res;
|
|
418
|
+
}
|
|
419
|
+
track_on() {
|
|
420
|
+
this.cursor = this.pub_from;
|
|
421
|
+
const sub = $mol_wire_auto();
|
|
422
|
+
$mol_wire_auto(this);
|
|
423
|
+
return sub;
|
|
424
|
+
}
|
|
425
|
+
promote() {
|
|
426
|
+
if (this.cursor >= this.pub_from) {
|
|
427
|
+
$mol_fail(new Error('Circular subscription'));
|
|
428
|
+
}
|
|
429
|
+
super.promote();
|
|
430
|
+
}
|
|
431
|
+
track_next(pub) {
|
|
432
|
+
if (this.cursor < 0)
|
|
433
|
+
$mol_fail(new Error('Promo to non begun sub'));
|
|
434
|
+
if (this.cursor < this.sub_from) {
|
|
435
|
+
const next = this.data[this.cursor];
|
|
436
|
+
if (pub === undefined)
|
|
437
|
+
return next ?? null;
|
|
438
|
+
if (next === pub) {
|
|
439
|
+
this.cursor += 2;
|
|
440
|
+
return next;
|
|
441
|
+
}
|
|
442
|
+
if (next) {
|
|
443
|
+
if (this.sub_from < this.data.length) {
|
|
444
|
+
this.peer_move(this.sub_from, this.data.length);
|
|
445
|
+
}
|
|
446
|
+
this.peer_move(this.cursor, this.sub_from);
|
|
447
|
+
this.sub_from += 2;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
if (pub === undefined)
|
|
452
|
+
return null;
|
|
453
|
+
if (this.sub_from < this.data.length) {
|
|
454
|
+
this.peer_move(this.sub_from, this.data.length);
|
|
455
|
+
}
|
|
456
|
+
this.sub_from += 2;
|
|
457
|
+
}
|
|
458
|
+
this.data[this.cursor] = pub;
|
|
459
|
+
this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
|
|
460
|
+
this.cursor += 2;
|
|
461
|
+
return pub;
|
|
462
|
+
}
|
|
463
|
+
track_off(sub) {
|
|
464
|
+
$mol_wire_auto(sub);
|
|
465
|
+
if (this.cursor < 0) {
|
|
466
|
+
$mol_fail(new Error('End of non begun sub'));
|
|
467
|
+
}
|
|
468
|
+
for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
|
|
469
|
+
const pub = this.data[cursor];
|
|
470
|
+
pub.fresh();
|
|
471
|
+
}
|
|
472
|
+
this.cursor = $mol_wire_cursor.fresh;
|
|
473
|
+
}
|
|
474
|
+
pub_off(sub_pos) {
|
|
475
|
+
this.data[sub_pos] = undefined;
|
|
476
|
+
this.data[sub_pos + 1] = undefined;
|
|
477
|
+
}
|
|
478
|
+
destructor() {
|
|
479
|
+
for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
|
|
480
|
+
const sub = this.data[cursor];
|
|
481
|
+
const pos = this.data[cursor + 1];
|
|
482
|
+
sub.pub_off(pos);
|
|
483
|
+
this.data.pop();
|
|
484
|
+
this.data.pop();
|
|
485
|
+
}
|
|
486
|
+
this.cursor = this.pub_from;
|
|
487
|
+
this.track_cut();
|
|
488
|
+
this.cursor = $mol_wire_cursor.final;
|
|
489
|
+
}
|
|
490
|
+
track_cut() {
|
|
491
|
+
if (this.cursor < this.pub_from) {
|
|
492
|
+
$mol_fail(new Error('Cut of non begun sub'));
|
|
493
|
+
}
|
|
494
|
+
let tail = 0;
|
|
495
|
+
for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
|
|
496
|
+
const pub = this.data[cursor];
|
|
497
|
+
pub?.sub_off(this.data[cursor + 1]);
|
|
498
|
+
if (this.sub_from < this.data.length) {
|
|
499
|
+
this.peer_move(this.data.length - 2, cursor);
|
|
500
|
+
this.data.pop();
|
|
501
|
+
this.data.pop();
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
++tail;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
for (; tail; --tail) {
|
|
508
|
+
this.data.pop();
|
|
509
|
+
this.data.pop();
|
|
510
|
+
}
|
|
511
|
+
this.sub_from = this.cursor;
|
|
512
|
+
}
|
|
513
|
+
complete() { }
|
|
514
|
+
complete_pubs() {
|
|
515
|
+
const limit = this.cursor < 0 ? this.sub_from : this.cursor;
|
|
516
|
+
for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
|
|
517
|
+
const pub = this.data[cursor];
|
|
518
|
+
pub?.complete();
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
absorb(quant = $mol_wire_cursor.stale) {
|
|
522
|
+
if (this.cursor === $mol_wire_cursor.final)
|
|
523
|
+
return;
|
|
524
|
+
if (this.cursor >= quant)
|
|
525
|
+
return;
|
|
526
|
+
this.cursor = quant;
|
|
527
|
+
this.emit($mol_wire_cursor.doubt);
|
|
528
|
+
}
|
|
529
|
+
[$mol_dev_format_head]() {
|
|
530
|
+
return $mol_dev_format_native(this);
|
|
531
|
+
}
|
|
532
|
+
get pub_empty() {
|
|
533
|
+
return this.sub_from === this.pub_from;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
$.$mol_wire_pub_sub = $mol_wire_pub_sub;
|
|
537
|
+
})($ || ($ = {}));
|
|
538
|
+
//mol/wire/pub/sub/sub.ts
|
|
539
|
+
;
|
|
540
|
+
"use strict";
|
|
541
|
+
var $;
|
|
542
|
+
(function ($) {
|
|
543
|
+
class $mol_after_timeout extends $mol_object2 {
|
|
544
|
+
delay;
|
|
545
|
+
task;
|
|
546
|
+
id;
|
|
547
|
+
constructor(delay, task) {
|
|
548
|
+
super();
|
|
549
|
+
this.delay = delay;
|
|
550
|
+
this.task = task;
|
|
551
|
+
this.id = setTimeout(task, delay);
|
|
552
|
+
}
|
|
553
|
+
destructor() {
|
|
554
|
+
clearTimeout(this.id);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
$.$mol_after_timeout = $mol_after_timeout;
|
|
558
|
+
})($ || ($ = {}));
|
|
559
|
+
//mol/after/timeout/timeout.ts
|
|
560
|
+
;
|
|
561
|
+
"use strict";
|
|
562
|
+
var $;
|
|
563
|
+
(function ($) {
|
|
564
|
+
class $mol_after_frame extends $mol_after_timeout {
|
|
565
|
+
task;
|
|
566
|
+
constructor(task) {
|
|
567
|
+
super(16, task);
|
|
568
|
+
this.task = task;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
$.$mol_after_frame = $mol_after_frame;
|
|
572
|
+
})($ || ($ = {}));
|
|
573
|
+
//mol/after/frame/frame.node.ts
|
|
574
|
+
;
|
|
575
|
+
"use strict";
|
|
576
|
+
var $;
|
|
577
|
+
(function ($) {
|
|
578
|
+
function $mol_promise_like(val) {
|
|
579
|
+
return val && typeof val.then === 'function';
|
|
580
|
+
}
|
|
581
|
+
$.$mol_promise_like = $mol_promise_like;
|
|
582
|
+
})($ || ($ = {}));
|
|
583
|
+
//mol/promise/like/like.ts
|
|
584
|
+
;
|
|
585
|
+
"use strict";
|
|
586
|
+
var $;
|
|
587
|
+
(function ($) {
|
|
588
|
+
const handled = new WeakSet();
|
|
589
|
+
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
|
590
|
+
task;
|
|
591
|
+
host;
|
|
592
|
+
static warm = true;
|
|
593
|
+
static planning = new Set();
|
|
594
|
+
static reaping = new Set();
|
|
595
|
+
static plan_task = null;
|
|
596
|
+
static plan() {
|
|
597
|
+
if (this.plan_task)
|
|
598
|
+
return;
|
|
599
|
+
this.plan_task = new $mol_after_frame(() => {
|
|
600
|
+
try {
|
|
601
|
+
this.sync();
|
|
602
|
+
}
|
|
603
|
+
finally {
|
|
604
|
+
$mol_wire_fiber.plan_task = null;
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
static sync() {
|
|
609
|
+
while (this.planning.size) {
|
|
610
|
+
for (const fiber of this.planning) {
|
|
611
|
+
this.planning.delete(fiber);
|
|
612
|
+
if (fiber.cursor >= 0)
|
|
613
|
+
continue;
|
|
614
|
+
if (fiber.cursor === $mol_wire_cursor.final)
|
|
615
|
+
continue;
|
|
616
|
+
fiber.fresh();
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
while (this.reaping.size) {
|
|
620
|
+
const fibers = this.reaping;
|
|
621
|
+
this.reaping = new Set;
|
|
622
|
+
for (const fiber of fibers) {
|
|
623
|
+
if (!fiber.sub_empty)
|
|
624
|
+
continue;
|
|
625
|
+
fiber.destructor();
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
[Symbol.toStringTag];
|
|
630
|
+
cache = undefined;
|
|
631
|
+
get args() {
|
|
632
|
+
return this.data.slice(0, this.pub_from);
|
|
633
|
+
}
|
|
634
|
+
result() {
|
|
635
|
+
if ($mol_promise_like(this.cache))
|
|
636
|
+
return;
|
|
637
|
+
if (this.cache instanceof Error)
|
|
638
|
+
return;
|
|
639
|
+
return this.cache;
|
|
640
|
+
}
|
|
641
|
+
field() {
|
|
642
|
+
return this.task.name + '()';
|
|
643
|
+
}
|
|
644
|
+
constructor(id, task, host, args) {
|
|
645
|
+
super();
|
|
646
|
+
this.task = task;
|
|
647
|
+
this.host = host;
|
|
648
|
+
if (args)
|
|
649
|
+
this.data.push(...args);
|
|
650
|
+
this.pub_from = this.sub_from = args?.length ?? 0;
|
|
651
|
+
this[Symbol.toStringTag] = id;
|
|
652
|
+
}
|
|
653
|
+
plan() {
|
|
654
|
+
$mol_wire_fiber.planning.add(this);
|
|
655
|
+
$mol_wire_fiber.plan();
|
|
656
|
+
}
|
|
657
|
+
reap() {
|
|
658
|
+
$mol_wire_fiber.reaping.add(this);
|
|
659
|
+
$mol_wire_fiber.plan();
|
|
660
|
+
}
|
|
661
|
+
toString() {
|
|
662
|
+
return this[Symbol.toStringTag];
|
|
663
|
+
}
|
|
664
|
+
toJSON() {
|
|
665
|
+
return this[Symbol.toStringTag];
|
|
666
|
+
}
|
|
667
|
+
[$mol_dev_format_head]() {
|
|
668
|
+
const cursor = {
|
|
669
|
+
[$mol_wire_cursor.stale]: '🔴',
|
|
670
|
+
[$mol_wire_cursor.doubt]: '🟡',
|
|
671
|
+
[$mol_wire_cursor.fresh]: '🟢',
|
|
672
|
+
[$mol_wire_cursor.final]: '🔵',
|
|
673
|
+
}[this.cursor] ?? this.cursor.toString();
|
|
674
|
+
return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(cursor + ' '), $mol_dev_format_auto(this.cache));
|
|
675
|
+
}
|
|
676
|
+
get $() {
|
|
677
|
+
return (this.host ?? this.task)['$'];
|
|
678
|
+
}
|
|
679
|
+
emit(quant = $mol_wire_cursor.stale) {
|
|
680
|
+
if (this.sub_empty)
|
|
681
|
+
this.plan();
|
|
682
|
+
else
|
|
683
|
+
super.emit(quant);
|
|
684
|
+
}
|
|
685
|
+
fresh() {
|
|
686
|
+
if (this.cursor === $mol_wire_cursor.fresh)
|
|
687
|
+
return;
|
|
688
|
+
if (this.cursor === $mol_wire_cursor.final)
|
|
689
|
+
return;
|
|
690
|
+
check: if (this.cursor === $mol_wire_cursor.doubt) {
|
|
691
|
+
for (let i = this.pub_from; i < this.sub_from; i += 2) {
|
|
692
|
+
;
|
|
693
|
+
this.data[i]?.fresh();
|
|
694
|
+
if (this.cursor !== $mol_wire_cursor.doubt)
|
|
695
|
+
break check;
|
|
696
|
+
}
|
|
697
|
+
this.cursor = $mol_wire_cursor.fresh;
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
const bu = this.track_on();
|
|
701
|
+
let result;
|
|
702
|
+
try {
|
|
703
|
+
switch (this.pub_from) {
|
|
704
|
+
case 0:
|
|
705
|
+
result = this.task.call(this.host);
|
|
706
|
+
break;
|
|
707
|
+
case 1:
|
|
708
|
+
result = this.task.call(this.host, this.data[0]);
|
|
709
|
+
break;
|
|
710
|
+
default:
|
|
711
|
+
result = this.task.call(this.host, ...this.args);
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
if ($mol_promise_like(result)) {
|
|
715
|
+
const put = (res) => {
|
|
716
|
+
if (this.cache === result)
|
|
717
|
+
this.put(res);
|
|
718
|
+
return res;
|
|
719
|
+
};
|
|
720
|
+
result = Object.assign(result.then(put, put), {
|
|
721
|
+
destructor: result['destructor'] ?? (() => { })
|
|
722
|
+
});
|
|
723
|
+
handled.add(result);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
catch (error) {
|
|
727
|
+
if (error instanceof Error || $mol_promise_like(error)) {
|
|
728
|
+
result = error;
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
result = new Error(String(error), { cause: error });
|
|
732
|
+
}
|
|
733
|
+
if ($mol_promise_like(result) && !handled.has(result)) {
|
|
734
|
+
result = Object.assign(result.finally(() => {
|
|
735
|
+
if (this.cache === result)
|
|
736
|
+
this.absorb();
|
|
737
|
+
}), {
|
|
738
|
+
destructor: result['destructor'] ?? (() => { })
|
|
739
|
+
});
|
|
740
|
+
handled.add(result);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
if (!$mol_promise_like(result)) {
|
|
744
|
+
this.track_cut();
|
|
745
|
+
}
|
|
746
|
+
this.track_off(bu);
|
|
747
|
+
this.put(result);
|
|
748
|
+
}
|
|
749
|
+
refresh() {
|
|
750
|
+
this.cursor = $mol_wire_cursor.stale;
|
|
751
|
+
this.fresh();
|
|
752
|
+
}
|
|
753
|
+
sync() {
|
|
754
|
+
if (!$mol_wire_fiber.warm) {
|
|
755
|
+
return this.result();
|
|
756
|
+
}
|
|
757
|
+
this.promote();
|
|
758
|
+
this.fresh();
|
|
759
|
+
if (this.cache instanceof Error) {
|
|
760
|
+
return $mol_fail_hidden(this.cache);
|
|
761
|
+
}
|
|
762
|
+
if ($mol_promise_like(this.cache)) {
|
|
763
|
+
return $mol_fail_hidden(this.cache);
|
|
764
|
+
}
|
|
765
|
+
return this.cache;
|
|
766
|
+
}
|
|
767
|
+
async async() {
|
|
768
|
+
while (true) {
|
|
769
|
+
this.fresh();
|
|
770
|
+
if (this.cache instanceof Error) {
|
|
771
|
+
$mol_fail_hidden(this.cache);
|
|
772
|
+
}
|
|
773
|
+
if (!$mol_promise_like(this.cache))
|
|
774
|
+
return this.cache;
|
|
775
|
+
await this.cache;
|
|
776
|
+
if (this.cursor === $mol_wire_cursor.final) {
|
|
777
|
+
await new Promise(() => { });
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
$.$mol_wire_fiber = $mol_wire_fiber;
|
|
783
|
+
})($ || ($ = {}));
|
|
784
|
+
//mol/wire/fiber/fiber.ts
|
|
785
|
+
;
|
|
786
|
+
"use strict";
|
|
787
|
+
var $;
|
|
788
|
+
(function ($) {
|
|
789
|
+
const named = new WeakSet();
|
|
790
|
+
function $mol_func_name(func) {
|
|
791
|
+
let name = func.name;
|
|
792
|
+
if (name?.length > 1)
|
|
793
|
+
return name;
|
|
794
|
+
if (named.has(func))
|
|
795
|
+
return name;
|
|
796
|
+
for (let key in this) {
|
|
797
|
+
try {
|
|
798
|
+
if (this[key] !== func)
|
|
799
|
+
continue;
|
|
800
|
+
name = key;
|
|
801
|
+
Object.defineProperty(func, 'name', { value: name });
|
|
802
|
+
break;
|
|
803
|
+
}
|
|
804
|
+
catch { }
|
|
805
|
+
}
|
|
806
|
+
named.add(func);
|
|
807
|
+
return name;
|
|
808
|
+
}
|
|
809
|
+
$.$mol_func_name = $mol_func_name;
|
|
810
|
+
function $mol_func_name_from(target, source) {
|
|
811
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
|
812
|
+
return target;
|
|
813
|
+
}
|
|
814
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
|
815
|
+
})($ || ($ = {}));
|
|
816
|
+
//mol/func/name/name.ts
|
|
817
|
+
;
|
|
818
|
+
"use strict";
|
|
819
|
+
var $;
|
|
820
|
+
(function ($) {
|
|
821
|
+
function $mol_guid(length = 8, exists = () => false) {
|
|
822
|
+
for (;;) {
|
|
823
|
+
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
824
|
+
if (exists(id))
|
|
825
|
+
continue;
|
|
826
|
+
return id;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
$.$mol_guid = $mol_guid;
|
|
830
|
+
})($ || ($ = {}));
|
|
831
|
+
//mol/guid/guid.ts
|
|
832
|
+
;
|
|
833
|
+
"use strict";
|
|
834
|
+
var $;
|
|
835
|
+
(function ($) {
|
|
836
|
+
$.$mol_key_store = new WeakMap();
|
|
837
|
+
function $mol_key(value) {
|
|
838
|
+
if (!value)
|
|
839
|
+
return JSON.stringify(value);
|
|
840
|
+
if (typeof value !== 'object' && typeof value !== 'function')
|
|
841
|
+
return JSON.stringify(value);
|
|
842
|
+
return JSON.stringify(value, (field, value) => {
|
|
843
|
+
if (!value)
|
|
844
|
+
return value;
|
|
845
|
+
if (typeof value !== 'object' && typeof value !== 'function')
|
|
846
|
+
return value;
|
|
847
|
+
if (Array.isArray(value))
|
|
848
|
+
return value;
|
|
849
|
+
const proto = Reflect.getPrototypeOf(value);
|
|
850
|
+
if (!proto)
|
|
851
|
+
return value;
|
|
852
|
+
if (Reflect.getPrototypeOf(proto) === null)
|
|
853
|
+
return value;
|
|
854
|
+
if ('toJSON' in value)
|
|
855
|
+
return value;
|
|
856
|
+
if (value instanceof RegExp)
|
|
857
|
+
return value.toString();
|
|
858
|
+
let key = $.$mol_key_store.get(value);
|
|
859
|
+
if (key)
|
|
860
|
+
return key;
|
|
861
|
+
key = $mol_guid();
|
|
862
|
+
$.$mol_key_store.set(value, key);
|
|
863
|
+
return key;
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
$.$mol_key = $mol_key;
|
|
867
|
+
})($ || ($ = {}));
|
|
868
|
+
//mol/key/key.ts
|
|
869
|
+
;
|
|
870
|
+
"use strict";
|
|
871
|
+
var $;
|
|
872
|
+
(function ($) {
|
|
873
|
+
$.$mol_compare_deep_cache = new WeakMap();
|
|
874
|
+
function $mol_compare_deep(left, right) {
|
|
875
|
+
if (Object.is(left, right))
|
|
876
|
+
return true;
|
|
877
|
+
if (left === null)
|
|
878
|
+
return false;
|
|
879
|
+
if (right === null)
|
|
880
|
+
return false;
|
|
881
|
+
if (typeof left !== 'object')
|
|
882
|
+
return false;
|
|
883
|
+
if (typeof right !== 'object')
|
|
884
|
+
return false;
|
|
885
|
+
const left_proto = Reflect.getPrototypeOf(left);
|
|
886
|
+
const right_proto = Reflect.getPrototypeOf(right);
|
|
887
|
+
if (left_proto !== right_proto)
|
|
888
|
+
return false;
|
|
889
|
+
if (left instanceof Boolean)
|
|
890
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
891
|
+
if (left instanceof Number)
|
|
892
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
893
|
+
if (left instanceof String)
|
|
894
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
895
|
+
if (left instanceof Date)
|
|
896
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
897
|
+
if (left instanceof RegExp)
|
|
898
|
+
return left.source === right.source && left.flags === right.flags;
|
|
899
|
+
if (left instanceof Error)
|
|
900
|
+
return left.message === right.message && left.stack === right.stack;
|
|
901
|
+
let left_cache = $.$mol_compare_deep_cache.get(left);
|
|
902
|
+
if (left_cache) {
|
|
903
|
+
const right_cache = left_cache.get(right);
|
|
904
|
+
if (typeof right_cache === 'boolean')
|
|
905
|
+
return right_cache;
|
|
906
|
+
}
|
|
907
|
+
else {
|
|
908
|
+
left_cache = new WeakMap([[right, true]]);
|
|
909
|
+
$.$mol_compare_deep_cache.set(left, left_cache);
|
|
910
|
+
}
|
|
911
|
+
let result;
|
|
912
|
+
try {
|
|
913
|
+
if (!left_proto)
|
|
914
|
+
result = compare_pojo(left, right);
|
|
915
|
+
else if (!Reflect.getPrototypeOf(left_proto))
|
|
916
|
+
result = compare_pojo(left, right);
|
|
917
|
+
else if (Array.isArray(left))
|
|
918
|
+
result = compare_array(left, right);
|
|
919
|
+
else if (left instanceof Set)
|
|
920
|
+
result = compare_set(left, right);
|
|
921
|
+
else if (left instanceof Map)
|
|
922
|
+
result = compare_map(left, right);
|
|
923
|
+
else if (ArrayBuffer.isView(left))
|
|
924
|
+
result = compare_buffer(left, right);
|
|
925
|
+
else if (Symbol.toPrimitive in left)
|
|
926
|
+
result = compare_primitive(left, right);
|
|
927
|
+
else
|
|
928
|
+
result = false;
|
|
929
|
+
}
|
|
930
|
+
finally {
|
|
931
|
+
left_cache.set(right, result);
|
|
932
|
+
}
|
|
933
|
+
return result;
|
|
934
|
+
}
|
|
935
|
+
$.$mol_compare_deep = $mol_compare_deep;
|
|
936
|
+
function compare_array(left, right) {
|
|
937
|
+
const len = left.length;
|
|
938
|
+
if (len !== right.length)
|
|
939
|
+
return false;
|
|
940
|
+
for (let i = 0; i < len; ++i) {
|
|
941
|
+
if (!$mol_compare_deep(left[i], right[i]))
|
|
942
|
+
return false;
|
|
943
|
+
}
|
|
944
|
+
return true;
|
|
945
|
+
}
|
|
946
|
+
function compare_buffer(left, right) {
|
|
947
|
+
const len = left.byteLength;
|
|
948
|
+
if (len !== right.byteLength)
|
|
949
|
+
return false;
|
|
950
|
+
for (let i = 0; i < len; ++i) {
|
|
951
|
+
if (left[i] !== right[i])
|
|
952
|
+
return false;
|
|
953
|
+
}
|
|
954
|
+
return true;
|
|
955
|
+
}
|
|
956
|
+
function compare_iterator(left, right) {
|
|
957
|
+
while (true) {
|
|
958
|
+
const left_next = left.next();
|
|
959
|
+
const right_next = right.next();
|
|
960
|
+
if (left_next.done !== right_next.done)
|
|
961
|
+
return false;
|
|
962
|
+
if (left_next.done)
|
|
963
|
+
break;
|
|
964
|
+
if (!$mol_compare_deep(left_next.value, right_next.value))
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
return true;
|
|
968
|
+
}
|
|
969
|
+
function compare_set(left, right) {
|
|
970
|
+
if (left.size !== right.size)
|
|
971
|
+
return false;
|
|
972
|
+
return compare_iterator(left.values(), right.values());
|
|
973
|
+
}
|
|
974
|
+
function compare_map(left, right) {
|
|
975
|
+
if (left.size !== right.size)
|
|
976
|
+
return false;
|
|
977
|
+
return compare_iterator(left.keys(), right.keys())
|
|
978
|
+
&& compare_iterator(left.values(), right.values());
|
|
979
|
+
}
|
|
980
|
+
function compare_pojo(left, right) {
|
|
981
|
+
const left_keys = Object.getOwnPropertyNames(left);
|
|
982
|
+
const right_keys = Object.getOwnPropertyNames(right);
|
|
983
|
+
if (!compare_array(left_keys, right_keys))
|
|
984
|
+
return false;
|
|
985
|
+
for (let key of left_keys) {
|
|
986
|
+
if (!$mol_compare_deep(left[key], right[key]))
|
|
987
|
+
return false;
|
|
988
|
+
}
|
|
989
|
+
const left_syms = Object.getOwnPropertySymbols(left);
|
|
990
|
+
const right_syms = Object.getOwnPropertySymbols(right);
|
|
991
|
+
if (!compare_array(left_syms, right_syms))
|
|
992
|
+
return false;
|
|
993
|
+
for (let key of left_syms) {
|
|
994
|
+
if (!$mol_compare_deep(left[key], right[key]))
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
return true;
|
|
998
|
+
}
|
|
999
|
+
function compare_primitive(left, right) {
|
|
1000
|
+
return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
|
|
1001
|
+
}
|
|
1002
|
+
})($ || ($ = {}));
|
|
1003
|
+
//mol/compare/deep/deep.ts
|
|
1004
|
+
;
|
|
1005
|
+
"use strict";
|
|
1006
|
+
var $;
|
|
1007
|
+
(function ($) {
|
|
1008
|
+
class $mol_wire_task extends $mol_wire_fiber {
|
|
1009
|
+
static getter(task) {
|
|
1010
|
+
return function $mol_wire_task_get(host, args) {
|
|
1011
|
+
const sub = $mol_wire_auto();
|
|
1012
|
+
const existen = sub?.track_next();
|
|
1013
|
+
reuse: if (existen) {
|
|
1014
|
+
if (!existen.temp)
|
|
1015
|
+
break reuse;
|
|
1016
|
+
if (existen.host !== host)
|
|
1017
|
+
break reuse;
|
|
1018
|
+
if (existen.task !== task)
|
|
1019
|
+
break reuse;
|
|
1020
|
+
if (!$mol_compare_deep(existen.args, args))
|
|
1021
|
+
break reuse;
|
|
1022
|
+
return existen;
|
|
1023
|
+
}
|
|
1024
|
+
return new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, args);
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
get temp() {
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
1030
|
+
complete() {
|
|
1031
|
+
if ($mol_promise_like(this.cache))
|
|
1032
|
+
return;
|
|
1033
|
+
this.destructor();
|
|
1034
|
+
}
|
|
1035
|
+
put(next) {
|
|
1036
|
+
const prev = this.cache;
|
|
1037
|
+
this.cache = next;
|
|
1038
|
+
if ($mol_promise_like(next)) {
|
|
1039
|
+
this.cursor = $mol_wire_cursor.fresh;
|
|
1040
|
+
if (next !== prev)
|
|
1041
|
+
this.emit();
|
|
1042
|
+
return next;
|
|
1043
|
+
}
|
|
1044
|
+
this.cursor = $mol_wire_cursor.final;
|
|
1045
|
+
if (this.sub_empty)
|
|
1046
|
+
this.destructor();
|
|
1047
|
+
else if (next !== prev)
|
|
1048
|
+
this.emit();
|
|
1049
|
+
return next;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
$.$mol_wire_task = $mol_wire_task;
|
|
1053
|
+
})($ || ($ = {}));
|
|
1054
|
+
//mol/wire/task/task.ts
|
|
1055
|
+
;
|
|
1056
|
+
"use strict";
|
|
1057
|
+
var $;
|
|
1058
|
+
(function ($) {
|
|
1059
|
+
function $mol_wire_method(host, field, descr) {
|
|
1060
|
+
if (!descr)
|
|
1061
|
+
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
1062
|
+
const orig = descr?.value ?? host[field];
|
|
1063
|
+
const sup = Reflect.getPrototypeOf(host);
|
|
1064
|
+
if (typeof sup[field] === 'function') {
|
|
1065
|
+
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
|
1066
|
+
}
|
|
1067
|
+
const temp = $mol_wire_task.getter(orig);
|
|
1068
|
+
const value = function (...args) {
|
|
1069
|
+
const fiber = temp(this ?? null, args);
|
|
1070
|
+
return fiber.sync();
|
|
1071
|
+
};
|
|
1072
|
+
Object.defineProperty(value, 'name', { value: orig.name + ' ' });
|
|
1073
|
+
Object.assign(value, { orig });
|
|
1074
|
+
const descr2 = { ...descr, value };
|
|
1075
|
+
Reflect.defineProperty(host, field, descr2);
|
|
1076
|
+
return descr2;
|
|
1077
|
+
}
|
|
1078
|
+
$.$mol_wire_method = $mol_wire_method;
|
|
1079
|
+
})($ || ($ = {}));
|
|
1080
|
+
//mol/wire/method/method.ts
|
|
1081
|
+
;
|
|
1082
|
+
"use strict";
|
|
1083
|
+
//mol/type/tail/tail.ts
|
|
1084
|
+
;
|
|
1085
|
+
"use strict";
|
|
1086
|
+
//mol/type/foot/foot.ts
|
|
1087
|
+
;
|
|
1088
|
+
"use strict";
|
|
1089
|
+
var $;
|
|
1090
|
+
(function ($) {
|
|
1091
|
+
const catched = new WeakMap();
|
|
1092
|
+
function $mol_fail_catch(error) {
|
|
1093
|
+
if (typeof error !== 'object')
|
|
1094
|
+
return false;
|
|
1095
|
+
if ($mol_promise_like(error))
|
|
1096
|
+
$mol_fail_hidden(error);
|
|
1097
|
+
if (catched.get(error))
|
|
1098
|
+
return false;
|
|
1099
|
+
catched.set(error, true);
|
|
1100
|
+
return true;
|
|
1101
|
+
}
|
|
1102
|
+
$.$mol_fail_catch = $mol_fail_catch;
|
|
1103
|
+
})($ || ($ = {}));
|
|
1104
|
+
//mol/fail/catch/catch.ts
|
|
1105
|
+
;
|
|
1106
|
+
"use strict";
|
|
1107
|
+
var $;
|
|
1108
|
+
(function ($) {
|
|
1109
|
+
function $mol_fail_log(error) {
|
|
1110
|
+
if ($mol_promise_like(error))
|
|
1111
|
+
return false;
|
|
1112
|
+
if (!$mol_fail_catch(error))
|
|
1113
|
+
return false;
|
|
1114
|
+
console.error(error);
|
|
1115
|
+
return true;
|
|
1116
|
+
}
|
|
1117
|
+
$.$mol_fail_log = $mol_fail_log;
|
|
1118
|
+
})($ || ($ = {}));
|
|
1119
|
+
//mol/fail/log/log.ts
|
|
1120
|
+
;
|
|
1121
|
+
"use strict";
|
|
1122
|
+
var $;
|
|
1123
|
+
(function ($) {
|
|
1124
|
+
class $mol_wire_atom extends $mol_wire_fiber {
|
|
1125
|
+
static solo(host, task) {
|
|
1126
|
+
const field = task.name + '()';
|
|
1127
|
+
const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1128
|
+
if (existen)
|
|
1129
|
+
return existen;
|
|
1130
|
+
const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
|
|
1131
|
+
const key = `${prefix}.${field}`;
|
|
1132
|
+
const fiber = new $mol_wire_atom(key, task, host, []);
|
|
1133
|
+
(host ?? task)[field] = fiber;
|
|
1134
|
+
return fiber;
|
|
1135
|
+
}
|
|
1136
|
+
static plex(host, task, key) {
|
|
1137
|
+
const field = task.name + '()';
|
|
1138
|
+
let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1139
|
+
const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
|
|
1140
|
+
const id = `${prefix}.${task.name}(${$mol_key(key)})`;
|
|
1141
|
+
if (dict) {
|
|
1142
|
+
const existen = dict.get(id);
|
|
1143
|
+
if (existen)
|
|
1144
|
+
return existen;
|
|
1145
|
+
}
|
|
1146
|
+
else {
|
|
1147
|
+
dict = (host ?? task)[field] = new Map();
|
|
1148
|
+
}
|
|
1149
|
+
const fiber = new $mol_wire_atom(id, task, host, [key]);
|
|
1150
|
+
dict.set(id, fiber);
|
|
1151
|
+
return fiber;
|
|
1152
|
+
}
|
|
1153
|
+
static watching = new Set();
|
|
1154
|
+
static watcher = null;
|
|
1155
|
+
static watch() {
|
|
1156
|
+
$mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
|
|
1157
|
+
for (const atom of $mol_wire_atom.watching) {
|
|
1158
|
+
if (atom.cursor === $mol_wire_cursor.final) {
|
|
1159
|
+
$mol_wire_atom.watching.delete(atom);
|
|
1160
|
+
}
|
|
1161
|
+
else {
|
|
1162
|
+
atom.cursor = $mol_wire_cursor.stale;
|
|
1163
|
+
atom.fresh();
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
watch() {
|
|
1168
|
+
if (!$mol_wire_atom.watcher) {
|
|
1169
|
+
$mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
|
|
1170
|
+
}
|
|
1171
|
+
$mol_wire_atom.watching.add(this);
|
|
1172
|
+
}
|
|
1173
|
+
resync(args) {
|
|
1174
|
+
return this.put(this.task.call(this.host, ...args));
|
|
1175
|
+
}
|
|
1176
|
+
once() {
|
|
1177
|
+
return this.sync();
|
|
1178
|
+
}
|
|
1179
|
+
channel() {
|
|
1180
|
+
return Object.assign((next) => {
|
|
1181
|
+
if (next !== undefined)
|
|
1182
|
+
return this.resync([...this.args, next]);
|
|
1183
|
+
if (!$mol_wire_fiber.warm)
|
|
1184
|
+
return this.result();
|
|
1185
|
+
if ($mol_wire_auto()?.temp) {
|
|
1186
|
+
return this.once();
|
|
1187
|
+
}
|
|
1188
|
+
else {
|
|
1189
|
+
return this.sync();
|
|
1190
|
+
}
|
|
1191
|
+
}, { atom: this });
|
|
1192
|
+
}
|
|
1193
|
+
destructor() {
|
|
1194
|
+
super.destructor();
|
|
1195
|
+
const prev = this.cache;
|
|
1196
|
+
if ($mol_owning_check(this, prev)) {
|
|
1197
|
+
prev.destructor();
|
|
1198
|
+
}
|
|
1199
|
+
if (this.pub_from === 0) {
|
|
1200
|
+
;
|
|
1201
|
+
(this.host ?? this.task)[this.field()] = null;
|
|
1202
|
+
}
|
|
1203
|
+
else {
|
|
1204
|
+
;
|
|
1205
|
+
(this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
put(next) {
|
|
1209
|
+
const prev = this.cache;
|
|
1210
|
+
update: if (next !== prev) {
|
|
1211
|
+
try {
|
|
1212
|
+
if ($mol_compare_deep(prev, next))
|
|
1213
|
+
break update;
|
|
1214
|
+
}
|
|
1215
|
+
catch (error) {
|
|
1216
|
+
$mol_fail_log(error);
|
|
1217
|
+
}
|
|
1218
|
+
if ($mol_owning_check(this, prev)) {
|
|
1219
|
+
prev.destructor();
|
|
1220
|
+
}
|
|
1221
|
+
if ($mol_owning_catch(this, next)) {
|
|
1222
|
+
try {
|
|
1223
|
+
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
1224
|
+
}
|
|
1225
|
+
catch {
|
|
1226
|
+
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
if (!this.sub_empty)
|
|
1230
|
+
this.emit();
|
|
1231
|
+
}
|
|
1232
|
+
this.cache = next;
|
|
1233
|
+
this.cursor = $mol_wire_cursor.fresh;
|
|
1234
|
+
if ($mol_promise_like(next))
|
|
1235
|
+
return next;
|
|
1236
|
+
this.complete_pubs();
|
|
1237
|
+
return next;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
__decorate([
|
|
1241
|
+
$mol_wire_method
|
|
1242
|
+
], $mol_wire_atom.prototype, "resync", null);
|
|
1243
|
+
__decorate([
|
|
1244
|
+
$mol_wire_method
|
|
1245
|
+
], $mol_wire_atom.prototype, "once", null);
|
|
1246
|
+
$.$mol_wire_atom = $mol_wire_atom;
|
|
1247
|
+
})($ || ($ = {}));
|
|
1248
|
+
//mol/wire/atom/atom.ts
|
|
1249
|
+
;
|
|
1250
|
+
"use strict";
|
|
1251
|
+
var $;
|
|
1252
|
+
(function ($) {
|
|
1253
|
+
function $mol_wire_solo(host, field, descr) {
|
|
1254
|
+
if (!descr)
|
|
1255
|
+
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
1256
|
+
const orig = descr?.value ?? host[field];
|
|
1257
|
+
const sup = Reflect.getPrototypeOf(host);
|
|
1258
|
+
if (typeof sup[field] === 'function') {
|
|
1259
|
+
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
|
1260
|
+
}
|
|
1261
|
+
const descr2 = {
|
|
1262
|
+
...descr,
|
|
1263
|
+
value: function (...args) {
|
|
1264
|
+
let atom = $mol_wire_atom.solo(this, orig);
|
|
1265
|
+
if ((args.length === 0) || (args[0] === undefined)) {
|
|
1266
|
+
if (!$mol_wire_fiber.warm)
|
|
1267
|
+
return atom.result();
|
|
1268
|
+
if ($mol_wire_auto()?.temp) {
|
|
1269
|
+
return atom.once();
|
|
1270
|
+
}
|
|
1271
|
+
else {
|
|
1272
|
+
return atom.sync();
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
return atom.resync(args);
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
|
|
1279
|
+
Object.assign(descr2.value, { orig });
|
|
1280
|
+
Reflect.defineProperty(host, field, descr2);
|
|
1281
|
+
return descr2;
|
|
1282
|
+
}
|
|
1283
|
+
$.$mol_wire_solo = $mol_wire_solo;
|
|
1284
|
+
})($ || ($ = {}));
|
|
1285
|
+
//mol/wire/solo/solo.ts
|
|
1286
|
+
;
|
|
1287
|
+
"use strict";
|
|
1288
|
+
var $;
|
|
1289
|
+
(function ($) {
|
|
1290
|
+
function $mol_wire_plex(host, field, descr) {
|
|
1291
|
+
if (!descr)
|
|
1292
|
+
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
1293
|
+
const orig = descr?.value ?? host[field];
|
|
1294
|
+
const sup = Reflect.getPrototypeOf(host);
|
|
1295
|
+
if (typeof sup[field] === 'function') {
|
|
1296
|
+
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
|
1297
|
+
}
|
|
1298
|
+
const descr2 = {
|
|
1299
|
+
...descr,
|
|
1300
|
+
value: function (...args) {
|
|
1301
|
+
let atom = $mol_wire_atom.plex(this, orig, args[0]);
|
|
1302
|
+
if ((args.length === 1) || (args[1] === undefined)) {
|
|
1303
|
+
if (!$mol_wire_fiber.warm)
|
|
1304
|
+
return atom.result();
|
|
1305
|
+
if ($mol_wire_auto()?.temp) {
|
|
1306
|
+
return atom.once();
|
|
1307
|
+
}
|
|
1308
|
+
else {
|
|
1309
|
+
return atom.sync();
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
return atom.resync(args);
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
|
|
1316
|
+
Object.assign(descr2.value, { orig });
|
|
1317
|
+
Reflect.defineProperty(host, field, descr2);
|
|
1318
|
+
return descr2;
|
|
1319
|
+
}
|
|
1320
|
+
$.$mol_wire_plex = $mol_wire_plex;
|
|
1321
|
+
})($ || ($ = {}));
|
|
1322
|
+
//mol/wire/plex/plex.ts
|
|
1323
|
+
;
|
|
1324
|
+
"use strict";
|
|
1325
|
+
var $;
|
|
1326
|
+
(function ($) {
|
|
1327
|
+
$.$mol_mem = $mol_wire_solo;
|
|
1328
|
+
$.$mol_mem_key = $mol_wire_plex;
|
|
1329
|
+
})($ || ($ = {}));
|
|
1330
|
+
//mol/mem/mem.ts
|
|
1331
|
+
;
|
|
1332
|
+
"use strict";
|
|
1333
|
+
var $;
|
|
1334
|
+
(function ($) {
|
|
1335
|
+
function $mol_wire_sync(obj) {
|
|
1336
|
+
return new Proxy(obj, {
|
|
1337
|
+
get(obj, field) {
|
|
1338
|
+
const val = obj[field];
|
|
1339
|
+
if (typeof val !== 'function')
|
|
1340
|
+
return val;
|
|
1341
|
+
const temp = $mol_wire_task.getter(val);
|
|
1342
|
+
return function $mol_wire_sync(...args) {
|
|
1343
|
+
const fiber = temp(obj, args);
|
|
1344
|
+
return fiber.sync();
|
|
1345
|
+
};
|
|
1346
|
+
},
|
|
1347
|
+
apply(obj, self, args) {
|
|
1348
|
+
const temp = $mol_wire_task.getter(obj);
|
|
1349
|
+
const fiber = temp(self, args);
|
|
1350
|
+
return fiber.sync();
|
|
1351
|
+
},
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
$.$mol_wire_sync = $mol_wire_sync;
|
|
1355
|
+
})($ || ($ = {}));
|
|
1356
|
+
//mol/wire/sync/sync.ts
|
|
1357
|
+
;
|
|
1358
|
+
"use strict";
|
|
1359
|
+
var $;
|
|
1360
|
+
(function ($_1) {
|
|
1361
|
+
let $$;
|
|
1362
|
+
(function ($$) {
|
|
1363
|
+
let $;
|
|
1364
|
+
})($$ = $_1.$$ || ($_1.$$ = {}));
|
|
1365
|
+
$_1.$mol_object_field = Symbol('$mol_object_field');
|
|
1366
|
+
class $mol_object extends $mol_object2 {
|
|
1367
|
+
static make(config) {
|
|
1368
|
+
return super.create(obj => {
|
|
1369
|
+
for (let key in config)
|
|
1370
|
+
obj[key] = config[key];
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
$_1.$mol_object = $mol_object;
|
|
1375
|
+
})($ || ($ = {}));
|
|
1376
|
+
//mol/object/object.ts
|
|
1377
|
+
;
|
|
1378
|
+
"use strict";
|
|
1379
|
+
var $;
|
|
1380
|
+
(function ($) {
|
|
1381
|
+
})($ || ($ = {}));
|
|
1382
|
+
//mol/dom/context/context.ts
|
|
1383
|
+
;
|
|
1384
|
+
"use strict";
|
|
1385
|
+
//node/node.ts
|
|
1386
|
+
;
|
|
1387
|
+
"use strict";
|
|
1388
|
+
var $node = new Proxy({ require }, {
|
|
1389
|
+
get(target, name, wrapper) {
|
|
1390
|
+
if (target[name])
|
|
1391
|
+
return target[name];
|
|
1392
|
+
const mod = target.require('module');
|
|
1393
|
+
if (mod.builtinModules.indexOf(name) >= 0)
|
|
1394
|
+
return target.require(name);
|
|
1395
|
+
if (name[0] === '.')
|
|
1396
|
+
return target.require(name);
|
|
1397
|
+
const path = target.require('path');
|
|
1398
|
+
const fs = target.require('fs');
|
|
1399
|
+
let dir = path.resolve('.');
|
|
1400
|
+
const suffix = `./node_modules/${name}`;
|
|
1401
|
+
const $$ = $;
|
|
1402
|
+
while (!fs.existsSync(path.join(dir, suffix))) {
|
|
1403
|
+
const parent = path.resolve(dir, '..');
|
|
1404
|
+
if (parent === dir) {
|
|
1405
|
+
$$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
|
|
1406
|
+
try {
|
|
1407
|
+
$$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
|
|
1408
|
+
}
|
|
1409
|
+
catch { }
|
|
1410
|
+
break;
|
|
1411
|
+
}
|
|
1412
|
+
else {
|
|
1413
|
+
dir = parent;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
return target.require(name);
|
|
1417
|
+
},
|
|
1418
|
+
set(target, name, value) {
|
|
1419
|
+
target[name] = value;
|
|
1420
|
+
return true;
|
|
1421
|
+
},
|
|
1422
|
+
});
|
|
1423
|
+
require = (req => Object.assign(function require(name) {
|
|
1424
|
+
return $node[name];
|
|
1425
|
+
}, req))(require);
|
|
1426
|
+
//node/node.node.ts
|
|
1427
|
+
;
|
|
1428
|
+
"use strict";
|
|
1429
|
+
var $;
|
|
1430
|
+
(function ($) {
|
|
1431
|
+
function $mol_log3_area_lazy(event) {
|
|
1432
|
+
const self = this;
|
|
1433
|
+
const stack = self.$mol_log3_stack;
|
|
1434
|
+
const deep = stack.length;
|
|
1435
|
+
let logged = false;
|
|
1436
|
+
stack.push(() => {
|
|
1437
|
+
logged = true;
|
|
1438
|
+
self.$mol_log3_area.call(self, event);
|
|
1439
|
+
});
|
|
1440
|
+
return () => {
|
|
1441
|
+
if (logged)
|
|
1442
|
+
self.console.groupEnd();
|
|
1443
|
+
if (stack.length > deep)
|
|
1444
|
+
stack.length = deep;
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
1448
|
+
$.$mol_log3_stack = [];
|
|
1449
|
+
})($ || ($ = {}));
|
|
1450
|
+
//mol/log3/log3.ts
|
|
1451
|
+
;
|
|
1452
|
+
"use strict";
|
|
1453
|
+
var $;
|
|
1454
|
+
(function ($) {
|
|
1455
|
+
class $mol_span extends $mol_object2 {
|
|
1456
|
+
uri;
|
|
1457
|
+
source;
|
|
1458
|
+
row;
|
|
1459
|
+
col;
|
|
1460
|
+
length;
|
|
1461
|
+
constructor(uri, source, row, col, length) {
|
|
1462
|
+
super();
|
|
1463
|
+
this.uri = uri;
|
|
1464
|
+
this.source = source;
|
|
1465
|
+
this.row = row;
|
|
1466
|
+
this.col = col;
|
|
1467
|
+
this.length = length;
|
|
1468
|
+
this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
|
|
1469
|
+
}
|
|
1470
|
+
static unknown = $mol_span.begin('?');
|
|
1471
|
+
static begin(uri, source = '') {
|
|
1472
|
+
return new $mol_span(uri, source, 1, 1, 0);
|
|
1473
|
+
}
|
|
1474
|
+
static end(uri, source) {
|
|
1475
|
+
return new $mol_span(uri, source, 1, source.length + 1, length);
|
|
1476
|
+
}
|
|
1477
|
+
static entire(uri, source) {
|
|
1478
|
+
return new $mol_span(uri, source, 1, 1, source.length);
|
|
1479
|
+
}
|
|
1480
|
+
toString() {
|
|
1481
|
+
return this[Symbol.toStringTag];
|
|
1482
|
+
}
|
|
1483
|
+
toJSON() {
|
|
1484
|
+
return {
|
|
1485
|
+
uri: this.uri,
|
|
1486
|
+
row: this.row,
|
|
1487
|
+
col: this.col,
|
|
1488
|
+
length: this.length
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
error(message, Class = Error) {
|
|
1492
|
+
return new Class(`${message}${this}`);
|
|
1493
|
+
}
|
|
1494
|
+
span(row, col, length) {
|
|
1495
|
+
return new $mol_span(this.uri, this.source, row, col, length);
|
|
1496
|
+
}
|
|
1497
|
+
after(length = 0) {
|
|
1498
|
+
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
1499
|
+
}
|
|
1500
|
+
slice(begin, end = -1) {
|
|
1501
|
+
let len = this.length;
|
|
1502
|
+
if (begin < 0)
|
|
1503
|
+
begin += len;
|
|
1504
|
+
if (end < 0)
|
|
1505
|
+
end += len;
|
|
1506
|
+
if (begin < 0 || begin > len)
|
|
1507
|
+
this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
|
|
1508
|
+
if (end < 0 || end > len)
|
|
1509
|
+
this.$.$mol_fail(`End value '${end}' out of range ${this}`);
|
|
1510
|
+
if (end < begin)
|
|
1511
|
+
this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
|
|
1512
|
+
return this.span(this.row, this.col + begin, end - begin);
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
$.$mol_span = $mol_span;
|
|
1516
|
+
})($ || ($ = {}));
|
|
1517
|
+
//mol/span/span.ts
|
|
1518
|
+
;
|
|
1519
|
+
"use strict";
|
|
1520
|
+
var $;
|
|
1521
|
+
(function ($) {
|
|
1522
|
+
function $mol_tree2_to_string(tree) {
|
|
1523
|
+
let output = [];
|
|
1524
|
+
function dump(tree, prefix = '') {
|
|
1525
|
+
if (tree.type.length) {
|
|
1526
|
+
if (!prefix.length) {
|
|
1527
|
+
prefix = "\t";
|
|
1528
|
+
}
|
|
1529
|
+
output.push(tree.type);
|
|
1530
|
+
if (tree.kids.length == 1) {
|
|
1531
|
+
output.push(' ');
|
|
1532
|
+
dump(tree.kids[0], prefix);
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
output.push("\n");
|
|
1536
|
+
}
|
|
1537
|
+
else if (tree.value.length || prefix.length) {
|
|
1538
|
+
output.push("\\" + tree.value + "\n");
|
|
1539
|
+
}
|
|
1540
|
+
for (const kid of tree.kids) {
|
|
1541
|
+
output.push(prefix);
|
|
1542
|
+
dump(kid, prefix + "\t");
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
dump(tree);
|
|
1546
|
+
return output.join('');
|
|
1547
|
+
}
|
|
1548
|
+
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
1549
|
+
})($ || ($ = {}));
|
|
1550
|
+
//mol/tree2/to/string/string.ts
|
|
1551
|
+
;
|
|
1552
|
+
"use strict";
|
|
1553
|
+
var $;
|
|
1554
|
+
(function ($) {
|
|
1555
|
+
class $mol_tree2 extends Object {
|
|
1556
|
+
type;
|
|
1557
|
+
value;
|
|
1558
|
+
kids;
|
|
1559
|
+
span;
|
|
1560
|
+
constructor(type, value, kids, span) {
|
|
1561
|
+
super();
|
|
1562
|
+
this.type = type;
|
|
1563
|
+
this.value = value;
|
|
1564
|
+
this.kids = kids;
|
|
1565
|
+
this.span = span;
|
|
1566
|
+
this[Symbol.toStringTag] = type || '\\' + value;
|
|
1567
|
+
}
|
|
1568
|
+
static list(kids, span = $mol_span.unknown) {
|
|
1569
|
+
return new $mol_tree2('', '', kids, span);
|
|
1570
|
+
}
|
|
1571
|
+
list(kids) {
|
|
1572
|
+
return $mol_tree2.list(kids, this.span);
|
|
1573
|
+
}
|
|
1574
|
+
static data(value, kids = [], span = $mol_span.unknown) {
|
|
1575
|
+
const chunks = value.split('\n');
|
|
1576
|
+
if (chunks.length > 1) {
|
|
1577
|
+
let kid_span = span.span(span.row, span.col, 0);
|
|
1578
|
+
const data = chunks.map(chunk => {
|
|
1579
|
+
kid_span = kid_span.after(chunk.length);
|
|
1580
|
+
return new $mol_tree2('', chunk, [], kid_span);
|
|
1581
|
+
});
|
|
1582
|
+
kids = [...data, ...kids];
|
|
1583
|
+
value = '';
|
|
1584
|
+
}
|
|
1585
|
+
return new $mol_tree2('', value, kids, span);
|
|
1586
|
+
}
|
|
1587
|
+
data(value, kids = []) {
|
|
1588
|
+
return $mol_tree2.data(value, kids, this.span);
|
|
1589
|
+
}
|
|
1590
|
+
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
1591
|
+
if (/[ \n\t\\]/.test(type)) {
|
|
1592
|
+
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
1593
|
+
}
|
|
1594
|
+
return new $mol_tree2(type, '', kids, span);
|
|
1595
|
+
}
|
|
1596
|
+
struct(type, kids = []) {
|
|
1597
|
+
return $mol_tree2.struct(type, kids, this.span);
|
|
1598
|
+
}
|
|
1599
|
+
clone(kids, span = this.span) {
|
|
1600
|
+
return new $mol_tree2(this.type, this.value, kids, span);
|
|
1601
|
+
}
|
|
1602
|
+
text() {
|
|
1603
|
+
var values = [];
|
|
1604
|
+
for (var kid of this.kids) {
|
|
1605
|
+
if (kid.type)
|
|
1606
|
+
continue;
|
|
1607
|
+
values.push(kid.value);
|
|
1608
|
+
}
|
|
1609
|
+
return this.value + values.join('\n');
|
|
1610
|
+
}
|
|
1611
|
+
static fromString(str, uri = 'unknown') {
|
|
1612
|
+
return $$.$mol_tree2_from_string(str, uri);
|
|
1613
|
+
}
|
|
1614
|
+
toString() {
|
|
1615
|
+
return $$.$mol_tree2_to_string(this);
|
|
1616
|
+
}
|
|
1617
|
+
insert(value, ...path) {
|
|
1618
|
+
if (path.length === 0)
|
|
1619
|
+
return value;
|
|
1620
|
+
const type = path[0];
|
|
1621
|
+
if (typeof type === 'string') {
|
|
1622
|
+
let replaced = false;
|
|
1623
|
+
const sub = this.kids.map((item, index) => {
|
|
1624
|
+
if (item.type !== type)
|
|
1625
|
+
return item;
|
|
1626
|
+
replaced = true;
|
|
1627
|
+
return item.insert(value, ...path.slice(1));
|
|
1628
|
+
}).filter(Boolean);
|
|
1629
|
+
if (!replaced && value) {
|
|
1630
|
+
sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
|
|
1631
|
+
}
|
|
1632
|
+
return this.clone(sub);
|
|
1633
|
+
}
|
|
1634
|
+
else if (typeof type === 'number') {
|
|
1635
|
+
const sub = this.kids.slice();
|
|
1636
|
+
sub[type] = (sub[type] || this.list([]))
|
|
1637
|
+
.insert(value, ...path.slice(1));
|
|
1638
|
+
return this.clone(sub.filter(Boolean));
|
|
1639
|
+
}
|
|
1640
|
+
else {
|
|
1641
|
+
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
1642
|
+
.map(item => item.insert(value, ...path.slice(1)))
|
|
1643
|
+
.filter(Boolean);
|
|
1644
|
+
return this.clone(kids);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
select(...path) {
|
|
1648
|
+
let next = [this];
|
|
1649
|
+
for (const type of path) {
|
|
1650
|
+
if (!next.length)
|
|
1651
|
+
break;
|
|
1652
|
+
const prev = next;
|
|
1653
|
+
next = [];
|
|
1654
|
+
for (var item of prev) {
|
|
1655
|
+
switch (typeof (type)) {
|
|
1656
|
+
case 'string':
|
|
1657
|
+
for (var child of item.kids) {
|
|
1658
|
+
if (child.type == type) {
|
|
1659
|
+
next.push(child);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
break;
|
|
1663
|
+
case 'number':
|
|
1664
|
+
if (type < item.kids.length)
|
|
1665
|
+
next.push(item.kids[type]);
|
|
1666
|
+
break;
|
|
1667
|
+
default: next.push(...item.kids);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
return this.list(next);
|
|
1672
|
+
}
|
|
1673
|
+
filter(path, value) {
|
|
1674
|
+
const sub = this.kids.filter(item => {
|
|
1675
|
+
var found = item.select(...path);
|
|
1676
|
+
if (value === undefined) {
|
|
1677
|
+
return Boolean(found.kids.length);
|
|
1678
|
+
}
|
|
1679
|
+
else {
|
|
1680
|
+
return found.kids.some(child => child.value == value);
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
return this.clone(sub);
|
|
1684
|
+
}
|
|
1685
|
+
hack(belt, context = {}) {
|
|
1686
|
+
return [].concat(...this.kids.map(child => {
|
|
1687
|
+
let handle = belt[child.type] || belt[''];
|
|
1688
|
+
if (!handle || handle === Object.prototype[child.type]) {
|
|
1689
|
+
handle = (input, belt, context) => [
|
|
1690
|
+
input.clone(input.hack(belt, context), context.span)
|
|
1691
|
+
];
|
|
1692
|
+
}
|
|
1693
|
+
try {
|
|
1694
|
+
return handle(child, belt, context);
|
|
1695
|
+
}
|
|
1696
|
+
catch (error) {
|
|
1697
|
+
error.message += `\n${child.clone([])}${child.span}`;
|
|
1698
|
+
$mol_fail_hidden(error);
|
|
1699
|
+
}
|
|
1700
|
+
}));
|
|
1701
|
+
}
|
|
1702
|
+
error(message, Class = Error) {
|
|
1703
|
+
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
$.$mol_tree2 = $mol_tree2;
|
|
1707
|
+
class $mol_tree2_empty extends $mol_tree2 {
|
|
1708
|
+
constructor() {
|
|
1709
|
+
super('', '', [], $mol_span.unknown);
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
$.$mol_tree2_empty = $mol_tree2_empty;
|
|
1713
|
+
})($ || ($ = {}));
|
|
1714
|
+
//mol/tree2/tree2.ts
|
|
1715
|
+
;
|
|
1716
|
+
"use strict";
|
|
1717
|
+
var $;
|
|
1718
|
+
(function ($) {
|
|
1719
|
+
class $mol_error_syntax extends SyntaxError {
|
|
1720
|
+
reason;
|
|
1721
|
+
line;
|
|
1722
|
+
span;
|
|
1723
|
+
constructor(reason, line, span) {
|
|
1724
|
+
super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
|
|
1725
|
+
this.reason = reason;
|
|
1726
|
+
this.line = line;
|
|
1727
|
+
this.span = span;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
$.$mol_error_syntax = $mol_error_syntax;
|
|
1731
|
+
})($ || ($ = {}));
|
|
1732
|
+
//mol/error/syntax/syntax.ts
|
|
1733
|
+
;
|
|
1734
|
+
"use strict";
|
|
1735
|
+
var $;
|
|
1736
|
+
(function ($) {
|
|
1737
|
+
function $mol_tree2_from_string(str, uri = '?') {
|
|
1738
|
+
const span = $mol_span.entire(uri, str);
|
|
1739
|
+
var root = $mol_tree2.list([], span);
|
|
1740
|
+
var stack = [root];
|
|
1741
|
+
var pos = 0, row = 0, min_indent = 0;
|
|
1742
|
+
while (str.length > pos) {
|
|
1743
|
+
var indent = 0;
|
|
1744
|
+
var line_start = pos;
|
|
1745
|
+
row++;
|
|
1746
|
+
while (str.length > pos && str[pos] == '\t') {
|
|
1747
|
+
indent++;
|
|
1748
|
+
pos++;
|
|
1749
|
+
}
|
|
1750
|
+
if (!root.kids.length) {
|
|
1751
|
+
min_indent = indent;
|
|
1752
|
+
}
|
|
1753
|
+
indent -= min_indent;
|
|
1754
|
+
if (indent < 0 || indent >= stack.length) {
|
|
1755
|
+
const sp = span.span(row, 1, pos - line_start);
|
|
1756
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
1757
|
+
pos++;
|
|
1758
|
+
}
|
|
1759
|
+
if (indent < 0) {
|
|
1760
|
+
if (str.length > pos) {
|
|
1761
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
else {
|
|
1765
|
+
this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
stack.length = indent + 1;
|
|
1769
|
+
var parent = stack[indent];
|
|
1770
|
+
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
1771
|
+
var error_start = pos;
|
|
1772
|
+
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
1773
|
+
pos++;
|
|
1774
|
+
}
|
|
1775
|
+
if (pos > error_start) {
|
|
1776
|
+
let line_end = str.indexOf('\n', pos);
|
|
1777
|
+
if (line_end === -1)
|
|
1778
|
+
line_end = str.length;
|
|
1779
|
+
const sp = span.span(row, error_start - line_start + 1, pos - error_start);
|
|
1780
|
+
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
1781
|
+
}
|
|
1782
|
+
var type_start = pos;
|
|
1783
|
+
while (str.length > pos &&
|
|
1784
|
+
str[pos] != '\\' &&
|
|
1785
|
+
str[pos] != ' ' &&
|
|
1786
|
+
str[pos] != '\t' &&
|
|
1787
|
+
str[pos] != '\n') {
|
|
1788
|
+
pos++;
|
|
1789
|
+
}
|
|
1790
|
+
if (pos > type_start) {
|
|
1791
|
+
let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
|
|
1792
|
+
const parent_kids = parent.kids;
|
|
1793
|
+
parent_kids.push(next);
|
|
1794
|
+
parent = next;
|
|
1795
|
+
}
|
|
1796
|
+
if (str.length > pos && str[pos] == ' ') {
|
|
1797
|
+
pos++;
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
if (str.length > pos && str[pos] == '\\') {
|
|
1801
|
+
var data_start = pos;
|
|
1802
|
+
while (str.length > pos && str[pos] != '\n') {
|
|
1803
|
+
pos++;
|
|
1804
|
+
}
|
|
1805
|
+
let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
|
|
1806
|
+
const parent_kids = parent.kids;
|
|
1807
|
+
parent_kids.push(next);
|
|
1808
|
+
parent = next;
|
|
1809
|
+
}
|
|
1810
|
+
if (str.length === pos && stack.length > 0) {
|
|
1811
|
+
const sp = span.span(row, pos - line_start + 1, 1);
|
|
1812
|
+
this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
1813
|
+
}
|
|
1814
|
+
stack.push(parent);
|
|
1815
|
+
pos++;
|
|
1816
|
+
}
|
|
1817
|
+
return root;
|
|
1818
|
+
}
|
|
1819
|
+
$.$mol_tree2_from_string = $mol_tree2_from_string;
|
|
1820
|
+
})($ || ($ = {}));
|
|
1821
|
+
//mol/tree2/from/string/string.ts
|
|
1822
|
+
;
|
|
1823
|
+
"use strict";
|
|
1824
|
+
var $;
|
|
1825
|
+
(function ($) {
|
|
1826
|
+
function $mol_tree2_from_json(json, span = $mol_span.unknown) {
|
|
1827
|
+
if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
|
|
1828
|
+
return new $mol_tree2(String(json), '', [], span);
|
|
1829
|
+
}
|
|
1830
|
+
if (typeof json === 'string') {
|
|
1831
|
+
return $mol_tree2.data(json, [], span);
|
|
1832
|
+
}
|
|
1833
|
+
if (Array.isArray(json)) {
|
|
1834
|
+
const sub = json.map(json => $mol_tree2_from_json(json, span));
|
|
1835
|
+
return new $mol_tree2('/', '', sub, span);
|
|
1836
|
+
}
|
|
1837
|
+
if (ArrayBuffer.isView(json)) {
|
|
1838
|
+
const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
|
|
1839
|
+
return $mol_tree2.data(String.fromCharCode(...buf), [], span);
|
|
1840
|
+
}
|
|
1841
|
+
if (json instanceof Date) {
|
|
1842
|
+
return new $mol_tree2('', json.toISOString(), [], span);
|
|
1843
|
+
}
|
|
1844
|
+
if (typeof json.toJSON === 'function') {
|
|
1845
|
+
return $mol_tree2_from_json(json.toJSON());
|
|
1846
|
+
}
|
|
1847
|
+
if (json instanceof Error) {
|
|
1848
|
+
const { name, message, stack } = json;
|
|
1849
|
+
json = { ...json, name, message, stack };
|
|
1850
|
+
}
|
|
1851
|
+
const sub = [];
|
|
1852
|
+
for (var key in json) {
|
|
1853
|
+
const val = json[key];
|
|
1854
|
+
if (val === undefined)
|
|
1855
|
+
continue;
|
|
1856
|
+
const subsub = $mol_tree2_from_json(val, span);
|
|
1857
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
1858
|
+
sub.push(new $mol_tree2(key, '', [subsub], span));
|
|
1859
|
+
}
|
|
1860
|
+
else {
|
|
1861
|
+
sub.push($mol_tree2.data(key, [subsub], span));
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
return new $mol_tree2('*', '', sub, span);
|
|
1865
|
+
}
|
|
1866
|
+
$.$mol_tree2_from_json = $mol_tree2_from_json;
|
|
1867
|
+
})($ || ($ = {}));
|
|
1868
|
+
//mol/tree2/from/json/json.ts
|
|
1869
|
+
;
|
|
1870
|
+
"use strict";
|
|
1871
|
+
var $;
|
|
1872
|
+
(function ($) {
|
|
1873
|
+
class $mol_term_color {
|
|
1874
|
+
static reset = this.ansi(0, 0);
|
|
1875
|
+
static bold = this.ansi(1, 22);
|
|
1876
|
+
static italic = this.ansi(3, 23);
|
|
1877
|
+
static underline = this.ansi(4, 24);
|
|
1878
|
+
static inverse = this.ansi(7, 27);
|
|
1879
|
+
static hidden = this.ansi(8, 28);
|
|
1880
|
+
static strike = this.ansi(9, 29);
|
|
1881
|
+
static gray = this.ansi(90, 39);
|
|
1882
|
+
static red = this.ansi(91, 39);
|
|
1883
|
+
static green = this.ansi(92, 39);
|
|
1884
|
+
static yellow = this.ansi(93, 39);
|
|
1885
|
+
static blue = this.ansi(94, 39);
|
|
1886
|
+
static magenta = this.ansi(95, 39);
|
|
1887
|
+
static cyan = this.ansi(96, 39);
|
|
1888
|
+
static Gray = (str) => this.inverse(this.gray(str));
|
|
1889
|
+
static Red = (str) => this.inverse(this.red(str));
|
|
1890
|
+
static Green = (str) => this.inverse(this.green(str));
|
|
1891
|
+
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
1892
|
+
static Blue = (str) => this.inverse(this.blue(str));
|
|
1893
|
+
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
1894
|
+
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
1895
|
+
static ansi(open, close) {
|
|
1896
|
+
if (typeof process === 'undefined')
|
|
1897
|
+
return String;
|
|
1898
|
+
if (!process.stdout.isTTY)
|
|
1899
|
+
return String;
|
|
1900
|
+
const prefix = `\x1b[${open}m`;
|
|
1901
|
+
const postfix = `\x1b[${close}m`;
|
|
1902
|
+
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
1903
|
+
return function colorer(str) {
|
|
1904
|
+
str = String(str);
|
|
1905
|
+
if (str === '')
|
|
1906
|
+
return str;
|
|
1907
|
+
const suffix = str.replace(suffix_regexp, prefix);
|
|
1908
|
+
return prefix + suffix + postfix;
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
$.$mol_term_color = $mol_term_color;
|
|
1913
|
+
})($ || ($ = {}));
|
|
1914
|
+
//mol/term/color/color.ts
|
|
1915
|
+
;
|
|
1916
|
+
"use strict";
|
|
1917
|
+
var $;
|
|
1918
|
+
(function ($) {
|
|
1919
|
+
function $mol_log3_node_make(level, output, type, color) {
|
|
1920
|
+
return function $mol_log3_logger(event) {
|
|
1921
|
+
if (!event.time)
|
|
1922
|
+
event = { time: new Date().toISOString(), ...event };
|
|
1923
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
1924
|
+
tree = tree.struct(type, tree.kids);
|
|
1925
|
+
let str = color(tree.toString());
|
|
1926
|
+
this.console[level](str);
|
|
1927
|
+
const self = this;
|
|
1928
|
+
return () => self.console.groupEnd();
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
1932
|
+
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
1933
|
+
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
1934
|
+
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
1935
|
+
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
1936
|
+
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
1937
|
+
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
1938
|
+
})($ || ($ = {}));
|
|
1939
|
+
//mol/log3/log3.node.ts
|
|
1940
|
+
;
|
|
1941
|
+
"use strict";
|
|
1942
|
+
var $;
|
|
1943
|
+
(function ($) {
|
|
1944
|
+
function $mol_env() {
|
|
1945
|
+
return {};
|
|
1946
|
+
}
|
|
1947
|
+
$.$mol_env = $mol_env;
|
|
1948
|
+
})($ || ($ = {}));
|
|
1949
|
+
//mol/env/env.ts
|
|
1950
|
+
;
|
|
1951
|
+
"use strict";
|
|
1952
|
+
var $;
|
|
1953
|
+
(function ($) {
|
|
1954
|
+
$.$mol_env = function $mol_env() {
|
|
1955
|
+
return this.process.env;
|
|
1956
|
+
};
|
|
1957
|
+
})($ || ($ = {}));
|
|
1958
|
+
//mol/env/env.node.ts
|
|
1959
|
+
;
|
|
1960
|
+
"use strict";
|
|
1961
|
+
var $;
|
|
1962
|
+
(function ($) {
|
|
1963
|
+
function $mol_exec(dir, command, ...args) {
|
|
1964
|
+
let [app, ...args0] = command.split(' ');
|
|
1965
|
+
args = [...args0, ...args];
|
|
1966
|
+
this.$mol_log3_come({
|
|
1967
|
+
place: '$mol_exec',
|
|
1968
|
+
dir: $node.path.relative('', dir),
|
|
1969
|
+
message: 'Run',
|
|
1970
|
+
command: `${app} ${args.join(' ')}`,
|
|
1971
|
+
});
|
|
1972
|
+
var res = $node['child_process'].spawnSync(app, args, {
|
|
1973
|
+
cwd: $node.path.resolve(dir),
|
|
1974
|
+
shell: true,
|
|
1975
|
+
env: this.$mol_env(),
|
|
1976
|
+
});
|
|
1977
|
+
if (res.status || res.error)
|
|
1978
|
+
return $mol_fail(res.error || new Error(res.stderr.toString()));
|
|
1979
|
+
if (!res.stdout)
|
|
1980
|
+
res.stdout = Buffer.from([]);
|
|
1981
|
+
return res;
|
|
1982
|
+
}
|
|
1983
|
+
$.$mol_exec = $mol_exec;
|
|
1984
|
+
})($ || ($ = {}));
|
|
1985
|
+
//mol/exec/exec.node.ts
|
|
1986
|
+
;
|
|
1987
|
+
"use strict";
|
|
1988
|
+
var $;
|
|
1989
|
+
(function ($) {
|
|
1990
|
+
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
|
|
1991
|
+
})($ || ($ = {}));
|
|
1992
|
+
//mol/dom/context/context.node.ts
|
|
1993
|
+
;
|
|
1994
|
+
"use strict";
|
|
1995
|
+
var $;
|
|
1996
|
+
(function ($) {
|
|
1997
|
+
class $mol_state_local extends $mol_object {
|
|
1998
|
+
static 'native()';
|
|
1999
|
+
static native() {
|
|
2000
|
+
if (this['native()'])
|
|
2001
|
+
return this['native()'];
|
|
2002
|
+
check: try {
|
|
2003
|
+
const native = $mol_dom_context.localStorage;
|
|
2004
|
+
if (!native)
|
|
2005
|
+
break check;
|
|
2006
|
+
native.setItem('', '');
|
|
2007
|
+
native.removeItem('');
|
|
2008
|
+
return this['native()'] = native;
|
|
2009
|
+
}
|
|
2010
|
+
catch (error) {
|
|
2011
|
+
console.warn(error);
|
|
2012
|
+
}
|
|
2013
|
+
return this['native()'] = {
|
|
2014
|
+
getItem(key) {
|
|
2015
|
+
return this[':' + key];
|
|
2016
|
+
},
|
|
2017
|
+
setItem(key, value) {
|
|
2018
|
+
this[':' + key] = value;
|
|
2019
|
+
},
|
|
2020
|
+
removeItem(key) {
|
|
2021
|
+
this[':' + key] = void 0;
|
|
2022
|
+
}
|
|
2023
|
+
};
|
|
2024
|
+
}
|
|
2025
|
+
static changes(next) { return next; }
|
|
2026
|
+
static value(key, next) {
|
|
2027
|
+
this.changes();
|
|
2028
|
+
if (next === void 0)
|
|
2029
|
+
return JSON.parse(this.native().getItem(key) || 'null');
|
|
2030
|
+
if (next === null)
|
|
2031
|
+
this.native().removeItem(key);
|
|
2032
|
+
else
|
|
2033
|
+
this.native().setItem(key, JSON.stringify(next));
|
|
2034
|
+
return next;
|
|
2035
|
+
}
|
|
2036
|
+
prefix() { return ''; }
|
|
2037
|
+
value(key, next) {
|
|
2038
|
+
return $mol_state_local.value(this.prefix() + '.' + key, next);
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
__decorate([
|
|
2042
|
+
$mol_mem
|
|
2043
|
+
], $mol_state_local, "changes", null);
|
|
2044
|
+
__decorate([
|
|
2045
|
+
$mol_mem_key
|
|
2046
|
+
], $mol_state_local, "value", null);
|
|
2047
|
+
$.$mol_state_local = $mol_state_local;
|
|
2048
|
+
})($ || ($ = {}));
|
|
2049
|
+
//mol/state/local/local.ts
|
|
2050
|
+
;
|
|
2051
|
+
"use strict";
|
|
2052
|
+
var $;
|
|
2053
|
+
(function ($) {
|
|
2054
|
+
const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
|
|
2055
|
+
const encoder = new TextEncoder();
|
|
2056
|
+
function $mol_charset_encode(value) {
|
|
2057
|
+
return encoder.encode(value);
|
|
2058
|
+
}
|
|
2059
|
+
$.$mol_charset_encode = $mol_charset_encode;
|
|
2060
|
+
})($ || ($ = {}));
|
|
2061
|
+
//mol/charset/encode/encode.ts
|
|
2062
|
+
;
|
|
2063
|
+
"use strict";
|
|
2064
|
+
var $;
|
|
2065
|
+
(function ($) {
|
|
2066
|
+
function $mol_int62_string_ensure(str) {
|
|
2067
|
+
if (typeof str !== 'string')
|
|
2068
|
+
return null;
|
|
2069
|
+
return $mol_int62_from_string(str) && str;
|
|
2070
|
+
}
|
|
2071
|
+
$.$mol_int62_string_ensure = $mol_int62_string_ensure;
|
|
2072
|
+
$.$mol_int62_max = (2 ** 30) - 1;
|
|
2073
|
+
$.$mol_int62_min = -(2 ** 30);
|
|
2074
|
+
$.$mol_int62_range = $.$mol_int62_max - $.$mol_int62_min + 1;
|
|
2075
|
+
function $mol_int62_to_string({ lo, hi }) {
|
|
2076
|
+
lo = (lo + $.$mol_int62_range) % $.$mol_int62_range;
|
|
2077
|
+
hi = (hi + $.$mol_int62_range) % $.$mol_int62_range;
|
|
2078
|
+
return lo.toString(36) + '_' + hi.toString(36);
|
|
2079
|
+
}
|
|
2080
|
+
$.$mol_int62_to_string = $mol_int62_to_string;
|
|
2081
|
+
function $mol_int62_from_string(str) {
|
|
2082
|
+
const [str_lo, str_hi] = str.split('_');
|
|
2083
|
+
const int_lo = parseInt(str_lo, 36);
|
|
2084
|
+
const int_hi = parseInt(str_hi, 36);
|
|
2085
|
+
if (int_lo.toString(36) !== str_lo || int_hi.toString(36) !== str_hi) {
|
|
2086
|
+
return null;
|
|
2087
|
+
}
|
|
2088
|
+
return {
|
|
2089
|
+
lo: (int_lo - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
|
|
2090
|
+
hi: (int_hi - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
|
|
2091
|
+
};
|
|
2092
|
+
}
|
|
2093
|
+
$.$mol_int62_from_string = $mol_int62_from_string;
|
|
2094
|
+
function $mol_int62_compare(left_lo, left_hi, right_lo, right_hi) {
|
|
2095
|
+
return (right_hi - left_hi) || (right_lo - left_lo);
|
|
2096
|
+
}
|
|
2097
|
+
$.$mol_int62_compare = $mol_int62_compare;
|
|
2098
|
+
function $mol_int62_inc(lo, hi, max = $.$mol_int62_max) {
|
|
2099
|
+
if (lo === max) {
|
|
2100
|
+
return { lo: -max, hi: hi + 1 };
|
|
2101
|
+
}
|
|
2102
|
+
else {
|
|
2103
|
+
return { lo: lo + 1, hi };
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
$.$mol_int62_inc = $mol_int62_inc;
|
|
2107
|
+
function $mol_int62_random() {
|
|
2108
|
+
return {
|
|
2109
|
+
lo: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
|
|
2110
|
+
hi: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
|
|
2111
|
+
};
|
|
2112
|
+
}
|
|
2113
|
+
$.$mol_int62_random = $mol_int62_random;
|
|
2114
|
+
function $mol_int62_hash_string(str) {
|
|
2115
|
+
return $mol_int62_to_string($mol_int62_hash_buffer($mol_charset_encode(str)));
|
|
2116
|
+
}
|
|
2117
|
+
$.$mol_int62_hash_string = $mol_int62_hash_string;
|
|
2118
|
+
function $mol_int62_hash_buffer(buf, seed = { lo: 0, hi: 0 }) {
|
|
2119
|
+
let h1 = 0xdeadbeef ^ seed.lo;
|
|
2120
|
+
let h2 = 0x41c6ce57 ^ seed.hi;
|
|
2121
|
+
for (const byte of buf) {
|
|
2122
|
+
h1 = Math.imul(h1 ^ byte, 2654435761);
|
|
2123
|
+
h2 = Math.imul(h2 ^ byte, 1597334677);
|
|
2124
|
+
}
|
|
2125
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
2126
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
2127
|
+
return { lo: h1 << 1 >> 1, hi: h2 << 1 >> 1 };
|
|
2128
|
+
}
|
|
2129
|
+
$.$mol_int62_hash_buffer = $mol_int62_hash_buffer;
|
|
2130
|
+
})($ || ($ = {}));
|
|
2131
|
+
//mol/int62/int62.ts
|
|
2132
|
+
;
|
|
2133
|
+
"use strict";
|
|
2134
|
+
var $;
|
|
2135
|
+
(function ($) {
|
|
2136
|
+
$.$mol_crypto_native = $node.crypto.webcrypto;
|
|
2137
|
+
})($ || ($ = {}));
|
|
2138
|
+
//mol/crypto/native/native.node.ts
|
|
2139
|
+
;
|
|
2140
|
+
"use strict";
|
|
2141
|
+
var $;
|
|
2142
|
+
(function ($) {
|
|
2143
|
+
const algorithm = {
|
|
2144
|
+
name: 'ECDSA',
|
|
2145
|
+
hash: 'SHA-256',
|
|
2146
|
+
namedCurve: "P-256",
|
|
2147
|
+
};
|
|
2148
|
+
async function $mol_crypto_auditor_pair() {
|
|
2149
|
+
const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
|
|
2150
|
+
return {
|
|
2151
|
+
public: new $mol_crypto_auditor_public(pair.publicKey),
|
|
2152
|
+
private: new $mol_crypto_auditor_private(pair.privateKey),
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
$.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
|
|
2156
|
+
class $mol_crypto_auditor_public extends Object {
|
|
2157
|
+
native;
|
|
2158
|
+
static size = 86;
|
|
2159
|
+
constructor(native) {
|
|
2160
|
+
super();
|
|
2161
|
+
this.native = native;
|
|
2162
|
+
}
|
|
2163
|
+
static async from(serial) {
|
|
2164
|
+
return new this(await $mol_crypto_native.subtle.importKey('jwk', {
|
|
2165
|
+
crv: "P-256",
|
|
2166
|
+
ext: true,
|
|
2167
|
+
key_ops: ['verify'],
|
|
2168
|
+
kty: "EC",
|
|
2169
|
+
x: serial.slice(0, 43),
|
|
2170
|
+
y: serial.slice(43, 86),
|
|
2171
|
+
}, algorithm, true, ['verify']));
|
|
2172
|
+
}
|
|
2173
|
+
async serial() {
|
|
2174
|
+
const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
|
|
2175
|
+
return x + y;
|
|
2176
|
+
}
|
|
2177
|
+
async verify(data, sign) {
|
|
2178
|
+
return await $mol_crypto_native.subtle.verify(algorithm, this.native, sign, data);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
$.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
|
|
2182
|
+
class $mol_crypto_auditor_private extends Object {
|
|
2183
|
+
native;
|
|
2184
|
+
static size = 129;
|
|
2185
|
+
constructor(native) {
|
|
2186
|
+
super();
|
|
2187
|
+
this.native = native;
|
|
2188
|
+
}
|
|
2189
|
+
static async from(serial) {
|
|
2190
|
+
return new this(await $mol_crypto_native.subtle.importKey('jwk', {
|
|
2191
|
+
crv: "P-256",
|
|
2192
|
+
ext: true,
|
|
2193
|
+
key_ops: ['sign'],
|
|
2194
|
+
kty: "EC",
|
|
2195
|
+
x: serial.slice(0, 43),
|
|
2196
|
+
y: serial.slice(43, 86),
|
|
2197
|
+
d: serial.slice(86, 129),
|
|
2198
|
+
}, algorithm, true, ['sign']));
|
|
2199
|
+
}
|
|
2200
|
+
async serial() {
|
|
2201
|
+
const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
|
|
2202
|
+
return x + y + d;
|
|
2203
|
+
}
|
|
2204
|
+
async sign(data) {
|
|
2205
|
+
return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
|
|
2206
|
+
}
|
|
2207
|
+
async public() {
|
|
2208
|
+
return await $mol_crypto_auditor_public.from($mol_crypto_auditor_private_to_public(await this.serial()));
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
$.$mol_crypto_auditor_private = $mol_crypto_auditor_private;
|
|
2212
|
+
$.$mol_crypto_auditor_sign_size = 64;
|
|
2213
|
+
function $mol_crypto_auditor_private_to_public(serial) {
|
|
2214
|
+
return serial.slice(0, 86);
|
|
2215
|
+
}
|
|
2216
|
+
$.$mol_crypto_auditor_private_to_public = $mol_crypto_auditor_private_to_public;
|
|
2217
|
+
})($ || ($ = {}));
|
|
2218
|
+
//mol/crypto/auditor/auditor.ts
|
|
2219
|
+
;
|
|
2220
|
+
"use strict";
|
|
2221
|
+
var $;
|
|
2222
|
+
(function ($) {
|
|
2223
|
+
let $hyoo_crowd_peer_level;
|
|
2224
|
+
(function ($hyoo_crowd_peer_level) {
|
|
2225
|
+
$hyoo_crowd_peer_level[$hyoo_crowd_peer_level["get"] = 0] = "get";
|
|
2226
|
+
$hyoo_crowd_peer_level[$hyoo_crowd_peer_level["add"] = 1] = "add";
|
|
2227
|
+
$hyoo_crowd_peer_level[$hyoo_crowd_peer_level["mod"] = 2] = "mod";
|
|
2228
|
+
$hyoo_crowd_peer_level[$hyoo_crowd_peer_level["law"] = 3] = "law";
|
|
2229
|
+
})($hyoo_crowd_peer_level = $.$hyoo_crowd_peer_level || ($.$hyoo_crowd_peer_level = {}));
|
|
2230
|
+
class $hyoo_crowd_peer extends Object {
|
|
2231
|
+
key_public;
|
|
2232
|
+
key_public_serial;
|
|
2233
|
+
key_private;
|
|
2234
|
+
key_private_serial;
|
|
2235
|
+
id;
|
|
2236
|
+
constructor(key_public, key_public_serial, key_private, key_private_serial) {
|
|
2237
|
+
super();
|
|
2238
|
+
this.key_public = key_public;
|
|
2239
|
+
this.key_public_serial = key_public_serial;
|
|
2240
|
+
this.key_private = key_private;
|
|
2241
|
+
this.key_private_serial = key_private_serial;
|
|
2242
|
+
this.id = $mol_int62_hash_string(this.key_public_serial);
|
|
2243
|
+
}
|
|
2244
|
+
static async generate() {
|
|
2245
|
+
const pair = await $$.$mol_crypto_auditor_pair();
|
|
2246
|
+
const serial = await pair.private.serial();
|
|
2247
|
+
return new this(pair.public, $mol_crypto_auditor_private_to_public(serial), pair.private, serial);
|
|
2248
|
+
}
|
|
2249
|
+
static async restore(serial) {
|
|
2250
|
+
return new this(await $$.$mol_crypto_auditor_public.from(serial), $mol_crypto_auditor_private_to_public(serial), await $$.$mol_crypto_auditor_private.from(serial), serial);
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
$.$hyoo_crowd_peer = $hyoo_crowd_peer;
|
|
2254
|
+
})($ || ($ = {}));
|
|
2255
|
+
//hyoo/crowd/peer/peer.ts
|
|
2256
|
+
;
|
|
2257
|
+
"use strict";
|
|
2258
|
+
var $;
|
|
2259
|
+
(function ($) {
|
|
2260
|
+
async function $hyoo_sync_peer(path) {
|
|
2261
|
+
let serial = $mol_state_local.value('$hyoo_sync_peer');
|
|
2262
|
+
if (typeof serial === 'string') {
|
|
2263
|
+
return await $hyoo_crowd_peer.restore(serial);
|
|
2264
|
+
}
|
|
2265
|
+
const peer = await $hyoo_crowd_peer.generate();
|
|
2266
|
+
$mol_state_local.value('$hyoo_sync_peer', peer.key_private_serial);
|
|
2267
|
+
return peer;
|
|
2268
|
+
}
|
|
2269
|
+
$.$hyoo_sync_peer = $hyoo_sync_peer;
|
|
2270
|
+
})($ || ($ = {}));
|
|
2271
|
+
//hyoo/sync/peer/peer.node.ts
|
|
2272
|
+
;
|
|
2273
|
+
"use strict";
|
|
2274
|
+
var $;
|
|
2275
|
+
(function ($) {
|
|
2276
|
+
function $mol_wire_solid() {
|
|
2277
|
+
const current = $mol_wire_auto();
|
|
2278
|
+
if (current.reap !== nothing) {
|
|
2279
|
+
current?.sub_on(sub, sub.data.length);
|
|
2280
|
+
}
|
|
2281
|
+
current.reap = nothing;
|
|
2282
|
+
}
|
|
2283
|
+
$.$mol_wire_solid = $mol_wire_solid;
|
|
2284
|
+
const nothing = () => { };
|
|
2285
|
+
const sub = new $mol_wire_pub_sub;
|
|
2286
|
+
})($ || ($ = {}));
|
|
2287
|
+
//mol/wire/solid/solid.ts
|
|
2288
|
+
;
|
|
2289
|
+
"use strict";
|
|
2290
|
+
var $;
|
|
2291
|
+
(function ($) {
|
|
2292
|
+
class $mol_wrapper extends $mol_object2 {
|
|
2293
|
+
static wrap;
|
|
2294
|
+
static run(task) {
|
|
2295
|
+
return this.func(task)();
|
|
2296
|
+
}
|
|
2297
|
+
static func(func) {
|
|
2298
|
+
return this.wrap(func);
|
|
2299
|
+
}
|
|
2300
|
+
static get class() {
|
|
2301
|
+
return (Class) => {
|
|
2302
|
+
const construct = (target, args) => new Class(...args);
|
|
2303
|
+
const handler = {
|
|
2304
|
+
construct: this.func(construct)
|
|
2305
|
+
};
|
|
2306
|
+
handler[Symbol.toStringTag] = Class.name + '#';
|
|
2307
|
+
return new Proxy(Class, handler);
|
|
2308
|
+
};
|
|
2309
|
+
}
|
|
2310
|
+
static get method() {
|
|
2311
|
+
return (obj, name, descr) => {
|
|
2312
|
+
descr.value = this.func(descr.value);
|
|
2313
|
+
return descr;
|
|
2314
|
+
};
|
|
2315
|
+
}
|
|
2316
|
+
static get field() {
|
|
2317
|
+
return (obj, name, descr) => {
|
|
2318
|
+
descr.get = descr.set = this.func(descr.get);
|
|
2319
|
+
return descr;
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
$.$mol_wrapper = $mol_wrapper;
|
|
2324
|
+
})($ || ($ = {}));
|
|
2325
|
+
//mol/wrapper/wrapper.ts
|
|
2326
|
+
;
|
|
2327
|
+
"use strict";
|
|
2328
|
+
var $;
|
|
2329
|
+
(function ($) {
|
|
2330
|
+
class $mol_memo extends $mol_wrapper {
|
|
2331
|
+
static wrap(task) {
|
|
2332
|
+
const store = new WeakMap();
|
|
2333
|
+
return function (next) {
|
|
2334
|
+
if (next === undefined && store.has(this))
|
|
2335
|
+
return store.get(this);
|
|
2336
|
+
const val = task.call(this, next) ?? next;
|
|
2337
|
+
store.set(this, val);
|
|
2338
|
+
return val;
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
$.$mol_memo = $mol_memo;
|
|
2343
|
+
})($ || ($ = {}));
|
|
2344
|
+
//mol/memo/memo.ts
|
|
2345
|
+
;
|
|
2346
|
+
"use strict";
|
|
2347
|
+
//mol/data/value/value.ts
|
|
2348
|
+
;
|
|
2349
|
+
"use strict";
|
|
2350
|
+
var $;
|
|
2351
|
+
(function ($) {
|
|
2352
|
+
function $mol_data_setup(value, config) {
|
|
2353
|
+
return Object.assign(value, {
|
|
2354
|
+
config,
|
|
2355
|
+
Value: null
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
$.$mol_data_setup = $mol_data_setup;
|
|
2359
|
+
})($ || ($ = {}));
|
|
2360
|
+
//mol/data/setup/setup.ts
|
|
2361
|
+
;
|
|
2362
|
+
"use strict";
|
|
2363
|
+
var $;
|
|
2364
|
+
(function ($) {
|
|
2365
|
+
function $mol_diff_path(...paths) {
|
|
2366
|
+
const limit = Math.min(...paths.map(path => path.length));
|
|
2367
|
+
lookup: for (var i = 0; i < limit; ++i) {
|
|
2368
|
+
const first = paths[0][i];
|
|
2369
|
+
for (let j = 1; j < paths.length; ++j) {
|
|
2370
|
+
if (paths[j][i] !== first)
|
|
2371
|
+
break lookup;
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
return {
|
|
2375
|
+
prefix: paths[0].slice(0, i),
|
|
2376
|
+
suffix: paths.map(path => path.slice(i)),
|
|
2377
|
+
};
|
|
2378
|
+
}
|
|
2379
|
+
$.$mol_diff_path = $mol_diff_path;
|
|
2380
|
+
})($ || ($ = {}));
|
|
2381
|
+
//mol/diff/path/path.ts
|
|
2382
|
+
;
|
|
2383
|
+
"use strict";
|
|
2384
|
+
var $;
|
|
2385
|
+
(function ($) {
|
|
2386
|
+
class $mol_error_mix extends Error {
|
|
2387
|
+
errors;
|
|
2388
|
+
constructor(message, ...errors) {
|
|
2389
|
+
super(message);
|
|
2390
|
+
this.errors = errors;
|
|
2391
|
+
if (errors.length) {
|
|
2392
|
+
const stacks = [...errors.map(error => error.stack), this.stack];
|
|
2393
|
+
const diff = $mol_diff_path(...stacks.map(stack => {
|
|
2394
|
+
if (!stack)
|
|
2395
|
+
return [];
|
|
2396
|
+
return stack.split('\n').reverse();
|
|
2397
|
+
}));
|
|
2398
|
+
const head = diff.prefix.reverse().join('\n');
|
|
2399
|
+
const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
|
|
2400
|
+
this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
|
|
2401
|
+
this.message += errors.map(error => '\n' + error.message).join('');
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
toJSON() {
|
|
2405
|
+
return this.message;
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
$.$mol_error_mix = $mol_error_mix;
|
|
2409
|
+
})($ || ($ = {}));
|
|
2410
|
+
//mol/error/mix/mix.ts
|
|
2411
|
+
;
|
|
2412
|
+
"use strict";
|
|
2413
|
+
var $;
|
|
2414
|
+
(function ($) {
|
|
2415
|
+
class $mol_data_error extends $mol_error_mix {
|
|
2416
|
+
}
|
|
2417
|
+
$.$mol_data_error = $mol_data_error;
|
|
2418
|
+
})($ || ($ = {}));
|
|
2419
|
+
//mol/data/error/error.ts
|
|
2420
|
+
;
|
|
2421
|
+
"use strict";
|
|
2422
|
+
var $;
|
|
2423
|
+
(function ($) {
|
|
2424
|
+
function $mol_data_enum(name, dict) {
|
|
2425
|
+
const index = {};
|
|
2426
|
+
for (let key in dict) {
|
|
2427
|
+
if (Number.isNaN(Number(key))) {
|
|
2428
|
+
index[dict[key]] = key;
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
return $mol_data_setup((value) => {
|
|
2432
|
+
if (typeof index[value] !== 'string') {
|
|
2433
|
+
return $mol_fail(new $mol_data_error(`${value} is not value of ${name} enum`));
|
|
2434
|
+
}
|
|
2435
|
+
return value;
|
|
2436
|
+
}, { name, dict });
|
|
2437
|
+
}
|
|
2438
|
+
$.$mol_data_enum = $mol_data_enum;
|
|
2439
|
+
})($ || ($ = {}));
|
|
2440
|
+
//mol/data/enum/enum.ts
|
|
2441
|
+
;
|
|
2442
|
+
"use strict";
|
|
2443
|
+
//mol/charset/encoding/encoding.ts
|
|
2444
|
+
;
|
|
2445
|
+
"use strict";
|
|
2446
|
+
var $;
|
|
2447
|
+
(function ($) {
|
|
2448
|
+
const decoders = {};
|
|
2449
|
+
function $mol_charset_decode(buffer, encoding = 'utf8') {
|
|
2450
|
+
let decoder = decoders[encoding];
|
|
2451
|
+
if (!decoder)
|
|
2452
|
+
decoder = decoders[encoding] = new TextDecoder(encoding);
|
|
2453
|
+
return decoder.decode(buffer);
|
|
2454
|
+
}
|
|
2455
|
+
$.$mol_charset_decode = $mol_charset_decode;
|
|
2456
|
+
})($ || ($ = {}));
|
|
2457
|
+
//mol/charset/decode/decode.ts
|
|
2458
|
+
;
|
|
2459
|
+
"use strict";
|
|
2460
|
+
var $;
|
|
2461
|
+
(function ($) {
|
|
2462
|
+
const level = $mol_data_enum('level', $hyoo_crowd_peer_level);
|
|
2463
|
+
let $hyoo_crowd_unit_kind;
|
|
2464
|
+
(function ($hyoo_crowd_unit_kind) {
|
|
2465
|
+
$hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["grab"] = 0] = "grab";
|
|
2466
|
+
$hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["join"] = 1] = "join";
|
|
2467
|
+
$hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["give"] = 2] = "give";
|
|
2468
|
+
$hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["data"] = 3] = "data";
|
|
2469
|
+
})($hyoo_crowd_unit_kind = $.$hyoo_crowd_unit_kind || ($.$hyoo_crowd_unit_kind = {}));
|
|
2470
|
+
let $hyoo_crowd_unit_group;
|
|
2471
|
+
(function ($hyoo_crowd_unit_group) {
|
|
2472
|
+
$hyoo_crowd_unit_group[$hyoo_crowd_unit_group["auth"] = 0] = "auth";
|
|
2473
|
+
$hyoo_crowd_unit_group[$hyoo_crowd_unit_group["data"] = 1] = "data";
|
|
2474
|
+
})($hyoo_crowd_unit_group = $.$hyoo_crowd_unit_group || ($.$hyoo_crowd_unit_group = {}));
|
|
2475
|
+
class $hyoo_crowd_unit extends Object {
|
|
2476
|
+
land;
|
|
2477
|
+
auth;
|
|
2478
|
+
head;
|
|
2479
|
+
self;
|
|
2480
|
+
next;
|
|
2481
|
+
prev;
|
|
2482
|
+
time;
|
|
2483
|
+
data;
|
|
2484
|
+
bin;
|
|
2485
|
+
constructor(land, auth, head, self, next, prev, time, data, bin) {
|
|
2486
|
+
super();
|
|
2487
|
+
this.land = land;
|
|
2488
|
+
this.auth = auth;
|
|
2489
|
+
this.head = head;
|
|
2490
|
+
this.self = self;
|
|
2491
|
+
this.next = next;
|
|
2492
|
+
this.prev = prev;
|
|
2493
|
+
this.time = time;
|
|
2494
|
+
this.data = data;
|
|
2495
|
+
this.bin = bin;
|
|
2496
|
+
}
|
|
2497
|
+
kind() {
|
|
2498
|
+
if (this.head === this.self && this.auth === this.self) {
|
|
2499
|
+
if (this.head === this.land) {
|
|
2500
|
+
return $hyoo_crowd_unit_kind.grab;
|
|
2501
|
+
}
|
|
2502
|
+
else {
|
|
2503
|
+
return $hyoo_crowd_unit_kind.join;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
if (this.head === this.land) {
|
|
2507
|
+
return $hyoo_crowd_unit_kind.give;
|
|
2508
|
+
}
|
|
2509
|
+
return $hyoo_crowd_unit_kind.data;
|
|
2510
|
+
}
|
|
2511
|
+
group() {
|
|
2512
|
+
return this.kind() === $hyoo_crowd_unit_kind.data
|
|
2513
|
+
? $hyoo_crowd_unit_group.data
|
|
2514
|
+
: $hyoo_crowd_unit_group.auth;
|
|
2515
|
+
}
|
|
2516
|
+
level() {
|
|
2517
|
+
switch (this.kind()) {
|
|
2518
|
+
case $hyoo_crowd_unit_kind.grab: return $hyoo_crowd_peer_level.law;
|
|
2519
|
+
case $hyoo_crowd_unit_kind.give: return level(this.data);
|
|
2520
|
+
default: $mol_fail(new Error(`Wrong unit kind for getting level: ${this.kind()}`));
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
[Symbol.toPrimitive]() {
|
|
2524
|
+
return JSON.stringify(this);
|
|
2525
|
+
}
|
|
2526
|
+
[$mol_dev_format_head]() {
|
|
2527
|
+
switch (this.kind()) {
|
|
2528
|
+
case $hyoo_crowd_unit_kind.grab:
|
|
2529
|
+
return $mol_dev_format_div({}, $mol_dev_format_native(this), ' 👑');
|
|
2530
|
+
case $hyoo_crowd_unit_kind.join:
|
|
2531
|
+
return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🔑 ', this.self));
|
|
2532
|
+
case $hyoo_crowd_unit_kind.give:
|
|
2533
|
+
return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🏅 ', this.self, ' '), $mol_dev_format_native($hyoo_crowd_peer_level[this.data] ?? this.data));
|
|
2534
|
+
case $hyoo_crowd_unit_kind.data:
|
|
2535
|
+
return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 📦 ', this.head, '!', this.self, ' '), $mol_dev_format_native(this.data));
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
$.$hyoo_crowd_unit = $hyoo_crowd_unit;
|
|
2540
|
+
const offset = {
|
|
2541
|
+
land_lo: 0,
|
|
2542
|
+
land_hi: 4,
|
|
2543
|
+
auth_lo: 8,
|
|
2544
|
+
auth_hi: 12,
|
|
2545
|
+
head_lo: 16,
|
|
2546
|
+
head_hi: 20,
|
|
2547
|
+
self_lo: 24,
|
|
2548
|
+
self_hi: 28,
|
|
2549
|
+
next_lo: 32,
|
|
2550
|
+
next_hi: 36,
|
|
2551
|
+
prev_lo: 40,
|
|
2552
|
+
prev_hi: 44,
|
|
2553
|
+
time: 48,
|
|
2554
|
+
size: 54,
|
|
2555
|
+
data: 56,
|
|
2556
|
+
};
|
|
2557
|
+
class $hyoo_crowd_unit_bin extends DataView {
|
|
2558
|
+
static from_buffer(buffer) {
|
|
2559
|
+
const size = Math.ceil(Math.abs(buffer[offset.size / 2]) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
|
|
2560
|
+
return new this(buffer.slice(0, size / 2).buffer);
|
|
2561
|
+
}
|
|
2562
|
+
static from_unit(unit) {
|
|
2563
|
+
if (unit.bin)
|
|
2564
|
+
return unit.bin;
|
|
2565
|
+
const type = unit.data === null
|
|
2566
|
+
? 0
|
|
2567
|
+
: unit.data instanceof Uint8Array
|
|
2568
|
+
? -1
|
|
2569
|
+
: 1;
|
|
2570
|
+
const buff = type === 0 ? null
|
|
2571
|
+
: type > 0 ? $mol_charset_encode(JSON.stringify(unit.data))
|
|
2572
|
+
: unit.data;
|
|
2573
|
+
const size = buff?.byteLength ?? 0;
|
|
2574
|
+
if (type > 0 && size > 2 ** 15 - 1)
|
|
2575
|
+
throw new Error(`Too large json data: ${size} > ${2 ** 15 - 1}`);
|
|
2576
|
+
if (type < 0 && size > 2 ** 15)
|
|
2577
|
+
throw new Error(`Too large binary data: ${size} > ${2 ** 15}`);
|
|
2578
|
+
const total = offset.data + Math.ceil(size / 8) * 8 + $mol_crypto_auditor_sign_size;
|
|
2579
|
+
const mem = new Uint8Array(total);
|
|
2580
|
+
const bin = new $hyoo_crowd_unit_bin(mem.buffer);
|
|
2581
|
+
const land = $mol_int62_from_string(unit.land);
|
|
2582
|
+
bin.setInt32(offset.land_lo, land.lo, true);
|
|
2583
|
+
bin.setInt32(offset.land_hi, land.hi, true);
|
|
2584
|
+
const auth = $mol_int62_from_string(unit.auth);
|
|
2585
|
+
bin.setInt32(offset.auth_lo, auth.lo, true);
|
|
2586
|
+
bin.setInt32(offset.auth_hi, auth.hi, true);
|
|
2587
|
+
const head = $mol_int62_from_string(unit.head);
|
|
2588
|
+
bin.setInt32(offset.head_lo, head.lo, true);
|
|
2589
|
+
bin.setInt32(offset.head_hi, head.hi, true);
|
|
2590
|
+
const self = $mol_int62_from_string(unit.self);
|
|
2591
|
+
bin.setInt32(offset.self_lo, self.lo, true);
|
|
2592
|
+
bin.setInt32(offset.self_hi, self.hi, true);
|
|
2593
|
+
const next = $mol_int62_from_string(unit.next);
|
|
2594
|
+
bin.setInt32(offset.next_lo, next.lo, true);
|
|
2595
|
+
bin.setInt32(offset.next_hi, next.hi, true);
|
|
2596
|
+
const prev = $mol_int62_from_string(unit.prev);
|
|
2597
|
+
bin.setInt32(offset.prev_lo, prev.lo, true);
|
|
2598
|
+
bin.setInt32(offset.prev_hi, prev.hi, true);
|
|
2599
|
+
bin.setInt32(offset.time, unit.time, true);
|
|
2600
|
+
bin.setInt16(offset.size, type * size, true);
|
|
2601
|
+
if (buff)
|
|
2602
|
+
mem.set(buff, offset.data);
|
|
2603
|
+
return bin;
|
|
2604
|
+
}
|
|
2605
|
+
sign(next) {
|
|
2606
|
+
const sign_offset = this.byteOffset + this.byteLength - $mol_crypto_auditor_sign_size;
|
|
2607
|
+
const buff = new Uint8Array(this.buffer, sign_offset, $mol_crypto_auditor_sign_size);
|
|
2608
|
+
if (!next)
|
|
2609
|
+
return buff;
|
|
2610
|
+
buff.set(next);
|
|
2611
|
+
return buff;
|
|
2612
|
+
}
|
|
2613
|
+
size() {
|
|
2614
|
+
return Math.ceil(Math.abs(this.getInt16(offset.size, true)) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
|
|
2615
|
+
}
|
|
2616
|
+
sens() {
|
|
2617
|
+
return new Uint8Array(this.buffer, this.byteOffset, this.size() - $mol_crypto_auditor_sign_size);
|
|
2618
|
+
}
|
|
2619
|
+
unit() {
|
|
2620
|
+
const land = $mol_int62_to_string({
|
|
2621
|
+
lo: this.getInt32(offset.land_lo, true) << 1 >> 1,
|
|
2622
|
+
hi: this.getInt32(offset.land_hi, true) << 1 >> 1,
|
|
2623
|
+
});
|
|
2624
|
+
const auth = $mol_int62_to_string({
|
|
2625
|
+
lo: this.getInt32(offset.auth_lo, true) << 1 >> 1,
|
|
2626
|
+
hi: this.getInt32(offset.auth_hi, true) << 1 >> 1,
|
|
2627
|
+
});
|
|
2628
|
+
const head = $mol_int62_to_string({
|
|
2629
|
+
lo: this.getInt32(offset.head_lo, true) << 1 >> 1,
|
|
2630
|
+
hi: this.getInt32(offset.head_hi, true) << 1 >> 1,
|
|
2631
|
+
});
|
|
2632
|
+
const self = $mol_int62_to_string({
|
|
2633
|
+
lo: this.getInt32(offset.self_lo, true) << 1 >> 1,
|
|
2634
|
+
hi: this.getInt32(offset.self_hi, true) << 1 >> 1,
|
|
2635
|
+
});
|
|
2636
|
+
const next = $mol_int62_to_string({
|
|
2637
|
+
lo: this.getInt32(offset.next_lo, true) << 1 >> 1,
|
|
2638
|
+
hi: this.getInt32(offset.next_hi, true) << 1 >> 1,
|
|
2639
|
+
});
|
|
2640
|
+
const prev = $mol_int62_to_string({
|
|
2641
|
+
lo: this.getInt32(offset.prev_lo, true) << 1 >> 1,
|
|
2642
|
+
hi: this.getInt32(offset.prev_hi, true) << 1 >> 1,
|
|
2643
|
+
});
|
|
2644
|
+
const time = this.getInt32(offset.time, true) << 1 >> 1;
|
|
2645
|
+
const type_size = this.getInt16(offset.size, true);
|
|
2646
|
+
let data = null;
|
|
2647
|
+
if (type_size) {
|
|
2648
|
+
try {
|
|
2649
|
+
var buff = new Uint8Array(this.buffer, this.byteOffset + offset.data, Math.abs(type_size));
|
|
2650
|
+
}
|
|
2651
|
+
catch (error) {
|
|
2652
|
+
error['message'] += `\nhead=${head};self=${self}`;
|
|
2653
|
+
$mol_fail_hidden(error);
|
|
2654
|
+
}
|
|
2655
|
+
if (type_size < 0)
|
|
2656
|
+
data = buff;
|
|
2657
|
+
else
|
|
2658
|
+
data = JSON.parse($mol_charset_decode(buff));
|
|
2659
|
+
}
|
|
2660
|
+
return new $hyoo_crowd_unit(land, auth, head, self, next, prev, time, data, this);
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
$.$hyoo_crowd_unit_bin = $hyoo_crowd_unit_bin;
|
|
2664
|
+
function $hyoo_crowd_unit_compare(left, right) {
|
|
2665
|
+
return (left.group() - right.group())
|
|
2666
|
+
|| (left.time - right.time)
|
|
2667
|
+
|| ((left.auth > right.auth) ? 1 : (left.auth < right.auth) ? -1 : 0)
|
|
2668
|
+
|| ((left.self > right.self) ? 1 : (left.self < right.self) ? -1 : 0)
|
|
2669
|
+
|| ((left.head > right.head) ? 1 : (left.head < right.head) ? -1 : 0)
|
|
2670
|
+
|| ((left.prev > right.prev) ? 1 : (left.prev < right.prev) ? -1 : 0)
|
|
2671
|
+
|| ((left.next > right.next) ? 1 : (left.next < right.next) ? -1 : 0)
|
|
2672
|
+
|| ((left.land > right.land) ? 1 : (left.land < right.land) ? -1 : 0);
|
|
2673
|
+
}
|
|
2674
|
+
$.$hyoo_crowd_unit_compare = $hyoo_crowd_unit_compare;
|
|
2675
|
+
})($ || ($ = {}));
|
|
2676
|
+
//hyoo/crowd/unit/unit.ts
|
|
2677
|
+
;
|
|
2678
|
+
"use strict";
|
|
2679
|
+
var $;
|
|
2680
|
+
(function ($) {
|
|
2681
|
+
function $hyoo_crowd_time_now() {
|
|
2682
|
+
return Math.floor(Date.now() / 100) - 1767e7;
|
|
2683
|
+
}
|
|
2684
|
+
$.$hyoo_crowd_time_now = $hyoo_crowd_time_now;
|
|
2685
|
+
function $hyoo_crowd_time_stamp(time) {
|
|
2686
|
+
return 1767e9 + time * 100;
|
|
2687
|
+
}
|
|
2688
|
+
$.$hyoo_crowd_time_stamp = $hyoo_crowd_time_stamp;
|
|
2689
|
+
})($ || ($ = {}));
|
|
2690
|
+
//hyoo/crowd/time/time.ts
|
|
2691
|
+
;
|
|
2692
|
+
"use strict";
|
|
2693
|
+
var $;
|
|
2694
|
+
(function ($) {
|
|
2695
|
+
class $hyoo_crowd_clock extends Map {
|
|
2696
|
+
static begin = -1 * 2 ** 30;
|
|
2697
|
+
last_time = $hyoo_crowd_clock.begin;
|
|
2698
|
+
constructor(entries) {
|
|
2699
|
+
super(entries);
|
|
2700
|
+
if (!entries)
|
|
2701
|
+
return;
|
|
2702
|
+
for (const [peer, time] of entries) {
|
|
2703
|
+
this.see_time(time);
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
sync(right) {
|
|
2707
|
+
for (const [peer, time] of right) {
|
|
2708
|
+
this.see_peer(peer, time);
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
see_time(time) {
|
|
2712
|
+
if (time < this.last_time)
|
|
2713
|
+
return;
|
|
2714
|
+
this.last_time = time;
|
|
2715
|
+
}
|
|
2716
|
+
see_peer(peer, time) {
|
|
2717
|
+
if (!this.fresh(peer, time))
|
|
2718
|
+
return;
|
|
2719
|
+
this.set(peer, time);
|
|
2720
|
+
this.see_time(time);
|
|
2721
|
+
}
|
|
2722
|
+
see_bin(bin, group) {
|
|
2723
|
+
for (let cursor = offset.clocks; cursor < bin.byteLength; cursor += 16) {
|
|
2724
|
+
this.see_peer($mol_int62_to_string({
|
|
2725
|
+
lo: bin.getInt32(cursor + 0, true) << 1 >> 1,
|
|
2726
|
+
hi: bin.getInt32(cursor + 4, true) << 1 >> 1,
|
|
2727
|
+
}), bin.getInt32(cursor + 8 + 4 * group, true));
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
fresh(peer, time) {
|
|
2731
|
+
return time > this.time(peer);
|
|
2732
|
+
}
|
|
2733
|
+
ahead(clock) {
|
|
2734
|
+
for (const [peer, time] of this) {
|
|
2735
|
+
if (clock.fresh(peer, time))
|
|
2736
|
+
return true;
|
|
2737
|
+
}
|
|
2738
|
+
return false;
|
|
2739
|
+
}
|
|
2740
|
+
time(peer) {
|
|
2741
|
+
return this.get(peer) ?? $hyoo_crowd_clock.begin;
|
|
2742
|
+
}
|
|
2743
|
+
now() {
|
|
2744
|
+
return $hyoo_crowd_time_now();
|
|
2745
|
+
}
|
|
2746
|
+
last_stamp() {
|
|
2747
|
+
return $hyoo_crowd_time_stamp(this.last_time);
|
|
2748
|
+
}
|
|
2749
|
+
tick(peer) {
|
|
2750
|
+
let time = this.now();
|
|
2751
|
+
if (time <= this.last_time) {
|
|
2752
|
+
time = this.last_time + 1;
|
|
2753
|
+
}
|
|
2754
|
+
this.see_peer(peer, time);
|
|
2755
|
+
return time;
|
|
2756
|
+
}
|
|
2757
|
+
[$mol_dev_format_head]() {
|
|
2758
|
+
return $mol_dev_format_span({}, $mol_dev_format_native(this), $mol_dev_format_shade(' ' + new Date(this.last_stamp()).toISOString().replace('T', ' ')));
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
$.$hyoo_crowd_clock = $hyoo_crowd_clock;
|
|
2762
|
+
const offset = {
|
|
2763
|
+
land_lo: 0,
|
|
2764
|
+
land_hi: 4,
|
|
2765
|
+
clocks: 8,
|
|
2766
|
+
};
|
|
2767
|
+
class $hyoo_crowd_clock_bin extends DataView {
|
|
2768
|
+
static from(land_id, clocks) {
|
|
2769
|
+
const size = offset.clocks + clocks[0].size * 16;
|
|
2770
|
+
const mem = new Uint8Array(size);
|
|
2771
|
+
const bin = new $hyoo_crowd_clock_bin(mem.buffer);
|
|
2772
|
+
const land = $mol_int62_from_string(land_id);
|
|
2773
|
+
bin.setInt32(offset.land_lo, land.lo ^ (1 << 31), true);
|
|
2774
|
+
bin.setInt32(offset.land_hi, land.hi, true);
|
|
2775
|
+
let cursor = offset.clocks;
|
|
2776
|
+
for (const [peer_id, time] of clocks[0]) {
|
|
2777
|
+
const peer = $mol_int62_from_string(peer_id);
|
|
2778
|
+
bin.setInt32(cursor + 0, peer.lo, true);
|
|
2779
|
+
bin.setInt32(cursor + 4, peer.hi, true);
|
|
2780
|
+
bin.setInt32(cursor + 8, time, true);
|
|
2781
|
+
bin.setInt32(cursor + 12, clocks[1].get(peer_id) ?? $hyoo_crowd_clock.begin, true);
|
|
2782
|
+
cursor += 16;
|
|
2783
|
+
}
|
|
2784
|
+
return bin;
|
|
2785
|
+
}
|
|
2786
|
+
land() {
|
|
2787
|
+
return $mol_int62_to_string({
|
|
2788
|
+
lo: this.getInt32(offset.land_lo, true) << 1 >> 1,
|
|
2789
|
+
hi: this.getInt32(offset.land_hi, true) << 1 >> 1,
|
|
2790
|
+
});
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
$.$hyoo_crowd_clock_bin = $hyoo_crowd_clock_bin;
|
|
2794
|
+
})($ || ($ = {}));
|
|
2795
|
+
//hyoo/crowd/clock/clock.ts
|
|
2796
|
+
;
|
|
2797
|
+
"use strict";
|
|
2798
|
+
var $;
|
|
2799
|
+
(function ($) {
|
|
2800
|
+
class $hyoo_crowd_node extends $mol_object2 {
|
|
2801
|
+
land;
|
|
2802
|
+
head;
|
|
2803
|
+
constructor(land = new $hyoo_crowd_land, head = '0_0') {
|
|
2804
|
+
super();
|
|
2805
|
+
this.land = land;
|
|
2806
|
+
this.head = head;
|
|
2807
|
+
}
|
|
2808
|
+
static for(land, head) {
|
|
2809
|
+
return new this(land, head);
|
|
2810
|
+
}
|
|
2811
|
+
static toJSON() {
|
|
2812
|
+
return this.name;
|
|
2813
|
+
}
|
|
2814
|
+
id() {
|
|
2815
|
+
return this.head === '0_0'
|
|
2816
|
+
? this.land.id()
|
|
2817
|
+
: `${this.land.id()}!${this.head}`;
|
|
2818
|
+
}
|
|
2819
|
+
world() {
|
|
2820
|
+
return this.land.world();
|
|
2821
|
+
}
|
|
2822
|
+
as(Node) {
|
|
2823
|
+
return this.world()?.Fund(Node).Item(`${this.land.id()}!${this.head}`) ?? new Node(this.land, this.head);
|
|
2824
|
+
}
|
|
2825
|
+
units() {
|
|
2826
|
+
return this.land.unit_alives(this.head);
|
|
2827
|
+
}
|
|
2828
|
+
nodes(Node) {
|
|
2829
|
+
const fund = this.world()?.Fund(Node);
|
|
2830
|
+
return this.units().map(unit => fund?.Item(`${this.land.id()}!${unit.self}`) ?? new Node(this.land, unit.self));
|
|
2831
|
+
}
|
|
2832
|
+
virgin() {
|
|
2833
|
+
return this.land.unit_list(this.head).length === 0;
|
|
2834
|
+
}
|
|
2835
|
+
[Symbol.toPrimitive]() {
|
|
2836
|
+
return `${this.constructor.name}("${this.land.id()}","${this.head}")`;
|
|
2837
|
+
}
|
|
2838
|
+
toJSON() {
|
|
2839
|
+
return this.id();
|
|
2840
|
+
}
|
|
2841
|
+
[$mol_dev_format_head]() {
|
|
2842
|
+
return $mol_dev_format_span({}, $mol_dev_format_native(this), $mol_dev_format_shade(':'), $mol_dev_format_auto(this.land.unit_list(this.head)));
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
__decorate([
|
|
2846
|
+
$mol_mem_key
|
|
2847
|
+
], $hyoo_crowd_node.prototype, "nodes", null);
|
|
2848
|
+
$.$hyoo_crowd_node = $hyoo_crowd_node;
|
|
2849
|
+
})($ || ($ = {}));
|
|
2850
|
+
//hyoo/crowd/node/node.ts
|
|
2851
|
+
;
|
|
2852
|
+
"use strict";
|
|
2853
|
+
var $;
|
|
2854
|
+
(function ($) {
|
|
2855
|
+
class $hyoo_crowd_reg extends $hyoo_crowd_node {
|
|
2856
|
+
value(next) {
|
|
2857
|
+
const unit = this.units()[0];
|
|
2858
|
+
if (next === undefined)
|
|
2859
|
+
return unit?.data ?? null;
|
|
2860
|
+
if ($mol_compare_deep(unit?.data, next))
|
|
2861
|
+
return next;
|
|
2862
|
+
this.land.put(this.head, unit?.self ?? this.land.id_new(), '0_0', next);
|
|
2863
|
+
return next;
|
|
2864
|
+
}
|
|
2865
|
+
str(next) {
|
|
2866
|
+
return String(this.value(next) ?? '');
|
|
2867
|
+
}
|
|
2868
|
+
numb(next) {
|
|
2869
|
+
return Number(this.value(next));
|
|
2870
|
+
}
|
|
2871
|
+
bool(next) {
|
|
2872
|
+
return Boolean(this.value(next));
|
|
2873
|
+
}
|
|
2874
|
+
yoke(law = [''], mod = [], add = []) {
|
|
2875
|
+
const world = this.world();
|
|
2876
|
+
let land_id = $mol_int62_string_ensure(this.value());
|
|
2877
|
+
if (land_id)
|
|
2878
|
+
return world.land_sync(land_id);
|
|
2879
|
+
if (!this.land.allowed_add())
|
|
2880
|
+
return null;
|
|
2881
|
+
const land = $mol_wire_sync(world).grab(law, mod, add);
|
|
2882
|
+
this.value(land.id());
|
|
2883
|
+
world.land_init(land);
|
|
2884
|
+
return land;
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
$.$hyoo_crowd_reg = $hyoo_crowd_reg;
|
|
2888
|
+
})($ || ($ = {}));
|
|
2889
|
+
//hyoo/crowd/reg/reg.ts
|
|
2890
|
+
;
|
|
2891
|
+
"use strict";
|
|
2892
|
+
var $;
|
|
2893
|
+
(function ($) {
|
|
2894
|
+
class $hyoo_crowd_struct extends $hyoo_crowd_node {
|
|
2895
|
+
sub(key, Node) {
|
|
2896
|
+
const head = $mol_int62_hash_string(key + '\n' + this.head);
|
|
2897
|
+
return this.world()?.Fund(Node).Item(`${this.land.id()}!${head}`) ?? new Node(this.land, head);
|
|
2898
|
+
}
|
|
2899
|
+
yoke(key, Node, law = [''], mod = [], add = []) {
|
|
2900
|
+
const land = this.sub(key, $hyoo_crowd_reg).yoke(law, mod, add);
|
|
2901
|
+
return land?.chief.sub(key, Node) ?? null;
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
$.$hyoo_crowd_struct = $hyoo_crowd_struct;
|
|
2905
|
+
})($ || ($ = {}));
|
|
2906
|
+
//hyoo/crowd/struct/struct.ts
|
|
2907
|
+
;
|
|
2908
|
+
"use strict";
|
|
2909
|
+
var $;
|
|
2910
|
+
(function ($) {
|
|
2911
|
+
function $mol_const(value) {
|
|
2912
|
+
const getter = (() => value);
|
|
2913
|
+
getter['()'] = value;
|
|
2914
|
+
getter[Symbol.toStringTag] = value;
|
|
2915
|
+
return getter;
|
|
2916
|
+
}
|
|
2917
|
+
$.$mol_const = $mol_const;
|
|
2918
|
+
})($ || ($ = {}));
|
|
2919
|
+
//mol/const/const.ts
|
|
2920
|
+
;
|
|
2921
|
+
"use strict";
|
|
2922
|
+
var $;
|
|
2923
|
+
(function ($) {
|
|
2924
|
+
class $hyoo_crowd_land extends $mol_object {
|
|
2925
|
+
id() {
|
|
2926
|
+
return $mol_int62_to_string($mol_int62_random());
|
|
2927
|
+
}
|
|
2928
|
+
toJSON() {
|
|
2929
|
+
return this.id();
|
|
2930
|
+
}
|
|
2931
|
+
peer() {
|
|
2932
|
+
return this.world()?.peer;
|
|
2933
|
+
}
|
|
2934
|
+
peer_id() {
|
|
2935
|
+
return this.peer()?.id ?? '0_0';
|
|
2936
|
+
}
|
|
2937
|
+
world() {
|
|
2938
|
+
return null;
|
|
2939
|
+
}
|
|
2940
|
+
get clock_auth() {
|
|
2941
|
+
this.pub.promote();
|
|
2942
|
+
return this._clocks[$hyoo_crowd_unit_group.auth];
|
|
2943
|
+
}
|
|
2944
|
+
get clock_data() {
|
|
2945
|
+
this.pub.promote();
|
|
2946
|
+
return this._clocks[$hyoo_crowd_unit_group.data];
|
|
2947
|
+
}
|
|
2948
|
+
get clocks() {
|
|
2949
|
+
this.pub.promote();
|
|
2950
|
+
return this._clocks;
|
|
2951
|
+
}
|
|
2952
|
+
pub = new $mol_wire_pub;
|
|
2953
|
+
_clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock];
|
|
2954
|
+
_unit_all = new Map();
|
|
2955
|
+
unit(head, self) {
|
|
2956
|
+
return this._unit_all.get(`${head}!${self}`);
|
|
2957
|
+
}
|
|
2958
|
+
_unit_lists = new Map();
|
|
2959
|
+
_unit_alives = new Map();
|
|
2960
|
+
size() {
|
|
2961
|
+
return this._unit_all.size;
|
|
2962
|
+
}
|
|
2963
|
+
unit_list(head) {
|
|
2964
|
+
let kids = this._unit_lists.get(head);
|
|
2965
|
+
if (!kids)
|
|
2966
|
+
this._unit_lists.set(head, kids = Object.assign([], { dirty: false }));
|
|
2967
|
+
return kids;
|
|
2968
|
+
}
|
|
2969
|
+
unit_alives(head) {
|
|
2970
|
+
this.pub.promote();
|
|
2971
|
+
let kids = this._unit_alives.get(head);
|
|
2972
|
+
if (!kids) {
|
|
2973
|
+
const all = this.unit_list(head);
|
|
2974
|
+
if (all.dirty)
|
|
2975
|
+
this.resort(head);
|
|
2976
|
+
kids = all.filter(kid => kid.data !== null);
|
|
2977
|
+
this._unit_alives.set(head, kids);
|
|
2978
|
+
}
|
|
2979
|
+
return kids;
|
|
2980
|
+
}
|
|
2981
|
+
node(head, Node) {
|
|
2982
|
+
return new Node(this, head);
|
|
2983
|
+
}
|
|
2984
|
+
chief = this.node('0_0', $hyoo_crowd_struct);
|
|
2985
|
+
id_new() {
|
|
2986
|
+
for (let i = 0; i < 1000; ++i) {
|
|
2987
|
+
const id = $mol_int62_to_string($mol_int62_random());
|
|
2988
|
+
if (id === '0_0')
|
|
2989
|
+
continue;
|
|
2990
|
+
if (id === this.id())
|
|
2991
|
+
continue;
|
|
2992
|
+
if (this._unit_lists.has(id))
|
|
2993
|
+
continue;
|
|
2994
|
+
return id;
|
|
2995
|
+
}
|
|
2996
|
+
throw new Error(`Can't generate ID after 1000 times`);
|
|
2997
|
+
}
|
|
2998
|
+
fork(auth) {
|
|
2999
|
+
const fork = $hyoo_crowd_land.make({
|
|
3000
|
+
id: $mol_const(this.id()),
|
|
3001
|
+
peer: $mol_const(auth),
|
|
3002
|
+
});
|
|
3003
|
+
return fork.apply(this.delta());
|
|
3004
|
+
}
|
|
3005
|
+
delta(clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock]) {
|
|
3006
|
+
this.pub.promote();
|
|
3007
|
+
const delta = [];
|
|
3008
|
+
for (const unit of this._unit_all.values()) {
|
|
3009
|
+
const time = clocks[unit.group()].time(unit.auth);
|
|
3010
|
+
if (unit.time <= time)
|
|
3011
|
+
continue;
|
|
3012
|
+
delta.push(unit);
|
|
3013
|
+
}
|
|
3014
|
+
delta.sort($hyoo_crowd_unit_compare);
|
|
3015
|
+
return delta;
|
|
3016
|
+
}
|
|
3017
|
+
resort(head) {
|
|
3018
|
+
const kids = this._unit_lists.get(head);
|
|
3019
|
+
if (!kids.dirty)
|
|
3020
|
+
return kids;
|
|
3021
|
+
if (kids.length < 2) {
|
|
3022
|
+
kids.dirty = true;
|
|
3023
|
+
return kids;
|
|
3024
|
+
}
|
|
3025
|
+
const queue = kids.splice(0).sort((left, right) => -$hyoo_crowd_unit_compare(left, right));
|
|
3026
|
+
const locate = (self) => {
|
|
3027
|
+
for (let i = kids.length - 1; i >= 0; --i) {
|
|
3028
|
+
if (kids[i].self === self)
|
|
3029
|
+
return i;
|
|
3030
|
+
}
|
|
3031
|
+
return -1;
|
|
3032
|
+
};
|
|
3033
|
+
while (queue.length) {
|
|
3034
|
+
kids.push(queue.pop());
|
|
3035
|
+
for (let cursor = queue.length - 1; cursor >= 0; --cursor) {
|
|
3036
|
+
const kid = queue[cursor];
|
|
3037
|
+
let index = 0;
|
|
3038
|
+
if (kid.prev !== '0_0') {
|
|
3039
|
+
index = locate(kid.prev) + 1;
|
|
3040
|
+
if (!index)
|
|
3041
|
+
continue;
|
|
3042
|
+
}
|
|
3043
|
+
while (kids[index] && ($hyoo_crowd_unit_compare(kids[index], kid) > 0))
|
|
3044
|
+
++index;
|
|
3045
|
+
const exists = locate(kid.self);
|
|
3046
|
+
if (index === exists) {
|
|
3047
|
+
if (cursor === queue.length - 1)
|
|
3048
|
+
queue.pop();
|
|
3049
|
+
continue;
|
|
3050
|
+
}
|
|
3051
|
+
if (exists >= 0) {
|
|
3052
|
+
kids.splice(exists, 1);
|
|
3053
|
+
if (exists < index)
|
|
3054
|
+
--index;
|
|
3055
|
+
}
|
|
3056
|
+
kids.splice(index, 0, kid);
|
|
3057
|
+
if (cursor === queue.length - 1)
|
|
3058
|
+
queue.pop();
|
|
3059
|
+
cursor = queue.length;
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
kids.dirty = false;
|
|
3063
|
+
return kids;
|
|
3064
|
+
}
|
|
3065
|
+
apply(delta) {
|
|
3066
|
+
for (const next of delta) {
|
|
3067
|
+
this._clocks[next.group()].see_peer(next.auth, next.time);
|
|
3068
|
+
const kids = this.unit_list(next.head);
|
|
3069
|
+
const next_id = `${next.head}!${next.self}`;
|
|
3070
|
+
let prev = this._unit_all.get(next_id);
|
|
3071
|
+
if (prev) {
|
|
3072
|
+
if ($hyoo_crowd_unit_compare(prev, next) > 0)
|
|
3073
|
+
continue;
|
|
3074
|
+
kids[kids.indexOf(prev)] = next;
|
|
3075
|
+
}
|
|
3076
|
+
else {
|
|
3077
|
+
kids.push(next);
|
|
3078
|
+
}
|
|
3079
|
+
this._unit_all.set(next_id, next);
|
|
3080
|
+
if (kids.length > 1)
|
|
3081
|
+
kids.dirty = true;
|
|
3082
|
+
this._unit_alives.set(next.head, undefined);
|
|
3083
|
+
}
|
|
3084
|
+
this.pub.emit();
|
|
3085
|
+
return this;
|
|
3086
|
+
}
|
|
3087
|
+
_joined = false;
|
|
3088
|
+
join() {
|
|
3089
|
+
if (this._joined)
|
|
3090
|
+
return;
|
|
3091
|
+
const auth = this.peer();
|
|
3092
|
+
if (!auth)
|
|
3093
|
+
return;
|
|
3094
|
+
if (!auth.key_public_serial)
|
|
3095
|
+
return;
|
|
3096
|
+
const auth_id = `${auth.id}!${auth.id}`;
|
|
3097
|
+
const auth_unit = this._unit_all.get(auth_id);
|
|
3098
|
+
if (auth_unit?.data)
|
|
3099
|
+
return this._joined = true;
|
|
3100
|
+
const time = this._clocks[$hyoo_crowd_unit_group.auth].tick(auth.id);
|
|
3101
|
+
const join_unit = new $hyoo_crowd_unit(this.id(), auth.id, auth.id, auth.id, '0_0', '0_0', time, auth.key_public_serial, null);
|
|
3102
|
+
this._unit_all.set(auth_id, join_unit);
|
|
3103
|
+
this._joined = true;
|
|
3104
|
+
this.pub.emit();
|
|
3105
|
+
}
|
|
3106
|
+
leave() {
|
|
3107
|
+
const auth = this.peer();
|
|
3108
|
+
if (!auth)
|
|
3109
|
+
return;
|
|
3110
|
+
if (!auth.key_public_serial)
|
|
3111
|
+
return;
|
|
3112
|
+
const auth_id = `${auth.id}!${auth.id}`;
|
|
3113
|
+
const auth_unit = this._unit_all.get(auth_id);
|
|
3114
|
+
if (!auth_unit || !auth_unit.data)
|
|
3115
|
+
return this._joined = false;
|
|
3116
|
+
const time = this._clocks[$hyoo_crowd_unit_group.auth].tick(auth.id);
|
|
3117
|
+
const join_unit = new $hyoo_crowd_unit(this.id(), auth.id, auth.id, auth.id, '0_0', '0_0', time, null, null);
|
|
3118
|
+
this._unit_all.set(auth_id, join_unit);
|
|
3119
|
+
this._joined = false;
|
|
3120
|
+
this.pub.emit();
|
|
3121
|
+
}
|
|
3122
|
+
allowed_add(peer = this.peer().id) {
|
|
3123
|
+
return this.level(peer) >= $hyoo_crowd_peer_level.add;
|
|
3124
|
+
}
|
|
3125
|
+
allowed_mod(peer = this.peer().id) {
|
|
3126
|
+
return this.level(peer) >= $hyoo_crowd_peer_level.mod;
|
|
3127
|
+
}
|
|
3128
|
+
allowed_law(peer = this.peer().id) {
|
|
3129
|
+
return this.level(peer) >= $hyoo_crowd_peer_level.law;
|
|
3130
|
+
}
|
|
3131
|
+
level_base(next) {
|
|
3132
|
+
this.level('0_0', next);
|
|
3133
|
+
}
|
|
3134
|
+
level(peer, next) {
|
|
3135
|
+
if (next)
|
|
3136
|
+
this.join();
|
|
3137
|
+
else
|
|
3138
|
+
this.pub.promote();
|
|
3139
|
+
if (!peer)
|
|
3140
|
+
peer = this.peer_id();
|
|
3141
|
+
const level_id = `${this.id()}!${peer}`;
|
|
3142
|
+
const prev = this._unit_all.get(level_id)?.level()
|
|
3143
|
+
?? this._unit_all.get(`${this.id()}!0_0`)?.level()
|
|
3144
|
+
?? (this.id() === peer ? $hyoo_crowd_peer_level.law : $hyoo_crowd_peer_level.get);
|
|
3145
|
+
if (next === undefined)
|
|
3146
|
+
return prev;
|
|
3147
|
+
if (next <= prev)
|
|
3148
|
+
return prev;
|
|
3149
|
+
if (!this.allowed_law())
|
|
3150
|
+
return prev;
|
|
3151
|
+
const time = this._clocks[$hyoo_crowd_unit_group.auth].tick(peer);
|
|
3152
|
+
const auth = this.peer_id();
|
|
3153
|
+
const level_unit = new $hyoo_crowd_unit(this.id(), auth, this.id(), peer, '0_0', '0_0', time, next, null);
|
|
3154
|
+
this._unit_all.set(level_id, level_unit);
|
|
3155
|
+
this.pub.emit();
|
|
3156
|
+
return next;
|
|
3157
|
+
}
|
|
3158
|
+
grabbed() {
|
|
3159
|
+
if (this.id() === this.peer_id())
|
|
3160
|
+
return true;
|
|
3161
|
+
this.pub.promote();
|
|
3162
|
+
return this._unit_all.size > 0;
|
|
3163
|
+
}
|
|
3164
|
+
peers() {
|
|
3165
|
+
this.pub.promote();
|
|
3166
|
+
const lords = [];
|
|
3167
|
+
for (const unit of this._unit_all.values()) {
|
|
3168
|
+
switch (unit.kind()) {
|
|
3169
|
+
case $hyoo_crowd_unit_kind.data: continue;
|
|
3170
|
+
case $hyoo_crowd_unit_kind.join: continue;
|
|
3171
|
+
default: lords.push(unit.self);
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
return lords;
|
|
3175
|
+
}
|
|
3176
|
+
residents() {
|
|
3177
|
+
this.pub.promote();
|
|
3178
|
+
const lords = [];
|
|
3179
|
+
for (const unit of this._unit_all.values()) {
|
|
3180
|
+
if (unit.data === null)
|
|
3181
|
+
continue;
|
|
3182
|
+
if (unit.kind() !== $hyoo_crowd_unit_kind.join)
|
|
3183
|
+
continue;
|
|
3184
|
+
lords.push(unit.self);
|
|
3185
|
+
}
|
|
3186
|
+
return lords;
|
|
3187
|
+
}
|
|
3188
|
+
authors() {
|
|
3189
|
+
this.pub.promote();
|
|
3190
|
+
const authors = new Set();
|
|
3191
|
+
for (const unit of this._unit_all.values()) {
|
|
3192
|
+
if (unit.kind() !== $hyoo_crowd_unit_kind.data)
|
|
3193
|
+
continue;
|
|
3194
|
+
if (unit.data === null)
|
|
3195
|
+
continue;
|
|
3196
|
+
authors.add(unit.auth);
|
|
3197
|
+
}
|
|
3198
|
+
return authors;
|
|
3199
|
+
}
|
|
3200
|
+
steal_rights(donor) {
|
|
3201
|
+
if (!this.allowed_law())
|
|
3202
|
+
return;
|
|
3203
|
+
for (const peer of donor.peers()) {
|
|
3204
|
+
this.level(peer, donor.level(peer));
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
3207
|
+
first_stamp() {
|
|
3208
|
+
this.pub.promote();
|
|
3209
|
+
const grab_unit = this._unit_all.get(`${this.id()}!${this.id()}`);
|
|
3210
|
+
return (grab_unit && $hyoo_crowd_time_stamp(grab_unit.time)) ?? null;
|
|
3211
|
+
}
|
|
3212
|
+
last_stamp() {
|
|
3213
|
+
this.pub.promote();
|
|
3214
|
+
return this.clock_data.last_stamp();
|
|
3215
|
+
}
|
|
3216
|
+
selection(peer) {
|
|
3217
|
+
return this.world().land_sync(peer).chief.sub('$hyoo_crowd_land..selection', $hyoo_crowd_reg);
|
|
3218
|
+
}
|
|
3219
|
+
put(head, self, prev, data) {
|
|
3220
|
+
this.join();
|
|
3221
|
+
const old_id = `${head}!${self}`;
|
|
3222
|
+
let unit_old = this._unit_all.get(old_id);
|
|
3223
|
+
let unit_prev = prev !== '0_0'
|
|
3224
|
+
? this._unit_all.get(`${head}!${prev}`)
|
|
3225
|
+
: null;
|
|
3226
|
+
const unit_list = this.unit_list(head);
|
|
3227
|
+
if (unit_old)
|
|
3228
|
+
unit_list.splice(unit_list.indexOf(unit_old), 1);
|
|
3229
|
+
const seat = unit_prev ? unit_list.indexOf(unit_prev) + 1 : 0;
|
|
3230
|
+
const next = unit_list[seat]?.self ?? '0_0';
|
|
3231
|
+
const auth = this.peer_id();
|
|
3232
|
+
const time = this._clocks[$hyoo_crowd_unit_group.data].tick(auth);
|
|
3233
|
+
const unit_new = new $hyoo_crowd_unit(this.id(), auth, head, self, next, prev, time, data, null);
|
|
3234
|
+
this._unit_all.set(old_id, unit_new);
|
|
3235
|
+
unit_list.splice(seat, 0, unit_new);
|
|
3236
|
+
this._unit_alives.set(head, undefined);
|
|
3237
|
+
this.pub.emit();
|
|
3238
|
+
return unit_new;
|
|
3239
|
+
}
|
|
3240
|
+
wipe(unit) {
|
|
3241
|
+
if (unit.data === null)
|
|
3242
|
+
return unit;
|
|
3243
|
+
const unit_list = this.unit_list(unit.head);
|
|
3244
|
+
const seat = unit_list.indexOf(unit);
|
|
3245
|
+
const prev = seat > 0 ? unit_list[seat - 1].self : seat < 0 ? unit.prev : '0_0';
|
|
3246
|
+
return this.put(unit.head, unit.self, prev, null);
|
|
3247
|
+
}
|
|
3248
|
+
move(unit, head, prev) {
|
|
3249
|
+
const unit_list = this.unit_list(unit.head);
|
|
3250
|
+
const seat = unit_list.indexOf(unit);
|
|
3251
|
+
const next = unit_list[seat + 1];
|
|
3252
|
+
this.wipe(unit);
|
|
3253
|
+
if (next)
|
|
3254
|
+
this.put(next.head, next.self, unit_list[unit_list.indexOf(next) - 2]?.self ?? '0_0', next.data);
|
|
3255
|
+
this.put(head, unit.self, prev, unit.data);
|
|
3256
|
+
}
|
|
3257
|
+
insert(unit, head, seat) {
|
|
3258
|
+
const list = this.unit_list(head);
|
|
3259
|
+
const prev = seat ? list[seat - 1].self : '0_0';
|
|
3260
|
+
return this.move(unit, head, prev);
|
|
3261
|
+
}
|
|
3262
|
+
[$mol_dev_format_head]() {
|
|
3263
|
+
return $mol_dev_format_native(this);
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
__decorate([
|
|
3267
|
+
$mol_memo.method
|
|
3268
|
+
], $hyoo_crowd_land.prototype, "id", null);
|
|
3269
|
+
$.$hyoo_crowd_land = $hyoo_crowd_land;
|
|
3270
|
+
})($ || ($ = {}));
|
|
3271
|
+
//hyoo/crowd/land/land.ts
|
|
3272
|
+
;
|
|
3273
|
+
"use strict";
|
|
3274
|
+
var $;
|
|
3275
|
+
(function ($) {
|
|
3276
|
+
$.$mol_action = $mol_wire_method;
|
|
3277
|
+
})($ || ($ = {}));
|
|
3278
|
+
//mol/action/action.ts
|
|
3279
|
+
;
|
|
3280
|
+
"use strict";
|
|
3281
|
+
var $;
|
|
3282
|
+
(function ($) {
|
|
3283
|
+
class $hyoo_crowd_fund extends $mol_object {
|
|
3284
|
+
world;
|
|
3285
|
+
Node;
|
|
3286
|
+
constructor(world, Node) {
|
|
3287
|
+
super();
|
|
3288
|
+
this.world = world;
|
|
3289
|
+
this.Node = Node;
|
|
3290
|
+
}
|
|
3291
|
+
Item(id) {
|
|
3292
|
+
const [land, head] = id.split('!');
|
|
3293
|
+
if (!head)
|
|
3294
|
+
return this.Item(`${land}!0_0`);
|
|
3295
|
+
return this.world.land_sync(land).node(head, this.Node);
|
|
3296
|
+
}
|
|
3297
|
+
make(law = [''], mod = [], add = []) {
|
|
3298
|
+
const land = $mol_wire_sync(this.world).grab(law, mod, add);
|
|
3299
|
+
return this.Item(land.id());
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
__decorate([
|
|
3303
|
+
$mol_mem_key
|
|
3304
|
+
], $hyoo_crowd_fund.prototype, "Item", null);
|
|
3305
|
+
__decorate([
|
|
3306
|
+
$mol_action
|
|
3307
|
+
], $hyoo_crowd_fund.prototype, "make", null);
|
|
3308
|
+
$.$hyoo_crowd_fund = $hyoo_crowd_fund;
|
|
3309
|
+
})($ || ($ = {}));
|
|
3310
|
+
//hyoo/crowd/fund/fund.ts
|
|
3311
|
+
;
|
|
3312
|
+
"use strict";
|
|
3313
|
+
var $;
|
|
3314
|
+
(function ($) {
|
|
3315
|
+
$.$mol_dict_key = $mol_key;
|
|
3316
|
+
class $mol_dict extends Map {
|
|
3317
|
+
get(key) {
|
|
3318
|
+
return super.get($mol_key(key));
|
|
3319
|
+
}
|
|
3320
|
+
has(key) {
|
|
3321
|
+
return super.has($mol_key(key));
|
|
3322
|
+
}
|
|
3323
|
+
set(key, value) {
|
|
3324
|
+
return super.set($mol_key(key), value);
|
|
3325
|
+
}
|
|
3326
|
+
delete(key) {
|
|
3327
|
+
return super.delete($mol_key(key));
|
|
3328
|
+
}
|
|
3329
|
+
forEach(back, context) {
|
|
3330
|
+
return super.forEach((val, key, dict) => {
|
|
3331
|
+
if (typeof key === 'string')
|
|
3332
|
+
key = JSON.parse(key);
|
|
3333
|
+
return back.call(this, val, key, dict);
|
|
3334
|
+
}, context);
|
|
3335
|
+
}
|
|
3336
|
+
keys() {
|
|
3337
|
+
const iterator = super.keys();
|
|
3338
|
+
return {
|
|
3339
|
+
[Symbol.iterator]() {
|
|
3340
|
+
return this;
|
|
3341
|
+
},
|
|
3342
|
+
next() {
|
|
3343
|
+
const iteration = iterator.next();
|
|
3344
|
+
if (iteration.done)
|
|
3345
|
+
return iteration;
|
|
3346
|
+
iteration.value = JSON.parse(iteration.value);
|
|
3347
|
+
return iteration;
|
|
3348
|
+
}
|
|
3349
|
+
};
|
|
3350
|
+
}
|
|
3351
|
+
entries() {
|
|
3352
|
+
const iterator = super.entries();
|
|
3353
|
+
return {
|
|
3354
|
+
[Symbol.iterator]() {
|
|
3355
|
+
return this;
|
|
3356
|
+
},
|
|
3357
|
+
next() {
|
|
3358
|
+
const iteration = iterator.next();
|
|
3359
|
+
if (iteration.done)
|
|
3360
|
+
return iteration;
|
|
3361
|
+
iteration.value = [JSON.parse(iteration.value[0]), iteration.value[1]];
|
|
3362
|
+
return iteration;
|
|
3363
|
+
}
|
|
3364
|
+
};
|
|
3365
|
+
}
|
|
3366
|
+
[Symbol.iterator]() {
|
|
3367
|
+
return this.entries();
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
$.$mol_dict = $mol_dict;
|
|
3371
|
+
})($ || ($ = {}));
|
|
3372
|
+
//mol/dict/dict.ts
|
|
3373
|
+
;
|
|
3374
|
+
"use strict";
|
|
3375
|
+
var $;
|
|
3376
|
+
(function ($) {
|
|
3377
|
+
class $hyoo_crowd_world extends $mol_object {
|
|
3378
|
+
peer;
|
|
3379
|
+
constructor(peer) {
|
|
3380
|
+
super();
|
|
3381
|
+
this.peer = peer;
|
|
3382
|
+
if (peer)
|
|
3383
|
+
this._knights.set(peer.id, peer);
|
|
3384
|
+
}
|
|
3385
|
+
lands_pub = new $mol_wire_pub;
|
|
3386
|
+
_lands = new Map();
|
|
3387
|
+
get lands() {
|
|
3388
|
+
this.lands_pub.promote();
|
|
3389
|
+
return this._lands;
|
|
3390
|
+
}
|
|
3391
|
+
land_init(id) { }
|
|
3392
|
+
land(id) {
|
|
3393
|
+
const exists = this._lands.get(id);
|
|
3394
|
+
if (exists)
|
|
3395
|
+
return exists;
|
|
3396
|
+
const land = $hyoo_crowd_land.make({
|
|
3397
|
+
id: $mol_const(id),
|
|
3398
|
+
world: $mol_const(this),
|
|
3399
|
+
});
|
|
3400
|
+
this._lands.set(id, land);
|
|
3401
|
+
this.lands_pub.emit();
|
|
3402
|
+
return land;
|
|
3403
|
+
}
|
|
3404
|
+
land_sync(id) {
|
|
3405
|
+
const land = this.land(id);
|
|
3406
|
+
this.land_init(land);
|
|
3407
|
+
return land;
|
|
3408
|
+
}
|
|
3409
|
+
Fund(Item) {
|
|
3410
|
+
return new $hyoo_crowd_fund(this, Item);
|
|
3411
|
+
}
|
|
3412
|
+
home() {
|
|
3413
|
+
return this.land_sync(this.peer.id);
|
|
3414
|
+
}
|
|
3415
|
+
_knights = new $mol_dict();
|
|
3416
|
+
_signs = new WeakMap();
|
|
3417
|
+
async grab(law = [''], mod = [], add = []) {
|
|
3418
|
+
const knight = await $hyoo_crowd_peer.generate();
|
|
3419
|
+
this._knights.set(knight.id, knight);
|
|
3420
|
+
const land_inner = this.land(knight.id);
|
|
3421
|
+
const land_outer = $hyoo_crowd_land.make({
|
|
3422
|
+
id: $mol_const(knight.id),
|
|
3423
|
+
peer: $mol_const(knight),
|
|
3424
|
+
});
|
|
3425
|
+
for (const peer of law)
|
|
3426
|
+
land_outer.level(peer || this.peer.id, $hyoo_crowd_peer_level.law);
|
|
3427
|
+
for (const peer of mod)
|
|
3428
|
+
land_outer.level(peer || this.peer.id, $hyoo_crowd_peer_level.mod);
|
|
3429
|
+
for (const peer of add)
|
|
3430
|
+
land_outer.level(peer || this.peer.id, $hyoo_crowd_peer_level.add);
|
|
3431
|
+
land_inner.apply(land_outer.delta());
|
|
3432
|
+
return land_inner;
|
|
3433
|
+
}
|
|
3434
|
+
sign_units(units) {
|
|
3435
|
+
return Promise.all(units.map(async (unit) => {
|
|
3436
|
+
if (unit.bin)
|
|
3437
|
+
return unit;
|
|
3438
|
+
const bin = $hyoo_crowd_unit_bin.from_unit(unit);
|
|
3439
|
+
let sign = this._signs.get(unit);
|
|
3440
|
+
if (!sign) {
|
|
3441
|
+
const knight = this._knights.get(unit.auth);
|
|
3442
|
+
sign = new Uint8Array(await knight.key_private.sign(bin.sens()));
|
|
3443
|
+
}
|
|
3444
|
+
bin.sign(sign);
|
|
3445
|
+
unit.bin = bin;
|
|
3446
|
+
this._signs.set(unit, sign);
|
|
3447
|
+
return unit;
|
|
3448
|
+
}));
|
|
3449
|
+
}
|
|
3450
|
+
delta_land(land, clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock]) {
|
|
3451
|
+
return this.sign_units(land.delta(clocks));
|
|
3452
|
+
}
|
|
3453
|
+
async delta_batch(land, clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock]) {
|
|
3454
|
+
const units = await this.delta_land(land, clocks);
|
|
3455
|
+
let size = 0;
|
|
3456
|
+
const bins = [];
|
|
3457
|
+
for (const unit of units) {
|
|
3458
|
+
const bin = unit.bin;
|
|
3459
|
+
bins.push(bin);
|
|
3460
|
+
size += bin.byteLength;
|
|
3461
|
+
}
|
|
3462
|
+
const batch = new Uint8Array(size);
|
|
3463
|
+
let offset = 0;
|
|
3464
|
+
for (const bin of bins) {
|
|
3465
|
+
batch.set(new Uint8Array(bin.buffer, bin.byteOffset, bin.byteLength), offset);
|
|
3466
|
+
offset += bin.byteLength;
|
|
3467
|
+
}
|
|
3468
|
+
return batch;
|
|
3469
|
+
}
|
|
3470
|
+
async *delta(clocks = new Map()) {
|
|
3471
|
+
for (const land of this.lands.values()) {
|
|
3472
|
+
const batch = await this.delta_batch(land, clocks.get(land.id()));
|
|
3473
|
+
if (batch.length)
|
|
3474
|
+
yield batch;
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
async merge(donor) {
|
|
3478
|
+
for await (const batch of donor.delta())
|
|
3479
|
+
await this.apply(batch);
|
|
3480
|
+
}
|
|
3481
|
+
async apply(delta) {
|
|
3482
|
+
const units = [];
|
|
3483
|
+
let bin_offset = 0;
|
|
3484
|
+
while (bin_offset < delta.byteLength) {
|
|
3485
|
+
const buf = new Int16Array(delta.buffer, delta.byteOffset + bin_offset);
|
|
3486
|
+
const bin = $hyoo_crowd_unit_bin.from_buffer(buf);
|
|
3487
|
+
units.push(bin.unit());
|
|
3488
|
+
bin_offset += bin.size();
|
|
3489
|
+
}
|
|
3490
|
+
const land = this.land(units[0].land);
|
|
3491
|
+
const report = await this.audit_delta(land, units);
|
|
3492
|
+
land.apply(report.allow);
|
|
3493
|
+
return report;
|
|
3494
|
+
}
|
|
3495
|
+
async audit_delta(land, delta) {
|
|
3496
|
+
const all = new Map();
|
|
3497
|
+
const desync = 60 * 60 * 10;
|
|
3498
|
+
const deadline = land.clock_data.now() + desync;
|
|
3499
|
+
const get_unit = (id) => {
|
|
3500
|
+
return all.get(id) ?? land._unit_all.get(id);
|
|
3501
|
+
};
|
|
3502
|
+
const get_level = (head, self) => {
|
|
3503
|
+
return get_unit(`${head}!${self}`)?.level()
|
|
3504
|
+
?? get_unit(`${head}!0_0`)?.level()
|
|
3505
|
+
?? $hyoo_crowd_peer_level.get;
|
|
3506
|
+
};
|
|
3507
|
+
const check_unit = async (unit) => {
|
|
3508
|
+
const bin = unit.bin;
|
|
3509
|
+
if (unit.time > deadline)
|
|
3510
|
+
return 'Far future';
|
|
3511
|
+
const auth_unit = get_unit(`${unit.auth}!${unit.auth}`);
|
|
3512
|
+
const kind = unit.kind();
|
|
3513
|
+
switch (kind) {
|
|
3514
|
+
case $hyoo_crowd_unit_kind.grab:
|
|
3515
|
+
case $hyoo_crowd_unit_kind.join: {
|
|
3516
|
+
const key_str = auth_unit?.data ?? unit.data;
|
|
3517
|
+
if (typeof key_str !== 'string')
|
|
3518
|
+
return 'No join key';
|
|
3519
|
+
const self = $mol_int62_hash_string(key_str);
|
|
3520
|
+
if (unit.self !== self)
|
|
3521
|
+
return 'Alien join key';
|
|
3522
|
+
const key = await $mol_crypto_auditor_public.from(key_str);
|
|
3523
|
+
const sign = bin.sign();
|
|
3524
|
+
const valid = await key.verify(bin.sens(), sign);
|
|
3525
|
+
if (!valid)
|
|
3526
|
+
return 'Wrong join sign';
|
|
3527
|
+
all.set(`${unit.head}!${unit.auth}`, unit);
|
|
3528
|
+
this._signs.set(unit, sign);
|
|
3529
|
+
return '';
|
|
3530
|
+
}
|
|
3531
|
+
case $hyoo_crowd_unit_kind.give: {
|
|
3532
|
+
const lord_level = get_level(land.id(), unit.auth);
|
|
3533
|
+
if (lord_level < $hyoo_crowd_peer_level.law)
|
|
3534
|
+
return `Level too low`;
|
|
3535
|
+
const peer_level = get_level(land.id(), unit.self);
|
|
3536
|
+
if (peer_level > unit.level())
|
|
3537
|
+
return `Cancel unsupported`;
|
|
3538
|
+
break;
|
|
3539
|
+
}
|
|
3540
|
+
case $hyoo_crowd_unit_kind.data: {
|
|
3541
|
+
const level = get_level(land.id(), unit.auth);
|
|
3542
|
+
if (level >= $hyoo_crowd_peer_level.mod)
|
|
3543
|
+
break;
|
|
3544
|
+
if (level === $hyoo_crowd_peer_level.add) {
|
|
3545
|
+
const exists = get_unit(`${unit.head}!${unit.self}`);
|
|
3546
|
+
if (!exists)
|
|
3547
|
+
break;
|
|
3548
|
+
if (exists.auth === unit.auth)
|
|
3549
|
+
break;
|
|
3550
|
+
}
|
|
3551
|
+
return `Level too low`;
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
const key_str = auth_unit?.data;
|
|
3555
|
+
if (typeof key_str !== 'string')
|
|
3556
|
+
return 'No auth key';
|
|
3557
|
+
const key = await $mol_crypto_auditor_public.from(key_str);
|
|
3558
|
+
const sign = bin.sign();
|
|
3559
|
+
const valid = await key.verify(bin.sens(), sign);
|
|
3560
|
+
if (!valid)
|
|
3561
|
+
return 'Wrong auth sign';
|
|
3562
|
+
all.set(`${unit.head}!${unit.self}`, unit);
|
|
3563
|
+
this._signs.set(unit, sign);
|
|
3564
|
+
return '';
|
|
3565
|
+
};
|
|
3566
|
+
const allow = [];
|
|
3567
|
+
const forbid = new Map();
|
|
3568
|
+
const proceed_unit = async (unit) => {
|
|
3569
|
+
const error = await check_unit(unit);
|
|
3570
|
+
if (error)
|
|
3571
|
+
forbid.set(unit, error);
|
|
3572
|
+
else
|
|
3573
|
+
allow.push(unit);
|
|
3574
|
+
};
|
|
3575
|
+
const tasks = [];
|
|
3576
|
+
for (const unit of delta) {
|
|
3577
|
+
const task = proceed_unit(unit);
|
|
3578
|
+
tasks.push(task);
|
|
3579
|
+
if (unit.group() === $hyoo_crowd_unit_group.auth)
|
|
3580
|
+
await task;
|
|
3581
|
+
}
|
|
3582
|
+
await Promise.all(tasks);
|
|
3583
|
+
return { allow, forbid };
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
__decorate([
|
|
3587
|
+
$mol_mem_key
|
|
3588
|
+
], $hyoo_crowd_world.prototype, "Fund", null);
|
|
3589
|
+
$.$hyoo_crowd_world = $hyoo_crowd_world;
|
|
3590
|
+
})($ || ($ = {}));
|
|
3591
|
+
//hyoo/crowd/world/world.ts
|
|
3592
|
+
;
|
|
3593
|
+
"use strict";
|
|
3594
|
+
var $;
|
|
3595
|
+
(function ($) {
|
|
3596
|
+
function $mol_promise() {
|
|
3597
|
+
let done;
|
|
3598
|
+
let fail;
|
|
3599
|
+
const promise = new Promise((d, f) => {
|
|
3600
|
+
done = d;
|
|
3601
|
+
fail = f;
|
|
3602
|
+
});
|
|
3603
|
+
return Object.assign(promise, {
|
|
3604
|
+
done,
|
|
3605
|
+
fail,
|
|
3606
|
+
});
|
|
3607
|
+
}
|
|
3608
|
+
$.$mol_promise = $mol_promise;
|
|
3609
|
+
})($ || ($ = {}));
|
|
3610
|
+
//mol/promise/promise/promise.ts
|
|
3611
|
+
;
|
|
3612
|
+
"use strict";
|
|
3613
|
+
var $;
|
|
3614
|
+
(function ($) {
|
|
3615
|
+
function $mol_wait_timeout_async(timeout) {
|
|
3616
|
+
const promise = $mol_promise();
|
|
3617
|
+
const task = new this.$mol_after_timeout(timeout, () => promise.done());
|
|
3618
|
+
return Object.assign(promise, {
|
|
3619
|
+
destructor: () => task.destructor()
|
|
3620
|
+
});
|
|
3621
|
+
}
|
|
3622
|
+
$.$mol_wait_timeout_async = $mol_wait_timeout_async;
|
|
3623
|
+
function $mol_wait_timeout(timeout) {
|
|
3624
|
+
return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
|
|
3625
|
+
}
|
|
3626
|
+
$.$mol_wait_timeout = $mol_wait_timeout;
|
|
3627
|
+
})($ || ($ = {}));
|
|
3628
|
+
//mol/wait/timeout/timeout.ts
|
|
3629
|
+
;
|
|
3630
|
+
"use strict";
|
|
3631
|
+
var $;
|
|
3632
|
+
(function ($) {
|
|
3633
|
+
function $mol_wire_race(...tasks) {
|
|
3634
|
+
const results = tasks.map(task => {
|
|
3635
|
+
try {
|
|
3636
|
+
return task();
|
|
3637
|
+
}
|
|
3638
|
+
catch (error) {
|
|
3639
|
+
return error;
|
|
3640
|
+
}
|
|
3641
|
+
});
|
|
3642
|
+
const promises = results.filter(res => $mol_promise_like(res));
|
|
3643
|
+
if (promises.length)
|
|
3644
|
+
$mol_fail(Promise.race(promises));
|
|
3645
|
+
const error = results.find(res => res instanceof Error);
|
|
3646
|
+
if (error)
|
|
3647
|
+
$mol_fail(error);
|
|
3648
|
+
return results;
|
|
3649
|
+
}
|
|
3650
|
+
$.$mol_wire_race = $mol_wire_race;
|
|
3651
|
+
})($ || ($ = {}));
|
|
3652
|
+
//mol/wire/race/race.ts
|
|
3653
|
+
;
|
|
3654
|
+
"use strict";
|
|
3655
|
+
var $;
|
|
3656
|
+
(function ($) {
|
|
3657
|
+
$.$hyoo_sync_masters = [
|
|
3658
|
+
`sync.hyoo.ru`,
|
|
3659
|
+
`crowd.up.railway.app`,
|
|
3660
|
+
`crowd2.up.railway.app`,
|
|
3661
|
+
];
|
|
3662
|
+
})($ || ($ = {}));
|
|
3663
|
+
//hyoo/sync/masters/masters.ts
|
|
3664
|
+
;
|
|
3665
|
+
"use strict";
|
|
3666
|
+
var $;
|
|
3667
|
+
(function ($) {
|
|
3668
|
+
function $mol_wire_async(obj) {
|
|
3669
|
+
let fiber;
|
|
3670
|
+
const temp = $mol_wire_task.getter(obj);
|
|
3671
|
+
return new Proxy(obj, {
|
|
3672
|
+
get(obj, field) {
|
|
3673
|
+
const val = obj[field];
|
|
3674
|
+
if (typeof val !== 'function')
|
|
3675
|
+
return val;
|
|
3676
|
+
let fiber;
|
|
3677
|
+
const temp = $mol_wire_task.getter(val);
|
|
3678
|
+
return function $mol_wire_async(...args) {
|
|
3679
|
+
fiber?.destructor();
|
|
3680
|
+
fiber = temp(obj, args);
|
|
3681
|
+
return fiber.async();
|
|
3682
|
+
};
|
|
3683
|
+
},
|
|
3684
|
+
apply(obj, self, args) {
|
|
3685
|
+
fiber?.destructor();
|
|
3686
|
+
fiber = temp(self, args);
|
|
3687
|
+
return fiber.async();
|
|
3688
|
+
},
|
|
3689
|
+
});
|
|
3690
|
+
}
|
|
3691
|
+
$.$mol_wire_async = $mol_wire_async;
|
|
3692
|
+
})($ || ($ = {}));
|
|
3693
|
+
//mol/wire/async/async.ts
|
|
3694
|
+
;
|
|
3695
|
+
"use strict";
|
|
3696
|
+
var $;
|
|
3697
|
+
(function ($) {
|
|
3698
|
+
class $hyoo_sync_yard extends $mol_object2 {
|
|
3699
|
+
log_pack(data) {
|
|
3700
|
+
return data;
|
|
3701
|
+
}
|
|
3702
|
+
peer() {
|
|
3703
|
+
return $mol_wire_sync($hyoo_sync_peer)(this + '.peer()');
|
|
3704
|
+
}
|
|
3705
|
+
world() {
|
|
3706
|
+
$mol_wire_solid();
|
|
3707
|
+
const world = new this.$.$hyoo_crowd_world(this.peer());
|
|
3708
|
+
world.land_init = land => this.land_init(land);
|
|
3709
|
+
return world;
|
|
3710
|
+
}
|
|
3711
|
+
land_init(land) {
|
|
3712
|
+
this.db_land_init(land);
|
|
3713
|
+
try {
|
|
3714
|
+
this.db_land_sync(land);
|
|
3715
|
+
}
|
|
3716
|
+
catch (error) {
|
|
3717
|
+
$mol_fail_log(error);
|
|
3718
|
+
}
|
|
3719
|
+
if (!land.grabbed())
|
|
3720
|
+
this.$.$mol_wait_timeout(10_000);
|
|
3721
|
+
}
|
|
3722
|
+
land(id) {
|
|
3723
|
+
return this.world().land_sync(id);
|
|
3724
|
+
}
|
|
3725
|
+
land_grab(law = [''], mod = [], add = []) {
|
|
3726
|
+
return $mol_wire_sync(this.world()).grab(law, mod, add);
|
|
3727
|
+
}
|
|
3728
|
+
home() {
|
|
3729
|
+
return this.land(this.peer().id);
|
|
3730
|
+
}
|
|
3731
|
+
land_search(query) {
|
|
3732
|
+
const stat = new Map();
|
|
3733
|
+
for (const prefix of query.match(/\p{Letter}{2,}/gu) ?? []) {
|
|
3734
|
+
const caps = prefix.slice(0, 1).toUpperCase() + prefix.slice(1);
|
|
3735
|
+
const prefs = new Set([
|
|
3736
|
+
caps, ' ' + caps,
|
|
3737
|
+
prefix, ' ' + prefix,
|
|
3738
|
+
]);
|
|
3739
|
+
const lands = new Set();
|
|
3740
|
+
const founds = $mol_wire_race(...[...prefs].map(pref => () => $mol_wire_sync(this).db_land_search(pref)));
|
|
3741
|
+
for (const found of founds) {
|
|
3742
|
+
for (const land of [...found].reverse())
|
|
3743
|
+
lands.add(land);
|
|
3744
|
+
}
|
|
3745
|
+
for (const land of lands) {
|
|
3746
|
+
stat.set(land, (stat.get(land) ?? 0) + 1);
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3749
|
+
return [...stat].sort((left, right) => right[1] - left[1]).map(pair => pair[0]);
|
|
3750
|
+
}
|
|
3751
|
+
sync() {
|
|
3752
|
+
this.server();
|
|
3753
|
+
for (const land of this.world().lands.values()) {
|
|
3754
|
+
this.db_land_sync(land);
|
|
3755
|
+
}
|
|
3756
|
+
const master = this.master();
|
|
3757
|
+
if (master)
|
|
3758
|
+
$mol_wire_race(...[...this.world().lands.values()].map(land => () => this.line_land_sync({ line: master, land })));
|
|
3759
|
+
$mol_wire_race(...this.slaves().map(line => () => this.line_sync(line)));
|
|
3760
|
+
}
|
|
3761
|
+
land_sync(land) {
|
|
3762
|
+
this.db_land_init(land);
|
|
3763
|
+
try {
|
|
3764
|
+
this.db_land_sync(land);
|
|
3765
|
+
}
|
|
3766
|
+
catch (error) {
|
|
3767
|
+
$mol_fail_log(error);
|
|
3768
|
+
}
|
|
3769
|
+
try {
|
|
3770
|
+
const master = this.master();
|
|
3771
|
+
if (master)
|
|
3772
|
+
this.line_land_sync({ line: master, land });
|
|
3773
|
+
}
|
|
3774
|
+
catch (error) {
|
|
3775
|
+
$mol_fail_log(error);
|
|
3776
|
+
}
|
|
3777
|
+
try {
|
|
3778
|
+
$mol_wire_race(...this.slaves()
|
|
3779
|
+
.filter(line => this.line_lands(line).includes(land))
|
|
3780
|
+
.map(line => () => this.line_land_sync({ line, land })));
|
|
3781
|
+
}
|
|
3782
|
+
catch (error) {
|
|
3783
|
+
$mol_fail_log(error);
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
db_land_clocks(land, next) {
|
|
3787
|
+
$mol_wire_solid();
|
|
3788
|
+
return next;
|
|
3789
|
+
}
|
|
3790
|
+
db_land_sync(land) {
|
|
3791
|
+
this.db_land_init(land);
|
|
3792
|
+
const db_clocks = this.db_land_clocks(land.id());
|
|
3793
|
+
land.clocks;
|
|
3794
|
+
const units = land.delta(db_clocks);
|
|
3795
|
+
if (!units.length)
|
|
3796
|
+
return;
|
|
3797
|
+
$mol_wire_sync(this.world()).sign_units(units);
|
|
3798
|
+
$mol_wire_sync(this).db_land_save(land, units);
|
|
3799
|
+
for (const unit of units) {
|
|
3800
|
+
db_clocks[unit.group()].see_peer(unit.auth, unit.time);
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
db_land_init(land) {
|
|
3804
|
+
try {
|
|
3805
|
+
var units = $mol_wire_sync(this).db_land_load(land);
|
|
3806
|
+
}
|
|
3807
|
+
catch (error) {
|
|
3808
|
+
if (!(error instanceof Error))
|
|
3809
|
+
$mol_fail_hidden(error);
|
|
3810
|
+
this.$.$mol_log3_fail({
|
|
3811
|
+
place: this,
|
|
3812
|
+
land: land.id(),
|
|
3813
|
+
message: error.message,
|
|
3814
|
+
});
|
|
3815
|
+
units = [];
|
|
3816
|
+
}
|
|
3817
|
+
units.sort($hyoo_crowd_unit_compare);
|
|
3818
|
+
const clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock];
|
|
3819
|
+
this.db_land_clocks(land.id(), clocks);
|
|
3820
|
+
land.apply(units);
|
|
3821
|
+
for (const unit of units) {
|
|
3822
|
+
clocks[unit.group()].see_peer(unit.auth, unit.time);
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
async db_land_load(land) {
|
|
3826
|
+
return [];
|
|
3827
|
+
}
|
|
3828
|
+
async db_land_search(from, to = from) {
|
|
3829
|
+
return new Set();
|
|
3830
|
+
}
|
|
3831
|
+
async db_land_save(land, units) { }
|
|
3832
|
+
master_cursor(next = 0) {
|
|
3833
|
+
return next;
|
|
3834
|
+
}
|
|
3835
|
+
master_link() {
|
|
3836
|
+
const scheme = this.$.$mol_dom_context.document.location.protocol.replace(/^http/, 'ws');
|
|
3837
|
+
const host = this.$.$hyoo_sync_masters[this.master_cursor()];
|
|
3838
|
+
return `${scheme}//${host}`;
|
|
3839
|
+
}
|
|
3840
|
+
master() {
|
|
3841
|
+
return null;
|
|
3842
|
+
}
|
|
3843
|
+
server() {
|
|
3844
|
+
return null;
|
|
3845
|
+
}
|
|
3846
|
+
slaves(next = []) {
|
|
3847
|
+
return next;
|
|
3848
|
+
}
|
|
3849
|
+
line_lands(line, next = []) {
|
|
3850
|
+
return next;
|
|
3851
|
+
}
|
|
3852
|
+
line_land_clocks({ line, land }, next) {
|
|
3853
|
+
$mol_wire_solid();
|
|
3854
|
+
this.master();
|
|
3855
|
+
return next;
|
|
3856
|
+
}
|
|
3857
|
+
line_sync(line) {
|
|
3858
|
+
$mol_wire_race(...this.line_lands(line).map(land => () => this.line_land_sync({ line, land })));
|
|
3859
|
+
}
|
|
3860
|
+
line_land_sync({ line, land }) {
|
|
3861
|
+
this.line_land_init({ line, land });
|
|
3862
|
+
let clocks = this.line_land_clocks({ line, land });
|
|
3863
|
+
if (!clocks)
|
|
3864
|
+
return;
|
|
3865
|
+
const units = land.delta(clocks);
|
|
3866
|
+
if (!units.length)
|
|
3867
|
+
return;
|
|
3868
|
+
this.line_send_units(line, units);
|
|
3869
|
+
this.$.$mol_log3_rise({
|
|
3870
|
+
place: this,
|
|
3871
|
+
land: land.id(),
|
|
3872
|
+
message: 'Sync Sent',
|
|
3873
|
+
line: $mol_key(line),
|
|
3874
|
+
units: this.log_pack(units),
|
|
3875
|
+
});
|
|
3876
|
+
for (const unit of units) {
|
|
3877
|
+
clocks[unit.group()].see_peer(unit.auth, unit.time);
|
|
3878
|
+
}
|
|
3879
|
+
}
|
|
3880
|
+
line_land_init({ line, land }) {
|
|
3881
|
+
this.db_land_init(land);
|
|
3882
|
+
this.line_send_clocks(line, land);
|
|
3883
|
+
}
|
|
3884
|
+
line_land_neck({ line, land }, next = []) {
|
|
3885
|
+
return next;
|
|
3886
|
+
}
|
|
3887
|
+
async line_receive(line, message) {
|
|
3888
|
+
if (!message.byteLength)
|
|
3889
|
+
return;
|
|
3890
|
+
const view = new DataView(message.buffer, message.byteOffset, message.byteLength);
|
|
3891
|
+
const int0 = view.getInt32(0, true);
|
|
3892
|
+
const int1 = view.getInt32(4, true);
|
|
3893
|
+
const land_id = $mol_int62_to_string({
|
|
3894
|
+
lo: int0 << 1 >> 1,
|
|
3895
|
+
hi: int1 << 1 >> 1,
|
|
3896
|
+
});
|
|
3897
|
+
const handle = async (prev) => {
|
|
3898
|
+
if (prev)
|
|
3899
|
+
await prev;
|
|
3900
|
+
const world = this.world();
|
|
3901
|
+
const land = await $mol_wire_async(world).land(land_id);
|
|
3902
|
+
let clocks = this.line_land_clocks({ line, land });
|
|
3903
|
+
if (!clocks)
|
|
3904
|
+
this.line_land_clocks({ line, land }, clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock]);
|
|
3905
|
+
if (int0 << 1 >> 1 ^ int0) {
|
|
3906
|
+
const bin = new $hyoo_crowd_clock_bin(message.buffer, message.byteOffset, message.byteLength);
|
|
3907
|
+
for (let group = 0; group < clocks.length; ++group) {
|
|
3908
|
+
clocks[group].see_bin(bin, group);
|
|
3909
|
+
}
|
|
3910
|
+
const lands = this.line_lands(line);
|
|
3911
|
+
if (lands.includes(land)) {
|
|
3912
|
+
this.$.$mol_log3_warn({
|
|
3913
|
+
place: this,
|
|
3914
|
+
land: land.id(),
|
|
3915
|
+
message: 'Already syncing',
|
|
3916
|
+
hint: 'Bug at $hyoo_sync_yard',
|
|
3917
|
+
line: $mol_key(line),
|
|
3918
|
+
clocks,
|
|
3919
|
+
});
|
|
3920
|
+
}
|
|
3921
|
+
else {
|
|
3922
|
+
this.line_lands(line, [...lands, land]);
|
|
3923
|
+
}
|
|
3924
|
+
return;
|
|
3925
|
+
}
|
|
3926
|
+
const { allow, forbid } = await world.apply(message);
|
|
3927
|
+
for (const [{ bin, ...unit }, error] of forbid) {
|
|
3928
|
+
this.$.$mol_log3_fail({
|
|
3929
|
+
place: this,
|
|
3930
|
+
land: land.id(),
|
|
3931
|
+
message: error,
|
|
3932
|
+
line: $mol_key(line),
|
|
3933
|
+
unit,
|
|
3934
|
+
});
|
|
3935
|
+
}
|
|
3936
|
+
if (!allow.length)
|
|
3937
|
+
return;
|
|
3938
|
+
for (const unit of allow) {
|
|
3939
|
+
clocks[unit.group()].see_peer(unit.auth, unit.time);
|
|
3940
|
+
}
|
|
3941
|
+
this.$.$mol_log3_rise({
|
|
3942
|
+
place: this,
|
|
3943
|
+
land: land.id(),
|
|
3944
|
+
message: 'Sync Gain',
|
|
3945
|
+
line: $mol_key(line),
|
|
3946
|
+
units: this.log_pack(allow),
|
|
3947
|
+
});
|
|
3948
|
+
};
|
|
3949
|
+
this.line_land_neck({ line, land: land_id }, [
|
|
3950
|
+
handle(this.line_land_neck({ line, land: land_id })[0])
|
|
3951
|
+
]);
|
|
3952
|
+
}
|
|
3953
|
+
line_send_clocks(line, land) { }
|
|
3954
|
+
async line_send_units(line, units) { }
|
|
3955
|
+
[$mol_dev_format_head]() {
|
|
3956
|
+
return $mol_dev_format_native(this);
|
|
3957
|
+
}
|
|
3958
|
+
}
|
|
3959
|
+
__decorate([
|
|
3960
|
+
$mol_mem
|
|
3961
|
+
], $hyoo_sync_yard.prototype, "peer", null);
|
|
3962
|
+
__decorate([
|
|
3963
|
+
$mol_mem
|
|
3964
|
+
], $hyoo_sync_yard.prototype, "world", null);
|
|
3965
|
+
__decorate([
|
|
3966
|
+
$mol_mem_key
|
|
3967
|
+
], $hyoo_sync_yard.prototype, "land_init", null);
|
|
3968
|
+
__decorate([
|
|
3969
|
+
$mol_action
|
|
3970
|
+
], $hyoo_sync_yard.prototype, "land_search", null);
|
|
3971
|
+
__decorate([
|
|
3972
|
+
$mol_mem
|
|
3973
|
+
], $hyoo_sync_yard.prototype, "sync", null);
|
|
3974
|
+
__decorate([
|
|
3975
|
+
$mol_mem_key
|
|
3976
|
+
], $hyoo_sync_yard.prototype, "land_sync", null);
|
|
3977
|
+
__decorate([
|
|
3978
|
+
$mol_mem_key
|
|
3979
|
+
], $hyoo_sync_yard.prototype, "db_land_clocks", null);
|
|
3980
|
+
__decorate([
|
|
3981
|
+
$mol_mem_key
|
|
3982
|
+
], $hyoo_sync_yard.prototype, "db_land_sync", null);
|
|
3983
|
+
__decorate([
|
|
3984
|
+
$mol_mem_key
|
|
3985
|
+
], $hyoo_sync_yard.prototype, "db_land_init", null);
|
|
3986
|
+
__decorate([
|
|
3987
|
+
$mol_mem
|
|
3988
|
+
], $hyoo_sync_yard.prototype, "master_cursor", null);
|
|
3989
|
+
__decorate([
|
|
3990
|
+
$mol_mem
|
|
3991
|
+
], $hyoo_sync_yard.prototype, "master_link", null);
|
|
3992
|
+
__decorate([
|
|
3993
|
+
$mol_mem
|
|
3994
|
+
], $hyoo_sync_yard.prototype, "slaves", null);
|
|
3995
|
+
__decorate([
|
|
3996
|
+
$mol_mem_key
|
|
3997
|
+
], $hyoo_sync_yard.prototype, "line_lands", null);
|
|
3998
|
+
__decorate([
|
|
3999
|
+
$mol_mem_key
|
|
4000
|
+
], $hyoo_sync_yard.prototype, "line_land_clocks", null);
|
|
4001
|
+
__decorate([
|
|
4002
|
+
$mol_mem_key
|
|
4003
|
+
], $hyoo_sync_yard.prototype, "line_sync", null);
|
|
4004
|
+
__decorate([
|
|
4005
|
+
$mol_mem_key
|
|
4006
|
+
], $hyoo_sync_yard.prototype, "line_land_sync", null);
|
|
4007
|
+
__decorate([
|
|
4008
|
+
$mol_mem_key
|
|
4009
|
+
], $hyoo_sync_yard.prototype, "line_land_init", null);
|
|
4010
|
+
__decorate([
|
|
4011
|
+
$mol_mem_key
|
|
4012
|
+
], $hyoo_sync_yard.prototype, "line_land_neck", null);
|
|
4013
|
+
$.$hyoo_sync_yard = $hyoo_sync_yard;
|
|
4014
|
+
})($ || ($ = {}));
|
|
4015
|
+
//hyoo/sync/yard/yard.ts
|
|
4016
|
+
;
|
|
4017
|
+
"use strict";
|
|
4018
|
+
var $;
|
|
4019
|
+
(function ($) {
|
|
4020
|
+
function $mol_db_response(request) {
|
|
4021
|
+
return new Promise((done, fail) => {
|
|
4022
|
+
request.onerror = () => fail(new Error(request.error.message));
|
|
4023
|
+
request.onsuccess = () => done(request.result);
|
|
4024
|
+
});
|
|
4025
|
+
}
|
|
4026
|
+
$.$mol_db_response = $mol_db_response;
|
|
4027
|
+
})($ || ($ = {}));
|
|
4028
|
+
//mol/db/response/response.ts
|
|
4029
|
+
;
|
|
4030
|
+
"use strict";
|
|
4031
|
+
var $;
|
|
4032
|
+
(function ($) {
|
|
4033
|
+
async function $mol_db(name, ...migrations) {
|
|
4034
|
+
const request = this.$mol_dom_context.indexedDB.open(name, migrations.length ? migrations.length + 1 : undefined);
|
|
4035
|
+
request.onupgradeneeded = event => {
|
|
4036
|
+
migrations.splice(0, event.oldVersion - 1);
|
|
4037
|
+
const transaction = new $mol_db_transaction(request.transaction);
|
|
4038
|
+
for (const migrate of migrations)
|
|
4039
|
+
migrate(transaction);
|
|
4040
|
+
};
|
|
4041
|
+
const db = await $mol_db_response(request);
|
|
4042
|
+
return new $mol_db_database(db);
|
|
4043
|
+
}
|
|
4044
|
+
$.$mol_db = $mol_db;
|
|
4045
|
+
})($ || ($ = {}));
|
|
4046
|
+
//mol/db/db.ts
|
|
4047
|
+
;
|
|
4048
|
+
"use strict";
|
|
4049
|
+
var $;
|
|
4050
|
+
(function ($) {
|
|
4051
|
+
class $mol_db_store {
|
|
4052
|
+
native;
|
|
4053
|
+
constructor(native) {
|
|
4054
|
+
this.native = native;
|
|
4055
|
+
}
|
|
4056
|
+
get name() {
|
|
4057
|
+
return this.native.name;
|
|
4058
|
+
}
|
|
4059
|
+
get path() {
|
|
4060
|
+
return this.native.keyPath;
|
|
4061
|
+
}
|
|
4062
|
+
get incremental() {
|
|
4063
|
+
return this.native.autoIncrement;
|
|
4064
|
+
}
|
|
4065
|
+
get indexes() {
|
|
4066
|
+
return new Proxy({}, {
|
|
4067
|
+
ownKeys: () => [...this.native.indexNames],
|
|
4068
|
+
has: (_, name) => this.native.indexNames.contains(name),
|
|
4069
|
+
get: (_, name) => new $mol_db_index(this.native.index(name))
|
|
4070
|
+
});
|
|
4071
|
+
}
|
|
4072
|
+
index_make(name, path = [], unique = false, multiEntry = false) {
|
|
4073
|
+
return this.native.createIndex(name, path, { multiEntry, unique });
|
|
4074
|
+
}
|
|
4075
|
+
index_drop(name) {
|
|
4076
|
+
this.native.deleteIndex(name);
|
|
4077
|
+
return this;
|
|
4078
|
+
}
|
|
4079
|
+
get transaction() {
|
|
4080
|
+
return new $mol_db_transaction(this.native.transaction);
|
|
4081
|
+
}
|
|
4082
|
+
get db() {
|
|
4083
|
+
return this.transaction.db;
|
|
4084
|
+
}
|
|
4085
|
+
clear() {
|
|
4086
|
+
return $mol_db_response(this.native.clear());
|
|
4087
|
+
}
|
|
4088
|
+
count(keys) {
|
|
4089
|
+
return $mol_db_response(this.native.count(keys));
|
|
4090
|
+
}
|
|
4091
|
+
put(doc, key) {
|
|
4092
|
+
return $mol_db_response(this.native.put(doc, key));
|
|
4093
|
+
}
|
|
4094
|
+
get(key) {
|
|
4095
|
+
return $mol_db_response(this.native.get(key));
|
|
4096
|
+
}
|
|
4097
|
+
select(key, count) {
|
|
4098
|
+
return $mol_db_response(this.native.getAll(key, count));
|
|
4099
|
+
}
|
|
4100
|
+
drop(keys) {
|
|
4101
|
+
return $mol_db_response(this.native.delete(keys));
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
$.$mol_db_store = $mol_db_store;
|
|
4105
|
+
})($ || ($ = {}));
|
|
4106
|
+
//mol/db/store/store.ts
|
|
4107
|
+
;
|
|
4108
|
+
"use strict";
|
|
4109
|
+
//mol/db/store/store_schema.ts
|
|
4110
|
+
;
|
|
4111
|
+
"use strict";
|
|
4112
|
+
var $;
|
|
4113
|
+
(function ($) {
|
|
4114
|
+
class $mol_db_index {
|
|
4115
|
+
native;
|
|
4116
|
+
constructor(native) {
|
|
4117
|
+
this.native = native;
|
|
4118
|
+
}
|
|
4119
|
+
get name() {
|
|
4120
|
+
return this.native.name;
|
|
4121
|
+
}
|
|
4122
|
+
get paths() {
|
|
4123
|
+
return this.native.keyPath;
|
|
4124
|
+
}
|
|
4125
|
+
get unique() {
|
|
4126
|
+
return this.native.unique;
|
|
4127
|
+
}
|
|
4128
|
+
get multiple() {
|
|
4129
|
+
return this.native.multiEntry;
|
|
4130
|
+
}
|
|
4131
|
+
get store() {
|
|
4132
|
+
return new $mol_db_store(this.native.objectStore);
|
|
4133
|
+
}
|
|
4134
|
+
get transaction() {
|
|
4135
|
+
return this.store.transaction;
|
|
4136
|
+
}
|
|
4137
|
+
get db() {
|
|
4138
|
+
return this.store.db;
|
|
4139
|
+
}
|
|
4140
|
+
count(keys) {
|
|
4141
|
+
return $mol_db_response(this.native.count(keys));
|
|
4142
|
+
}
|
|
4143
|
+
get(key) {
|
|
4144
|
+
return $mol_db_response(this.native.get(key));
|
|
4145
|
+
}
|
|
4146
|
+
select(key, count) {
|
|
4147
|
+
return $mol_db_response(this.native.getAll(key, count));
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
$.$mol_db_index = $mol_db_index;
|
|
4151
|
+
})($ || ($ = {}));
|
|
4152
|
+
//mol/db/index/index.ts
|
|
4153
|
+
;
|
|
4154
|
+
"use strict";
|
|
4155
|
+
//mol/db/index/index_schema.ts
|
|
4156
|
+
;
|
|
4157
|
+
"use strict";
|
|
4158
|
+
var $;
|
|
4159
|
+
(function ($) {
|
|
4160
|
+
$mol_dom_context.indexedDB = $node['fake-indexeddb'].indexedDB;
|
|
4161
|
+
$mol_dom_context.IDBCursor = $node['fake-indexeddb'].IDBCursor;
|
|
4162
|
+
$mol_dom_context.IDBCursorWithValue = $node['fake-indexeddb'].IDBCursorWithValue;
|
|
4163
|
+
$mol_dom_context.IDBDatabase = $node['fake-indexeddb'].IDBDatabase;
|
|
4164
|
+
$mol_dom_context.IDBFactory = $node['fake-indexeddb'].IDBFactory;
|
|
4165
|
+
$mol_dom_context.IDBIndex = $node['fake-indexeddb'].IDBIndex;
|
|
4166
|
+
$mol_dom_context.IDBKeyRange = $node['fake-indexeddb'].IDBKeyRange;
|
|
4167
|
+
$mol_dom_context.IDBObjectStore = $node['fake-indexeddb'].IDBObjectStore;
|
|
4168
|
+
$mol_dom_context.IDBOpenDBRequest = $node['fake-indexeddb'].IDBOpenDBRequest;
|
|
4169
|
+
$mol_dom_context.IDBRequest = $node['fake-indexeddb'].IDBRequest;
|
|
4170
|
+
$mol_dom_context.IDBTransaction = $node['fake-indexeddb'].IDBTransaction;
|
|
4171
|
+
$mol_dom_context.IDBVersionChangeEvent = $node['fake-indexeddb'].IDBVersionChangeEvent;
|
|
4172
|
+
})($ || ($ = {}));
|
|
4173
|
+
//mol/db/db.node.ts
|
|
4174
|
+
;
|
|
4175
|
+
"use strict";
|
|
4176
|
+
//mol/db/db_schema.ts
|
|
4177
|
+
;
|
|
4178
|
+
"use strict";
|
|
4179
|
+
var $;
|
|
4180
|
+
(function ($) {
|
|
4181
|
+
function $mol_wire_probe(task, next) {
|
|
4182
|
+
const warm = $mol_wire_fiber.warm;
|
|
4183
|
+
try {
|
|
4184
|
+
$mol_wire_fiber.warm = false;
|
|
4185
|
+
return task();
|
|
4186
|
+
}
|
|
4187
|
+
finally {
|
|
4188
|
+
$mol_wire_fiber.warm = warm;
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
4191
|
+
$.$mol_wire_probe = $mol_wire_probe;
|
|
4192
|
+
})($ || ($ = {}));
|
|
4193
|
+
//mol/wire/probe/probe.ts
|
|
4194
|
+
;
|
|
4195
|
+
"use strict";
|
|
4196
|
+
var $;
|
|
4197
|
+
(function ($) {
|
|
4198
|
+
class $mol_db_database {
|
|
4199
|
+
native;
|
|
4200
|
+
constructor(native) {
|
|
4201
|
+
this.native = native;
|
|
4202
|
+
}
|
|
4203
|
+
get name() {
|
|
4204
|
+
return this.native.name;
|
|
4205
|
+
}
|
|
4206
|
+
get version() {
|
|
4207
|
+
return this.native.version;
|
|
4208
|
+
}
|
|
4209
|
+
get stores() {
|
|
4210
|
+
return [...this.native.objectStoreNames];
|
|
4211
|
+
}
|
|
4212
|
+
read(...names) {
|
|
4213
|
+
return new $mol_db_transaction(this.native.transaction(names, 'readonly')).stores;
|
|
4214
|
+
}
|
|
4215
|
+
change(...names) {
|
|
4216
|
+
return new $mol_db_transaction(this.native.transaction(names, 'readwrite'));
|
|
4217
|
+
}
|
|
4218
|
+
kill() {
|
|
4219
|
+
this.native.close();
|
|
4220
|
+
const request = $mol_dom_context.indexedDB.deleteDatabase(this.name);
|
|
4221
|
+
request.onblocked = console.warn;
|
|
4222
|
+
return $mol_db_response(request);
|
|
4223
|
+
}
|
|
4224
|
+
destructor() {
|
|
4225
|
+
this.native.close();
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4228
|
+
$.$mol_db_database = $mol_db_database;
|
|
4229
|
+
})($ || ($ = {}));
|
|
4230
|
+
//mol/db/database/database.ts
|
|
4231
|
+
;
|
|
4232
|
+
"use strict";
|
|
4233
|
+
var $;
|
|
4234
|
+
(function ($) {
|
|
4235
|
+
class $mol_db_transaction {
|
|
4236
|
+
native;
|
|
4237
|
+
constructor(native) {
|
|
4238
|
+
this.native = native;
|
|
4239
|
+
}
|
|
4240
|
+
get stores() {
|
|
4241
|
+
return new Proxy({}, {
|
|
4242
|
+
ownKeys: () => [...this.native.objectStoreNames],
|
|
4243
|
+
has: (_, name) => this.native.objectStoreNames.contains(name),
|
|
4244
|
+
get: (_, name) => new $mol_db_store(this.native.objectStore(name)),
|
|
4245
|
+
});
|
|
4246
|
+
}
|
|
4247
|
+
store_make(name) {
|
|
4248
|
+
return this.native.db.createObjectStore(name, { autoIncrement: true });
|
|
4249
|
+
}
|
|
4250
|
+
store_drop(name) {
|
|
4251
|
+
this.native.db.deleteObjectStore(name);
|
|
4252
|
+
return this;
|
|
4253
|
+
}
|
|
4254
|
+
abort() {
|
|
4255
|
+
if (this.native.error)
|
|
4256
|
+
return;
|
|
4257
|
+
this.native.abort();
|
|
4258
|
+
}
|
|
4259
|
+
commit() {
|
|
4260
|
+
this.native.commit?.();
|
|
4261
|
+
return new Promise((done, fail) => {
|
|
4262
|
+
this.native.onerror = () => fail(new Error(this.native.error.message));
|
|
4263
|
+
this.native.oncomplete = () => done();
|
|
4264
|
+
});
|
|
4265
|
+
}
|
|
4266
|
+
get db() {
|
|
4267
|
+
return new $mol_db_database(this.native.db);
|
|
4268
|
+
}
|
|
4269
|
+
}
|
|
4270
|
+
$.$mol_db_transaction = $mol_db_transaction;
|
|
4271
|
+
})($ || ($ = {}));
|
|
4272
|
+
//mol/db/transaction/transaction.ts
|
|
4273
|
+
;
|
|
4274
|
+
"use strict";
|
|
4275
|
+
var $;
|
|
4276
|
+
(function ($) {
|
|
4277
|
+
class $hyoo_sync_client extends $hyoo_sync_yard {
|
|
4278
|
+
async db() {
|
|
4279
|
+
const db1 = await this.$.$mol_db('$hyoo_sync_client_db');
|
|
4280
|
+
await db1.kill();
|
|
4281
|
+
return await this.$.$mol_db('$hyoo_sync_client_db2', mig => mig.store_make('Unit'), mig => mig.stores.Unit.index_make('Land', ['land']), mig => mig.stores.Unit.index_make('Data', ['data']));
|
|
4282
|
+
}
|
|
4283
|
+
async db_land_load(land) {
|
|
4284
|
+
try {
|
|
4285
|
+
var db = await this.db();
|
|
4286
|
+
}
|
|
4287
|
+
catch (error) {
|
|
4288
|
+
$mol_fail_log(error);
|
|
4289
|
+
return [];
|
|
4290
|
+
}
|
|
4291
|
+
const Unit = db.read('Unit').Unit;
|
|
4292
|
+
const recs = await Unit.indexes.Land.select([land.id()]);
|
|
4293
|
+
if (!recs)
|
|
4294
|
+
return [];
|
|
4295
|
+
const units = recs.map(rec => new $hyoo_crowd_unit(rec.land, rec.auth, rec.head, rec.self, rec.next, rec.prev, rec.time, rec.data, new $hyoo_crowd_unit_bin(rec.bin.buffer)));
|
|
4296
|
+
return units;
|
|
4297
|
+
}
|
|
4298
|
+
async db_land_search(from, to = from + '\uFFFF') {
|
|
4299
|
+
try {
|
|
4300
|
+
var db = await this.db();
|
|
4301
|
+
}
|
|
4302
|
+
catch (error) {
|
|
4303
|
+
$mol_fail_log(error);
|
|
4304
|
+
return new Set();
|
|
4305
|
+
}
|
|
4306
|
+
const Unit = db.read('Unit').Unit;
|
|
4307
|
+
const query = IDBKeyRange.bound([from], [to]);
|
|
4308
|
+
const recs = await Unit.indexes.Data.select(query);
|
|
4309
|
+
return new Set(recs.map(rec => rec.land));
|
|
4310
|
+
}
|
|
4311
|
+
async db_land_save(land, units) {
|
|
4312
|
+
try {
|
|
4313
|
+
var db = await this.db();
|
|
4314
|
+
}
|
|
4315
|
+
catch (error) {
|
|
4316
|
+
$mol_fail_log(error);
|
|
4317
|
+
return;
|
|
4318
|
+
}
|
|
4319
|
+
const trans = db.change('Unit');
|
|
4320
|
+
const Unit = trans.stores.Unit;
|
|
4321
|
+
for (const unit of units) {
|
|
4322
|
+
Unit.put(unit, [unit.land, unit.head, unit.self]);
|
|
4323
|
+
}
|
|
4324
|
+
await trans.commit();
|
|
4325
|
+
}
|
|
4326
|
+
reconnects(reset) {
|
|
4327
|
+
return ($mol_wire_probe(() => this.reconnects()) ?? 0) + 1;
|
|
4328
|
+
}
|
|
4329
|
+
master() {
|
|
4330
|
+
this.reconnects();
|
|
4331
|
+
const link = this.master_link();
|
|
4332
|
+
const line = new $mol_dom_context.WebSocket(link);
|
|
4333
|
+
line.binaryType = 'arraybuffer';
|
|
4334
|
+
line.onmessage = async (event) => {
|
|
4335
|
+
if (event.data instanceof ArrayBuffer) {
|
|
4336
|
+
await this.line_receive(line, new Uint8Array(event.data));
|
|
4337
|
+
}
|
|
4338
|
+
else {
|
|
4339
|
+
this.$.$mol_log3_fail({
|
|
4340
|
+
place: this,
|
|
4341
|
+
message: 'Wrong data',
|
|
4342
|
+
data: event.data
|
|
4343
|
+
});
|
|
4344
|
+
}
|
|
4345
|
+
};
|
|
4346
|
+
let interval;
|
|
4347
|
+
line.onclose = () => {
|
|
4348
|
+
clearInterval(interval);
|
|
4349
|
+
setTimeout(() => this.reconnects(null), 1000);
|
|
4350
|
+
};
|
|
4351
|
+
Object.assign(line, {
|
|
4352
|
+
destructor: () => {
|
|
4353
|
+
line.onclose = () => { };
|
|
4354
|
+
clearInterval(interval);
|
|
4355
|
+
line.close();
|
|
4356
|
+
}
|
|
4357
|
+
});
|
|
4358
|
+
return new Promise((done, fail) => {
|
|
4359
|
+
line.onopen = () => {
|
|
4360
|
+
this.$.$mol_log3_come({
|
|
4361
|
+
place: this,
|
|
4362
|
+
message: 'Connected to Master',
|
|
4363
|
+
line: $mol_key(line),
|
|
4364
|
+
server: link,
|
|
4365
|
+
});
|
|
4366
|
+
interval = setInterval(() => line.send(new Uint8Array), 30000);
|
|
4367
|
+
done(line);
|
|
4368
|
+
};
|
|
4369
|
+
line.onerror = () => {
|
|
4370
|
+
line.onclose = event => {
|
|
4371
|
+
fail(new Error(`Master is unavailable (${event.code})`));
|
|
4372
|
+
};
|
|
4373
|
+
clearInterval(interval);
|
|
4374
|
+
this.master_cursor((this.master_cursor() + 1) % this.$.$hyoo_sync_masters.length);
|
|
4375
|
+
};
|
|
4376
|
+
});
|
|
4377
|
+
}
|
|
4378
|
+
line_send_clocks(line, land) {
|
|
4379
|
+
if (line instanceof WebSocket) {
|
|
4380
|
+
const message = new Uint8Array($hyoo_crowd_clock_bin.from(land.id(), land._clocks).buffer);
|
|
4381
|
+
line.send(message);
|
|
4382
|
+
}
|
|
4383
|
+
else {
|
|
4384
|
+
const message = land._clocks;
|
|
4385
|
+
line.postMessage(['hyoo_sync_clocks', land.id(), message]);
|
|
4386
|
+
}
|
|
4387
|
+
}
|
|
4388
|
+
async line_send_units(line, units) {
|
|
4389
|
+
if (line instanceof WebSocket) {
|
|
4390
|
+
await this.world().sign_units(units);
|
|
4391
|
+
const message = new Blob(units.map(unit => unit.bin));
|
|
4392
|
+
line.send(message);
|
|
4393
|
+
}
|
|
4394
|
+
else {
|
|
4395
|
+
line.postMessage(['hyoo_sync_units', units[0].land, units]);
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4398
|
+
}
|
|
4399
|
+
__decorate([
|
|
4400
|
+
$mol_memo.method
|
|
4401
|
+
], $hyoo_sync_client.prototype, "db", null);
|
|
4402
|
+
__decorate([
|
|
4403
|
+
$mol_mem
|
|
4404
|
+
], $hyoo_sync_client.prototype, "reconnects", null);
|
|
4405
|
+
__decorate([
|
|
4406
|
+
$mol_mem
|
|
4407
|
+
], $hyoo_sync_client.prototype, "master", null);
|
|
4408
|
+
$.$hyoo_sync_client = $hyoo_sync_client;
|
|
4409
|
+
})($ || ($ = {}));
|
|
4410
|
+
//hyoo/sync/client/client.ts
|
|
4411
|
+
|
|
4412
|
+
//# sourceMappingURL=node.js.map
|