@effect-native/libcrsql 0.16.300 → 0.16.303
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/README.md +42 -1
- package/dist/cjs/effect.js +92 -0
- package/dist/cjs/effect.js.map +1 -0
- package/dist/dts/effect.d.ts +74 -0
- package/dist/dts/effect.d.ts.map +1 -0
- package/dist/esm/effect.js +81 -0
- package/dist/esm/effect.js.map +1 -0
- package/dist/lib/darwin-aarch64/libcrsqlite.dylib +0 -0
- package/dist/lib/darwin-x86_64/libcrsqlite.dylib +0 -0
- package/dist/lib/linux-aarch64/libcrsqlite.so +0 -0
- package/dist/lib/linux-x86_64/libcrsqlite.so +0 -0
- package/dist/lib/win-i686/crsqlite.dll +0 -0
- package/dist/lib/win-x86_64/crsqlite.dll +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ db.loadExtension(pathToCrSqliteExtension)
|
|
|
24
24
|
## Absolute constants (no side effects)
|
|
25
25
|
|
|
26
26
|
import { linux_x86_64 } from "@effect-native/libcrsql/paths"
|
|
27
|
-
// linux_x86_64 is an absolute string like
|
|
27
|
+
// linux_x86_64 is an absolute string like
|
|
28
28
|
// /.../node_modules/@effect-native/libcrsql/lib/linux-x86_64/libcrsqlite.so
|
|
29
29
|
|
|
30
30
|
## Effect entrypoint (optional)
|
|
@@ -63,3 +63,44 @@ Run a local integrity check to verify bundled binaries match the expected SHA256
|
|
|
63
63
|
```
|
|
64
64
|
pnpm --filter @effect-native/libcrsql run verify
|
|
65
65
|
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
# Example: Embed and use libsqlite and crsqlite in a compiled Bun single file executable
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
73
|
+
// GOAL: embed and use libsqlite and crsqlite in a compiled Bun single file executable
|
|
74
|
+
|
|
75
|
+
import { Database } from "bun:sqlite"
|
|
76
|
+
|
|
77
|
+
import { getCrSqliteExtensionPathSync } from "@effect-native/libcrsql" with { type: "macro" }
|
|
78
|
+
import { getLibSqlitePathSync } from "@effect-native/libsqlite" with { type: "macro" }
|
|
79
|
+
|
|
80
|
+
const embeddedLibSqlitePath = String(require(getLibSqlitePathSync()))
|
|
81
|
+
const embeddedCrSqliteExtensionPath = String(require(getCrSqliteExtensionPathSync()))
|
|
82
|
+
|
|
83
|
+
if (Bun.embeddedFiles.length) {
|
|
84
|
+
const embeddedLibSqliteFile = Bun.file(embeddedLibSqlitePath)
|
|
85
|
+
const exportedLibSqlitePath = `./.${embeddedLibSqliteFile.name}`
|
|
86
|
+
Bun.write(exportedLibSqlitePath, embeddedLibSqliteFile)
|
|
87
|
+
Database.setCustomSQLite(exportedLibSqlitePath)
|
|
88
|
+
} else {
|
|
89
|
+
Database.setCustomSQLite(embeddedLibSqlitePath)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const db = new Database(":memory:")
|
|
93
|
+
console.log("LibSqlite loaded successfully?", db.query("SELECT sqlite_version() AS sqliteVersion").get())
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
db.loadExtension(embeddedCrSqliteExtensionPath, "sqlite3_crsqlite_init")
|
|
97
|
+
} catch (cause) {
|
|
98
|
+
if (!String(cause).includes("no such file")) throw cause
|
|
99
|
+
const embeddedCrSqliteExtensionFile = Bun.file(embeddedCrSqliteExtensionPath)
|
|
100
|
+
const exportedCrSqliteExtensionPath = `./.${embeddedCrSqliteExtensionFile.name}`
|
|
101
|
+
Bun.write(exportedCrSqliteExtensionPath, embeddedCrSqliteExtensionFile)
|
|
102
|
+
db.loadExtension(exportedCrSqliteExtensionPath, "sqlite3_crsqlite_init")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log("CRSQLite extension loaded successfully?", db.query("SELECT hex(crsql_site_id()) AS siteId").get())
|
|
106
|
+
```
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getCrSqliteExtensionPath = exports.SUPPORTED_PLATFORMS = exports.PlatformNotSupportedError = exports.ExtensionPath = exports.ExtensionNotFoundError = void 0;
|
|
7
|
+
var _effect = require("effect");
|
|
8
|
+
var fs = _interopRequireWildcard(require("node:fs"));
|
|
9
|
+
var _nodeUrl = require("node:url");
|
|
10
|
+
var _platform = require("./platform.js");
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
|
+
/**
|
|
13
|
+
* Effect entrypoint: idiomatic Effect API with TaggedError failures.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.16.300
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Error indicating that a platform-arch combination is not supported.
|
|
20
|
+
* @since 0.16.300
|
|
21
|
+
*/
|
|
22
|
+
class PlatformNotSupportedError extends /*#__PURE__*/_effect.Data.TaggedError("PlatformNotSupportedError") {
|
|
23
|
+
/**
|
|
24
|
+
* @since 0.16.300
|
|
25
|
+
*/
|
|
26
|
+
get message() {
|
|
27
|
+
return `Platform "${this.platform}" is not supported. Detected: ${this.detectedPlatform}-${this.detectedArch}. Supported: ${this.supportedPlatforms.join(", ")}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Error indicating that the resolved binary path does not exist.
|
|
32
|
+
* @since 0.16.300
|
|
33
|
+
*/
|
|
34
|
+
exports.PlatformNotSupportedError = PlatformNotSupportedError;
|
|
35
|
+
class ExtensionNotFoundError extends /*#__PURE__*/_effect.Data.TaggedError("ExtensionNotFoundError") {}
|
|
36
|
+
/**
|
|
37
|
+
* Brand constructor for `ExtensionPath`.
|
|
38
|
+
* @since 0.16.300
|
|
39
|
+
*/
|
|
40
|
+
exports.ExtensionNotFoundError = ExtensionNotFoundError;
|
|
41
|
+
const ExtensionPath = exports.ExtensionPath = /*#__PURE__*/_effect.Brand.nominal();
|
|
42
|
+
// Uses a best-effort Node fs sync check without depending on @effect/platform.
|
|
43
|
+
/**
|
|
44
|
+
* Effect-based absolute path resolution with idiomatic TaggedError failures.
|
|
45
|
+
*
|
|
46
|
+
* - Succeeds with a branded `ExtensionPath` string.
|
|
47
|
+
* - Fails with `PlatformNotSupportedError` or `ExtensionNotFoundError`.
|
|
48
|
+
*
|
|
49
|
+
* @since 0.16.300
|
|
50
|
+
* @example
|
|
51
|
+
* import { getCrSqliteExtensionPath } from "@effect-native/libcrsql/effect"
|
|
52
|
+
* import { Effect } from "effect"
|
|
53
|
+
*
|
|
54
|
+
* const program = getCrSqliteExtensionPath()
|
|
55
|
+
* Effect.runPromise(program)
|
|
56
|
+
*/
|
|
57
|
+
const getCrSqliteExtensionPath = platform => _effect.Effect.gen(function* () {
|
|
58
|
+
const target = platform ?? (0, _platform.detectPlatform)();
|
|
59
|
+
if (!(0, _platform.isSupportedPlatform)(target)) {
|
|
60
|
+
return yield* _effect.Effect.fail(new PlatformNotSupportedError({
|
|
61
|
+
platform: target,
|
|
62
|
+
supportedPlatforms: SUPPORTED_PLATFORMS,
|
|
63
|
+
detectedArch: process.arch,
|
|
64
|
+
detectedPlatform: process.platform
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
const abs = (0, _nodeUrl.fileURLToPath)(new URL(`../${(0, _platform.buildRelativeLibraryPath)(target)}`, import.meta.url));
|
|
68
|
+
const exists = yield* _effect.Effect.sync(() => {
|
|
69
|
+
try {
|
|
70
|
+
// Synchronous check is acceptable here since this path is computed
|
|
71
|
+
// infrequently and typically only once per process.
|
|
72
|
+
fs.accessSync(abs);
|
|
73
|
+
return true;
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (!exists) {
|
|
79
|
+
return yield* _effect.Effect.fail(new ExtensionNotFoundError({
|
|
80
|
+
path: abs,
|
|
81
|
+
platform: target
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
return ExtensionPath(abs);
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* List of supported platforms.
|
|
88
|
+
* @since 0.16.300
|
|
89
|
+
*/
|
|
90
|
+
exports.getCrSqliteExtensionPath = getCrSqliteExtensionPath;
|
|
91
|
+
const SUPPORTED_PLATFORMS = exports.SUPPORTED_PLATFORMS = _platform.SUPPORTED_PLATFORMS;
|
|
92
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect.js","names":["_effect","require","fs","_interopRequireWildcard","_nodeUrl","_platform","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","PlatformNotSupportedError","Data","TaggedError","message","platform","detectedPlatform","detectedArch","supportedPlatforms","join","exports","ExtensionNotFoundError","ExtensionPath","Brand","nominal","getCrSqliteExtensionPath","Effect","gen","target","detectPlatform","isSupportedPlatform","fail","SUPPORTED_PLATFORMS","process","arch","abs","fileURLToPath","URL","buildRelativeLibraryPath","import","meta","url","exists","sync","accessSync","path","_SUPPORTED_PLATFORMS"],"sources":["../../src/effect.ts"],"sourcesContent":[null],"mappings":";;;;;;AAKA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,EAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IA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AAEpB,QAAQ,EAAEa;IAAM,CAAE,CAAC,CAAC;EACxF;EAEA,OAAON,aAAa,CAACa,GAAG,CAAC;AAC3B,CAAC,CAAC;AAQJ;;;;AAAAf,OAAA,CAAAK,wBAAA,GAAAA,wBAAA;AAIO,MAAMO,mBAAmB,GAAAZ,OAAA,CAAAY,mBAAA,GAAGc,6BAAoB","ignoreList":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effect entrypoint: idiomatic Effect API with TaggedError failures.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.16.300
|
|
5
|
+
*/
|
|
6
|
+
import { Brand, Effect } from "effect";
|
|
7
|
+
import type { Platform as _Platform } from "./platform.js";
|
|
8
|
+
declare const PlatformNotSupportedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
9
|
+
readonly _tag: "PlatformNotSupportedError";
|
|
10
|
+
} & Readonly<A>;
|
|
11
|
+
/**
|
|
12
|
+
* Error indicating that a platform-arch combination is not supported.
|
|
13
|
+
* @since 0.16.300
|
|
14
|
+
*/
|
|
15
|
+
export declare class PlatformNotSupportedError extends PlatformNotSupportedError_base<{
|
|
16
|
+
readonly platform: string;
|
|
17
|
+
readonly supportedPlatforms: ReadonlyArray<string>;
|
|
18
|
+
readonly detectedArch: string;
|
|
19
|
+
readonly detectedPlatform: string;
|
|
20
|
+
}> {
|
|
21
|
+
/**
|
|
22
|
+
* @since 0.16.300
|
|
23
|
+
*/
|
|
24
|
+
get message(): string;
|
|
25
|
+
}
|
|
26
|
+
declare const ExtensionNotFoundError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
27
|
+
readonly _tag: "ExtensionNotFoundError";
|
|
28
|
+
} & Readonly<A>;
|
|
29
|
+
/**
|
|
30
|
+
* Error indicating that the resolved binary path does not exist.
|
|
31
|
+
* @since 0.16.300
|
|
32
|
+
*/
|
|
33
|
+
export declare class ExtensionNotFoundError extends ExtensionNotFoundError_base<{
|
|
34
|
+
readonly path: string;
|
|
35
|
+
readonly platform: string;
|
|
36
|
+
}> {
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Branded absolute path to the cr-sqlite binary.
|
|
40
|
+
* @since 0.16.300
|
|
41
|
+
*/
|
|
42
|
+
export type ExtensionPath = string & Brand.Brand<"ExtensionPath">;
|
|
43
|
+
/**
|
|
44
|
+
* Brand constructor for `ExtensionPath`.
|
|
45
|
+
* @since 0.16.300
|
|
46
|
+
*/
|
|
47
|
+
export declare const ExtensionPath: Brand.Brand.Constructor<ExtensionPath>;
|
|
48
|
+
/**
|
|
49
|
+
* Effect-based absolute path resolution with idiomatic TaggedError failures.
|
|
50
|
+
*
|
|
51
|
+
* - Succeeds with a branded `ExtensionPath` string.
|
|
52
|
+
* - Fails with `PlatformNotSupportedError` or `ExtensionNotFoundError`.
|
|
53
|
+
*
|
|
54
|
+
* @since 0.16.300
|
|
55
|
+
* @example
|
|
56
|
+
* import { getCrSqliteExtensionPath } from "@effect-native/libcrsql/effect"
|
|
57
|
+
* import { Effect } from "effect"
|
|
58
|
+
*
|
|
59
|
+
* const program = getCrSqliteExtensionPath()
|
|
60
|
+
* Effect.runPromise(program)
|
|
61
|
+
*/
|
|
62
|
+
export declare const getCrSqliteExtensionPath: (platform?: Platform) => Effect.Effect<ExtensionPath, PlatformNotSupportedError | ExtensionNotFoundError>;
|
|
63
|
+
/**
|
|
64
|
+
* Supported platform-arch identifiers.
|
|
65
|
+
* @since 0.16.300
|
|
66
|
+
*/
|
|
67
|
+
export type Platform = _Platform;
|
|
68
|
+
/**
|
|
69
|
+
* List of supported platforms.
|
|
70
|
+
* @since 0.16.300
|
|
71
|
+
*/
|
|
72
|
+
export declare const SUPPORTED_PLATF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
|
+
/**
|
|
2
|
+
* Effect entrypoint: idiomatic Effect API with TaggedError failures.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.16.300
|
|
5
|
+
*/
|
|
6
|
+
import { Brand, Data, Effect } from "effect";
|
|
7
|
+
import * as fs from "node:fs";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { buildRelativeLibraryPath, detectPlatform, isSupportedPlatform, SUPPORTED_PLATFORMS as _SUPPORTED_PLATFORMS } from "./platform.js";
|
|
10
|
+
/**
|
|
11
|
+
* Error indicating that a platform-arch combination is not supported.
|
|
12
|
+
* @since 0.16.300
|
|
13
|
+
*/
|
|
14
|
+
export class PlatformNotSupportedError extends /*#__PURE__*/Data.TaggedError("PlatformNotSupportedError") {
|
|
15
|
+
/**
|
|
16
|
+
* @since 0.16.300
|
|
17
|
+
*/
|
|
18
|
+
get message() {
|
|
19
|
+
return `Platform "${this.platform}" is not supported. Detected: ${this.detectedPlatform}-${this.detectedArch}. Supported: ${this.supportedPlatforms.join(", ")}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error indicating that the resolved binary path does not exist.
|
|
24
|
+
* @since 0.16.300
|
|
25
|
+
*/
|
|
26
|
+
export class ExtensionNotFoundError extends /*#__PURE__*/Data.TaggedError("ExtensionNotFoundError") {}
|
|
27
|
+
/**
|
|
28
|
+
* Brand constructor for `ExtensionPath`.
|
|
29
|
+
* @since 0.16.300
|
|
30
|
+
*/
|
|
31
|
+
export const ExtensionPath = /*#__PURE__*/Brand.nominal();
|
|
32
|
+
// Uses a best-effort Node fs sync check without depending on @effect/platform.
|
|
33
|
+
/**
|
|
34
|
+
* Effect-based absolute path resolution with idiomatic TaggedError failures.
|
|
35
|
+
*
|
|
36
|
+
* - Succeeds with a branded `ExtensionPath` string.
|
|
37
|
+
* - Fails with `PlatformNotSupportedError` or `ExtensionNotFoundError`.
|
|
38
|
+
*
|
|
39
|
+
* @since 0.16.300
|
|
40
|
+
* @example
|
|
41
|
+
* import { getCrSqliteExtensionPath } from "@effect-native/libcrsql/effect"
|
|
42
|
+
* import { Effect } from "effect"
|
|
43
|
+
*
|
|
44
|
+
* const program = getCrSqliteExtensionPath()
|
|
45
|
+
* Effect.runPromise(program)
|
|
46
|
+
*/
|
|
47
|
+
export const getCrSqliteExtensionPath = platform => Effect.gen(function* () {
|
|
48
|
+
const target = platform ?? detectPlatform();
|
|
49
|
+
if (!isSupportedPlatform(target)) {
|
|
50
|
+
return yield* Effect.fail(new PlatformNotSupportedError({
|
|
51
|
+
platform: target,
|
|
52
|
+
supportedPlatforms: SUPPORTED_PLATFORMS,
|
|
53
|
+
detectedArch: process.arch,
|
|
54
|
+
detectedPlatform: process.platform
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
const abs = fileURLToPath(new URL(`../${buildRelativeLibraryPath(target)}`, import.meta.url));
|
|
58
|
+
const exists = yield* Effect.sync(() => {
|
|
59
|
+
try {
|
|
60
|
+
// Synchronous check is acceptable here since this path is computed
|
|
61
|
+
// infrequently and typically only once per process.
|
|
62
|
+
fs.accessSync(abs);
|
|
63
|
+
return true;
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (!exists) {
|
|
69
|
+
return yield* Effect.fail(new ExtensionNotFoundError({
|
|
70
|
+
path: abs,
|
|
71
|
+
platform: target
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
return ExtensionPath(abs);
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* List of supported platforms.
|
|
78
|
+
* @since 0.16.300
|
|
79
|
+
*/
|
|
80
|
+
export const SUPPORTED_PLATFORMS = _SUPPORTED_PLATFORMS;
|
|
81
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect.js","names":["Brand","Data","Effect","fs","fileURLToPath","buildRelativeLibraryPath","detectPlatform","isSupportedPlatform","SUPPORTED_PLATFORMS","_SUPPORTED_PLATFORMS","PlatformNotSupportedError","TaggedError","message","platform","detectedPlatform","detectedArch","supportedPlatforms","join","ExtensionNotFoundError","ExtensionPath","nominal","getCrSqliteExtensionPath","gen","target","fail","process","arch","abs","URL","import","meta","url","exists","sync","accessSync","path"],"sources":["../../src/effect.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,SAASA,KAAK,EAAEC,IAAI,EAAEC,MAAM,QAAQ,QAAQ;AAC5C,OAAO,KAAKC,EAAE,MAAM,SAAS;AAC7B,SAASC,aAAa,QAAQ,UAAU;AACxC,SACEC,wBAAwB,EACxBC,cAAc,EACdC,mBAAmB,EACnBC,mBAAmB,IAAIC,oBAAoB,QACtC,eAAe;AAGtB;;;;AAIA,OAAM,MAAOC,yBAA0B,sBAAQT,IAAI,CAACU,WAAW,CAAC,2BAA2B,CAKzF;EACA;;;EAGA,IAAIC,OAAOA,CAAA;IACT,OAAO,aAAa,IAAI,CAACC,QAAQ,iCAAiC,IAAI,CAACC,gBAAgB,IAAI,IAAI,CAACC,YAAY,gBAC1G,IAAI,CAACC,kBAAkB,CAACC,IAAI,CAAC,IAAI,CACnC,EAAE;EACJ;;AAGF;;;;AAIA,OAAM,MAAOC,sBAAuB,sBAAQjB,IAAI,CAACU,WAAW,CAAC,wBAAwB,CAGnF;AAOF;;;;AAIA,OAAO,MAAMQ,aAAa,gBAAGnB,KAAK,CAACoB,OAAO,EAAiB;AAE3D;AACA;;;;;;;;;;;;;;AAcA,OAAO,MAAMC,wBAAwB,GACnCR,QAAmB,IAEnBX,MAAM,CAACoB,GAAG,CAAC,aAAS;EAClB,MAAMC,MAAM,GAAGV,QAAQ,IAAIP,cAAc,EAAE;EAC3C,IAAI,CAACC,mBAAmB,CAACgB,MAAM,CAAC,EAAE;IAChC,OAAO,OAAOrB,MAAM,CAACsB,IAAI,CACvB,IAAId,yBAAyB,CAAC;MAC5BG,QAAQ,EAAEU,MAAM;MAChBP,kBAAkB,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