@prisma-next/family-sql 0.4.1 → 0.4.3
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 +2 -2
- package/dist/control-adapter.d.mts +28 -3
- package/dist/control-adapter.d.mts.map +1 -1
- package/dist/control.d.mts +3 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +1025 -11
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +14 -2
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +16 -1
- package/dist/migration.mjs.map +1 -1
- package/dist/schema-verify.d.mts +2 -2
- package/dist/{types-C6K4mxDM.d.mts → types-gLyIyd2X.d.mts} +36 -11
- package/dist/types-gLyIyd2X.d.mts.map +1 -0
- package/dist/verify-BdES8wgQ.mjs +82 -0
- package/dist/verify-BdES8wgQ.mjs.map +1 -0
- package/dist/verify-sql-schema-Ovz7RXR5.mjs.map +1 -1
- package/dist/{verify-sql-schema-BBhkqEDo.d.mts → verify-sql-schema-_EoNcGIq.d.mts} +2 -2
- package/dist/{verify-sql-schema-BBhkqEDo.d.mts.map → verify-sql-schema-_EoNcGIq.d.mts.map} +1 -1
- package/dist/verify.d.mts +16 -20
- package/dist/verify.d.mts.map +1 -1
- package/dist/verify.mjs +2 -2
- package/package.json +20 -20
- package/src/core/control-adapter.ts +33 -1
- package/src/core/control-instance.ts +43 -15
- package/src/core/migrations/plan-helpers.ts +1 -0
- package/src/core/migrations/types.ts +29 -6
- package/src/core/operation-preview.ts +62 -0
- package/src/core/psl-contract-infer/default-mapping.ts +56 -0
- package/src/core/psl-contract-infer/name-transforms.ts +178 -0
- package/src/core/psl-contract-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-contract-infer/postgres-type-map.ts +165 -0
- package/src/core/psl-contract-infer/printer-config.ts +55 -0
- package/src/core/psl-contract-infer/raw-default-parser.ts +91 -0
- package/src/core/psl-contract-infer/relation-inference.ts +196 -0
- package/src/core/psl-contract-infer/sql-schema-ir-to-psl-ast.ts +832 -0
- package/src/core/sql-migration.ts +19 -3
- package/src/core/verify.ts +46 -108
- package/src/exports/verify.ts +1 -1
- package/dist/types-C6K4mxDM.d.mts.map +0 -1
- package/dist/verify-4GshvY4p.mjs +0 -122
- package/dist/verify-4GshvY4p.mjs.map +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ControlAdapterDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlFamilyInstance, ControlStack, DataTransformOperation, MigratableTargetDescriptor, MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlannerConflict, MigrationPlannerFailureResult, MigrationPlannerSuccessResult, MigrationRunnerExecutionChecks, MigrationRunnerFailure, MigrationRunnerSuccessValue, OperationContext, SchemaIssue, SchemaViewCapable, SignDatabaseResult, VerifyDatabaseResult, VerifyDatabaseSchemaResult } from "@prisma-next/framework-components/control";
|
|
1
|
+
import { ControlAdapterDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlFamilyInstance, ControlStack, DataTransformOperation, MigratableTargetDescriptor, MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlannerConflict, MigrationPlannerFailureResult, MigrationPlannerSuccessResult, MigrationRunnerExecutionChecks, MigrationRunnerFailure, MigrationRunnerSuccessValue, OperationContext, OperationPreview, OperationPreviewCapable, PslContractInferCapable, SchemaIssue, SchemaViewCapable, SignDatabaseResult, VerifyDatabaseResult, VerifyDatabaseSchemaResult } from "@prisma-next/framework-components/control";
|
|
2
2
|
import { Result } from "@prisma-next/utils/result";
|
|
3
|
-
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
4
3
|
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
+
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
5
5
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
6
6
|
import { SqlStorage, StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
7
7
|
import { TypesImportSpec } from "@prisma-next/framework-components/emission";
|
|
8
|
+
import { PslDocumentAst } from "@prisma-next/framework-components/psl-ast";
|
|
8
9
|
import { SqlOperationDescriptor } from "@prisma-next/sql-operations";
|
|
9
10
|
|
|
10
11
|
//#region src/core/control-instance.d.ts
|
|
@@ -32,7 +33,7 @@ interface SchemaVerifyOptions {
|
|
|
32
33
|
*/
|
|
33
34
|
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
34
35
|
}
|
|
35
|
-
interface SqlControlFamilyInstance extends ControlFamilyInstance<'sql', SqlSchemaIR>, SchemaViewCapable<SqlSchemaIR>, SqlFamilyInstanceState {
|
|
36
|
+
interface SqlControlFamilyInstance extends ControlFamilyInstance<'sql', SqlSchemaIR>, SchemaViewCapable<SqlSchemaIR>, PslContractInferCapable<SqlSchemaIR>, OperationPreviewCapable, SqlFamilyInstanceState {
|
|
36
37
|
validateContract(contractJson: unknown): Contract;
|
|
37
38
|
verify(options: {
|
|
38
39
|
readonly driver: ControlDriverInstance<'sql', string>;
|
|
@@ -52,6 +53,8 @@ interface SqlControlFamilyInstance extends ControlFamilyInstance<'sql', SqlSchem
|
|
|
52
53
|
readonly driver: ControlDriverInstance<'sql', string>;
|
|
53
54
|
readonly contract?: unknown;
|
|
54
55
|
}): Promise<SqlSchemaIR>;
|
|
56
|
+
inferPslContract(schemaIR: SqlSchemaIR): PslDocumentAst;
|
|
57
|
+
toOperationPreview(operations: readonly MigrationPlanOperation[]): OperationPreview;
|
|
55
58
|
}
|
|
56
59
|
//#endregion
|
|
57
60
|
//#region src/core/migrations/types.d.ts
|
|
@@ -193,6 +196,15 @@ interface SqlMigrationPlan<TTargetDetails> extends MigrationPlan {
|
|
|
193
196
|
*/
|
|
194
197
|
readonly destination: SqlMigrationPlanContractInfo;
|
|
195
198
|
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
199
|
+
/**
|
|
200
|
+
* Sorted, deduplicated invariant ids declared by this plan's data-transform
|
|
201
|
+
* ops. Required at the SQL-family layer (the SQL runners consume this as
|
|
202
|
+
* the source of truth for marker writes and self-edge no-op checks); the
|
|
203
|
+
* framework-level {@link MigrationPlan.providedInvariants} stays optional
|
|
204
|
+
* because `db init` / `db update` plans don't have a corresponding
|
|
205
|
+
* migration manifest.
|
|
206
|
+
*/
|
|
207
|
+
readonly providedInvariants: readonly string[];
|
|
196
208
|
readonly meta?: AnyRecord;
|
|
197
209
|
}
|
|
198
210
|
type SqlPlannerConflictKind = 'typeMismatch' | 'nullabilityConflict' | 'indexIncompatible' | 'foreignKeyConflict' | 'missingButNonAdditive' | 'unsupportedOperation';
|
|
@@ -223,14 +235,21 @@ interface SqlMigrationPlannerPlanOptions {
|
|
|
223
235
|
readonly policy: MigrationOperationPolicy;
|
|
224
236
|
readonly schemaName?: string;
|
|
225
237
|
/**
|
|
226
|
-
* The "from" contract (state the planner assumes the database starts at)
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
238
|
+
* The "from" contract (state the planner assumes the database starts at),
|
|
239
|
+
* or `null` for reconciliation flows that have no prior contract.
|
|
240
|
+
*
|
|
241
|
+
* Required at every call site so the structural fact "I have a prior
|
|
242
|
+
* contract / I don't" is visible in the type. `migration plan` supplies
|
|
243
|
+
* the previous bundle's `metadata.toContract`; `db update` / `db init`
|
|
244
|
+
* reconcile against the live schema and pass `null`. Strategies that
|
|
245
|
+
* need from/to column-shape comparisons (unsafe type change, nullability
|
|
230
246
|
* tightening) use this to decide whether to emit `dataTransform`
|
|
231
|
-
* placeholders
|
|
247
|
+
* placeholders; they short-circuit when it is `null`.
|
|
248
|
+
*
|
|
249
|
+
* Planners also derive the "from" identity they stamp onto the produced
|
|
250
|
+
* plan's `describe()` as `fromContract?.storage.storageHash ?? null`.
|
|
232
251
|
*/
|
|
233
|
-
readonly fromContract
|
|
252
|
+
readonly fromContract: Contract<SqlStorage> | null;
|
|
234
253
|
/**
|
|
235
254
|
* Active framework components participating in this composition.
|
|
236
255
|
* SQL targets can interpret this list to derive database dependencies.
|
|
@@ -274,7 +293,7 @@ interface SqlMigrationRunnerExecuteOptions<TTargetDetails> {
|
|
|
274
293
|
*/
|
|
275
294
|
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
276
295
|
}
|
|
277
|
-
type SqlMigrationRunnerErrorCode = 'DESTINATION_CONTRACT_MISMATCH' | 'MARKER_ORIGIN_MISMATCH' | 'POLICY_VIOLATION' | 'PRECHECK_FAILED' | 'POSTCHECK_FAILED' | 'SCHEMA_VERIFY_FAILED' | 'EXECUTION_FAILED';
|
|
296
|
+
type SqlMigrationRunnerErrorCode = 'DESTINATION_CONTRACT_MISMATCH' | 'MARKER_ORIGIN_MISMATCH' | 'POLICY_VIOLATION' | 'PRECHECK_FAILED' | 'POSTCHECK_FAILED' | 'SCHEMA_VERIFY_FAILED' | 'FOREIGN_KEY_VIOLATION' | 'EXECUTION_FAILED';
|
|
278
297
|
interface SqlMigrationRunnerFailure extends MigrationRunnerFailure {
|
|
279
298
|
readonly code: SqlMigrationRunnerErrorCode;
|
|
280
299
|
readonly meta?: AnyRecord;
|
|
@@ -294,8 +313,14 @@ interface CreateSqlMigrationPlanOptions<TTargetDetails> {
|
|
|
294
313
|
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
295
314
|
readonly destination: SqlMigrationPlanContractInfo;
|
|
296
315
|
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
316
|
+
/**
|
|
317
|
+
* Sorted, deduplicated invariant ids for this plan; mirrors the required
|
|
318
|
+
* field on {@link SqlMigrationPlan}. Callers without a migration manifest
|
|
319
|
+
* (`db init`, `db update`, planner-built plans) pass `[]`.
|
|
320
|
+
*/
|
|
321
|
+
readonly providedInvariants: readonly string[];
|
|
297
322
|
readonly meta?: AnyRecord;
|
|
298
323
|
}
|
|
299
324
|
//#endregion
|
|
300
325
|
export { SqlPlannerFailureResult as A, SqlMigrationRunnerFailure as C, SqlPlannerConflict as D, SqlPlanTargetDetails as E, isDatabaseDependencyProvider as F, SchemaVerifyOptions as I, SqlControlFamilyInstance as L, SqlPlannerSuccessResult as M, StorageTypePlanResult as N, SqlPlannerConflictKind as O, collectInitDependencies as P, SqlMigrationRunnerExecuteOptions as S, SqlMigrationRunnerSuccessValue as T, SqlMigrationPlanner as _, ComponentDatabaseDependency as a, SqlMigrationRunnerErrorCode as b, ResolveIdentityValueInput as c, SqlControlTargetDescriptor as d, SqlMigrationPlan as f, SqlMigrationPlanOperationTarget as g, SqlMigrationPlanOperationStep as h, ComponentDatabaseDependencies as i, SqlPlannerResult as j, SqlPlannerConflictLocation as k, SqlControlAdapterDescriptor as l, SqlMigrationPlanOperation as m, AnySqlMigrationOperation as n, CreateSqlMigrationPlanOptions as o, SqlMigrationPlanContractInfo as p, CodecControlHooks as r, ExpandNativeTypeInput as s, AnyRecord as t, SqlControlExtensionDescriptor as u, SqlMigrationPlannerPlanOptions as v, SqlMigrationRunnerResult as w, SqlMigrationRunnerExecuteCallbacks as x, SqlMigrationRunner as y };
|
|
301
|
-
//# sourceMappingURL=types-
|
|
326
|
+
//# sourceMappingURL=types-gLyIyd2X.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-gLyIyd2X.d.mts","names":[],"sources":["../src/core/control-instance.ts","../src/core/migrations/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;UAgKU,eAAA;;;;;AA3HsE;AA2HvD,KAOpB,uBAAA,GAA0B,GAAH,CAAA,MAAA,EAAe,eAAA,CAAZ;AAAG,UAExB,sBAAA,CAAsB;EACW,SAAA,gBAAA,EAAd,aAAc,CAAA,eAAA,CAAA;EAAd,SAAA,oBAAA,EACI,aADJ,CACkB,eADlB,CAAA;EACkB,SAAA,YAAA,EACtB,aADsB,CAAA,MAAA,CAAA;EAAd,SAAA,oBAAA,EAEA,uBAFA;;AAEA,UAGhB,mBAAA,CAHgB;EAAuB,SAAA,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"unknown" });
|
|
5
|
+
function parseMeta(meta) {
|
|
6
|
+
if (meta === null || meta === void 0) return {};
|
|
7
|
+
let parsed;
|
|
8
|
+
if (typeof meta === "string") try {
|
|
9
|
+
parsed = JSON.parse(meta);
|
|
10
|
+
} catch {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
else parsed = meta;
|
|
14
|
+
const result = MetaSchema(parsed);
|
|
15
|
+
if (result instanceof type.errors) return {};
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* SQLite stores `contract_json` as TEXT, so the wire shape is a JSON string;
|
|
20
|
+
* Postgres uses `jsonb` and returns an already-parsed value. Normalize both
|
|
21
|
+
* here so `ContractMarkerRecord.contractJson` is always the structured form.
|
|
22
|
+
*/
|
|
23
|
+
function parseContractJson(value) {
|
|
24
|
+
if (value === null || value === void 0) return null;
|
|
25
|
+
if (typeof value !== "string") return value;
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(value);
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const ContractMarkerRowSchema = type({
|
|
33
|
+
core_hash: "string",
|
|
34
|
+
profile_hash: "string",
|
|
35
|
+
"contract_json?": "unknown | null",
|
|
36
|
+
"canonical_version?": "number | null",
|
|
37
|
+
"updated_at?": "Date | string",
|
|
38
|
+
"app_tag?": "string | null",
|
|
39
|
+
"meta?": "unknown | null",
|
|
40
|
+
invariants: type("string").array()
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Parses a contract marker row from database query result.
|
|
44
|
+
* This is SQL-specific parsing logic (handles SQL row structure with snake_case columns).
|
|
45
|
+
*/
|
|
46
|
+
function parseContractMarkerRow(row) {
|
|
47
|
+
const result = ContractMarkerRowSchema(row);
|
|
48
|
+
if (result instanceof type.errors) {
|
|
49
|
+
const messages = result.map((p) => p.message).join("; ");
|
|
50
|
+
throw new Error(`Invalid contract marker row: ${messages}`);
|
|
51
|
+
}
|
|
52
|
+
const updatedAt = result.updated_at ? result.updated_at instanceof Date ? result.updated_at : new Date(result.updated_at) : /* @__PURE__ */ new Date();
|
|
53
|
+
return {
|
|
54
|
+
storageHash: result.core_hash,
|
|
55
|
+
profileHash: result.profile_hash,
|
|
56
|
+
contractJson: parseContractJson(result.contract_json),
|
|
57
|
+
canonicalVersion: result.canonical_version ?? null,
|
|
58
|
+
updatedAt,
|
|
59
|
+
appTag: result.app_tag ?? null,
|
|
60
|
+
meta: parseMeta(result.meta),
|
|
61
|
+
invariants: result.invariants
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Collects supported codec type IDs from adapter and extension manifests.
|
|
66
|
+
* Returns a sorted, unique array of type IDs that are declared in the manifests.
|
|
67
|
+
* This enables coverage checks by comparing contract column types against supported types.
|
|
68
|
+
*
|
|
69
|
+
* Note: This extracts type IDs from manifest type imports, not from runtime codec registries.
|
|
70
|
+
* The manifests declare which codec types are available, but the actual type IDs
|
|
71
|
+
* are defined in the codec-types TypeScript modules that are imported.
|
|
72
|
+
*
|
|
73
|
+
* For MVP, we return an empty array since extracting type IDs from TypeScript modules
|
|
74
|
+
* would require runtime evaluation or static analysis. This can be enhanced later.
|
|
75
|
+
*/
|
|
76
|
+
function collectSupportedCodecTypeIds(descriptors) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { parseContractMarkerRow as n, collectSupportedCodecTypeIds as t };
|
|
82
|
+
//# sourceMappingURL=verify-BdES8wgQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-BdES8wgQ.mjs","names":["parsed: unknown"],"sources":["../src/core/verify.ts"],"sourcesContent":["import type { ContractMarkerRecord } from '@prisma-next/contract/types';\nimport { type } from 'arktype';\n\nconst MetaSchema = type({ '[string]': 'unknown' });\n\nfunction parseMeta(meta: unknown): Record<string, unknown> {\n if (meta === null || meta === undefined) {\n return {};\n }\n\n let parsed: unknown;\n if (typeof meta === 'string') {\n try {\n parsed = JSON.parse(meta);\n } catch {\n return {};\n }\n } else {\n parsed = meta;\n }\n\n const result = MetaSchema(parsed);\n if (result instanceof type.errors) {\n return {};\n }\n\n return result as Record<string, unknown>;\n}\n\n/**\n * SQLite stores `contract_json` as TEXT, so the wire shape is a JSON string;\n * Postgres uses `jsonb` and returns an already-parsed value. Normalize both\n * here so `ContractMarkerRecord.contractJson` is always the structured form.\n */\nfunction parseContractJson(value: unknown): unknown {\n if (value === null || value === undefined) return null;\n if (typeof value !== 'string') return value;\n try {\n return JSON.parse(value);\n } catch {\n return null;\n }\n}\n\n/**\n * Wire shape of a `prisma_contract.marker` row as it comes out of a SQL\n * driver. Snake-cased to match the on-disk column names. Shared by every\n * SQL target's `readMarker` so each runner doesn't redeclare it inline.\n */\nexport type ContractMarkerRow = {\n core_hash: string;\n profile_hash: string;\n contract_json: unknown | null;\n canonical_version: number | null;\n updated_at: Date | string;\n app_tag: string | null;\n meta: unknown | null;\n // SQLite stores arrays as JSON-TEXT, so this is `string` on the wire from\n // a SQLite driver and `string[]` from a Postgres driver. Targets normalize\n // before passing to `parseContractMarkerRow`.\n invariants: unknown;\n};\n\nconst ContractMarkerRowSchema = type({\n core_hash: 'string',\n profile_hash: 'string',\n 'contract_json?': 'unknown | null',\n 'canonical_version?': 'number | null',\n 'updated_at?': 'Date | string',\n 'app_tag?': 'string | null',\n 'meta?': 'unknown | null',\n invariants: type('string').array(),\n});\n\n/**\n * Parses a contract marker row from database query result.\n * This is SQL-specific parsing logic (handles SQL row structure with snake_case columns).\n */\nexport function parseContractMarkerRow(row: unknown): ContractMarkerRecord {\n const result = ContractMarkerRowSchema(row);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Invalid contract marker row: ${messages}`);\n }\n\n const updatedAt = result.updated_at\n ? result.updated_at instanceof Date\n ? result.updated_at\n : new Date(result.updated_at)\n : new Date();\n\n return {\n storageHash: result.core_hash,\n profileHash: result.profile_hash,\n contractJson: parseContractJson(result.contract_json),\n canonicalVersion: result.canonical_version ?? null,\n updatedAt,\n appTag: result.app_tag ?? null,\n meta: parseMeta(result.meta),\n invariants: result.invariants,\n };\n}\n\n/**\n * Collects supported codec type IDs from adapter and extension manifests.\n * Returns a sorted, unique array of type IDs that are declared in the manifests.\n * This enables coverage checks by comparing contract column types against supported types.\n *\n * Note: This extracts type IDs from manifest type imports, not from runtime codec registries.\n * The manifests declare which codec types are available, but the actual type IDs\n * are defined in the codec-types TypeScript modules that are imported.\n *\n * For MVP, we return an empty array since extracting type IDs from TypeScript modules\n * would require runtime evaluation or static analysis. This can be enhanced later.\n */\nexport function collectSupportedCodecTypeIds(\n descriptors: ReadonlyArray<{ readonly id: string }>,\n): readonly string[] {\n // For MVP, return empty array\n // Future enhancement: Extract type IDs from codec-types modules via static analysis\n // or require manifests to explicitly list supported type IDs\n void descriptors;\n return [];\n}\n"],"mappings":";;;AAGA,MAAM,aAAa,KAAK,EAAE,YAAY,WAAW,CAAC;AAElD,SAAS,UAAU,MAAwC;AACzD,KAAI,SAAS,QAAQ,SAAS,OAC5B,QAAO,EAAE;CAGX,IAAIA;AACJ,KAAI,OAAO,SAAS,SAClB,KAAI;AACF,WAAS,KAAK,MAAM,KAAK;SACnB;AACN,SAAO,EAAE;;KAGX,UAAS;CAGX,MAAM,SAAS,WAAW,OAAO;AACjC,KAAI,kBAAkB,KAAK,OACzB,QAAO,EAAE;AAGX,QAAO;;;;;;;AAQT,SAAS,kBAAkB,OAAyB;AAClD,KAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;SAClB;AACN,SAAO;;;AAuBX,MAAM,0BAA0B,KAAK;CACnC,WAAW;CACX,cAAc;CACd,kBAAkB;CAClB,sBAAsB;CACtB,eAAe;CACf,YAAY;CACZ,S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