@lionden/config 0.1.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/LICENSE +201 -0
- package/README.md +23 -0
- package/dist/aleo-address.d.ts +17 -0
- package/dist/aleo-address.d.ts.map +1 -0
- package/dist/aleo-address.js +21 -0
- package/dist/aleo-address.js.map +1 -0
- package/dist/config-variable.d.ts +25 -0
- package/dist/config-variable.d.ts.map +1 -0
- package/dist/config-variable.js +22 -0
- package/dist/config-variable.js.map +1 -0
- package/dist/declaration-merging.d.ts +23 -0
- package/dist/declaration-merging.d.ts.map +1 -0
- package/dist/declaration-merging.js +20 -0
- package/dist/declaration-merging.js.map +1 -0
- package/dist/define-config.d.ts +22 -0
- package/dist/define-config.d.ts.map +1 -0
- package/dist/define-config.js +4 -0
- package/dist/define-config.js.map +1 -0
- package/dist/env.d.ts +11 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +23 -0
- package/dist/env.js.map +1 -0
- package/dist/execution-imports.d.ts +51 -0
- package/dist/execution-imports.d.ts.map +1 -0
- package/dist/execution-imports.js +102 -0
- package/dist/execution-imports.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/named-account.d.ts +150 -0
- package/dist/named-account.d.ts.map +1 -0
- package/dist/named-account.js +153 -0
- package/dist/named-account.js.map +1 -0
- package/dist/types.d.ts +488 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,gBAAgB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/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { isValidAleoAddress } from "./aleo-address.js";
|
|
2
|
+
export { configVariable, isConfigVariable, resolveConfigVariable, } from "./config-variable.js";
|
|
3
|
+
export { defineConfig } from "./define-config.js";
|
|
4
|
+
export { parseBooleanEnv } from "./env.js";
|
|
5
|
+
export { checkRuntimeImportRefExists, classifyRuntimeImportRef, isValidExecutionImportsMapKey, looksLikePath, normalizeProgramId, normalizeRuntimeImportRef, } from "./execution-imports.js";
|
|
6
|
+
export { asSigner, createNamedAccountAccessor, isSignable, requireNamedAccount, requireSignableNamedAccount, } from "./named-account.js";
|
|
7
|
+
export { SDK_LOG_LEVELS } from "./types.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,6BAA6B,EAC7B,aAAa,EACb,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,wBAAwB,CAAC;AAUhC,OAAO,EACL,QAAQ,EACR,0BAA0B,EAC1B,UAAU,EACV,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,oBAAoB,CAAC;AAyC5B,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named account runtime types and helpers.
|
|
3
|
+
*
|
|
4
|
+
* A named account maps a human-readable role (e.g. "deployer", "admin",
|
|
5
|
+
* "treasury") to a resolved account value. Two shapes exist:
|
|
6
|
+
*
|
|
7
|
+
* - SignableNamedAccount: has a private key — can sign transactions.
|
|
8
|
+
* Structurally satisfies the Signer interface from @lionden/network
|
|
9
|
+
* (both have `privateKey` and `address`), so it can be passed directly
|
|
10
|
+
* to ExecuteOptions.signer without an adapter.
|
|
11
|
+
*
|
|
12
|
+
* - AddressOnlyNamedAccount: address only — cannot sign. Useful for roles
|
|
13
|
+
* like a treasury receiver where you only need to reference the address.
|
|
14
|
+
*
|
|
15
|
+
* These types live in @lionden/config (zero deps) so that @lionden/core,
|
|
16
|
+
* @lionden/network, and the plugin packages can all import them without
|
|
17
|
+
* creating circular dependencies.
|
|
18
|
+
*/
|
|
19
|
+
export interface SignableNamedAccount {
|
|
20
|
+
readonly type: "signable";
|
|
21
|
+
/** The role name (e.g. "deployer", "admin"). */
|
|
22
|
+
readonly name: string;
|
|
23
|
+
/** The Aleo address derived from the private key. */
|
|
24
|
+
readonly address: string;
|
|
25
|
+
/** The private key for this account. */
|
|
26
|
+
readonly privateKey: string;
|
|
27
|
+
}
|
|
28
|
+
export interface AddressOnlyNamedAccount {
|
|
29
|
+
readonly type: "address-only";
|
|
30
|
+
/** The role name (e.g. "treasury"). */
|
|
31
|
+
readonly name: string;
|
|
32
|
+
/** The Aleo address for this account. */
|
|
33
|
+
readonly address: string;
|
|
34
|
+
}
|
|
35
|
+
/** A resolved named account — either signable or address-only. */
|
|
36
|
+
export type NamedAccount = SignableNamedAccount | AddressOnlyNamedAccount;
|
|
37
|
+
/** Resolved named accounts keyed by role name. A role may be absent. */
|
|
38
|
+
export type NamedAccounts = Readonly<Partial<Record<string, NamedAccount>>>;
|
|
39
|
+
/** Named account role contract used by the context-level named account DSL. */
|
|
40
|
+
export type NamedAccountRole = "signer" | "address";
|
|
41
|
+
/** Reusable named account contract for recipes and tests. */
|
|
42
|
+
export type NamedAccountSpec = Record<string, NamedAccountRole>;
|
|
43
|
+
type ResolveNamedAccountRole<R extends NamedAccountRole> = R extends "signer" ? SignableNamedAccount : NamedAccount;
|
|
44
|
+
export interface NamedAccountAccessor {
|
|
45
|
+
/**
|
|
46
|
+
* Return a required signable account.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const deployer = ctx.named.signer("deployer");
|
|
51
|
+
* await ctx.execute("prog.aleo", "admin_fn", [], { signer: deployer });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
signer(name: string): SignableNamedAccount;
|
|
55
|
+
/**
|
|
56
|
+
* Return a required account where an address is sufficient.
|
|
57
|
+
*
|
|
58
|
+
* The "address" contract returns the full NamedAccount, not a bare address
|
|
59
|
+
* string, so callers can still pass the value to APIs that accept NamedAccount.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const treasury = ctx.named.address("treasury");
|
|
64
|
+
* await ctx.execute("token.aleo", "mint_public", [treasury.address, "1000u64"]);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
address(name: string): NamedAccount;
|
|
68
|
+
/**
|
|
69
|
+
* Validate a recipe-local named account contract and return typed accounts.
|
|
70
|
+
*
|
|
71
|
+
* Inline object literals infer literal role values without `as const`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const { deployer, treasury } = ctx.named.require({
|
|
76
|
+
* deployer: "signer",
|
|
77
|
+
* treasury: "address",
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
require<const Spec extends NamedAccountSpec>(spec: Spec): {
|
|
82
|
+
[K in keyof Spec]: ResolveNamedAccountRole<Spec[K]>;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Type guard — returns true if the account can sign transactions.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const maybeAdmin = ctx.namedAccounts.admin;
|
|
91
|
+
* if (isSignable(maybeAdmin)) {
|
|
92
|
+
* await ctx.execute("prog.aleo", "admin_fn", [], { signer: maybeAdmin });
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* When working from a DeploymentContext or TestContext, prefer
|
|
97
|
+
* `ctx.named.signer(...)` or `ctx.named.require(...)` for required roles.
|
|
98
|
+
*/
|
|
99
|
+
export declare function isSignable(account: NamedAccount | null | undefined): account is SignableNamedAccount;
|
|
100
|
+
export declare function createNamedAccountAccessor(accounts: NamedAccounts, networkName: string): NamedAccountAccessor;
|
|
101
|
+
/**
|
|
102
|
+
* Return a configured named account or throw a clear configuration error.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const treasury = requireNamedAccount(ctx.namedAccounts, "treasury");
|
|
107
|
+
* await ctx.execute("token.aleo", "mint_public", [treasury.address, "1000u64"]);
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @deprecated Prefer `ctx.named.address(...)` or `ctx.named.require(...)`
|
|
111
|
+
* when working from a DeploymentContext or TestContext.
|
|
112
|
+
*/
|
|
113
|
+
export declare function requireNamedAccount(accounts: NamedAccounts, name: string): NamedAccount;
|
|
114
|
+
/**
|
|
115
|
+
* Return a configured signable named account or throw a clear configuration error.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const deployer = requireSignableNamedAccount(ctx.namedAccounts, "deployer");
|
|
120
|
+
* await ctx.execute("prog.aleo", "admin_fn", [], { signer: deployer });
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @deprecated Prefer `ctx.named.signer(...)` or `ctx.named.require(...)`
|
|
124
|
+
* when working from a DeploymentContext or TestContext.
|
|
125
|
+
*/
|
|
126
|
+
export declare function requireSignableNamedAccount(accounts: NamedAccounts, name: string): SignableNamedAccount;
|
|
127
|
+
/**
|
|
128
|
+
* Extract the structural signer shape `{ privateKey, address }` from a named account.
|
|
129
|
+
*
|
|
130
|
+
* Throws if the account is address-only (no private key available).
|
|
131
|
+
*
|
|
132
|
+
* Returns a plain object — intentionally does NOT import `Signer` from
|
|
133
|
+
* @lionden/network to preserve the zero-dep constraint of this package.
|
|
134
|
+
* The returned shape structurally satisfies `Signer` in all consuming packages.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* import { asSigner } from "@lionden/config";
|
|
139
|
+
* await ctx.execute("prog.aleo", "transfer", [amount], { signer: asSigner(ctx.namedAccounts.deployer) });
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @deprecated Prefer passing values from `ctx.named.signer(...)` or
|
|
143
|
+
* signer roles returned by `ctx.named.require(...)` directly.
|
|
144
|
+
*/
|
|
145
|
+
export declare function asSigner(account: NamedAccount): {
|
|
146
|
+
readonly privateKey: string;
|
|
147
|
+
readonly address: string;
|
|
148
|
+
};
|
|
149
|
+
export {};
|
|
150
|
+
//# sourceMappingURL=named-account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named-account.d.ts","sourceRoot":"","sources":["../src/named-account.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,gDAAgD;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,uCAAuC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,kEA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,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,GACX,oBAAoB,CAStB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAQA"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named account runtime types and helpers.
|
|
3
|
+
*
|
|
4
|
+
* A named account maps a human-readable role (e.g. "deployer", "admin",
|
|
5
|
+
* "treasury") to a resolved account value. Two shapes exist:
|
|
6
|
+
*
|
|
7
|
+
* - SignableNamedAccount: has a private key — can sign transactions.
|
|
8
|
+
* Structurally satisfies the Signer interface from @lionden/network
|
|
9
|
+
* (both have `privateKey` and `address`), so it can be passed directly
|
|
10
|
+
* to ExecuteOptions.signer without an adapter.
|
|
11
|
+
*
|
|
12
|
+
* - AddressOnlyNamedAccount: address only — cannot sign. Useful for roles
|
|
13
|
+
* like a treasury receiver where you only need to reference the address.
|
|
14
|
+
*
|
|
15
|
+
* These types live in @lionden/config (zero deps) so that @lionden/core,
|
|
16
|
+
* @lionden/network, and the plugin packages can all import them without
|
|
17
|
+
* creating circular dependencies.
|
|
18
|
+
*/
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Helpers
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* Type guard — returns true if the account can sign transactions.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const maybeAdmin = ctx.namedAccounts.admin;
|
|
28
|
+
* if (isSignable(maybeAdmin)) {
|
|
29
|
+
* await ctx.execute("prog.aleo", "admin_fn", [], { signer: maybeAdmin });
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* When working from a DeploymentContext or TestContext, prefer
|
|
34
|
+
* `ctx.named.signer(...)` or `ctx.named.require(...)` for required roles.
|
|
35
|
+
*/
|
|
36
|
+
export function isSignable(account) {
|
|
37
|
+
return account?.type === "signable";
|
|
38
|
+
}
|
|
39
|
+
export function createNamedAccountAccessor(accounts, networkName) {
|
|
40
|
+
const requireOne = (name, role) => {
|
|
41
|
+
const failure = getRoleFailure(accounts, name, role);
|
|
42
|
+
if (failure) {
|
|
43
|
+
throw new Error(formatNamedAccountContractError(networkName, [failure]));
|
|
44
|
+
}
|
|
45
|
+
return accounts[name];
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
signer(name) {
|
|
49
|
+
return requireOne(name, "signer");
|
|
50
|
+
},
|
|
51
|
+
address(name) {
|
|
52
|
+
return requireOne(name, "address");
|
|
53
|
+
},
|
|
54
|
+
require(spec) {
|
|
55
|
+
const failures = [];
|
|
56
|
+
const result = {};
|
|
57
|
+
for (const [name, role] of Object.entries(spec)) {
|
|
58
|
+
const failure = getRoleFailure(accounts, name, role);
|
|
59
|
+
if (failure) {
|
|
60
|
+
failures.push(failure);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
result[name] = accounts[name];
|
|
64
|
+
}
|
|
65
|
+
if (failures.length > 0) {
|
|
66
|
+
throw new Error(formatNamedAccountContractError(networkName, failures));
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Return a configured named account or throw a clear configuration error.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const treasury = requireNamedAccount(ctx.namedAccounts, "treasury");
|
|
78
|
+
* await ctx.execute("token.aleo", "mint_public", [treasury.address, "1000u64"]);
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @deprecated Prefer `ctx.named.address(...)` or `ctx.named.require(...)`
|
|
82
|
+
* when working from a DeploymentContext or TestContext.
|
|
83
|
+
*/
|
|
84
|
+
export function requireNamedAccount(accounts, name) {
|
|
85
|
+
const account = accounts[name];
|
|
86
|
+
if (!account) {
|
|
87
|
+
throw new Error(`Named account "${name}" is not configured. ` +
|
|
88
|
+
`Add it to namedAccounts in your LionDen config.`);
|
|
89
|
+
}
|
|
90
|
+
return account;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Return a configured signable named account or throw a clear configuration error.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const deployer = requireSignableNamedAccount(ctx.namedAccounts, "deployer");
|
|
98
|
+
* await ctx.execute("prog.aleo", "admin_fn", [], { signer: deployer });
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @deprecated Prefer `ctx.named.signer(...)` or `ctx.named.require(...)`
|
|
102
|
+
* when working from a DeploymentContext or TestContext.
|
|
103
|
+
*/
|
|
104
|
+
export function requireSignableNamedAccount(accounts, name) {
|
|
105
|
+
const account = requireNamedAccount(accounts, name);
|
|
106
|
+
if (!isSignable(account)) {
|
|
107
|
+
throw new Error(`Named account "${name}" is address-only and cannot be used as a signer. ` +
|
|
108
|
+
`Configure a private key or devnode account index for this role.`);
|
|
109
|
+
}
|
|
110
|
+
return account;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Extract the structural signer shape `{ privateKey, address }` from a named account.
|
|
114
|
+
*
|
|
115
|
+
* Throws if the account is address-only (no private key available).
|
|
116
|
+
*
|
|
117
|
+
* Returns a plain object — intentionally does NOT import `Signer` from
|
|
118
|
+
* @lionden/network to preserve the zero-dep constraint of this package.
|
|
119
|
+
* The returned shape structurally satisfies `Signer` in all consuming packages.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* import { asSigner } from "@lionden/config";
|
|
124
|
+
* await ctx.execute("prog.aleo", "transfer", [amount], { signer: asSigner(ctx.namedAccounts.deployer) });
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @deprecated Prefer passing values from `ctx.named.signer(...)` or
|
|
128
|
+
* signer roles returned by `ctx.named.require(...)` directly.
|
|
129
|
+
*/
|
|
130
|
+
export function asSigner(account) {
|
|
131
|
+
if (account.type !== "signable") {
|
|
132
|
+
throw new Error(`Named account "${account.name}" is address-only and cannot be used as a signer. ` +
|
|
133
|
+
`Configure a private key or devnode account index for this role.`);
|
|
134
|
+
}
|
|
135
|
+
return { privateKey: account.privateKey, address: account.address };
|
|
136
|
+
}
|
|
137
|
+
function getRoleFailure(accounts, name, role) {
|
|
138
|
+
const account = accounts[name];
|
|
139
|
+
if (!account) {
|
|
140
|
+
return `"${name}" is not configured`;
|
|
141
|
+
}
|
|
142
|
+
if (role === "signer" && !isSignable(account)) {
|
|
143
|
+
return `"${name}" is address-only but the contract requires a signer`;
|
|
144
|
+
}
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
function formatNamedAccountContractError(networkName, failures) {
|
|
148
|
+
return [
|
|
149
|
+
`Named accounts contract failed for network "${networkName}":`,
|
|
150
|
+
...failures.map((failure) => ` - ${failure}`),
|
|
151
|
+
].join("\n");
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=named-account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named-account.js","sourceRoot":"","sources":["../src/named-account.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAoFH,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CACxB,OAAwC;IAExC,OAAO,OAAO,EAAE,IAAI,KAAK,UAAU,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,QAAuB,EACvB,WAAmB;IAEnB,MAAM,UAAU,GAAG,CACjB,IAAY,EACZ,IAAU,EACqB,EAAE;QACjC,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,EAAE,I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