@prisma-next/target-postgres 0.13.0-dev.33 → 0.13.0-dev.35

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.
Files changed (33) hide show
  1. package/dist/control.mjs +2 -2
  2. package/dist/{issue-planner-DsjB7xDj.mjs → issue-planner-9AVUEL74.mjs} +5 -5
  3. package/dist/{issue-planner-DsjB7xDj.mjs.map → issue-planner-9AVUEL74.mjs.map} +1 -1
  4. package/dist/issue-planner.d.mts +1 -1
  5. package/dist/issue-planner.mjs +1 -1
  6. package/dist/migration.mjs +2 -2
  7. package/dist/{op-factory-call-CjR846f7.mjs → op-factory-call-CvDOetGa.mjs} +2 -2
  8. package/dist/{op-factory-call-CjR846f7.mjs.map → op-factory-call-CvDOetGa.mjs.map} +1 -1
  9. package/dist/op-factory-call.mjs +1 -1
  10. package/dist/{planner-_FOL4I21.mjs → planner-BZxjjT8T.mjs} +4 -4
  11. package/dist/{planner-_FOL4I21.mjs.map → planner-BZxjjT8T.mjs.map} +1 -1
  12. package/dist/{planner-produced-postgres-migration-BmCpyWLJ.mjs → planner-produced-postgres-migration-CkECqqTy.mjs} +2 -2
  13. package/dist/{planner-produced-postgres-migration-BmCpyWLJ.mjs.map → planner-produced-postgres-migration-CkECqqTy.mjs.map} +1 -1
  14. package/dist/planner-produced-postgres-migration.mjs +1 -1
  15. package/dist/{planner-sql-checks-CJJtPfDH.mjs → planner-sql-checks-Bj4G0_gO.mjs} +2 -2
  16. package/dist/{planner-sql-checks-CJJtPfDH.mjs.map → planner-sql-checks-Bj4G0_gO.mjs.map} +1 -1
  17. package/dist/planner-sql-checks.mjs +1 -1
  18. package/dist/planner.mjs +1 -1
  19. package/dist/{postgres-contract-serializer-CyAe8ZFv.mjs → postgres-contract-serializer-sdg1B6Og.mjs} +3 -3
  20. package/dist/postgres-contract-serializer-sdg1B6Og.mjs.map +1 -0
  21. package/dist/{postgres-migration-dG-J0aI8.mjs → postgres-migration-DMnWjdni.mjs} +2 -2
  22. package/dist/{postgres-migration-dG-J0aI8.mjs.map → postgres-migration-DMnWjdni.mjs.map} +1 -1
  23. package/dist/{postgres-schema-CTKYiTHu.mjs → postgres-schema-CDaLWZwd.mjs} +12 -23
  24. package/dist/postgres-schema-CDaLWZwd.mjs.map +1 -0
  25. package/dist/runtime.mjs +1 -1
  26. package/dist/types.d.mts +2 -2
  27. package/dist/types.d.mts.map +1 -1
  28. package/dist/types.mjs +1 -1
  29. package/package.json +17 -17
  30. package/src/core/postgres-contract-serializer.ts +1 -1
  31. package/src/core/postgres-schema.ts +24 -47
  32. package/dist/postgres-contract-serializer-CyAe8ZFv.mjs.map +0 -1
  33. package/dist/postgres-schema-CTKYiTHu.mjs.map +0 -1
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  freezeNode,
3
+ hydrateNamespaceEntities,
3
4
  NamespaceBase,
4
5
  UNBOUND_NAMESPACE_ID,
5
6
  } from '@prisma-next/framework-components/ir';
6
- import {
7
- type SqlNamespaceTablesInput,
8
- type SqlStorage,
7
+ import { composeSqlEntityKinds } from '@prisma-next/sql-contract/entity-kinds';
8
+ import type {
9
+ SqlNamespaceEntries,
10
+ SqlNamespaceTablesInput,
11
+ SqlStorage,
9
12
  StorageTable,
10
- type StorageTableInput,
11
13
  StorageValueSet,
12
- type StorageValueSetInput,
13
14
  } from '@prisma-next/sql-contract/types';
14
15
  import { blindCast } from '@prisma-next/utils/casts';
15
- import { ifDefined } from '@prisma-next/utils/defined';
16
16
  import { escapeLiteral } from './sql-utils';
17
17
 
18
18
  export interface PostgresSchemaInput {
@@ -46,50 +46,27 @@ export class PostgresSchema extends NamespaceBase {
46
46
 
47
47
  declare readonly kind: 'schema';
48
48
  readonly id: string;
49
- readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
49
+ readonly entries: SqlNamespaceEntries;
50
50
 
51
51
  constructor(input: PostgresSchemaInput) {
52
52
  super();
53
53
  this.id = input.id;
54
54
 
55
- const carried: Record<string, Readonly<Record<string, unknown>>> = {};
56
- let table: Readonly<Record<string, StorageTable>> = Object.freeze({});
57
- let valueSet: Readonly<Record<string, StorageValueSet>> | undefined;
58
- for (const [kind, rawMap] of Object.entries(input.entries)) {
59
- if (kind === 'table') {
60
- const tableMap: Record<string, StorageTable> = {};
61
- for (const [name, v] of Object.entries(
62
- blindCast<
63
- Record<string, StorageTableInput>,
64
- 'entries[table] holds StorageTableInput by construction'
65
- >(rawMap),
66
- )) {
67
- tableMap[name] = new StorageTable(v);
68
- }
69
- table = Object.freeze(tableMap);
70
- } else if (kind === 'valueSet') {
71
- const vsMap: Record<string, StorageValueSet> = {};
72
- for (const [name, v] of Object.entries(
73
- blindCast<
74
- Record<string, StorageValueSetInput>,
75
- 'entries[valueSet] holds StorageValueSetInput by construction'
76
- >(rawMap),
77
- )) {
78
- vsMap[name] = new StorageValueSet(v);
79
- }
80
- if (Object.keys(vsMap).length > 0) {
81
- valueSet = Object.freeze(vsMap);
82
- }
83
- } else {
84
- carried[kind] = Object.freeze(rawMap);
85
- }
86
- }
87
-
88
- this.entries = Object.freeze({
89
- ...carried,
90
- table,
91
- ...ifDefined('valueSet', valueSet),
92
- });
55
+ const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), 'carry');
56
+
57
+ // Drop an empty valueSet so presence signals non-emptiness.
58
+ const valueSetRaw = dispatched['valueSet'];
59
+ const withPresence =
60
+ valueSetRaw !== undefined && Object.keys(valueSetRaw).length === 0
61
+ ? { ...dispatched, valueSet: undefined }
62
+ : dispatched;
63
+
64
+ this.entries = Object.freeze(
65
+ blindCast<
66
+ SqlNamespaceEntries,
67
+ 'composeSqlEntityKinds() supplies table→StorageTable and valueSet→StorageValueSet descriptors, so this open-dict result holds exactly the typed members SqlNamespaceEntries declares; the descriptor Map erases those per-kind Node types from the return.'
68
+ >(withPresence),
69
+ );
93
70
  Object.defineProperty(this, 'kind', {
94
71
  value: 'schema',
95
72
  writable: false,
@@ -100,11 +77,11 @@ export class PostgresSchema extends NamespaceBase {
100
77
  }
101
78
 
102
79
  get table(): Readonly<Record<string, StorageTable>> {
103
- return this.entries['table'] ?? Object.freeze({});
80
+ return this.entries.table ?? Object.freeze({});
104
81
  }
105
82
 
106
83
  get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined {
107
- return this.entries['valueSet'] as Readonly<Record<string, StorageValueSet>> | undefined;
84
+ return this.entries.valueSet;
108
85
  }
109
86
 
110
87
  /**
@@ -1 +0,0 @@
1
- {"version":3,"file":"postgres-contract-serializer-CyAe8ZFv.mjs","names":[],"sources":["../src/core/postgres-contract-serializer.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport {\n SqlContractSerializerBase,\n type SqlEntityHydrationFactory,\n} from '@prisma-next/family-sql/ir';\nimport {\n type AuthoringEntityContext,\n type AuthoringEntityTypeFactoryOutput,\n type AuthoringEntityTypeNamespace,\n isAuthoringEntityTypeDescriptor,\n} from '@prisma-next/framework-components/authoring';\nimport {\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type { SqlNamespaceTablesInput, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport { postgresAuthoringEntityTypes } from './authoring';\nimport { isPostgresSchema, PostgresSchema } from './postgres-schema';\n\nconst POSTGRES_AUTHORING_CTX: AuthoringEntityContext = {\n family: 'sql',\n target: 'postgres',\n};\n\nfunction isAuthoringEntityTypeFactoryOutput(\n output: unknown,\n): output is AuthoringEntityTypeFactoryOutput<unknown, unknown> {\n return (\n typeof output === 'object' &&\n output !== null &&\n typeof (output as AuthoringEntityTypeFactoryOutput).factory === 'function'\n );\n}\n\n/**\n * Walks a pack's entity-type namespace tree and emits hydration factories\n * keyed by the descriptor's `discriminator`. Used for `storage.types`\n * (codec-triple hydration). Namespace entries hydration dispatches by\n * entries key, not discriminator — handled by `hydrateEntriesKind`.\n */\nfunction collectStorageTypesHydrators(\n namespace: AuthoringEntityTypeNamespace,\n): ReadonlyMap<string, SqlEntityHydrationFactory> {\n const registry = new Map<string, SqlEntityHydrationFactory>();\n const walk = (node: AuthoringEntityTypeNamespace): void => {\n for (const value of Object.values(node)) {\n if (isAuthoringEntityTypeDescriptor(value)) {\n if (isAuthoringEntityTypeFactoryOutput(value.output)) {\n const { factory } = value.output;\n registry.set(value.discriminator, (raw) => factory(raw, POSTGRES_AUTHORING_CTX));\n }\n continue;\n }\n if (typeof value === 'object' && value !== null) {\n walk(value);\n }\n }\n };\n walk(namespace);\n return registry;\n}\n\nexport class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n const storageTypesHydrators = collectStorageTypesHydrators(postgresAuthoringEntityTypes);\n super(storageTypesHydrators);\n }\n\n protected override hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Namespace | Record<string, unknown>,\n ): Namespace | SqlNamespaceTablesInput {\n if (raw instanceof NamespaceBase) {\n return raw;\n }\n const hydrated = blindCast<\n SqlNamespaceTablesInput,\n 'super.hydrateSqlNamespaceEntry returns SqlNamespaceTablesInput when raw is not a NamespaceBase'\n >(super.hydrateSqlNamespaceEntry(nsId, raw));\n const { id, entries } = hydrated;\n\n const valueSetSlot = entries['valueSet'];\n const hasValueSets = valueSetSlot !== undefined && Object.keys(valueSetSlot).length > 0;\n const emptyTables = Object.keys(entries['table'] ?? {}).length === 0;\n if (id === UNBOUND_NAMESPACE_ID && emptyTables && !hasValueSets) {\n return PostgresSchema.unbound;\n }\n return new PostgresSchema({\n id,\n entries: {\n ...entries,\n table: entries['table'] ?? {},\n ...(hasValueSets ? { valueSet: valueSetSlot } : {}),\n },\n });\n }\n\n override serializeContract(contract: Contract<SqlStorage>): JsonObject {\n const { storage, ...rest } = contract;\n const namespacesJson: Record<string, JsonObject> = {};\n for (const [nsId, ns] of Object.entries(storage.namespaces)) {\n if (isPostgresSchema(ns)) {\n namespacesJson[nsId] = this.serializePostgresNamespace(ns, ns.id === UNBOUND_NAMESPACE_ID);\n } else {\n const isUnboundSlot = nsId === UNBOUND_NAMESPACE_ID;\n namespacesJson[nsId] = {\n id: nsId,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: Object.fromEntries(\n Object.entries(ns.entries.table ?? {}).map(([tableName, table]) => [\n tableName,\n this.serializeJsonValue(table) as JsonObject,\n ]),\n ),\n },\n };\n }\n }\n const storageOut: Record<string, unknown> = {\n storageHash: String(storage.storageHash),\n namespaces: namespacesJson,\n };\n if (storage.types !== undefined) {\n const typesOut: Record<string, JsonObject> = {};\n for (const [name, entry] of Object.entries(storage.types)) {\n typesOut[name] = this.serializeJsonValue(entry) as JsonObject;\n }\n storageOut['types'] = typesOut;\n }\n return {\n ...rest,\n storage: storageOut,\n } as unknown as JsonObject;\n }\n\n private serializePostgresNamespace(ns: PostgresSchema, isUnboundSlot: boolean): JsonObject {\n const tablesOut: Record<string, JsonObject> = {};\n for (const [tableName, table] of Object.entries(ns.table)) {\n tablesOut[tableName] = this.serializeJsonValue(table) as JsonObject;\n }\n const valueSetEntries = ns.valueSet;\n const valueSetOut: Record<string, JsonObject> = {};\n if (valueSetEntries !== undefined) {\n for (const [valueSetName, valueSet] of Object.entries(valueSetEntries)) {\n valueSetOut[valueSetName] = blindCast<\n JsonObject,\n 'serializeJsonValue round-trips the value-set node through JSON, yielding a JsonObject'\n >(this.serializeJsonValue(valueSet));\n }\n }\n return {\n id: ns.id,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: tablesOut,\n ...(Object.keys(valueSetOut).length > 0 ? { valueSet: valueSetOut } : {}),\n },\n };\n }\n\n private serializeJsonValue(value: unknown): unknown {\n return JSON.parse(JSON.stringify(value)) as unknown;\n }\n}\n"],"mappings":";;;;;;;AAsBA,MAAM,yBAAiD;CACrD,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,mCACP,QAC8D;CAC9D,OACE,OA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CAAC;CACzC;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"postgres-schema-CTKYiTHu.mjs","names":[],"sources":["../src/core/postgres-schema.ts"],"sourcesContent":["import {\n freezeNode,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport {\n type SqlNamespaceTablesInput,\n type SqlStorage,\n StorageTable,\n type StorageTableInput,\n StorageValueSet,\n type StorageValueSetInput,\n} from '@prisma-next/sql-contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { escapeLiteral } from './sql-utils';\n\nexport interface PostgresSchemaInput {\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\n/**\n * Postgres target `Namespace` concretion — a Postgres schema (`CREATE\n * SCHEMA …`). Each Postgres `SqlStorage` carries a\n * `namespaces: Record<NamespaceId, PostgresSchema>` map populated by\n * the Postgres PSL interpreter from `namespace { … }` AST buckets.\n *\n * `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier\n * emission is the rendering seam: DDL / SQL emission asks the namespace\n * for its qualifier (`\"<schema>\"`) or for a qualified table name\n * (`\"<schema>\".\"<table>\"`) and consumes the result polymorphically.\n * The unbound singleton below overrides these methods to elide the\n * prefix entirely — call sites stay polymorphic and never branch on\n * `id === UNBOUND_NAMESPACE_ID`.\n */\nexport class PostgresSchema extends NamespaceBase {\n /**\n * Stable singleton reference for the late-bound slot. Materialised\n * lazily below the singleton subclass declaration so the static\n * initialiser sees the subclass before assigning. Consumers always\n * reach for `PostgresSchema.unbound` (or `PostgresUnboundSchema.instance`\n * — same identity).\n */\n static unbound: PostgresUnboundSchema;\n\n declare readonly kind: 'schema';\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n\n constructor(input: PostgresSchemaInput) {\n super();\n this.id = input.id;\n\n const carried: Record<string, Readonly<Record<string, unknown>>> = {};\n let table: Readonly<Record<string, StorageTable>> = Object.freeze({});\n let valueSet: Readonly<Record<string, StorageValueSet>> | undefined;\n for (const [kind, rawMap] of Object.entries(input.entries)) {\n if (kind === 'table') {\n const tableMap: Record<string, StorageTable> = {};\n for (const [name, v] of Object.entries(\n blindCast<\n Record<string, StorageTableInput>,\n 'entries[table] holds StorageTableInput by construction'\n >(rawMap),\n )) {\n tableMap[name] = new StorageTable(v);\n }\n table = Object.freeze(tableMap);\n } else if (kind === 'valueSet') {\n const vsMap: Record<string, StorageValueSet> = {};\n for (const [name, v] of Object.entries(\n blindCast<\n Record<string, StorageValueSetInput>,\n 'entries[valueSet] holds StorageValueSetInput by construction'\n >(rawMap),\n )) {\n vsMap[name] = new StorageValueSet(v);\n }\n if (Object.keys(vsMap).length > 0) {\n valueSet = Object.freeze(vsMap);\n }\n } else {\n carried[kind] = Object.freeze(rawMap);\n }\n }\n\n this.entries = Object.freeze({\n ...carried,\n table,\n ...ifDefined('valueSet', valueSet),\n });\n Object.defineProperty(this, 'kind', {\n value: 'schema',\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return this.entries['table'] ?? Object.freeze({});\n }\n\n get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined {\n return this.entries['valueSet'] as Readonly<Record<string, StorageValueSet>> | undefined;\n }\n\n /**\n * The bare schema qualifier as it would appear in a rendered SQL\n * fragment (already quoted). The unbound-schema singleton overrides\n * this to return `''`.\n */\n qualifier(): string {\n return `\"${this.id}\"`;\n }\n\n /**\n * Qualify a table name with the schema prefix\n * (`\"<schema>\".\"<table>\"`). The unbound-schema singleton overrides\n * this to emit just `\"<table>\"` so the resolved DDL is unqualified\n * and `search_path` decides where the object lands at runtime.\n */\n qualifyTable(tableName: string): string {\n return `\"${this.id}\".\"${tableName}\"`;\n }\n\n /**\n * Render a SQL string-literal containing the qualified-name form\n * suitable for `to_regclass(...)` arguments (e.g. `'\"public\".\"user\"'`).\n * The unbound singleton overrides this to elide the schema prefix\n * (`'\"user\"'`) so `search_path` resolves the object at runtime.\n */\n regclassLiteral(name: string): string {\n return `'${escapeLiteral(this.qualifyTable(name))}'`;\n }\n\n /**\n * Render a SQL expression that evaluates to this namespace's schema\n * name at runtime, ready to drop into a `WHERE table_schema = …` /\n * `WHERE n.nspname = …` clause. Named schemas emit a quoted SQL\n * literal (`'public'`); the unbound singleton overrides this to emit\n * `current_schema()` so catalog queries match whichever schema the\n * connection's `search_path` resolved at runtime.\n */\n schemaSqlExpression(): string {\n return `'${escapeLiteral(this.id)}'`;\n }\n\n /**\n * The bare schema name a DDL planner should target when emitting\n * statements that need to identify this namespace in the live\n * database (e.g. `CREATE TABLE \"<ddlSchemaName>\".\"<table>\" …`,\n * catalog filters, planner conflict lookups). Named schemas resolve\n * to their own id. The `PostgresUnboundSchema` singleton inherits\n * this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch\n * through `qualifyTableName` / `toRegclassLiteral` route through the\n * polymorphic `PostgresUnboundSchema` overrides and produce\n * unqualified (search-path-resolved) output automatically.\n */\n ddlSchemaName(_storage: SqlStorage): string {\n return this.id;\n }\n}\n\n/**\n * Singleton subclass for the reserved sentinel namespace id\n * (`UNBOUND_NAMESPACE_ID`) — the late-bound Postgres slot whose binding\n * the connection's `search_path` resolves at runtime. Overrides\n * qualifier emission to elide the schema prefix; call sites that consume\n * `qualifier()` / `qualifyTable()` get unqualified output without\n * branching on the namespace id.\n *\n * This is the target-side materialization of \"the framework provides\n * affordances; targets implement specifics\": the framework names the\n * sentinel; Postgres decides what late-bound means here (the table\n * name, naked — the schema is supplied by the live connection's\n * `search_path`).\n *\n * `ddlSchemaName` is inherited from `PostgresSchema` and returns\n * `UNBOUND_NAMESPACE_ID`. Downstream helpers (`qualifyTableName`,\n * `toRegclassLiteral`) route through the polymorphic factory and\n * produce unqualified output automatically.\n */\nexport class PostgresUnboundSchema extends PostgresSchema {\n static readonly instance: PostgresUnboundSchema = new PostgresUnboundSchema();\n\n constructor(input?: PostgresSchemaInput) {\n super(input ?? { id: UNBOUND_NAMESPACE_ID, entries: { table: {} } });\n }\n\n override qualifier(): string {\n return '';\n }\n\n override qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n\n override schemaSqlExpression(): string {\n return 'current_schema()';\n }\n}\n\nPostgresSchema.unbound = PostgresUnboundSchema.instance;\n\n/**\n * Narrow an arbitrary namespace (or `undefined`) to `PostgresSchema`\n * so callers can dispatch to the polymorphic emission methods without\n * branching at the call site. Uses the structural `kind` discriminator\n * (`'schema'`) rather than `instanceof` so the check survives realm /\n * bundle / hot-reload boundaries — matching the rest of the IR's\n * narrowing convention. `PostgresUnboundSchema` passes through because\n * it inherits the same `kind: 'schema'` from `PostgresSchema`.\n */\nexport function isPostgresSchema(ns: unknown): ns is PostgresSchema {\n return (ns as { kind?: unknown } | null | undefined)?.kind === 'schema';\n}\n\n/**\n * Target-supplied `Namespace` factory the Postgres target plumbs\n * through `defineContract({ createNamespace })` and the SQL PSL\n * interpreter. Returns the unbound singleton for the framework\n * sentinel and a fresh `PostgresSchema` for any other coordinate.\n *\n * The factory has no per-call state — every named id deterministically\n * maps to a distinct schema instance — so callers can pass it through\n * by reference and trust the resulting `SqlStorage.namespaces` map to\n * be value-stable for a given input set.\n */\nexport function postgresCreateNamespace(input: SqlNamespaceTablesInput): PostgresSchema {\n const schemaInput: PostgresSchemaInput = {\n id: input.id,\n entries: {\n ...input.entries,\n table: input.entries['table'] ?? {},\n },\n };\n if (input.id === UNBOUND_NAMESPACE_ID) {\n return new PostgresUnboundSchema(schemaInput);\n }\n return new PostgresSchema(schemaInput);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,iBAAb,cAAoC,cAAc;;;;;;;;CAQhD,OAAO;CAGP;CACA;CAEA,YAAY,OAA4B;EACtC,MAAM;EACN,KAAK,KAAK,MAAM;EAEhB,MAAM,UAA6D,CAAC;EACpE,IAAI,QAAgD,OAAO,OAAO,CAAC,CAAC;E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