@party-stack/expo-runtime 0.6.2 → 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/ExpoNetworkConnectivity.d.ts +2 -5
- package/lib/ExpoNetworkConnectivity.d.ts.map +1 -1
- package/lib/ExpoNetworkConnectivity.js +27 -7
- package/lib/ExpoNetworkConnectivity.js.map +1 -1
- package/lib/createExpoRuntime.js +4 -4
- package/lib/createExpoRuntime.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { RuntimeError } from "@party-stack/runtime";
|
|
1
|
+
import { NetworkLinks, RuntimeError } from "@party-stack/runtime";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
//#region src/ExpoNetworkConnectivity.d.ts
|
|
4
|
-
export declare const
|
|
5
|
-
online: Effect.Effect<boolean, never, never>;
|
|
6
|
-
changes: import("effect/Stream").Stream<boolean, never, never>;
|
|
7
|
-
}, RuntimeError, import("effect/Scope").Scope>;
|
|
4
|
+
export declare const makeExpoNetworkLinks: () => Effect.Effect<NetworkLinks, RuntimeError, import("effect/Scope").Scope>;
|
|
8
5
|
//#endregion
|
|
9
6
|
//# sourceMappingURL=ExpoNetworkConnectivity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoNetworkConnectivity.d.ts","names":[],"sources":["../src/ExpoNetworkConnectivity.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ExpoNetworkConnectivity.d.ts","names":[],"sources":["../src/ExpoNetworkConnectivity.ts"],"mappings":";;;qBA8Ba,4BAAoB,OAAA,OAAA,cAAA,qCAAA"}
|
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
import { RuntimeError,
|
|
1
|
+
import { INTERNET, RuntimeError, makeNetworkLinks } from "@party-stack/runtime";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import NetInfo from "@react-native-community/netinfo";
|
|
4
4
|
//#region src/ExpoNetworkConnectivity.ts
|
|
5
|
-
const
|
|
5
|
+
const kinds = {
|
|
6
|
+
wifi: "wifi",
|
|
7
|
+
cellular: "cellular",
|
|
8
|
+
ethernet: "ethernet",
|
|
9
|
+
bluetooth: "bluetooth",
|
|
10
|
+
wimax: "cellular",
|
|
11
|
+
vpn: "other",
|
|
12
|
+
other: "other"
|
|
13
|
+
};
|
|
14
|
+
/** NetInfo reports the connection in use: one link to the internet, with its kind and whether
|
|
15
|
+
* it is metered. NetInfo does not report Low Data Mode or Data Saver. */
|
|
16
|
+
const linkOf = (state) => {
|
|
17
|
+
const details = state.details;
|
|
18
|
+
return {
|
|
19
|
+
kind: kinds[state.type] ?? "unknown",
|
|
20
|
+
available: state.isConnected === true,
|
|
21
|
+
networks: [INTERNET],
|
|
22
|
+
...typeof details?.isConnectionExpensive === "boolean" && { metered: details.isConnectionExpensive }
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const makeExpoNetworkLinks = Effect.fnUntraced(function* () {
|
|
6
26
|
const initial = yield* Effect.tryPromise({
|
|
7
27
|
try: () => NetInfo.fetch(),
|
|
8
28
|
catch: (cause) => new RuntimeError({
|
|
@@ -10,16 +30,16 @@ const makeExpoNetworkConnectivity = Effect.fnUntraced(function* () {
|
|
|
10
30
|
cause
|
|
11
31
|
})
|
|
12
32
|
});
|
|
13
|
-
const
|
|
33
|
+
const links = yield* makeNetworkLinks([linkOf(initial)]);
|
|
14
34
|
yield* Effect.acquireRelease(Effect.sync(() => NetInfo.addEventListener((value) => {
|
|
15
|
-
Effect.runSync(
|
|
35
|
+
Effect.runSync(links.set([linkOf(value)]));
|
|
16
36
|
})), (unsubscribe) => Effect.sync(unsubscribe));
|
|
17
37
|
return {
|
|
18
|
-
|
|
19
|
-
changes:
|
|
38
|
+
current: links.current,
|
|
39
|
+
changes: links.changes
|
|
20
40
|
};
|
|
21
41
|
});
|
|
22
42
|
//#endregion
|
|
23
|
-
export {
|
|
43
|
+
export { makeExpoNetworkLinks };
|
|
24
44
|
|
|
25
45
|
//# sourceMappingURL=ExpoNetworkConnectivity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoNetworkConnectivity.js","names":[],"sources":["../src/ExpoNetworkConnectivity.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"ExpoNetworkConnectivity.js","names":[],"sources":["../src/ExpoNetworkConnectivity.ts"],"sourcesContent":["import { INTERNET, makeNetworkLinks, RuntimeError } from \"@party-stack/runtime\";\nimport NetInfo from \"@react-native-community/netinfo\";\nimport { Effect } from \"effect\";\nimport type { NetworkLink, NetworkLinks } from \"@party-stack/runtime\";\nimport type { NetInfoState } from \"@react-native-community/netinfo\";\n\nconst kinds: Readonly<Record<string, NetworkLink[\"kind\"]>> = {\n wifi: \"wifi\",\n cellular: \"cellular\",\n ethernet: \"ethernet\",\n bluetooth: \"bluetooth\",\n wimax: \"cellular\",\n vpn: \"other\",\n other: \"other\",\n};\n\n/** NetInfo reports the connection in use: one link to the internet, with its kind and whether\n * it is metered. NetInfo does not report Low Data Mode or Data Saver. */\nconst linkOf = (state: NetInfoState): NetworkLink => {\n const details = state.details as { readonly isConnectionExpensive?: boolean } | null;\n return {\n kind: kinds[state.type] ?? \"unknown\",\n available: state.isConnected === true,\n networks: [INTERNET],\n ...(typeof details?.isConnectionExpensive === \"boolean\" && {\n metered: details.isConnectionExpensive,\n }),\n };\n};\n\nexport const makeExpoNetworkLinks = Effect.fnUntraced(function* (): Effect.fn.Return<\n NetworkLinks,\n RuntimeError,\n import(\"effect\").Scope.Scope\n> {\n const initial = yield* Effect.tryPromise({\n try: () => NetInfo.fetch(),\n catch: (cause) => new RuntimeError({ operation: \"expoRuntime.connectivity\", cause }),\n });\n const links = yield* makeNetworkLinks([linkOf(initial)]);\n yield* Effect.acquireRelease(\n Effect.sync(() =>\n NetInfo.addEventListener((value) => {\n Effect.runSync(links.set([linkOf(value)]));\n })\n ),\n (unsubscribe) => Effect.sync(unsubscribe)\n );\n return { current: links.current, changes: links.changes };\n});\n"],"mappings":";;;;AAMA,MAAM,QAAuD;CACzD,MAAM;CACN,UAAU;CACV,UAAU;CACV,WAAW;CACX,OAAO;CACP,KAAK;CACL,OAAO;AACX;;;AAIA,MAAM,UAAU,UAAqC;CACjD,MAAM,UAAU,MAAM;CACtB,OAAO;EACH,MAAM,MAAM,MAAM,SAAS;EAC3B,WAAW,MAAM,gBAAgB;EACjC,UAAU,CAAC,QAAQ;EACnB,GAAI,OAAO,SAAS,0BAA0B,aAAa,EACvD,SAAS,QAAQ,sBACrB;CACJ;AACJ;AAEA,MAAa,uBAAuB,OAAO,WAAW,aAIpD;CACE,MAAM,UAAU,OAAO,OAAO,WAAW;EACrC,WAAW,QAAQ,MAAM;EACzB,QAAQ,UAAU,IAAI,aAAa;GAAE,WAAW;GAA4B;EAAM,CAAC;CACvF,CAAC;CACD,MAAM,QAAQ,OAAO,iBAAiB,CAAC,OAAO,OAAO,CAAC,CAAC;CACvD,OAAO,OAAO,eACV,OAAO,WACH,QAAQ,kBAAkB,UAAU;EAChC,OAAO,QAAQ,MAAM,IAAI,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;CAC7C,CAAC,CACL,IACC,gBAAgB,OAAO,KAAK,WAAW,CAC5C;CACA,OAAO;EAAE,SAAS,MAAM;EAAS,SAAS,MAAM;CAAQ;AAC5D,CAAC"}
|
package/lib/createExpoRuntime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { hashStorageName } from "./hashStorageName.js";
|
|
2
2
|
import { ExpoFileSystemBlobBytesStore } from "./ExpoFileSystemBlobBytesStore.js";
|
|
3
3
|
import { makeKeyMaterialStore } from "./ExpoKeyMaterialStore.js";
|
|
4
|
-
import {
|
|
4
|
+
import { makeExpoNetworkLinks } from "./ExpoNetworkConnectivity.js";
|
|
5
5
|
import { createExpoBrowserAuthentication } from "./createExpoBrowserAuthentication.js";
|
|
6
6
|
import { createExpoGeolocation } from "./createExpoGeolocation.js";
|
|
7
7
|
import { nativeKeyCodec } from "./encryptionKeys.js";
|
|
@@ -22,7 +22,7 @@ configureNativeSha256((bytes) => digest(CryptoDigestAlgorithm.SHA256, bytes));
|
|
|
22
22
|
const geolocationOf = (options) => options.geolocation === false ? void 0 : options.geolocation ?? createExpoGeolocation();
|
|
23
23
|
const make = Effect.fn("ExpoRuntime.make")(function* (options = {}) {
|
|
24
24
|
const { owner, namespace } = yield* RuntimePartition;
|
|
25
|
-
const
|
|
25
|
+
const links = yield* makeExpoNetworkLinks();
|
|
26
26
|
if (options.storage === "memory") {
|
|
27
27
|
const materials = /* @__PURE__ */ new Map();
|
|
28
28
|
return yield* Runtime.make({
|
|
@@ -39,7 +39,7 @@ const make = Effect.fn("ExpoRuntime.make")(function* (options = {}) {
|
|
|
39
39
|
}, nativeKeyCodec),
|
|
40
40
|
browserAuthentication: createExpoBrowserAuthentication(),
|
|
41
41
|
geolocation: geolocationOf(options),
|
|
42
|
-
|
|
42
|
+
links,
|
|
43
43
|
capacity: {
|
|
44
44
|
memory: Effect.succeed(void 0),
|
|
45
45
|
storage: Effect.succeed(void 0)
|
|
@@ -103,7 +103,7 @@ const make = Effect.fn("ExpoRuntime.make")(function* (options = {}) {
|
|
|
103
103
|
browserAuthentication: createExpoBrowserAuthentication(),
|
|
104
104
|
geolocation: geolocationOf(options),
|
|
105
105
|
encryptionKeyring,
|
|
106
|
-
|
|
106
|
+
links,
|
|
107
107
|
tables: ownedTables,
|
|
108
108
|
destroy: Effect.tryPromise({
|
|
109
109
|
try: async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExpoRuntime.js","names":[],"sources":["../src/createExpoRuntime.ts"],"sourcesContent":["import { configureNativeSha256 } from \"@party-stack/ontology-storage/blobs\";\nimport { storageError } from \"@party-stack/ontology-storage/driver\";\nimport * as MemoryTables from \"@party-stack/ontology-storage/memory/tables\";\nimport { Runtime, RuntimeError, RuntimePartition, makeKeyMaterialStoreKeyring } from \"@party-stack/runtime\";\nimport { Runtimes, MemoryBlobBytesStore, type KeyMaterialStore } from \"@party-stack/runtime\";\nimport * as SQLite from \"@party-stack/sql-ontology-storage/sqlite\";\nimport * as SqlTables from \"@party-stack/sql-ontology-storage/tables\";\nimport { Effect, Layer, Schema } from \"effect\";\nimport * as Reactivity from \"effect/reactivity/Reactivity\";\nimport * as SqlClient from \"effect/sql/SqlClient\";\nimport { CryptoDigestAlgorithm, digest } from \"expo-crypto\";\nimport { Paths } from \"expo-file-system\";\nimport { deleteDatabaseAsync, openDatabaseAsync } from \"expo-sqlite\";\nimport { createExpoBrowserAuthentication } from \"./createExpoBrowserAuthentication.js\";\nimport { createExpoGeolocation } from \"./createExpoGeolocation.js\";\nimport { nativeKeyCodec } from \"./encryptionKeys.js\";\nimport { ExpoFileSystemBlobBytesStore } from \"./ExpoFileSystemBlobBytesStore.js\";\nimport { makeKeyMaterialStore } from \"./ExpoKeyMaterialStore.js\";\nimport { makeExpoNetworkConnectivity } from \"./ExpoNetworkConnectivity.js\";\nimport { hashStorageName } from \"./hashStorageName.js\";\nimport type { Geolocation } from \"@party-stack/runtime\";\nimport type { SQLiteBindValue } from \"expo-sqlite\";\n\n// Content digests use the platform SHA-256; portable JavaScript hashing costs\n// hundreds of milliseconds per MiB on Hermes. Bounded inputs only; see digestBytes.\nconfigureNativeSha256((bytes) => digest(CryptoDigestAlgorithm.SHA256, bytes));\n\nexport interface ExpoRuntimeOptions {\n /** Persistent SQLite/filesystem storage by default; memory keeps native platform capabilities. */\n readonly storage?: \"persistent\" | \"memory\";\n /** Device location through expo-location by default. Permission is requested on\n * first use; add expo-location's config plugin for the platform purpose strings.\n * Pass `false` for none. */\n readonly geolocation?: Geolocation | false;\n}\n\nconst geolocationOf = (options: ExpoRuntimeOptions) =>\n options.geolocation === false ? undefined : (options.geolocation ?? createExpoGeolocation());\n\nexport const make = Effect.fn(\"ExpoRuntime.make\")(function* (options: ExpoRuntimeOptions = {}) {\n const { owner, namespace } = yield* RuntimePartition;\n const connectivity = yield* makeExpoNetworkConnectivity();\n if (options.storage === \"memory\") {\n const materials = new Map<string, string>();\n const secrets: KeyMaterialStore = {\n get: (id) => Effect.sync(() => materials.get(id)),\n set: (id, value) =>\n Effect.sync(() => {\n materials.set(id, value);\n }),\n delete: (id) =>\n Effect.sync(() => {\n materials.delete(id);\n }),\n };\n return yield* Runtime.make({\n tables: yield* MemoryTables.make(),\n blobBytes: new MemoryBlobBytesStore(),\n encryptionKeyring: yield* makeKeyMaterialStoreKeyring(secrets, nativeKeyCodec),\n browserAuthentication: createExpoBrowserAuthentication(),\n geolocation: geolocationOf(options),\n connectivity,\n capacity: { memory: Effect.succeed(undefined), storage: Effect.succeed(undefined) },\n });\n }\n const name = `party-stack:${owner}:${namespace}`;\n const storageName = `party-stack-${yield* Effect.tryPromise({ try: () => hashStorageName(JSON.stringify([owner, namespace])), catch: (cause) => new RuntimeError({ operation: \"expoRuntime.name\", cause }) })}`;\n const blobBytes = new ExpoFileSystemBlobBytesStore({\n directoryName: `${storageName}-blobs`,\n });\n const tables = Effect.gen(function* () {\n const database = yield* Effect.acquireRelease(\n Effect.tryPromise({\n try: () => openDatabaseAsync(`${storageName}-storage.db`),\n catch: (cause) => storageError(\"sql\", \"open\", cause),\n }),\n (database) => Effect.promise(() => database.closeAsync())\n );\n let active = database;\n const sql = yield* SQLite.makeClient({\n exec: (query) => active.execSync(query),\n prepare: (query) => ({\n all: (...values) => active.getAllSync(query, values as SQLiteBindValue[]),\n run: (...values) => active.runSync(query, values as SQLiteBindValue[]),\n }),\n transactionAsync: <A>(body: () => Promise<A>) => {\n let value: A;\n return database\n .withExclusiveTransactionAsync(async (tx) => {\n active = tx;\n try {\n value = await body();\n } finally {\n active = database;\n }\n })\n .then(() => value);\n },\n }).pipe(\n Effect.provide(Reactivity.layer),\n Effect.mapError((cause) => storageError(\"sql\", \"open\", cause))\n );\n return yield* SqlTables.make().pipe(Effect.provideService(SqlClient.SqlClient, sql));\n });\n const secrets = makeKeyMaterialStore(`${name}:secrets`);\n const ownedTables = yield* tables;\n const encryptionKeyring = yield* makeKeyMaterialStoreKeyring(secrets, nativeKeyCodec);\n return yield* Runtime.make({\n blobBytes,\n capacity: {\n memory: Effect.succeed(undefined),\n storage: Effect.try({\n try: () => ({\n scope: \"filesystem\" as const,\n limitBytes: Paths.totalDiskSpace,\n availableBytes: Paths.availableDiskSpace,\n }),\n catch: (cause) => new RuntimeError({ operation: \"capacity.storage\", cause }),\n }),\n },\n browserAuthentication: createExpoBrowserAuthentication(),\n geolocation: geolocationOf(options),\n encryptionKeyring,\n connectivity,\n\n tables: ownedTables,\n destroy: Effect.tryPromise({\n try: async () => {\n await Promise.all([\n deleteDatabaseAsync(`${storageName}-storage.db`).catch((cause) => {\n if (\n !Schema.is(Schema.Struct({ code: Schema.Literal(\"ERR_DATABASE_NOT_FOUND\") }))(\n cause\n )\n )\n throw cause;\n }),\n Effect.runPromise(blobBytes.clear()),\n ]);\n },\n catch: (cause) => new RuntimeError({ operation: \"destroy\", cause }),\n }),\n });\n});\nexport const layer = (options: ExpoRuntimeOptions = {}) => Layer.effect(Runtime, make(options));\nexport const expoRuntime = (options: ExpoRuntimeOptions = {}) =>\n Runtimes.layer(layer(options), {\n browserAuthentication: createExpoBrowserAuthentication(),\n geolocation: geolocationOf(options),\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA,uBAAuB,UAAU,OAAO,sBAAsB,QAAQ,KAAK,CAAC;AAW5E,MAAM,iBAAiB,YACnB,QAAQ,gBAAgB,QAAQ,KAAA,IAAa,QAAQ,eAAe,sBAAsB;AAE9F,MAAa,OAAO,OAAO,GAAG,kBAAkB,CAAC,CAAC,WAAW,UAA8B,CAAC,GAAG;CAC3F,MAAM,EAAE,OAAO,cAAc,OAAO;CACpC,MAAM,eAAe,OAAO,4BAA4B;CACxD,IAAI,QAAQ,YAAY,UAAU;EAC9B,MAAM,4BAAY,IAAI,IAAoB;EAY1C,OAAO,OAAO,QAAQ,KAAK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,MAAM,OAAO,SAAS,KAAK,OAAO,CAAC;AAC9F,MAAa,eAAe,UAA8B,CAAC,MACvD,SAAS,MAAM,MAAM,OAAO,GAAG;CAC3B,uBAAuB,gCAAgC;CACvD,aAAa,cAAc,OAAO;AACtC,CAAC"}
|
|
1
|
+
{"version":3,"file":"createExpoRuntime.js","names":[],"sources":["../src/createExpoRuntime.ts"],"sourcesContent":["import { configureNativeSha256 } from \"@party-stack/ontology-storage/blobs\";\nimport { storageError } from \"@party-stack/ontology-storage/driver\";\nimport * as MemoryTables from \"@party-stack/ontology-storage/memory/tables\";\nimport { Runtime, RuntimeError, RuntimePartition, makeKeyMaterialStoreKeyring } from \"@party-stack/runtime\";\nimport { Runtimes, MemoryBlobBytesStore, type KeyMaterialStore } from \"@party-stack/runtime\";\nimport * as SQLite from \"@party-stack/sql-ontology-storage/sqlite\";\nimport * as SqlTables from \"@party-stack/sql-ontology-storage/tables\";\nimport { Effect, Layer, Schema } from \"effect\";\nimport * as Reactivity from \"effect/reactivity/Reactivity\";\nimport * as SqlClient from \"effect/sql/SqlClient\";\nimport { CryptoDigestAlgorithm, digest } from \"expo-crypto\";\nimport { Paths } from \"expo-file-system\";\nimport { deleteDatabaseAsync, openDatabaseAsync } from \"expo-sqlite\";\nimport { createExpoBrowserAuthentication } from \"./createExpoBrowserAuthentication.js\";\nimport { createExpoGeolocation } from \"./createExpoGeolocation.js\";\nimport { nativeKeyCodec } from \"./encryptionKeys.js\";\nimport { ExpoFileSystemBlobBytesStore } from \"./ExpoFileSystemBlobBytesStore.js\";\nimport { makeKeyMaterialStore } from \"./ExpoKeyMaterialStore.js\";\nimport { makeExpoNetworkLinks } from \"./ExpoNetworkConnectivity.js\";\nimport { hashStorageName } from \"./hashStorageName.js\";\nimport type { Geolocation } from \"@party-stack/runtime\";\nimport type { SQLiteBindValue } from \"expo-sqlite\";\n\n// Content digests use the platform SHA-256; portable JavaScript hashing costs\n// hundreds of milliseconds per MiB on Hermes. Bounded inputs only; see digestBytes.\nconfigureNativeSha256((bytes) => digest(CryptoDigestAlgorithm.SHA256, bytes));\n\nexport interface ExpoRuntimeOptions {\n /** Persistent SQLite/filesystem storage by default; memory keeps native platform capabilities. */\n readonly storage?: \"persistent\" | \"memory\";\n /** Device location through expo-location by default. Permission is requested on\n * first use; add expo-location's config plugin for the platform purpose strings.\n * Pass `false` for none. */\n readonly geolocation?: Geolocation | false;\n}\n\nconst geolocationOf = (options: ExpoRuntimeOptions) =>\n options.geolocation === false ? undefined : (options.geolocation ?? createExpoGeolocation());\n\nexport const make = Effect.fn(\"ExpoRuntime.make\")(function* (options: ExpoRuntimeOptions = {}) {\n const { owner, namespace } = yield* RuntimePartition;\n const links = yield* makeExpoNetworkLinks();\n if (options.storage === \"memory\") {\n const materials = new Map<string, string>();\n const secrets: KeyMaterialStore = {\n get: (id) => Effect.sync(() => materials.get(id)),\n set: (id, value) =>\n Effect.sync(() => {\n materials.set(id, value);\n }),\n delete: (id) =>\n Effect.sync(() => {\n materials.delete(id);\n }),\n };\n return yield* Runtime.make({\n tables: yield* MemoryTables.make(),\n blobBytes: new MemoryBlobBytesStore(),\n encryptionKeyring: yield* makeKeyMaterialStoreKeyring(secrets, nativeKeyCodec),\n browserAuthentication: createExpoBrowserAuthentication(),\n geolocation: geolocationOf(options),\n links,\n capacity: { memory: Effect.succeed(undefined), storage: Effect.succeed(undefined) },\n });\n }\n const name = `party-stack:${owner}:${namespace}`;\n const storageName = `party-stack-${yield* Effect.tryPromise({ try: () => hashStorageName(JSON.stringify([owner, namespace])), catch: (cause) => new RuntimeError({ operation: \"expoRuntime.name\", cause }) })}`;\n const blobBytes = new ExpoFileSystemBlobBytesStore({\n directoryName: `${storageName}-blobs`,\n });\n const tables = Effect.gen(function* () {\n const database = yield* Effect.acquireRelease(\n Effect.tryPromise({\n try: () => openDatabaseAsync(`${storageName}-storage.db`),\n catch: (cause) => storageError(\"sql\", \"open\", cause),\n }),\n (database) => Effect.promise(() => database.closeAsync())\n );\n let active = database;\n const sql = yield* SQLite.makeClient({\n exec: (query) => active.execSync(query),\n prepare: (query) => ({\n all: (...values) => active.getAllSync(query, values as SQLiteBindValue[]),\n run: (...values) => active.runSync(query, values as SQLiteBindValue[]),\n }),\n transactionAsync: <A>(body: () => Promise<A>) => {\n let value: A;\n return database\n .withExclusiveTransactionAsync(async (tx) => {\n active = tx;\n try {\n value = await body();\n } finally {\n active = database;\n }\n })\n .then(() => value);\n },\n }).pipe(\n Effect.provide(Reactivity.layer),\n Effect.mapError((cause) => storageError(\"sql\", \"open\", cause))\n );\n return yield* SqlTables.make().pipe(Effect.provideService(SqlClient.SqlClient, sql));\n });\n const secrets = makeKeyMaterialStore(`${name}:secrets`);\n const ownedTables = yield* tables;\n const encryptionKeyring = yield* makeKeyMaterialStoreKeyring(secrets, nativeKeyCodec);\n return yield* Runtime.make({\n blobBytes,\n capacity: {\n memory: Effect.succeed(undefined),\n storage: Effect.try({\n try: () => ({\n scope: \"filesystem\" as const,\n limitBytes: Paths.totalDiskSpace,\n availableBytes: Paths.availableDiskSpace,\n }),\n catch: (cause) => new RuntimeError({ operation: \"capacity.storage\", cause }),\n }),\n },\n browserAuthentication: createExpoBrowserAuthentication(),\n geolocation: geolocationOf(options),\n encryptionKeyring,\n links,\n\n tables: ownedTables,\n destroy: Effect.tryPromise({\n try: async () => {\n await Promise.all([\n deleteDatabaseAsync(`${storageName}-storage.db`).catch((cause) => {\n if (\n !Schema.is(Schema.Struct({ code: Schema.Literal(\"ERR_DATABASE_NOT_FOUND\") }))(\n cause\n )\n )\n throw cause;\n }),\n Effect.runPromise(blobBytes.clear()),\n ]);\n },\n catch: (cause) => new RuntimeError({ operation: \"destroy\", cause }),\n }),\n });\n});\nexport const layer = (options: ExpoRuntimeOptions = {}) => Layer.effect(Runtime, make(options));\nexport const expoRuntime = (options: ExpoRuntimeOptions = {}) =>\n Runtimes.layer(layer(options), {\n browserAuthentication: createExpoBrowserAuthentication(),\n geolocation: geolocationOf(options),\n });\n"],"mappings":";;;;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AK,YAAY;IACb,MAAM,QAAQ,IAAI,CACd,oBAAoB,GAAG,YAAY,YAAY,CAAC,CAAC,OAAO,UAAU;KAC9D,IACI,CAAC,OAAO,GAAG,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,wBAAwB,EAAE,CAAC,CAAC,CAAC,CACzE,KACJ,GAEA,MAAM;IACd,CAAC,GACD,OAAO,WAAW,UAAU,MAAM,CAAC,CACvC,CAAC;GACL;GACA,QAAQ,UAAU,IAAI,aAAa;IAAE,WAAW;IAAW;GAAM,CAAC;EACtE,CAAC;CACL,CAAC;AACL,CAAC;AACD,MAAa,SAAS,UAA8B,CAAC,MAAM,MAAM,OAAO,SAAS,KAAK,OAAO,CAAC;AAC9F,MAAa,eAAe,UAA8B,CAAC,MACvD,SAAS,MAAM,MAAM,OAAO,GAAG;CAC3B,uBAAuB,gCAAgC;CACvD,aAAa,cAAc,OAAO;AACtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@party-stack/expo-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"plugin"
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"expo-secure-store": "^57.0.4",
|
|
32
32
|
"expo-web-browser": "^57.0.3",
|
|
33
33
|
"temporal-polyfill": "^0.3.0",
|
|
34
|
-
"@party-stack/ontology-storage": "0.
|
|
35
|
-
"@party-stack/runtime": "0.
|
|
36
|
-
"@party-stack/sql-ontology-storage": "0.3.
|
|
34
|
+
"@party-stack/ontology-storage": "0.4.1",
|
|
35
|
+
"@party-stack/runtime": "0.7.0",
|
|
36
|
+
"@party-stack/sql-ontology-storage": "0.3.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@react-native-community/netinfo": "^12.0.1",
|