@emuanalytics/flow-rdf-core 0.0.20 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +132 -40
- package/dist/index.d.cts +15 -2
- package/dist/index.d.mts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.mjs +130 -40
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,34 @@ const Debug__default = /*#__PURE__*/_interopDefaultCompat(Debug);
|
|
|
33
33
|
const EventEmitter__default = /*#__PURE__*/_interopDefaultCompat(EventEmitter);
|
|
34
34
|
const maplibre__default = /*#__PURE__*/_interopDefaultCompat(maplibre);
|
|
35
35
|
|
|
36
|
+
const version = "0.0.22";
|
|
37
|
+
|
|
38
|
+
const CONSOLE_HIGHLIGHT_STYLE$1 = `
|
|
39
|
+
padding: 2px 4px;
|
|
40
|
+
border-radius: 2px;
|
|
41
|
+
background: #389DFF;
|
|
42
|
+
color: white;`;
|
|
43
|
+
function announce() {
|
|
44
|
+
console.log("%cFlo.w RDF Core v%s", CONSOLE_HIGHLIGHT_STYLE$1, version);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const mockGlobal = {};
|
|
48
|
+
function getGlobal() {
|
|
49
|
+
if (typeof globalThis !== "undefined") {
|
|
50
|
+
return globalThis;
|
|
51
|
+
}
|
|
52
|
+
if (typeof window !== "undefined") {
|
|
53
|
+
return window;
|
|
54
|
+
}
|
|
55
|
+
if (typeof global !== "undefined") {
|
|
56
|
+
return global;
|
|
57
|
+
}
|
|
58
|
+
if (typeof self !== "undefined") {
|
|
59
|
+
return self;
|
|
60
|
+
}
|
|
61
|
+
return mockGlobal;
|
|
62
|
+
}
|
|
63
|
+
|
|
36
64
|
function deferred() {
|
|
37
65
|
let methods;
|
|
38
66
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -41,10 +69,10 @@ function deferred() {
|
|
|
41
69
|
return Object.assign(promise, methods);
|
|
42
70
|
}
|
|
43
71
|
|
|
44
|
-
var __defProp$
|
|
45
|
-
var __defNormalProp$
|
|
46
|
-
var __publicField$
|
|
47
|
-
__defNormalProp$
|
|
72
|
+
var __defProp$d = Object.defineProperty;
|
|
73
|
+
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
74
|
+
var __publicField$d = (obj, key, value) => {
|
|
75
|
+
__defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
48
76
|
return value;
|
|
49
77
|
};
|
|
50
78
|
const FLOW_GLOBAL = "FDBG";
|
|
@@ -65,8 +93,8 @@ class Debugger {
|
|
|
65
93
|
*/
|
|
66
94
|
constructor(context) {
|
|
67
95
|
this.context = context;
|
|
68
|
-
__publicField$
|
|
69
|
-
__publicField$
|
|
96
|
+
__publicField$d(this, "spyDisposer");
|
|
97
|
+
__publicField$d(this, "watchDisposers", {});
|
|
70
98
|
}
|
|
71
99
|
/**
|
|
72
100
|
* Install a 'watch' for the specified context state property path.
|
|
@@ -253,16 +281,16 @@ function toJSHelper(source, options, __alreadySeen = null) {
|
|
|
253
281
|
return res;
|
|
254
282
|
}
|
|
255
283
|
|
|
256
|
-
var __defProp$
|
|
257
|
-
var __defNormalProp$
|
|
258
|
-
var __publicField$
|
|
259
|
-
__defNormalProp$
|
|
284
|
+
var __defProp$c = Object.defineProperty;
|
|
285
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
286
|
+
var __publicField$c = (obj, key, value) => {
|
|
287
|
+
__defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
260
288
|
return value;
|
|
261
289
|
};
|
|
262
290
|
const debug$4 = Debug__default("flow:map-registry");
|
|
263
291
|
class MapRegistry {
|
|
264
292
|
constructor() {
|
|
265
|
-
__publicField$
|
|
293
|
+
__publicField$c(this, "_maps", /* @__PURE__ */ new Map());
|
|
266
294
|
}
|
|
267
295
|
/**
|
|
268
296
|
* Register a Flo.w map.
|
|
@@ -304,16 +332,16 @@ class MapRegistry {
|
|
|
304
332
|
}
|
|
305
333
|
}
|
|
306
334
|
|
|
307
|
-
var __defProp$
|
|
308
|
-
var __defNormalProp$
|
|
309
|
-
var __publicField$
|
|
310
|
-
__defNormalProp$
|
|
335
|
+
var __defProp$b = Object.defineProperty;
|
|
336
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
337
|
+
var __publicField$b = (obj, key, value) => {
|
|
338
|
+
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
311
339
|
return value;
|
|
312
340
|
};
|
|
313
341
|
const debug$3 = Debug__default("flow:query-registry");
|
|
314
342
|
class QueryRegistry {
|
|
315
343
|
constructor() {
|
|
316
|
-
__publicField$
|
|
344
|
+
__publicField$b(this, "_queries", /* @__PURE__ */ new Map());
|
|
317
345
|
}
|
|
318
346
|
/**
|
|
319
347
|
* Register a Flo.w reactive query.
|
|
@@ -353,10 +381,10 @@ class QueryRegistry {
|
|
|
353
381
|
}
|
|
354
382
|
}
|
|
355
383
|
|
|
356
|
-
var __defProp$
|
|
357
|
-
var __defNormalProp$
|
|
358
|
-
var __publicField$
|
|
359
|
-
__defNormalProp$
|
|
384
|
+
var __defProp$a = Object.defineProperty;
|
|
385
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
386
|
+
var __publicField$a = (obj, key, value) => {
|
|
387
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
360
388
|
return value;
|
|
361
389
|
};
|
|
362
390
|
const DEFAULT_FLOW_HOST = "https://flow.emu-analytics.net";
|
|
@@ -373,13 +401,13 @@ const _FlowContext = class _FlowContext {
|
|
|
373
401
|
* @param enableDebug Set to `true` to enable the debugger.
|
|
374
402
|
*/
|
|
375
403
|
constructor(options) {
|
|
376
|
-
__publicField$
|
|
377
|
-
__publicField$
|
|
378
|
-
__publicField$
|
|
379
|
-
__publicField$
|
|
380
|
-
__publicField$
|
|
404
|
+
__publicField$a(this, "_options");
|
|
405
|
+
__publicField$a(this, "flowClient");
|
|
406
|
+
__publicField$a(this, "state");
|
|
407
|
+
__publicField$a(this, "maps", new MapRegistry());
|
|
408
|
+
__publicField$a(this, "queries", new QueryRegistry());
|
|
381
409
|
/** The Flo.w debugger. Available as `window.FDBG` in the browser's web developer console. */
|
|
382
|
-
__publicField$
|
|
410
|
+
__publicField$a(this, "debugger");
|
|
383
411
|
this._options = {
|
|
384
412
|
..._FlowContext._defaultOptions,
|
|
385
413
|
...options
|
|
@@ -403,23 +431,23 @@ const _FlowContext = class _FlowContext {
|
|
|
403
431
|
return expression.value;
|
|
404
432
|
}
|
|
405
433
|
};
|
|
406
|
-
__publicField$
|
|
434
|
+
__publicField$a(_FlowContext, "_defaultOptions", {
|
|
407
435
|
id: DEFAULT_CONTEXT_ID,
|
|
408
436
|
host: DEFAULT_FLOW_HOST,
|
|
409
437
|
enableDebug: false
|
|
410
438
|
});
|
|
411
439
|
let FlowContext = _FlowContext;
|
|
412
440
|
|
|
413
|
-
var __defProp$
|
|
414
|
-
var __defNormalProp$
|
|
415
|
-
var __publicField$
|
|
416
|
-
__defNormalProp$
|
|
441
|
+
var __defProp$9 = Object.defineProperty;
|
|
442
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
443
|
+
var __publicField$9 = (obj, key, value) => {
|
|
444
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
417
445
|
return value;
|
|
418
446
|
};
|
|
419
447
|
const debug$2 = Debug__default("flow:context-registry");
|
|
420
448
|
const _ContextRegistry = class _ContextRegistry {
|
|
421
449
|
constructor() {
|
|
422
|
-
__publicField$
|
|
450
|
+
__publicField$9(this, "_contexts", /* @__PURE__ */ new Map());
|
|
423
451
|
}
|
|
424
452
|
/**
|
|
425
453
|
* Initialize a new Flo.w context.
|
|
@@ -462,12 +490,72 @@ const _ContextRegistry = class _ContextRegistry {
|
|
|
462
490
|
return deferredContext?.deferred;
|
|
463
491
|
}
|
|
464
492
|
};
|
|
465
|
-
__publicField$
|
|
493
|
+
__publicField$9(_ContextRegistry, "_defaultOptions", {
|
|
466
494
|
id: DEFAULT_CONTEXT_ID,
|
|
467
495
|
host: "https://flow.emu-analytics.net"
|
|
468
496
|
});
|
|
469
497
|
let ContextRegistry = _ContextRegistry;
|
|
470
|
-
|
|
498
|
+
|
|
499
|
+
var __defProp$8 = Object.defineProperty;
|
|
500
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
501
|
+
var __publicField$8 = (obj, key, value) => {
|
|
502
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
503
|
+
return value;
|
|
504
|
+
};
|
|
505
|
+
class FlowRdfCoreGlobals {
|
|
506
|
+
constructor() {
|
|
507
|
+
/**
|
|
508
|
+
* FlowRdfCoreGlobals version.
|
|
509
|
+
* Compatiblity with other versions loaded in memory as long as this version matches.
|
|
510
|
+
* It indicates that the global state still stores similar information
|
|
511
|
+
*
|
|
512
|
+
* N.B: this version is unrelated to the package version.
|
|
513
|
+
*/
|
|
514
|
+
__publicField$8(this, "version", 1);
|
|
515
|
+
__publicField$8(this, "globalContextRegistry", new ContextRegistry());
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
let canMergeGlobalState = true;
|
|
519
|
+
let isolateCalled = false;
|
|
520
|
+
let globalState = function() {
|
|
521
|
+
const global = getGlobal();
|
|
522
|
+
if (global.__flowRdfCoreInstanceCount > 0 && !global.__flowRdfCoreGlobals) {
|
|
523
|
+
canMergeGlobalState = false;
|
|
524
|
+
}
|
|
525
|
+
if (global.__flowRdfCoreGlobals && global.__flowRdfCoreGlobals.version !== new FlowRdfCoreGlobals().version) {
|
|
526
|
+
canMergeGlobalState = false;
|
|
527
|
+
}
|
|
528
|
+
if (!canMergeGlobalState) {
|
|
529
|
+
setTimeout(() => {
|
|
530
|
+
if (!isolateCalled) {
|
|
531
|
+
throw new Error(
|
|
532
|
+
'There are multiple, different versions of FlowRdfCore active. Make sure FlowRdfCore is loaded only once or use `configure({ isolateGlobalState: true })`",'
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
}, 1);
|
|
536
|
+
return new FlowRdfCoreGlobals();
|
|
537
|
+
} else if (global.__flowRdfCoreGlobals) {
|
|
538
|
+
global.__flowRdfCoreInstanceCount += 1;
|
|
539
|
+
return global.__flowRdfCoreGlobals;
|
|
540
|
+
} else {
|
|
541
|
+
global.__flowRdfCoreInstanceCount = 1;
|
|
542
|
+
announce();
|
|
543
|
+
return global.__flowRdfCoreGlobals = new FlowRdfCoreGlobals();
|
|
544
|
+
}
|
|
545
|
+
}();
|
|
546
|
+
function isolateGlobalState() {
|
|
547
|
+
isolateCalled = true;
|
|
548
|
+
if (canMergeGlobalState) {
|
|
549
|
+
const global = getGlobal();
|
|
550
|
+
if (--global.__flowRdfCoreInstanceCount === 0) {
|
|
551
|
+
global.__flowRdfCoreGlobals = void 0;
|
|
552
|
+
}
|
|
553
|
+
globalState = new FlowRdfCoreGlobals();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
function getGlobalState() {
|
|
557
|
+
return globalState;
|
|
558
|
+
}
|
|
471
559
|
|
|
472
560
|
var __defProp$7 = Object.defineProperty;
|
|
473
561
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -2492,6 +2580,7 @@ const _FlowMap = class _FlowMap extends EventEmitter__default {
|
|
|
2492
2580
|
}
|
|
2493
2581
|
}
|
|
2494
2582
|
async initialize() {
|
|
2583
|
+
const globalContextRegistry = getGlobalState().globalContextRegistry;
|
|
2495
2584
|
this._context = await globalContextRegistry.getContext(this._options.contextId);
|
|
2496
2585
|
this._style.bindState(this._context.state);
|
|
2497
2586
|
const baseStyle = await this.loadBaseStyle(this._options.baseStyle);
|
|
@@ -2603,7 +2692,7 @@ const _Query = class _Query {
|
|
|
2603
2692
|
if (transformFn) {
|
|
2604
2693
|
this._transformFn = transformFn;
|
|
2605
2694
|
}
|
|
2606
|
-
globalContextRegistry.getContext(this._options?.contextId).then((context) => {
|
|
2695
|
+
getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
|
|
2607
2696
|
context.queries.registerQuery(this);
|
|
2608
2697
|
});
|
|
2609
2698
|
}
|
|
@@ -2617,12 +2706,12 @@ const _Query = class _Query {
|
|
|
2617
2706
|
return this._options.id;
|
|
2618
2707
|
}
|
|
2619
2708
|
destroy() {
|
|
2620
|
-
globalContextRegistry.getContext(this._options?.contextId).then((context) => {
|
|
2709
|
+
getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
|
|
2621
2710
|
context.queries.unregisterQuery(this);
|
|
2622
2711
|
});
|
|
2623
2712
|
}
|
|
2624
2713
|
async runImmediately() {
|
|
2625
|
-
const context = await globalContextRegistry.getContext(this._options.contextId);
|
|
2714
|
+
const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
|
|
2626
2715
|
const queryDefinition = this.queryFn.call(context.state, context.state);
|
|
2627
2716
|
await this.runQuery(queryDefinition);
|
|
2628
2717
|
if (this.error) {
|
|
@@ -2632,7 +2721,7 @@ const _Query = class _Query {
|
|
|
2632
2721
|
}
|
|
2633
2722
|
async wake() {
|
|
2634
2723
|
this.sleep();
|
|
2635
|
-
const context = await globalContextRegistry.getContext(this._options.contextId);
|
|
2724
|
+
const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
|
|
2636
2725
|
this._disposer = mobx.reaction(
|
|
2637
2726
|
(r) => {
|
|
2638
2727
|
return this.queryFn.call(context.state, context.state);
|
|
@@ -2658,7 +2747,7 @@ const _Query = class _Query {
|
|
|
2658
2747
|
}
|
|
2659
2748
|
async runQuery(queryDefinition) {
|
|
2660
2749
|
debug(`${this.formattedName}: running query`, queryDefinition);
|
|
2661
|
-
const context = await globalContextRegistry.getContext(this._options.contextId);
|
|
2750
|
+
const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
|
|
2662
2751
|
try {
|
|
2663
2752
|
if (queryDefinition === null) {
|
|
2664
2753
|
mobx.runInAction(() => {
|
|
@@ -3076,6 +3165,7 @@ function traceReaction() {
|
|
|
3076
3165
|
}
|
|
3077
3166
|
|
|
3078
3167
|
mobx.configure({ isolateGlobalState: false, useProxies: "always" });
|
|
3168
|
+
const globalContextRegistry = getGlobalState().globalContextRegistry;
|
|
3079
3169
|
const initializeContext = globalContextRegistry.initializeContext.bind(globalContextRegistry);
|
|
3080
3170
|
const uninitializeContext = globalContextRegistry.uninitializeContext.bind(globalContextRegistry);
|
|
3081
3171
|
const getContext = globalContextRegistry.getContext.bind(globalContextRegistry);
|
|
@@ -3087,6 +3177,7 @@ exports.ContextRegistry = ContextRegistry;
|
|
|
3087
3177
|
exports.DEFAULT_CONTEXT_ID = DEFAULT_CONTEXT_ID;
|
|
3088
3178
|
exports.FlowContext = FlowContext;
|
|
3089
3179
|
exports.FlowMap = FlowMap;
|
|
3180
|
+
exports.FlowRdfCoreGlobals = FlowRdfCoreGlobals;
|
|
3090
3181
|
exports.MapLayerStyleBuilder = MapLayerStyleBuilder;
|
|
3091
3182
|
exports.MapStyle = MapStyle;
|
|
3092
3183
|
exports.Query = Query;
|
|
@@ -3095,8 +3186,9 @@ exports.StyleExpression = StyleExpression;
|
|
|
3095
3186
|
exports.computed = computed;
|
|
3096
3187
|
exports.expr = expr;
|
|
3097
3188
|
exports.getContext = getContext;
|
|
3098
|
-
exports.
|
|
3189
|
+
exports.getGlobalState = getGlobalState;
|
|
3099
3190
|
exports.initializeContext = initializeContext;
|
|
3191
|
+
exports.isolateGlobalState = isolateGlobalState;
|
|
3100
3192
|
exports.layerStyle = layerStyle;
|
|
3101
3193
|
exports.observable = observable;
|
|
3102
3194
|
exports.query = query;
|
package/dist/index.d.cts
CHANGED
|
@@ -40,7 +40,20 @@ declare class ContextRegistry {
|
|
|
40
40
|
uninitializeContext(contextId?: string): void;
|
|
41
41
|
getContext<TState extends StateStore = StateStore>(id?: string): Promise<FlowContext<TState>>;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
declare class FlowRdfCoreGlobals {
|
|
45
|
+
/**
|
|
46
|
+
* FlowRdfCoreGlobals version.
|
|
47
|
+
* Compatiblity with other versions loaded in memory as long as this version matches.
|
|
48
|
+
* It indicates that the global state still stores similar information
|
|
49
|
+
*
|
|
50
|
+
* N.B: this version is unrelated to the package version.
|
|
51
|
+
*/
|
|
52
|
+
version: number;
|
|
53
|
+
globalContextRegistry: ContextRegistry;
|
|
54
|
+
}
|
|
55
|
+
declare function isolateGlobalState(): void;
|
|
56
|
+
declare function getGlobalState(): FlowRdfCoreGlobals;
|
|
44
57
|
|
|
45
58
|
interface MapStyleOptions {
|
|
46
59
|
id: string;
|
|
@@ -72,4 +85,4 @@ declare const initializeContext: <TState extends StateStore = StateStore>(option
|
|
|
72
85
|
declare const uninitializeContext: (contextId?: string) => void;
|
|
73
86
|
declare const getContext: <TState extends StateStore = StateStore>(id?: string) => Promise<FlowContext<TState>>;
|
|
74
87
|
|
|
75
|
-
export { ContextRegistry, FlowContext, FlowContextOptions, MapDataSource, MapLayer, MapStyle, MapStyleOptions, MapStyleSpecification, StateStore, computed, getContext,
|
|
88
|
+
export { ContextRegistry, FlowContext, FlowContextOptions, FlowRdfCoreGlobals, MapDataSource, MapLayer, MapStyle, MapStyleOptions, MapStyleSpecification, StateStore, computed, getContext, getGlobalState, initializeContext, isolateGlobalState, observable, serialize, uninitializeContext };
|
package/dist/index.d.mts
CHANGED
|
@@ -40,7 +40,20 @@ declare class ContextRegistry {
|
|
|
40
40
|
uninitializeContext(contextId?: string): void;
|
|
41
41
|
getContext<TState extends StateStore = StateStore>(id?: string): Promise<FlowContext<TState>>;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
declare class FlowRdfCoreGlobals {
|
|
45
|
+
/**
|
|
46
|
+
* FlowRdfCoreGlobals version.
|
|
47
|
+
* Compatiblity with other versions loaded in memory as long as this version matches.
|
|
48
|
+
* It indicates that the global state still stores similar information
|
|
49
|
+
*
|
|
50
|
+
* N.B: this version is unrelated to the package version.
|
|
51
|
+
*/
|
|
52
|
+
version: number;
|
|
53
|
+
globalContextRegistry: ContextRegistry;
|
|
54
|
+
}
|
|
55
|
+
declare function isolateGlobalState(): void;
|
|
56
|
+
declare function getGlobalState(): FlowRdfCoreGlobals;
|
|
44
57
|
|
|
45
58
|
interface MapStyleOptions {
|
|
46
59
|
id: string;
|
|
@@ -72,4 +85,4 @@ declare const initializeContext: <TState extends StateStore = StateStore>(option
|
|
|
72
85
|
declare const uninitializeContext: (contextId?: string) => void;
|
|
73
86
|
declare const getContext: <TState extends StateStore = StateStore>(id?: string) => Promise<FlowContext<TState>>;
|
|
74
87
|
|
|
75
|
-
export { ContextRegistry, FlowContext, FlowContextOptions, MapDataSource, MapLayer, MapStyle, MapStyleOptions, MapStyleSpecification, StateStore, computed, getContext,
|
|
88
|
+
export { ContextRegistry, FlowContext, FlowContextOptions, FlowRdfCoreGlobals, MapDataSource, MapLayer, MapStyle, MapStyleOptions, MapStyleSpecification, StateStore, computed, getContext, getGlobalState, initializeContext, isolateGlobalState, observable, serialize, uninitializeContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -40,7 +40,20 @@ declare class ContextRegistry {
|
|
|
40
40
|
uninitializeContext(contextId?: string): void;
|
|
41
41
|
getContext<TState extends StateStore = StateStore>(id?: string): Promise<FlowContext<TState>>;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
declare class FlowRdfCoreGlobals {
|
|
45
|
+
/**
|
|
46
|
+
* FlowRdfCoreGlobals version.
|
|
47
|
+
* Compatiblity with other versions loaded in memory as long as this version matches.
|
|
48
|
+
* It indicates that the global state still stores similar information
|
|
49
|
+
*
|
|
50
|
+
* N.B: this version is unrelated to the package version.
|
|
51
|
+
*/
|
|
52
|
+
version: number;
|
|
53
|
+
globalContextRegistry: ContextRegistry;
|
|
54
|
+
}
|
|
55
|
+
declare function isolateGlobalState(): void;
|
|
56
|
+
declare function getGlobalState(): FlowRdfCoreGlobals;
|
|
44
57
|
|
|
45
58
|
interface MapStyleOptions {
|
|
46
59
|
id: string;
|
|
@@ -72,4 +85,4 @@ declare const initializeContext: <TState extends StateStore = StateStore>(option
|
|
|
72
85
|
declare const uninitializeContext: (contextId?: string) => void;
|
|
73
86
|
declare const getContext: <TState extends StateStore = StateStore>(id?: string) => Promise<FlowContext<TState>>;
|
|
74
87
|
|
|
75
|
-
export { ContextRegistry, FlowContext, FlowContextOptions, MapDataSource, MapLayer, MapStyle, MapStyleOptions, MapStyleSpecification, StateStore, computed, getContext,
|
|
88
|
+
export { ContextRegistry, FlowContext, FlowContextOptions, FlowRdfCoreGlobals, MapDataSource, MapLayer, MapStyle, MapStyleOptions, MapStyleSpecification, StateStore, computed, getContext, getGlobalState, initializeContext, isolateGlobalState, observable, serialize, uninitializeContext };
|
package/dist/index.mjs
CHANGED
|
@@ -13,6 +13,34 @@ import 'parsimmon';
|
|
|
13
13
|
import 'colorbrewer';
|
|
14
14
|
import 'nanoid';
|
|
15
15
|
|
|
16
|
+
const version = "0.0.22";
|
|
17
|
+
|
|
18
|
+
const CONSOLE_HIGHLIGHT_STYLE$1 = `
|
|
19
|
+
padding: 2px 4px;
|
|
20
|
+
border-radius: 2px;
|
|
21
|
+
background: #389DFF;
|
|
22
|
+
color: white;`;
|
|
23
|
+
function announce() {
|
|
24
|
+
console.log("%cFlo.w RDF Core v%s", CONSOLE_HIGHLIGHT_STYLE$1, version);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const mockGlobal = {};
|
|
28
|
+
function getGlobal() {
|
|
29
|
+
if (typeof globalThis !== "undefined") {
|
|
30
|
+
return globalThis;
|
|
31
|
+
}
|
|
32
|
+
if (typeof window !== "undefined") {
|
|
33
|
+
return window;
|
|
34
|
+
}
|
|
35
|
+
if (typeof global !== "undefined") {
|
|
36
|
+
return global;
|
|
37
|
+
}
|
|
38
|
+
if (typeof self !== "undefined") {
|
|
39
|
+
return self;
|
|
40
|
+
}
|
|
41
|
+
return mockGlobal;
|
|
42
|
+
}
|
|
43
|
+
|
|
16
44
|
function deferred() {
|
|
17
45
|
let methods;
|
|
18
46
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -21,10 +49,10 @@ function deferred() {
|
|
|
21
49
|
return Object.assign(promise, methods);
|
|
22
50
|
}
|
|
23
51
|
|
|
24
|
-
var __defProp$
|
|
25
|
-
var __defNormalProp$
|
|
26
|
-
var __publicField$
|
|
27
|
-
__defNormalProp$
|
|
52
|
+
var __defProp$d = Object.defineProperty;
|
|
53
|
+
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
54
|
+
var __publicField$d = (obj, key, value) => {
|
|
55
|
+
__defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
28
56
|
return value;
|
|
29
57
|
};
|
|
30
58
|
const FLOW_GLOBAL = "FDBG";
|
|
@@ -45,8 +73,8 @@ class Debugger {
|
|
|
45
73
|
*/
|
|
46
74
|
constructor(context) {
|
|
47
75
|
this.context = context;
|
|
48
|
-
__publicField$
|
|
49
|
-
__publicField$
|
|
76
|
+
__publicField$d(this, "spyDisposer");
|
|
77
|
+
__publicField$d(this, "watchDisposers", {});
|
|
50
78
|
}
|
|
51
79
|
/**
|
|
52
80
|
* Install a 'watch' for the specified context state property path.
|
|
@@ -233,16 +261,16 @@ function toJSHelper(source, options, __alreadySeen = null) {
|
|
|
233
261
|
return res;
|
|
234
262
|
}
|
|
235
263
|
|
|
236
|
-
var __defProp$
|
|
237
|
-
var __defNormalProp$
|
|
238
|
-
var __publicField$
|
|
239
|
-
__defNormalProp$
|
|
264
|
+
var __defProp$c = Object.defineProperty;
|
|
265
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
266
|
+
var __publicField$c = (obj, key, value) => {
|
|
267
|
+
__defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
240
268
|
return value;
|
|
241
269
|
};
|
|
242
270
|
const debug$4 = Debug("flow:map-registry");
|
|
243
271
|
class MapRegistry {
|
|
244
272
|
constructor() {
|
|
245
|
-
__publicField$
|
|
273
|
+
__publicField$c(this, "_maps", /* @__PURE__ */ new Map());
|
|
246
274
|
}
|
|
247
275
|
/**
|
|
248
276
|
* Register a Flo.w map.
|
|
@@ -284,16 +312,16 @@ class MapRegistry {
|
|
|
284
312
|
}
|
|
285
313
|
}
|
|
286
314
|
|
|
287
|
-
var __defProp$
|
|
288
|
-
var __defNormalProp$
|
|
289
|
-
var __publicField$
|
|
290
|
-
__defNormalProp$
|
|
315
|
+
var __defProp$b = Object.defineProperty;
|
|
316
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
317
|
+
var __publicField$b = (obj, key, value) => {
|
|
318
|
+
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
291
319
|
return value;
|
|
292
320
|
};
|
|
293
321
|
const debug$3 = Debug("flow:query-registry");
|
|
294
322
|
class QueryRegistry {
|
|
295
323
|
constructor() {
|
|
296
|
-
__publicField$
|
|
324
|
+
__publicField$b(this, "_queries", /* @__PURE__ */ new Map());
|
|
297
325
|
}
|
|
298
326
|
/**
|
|
299
327
|
* Register a Flo.w reactive query.
|
|
@@ -333,10 +361,10 @@ class QueryRegistry {
|
|
|
333
361
|
}
|
|
334
362
|
}
|
|
335
363
|
|
|
336
|
-
var __defProp$
|
|
337
|
-
var __defNormalProp$
|
|
338
|
-
var __publicField$
|
|
339
|
-
__defNormalProp$
|
|
364
|
+
var __defProp$a = Object.defineProperty;
|
|
365
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
366
|
+
var __publicField$a = (obj, key, value) => {
|
|
367
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
340
368
|
return value;
|
|
341
369
|
};
|
|
342
370
|
const DEFAULT_FLOW_HOST = "https://flow.emu-analytics.net";
|
|
@@ -353,13 +381,13 @@ const _FlowContext = class _FlowContext {
|
|
|
353
381
|
* @param enableDebug Set to `true` to enable the debugger.
|
|
354
382
|
*/
|
|
355
383
|
constructor(options) {
|
|
356
|
-
__publicField$
|
|
357
|
-
__publicField$
|
|
358
|
-
__publicField$
|
|
359
|
-
__publicField$
|
|
360
|
-
__publicField$
|
|
384
|
+
__publicField$a(this, "_options");
|
|
385
|
+
__publicField$a(this, "flowClient");
|
|
386
|
+
__publicField$a(this, "state");
|
|
387
|
+
__publicField$a(this, "maps", new MapRegistry());
|
|
388
|
+
__publicField$a(this, "queries", new QueryRegistry());
|
|
361
389
|
/** The Flo.w debugger. Available as `window.FDBG` in the browser's web developer console. */
|
|
362
|
-
__publicField$
|
|
390
|
+
__publicField$a(this, "debugger");
|
|
363
391
|
this._options = {
|
|
364
392
|
..._FlowContext._defaultOptions,
|
|
365
393
|
...options
|
|
@@ -383,23 +411,23 @@ const _FlowContext = class _FlowContext {
|
|
|
383
411
|
return expression.value;
|
|
384
412
|
}
|
|
385
413
|
};
|
|
386
|
-
__publicField$
|
|
414
|
+
__publicField$a(_FlowContext, "_defaultOptions", {
|
|
387
415
|
id: DEFAULT_CONTEXT_ID,
|
|
388
416
|
host: DEFAULT_FLOW_HOST,
|
|
389
417
|
enableDebug: false
|
|
390
418
|
});
|
|
391
419
|
let FlowContext = _FlowContext;
|
|
392
420
|
|
|
393
|
-
var __defProp$
|
|
394
|
-
var __defNormalProp$
|
|
395
|
-
var __publicField$
|
|
396
|
-
__defNormalProp$
|
|
421
|
+
var __defProp$9 = Object.defineProperty;
|
|
422
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
423
|
+
var __publicField$9 = (obj, key, value) => {
|
|
424
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
397
425
|
return value;
|
|
398
426
|
};
|
|
399
427
|
const debug$2 = Debug("flow:context-registry");
|
|
400
428
|
const _ContextRegistry = class _ContextRegistry {
|
|
401
429
|
constructor() {
|
|
402
|
-
__publicField$
|
|
430
|
+
__publicField$9(this, "_contexts", /* @__PURE__ */ new Map());
|
|
403
431
|
}
|
|
404
432
|
/**
|
|
405
433
|
* Initialize a new Flo.w context.
|
|
@@ -442,12 +470,72 @@ const _ContextRegistry = class _ContextRegistry {
|
|
|
442
470
|
return deferredContext?.deferred;
|
|
443
471
|
}
|
|
444
472
|
};
|
|
445
|
-
__publicField$
|
|
473
|
+
__publicField$9(_ContextRegistry, "_defaultOptions", {
|
|
446
474
|
id: DEFAULT_CONTEXT_ID,
|
|
447
475
|
host: "https://flow.emu-analytics.net"
|
|
448
476
|
});
|
|
449
477
|
let ContextRegistry = _ContextRegistry;
|
|
450
|
-
|
|
478
|
+
|
|
479
|
+
var __defProp$8 = Object.defineProperty;
|
|
480
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
481
|
+
var __publicField$8 = (obj, key, value) => {
|
|
482
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
483
|
+
return value;
|
|
484
|
+
};
|
|
485
|
+
class FlowRdfCoreGlobals {
|
|
486
|
+
constructor() {
|
|
487
|
+
/**
|
|
488
|
+
* FlowRdfCoreGlobals version.
|
|
489
|
+
* Compatiblity with other versions loaded in memory as long as this version matches.
|
|
490
|
+
* It indicates that the global state still stores similar information
|
|
491
|
+
*
|
|
492
|
+
* N.B: this version is unrelated to the package version.
|
|
493
|
+
*/
|
|
494
|
+
__publicField$8(this, "version", 1);
|
|
495
|
+
__publicField$8(this, "globalContextRegistry", new ContextRegistry());
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
let canMergeGlobalState = true;
|
|
499
|
+
let isolateCalled = false;
|
|
500
|
+
let globalState = function() {
|
|
501
|
+
const global = getGlobal();
|
|
502
|
+
if (global.__flowRdfCoreInstanceCount > 0 && !global.__flowRdfCoreGlobals) {
|
|
503
|
+
canMergeGlobalState = false;
|
|
504
|
+
}
|
|
505
|
+
if (global.__flowRdfCoreGlobals && global.__flowRdfCoreGlobals.version !== new FlowRdfCoreGlobals().version) {
|
|
506
|
+
canMergeGlobalState = false;
|
|
507
|
+
}
|
|
508
|
+
if (!canMergeGlobalState) {
|
|
509
|
+
setTimeout(() => {
|
|
510
|
+
if (!isolateCalled) {
|
|
511
|
+
throw new Error(
|
|
512
|
+
'There are multiple, different versions of FlowRdfCore active. Make sure FlowRdfCore is loaded only once or use `configure({ isolateGlobalState: true })`",'
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
}, 1);
|
|
516
|
+
return new FlowRdfCoreGlobals();
|
|
517
|
+
} else if (global.__flowRdfCoreGlobals) {
|
|
518
|
+
global.__flowRdfCoreInstanceCount += 1;
|
|
519
|
+
return global.__flowRdfCoreGlobals;
|
|
520
|
+
} else {
|
|
521
|
+
global.__flowRdfCoreInstanceCount = 1;
|
|
522
|
+
announce();
|
|
523
|
+
return global.__flowRdfCoreGlobals = new FlowRdfCoreGlobals();
|
|
524
|
+
}
|
|
525
|
+
}();
|
|
526
|
+
function isolateGlobalState() {
|
|
527
|
+
isolateCalled = true;
|
|
528
|
+
if (canMergeGlobalState) {
|
|
529
|
+
const global = getGlobal();
|
|
530
|
+
if (--global.__flowRdfCoreInstanceCount === 0) {
|
|
531
|
+
global.__flowRdfCoreGlobals = void 0;
|
|
532
|
+
}
|
|
533
|
+
globalState = new FlowRdfCoreGlobals();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function getGlobalState() {
|
|
537
|
+
return globalState;
|
|
538
|
+
}
|
|
451
539
|
|
|
452
540
|
var __defProp$7 = Object.defineProperty;
|
|
453
541
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -2472,6 +2560,7 @@ const _FlowMap = class _FlowMap extends EventEmitter {
|
|
|
2472
2560
|
}
|
|
2473
2561
|
}
|
|
2474
2562
|
async initialize() {
|
|
2563
|
+
const globalContextRegistry = getGlobalState().globalContextRegistry;
|
|
2475
2564
|
this._context = await globalContextRegistry.getContext(this._options.contextId);
|
|
2476
2565
|
this._style.bindState(this._context.state);
|
|
2477
2566
|
const baseStyle = await this.loadBaseStyle(this._options.baseStyle);
|
|
@@ -2583,7 +2672,7 @@ const _Query = class _Query {
|
|
|
2583
2672
|
if (transformFn) {
|
|
2584
2673
|
this._transformFn = transformFn;
|
|
2585
2674
|
}
|
|
2586
|
-
globalContextRegistry.getContext(this._options?.contextId).then((context) => {
|
|
2675
|
+
getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
|
|
2587
2676
|
context.queries.registerQuery(this);
|
|
2588
2677
|
});
|
|
2589
2678
|
}
|
|
@@ -2597,12 +2686,12 @@ const _Query = class _Query {
|
|
|
2597
2686
|
return this._options.id;
|
|
2598
2687
|
}
|
|
2599
2688
|
destroy() {
|
|
2600
|
-
globalContextRegistry.getContext(this._options?.contextId).then((context) => {
|
|
2689
|
+
getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
|
|
2601
2690
|
context.queries.unregisterQuery(this);
|
|
2602
2691
|
});
|
|
2603
2692
|
}
|
|
2604
2693
|
async runImmediately() {
|
|
2605
|
-
const context = await globalContextRegistry.getContext(this._options.contextId);
|
|
2694
|
+
const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
|
|
2606
2695
|
const queryDefinition = this.queryFn.call(context.state, context.state);
|
|
2607
2696
|
await this.runQuery(queryDefinition);
|
|
2608
2697
|
if (this.error) {
|
|
@@ -2612,7 +2701,7 @@ const _Query = class _Query {
|
|
|
2612
2701
|
}
|
|
2613
2702
|
async wake() {
|
|
2614
2703
|
this.sleep();
|
|
2615
|
-
const context = await globalContextRegistry.getContext(this._options.contextId);
|
|
2704
|
+
const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
|
|
2616
2705
|
this._disposer = reaction(
|
|
2617
2706
|
(r) => {
|
|
2618
2707
|
return this.queryFn.call(context.state, context.state);
|
|
@@ -2638,7 +2727,7 @@ const _Query = class _Query {
|
|
|
2638
2727
|
}
|
|
2639
2728
|
async runQuery(queryDefinition) {
|
|
2640
2729
|
debug(`${this.formattedName}: running query`, queryDefinition);
|
|
2641
|
-
const context = await globalContextRegistry.getContext(this._options.contextId);
|
|
2730
|
+
const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
|
|
2642
2731
|
try {
|
|
2643
2732
|
if (queryDefinition === null) {
|
|
2644
2733
|
runInAction(() => {
|
|
@@ -3056,8 +3145,9 @@ function traceReaction() {
|
|
|
3056
3145
|
}
|
|
3057
3146
|
|
|
3058
3147
|
configure({ isolateGlobalState: false, useProxies: "always" });
|
|
3148
|
+
const globalContextRegistry = getGlobalState().globalContextRegistry;
|
|
3059
3149
|
const initializeContext = globalContextRegistry.initializeContext.bind(globalContextRegistry);
|
|
3060
3150
|
const uninitializeContext = globalContextRegistry.uninitializeContext.bind(globalContextRegistry);
|
|
3061
3151
|
const getContext = globalContextRegistry.getContext.bind(globalContextRegistry);
|
|
3062
3152
|
|
|
3063
|
-
export { ContextRegistry, DEFAULT_CONTEXT_ID, FlowContext, FlowMap, MapDataSource, MapLayer, MapLayerStyleBuilder, MapStyle, Query, ReactiveExpression, StateStore, StyleExpression, computed, expr, getContext,
|
|
3153
|
+
export { ContextRegistry, DEFAULT_CONTEXT_ID, FlowContext, FlowMap, FlowRdfCoreGlobals, MapDataSource, MapLayer, MapLayerStyleBuilder, MapStyle, Query, ReactiveExpression, StateStore, StyleExpression, computed, expr, getContext, getGlobalState, initializeContext, isolateGlobalState, layerStyle, observable, query, queryMany, queryOne, serialize, traceReaction, uninitializeContext };
|