@emuanalytics/flow-rdf-core 0.0.19 → 0.0.21

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 CHANGED
@@ -33,6 +33,23 @@ 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 mockGlobal = {};
37
+ function getGlobal() {
38
+ if (typeof globalThis !== "undefined") {
39
+ return globalThis;
40
+ }
41
+ if (typeof window !== "undefined") {
42
+ return window;
43
+ }
44
+ if (typeof global !== "undefined") {
45
+ return global;
46
+ }
47
+ if (typeof self !== "undefined") {
48
+ return self;
49
+ }
50
+ return mockGlobal;
51
+ }
52
+
36
53
  function deferred() {
37
54
  let methods;
38
55
  const promise = new Promise((resolve, reject) => {
@@ -41,14 +58,14 @@ function deferred() {
41
58
  return Object.assign(promise, methods);
42
59
  }
43
60
 
44
- var __defProp$c = Object.defineProperty;
45
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
46
- var __publicField$c = (obj, key, value) => {
47
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
61
+ var __defProp$d = Object.defineProperty;
62
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
63
+ var __publicField$d = (obj, key, value) => {
64
+ __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
48
65
  return value;
49
66
  };
50
67
  const FLOW_GLOBAL = "FDBG";
51
- const CONSOLE_HIGHLIGHT_STYLE = `
68
+ const CONSOLE_HIGHLIGHT_STYLE$1 = `
52
69
  padding: 2px 4px;
53
70
  border-radius: 2px;
54
71
  background: #389DFF;
@@ -65,8 +82,8 @@ class Debugger {
65
82
  */
66
83
  constructor(context) {
67
84
  this.context = context;
68
- __publicField$c(this, "spyDisposer");
69
- __publicField$c(this, "watchDisposers", {});
85
+ __publicField$d(this, "spyDisposer");
86
+ __publicField$d(this, "watchDisposers", {});
70
87
  }
71
88
  /**
72
89
  * Install a 'watch' for the specified context state property path.
@@ -147,17 +164,17 @@ class Debugger {
147
164
  }
148
165
  }
149
166
  spyListener(event) {
150
- console.log(`%cspy`, CONSOLE_HIGHLIGHT_STYLE, event);
167
+ console.log(`%cspy`, CONSOLE_HIGHLIGHT_STYLE$1, event);
151
168
  }
152
169
  logStateValue(path) {
153
170
  const value = toJSHelper(this.context.state.get(path), { recurseEverything: false });
154
- console.log(`%cwatch%c %s`, CONSOLE_HIGHLIGHT_STYLE, CONSOLE_BOLD_STYLE, path, value);
171
+ console.log(`%cwatch%c %s`, CONSOLE_HIGHLIGHT_STYLE$1, CONSOLE_BOLD_STYLE, path, value);
155
172
  }
156
173
  }
157
174
  function installGlobalDebugger(dbg) {
158
175
  console.log(
159
176
  `%cFlow.w RDF Debbugger`,
160
- CONSOLE_HIGHLIGHT_STYLE,
177
+ CONSOLE_HIGHLIGHT_STYLE$1,
161
178
  `Enabled for context '${dbg.context.id}' - access using ${FLOW_GLOBAL} in web developer console.`
162
179
  );
163
180
  const g = typeof global !== "undefined" ? global : window;
@@ -253,16 +270,16 @@ function toJSHelper(source, options, __alreadySeen = null) {
253
270
  return res;
254
271
  }
255
272
 
256
- var __defProp$b = Object.defineProperty;
257
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
258
- var __publicField$b = (obj, key, value) => {
259
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
273
+ var __defProp$c = Object.defineProperty;
274
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
275
+ var __publicField$c = (obj, key, value) => {
276
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
260
277
  return value;
261
278
  };
262
279
  const debug$4 = Debug__default("flow:map-registry");
263
280
  class MapRegistry {
264
281
  constructor() {
265
- __publicField$b(this, "_maps", /* @__PURE__ */ new Map());
282
+ __publicField$c(this, "_maps", /* @__PURE__ */ new Map());
266
283
  }
267
284
  /**
268
285
  * Register a Flo.w map.
@@ -304,16 +321,16 @@ class MapRegistry {
304
321
  }
305
322
  }
306
323
 
307
- var __defProp$a = Object.defineProperty;
308
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
309
- var __publicField$a = (obj, key, value) => {
310
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
324
+ var __defProp$b = Object.defineProperty;
325
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
326
+ var __publicField$b = (obj, key, value) => {
327
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
311
328
  return value;
312
329
  };
313
330
  const debug$3 = Debug__default("flow:query-registry");
314
331
  class QueryRegistry {
315
332
  constructor() {
316
- __publicField$a(this, "_queries", /* @__PURE__ */ new Map());
333
+ __publicField$b(this, "_queries", /* @__PURE__ */ new Map());
317
334
  }
318
335
  /**
319
336
  * Register a Flo.w reactive query.
@@ -353,10 +370,10 @@ class QueryRegistry {
353
370
  }
354
371
  }
355
372
 
356
- var __defProp$9 = Object.defineProperty;
357
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
358
- var __publicField$9 = (obj, key, value) => {
359
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
373
+ var __defProp$a = Object.defineProperty;
374
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
375
+ var __publicField$a = (obj, key, value) => {
376
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
360
377
  return value;
361
378
  };
362
379
  const DEFAULT_FLOW_HOST = "https://flow.emu-analytics.net";
@@ -373,13 +390,13 @@ const _FlowContext = class _FlowContext {
373
390
  * @param enableDebug Set to `true` to enable the debugger.
374
391
  */
375
392
  constructor(options) {
376
- __publicField$9(this, "_options");
377
- __publicField$9(this, "flowClient");
378
- __publicField$9(this, "state");
379
- __publicField$9(this, "maps", new MapRegistry());
380
- __publicField$9(this, "queries", new QueryRegistry());
393
+ __publicField$a(this, "_options");
394
+ __publicField$a(this, "flowClient");
395
+ __publicField$a(this, "state");
396
+ __publicField$a(this, "maps", new MapRegistry());
397
+ __publicField$a(this, "queries", new QueryRegistry());
381
398
  /** The Flo.w debugger. Available as `window.FDBG` in the browser's web developer console. */
382
- __publicField$9(this, "debugger");
399
+ __publicField$a(this, "debugger");
383
400
  this._options = {
384
401
  ..._FlowContext._defaultOptions,
385
402
  ...options
@@ -403,23 +420,23 @@ const _FlowContext = class _FlowContext {
403
420
  return expression.value;
404
421
  }
405
422
  };
406
- __publicField$9(_FlowContext, "_defaultOptions", {
423
+ __publicField$a(_FlowContext, "_defaultOptions", {
407
424
  id: DEFAULT_CONTEXT_ID,
408
425
  host: DEFAULT_FLOW_HOST,
409
426
  enableDebug: false
410
427
  });
411
428
  let FlowContext = _FlowContext;
412
429
 
413
- var __defProp$8 = Object.defineProperty;
414
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
415
- var __publicField$8 = (obj, key, value) => {
416
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
430
+ var __defProp$9 = Object.defineProperty;
431
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
432
+ var __publicField$9 = (obj, key, value) => {
433
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
417
434
  return value;
418
435
  };
419
436
  const debug$2 = Debug__default("flow:context-registry");
420
437
  const _ContextRegistry = class _ContextRegistry {
421
438
  constructor() {
422
- __publicField$8(this, "_contexts", /* @__PURE__ */ new Map());
439
+ __publicField$9(this, "_contexts", /* @__PURE__ */ new Map());
423
440
  }
424
441
  /**
425
442
  * Initialize a new Flo.w context.
@@ -462,12 +479,85 @@ const _ContextRegistry = class _ContextRegistry {
462
479
  return deferredContext?.deferred;
463
480
  }
464
481
  };
465
- __publicField$8(_ContextRegistry, "_defaultOptions", {
482
+ __publicField$9(_ContextRegistry, "_defaultOptions", {
466
483
  id: DEFAULT_CONTEXT_ID,
467
484
  host: "https://flow.emu-analytics.net"
468
485
  });
469
486
  let ContextRegistry = _ContextRegistry;
470
- const globalContextRegistry = new ContextRegistry();
487
+
488
+ var __defProp$8 = Object.defineProperty;
489
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
490
+ var __publicField$8 = (obj, key, value) => {
491
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
492
+ return value;
493
+ };
494
+ class FlowRdfCoreGlobals {
495
+ constructor() {
496
+ /**
497
+ * FlowRdfCoreGlobals version.
498
+ * Compatiblity with other versions loaded in memory as long as this version matches.
499
+ * It indicates that the global state still stores similar information
500
+ *
501
+ * N.B: this version is unrelated to the package version.
502
+ */
503
+ __publicField$8(this, "version", 1);
504
+ __publicField$8(this, "globalContextRegistry", new ContextRegistry());
505
+ }
506
+ }
507
+ let canMergeGlobalState = true;
508
+ let isolateCalled = false;
509
+ let globalState = function() {
510
+ const global = getGlobal();
511
+ if (global.__flowRdfCoreInstanceCount > 0 && !global.__flowRdfCoreGlobals) {
512
+ canMergeGlobalState = false;
513
+ }
514
+ if (global.__flowRdfCoreGlobals && global.__flowRdfCoreGlobals.version !== new FlowRdfCoreGlobals().version) {
515
+ canMergeGlobalState = false;
516
+ }
517
+ if (!canMergeGlobalState) {
518
+ setTimeout(() => {
519
+ if (!isolateCalled) {
520
+ throw new Error(
521
+ 'There are multiple, different versions of FlowRdfCore active. Make sure FlowRdfCore is loaded only once or use `configure({ isolateGlobalState: true })`",'
522
+ );
523
+ }
524
+ }, 1);
525
+ return new FlowRdfCoreGlobals();
526
+ } else if (global.__flowRdfCoreGlobals) {
527
+ global.__flowRdfCoreInstanceCount += 1;
528
+ if (!global.__mobxGlobals.UNCHANGED) {
529
+ global.__mobxGlobals.UNCHANGED = {};
530
+ }
531
+ return global.__flowRdfCoreGlobals;
532
+ } else {
533
+ global.__mobxInstanceCount = 1;
534
+ return global.__flowRdfCoreGlobals = new FlowRdfCoreGlobals();
535
+ }
536
+ }();
537
+ function isolateGlobalState() {
538
+ isolateCalled = true;
539
+ if (canMergeGlobalState) {
540
+ const global = getGlobal();
541
+ if (--global.__flowRdfCoreInstanceCount === 0) {
542
+ global.__flowRdfCoreGlobals = void 0;
543
+ }
544
+ globalState = new FlowRdfCoreGlobals();
545
+ }
546
+ }
547
+ function getGlobalState() {
548
+ return globalState;
549
+ }
550
+
551
+ const version = "0.0.21";
552
+
553
+ const CONSOLE_HIGHLIGHT_STYLE = `
554
+ padding: 2px 4px;
555
+ border-radius: 2px;
556
+ background: #389DFF;
557
+ color: white;`;
558
+ function announce() {
559
+ console.log("%cFlo.w RDF Core v%s", CONSOLE_HIGHLIGHT_STYLE, version);
560
+ }
471
561
 
472
562
  var __defProp$7 = Object.defineProperty;
473
563
  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 +2582,7 @@ const _FlowMap = class _FlowMap extends EventEmitter__default {
2492
2582
  }
2493
2583
  }
2494
2584
  async initialize() {
2585
+ const globalContextRegistry = getGlobalState().globalContextRegistry;
2495
2586
  this._context = await globalContextRegistry.getContext(this._options.contextId);
2496
2587
  this._style.bindState(this._context.state);
2497
2588
  const baseStyle = await this.loadBaseStyle(this._options.baseStyle);
@@ -2603,7 +2694,7 @@ const _Query = class _Query {
2603
2694
  if (transformFn) {
2604
2695
  this._transformFn = transformFn;
2605
2696
  }
2606
- globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2697
+ getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2607
2698
  context.queries.registerQuery(this);
2608
2699
  });
2609
2700
  }
@@ -2617,12 +2708,12 @@ const _Query = class _Query {
2617
2708
  return this._options.id;
2618
2709
  }
2619
2710
  destroy() {
2620
- globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2711
+ getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2621
2712
  context.queries.unregisterQuery(this);
2622
2713
  });
2623
2714
  }
2624
2715
  async runImmediately() {
2625
- const context = await globalContextRegistry.getContext(this._options.contextId);
2716
+ const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
2626
2717
  const queryDefinition = this.queryFn.call(context.state, context.state);
2627
2718
  await this.runQuery(queryDefinition);
2628
2719
  if (this.error) {
@@ -2632,7 +2723,7 @@ const _Query = class _Query {
2632
2723
  }
2633
2724
  async wake() {
2634
2725
  this.sleep();
2635
- const context = await globalContextRegistry.getContext(this._options.contextId);
2726
+ const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
2636
2727
  this._disposer = mobx.reaction(
2637
2728
  (r) => {
2638
2729
  return this.queryFn.call(context.state, context.state);
@@ -2658,7 +2749,7 @@ const _Query = class _Query {
2658
2749
  }
2659
2750
  async runQuery(queryDefinition) {
2660
2751
  debug(`${this.formattedName}: running query`, queryDefinition);
2661
- const context = await globalContextRegistry.getContext(this._options.contextId);
2752
+ const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
2662
2753
  try {
2663
2754
  if (queryDefinition === null) {
2664
2755
  mobx.runInAction(() => {
@@ -3075,10 +3166,12 @@ function traceReaction() {
3075
3166
  mobx.trace();
3076
3167
  }
3077
3168
 
3078
- mobx.configure({ isolateGlobalState: true });
3169
+ mobx.configure({ isolateGlobalState: false, useProxies: "always" });
3170
+ const globalContextRegistry = getGlobalState().globalContextRegistry;
3079
3171
  const initializeContext = globalContextRegistry.initializeContext.bind(globalContextRegistry);
3080
3172
  const uninitializeContext = globalContextRegistry.uninitializeContext.bind(globalContextRegistry);
3081
3173
  const getContext = globalContextRegistry.getContext.bind(globalContextRegistry);
3174
+ announce();
3082
3175
 
3083
3176
  exports.MapDataSource = mapFeatureStream.MapDataSource;
3084
3177
  exports.MapLayer = mapFeatureStream.MapLayer;
@@ -3087,6 +3180,7 @@ exports.ContextRegistry = ContextRegistry;
3087
3180
  exports.DEFAULT_CONTEXT_ID = DEFAULT_CONTEXT_ID;
3088
3181
  exports.FlowContext = FlowContext;
3089
3182
  exports.FlowMap = FlowMap;
3183
+ exports.FlowRdfCoreGlobals = FlowRdfCoreGlobals;
3090
3184
  exports.MapLayerStyleBuilder = MapLayerStyleBuilder;
3091
3185
  exports.MapStyle = MapStyle;
3092
3186
  exports.Query = Query;
@@ -3095,8 +3189,9 @@ exports.StyleExpression = StyleExpression;
3095
3189
  exports.computed = computed;
3096
3190
  exports.expr = expr;
3097
3191
  exports.getContext = getContext;
3098
- exports.globalContextRegistry = globalContextRegistry;
3192
+ exports.getGlobalState = getGlobalState;
3099
3193
  exports.initializeContext = initializeContext;
3194
+ exports.isolateGlobalState = isolateGlobalState;
3100
3195
  exports.layerStyle = layerStyle;
3101
3196
  exports.observable = observable;
3102
3197
  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
- declare const globalContextRegistry: ContextRegistry;
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, globalContextRegistry, initializeContext, observable, serialize, uninitializeContext };
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
- declare const globalContextRegistry: ContextRegistry;
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, globalContextRegistry, initializeContext, observable, serialize, uninitializeContext };
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
- declare const globalContextRegistry: ContextRegistry;
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, globalContextRegistry, initializeContext, observable, serialize, uninitializeContext };
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,23 @@ import 'parsimmon';
13
13
  import 'colorbrewer';
14
14
  import 'nanoid';
15
15
 
16
+ const mockGlobal = {};
17
+ function getGlobal() {
18
+ if (typeof globalThis !== "undefined") {
19
+ return globalThis;
20
+ }
21
+ if (typeof window !== "undefined") {
22
+ return window;
23
+ }
24
+ if (typeof global !== "undefined") {
25
+ return global;
26
+ }
27
+ if (typeof self !== "undefined") {
28
+ return self;
29
+ }
30
+ return mockGlobal;
31
+ }
32
+
16
33
  function deferred() {
17
34
  let methods;
18
35
  const promise = new Promise((resolve, reject) => {
@@ -21,14 +38,14 @@ function deferred() {
21
38
  return Object.assign(promise, methods);
22
39
  }
23
40
 
24
- var __defProp$c = Object.defineProperty;
25
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
26
- var __publicField$c = (obj, key, value) => {
27
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
41
+ var __defProp$d = Object.defineProperty;
42
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
43
+ var __publicField$d = (obj, key, value) => {
44
+ __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
28
45
  return value;
29
46
  };
30
47
  const FLOW_GLOBAL = "FDBG";
31
- const CONSOLE_HIGHLIGHT_STYLE = `
48
+ const CONSOLE_HIGHLIGHT_STYLE$1 = `
32
49
  padding: 2px 4px;
33
50
  border-radius: 2px;
34
51
  background: #389DFF;
@@ -45,8 +62,8 @@ class Debugger {
45
62
  */
46
63
  constructor(context) {
47
64
  this.context = context;
48
- __publicField$c(this, "spyDisposer");
49
- __publicField$c(this, "watchDisposers", {});
65
+ __publicField$d(this, "spyDisposer");
66
+ __publicField$d(this, "watchDisposers", {});
50
67
  }
51
68
  /**
52
69
  * Install a 'watch' for the specified context state property path.
@@ -127,17 +144,17 @@ class Debugger {
127
144
  }
128
145
  }
129
146
  spyListener(event) {
130
- console.log(`%cspy`, CONSOLE_HIGHLIGHT_STYLE, event);
147
+ console.log(`%cspy`, CONSOLE_HIGHLIGHT_STYLE$1, event);
131
148
  }
132
149
  logStateValue(path) {
133
150
  const value = toJSHelper(this.context.state.get(path), { recurseEverything: false });
134
- console.log(`%cwatch%c %s`, CONSOLE_HIGHLIGHT_STYLE, CONSOLE_BOLD_STYLE, path, value);
151
+ console.log(`%cwatch%c %s`, CONSOLE_HIGHLIGHT_STYLE$1, CONSOLE_BOLD_STYLE, path, value);
135
152
  }
136
153
  }
137
154
  function installGlobalDebugger(dbg) {
138
155
  console.log(
139
156
  `%cFlow.w RDF Debbugger`,
140
- CONSOLE_HIGHLIGHT_STYLE,
157
+ CONSOLE_HIGHLIGHT_STYLE$1,
141
158
  `Enabled for context '${dbg.context.id}' - access using ${FLOW_GLOBAL} in web developer console.`
142
159
  );
143
160
  const g = typeof global !== "undefined" ? global : window;
@@ -233,16 +250,16 @@ function toJSHelper(source, options, __alreadySeen = null) {
233
250
  return res;
234
251
  }
235
252
 
236
- var __defProp$b = Object.defineProperty;
237
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
238
- var __publicField$b = (obj, key, value) => {
239
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
253
+ var __defProp$c = Object.defineProperty;
254
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
255
+ var __publicField$c = (obj, key, value) => {
256
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
240
257
  return value;
241
258
  };
242
259
  const debug$4 = Debug("flow:map-registry");
243
260
  class MapRegistry {
244
261
  constructor() {
245
- __publicField$b(this, "_maps", /* @__PURE__ */ new Map());
262
+ __publicField$c(this, "_maps", /* @__PURE__ */ new Map());
246
263
  }
247
264
  /**
248
265
  * Register a Flo.w map.
@@ -284,16 +301,16 @@ class MapRegistry {
284
301
  }
285
302
  }
286
303
 
287
- var __defProp$a = Object.defineProperty;
288
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
289
- var __publicField$a = (obj, key, value) => {
290
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
304
+ var __defProp$b = Object.defineProperty;
305
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
306
+ var __publicField$b = (obj, key, value) => {
307
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
291
308
  return value;
292
309
  };
293
310
  const debug$3 = Debug("flow:query-registry");
294
311
  class QueryRegistry {
295
312
  constructor() {
296
- __publicField$a(this, "_queries", /* @__PURE__ */ new Map());
313
+ __publicField$b(this, "_queries", /* @__PURE__ */ new Map());
297
314
  }
298
315
  /**
299
316
  * Register a Flo.w reactive query.
@@ -333,10 +350,10 @@ class QueryRegistry {
333
350
  }
334
351
  }
335
352
 
336
- var __defProp$9 = Object.defineProperty;
337
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
338
- var __publicField$9 = (obj, key, value) => {
339
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
353
+ var __defProp$a = Object.defineProperty;
354
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
355
+ var __publicField$a = (obj, key, value) => {
356
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
340
357
  return value;
341
358
  };
342
359
  const DEFAULT_FLOW_HOST = "https://flow.emu-analytics.net";
@@ -353,13 +370,13 @@ const _FlowContext = class _FlowContext {
353
370
  * @param enableDebug Set to `true` to enable the debugger.
354
371
  */
355
372
  constructor(options) {
356
- __publicField$9(this, "_options");
357
- __publicField$9(this, "flowClient");
358
- __publicField$9(this, "state");
359
- __publicField$9(this, "maps", new MapRegistry());
360
- __publicField$9(this, "queries", new QueryRegistry());
373
+ __publicField$a(this, "_options");
374
+ __publicField$a(this, "flowClient");
375
+ __publicField$a(this, "state");
376
+ __publicField$a(this, "maps", new MapRegistry());
377
+ __publicField$a(this, "queries", new QueryRegistry());
361
378
  /** The Flo.w debugger. Available as `window.FDBG` in the browser's web developer console. */
362
- __publicField$9(this, "debugger");
379
+ __publicField$a(this, "debugger");
363
380
  this._options = {
364
381
  ..._FlowContext._defaultOptions,
365
382
  ...options
@@ -383,23 +400,23 @@ const _FlowContext = class _FlowContext {
383
400
  return expression.value;
384
401
  }
385
402
  };
386
- __publicField$9(_FlowContext, "_defaultOptions", {
403
+ __publicField$a(_FlowContext, "_defaultOptions", {
387
404
  id: DEFAULT_CONTEXT_ID,
388
405
  host: DEFAULT_FLOW_HOST,
389
406
  enableDebug: false
390
407
  });
391
408
  let FlowContext = _FlowContext;
392
409
 
393
- var __defProp$8 = Object.defineProperty;
394
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
395
- var __publicField$8 = (obj, key, value) => {
396
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
410
+ var __defProp$9 = Object.defineProperty;
411
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
412
+ var __publicField$9 = (obj, key, value) => {
413
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
397
414
  return value;
398
415
  };
399
416
  const debug$2 = Debug("flow:context-registry");
400
417
  const _ContextRegistry = class _ContextRegistry {
401
418
  constructor() {
402
- __publicField$8(this, "_contexts", /* @__PURE__ */ new Map());
419
+ __publicField$9(this, "_contexts", /* @__PURE__ */ new Map());
403
420
  }
404
421
  /**
405
422
  * Initialize a new Flo.w context.
@@ -442,12 +459,85 @@ const _ContextRegistry = class _ContextRegistry {
442
459
  return deferredContext?.deferred;
443
460
  }
444
461
  };
445
- __publicField$8(_ContextRegistry, "_defaultOptions", {
462
+ __publicField$9(_ContextRegistry, "_defaultOptions", {
446
463
  id: DEFAULT_CONTEXT_ID,
447
464
  host: "https://flow.emu-analytics.net"
448
465
  });
449
466
  let ContextRegistry = _ContextRegistry;
450
- const globalContextRegistry = new ContextRegistry();
467
+
468
+ var __defProp$8 = Object.defineProperty;
469
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
470
+ var __publicField$8 = (obj, key, value) => {
471
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
472
+ return value;
473
+ };
474
+ class FlowRdfCoreGlobals {
475
+ constructor() {
476
+ /**
477
+ * FlowRdfCoreGlobals version.
478
+ * Compatiblity with other versions loaded in memory as long as this version matches.
479
+ * It indicates that the global state still stores similar information
480
+ *
481
+ * N.B: this version is unrelated to the package version.
482
+ */
483
+ __publicField$8(this, "version", 1);
484
+ __publicField$8(this, "globalContextRegistry", new ContextRegistry());
485
+ }
486
+ }
487
+ let canMergeGlobalState = true;
488
+ let isolateCalled = false;
489
+ let globalState = function() {
490
+ const global = getGlobal();
491
+ if (global.__flowRdfCoreInstanceCount > 0 && !global.__flowRdfCoreGlobals) {
492
+ canMergeGlobalState = false;
493
+ }
494
+ if (global.__flowRdfCoreGlobals && global.__flowRdfCoreGlobals.version !== new FlowRdfCoreGlobals().version) {
495
+ canMergeGlobalState = false;
496
+ }
497
+ if (!canMergeGlobalState) {
498
+ setTimeout(() => {
499
+ if (!isolateCalled) {
500
+ throw new Error(
501
+ 'There are multiple, different versions of FlowRdfCore active. Make sure FlowRdfCore is loaded only once or use `configure({ isolateGlobalState: true })`",'
502
+ );
503
+ }
504
+ }, 1);
505
+ return new FlowRdfCoreGlobals();
506
+ } else if (global.__flowRdfCoreGlobals) {
507
+ global.__flowRdfCoreInstanceCount += 1;
508
+ if (!global.__mobxGlobals.UNCHANGED) {
509
+ global.__mobxGlobals.UNCHANGED = {};
510
+ }
511
+ return global.__flowRdfCoreGlobals;
512
+ } else {
513
+ global.__mobxInstanceCount = 1;
514
+ return global.__flowRdfCoreGlobals = new FlowRdfCoreGlobals();
515
+ }
516
+ }();
517
+ function isolateGlobalState() {
518
+ isolateCalled = true;
519
+ if (canMergeGlobalState) {
520
+ const global = getGlobal();
521
+ if (--global.__flowRdfCoreInstanceCount === 0) {
522
+ global.__flowRdfCoreGlobals = void 0;
523
+ }
524
+ globalState = new FlowRdfCoreGlobals();
525
+ }
526
+ }
527
+ function getGlobalState() {
528
+ return globalState;
529
+ }
530
+
531
+ const version = "0.0.21";
532
+
533
+ const CONSOLE_HIGHLIGHT_STYLE = `
534
+ padding: 2px 4px;
535
+ border-radius: 2px;
536
+ background: #389DFF;
537
+ color: white;`;
538
+ function announce() {
539
+ console.log("%cFlo.w RDF Core v%s", CONSOLE_HIGHLIGHT_STYLE, version);
540
+ }
451
541
 
452
542
  var __defProp$7 = Object.defineProperty;
453
543
  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 +2562,7 @@ const _FlowMap = class _FlowMap extends EventEmitter {
2472
2562
  }
2473
2563
  }
2474
2564
  async initialize() {
2565
+ const globalContextRegistry = getGlobalState().globalContextRegistry;
2475
2566
  this._context = await globalContextRegistry.getContext(this._options.contextId);
2476
2567
  this._style.bindState(this._context.state);
2477
2568
  const baseStyle = await this.loadBaseStyle(this._options.baseStyle);
@@ -2583,7 +2674,7 @@ const _Query = class _Query {
2583
2674
  if (transformFn) {
2584
2675
  this._transformFn = transformFn;
2585
2676
  }
2586
- globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2677
+ getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2587
2678
  context.queries.registerQuery(this);
2588
2679
  });
2589
2680
  }
@@ -2597,12 +2688,12 @@ const _Query = class _Query {
2597
2688
  return this._options.id;
2598
2689
  }
2599
2690
  destroy() {
2600
- globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2691
+ getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2601
2692
  context.queries.unregisterQuery(this);
2602
2693
  });
2603
2694
  }
2604
2695
  async runImmediately() {
2605
- const context = await globalContextRegistry.getContext(this._options.contextId);
2696
+ const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
2606
2697
  const queryDefinition = this.queryFn.call(context.state, context.state);
2607
2698
  await this.runQuery(queryDefinition);
2608
2699
  if (this.error) {
@@ -2612,7 +2703,7 @@ const _Query = class _Query {
2612
2703
  }
2613
2704
  async wake() {
2614
2705
  this.sleep();
2615
- const context = await globalContextRegistry.getContext(this._options.contextId);
2706
+ const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
2616
2707
  this._disposer = reaction(
2617
2708
  (r) => {
2618
2709
  return this.queryFn.call(context.state, context.state);
@@ -2638,7 +2729,7 @@ const _Query = class _Query {
2638
2729
  }
2639
2730
  async runQuery(queryDefinition) {
2640
2731
  debug(`${this.formattedName}: running query`, queryDefinition);
2641
- const context = await globalContextRegistry.getContext(this._options.contextId);
2732
+ const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
2642
2733
  try {
2643
2734
  if (queryDefinition === null) {
2644
2735
  runInAction(() => {
@@ -3055,9 +3146,11 @@ function traceReaction() {
3055
3146
  trace();
3056
3147
  }
3057
3148
 
3058
- configure({ isolateGlobalState: true });
3149
+ configure({ isolateGlobalState: false, useProxies: "always" });
3150
+ const globalContextRegistry = getGlobalState().globalContextRegistry;
3059
3151
  const initializeContext = globalContextRegistry.initializeContext.bind(globalContextRegistry);
3060
3152
  const uninitializeContext = globalContextRegistry.uninitializeContext.bind(globalContextRegistry);
3061
3153
  const getContext = globalContextRegistry.getContext.bind(globalContextRegistry);
3154
+ announce();
3062
3155
 
3063
- export { ContextRegistry, DEFAULT_CONTEXT_ID, FlowContext, FlowMap, MapDataSource, MapLayer, MapLayerStyleBuilder, MapStyle, Query, ReactiveExpression, StateStore, StyleExpression, computed, expr, getContext, globalContextRegistry, initializeContext, layerStyle, observable, query, queryMany, queryOne, serialize, traceReaction, uninitializeContext };
3156
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emuanalytics/flow-rdf-core",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "type": "module",