@routier/core 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +78 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +82 -36
- package/dist/index.js.map +1 -1
- package/dist/results/index.cjs +40 -0
- package/dist/results/index.cjs.map +1 -1
- package/dist/results/index.d.ts +1 -0
- package/dist/results/index.js +44 -1
- package/dist/results/index.js.map +1 -1
- package/dist/results/liveQuery.d.ts +26 -0
- package/dist/schema/index.cjs +33 -33
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.js +33 -33
- package/dist/schema/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -9661,12 +9661,15 @@ class PluginEventResult extends BaseResult {
|
|
|
9661
9661
|
|
|
9662
9662
|
|
|
9663
9663
|
},
|
|
9664
|
-
|
|
9664
|
+
881(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
9665
9665
|
|
|
9666
9666
|
// EXPORTS
|
|
9667
9667
|
__webpack_require__.d(__webpack_exports__, {
|
|
9668
9668
|
PluginEventResult: () => (/* reexport */ Result/* .PluginEventResult */.D),
|
|
9669
9669
|
toPromise: () => (/* reexport */ toPromise),
|
|
9670
|
+
pendingLiveQueryState: () => (/* reexport */ pendingLiveQueryState),
|
|
9671
|
+
subscribeLiveQuery: () => (/* reexport */ subscribeLiveQuery),
|
|
9672
|
+
toLiveQueryState: () => (/* reexport */ toLiveQueryState),
|
|
9670
9673
|
Result: () => (/* reexport */ Result/* .Result */.Q)
|
|
9671
9674
|
});
|
|
9672
9675
|
|
|
@@ -9686,12 +9689,49 @@ function toPromise(fn) {
|
|
|
9686
9689
|
});
|
|
9687
9690
|
}
|
|
9688
9691
|
|
|
9692
|
+
;// CONCATENATED MODULE: ./src/results/liveQuery.ts
|
|
9693
|
+
|
|
9694
|
+
const pendingLiveQueryState = ()=>({
|
|
9695
|
+
status: "pending",
|
|
9696
|
+
loading: true,
|
|
9697
|
+
isSuccess: false,
|
|
9698
|
+
isError: false
|
|
9699
|
+
});
|
|
9700
|
+
const toLiveQueryState = (result)=>result.ok === Result/* .Result.SUCCESS */.Q.SUCCESS ? {
|
|
9701
|
+
status: "success",
|
|
9702
|
+
loading: false,
|
|
9703
|
+
data: result.data,
|
|
9704
|
+
isSuccess: true,
|
|
9705
|
+
isError: false
|
|
9706
|
+
} : {
|
|
9707
|
+
status: "error",
|
|
9708
|
+
loading: false,
|
|
9709
|
+
error: new Error(result.error?.message || "Unknown error"),
|
|
9710
|
+
isSuccess: false,
|
|
9711
|
+
isError: true
|
|
9712
|
+
};
|
|
9713
|
+
const subscribeLiveQuery = (query, onState)=>{
|
|
9714
|
+
let active = true;
|
|
9715
|
+
const unsubscribe = query((result)=>{
|
|
9716
|
+
if (active) {
|
|
9717
|
+
onState(toLiveQueryState(result));
|
|
9718
|
+
}
|
|
9719
|
+
});
|
|
9720
|
+
return ()=>{
|
|
9721
|
+
active = false;
|
|
9722
|
+
if (typeof unsubscribe === "function") {
|
|
9723
|
+
unsubscribe();
|
|
9724
|
+
}
|
|
9725
|
+
};
|
|
9726
|
+
};
|
|
9727
|
+
|
|
9689
9728
|
;// CONCATENATED MODULE: ./src/results/index.ts
|
|
9690
9729
|
|
|
9691
9730
|
|
|
9692
9731
|
|
|
9693
9732
|
|
|
9694
9733
|
|
|
9734
|
+
|
|
9695
9735
|
},
|
|
9696
9736
|
862(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
9697
9737
|
|
|
@@ -13264,7 +13304,6 @@ const getChannelRegistry = (schemaId, scope)=>{
|
|
|
13264
13304
|
registry[key] = channel;
|
|
13265
13305
|
return channel;
|
|
13266
13306
|
};
|
|
13267
|
-
// Must have a sender and receiver. Sender cannot listen for it's own message
|
|
13268
13307
|
class SchemaChannel {
|
|
13269
13308
|
sender;
|
|
13270
13309
|
receiver;
|
|
@@ -13273,8 +13312,8 @@ class SchemaChannel {
|
|
|
13273
13312
|
// hence a count rather than a boolean.
|
|
13274
13313
|
subscribers = 0;
|
|
13275
13314
|
constructor(channelKey){
|
|
13276
|
-
this.sender = new SchemaChannelSender(channelKey);
|
|
13277
13315
|
this.receiver = new SchemaChannelReceiver(channelKey);
|
|
13316
|
+
this.sender = new SchemaChannelSender(channelKey, this.receiver);
|
|
13278
13317
|
}
|
|
13279
13318
|
/**
|
|
13280
13319
|
* How many callbacks in THIS process are waiting on the channel.
|
|
@@ -13298,51 +13337,50 @@ class SchemaChannel {
|
|
|
13298
13337
|
this.receiver.close();
|
|
13299
13338
|
}
|
|
13300
13339
|
}
|
|
13301
|
-
|
|
13302
|
-
|
|
13303
|
-
|
|
13304
|
-
|
|
13305
|
-
|
|
13306
|
-
* does not call `destroyAsync()` runs to the end of its code and then hangs forever with two
|
|
13307
|
-
* live MessagePorts per collection — including the example in the README.
|
|
13308
|
-
*
|
|
13309
|
-
* `unref` is Node-only; the browser's BroadcastChannel has no such method and needs none.
|
|
13310
|
-
* A channel that is unreferenced still sends and receives normally. It only stops being a
|
|
13311
|
-
* reason for the process to stay alive, which is the correct default for a library: a program
|
|
13312
|
-
* with no work left should exit.
|
|
13313
|
-
*/ const unreference = (channel)=>{
|
|
13340
|
+
const openBroadcastChannel = (channelKey)=>{
|
|
13341
|
+
if (typeof BroadcastChannel !== "function") {
|
|
13342
|
+
return null;
|
|
13343
|
+
}
|
|
13344
|
+
const channel = new BroadcastChannel(`__routier-schema-subscription-channel:${channelKey}`);
|
|
13314
13345
|
const maybeUnref = channel.unref;
|
|
13315
|
-
if (typeof maybeUnref ===
|
|
13346
|
+
if (typeof maybeUnref === "function") {
|
|
13316
13347
|
maybeUnref.call(channel);
|
|
13317
13348
|
}
|
|
13349
|
+
return channel;
|
|
13318
13350
|
};
|
|
13319
13351
|
class SchemaChannelSender {
|
|
13320
13352
|
broadcastChannel;
|
|
13321
|
-
|
|
13322
|
-
|
|
13323
|
-
|
|
13353
|
+
localReceiver;
|
|
13354
|
+
constructor(channelKey, localReceiver){
|
|
13355
|
+
this.broadcastChannel = openBroadcastChannel(channelKey);
|
|
13356
|
+
this.localReceiver = localReceiver;
|
|
13324
13357
|
}
|
|
13325
13358
|
send(changes) {
|
|
13326
|
-
this.broadcastChannel
|
|
13359
|
+
if (this.broadcastChannel != null) {
|
|
13360
|
+
this.broadcastChannel.postMessage(changes);
|
|
13361
|
+
return;
|
|
13362
|
+
}
|
|
13363
|
+
const copy = structuredClone(changes);
|
|
13364
|
+
setTimeout(()=>this.localReceiver.dispatch(copy), 0);
|
|
13327
13365
|
}
|
|
13328
13366
|
close() {
|
|
13329
|
-
this.broadcastChannel
|
|
13367
|
+
this.broadcastChannel?.close();
|
|
13330
13368
|
}
|
|
13331
13369
|
}
|
|
13332
13370
|
class SchemaChannelReceiver {
|
|
13333
13371
|
broadcastChannel;
|
|
13334
13372
|
subscriptions = [];
|
|
13335
13373
|
constructor(channelKey){
|
|
13336
|
-
this.broadcastChannel =
|
|
13337
|
-
|
|
13338
|
-
|
|
13339
|
-
|
|
13340
|
-
|
|
13341
|
-
|
|
13342
|
-
|
|
13343
|
-
|
|
13344
|
-
|
|
13345
|
-
}
|
|
13374
|
+
this.broadcastChannel = openBroadcastChannel(channelKey);
|
|
13375
|
+
if (this.broadcastChannel != null) {
|
|
13376
|
+
this.broadcastChannel.onmessage = (e)=>this.dispatch(e.data);
|
|
13377
|
+
}
|
|
13378
|
+
}
|
|
13379
|
+
dispatch(changes) {
|
|
13380
|
+
const subscriptions = this.subscriptions;
|
|
13381
|
+
for(let i = 0, length = subscriptions.length; i < length; i++){
|
|
13382
|
+
subscriptions[i].action(changes);
|
|
13383
|
+
}
|
|
13346
13384
|
}
|
|
13347
13385
|
get listenerCount() {
|
|
13348
13386
|
return this.subscriptions.length;
|
|
@@ -13355,8 +13393,10 @@ class SchemaChannelReceiver {
|
|
|
13355
13393
|
}
|
|
13356
13394
|
close() {
|
|
13357
13395
|
this.subscriptions = [];
|
|
13358
|
-
this.broadcastChannel
|
|
13359
|
-
|
|
13396
|
+
if (this.broadcastChannel != null) {
|
|
13397
|
+
this.broadcastChannel.onmessage = null;
|
|
13398
|
+
this.broadcastChannel.close();
|
|
13399
|
+
}
|
|
13360
13400
|
}
|
|
13361
13401
|
}
|
|
13362
13402
|
class SubscriptionListener {
|
|
@@ -16425,6 +16465,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
16425
16465
|
parseFragment: () => (/* reexport safe */ _expressions__rspack_import_4.parseFragment),
|
|
16426
16466
|
parseSelector: () => (/* reexport safe */ _expressions__rspack_import_4.parseSelector),
|
|
16427
16467
|
peelCalls: () => (/* reexport safe */ _expressions__rspack_import_4.peelCalls),
|
|
16468
|
+
pendingLiveQueryState: () => (/* reexport safe */ _results__rspack_import_8.pendingLiveQueryState),
|
|
16428
16469
|
propertyInfoToJsonSchema: () => (/* reexport safe */ _schema__rspack_import_9.propertyInfoToJsonSchema),
|
|
16429
16470
|
readJoinKey: () => (/* reexport safe */ _plugins__rspack_import_7.readJoinKey),
|
|
16430
16471
|
rehydrateSchemaFromJsonSchema: () => (/* reexport safe */ _schema__rspack_import_9.rehydrateSchemaFromJsonSchema),
|
|
@@ -16441,9 +16482,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
16441
16482
|
setLogLevel: () => (/* reexport safe */ _utilities__rspack_import_10.setLogLevel),
|
|
16442
16483
|
splitSendableOptions: () => (/* reexport safe */ _plugins__rspack_import_7.splitSendableOptions),
|
|
16443
16484
|
stringifyObject: () => (/* reexport safe */ _utilities__rspack_import_10.stringifyObject),
|
|
16485
|
+
subscribeLiveQuery: () => (/* reexport safe */ _results__rspack_import_8.subscribeLiveQuery),
|
|
16444
16486
|
toEntityShape: () => (/* reexport safe */ _plugins__rspack_import_7.toEntityShape),
|
|
16445
16487
|
toEventArray: () => (/* reexport safe */ _utilities__rspack_import_10.toEventArray),
|
|
16446
16488
|
toExpression: () => (/* reexport safe */ _expressions__rspack_import_4.toExpression),
|
|
16489
|
+
toLiveQueryState: () => (/* reexport safe */ _results__rspack_import_8.toLiveQueryState),
|
|
16447
16490
|
toMap: () => (/* reexport safe */ _utilities__rspack_import_10.toMap),
|
|
16448
16491
|
toPredicate: () => (/* reexport safe */ _expressions__rspack_import_4.toPredicate),
|
|
16449
16492
|
toPromise: () => (/* reexport safe */ _results__rspack_import_8.toPromise),
|
|
@@ -16462,7 +16505,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
16462
16505
|
/* import */ var _performance__rspack_import_5 = __webpack_require__(971);
|
|
16463
16506
|
/* import */ var _pipeline__rspack_import_6 = __webpack_require__(314);
|
|
16464
16507
|
/* import */ var _plugins__rspack_import_7 = __webpack_require__(756);
|
|
16465
|
-
/* import */ var _results__rspack_import_8 = __webpack_require__(
|
|
16508
|
+
/* import */ var _results__rspack_import_8 = __webpack_require__(881);
|
|
16466
16509
|
/* import */ var _schema__rspack_import_9 = __webpack_require__(862);
|
|
16467
16510
|
/* import */ var _utilities__rspack_import_10 = __webpack_require__(222);
|
|
16468
16511
|
|