@party-stack/runtime 0.6.3 → 0.7.0
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/lib/NetworkConnectivity.d.ts +21 -1
- package/lib/NetworkConnectivity.d.ts.map +1 -1
- package/lib/NetworkConnectivity.js +54 -1
- package/lib/NetworkConnectivity.js.map +1 -1
- package/lib/Runtime.d.ts +3 -2
- package/lib/Runtime.d.ts.map +1 -1
- package/lib/Runtime.js +2 -2
- package/lib/Runtime.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -2
- package/lib/testing.d.ts +5 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +6 -3
- package/lib/testing.js.map +1 -1
- package/lib/types.d.ts +28 -1
- package/lib/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NetworkConnectivity } from "./types.js";
|
|
1
|
+
import { NetworkConnectivity, NetworkLink, NetworkLinks } from "./types.js";
|
|
2
2
|
import { Effect, Stream } from "effect";
|
|
3
3
|
//#region src/NetworkConnectivity.d.ts
|
|
4
4
|
/** Platforms without a monitor still handle individual request failures normally. */
|
|
@@ -9,5 +9,25 @@ export declare const makeNetworkConnectivity: (initial: boolean) => Effect.Effec
|
|
|
9
9
|
changes: Stream.Stream<boolean, never, never>;
|
|
10
10
|
set: (value: boolean) => Effect.Effect<void, never, never>;
|
|
11
11
|
}, never, import("effect/Scope").Scope>;
|
|
12
|
+
/** The network web and Expo runtimes report their connection as reaching, and the one a source
|
|
13
|
+
* is on by default. */
|
|
14
|
+
export declare const INTERNET = "internet";
|
|
15
|
+
/** A platform that monitors no links. */
|
|
16
|
+
export declare const noNetworkLinks: NetworkLinks;
|
|
17
|
+
/** Latest-value links, owned by the platform scope. */
|
|
18
|
+
export declare const makeNetworkLinks: (initial: readonly NetworkLink[]) => Effect.Effect<{
|
|
19
|
+
current: Effect.Effect<readonly NetworkLink[], never, never>;
|
|
20
|
+
changes: Stream.Stream<readonly NetworkLink[], never, never>;
|
|
21
|
+
set: (links: readonly NetworkLink[]) => Effect.Effect<void, never, never>;
|
|
22
|
+
}, never, import("effect/Scope").Scope>;
|
|
23
|
+
/** One link whose availability a platform monitor reports. */
|
|
24
|
+
export declare const singleNetworkLink: (connectivity: NetworkConnectivity, describe: () => Omit<NetworkLink, "available">) => NetworkLinks;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a source on `networks` can be reached now: while a link reaching one of them is
|
|
27
|
+
* available. A source on the same device is on no network and is always reachable. A network no
|
|
28
|
+
* link reaches is treated as available (nothing monitors it), so only links known to be down hold
|
|
29
|
+
* a source back. Without `networks`, the source is on the internet.
|
|
30
|
+
*/
|
|
31
|
+
export declare function networkConnectivity(links: NetworkLinks, networks?: readonly string[]): NetworkConnectivity;
|
|
12
32
|
//#endregion
|
|
13
33
|
//# sourceMappingURL=NetworkConnectivity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkConnectivity.d.ts","names":[],"sources":["../src/NetworkConnectivity.ts"],"mappings":";;;;qBAIa,0BAA0B;;qBAM1B,0BAAuB,qBAAA,OAAA;;;EAUf,MAAA,mBAAO,OAAA;iCAO1B"}
|
|
1
|
+
{"version":3,"file":"NetworkConnectivity.d.ts","names":[],"sources":["../src/NetworkConnectivity.ts"],"mappings":";;;;qBAIa,0BAA0B;;qBAM1B,0BAAuB,qBAAA,OAAA;;;EAUf,MAAA,mBAAO,OAAA;iCAO1B;;;qBAIW;;qBAGA,gBAAgB;;qBAGhB,mBAAgB,kBAAA,kBAAA,OAAA;;;EAUR,MAAA,gBAAS,kBAAa,OAAA;iCAMzC;;qBAGW,oBAAiB,cACZ,qBAAmB,gBACjB,KAAK,8BACtB;;;;;;;wBAWa,oBACZ,OAAO,cACP,+BACD"}
|
|
@@ -23,7 +23,60 @@ const makeNetworkConnectivity = Effect.fnUntraced(function* (initial) {
|
|
|
23
23
|
})
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
|
+
/** The network web and Expo runtimes report their connection as reaching, and the one a source
|
|
27
|
+
* is on by default. */
|
|
28
|
+
const INTERNET = "internet";
|
|
29
|
+
/** A platform that monitors no links. */
|
|
30
|
+
const noNetworkLinks = {
|
|
31
|
+
current: Effect.succeed([]),
|
|
32
|
+
changes: Stream.make([])
|
|
33
|
+
};
|
|
34
|
+
/** Latest-value links, owned by the platform scope. */
|
|
35
|
+
const makeNetworkLinks = Effect.fnUntraced(function* (initial) {
|
|
36
|
+
const events = yield* Effect.acquireRelease(PubSub.sliding({
|
|
37
|
+
capacity: 1,
|
|
38
|
+
replay: 1
|
|
39
|
+
}), PubSub.shutdown);
|
|
40
|
+
let current = initial;
|
|
41
|
+
yield* PubSub.publish(events, initial);
|
|
42
|
+
return {
|
|
43
|
+
current: Effect.sync(() => current),
|
|
44
|
+
changes: Stream.fromPubSub(events),
|
|
45
|
+
set: (links) => Effect.sync(() => {
|
|
46
|
+
current = links;
|
|
47
|
+
PubSub.publishUnsafe(events, links);
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
/** One link whose availability a platform monitor reports. */
|
|
52
|
+
const singleNetworkLink = (connectivity, describe) => ({
|
|
53
|
+
current: Effect.map(connectivity.online, (available) => [{
|
|
54
|
+
...describe(),
|
|
55
|
+
available
|
|
56
|
+
}]),
|
|
57
|
+
changes: Stream.map(connectivity.changes, (available) => [{
|
|
58
|
+
...describe(),
|
|
59
|
+
available
|
|
60
|
+
}])
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Whether a source on `networks` can be reached now: while a link reaching one of them is
|
|
64
|
+
* available. A source on the same device is on no network and is always reachable. A network no
|
|
65
|
+
* link reaches is treated as available (nothing monitors it), so only links known to be down hold
|
|
66
|
+
* a source back. Without `networks`, the source is on the internet.
|
|
67
|
+
*/
|
|
68
|
+
function networkConnectivity(links, networks = [INTERNET]) {
|
|
69
|
+
if (networks.length === 0) return alwaysOnlineConnectivity;
|
|
70
|
+
const reachable = (current) => networks.some((network) => {
|
|
71
|
+
const reaching = current.filter((link) => link.networks.includes(network));
|
|
72
|
+
return reaching.length === 0 || reaching.some((link) => link.available);
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
online: Effect.map(links.current, reachable),
|
|
76
|
+
changes: links.changes.pipe(Stream.map(reachable), Stream.changes)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
26
79
|
//#endregion
|
|
27
|
-
export { alwaysOnlineConnectivity, makeNetworkConnectivity };
|
|
80
|
+
export { INTERNET, alwaysOnlineConnectivity, makeNetworkConnectivity, makeNetworkLinks, networkConnectivity, noNetworkLinks, singleNetworkLink };
|
|
28
81
|
|
|
29
82
|
//# sourceMappingURL=NetworkConnectivity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkConnectivity.js","names":[],"sources":["../src/NetworkConnectivity.ts"],"sourcesContent":["import { Effect, PubSub, Stream } from \"effect\";\nimport type { NetworkConnectivity } from \"./types.js\";\n\n/** Platforms without a monitor still handle individual request failures normally. */\nexport const alwaysOnlineConnectivity: NetworkConnectivity = {\n online: Effect.succeed(true),\n changes: Stream.make(true),\n};\n\n/** Latest-value state with bounded delivery, owned by the platform scope. */\nexport const makeNetworkConnectivity = Effect.fnUntraced(function* (initial: boolean) {\n const events = yield* Effect.acquireRelease(\n PubSub.sliding<boolean>({ capacity: 1, replay: 1 }),\n PubSub.shutdown\n );\n let current = initial;\n yield* PubSub.publish(events, initial);\n return {\n online: Effect.sync(() => current),\n changes: Stream.fromPubSub(events),\n set: (value: boolean) =>\n Effect.sync(() => {\n if (value === current) return;\n current = value;\n PubSub.publishUnsafe(events, value);\n }),\n };\n});\n"],"mappings":";;;AAIA,MAAa,2BAAgD;CACzD,QAAQ,OAAO,QAAQ,IAAI;CAC3B,SAAS,OAAO,KAAK,IAAI;AAC7B;;AAGA,MAAa,0BAA0B,OAAO,WAAW,WAAW,SAAkB;CAClF,MAAM,SAAS,OAAO,OAAO,eACzB,OAAO,QAAiB;EAAE,UAAU;EAAG,QAAQ;CAAE,CAAC,GAClD,OAAO,QACX;CACA,IAAI,UAAU;CACd,OAAO,OAAO,QAAQ,QAAQ,OAAO;CACrC,OAAO;EACH,QAAQ,OAAO,WAAW,OAAO;EACjC,SAAS,OAAO,WAAW,MAAM;EACjC,MAAM,UACF,OAAO,WAAW;GACd,IAAI,UAAU,SAAS;GACvB,UAAU;GACV,OAAO,cAAc,QAAQ,KAAK;EACtC,CAAC;CACT;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"NetworkConnectivity.js","names":[],"sources":["../src/NetworkConnectivity.ts"],"sourcesContent":["import { Effect, PubSub, Stream } from \"effect\";\nimport type { NetworkConnectivity, NetworkLink, NetworkLinks } from \"./types.js\";\n\n/** Platforms without a monitor still handle individual request failures normally. */\nexport const alwaysOnlineConnectivity: NetworkConnectivity = {\n online: Effect.succeed(true),\n changes: Stream.make(true),\n};\n\n/** Latest-value state with bounded delivery, owned by the platform scope. */\nexport const makeNetworkConnectivity = Effect.fnUntraced(function* (initial: boolean) {\n const events = yield* Effect.acquireRelease(\n PubSub.sliding<boolean>({ capacity: 1, replay: 1 }),\n PubSub.shutdown\n );\n let current = initial;\n yield* PubSub.publish(events, initial);\n return {\n online: Effect.sync(() => current),\n changes: Stream.fromPubSub(events),\n set: (value: boolean) =>\n Effect.sync(() => {\n if (value === current) return;\n current = value;\n PubSub.publishUnsafe(events, value);\n }),\n };\n});\n\n/** The network web and Expo runtimes report their connection as reaching, and the one a source\n * is on by default. */\nexport const INTERNET = \"internet\";\n\n/** A platform that monitors no links. */\nexport const noNetworkLinks: NetworkLinks = { current: Effect.succeed([]), changes: Stream.make([]) };\n\n/** Latest-value links, owned by the platform scope. */\nexport const makeNetworkLinks = Effect.fnUntraced(function* (initial: readonly NetworkLink[]) {\n const events = yield* Effect.acquireRelease(\n PubSub.sliding<readonly NetworkLink[]>({ capacity: 1, replay: 1 }),\n PubSub.shutdown\n );\n let current = initial;\n yield* PubSub.publish(events, initial);\n return {\n current: Effect.sync(() => current),\n changes: Stream.fromPubSub(events),\n set: (links: readonly NetworkLink[]) =>\n Effect.sync(() => {\n current = links;\n PubSub.publishUnsafe(events, links);\n }),\n };\n});\n\n/** One link whose availability a platform monitor reports. */\nexport const singleNetworkLink = (\n connectivity: NetworkConnectivity,\n describe: () => Omit<NetworkLink, \"available\">\n): NetworkLinks => ({\n current: Effect.map(connectivity.online, (available) => [{ ...describe(), available }]),\n changes: Stream.map(connectivity.changes, (available) => [{ ...describe(), available }]),\n});\n\n/**\n * Whether a source on `networks` can be reached now: while a link reaching one of them is\n * available. A source on the same device is on no network and is always reachable. A network no\n * link reaches is treated as available (nothing monitors it), so only links known to be down hold\n * a source back. Without `networks`, the source is on the internet.\n */\nexport function networkConnectivity(\n links: NetworkLinks,\n networks: readonly string[] = [INTERNET]\n): NetworkConnectivity {\n if (networks.length === 0) return alwaysOnlineConnectivity;\n const reachable = (current: readonly NetworkLink[]) =>\n networks.some((network) => {\n const reaching = current.filter((link) => link.networks.includes(network));\n return reaching.length === 0 || reaching.some((link) => link.available);\n });\n return {\n online: Effect.map(links.current, reachable),\n changes: links.changes.pipe(Stream.map(reachable), Stream.changes),\n };\n}\n"],"mappings":";;;AAIA,MAAa,2BAAgD;CACzD,QAAQ,OAAO,QAAQ,IAAI;CAC3B,SAAS,OAAO,KAAK,IAAI;AAC7B;;AAGA,MAAa,0BAA0B,OAAO,WAAW,WAAW,SAAkB;CAClF,MAAM,SAAS,OAAO,OAAO,eACzB,OAAO,QAAiB;EAAE,UAAU;EAAG,QAAQ;CAAE,CAAC,GAClD,OAAO,QACX;CACA,IAAI,UAAU;CACd,OAAO,OAAO,QAAQ,QAAQ,OAAO;CACrC,OAAO;EACH,QAAQ,OAAO,WAAW,OAAO;EACjC,SAAS,OAAO,WAAW,MAAM;EACjC,MAAM,UACF,OAAO,WAAW;GACd,IAAI,UAAU,SAAS;GACvB,UAAU;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7 @@
|
|
|
1
1
|
import { Geolocation } from "./Geolocation.js";
|
|
2
2
|
import { RuntimePartition } from "./RuntimePartition.js";
|
|
3
3
|
import { ResourceCapacity } from "./capacity.js";
|
|
4
|
-
import { BrowserAuthentication,
|
|
4
|
+
import { BrowserAuthentication, NetworkLinks, RuntimeOptions } from "./types.js";
|
|
5
5
|
import { Context, Effect, Schema } from "effect";
|
|
6
6
|
import { EncryptionKeyringService } from "@party-stack/ontology-storage/encrypted";
|
|
7
7
|
import { BlobBytesService } from "@party-stack/ontology-storage/blobs";
|
|
@@ -24,7 +24,8 @@ export interface RuntimeService {
|
|
|
24
24
|
readonly destroy: Effect.Effect<void, RuntimeError>;
|
|
25
25
|
readonly tables: TablesService;
|
|
26
26
|
readonly encryptionKeyring?: EncryptionKeyringService;
|
|
27
|
-
|
|
27
|
+
/** The device's links (Wi-Fi, cellular, ...) and the networks they reach. */
|
|
28
|
+
readonly links: NetworkLinks;
|
|
28
29
|
readonly bytes: BlobBytesService;
|
|
29
30
|
}
|
|
30
31
|
declare const Runtime_base: Context.ServiceClass<Runtime, "@party-stack/runtime/Runtime", RuntimeService>;
|
package/lib/Runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Runtime.d.ts","names":[],"sources":["../src/Runtime.ts"],"mappings":";;;;;;;;;;;;;qBAUa,qBAAqB;;iBAKjB;WACJ,WAAW;;WAEX;WACA;WACA,wBAAwB;;WAExB,cAAc;WACd,SAAS,OAAO,aAAa;WAC7B,QAAQ;WACR,oBAAoB
|
|
1
|
+
{"version":3,"file":"Runtime.d.ts","names":[],"sources":["../src/Runtime.ts"],"mappings":";;;;;;;;;;;;;qBAUa,qBAAqB;;iBAKjB;WACJ,WAAW;;WAEX;WACA;WACA,wBAAwB;;WAExB,cAAc;WACd,SAAS,OAAO,aAAa;WAC7B,QAAQ;WACR,oBAAoB;;WAEpB,OAAO;WACP,OAAO;;;qBAEP,gBAAgB;;kBAET,OAAI,SAAA,mBAAA,OAAA,OAAA,uBAAA"}
|
package/lib/Runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { noNetworkLinks } from "./NetworkConnectivity.js";
|
|
2
2
|
import { RuntimePartition } from "./RuntimePartition.js";
|
|
3
3
|
import { Context, Effect, Schema } from "effect";
|
|
4
4
|
//#region src/Runtime.ts
|
|
@@ -18,7 +18,7 @@ var Runtime = class Runtime extends Context.Service()("@party-stack/runtime/Runt
|
|
|
18
18
|
destroy: adapter.destroy ?? Effect.void,
|
|
19
19
|
tables: adapter.tables,
|
|
20
20
|
encryptionKeyring: adapter.encryptionKeyring,
|
|
21
|
-
|
|
21
|
+
links: adapter.links ?? noNetworkLinks,
|
|
22
22
|
bytes: adapter.blobBytes
|
|
23
23
|
});
|
|
24
24
|
});
|
package/lib/Runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Runtime.js","names":[],"sources":["../src/Runtime.ts"],"sourcesContent":["import { Context, Effect, Schema } from \"effect\";\nimport {
|
|
1
|
+
{"version":3,"file":"Runtime.js","names":[],"sources":["../src/Runtime.ts"],"sourcesContent":["import { Context, Effect, Schema } from \"effect\";\nimport { noNetworkLinks } from \"./NetworkConnectivity.js\";\nimport { RuntimePartition } from \"./RuntimePartition.js\";\nimport type { ResourceCapacity } from \"./capacity.js\";\nimport type { Geolocation } from \"./Geolocation.js\";\nimport type { RuntimeOptions, BrowserAuthentication, NetworkLinks } from \"./types.js\";\nimport type { BlobBytesService } from \"@party-stack/ontology-storage/blobs\";\nimport type { EncryptionKeyringService } from \"@party-stack/ontology-storage/encrypted\";\nimport type { TablesService } from \"@party-stack/ontology-storage/tables\";\n\nexport class RuntimeError extends Schema.TaggedError<RuntimeError>()(\"RuntimeError\", {\n operation: Schema.String,\n cause: Schema.Defect(),\n}) {}\n/** Acquired platform capabilities and application-boundary bridges, owned by an Effect Scope. */\nexport interface RuntimeService {\n readonly capacity?: ResourceCapacity;\n /** Context-derived partition key; identity selection uses Connect's userId separately. */\n readonly owner: string;\n readonly namespace: string;\n readonly browserAuthentication?: BrowserAuthentication;\n /** Device location; absent where the platform has none (for example Node). */\n readonly geolocation?: Geolocation;\n readonly destroy: Effect.Effect<void, RuntimeError>;\n readonly tables: TablesService;\n readonly encryptionKeyring?: EncryptionKeyringService;\n /** The device's links (Wi-Fi, cellular, ...) and the networks they reach. */\n readonly links: NetworkLinks;\n readonly bytes: BlobBytesService;\n}\nexport class Runtime extends Context.Service<Runtime, RuntimeService>()(\"@party-stack/runtime/Runtime\") {\n /** Construct the runtime in the caller's Scope; platform Layers own their resources. */\n static readonly make = Effect.fnUntraced(function* (adapter: RuntimeOptions) {\n const partition = yield* RuntimePartition;\n\n const service = Runtime.of({\n ...partition,\n capacity: adapter.capacity,\n browserAuthentication: adapter.browserAuthentication,\n geolocation: adapter.geolocation,\n destroy: adapter.destroy ?? Effect.void,\n tables: adapter.tables,\n encryptionKeyring: adapter.encryptionKeyring,\n links: adapter.links ?? noNetworkLinks,\n bytes: adapter.blobBytes,\n });\n return service;\n });\n}\n"],"mappings":";;;;AAUA,IAAa,eAAb,cAAkC,OAAO,YAA0B,CAAC,CAAC,gBAAgB;CACjF,WAAW,OAAO;CAClB,OAAO,OAAO,OAAO;AACzB,CAAC,CAAC,CAAC,CAAC;AAiBJ,IAAa,UAAb,MAAa,gBAAgB,QAAQ,QAAiC,CAAC,CAAC,8BAA8B,CAAC,CAAC;;CAEpG,OAAgB,OAAO,OAAO,WAAW,WAAW,SAAyB;EACzE,MAAM,YAAY,OAAO;EAazB,OAXgB,QAAQ,GAAG;GACvB,GAAG;GACH,UAAU,QAAQ;GAClB,uBAAuB,QAAQ;GAC/B,aAAa,QAAQ;GACrB,SAAS,QAAQ,WAAW,OAAO;GACnC,QAAQ,QAAQ;GAChB,mBAAmB,QAAQ;GAC3B,OAAO,QAAQ,SAAS;GACxB,OAAO,QAAQ;EACnB,CACa;CACjB,CAAC;AACL"}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { BrowserAuthenticationError } from "./BrowserAuthenticationError.js";
|
|
|
2
2
|
import { Geolocation, GeolocationError, GeolocationOptions, GeolocationPosition, geolocationErrorCode } from "./Geolocation.js";
|
|
3
3
|
import { RuntimePartition } from "./RuntimePartition.js";
|
|
4
4
|
import { CapacityEstimate, ResourceCapacity, cloudflareCapacity } from "./capacity.js";
|
|
5
|
-
import { BrowserAuthentication, BrowserAuthenticationPresentation, BrowserAuthenticationSession, NetworkConnectivity, RuntimeAcquisitionError, RuntimeOptions } from "./types.js";
|
|
5
|
+
import { BrowserAuthentication, BrowserAuthenticationPresentation, BrowserAuthenticationSession, NetworkConnectivity, NetworkLink, NetworkLinkKind, NetworkLinks, RuntimeAcquisitionError, RuntimeOptions } from "./types.js";
|
|
6
6
|
import { Runtime, RuntimeError, RuntimeService } from "./Runtime.js";
|
|
7
7
|
import { MemoryRuntime_d_exports } from "./MemoryRuntime.js";
|
|
8
|
-
import { alwaysOnlineConnectivity, makeNetworkConnectivity } from "./NetworkConnectivity.js";
|
|
8
|
+
import { INTERNET, alwaysOnlineConnectivity, makeNetworkConnectivity, makeNetworkLinks, networkConnectivity, noNetworkLinks, singleNetworkLink } from "./NetworkConnectivity.js";
|
|
9
9
|
import { RuntimeLayer, Runtimes, RuntimesLayer } from "./Runtimes.js";
|
|
10
10
|
import { KeyMaterialCodec, KeyMaterialStore, makeKeyMaterialStoreKeyring, makeMemoryEncryptionKeyring } from "./encryptionKeys.js";
|
|
11
11
|
import { MemoryBlobBytesStore } from "./memory/MemoryBlobBytesStore.js";
|
|
12
12
|
import { BlobBytesService, ByteInput, ByteSource, byteChunks, byteIO, byteSource, collectByteBlob, readableByteSource } from "@party-stack/ontology-storage/blobs";
|
|
13
|
-
export { type BlobBytesService, type BrowserAuthentication, BrowserAuthenticationError, type BrowserAuthenticationPresentation, type BrowserAuthenticationSession, type ByteInput, type ByteSource, type CapacityEstimate, type Geolocation, GeolocationError, type GeolocationOptions, type GeolocationPosition, type KeyMaterialCodec, type KeyMaterialStore, MemoryBlobBytesStore, MemoryRuntime_d_exports as MemoryRuntime, type NetworkConnectivity, type ResourceCapacity, Runtime, type RuntimeAcquisitionError, RuntimeError, type RuntimeLayer, type RuntimeOptions, RuntimePartition, RuntimeService, Runtimes, type RuntimesLayer, alwaysOnlineConnectivity, byteChunks, byteIO, byteSource, cloudflareCapacity, collectByteBlob, geolocationErrorCode, makeKeyMaterialStoreKeyring, makeMemoryEncryptionKeyring, makeNetworkConnectivity, readableByteSource };
|
|
13
|
+
export { type BlobBytesService, type BrowserAuthentication, BrowserAuthenticationError, type BrowserAuthenticationPresentation, type BrowserAuthenticationSession, type ByteInput, type ByteSource, type CapacityEstimate, type Geolocation, GeolocationError, type GeolocationOptions, type GeolocationPosition, INTERNET, type KeyMaterialCodec, type KeyMaterialStore, MemoryBlobBytesStore, MemoryRuntime_d_exports as MemoryRuntime, type NetworkConnectivity, type NetworkLink, type NetworkLinkKind, type NetworkLinks, type ResourceCapacity, Runtime, type RuntimeAcquisitionError, RuntimeError, type RuntimeLayer, type RuntimeOptions, RuntimePartition, RuntimeService, Runtimes, type RuntimesLayer, alwaysOnlineConnectivity, byteChunks, byteIO, byteSource, cloudflareCapacity, collectByteBlob, geolocationErrorCode, makeKeyMaterialStoreKeyring, makeMemoryEncryptionKeyring, makeNetworkConnectivity, makeNetworkLinks, networkConnectivity, noNetworkLinks, readableByteSource, singleNetworkLink };
|
package/lib/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import { BrowserAuthenticationError } from "./BrowserAuthenticationError.js";
|
|
|
2
2
|
import { GeolocationError, geolocationErrorCode } from "./Geolocation.js";
|
|
3
3
|
import { makeKeyMaterialStoreKeyring, makeMemoryEncryptionKeyring } from "./encryptionKeys.js";
|
|
4
4
|
import { MemoryBlobBytesStore } from "./memory/MemoryBlobBytesStore.js";
|
|
5
|
-
import { alwaysOnlineConnectivity, makeNetworkConnectivity } from "./NetworkConnectivity.js";
|
|
5
|
+
import { INTERNET, alwaysOnlineConnectivity, makeNetworkConnectivity, makeNetworkLinks, networkConnectivity, noNetworkLinks, singleNetworkLink } from "./NetworkConnectivity.js";
|
|
6
6
|
import { RuntimePartition } from "./RuntimePartition.js";
|
|
7
7
|
import { Runtime, RuntimeError } from "./Runtime.js";
|
|
8
8
|
import { MemoryRuntime_exports } from "./MemoryRuntime.js";
|
|
9
9
|
import { Runtimes } from "./Runtimes.js";
|
|
10
10
|
import { cloudflareCapacity } from "./capacity.js";
|
|
11
11
|
import { byteChunks, byteIO, byteSource, collectByteBlob, readableByteSource } from "@party-stack/ontology-storage/blobs";
|
|
12
|
-
export { BrowserAuthenticationError, GeolocationError, MemoryBlobBytesStore, MemoryRuntime_exports as MemoryRuntime, Runtime, RuntimeError, RuntimePartition, Runtimes, alwaysOnlineConnectivity, byteChunks, byteIO, byteSource, cloudflareCapacity, collectByteBlob, geolocationErrorCode, makeKeyMaterialStoreKeyring, makeMemoryEncryptionKeyring, makeNetworkConnectivity, readableByteSource };
|
|
12
|
+
export { BrowserAuthenticationError, GeolocationError, INTERNET, MemoryBlobBytesStore, MemoryRuntime_exports as MemoryRuntime, Runtime, RuntimeError, RuntimePartition, Runtimes, alwaysOnlineConnectivity, byteChunks, byteIO, byteSource, cloudflareCapacity, collectByteBlob, geolocationErrorCode, makeKeyMaterialStoreKeyring, makeMemoryEncryptionKeyring, makeNetworkConnectivity, makeNetworkLinks, networkConnectivity, noNetworkLinks, readableByteSource, singleNetworkLink };
|
package/lib/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NetworkConnectivity, RuntimeOptions } from "./types.js";
|
|
1
|
+
import { NetworkConnectivity, NetworkLinks, RuntimeOptions } from "./types.js";
|
|
2
2
|
import { Runtime, RuntimeService } from "./Runtime.js";
|
|
3
3
|
import { Runtimes } from "./Runtimes.js";
|
|
4
4
|
import "./index.js";
|
|
@@ -7,13 +7,16 @@ import { EncryptionError, EncryptionKeyringService } from "@party-stack/ontology
|
|
|
7
7
|
import { OntologyStorageError } from "@party-stack/ontology-storage";
|
|
8
8
|
import { TablesService } from "@party-stack/ontology-storage/tables";
|
|
9
9
|
//#region src/testing.d.ts
|
|
10
|
-
export type RuntimeFixtureOptions = Omit<RuntimeOptions, "destroy" | "tables" | "encryptionKeyring" | "
|
|
10
|
+
export type RuntimeFixtureOptions = Omit<RuntimeOptions, "destroy" | "tables" | "encryptionKeyring" | "links"> & {
|
|
11
11
|
readonly tables?: Effect.Effect<TablesService, OntologyStorageError, Scope.Scope>;
|
|
12
12
|
readonly encryptionKeyring?: Effect.Effect<EncryptionKeyringService, EncryptionError, Scope.Scope>;
|
|
13
|
+
/** One link to the internet, available as this reports. */
|
|
13
14
|
readonly connectivity?: NetworkConnectivity | {
|
|
14
15
|
isConnected: boolean;
|
|
15
16
|
subscribe(callback: (online: boolean) => void): () => void;
|
|
16
17
|
};
|
|
18
|
+
/** The links, instead of `connectivity`. */
|
|
19
|
+
readonly links?: NetworkLinks;
|
|
17
20
|
readonly owner: string;
|
|
18
21
|
readonly namespace: string;
|
|
19
22
|
readonly destroy?: RuntimeOptions["destroy"] | (() => void | Promise<void>);
|
package/lib/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","names":[],"sources":["../src/testing.ts"],"mappings":";;;;;;;;;YAaY,wBAAwB,KAChC;WAGS,SAAS,OAAO,OAAO,eAAe,sBAAsB,MAAM;WAClE,oBAAoB,OAAO,OAAO,0BAA0B,iBAAiB,MAAM
|
|
1
|
+
{"version":3,"file":"testing.d.ts","names":[],"sources":["../src/testing.ts"],"mappings":";;;;;;;;;YAaY,wBAAwB,KAChC;WAGS,SAAS,OAAO,OAAO,eAAe,sBAAsB,MAAM;WAClE,oBAAoB,OAAO,OAAO,0BAA0B,iBAAiB,MAAM;;WAEnF,eACH;IACE;IAAsB,UAAU,WAAW;;;WAE1C,QAAQ;WACR;WACA;WACA,UAAU,0CAA0C;;YAErD,iBAAiB,KAAK;EAC9B,WAAW;EACX,WAAW;;qBAiDF,kBAAe,SAAa,0BAAqB,OAAA,OAAA,gBAAA,kBAAA,sBAAA,MAAA;wBAe9C,qBAAqB,WAAW,eAAe,sBAAsB,yBAAqB,eACjF,sBAAmB;qBAE/B,uBAAoB,eAFR,sBAAmB;wBAOtB,eAAe,GACjC,QAAQ,OAAO,OAAO,gBAAgB,GAAG,MAAM,SAChD,QAAQ;wBAuBK,sBAAsB,OAAO;EAvF5B,SAAA;EACF,OAAA,MAAM;EACJ;IAAE,YAAY,kBAAkB,OAAO,eAAe;;;qBAqH1D,sBAAmB,kBAAiB;;qBAQpC,iBAAc,WAEnB,eACA,sBACC;EAA0B,uBAAuB;MAAe,MAAA,MAAA"}
|
package/lib/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MemoryBlobBytesStore } from "./memory/MemoryBlobBytesStore.js";
|
|
2
|
-
import { makeNetworkConnectivity } from "./NetworkConnectivity.js";
|
|
2
|
+
import { makeNetworkConnectivity, singleNetworkLink } from "./NetworkConnectivity.js";
|
|
3
3
|
import { RuntimePartition } from "./RuntimePartition.js";
|
|
4
4
|
import { Runtime, RuntimeError } from "./Runtime.js";
|
|
5
5
|
import { Runtimes } from "./Runtimes.js";
|
|
@@ -38,7 +38,10 @@ const optionsFor = Effect.fnUntraced(function* (value) {
|
|
|
38
38
|
...original,
|
|
39
39
|
tables: yield* original.tables ?? Memory.make(),
|
|
40
40
|
encryptionKeyring: original.encryptionKeyring ? yield* original.encryptionKeyring : void 0,
|
|
41
|
-
connectivity,
|
|
41
|
+
links: original.links ?? (connectivity && singleNetworkLink(connectivity, () => ({
|
|
42
|
+
kind: "unknown",
|
|
43
|
+
networks: ["internet"]
|
|
44
|
+
}))),
|
|
42
45
|
destroy: destroyFor(value)
|
|
43
46
|
};
|
|
44
47
|
});
|
|
@@ -74,7 +77,7 @@ async function acquireRuntime(effect) {
|
|
|
74
77
|
tables: Effect.succeed(service.tables),
|
|
75
78
|
encryptionKeyring: service.encryptionKeyring ? Effect.succeed(service.encryptionKeyring) : void 0,
|
|
76
79
|
browserAuthentication: service.browserAuthentication,
|
|
77
|
-
|
|
80
|
+
links: service.links,
|
|
78
81
|
blobBytes: service.bytes,
|
|
79
82
|
destroy: service.destroy
|
|
80
83
|
});
|
package/lib/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","names":[],"sources":["../src/testing.ts"],"sourcesContent":["import * as Memory from \"@party-stack/ontology-storage/memory/tables\";\n/** Test boundaries for driving scoped services from Promise-based assertions. */\nimport { Context, Effect, Exit, Layer, Scope } from \"effect\";\nimport { MemoryBlobBytesStore } from \"./memory/MemoryBlobBytesStore.js\";\nimport { makeNetworkConnectivity } from \"./NetworkConnectivity.js\";\nimport { Runtime, RuntimeError } from \"./Runtime.js\";\nimport { RuntimePartition } from \"./RuntimePartition.js\";\nimport { Runtimes } from \"./Runtimes.js\";\nimport type { RuntimeOptions, RuntimeService, NetworkConnectivity } from \"./index.js\";\nimport type { OntologyStorageError } from \"@party-stack/ontology-storage\";\nimport type { EncryptionError, EncryptionKeyringService } from \"@party-stack/ontology-storage/encrypted\";\nimport type { TablesService } from \"@party-stack/ontology-storage/tables\";\n\nexport type RuntimeFixtureOptions = Omit<\n RuntimeOptions,\n \"destroy\" | \"tables\" | \"encryptionKeyring\" | \"connectivity\"\n> & {\n readonly tables?: Effect.Effect<TablesService, OntologyStorageError, Scope.Scope>;\n readonly encryptionKeyring?: Effect.Effect<EncryptionKeyringService, EncryptionError, Scope.Scope>;\n readonly connectivity?:\n | NetworkConnectivity\n | { isConnected: boolean; subscribe(callback: (online: boolean) => void): () => void };\n readonly owner: string;\n readonly namespace: string;\n readonly destroy?: RuntimeOptions[\"destroy\"] | (() => void | Promise<void>);\n};\nexport type RuntimeFixture = Omit<RuntimeFixtureOptions, \"destroy\"> & {\n cleanup(): Promise<void>;\n destroy(): Promise<void>;\n};\nconst optionsByFixture = new WeakMap<object, RuntimeFixtureOptions>();\nconst states = new WeakMap<\n object,\n { service: RuntimeService; scope: Scope.Closeable; closed: boolean; closing?: Promise<void> }\n>();\nconst bridges = new WeakMap<\n object,\n {\n service: RuntimeService;\n scope: Scope.Closeable;\n runtime: { runPromise: ReturnType<typeof Effect.runPromiseWith<Runtime>> };\n }\n>();\nconst destroyFor = (value: RuntimeFixtureOptions) => {\n const destroy = (optionsByFixture.get(value) ?? value).destroy;\n return typeof destroy === \"function\"\n ? Effect.tryPromise({\n try: async () => {\n await destroy();\n },\n catch: (cause) => new RuntimeError({ operation: \"destroy\", cause }),\n })\n : (destroy ?? Effect.void);\n};\nconst optionsFor = Effect.fnUntraced(function* (value: RuntimeFixtureOptions) {\n const original = optionsByFixture.get(value) ?? value;\n const monitor = original.connectivity;\n let connectivity: NetworkConnectivity | undefined;\n if (monitor && \"isConnected\" in monitor) {\n const state = yield* makeNetworkConnectivity(monitor.isConnected);\n yield* Effect.acquireRelease(\n Effect.sync(() => monitor.subscribe((online) => Effect.runSync(state.set(online)))),\n (unsubscribe) => Effect.sync(unsubscribe)\n );\n connectivity = { online: Effect.sync(() => monitor.isConnected), changes: state.changes };\n } else connectivity = monitor;\n return {\n ...original,\n tables: yield* original.tables ?? Memory.make(),\n encryptionKeyring: original.encryptionKeyring ? yield* original.encryptionKeyring : undefined,\n connectivity,\n destroy: destroyFor(value),\n } satisfies RuntimeOptions;\n});\nexport const makeTestRuntime = (options: RuntimeFixtureOptions) =>\n Effect.flatMap(optionsFor(options), Runtime.make).pipe(\n Effect.provideService(RuntimePartition, { owner: options.owner, namespace: options.namespace })\n );\nfunction fixture(options: RuntimeFixtureOptions): RuntimeFixture {\n let destroying: Promise<void> | undefined;\n const value = {\n ...options,\n cleanup: () => closeRuntimeFixture(value),\n destroy: () =>\n (destroying ??= closeRuntimeFixture(value).then(() => Effect.runPromise(destroyFor(value)))),\n };\n optionsByFixture.set(value, options);\n return value;\n}\nexport function defineRuntimeFixture(provider: (owner: string, namespace: string) => RuntimeFixtureOptions) {\n return (owner: string, namespace: string) => fixture(provider(owner, namespace));\n}\nexport const memoryRuntimeFixture = defineRuntimeFixture((owner, namespace) => ({\n owner,\n namespace,\n blobBytes: new MemoryBlobBytesStore(),\n}));\nexport async function acquireRuntime<E>(\n effect: Effect.Effect<RuntimeService, E, Scope.Scope>\n): Promise<RuntimeFixture> {\n const scope = Effect.runSync(Scope.make());\n try {\n const service = await Effect.runPromise(Scope.provide(effect, scope));\n const value = fixture({\n owner: service.owner,\n namespace: service.namespace,\n tables: Effect.succeed(service.tables),\n encryptionKeyring: service.encryptionKeyring\n ? Effect.succeed(service.encryptionKeyring)\n : undefined,\n browserAuthentication: service.browserAuthentication,\n connectivity: service.connectivity,\n blobBytes: service.bytes,\n destroy: service.destroy,\n });\n states.set(value, { service, scope, closed: false });\n return value;\n } catch (cause) {\n await Effect.runPromise(Scope.close(scope, Exit.fail(cause)));\n throw cause;\n }\n}\nexport function runtimeFixtureContext(value: RuntimeFixtureOptions) {\n let state = states.get(value);\n if (state?.closed) throw new Error(\"Runtime is closed.\");\n if (!state) {\n const scope = Effect.runSync(Scope.make());\n const service = Effect.runSync(\n Scope.provide(\n Effect.flatMap(optionsFor(value), Runtime.make).pipe(\n Effect.provideService(RuntimePartition, {\n owner: value.owner,\n namespace: value.namespace,\n })\n ),\n scope\n )\n );\n state = { service, scope, closed: false };\n states.set(value, state);\n }\n let bridge = bridges.get(value);\n if (!bridge) {\n bridge = {\n service: state.service,\n scope: state.scope,\n runtime: {\n runPromise: Effect.runPromiseWith(Context.make(Runtime, state.service)),\n },\n };\n bridges.set(value, bridge);\n }\n return bridge;\n}\nexport const closeRuntimeFixture = (value: object) => {\n const state = states.get(value);\n if (!state) return Promise.resolve();\n if (state.closing) return state.closing;\n state.closed = true;\n return (state.closing = Effect.runPromise(Scope.close(state.scope, Exit.void)));\n};\n/** Test Layers supply the same service contract as native platform Layers. */\nexport const asRuntimeLayer = (\n provider: (\n owner: string,\n namespace: string\n ) => RuntimeFixtureOptions & { cleanup?: () => void | Promise<void> }\n) =>\n Runtimes.layer(\n Layer.effect(\n Runtime,\n Effect.gen(function* () {\n const partition = yield* RuntimePartition;\n const value = yield* Effect.acquireRelease(\n Effect.sync(() => provider(partition.owner, partition.namespace)),\n (value) =>\n Effect.promise(async () => {\n await value.cleanup?.();\n })\n );\n const existing = states.get(value);\n if (existing && !existing.closed) return existing.service;\n return yield* Effect.flatMap(optionsFor(value), Runtime.make);\n })\n )\n );\n"],"mappings":";;;;;;;;;AA8BA,MAAM,mCAAmB,IAAI,QAAuC;AACpE,MAAM,yBAAS,IAAI,QAGjB;AACF,MAAM,0BAAU,IAAI,QAOlB;AACF,MAAM,cAAc,UAAiC;CACjD,MAAM,WAAW,iBAAiB,IAAI,KAAK,KAAK,MAAA,CAAO;CACvD,OAAO,OAAO,YAAY,aACpB,OAAO,WAAW;EACd,KAAK,YAAY;GACb,MAAM,QAAQ;EAClB;EACA,QAAQ,UAAU,IAAI,aAAa;GAAE,WAAW;GAAW;EAAM,CAAC;CACtE,CAAC,IACA,WAAW,OAAO;AAC7B;AACA,MAAM,aAAa,OAAO,WAAW,WAAW,OAA8B;CAC1E,MAAM,WAAW,iBAAiB,IAAI,KAAK,KAAK;CAChD,MAAM,UAAU,SAAS;CACzB,IAAI;CACJ,IAAI,WAAW,iBAAiB,SAAS;EACrC,MAAM,QAAQ,OAAO,wBAAwB,QAAQ,WAAW;EAChE,OAAO,OAAO,eACV,OAAO,WAAW,QAAQ,WAAW,WAAW,OAAO,QAAQ,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,IACjF,gBAAgB,OAAO,KAAK,WAAW,CAC5C;EACA,eAAe;GAAE,QAAQ,OAAO,WAAW,QAAQ,WAAW;GAAG,SAAS,MAAM;EAAQ;CAC5F,OAAO,eAAe;CACtB,OAAO;EACH,GAAG;EACH,QAAQ,OAAO,SAAS,UAAU,OAAO,KAAK;EAC9C,mBAA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C1B,CAAC,CACT;CACA,MAAM,WAAW,OAAO,IAAI,KAAK;CACjC,IAAI,YAAY,CAAC,SAAS,QAAQ,OAAO,SAAS;CAClD,OAAO,OAAO,OAAO,QAAQ,WAAW,KAAK,GAAG,QAAQ,IAAI;AAChE,CAAC,CACL,CACJ"}
|
|
1
|
+
{"version":3,"file":"testing.js","names":[],"sources":["../src/testing.ts"],"sourcesContent":["import * as Memory from \"@party-stack/ontology-storage/memory/tables\";\n/** Test boundaries for driving scoped services from Promise-based assertions. */\nimport { Context, Effect, Exit, Layer, Scope } from \"effect\";\nimport { MemoryBlobBytesStore } from \"./memory/MemoryBlobBytesStore.js\";\nimport { INTERNET, makeNetworkConnectivity, singleNetworkLink } from \"./NetworkConnectivity.js\";\nimport { Runtime, RuntimeError } from \"./Runtime.js\";\nimport { RuntimePartition } from \"./RuntimePartition.js\";\nimport { Runtimes } from \"./Runtimes.js\";\nimport type { RuntimeOptions, RuntimeService, NetworkConnectivity, NetworkLinks } from \"./index.js\";\nimport type { OntologyStorageError } from \"@party-stack/ontology-storage\";\nimport type { EncryptionError, EncryptionKeyringService } from \"@party-stack/ontology-storage/encrypted\";\nimport type { TablesService } from \"@party-stack/ontology-storage/tables\";\n\nexport type RuntimeFixtureOptions = Omit<\n RuntimeOptions,\n \"destroy\" | \"tables\" | \"encryptionKeyring\" | \"links\"\n> & {\n readonly tables?: Effect.Effect<TablesService, OntologyStorageError, Scope.Scope>;\n readonly encryptionKeyring?: Effect.Effect<EncryptionKeyringService, EncryptionError, Scope.Scope>;\n /** One link to the internet, available as this reports. */\n readonly connectivity?:\n | NetworkConnectivity\n | { isConnected: boolean; subscribe(callback: (online: boolean) => void): () => void };\n /** The links, instead of `connectivity`. */\n readonly links?: NetworkLinks;\n readonly owner: string;\n readonly namespace: string;\n readonly destroy?: RuntimeOptions[\"destroy\"] | (() => void | Promise<void>);\n};\nexport type RuntimeFixture = Omit<RuntimeFixtureOptions, \"destroy\"> & {\n cleanup(): Promise<void>;\n destroy(): Promise<void>;\n};\nconst optionsByFixture = new WeakMap<object, RuntimeFixtureOptions>();\nconst states = new WeakMap<\n object,\n { service: RuntimeService; scope: Scope.Closeable; closed: boolean; closing?: Promise<void> }\n>();\nconst bridges = new WeakMap<\n object,\n {\n service: RuntimeService;\n scope: Scope.Closeable;\n runtime: { runPromise: ReturnType<typeof Effect.runPromiseWith<Runtime>> };\n }\n>();\nconst destroyFor = (value: RuntimeFixtureOptions) => {\n const destroy = (optionsByFixture.get(value) ?? value).destroy;\n return typeof destroy === \"function\"\n ? Effect.tryPromise({\n try: async () => {\n await destroy();\n },\n catch: (cause) => new RuntimeError({ operation: \"destroy\", cause }),\n })\n : (destroy ?? Effect.void);\n};\nconst optionsFor = Effect.fnUntraced(function* (value: RuntimeFixtureOptions) {\n const original = optionsByFixture.get(value) ?? value;\n const monitor = original.connectivity;\n let connectivity: NetworkConnectivity | undefined;\n if (monitor && \"isConnected\" in monitor) {\n const state = yield* makeNetworkConnectivity(monitor.isConnected);\n yield* Effect.acquireRelease(\n Effect.sync(() => monitor.subscribe((online) => Effect.runSync(state.set(online)))),\n (unsubscribe) => Effect.sync(unsubscribe)\n );\n connectivity = { online: Effect.sync(() => monitor.isConnected), changes: state.changes };\n } else connectivity = monitor;\n return {\n ...original,\n tables: yield* original.tables ?? Memory.make(),\n encryptionKeyring: original.encryptionKeyring ? yield* original.encryptionKeyring : undefined,\n links:\n original.links ??\n (connectivity &&\n singleNetworkLink(connectivity, () => ({ kind: \"unknown\", networks: [INTERNET] }))),\n destroy: destroyFor(value),\n } satisfies RuntimeOptions;\n});\nexport const makeTestRuntime = (options: RuntimeFixtureOptions) =>\n Effect.flatMap(optionsFor(options), Runtime.make).pipe(\n Effect.provideService(RuntimePartition, { owner: options.owner, namespace: options.namespace })\n );\nfunction fixture(options: RuntimeFixtureOptions): RuntimeFixture {\n let destroying: Promise<void> | undefined;\n const value = {\n ...options,\n cleanup: () => closeRuntimeFixture(value),\n destroy: () =>\n (destroying ??= closeRuntimeFixture(value).then(() => Effect.runPromise(destroyFor(value)))),\n };\n optionsByFixture.set(value, options);\n return value;\n}\nexport function defineRuntimeFixture(provider: (owner: string, namespace: string) => RuntimeFixtureOptions) {\n return (owner: string, namespace: string) => fixture(provider(owner, namespace));\n}\nexport const memoryRuntimeFixture = defineRuntimeFixture((owner, namespace) => ({\n owner,\n namespace,\n blobBytes: new MemoryBlobBytesStore(),\n}));\nexport async function acquireRuntime<E>(\n effect: Effect.Effect<RuntimeService, E, Scope.Scope>\n): Promise<RuntimeFixture> {\n const scope = Effect.runSync(Scope.make());\n try {\n const service = await Effect.runPromise(Scope.provide(effect, scope));\n const value = fixture({\n owner: service.owner,\n namespace: service.namespace,\n tables: Effect.succeed(service.tables),\n encryptionKeyring: service.encryptionKeyring\n ? Effect.succeed(service.encryptionKeyring)\n : undefined,\n browserAuthentication: service.browserAuthentication,\n links: service.links,\n blobBytes: service.bytes,\n destroy: service.destroy,\n });\n states.set(value, { service, scope, closed: false });\n return value;\n } catch (cause) {\n await Effect.runPromise(Scope.close(scope, Exit.fail(cause)));\n throw cause;\n }\n}\nexport function runtimeFixtureContext(value: RuntimeFixtureOptions) {\n let state = states.get(value);\n if (state?.closed) throw new Error(\"Runtime is closed.\");\n if (!state) {\n const scope = Effect.runSync(Scope.make());\n const service = Effect.runSync(\n Scope.provide(\n Effect.flatMap(optionsFor(value), Runtime.make).pipe(\n Effect.provideService(RuntimePartition, {\n owner: value.owner,\n namespace: value.namespace,\n })\n ),\n scope\n )\n );\n state = { service, scope, closed: false };\n states.set(value, state);\n }\n let bridge = bridges.get(value);\n if (!bridge) {\n bridge = {\n service: state.service,\n scope: state.scope,\n runtime: {\n runPromise: Effect.runPromiseWith(Context.make(Runtime, state.service)),\n },\n };\n bridges.set(value, bridge);\n }\n return bridge;\n}\nexport const closeRuntimeFixture = (value: object) => {\n const state = states.get(value);\n if (!state) return Promise.resolve();\n if (state.closing) return state.closing;\n state.closed = true;\n return (state.closing = Effect.runPromise(Scope.close(state.scope, Exit.void)));\n};\n/** Test Layers supply the same service contract as native platform Layers. */\nexport const asRuntimeLayer = (\n provider: (\n owner: string,\n namespace: string\n ) => RuntimeFixtureOptions & { cleanup?: () => void | Promise<void> }\n) =>\n Runtimes.layer(\n Layer.effect(\n Runtime,\n Effect.gen(function* () {\n const partition = yield* RuntimePartition;\n const value = yield* Effect.acquireRelease(\n Effect.sync(() => provider(partition.owner, partition.namespace)),\n (value) =>\n Effect.promise(async () => {\n await value.cleanup?.();\n })\n );\n const existing = states.get(value);\n if (existing && !existing.closed) return existing.service;\n return yield* Effect.flatMap(optionsFor(value), Runtime.make);\n })\n )\n );\n"],"mappings":";;;;;;;;;AAiCA,MAAM,mCAAmB,IAAI,QAAuC;AACpE,MAAM,yBAAS,IAAI,QAGjB;AACF,MAAM,0BAAU,IAAI,QAOlB;AACF,MAAM,cAAc,UAAiC;CACjD,MAAM,WAAW,iBAAiB,IAAI,KAAK,KAAK,MAAA,CAAO;CACvD,OAAO,OAAO,YAAY,aACpB,OAAO,WAAW;EACd,KAAK,YAAY;GACb,MAAM,QAAQ;EAClB;EACA,QAAQ,UAAU,IAAI,aAAa;GAAE,WAAW;GAAW;EAAM,CAAC;CACtE,CAAC,IACA,WAAW,OAAO;AAC7B;AACA,MAAM,aAAa,OAAO,WAAW,WAAW,OAA8B;CAC1E,MAAM,WAAW,iBAAiB,IAAI,KAAK,KAAK;CAChD,MAAM,UAAU,SAAS;CACzB,IAAI;CACJ,IAAI,WAAW,iBAAiB,SAAS;EACrC,MAAM,QAAQ,OAAO,wBAAwB,QAAQ,WAAW;EAChE,OAAO,OAAO,eACV,OAAO,WAAW,QAAQ,WAAW,WAAW,OAAO,QAAQ,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,IACjF,gBAAgB,OAAO,KAAK,WAAW,CAC5C;EACA,eAAe;GAAE,QAAQ,OAAO,WAAW,QAAQ,WAAW;GAAG,SAAS,MAAM;EAAQ;CAC5F,OAAO,eAAe;CACtB,OAAO;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Y,OAAO;CACzB,MAAM,QAAQ,OAAO,OAAO,eACxB,OAAO,WAAW,SAAS,UAAU,OAAO,UAAU,SAAS,CAAC,IAC/D,UACG,OAAO,QAAQ,YAAY;EACvB,MAAM,MAAM,UAAU;CAC1B,CAAC,CACT;CACA,MAAM,WAAW,OAAO,IAAI,KAAK;CACjC,IAAI,YAAY,CAAC,SAAS,QAAQ,OAAO,SAAS;CAClD,OAAO,OAAO,OAAO,QAAQ,WAAW,KAAK,GAAG,QAAQ,IAAI;AAChE,CAAC,CACL,CACJ"}
|
package/lib/types.d.ts
CHANGED
|
@@ -8,11 +8,37 @@ import { BlobBytesService } from "@party-stack/ontology-storage/blobs";
|
|
|
8
8
|
import { OntologyStorageError } from "@party-stack/ontology-storage";
|
|
9
9
|
import { TablesService } from "@party-stack/ontology-storage/tables";
|
|
10
10
|
//#region src/types.d.ts
|
|
11
|
+
/** Whether something can be reached now, such as a source over the networks it is on. */
|
|
11
12
|
export interface NetworkConnectivity {
|
|
12
13
|
readonly online: Effect.Effect<boolean>;
|
|
13
14
|
/** Includes the current state; intermediate transitions may be coalesced. */
|
|
14
15
|
readonly changes: Stream.Stream<boolean>;
|
|
15
16
|
}
|
|
17
|
+
export type NetworkLinkKind = "wifi" | "cellular" | "ethernet" | "bluetooth" | "other" | "unknown";
|
|
18
|
+
/**
|
|
19
|
+
* One way the device connects (Wi-Fi, cellular, ...), as the platform reports it, and the networks
|
|
20
|
+
* it reaches. Web and Expo runtimes report their connection as reaching `"internet"`; a deployment
|
|
21
|
+
* on a private network says which network its links reach instead.
|
|
22
|
+
*/
|
|
23
|
+
export interface NetworkLink {
|
|
24
|
+
readonly kind: NetworkLinkKind;
|
|
25
|
+
readonly available: boolean;
|
|
26
|
+
/** Networks reachable over this link, such as `"internet"`. */
|
|
27
|
+
readonly networks: readonly string[];
|
|
28
|
+
/** Charged by usage or capped, such as cellular or a phone hotspot. Unset when unknown. */
|
|
29
|
+
readonly metered?: boolean;
|
|
30
|
+
/** The user turned on data saving for this link (Low Data Mode, Data Saver, Save-Data).
|
|
31
|
+
* Unset when unknown. */
|
|
32
|
+
readonly prefersReducedData?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The device's links. A backend names the networks it is on (`OntologyBackendService.networks`);
|
|
35
|
+
* its replica syncs while a link reaching one of them is available. */
|
|
36
|
+
export interface NetworkLinks {
|
|
37
|
+
/** The links now, read from the platform. */
|
|
38
|
+
readonly current: Effect.Effect<readonly NetworkLink[]>;
|
|
39
|
+
/** Includes the current links first; intermediate transitions may be coalesced. */
|
|
40
|
+
readonly changes: Stream.Stream<readonly NetworkLink[]>;
|
|
41
|
+
}
|
|
16
42
|
export type BrowserAuthenticationPresentation = "popup" | "redirect";
|
|
17
43
|
export interface BrowserAuthenticationSession {
|
|
18
44
|
open(authorizationUrl: string): Effect.Effect<{
|
|
@@ -29,7 +55,8 @@ export interface BrowserAuthentication {
|
|
|
29
55
|
export interface RuntimeOptions {
|
|
30
56
|
readonly capacity?: ResourceCapacity;
|
|
31
57
|
blobBytes: BlobBytesService;
|
|
32
|
-
|
|
58
|
+
/** The links the platform monitors. A network no link reaches is treated as available. */
|
|
59
|
+
links?: NetworkLinks;
|
|
33
60
|
browserAuthentication?: BrowserAuthentication;
|
|
34
61
|
/** Device location, where the platform provides it. */
|
|
35
62
|
geolocation?: Geolocation;
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;iBAWiB;WACJ,QAAQ,OAAO;;WAEf,SAAS,OAAO;;YAGjB;;;;;;iBAMK;WACJ,MAAM;WACN;;WAEA;;WAEA;;;WAGA;;;;iBAII;;WAEJ,SAAS,OAAO,gBAAgB;;WAEhC,SAAS,OAAO,gBAAgB;;YAGjC;iBAEK;EACb,KAAK,2BAA2B,OAAO;IAAS;KAAuB;;iBAG1D;EACb,MAAM;IACF;IACA,eAAe;MACf,OAAO,OAAO,8BAA8B,4BAA4B,MAAM;;;iBAIrE;WACJ,WAAW;EACpB,WAAW;;EAEX,QAAQ;EACR,wBAAwB;;EAExB,cAAc;EACd,oBAAoB;;EAEpB,QAAQ;EACR,UAAU,OAAO,aAAa;;YAGtB,0BAA0B,eAAe,uBAAuB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@party-stack/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib"
|
|
6
6
|
],
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"effect": "^4.0.5",
|
|
24
|
-
"@party-stack/ontology-storage": "0.4.
|
|
24
|
+
"@party-stack/ontology-storage": "0.4.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"temporal-polyfill": "^0.3.0",
|