@prisma-next/family-sql 0.11.0-dev.46 → 0.11.0-dev.48
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/dist/control-adapter.d.mts +11 -4
- package/dist/control-adapter.d.mts.map +1 -1
- package/dist/control.d.mts +24 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +36 -20
- package/dist/control.mjs.map +1 -1
- package/dist/schema-verify.d.mts +1 -1
- package/dist/schema-verify.mjs +1 -1
- package/dist/{verify-sql-schema-Bfvz07Ik.d.mts → verify-sql-schema-CN7pPoTC.d.mts} +2 -2
- package/dist/{verify-sql-schema-Bfvz07Ik.d.mts.map → verify-sql-schema-CN7pPoTC.d.mts.map} +1 -1
- package/dist/{verify-sql-schema-DcP55TWb.mjs → verify-sql-schema-CYLsGCFO.mjs} +50 -36
- package/dist/verify-sql-schema-CYLsGCFO.mjs.map +1 -0
- package/package.json +21 -21
- package/src/core/control-adapter.ts +16 -2
- package/src/core/control-instance.ts +4 -1
- package/src/core/migrations/contract-to-schema-ir.ts +81 -34
- package/src/core/schema-verify/verify-sql-schema.ts +89 -40
- package/src/exports/control.ts +1 -0
- package/dist/verify-sql-schema-DcP55TWb.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as NativeTypeNormalizer, t as DefaultNormalizer } from "./verify-sql-schema-
|
|
1
|
+
import { n as NativeTypeNormalizer, t as DefaultNormalizer } from "./verify-sql-schema-CN7pPoTC.mjs";
|
|
2
2
|
import { ControlAdapterInstance, ControlDriverInstance, ControlStack } from "@prisma-next/framework-components/control";
|
|
3
|
-
import { PostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
4
|
-
import { ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
3
|
+
import { PostgresEnumStorageEntry, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
4
|
+
import { Contract, ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
5
5
|
import { AnyQueryAst, LoweredStatement, LowererContext } from "@prisma-next/sql-relational-core/ast";
|
|
6
6
|
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
7
7
|
|
|
@@ -70,7 +70,14 @@ interface SqlControlAdapter<TTarget extends string = string> extends ControlAdap
|
|
|
70
70
|
* know the target-specific `schema.annotations` shape
|
|
71
71
|
* (e.g. `schema.annotations.pg.storageTypes`).
|
|
72
72
|
*/
|
|
73
|
-
readonly resolveExistingEnumValues?: (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry) => readonly string[] | null;
|
|
73
|
+
readonly resolveExistingEnumValues?: (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
74
|
+
/**
|
|
75
|
+
* Optional contract-scoped factory for {@link resolveExistingEnumValues}.
|
|
76
|
+
* Targets that need the contract storage to resolve namespace → DDL schema
|
|
77
|
+
* supply this; the family control instance prefers it over the bare adapter
|
|
78
|
+
* hook when present.
|
|
79
|
+
*/
|
|
80
|
+
readonly resolveExistingEnumValuesForContract?: (contract: Contract<SqlStorage>) => (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
74
81
|
/**
|
|
75
82
|
* Lower a SQL query AST into a target-flavored `{ sql, params }` payload.
|
|
76
83
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-adapter.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"mappings":";;;;;;;;;;AAqBA;;;;UAAiB,iBAAA,0CACP,sBAAA,QAA8B,OAAA;EAiB5B;;;;;;;;;;;;;;;EADV,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,WACC,OAAA,CAAQ,oBAAA;
|
|
1
|
+
{"version":3,"file":"control-adapter.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"mappings":";;;;;;;;;;AAqBA;;;;UAAiB,iBAAA,0CACP,sBAAA,QAA8B,OAAA;EAiB5B;;;;;;;;;;;;;;;EADV,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,WACC,OAAA,CAAQ,oBAAA;EAiEU;;;;;;;EAxDrB,cAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,IACpC,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EA9BD;;;;;;;;;;;;EA4C9B,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;EAnBD;;;;;EAAA,SA0BD,gBAAA,GAAmB,iBAAA;EAX5B;;;;;EAAA,SAkBS,mBAAA,GAAsB,oBAAA;EAd5B;;;;;;;;EAAA,SAwBM,yBAAA,IACP,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EADU;;;;;;EAAA,SASH,oCAAA,IACP,QAAA,EAAU,QAAA,CAAS,UAAA,OAEnB,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EAFQ;;;;;;;;;EAcV,KAAA,CAAM,GAAA,EAAK,WAAA,EAAa,OAAA,EAAS,cAAA,YAA0B,gBAAA;AAAA;;AAAgB;AAS7E;;;;UAAiB,2BAAA;EAOgD;;;;;;EAA/D,MAAA,CAAO,KAAA,EAAO,YAAA,QAAoB,OAAA,IAAW,iBAAA,CAAkB,OAAA;AAAA"}
|
package/dist/control.d.mts
CHANGED
|
@@ -271,6 +271,21 @@ type NativeTypeExpander = (input: {
|
|
|
271
271
|
* `contractToSchemaIR`, keeping the family layer target-agnostic.
|
|
272
272
|
*/
|
|
273
273
|
type DefaultRenderer = (def: ColumnDefault, column: StorageColumn) => string;
|
|
274
|
+
/**
|
|
275
|
+
* Target-supplied callback that computes the schema-qualified annotation-map
|
|
276
|
+
* key for a namespace-scoped enum storage type.
|
|
277
|
+
*
|
|
278
|
+
* Enum lookups (`readExistingEnumValues`) are namespace/schema-qualified so two
|
|
279
|
+
* namespaces holding an enum with the same TypeScript name (and even the same
|
|
280
|
+
* native type) resolve to distinct live-database types. The *format* of that
|
|
281
|
+
* key — and the namespace → DDL-schema resolution it depends on — is a
|
|
282
|
+
* target-specific concern (Postgres schemas; SQLite/MySQL differ), so the
|
|
283
|
+
* target injects it here as data rather than the family layer importing a
|
|
284
|
+
* concrete `ddlSchemaName`/key implementation. This keeps the family layer
|
|
285
|
+
* target-agnostic (no `@prisma-next/target-*` dependency) while the projection
|
|
286
|
+
* still emits keys that match the target's read side exactly.
|
|
287
|
+
*/
|
|
288
|
+
type EnumStorageKeyResolver = (storage: SqlStorage, namespaceId: string, nativeType: string) => string;
|
|
274
289
|
/**
|
|
275
290
|
* Detects destructive changes between two contract storages.
|
|
276
291
|
*
|
|
@@ -285,6 +300,14 @@ interface ContractToSchemaIROptions {
|
|
|
285
300
|
readonly annotationNamespace: string;
|
|
286
301
|
readonly expandNativeType?: NativeTypeExpander;
|
|
287
302
|
readonly renderDefault?: DefaultRenderer;
|
|
303
|
+
/**
|
|
304
|
+
* Target-supplied resolver for namespace/schema-qualified enum annotation
|
|
305
|
+
* keys. When provided (Postgres), every namespace-scoped enum is keyed by the
|
|
306
|
+
* resolver's output so the projected `storageTypes` map matches the target's
|
|
307
|
+
* `readExistingEnumValues` lookup. Targets without namespace-qualified enum
|
|
308
|
+
* storage (SQLite) omit it; enums are absent there.
|
|
309
|
+
*/
|
|
310
|
+
readonly resolveEnumStorageKey?: EnumStorageKeyResolver;
|
|
288
311
|
}
|
|
289
312
|
/**
|
|
290
313
|
* Converts a `Contract` to `SqlSchemaIR`.
|
|
@@ -411,5 +434,5 @@ declare function temporalAuthoringPresets<const CodecId extends string, const Na
|
|
|
411
434
|
//#region src/exports/control.d.ts
|
|
412
435
|
declare const _default: SqlFamilyDescriptor;
|
|
413
436
|
//#endregion
|
|
414
|
-
export { type CodecControlHooks, type ContractToSchemaIROptions, type CreateSqlMigrationPlanOptions, type DefaultRenderer, type ExpandNativeTypeInput, type FieldEvent, type FieldEventContext, INIT_ADDITIVE_POLICY, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerResult, type MultiSpaceRunnerFailure, type MultiSpaceRunnerResult, type MultiSpaceRunnerSuccessValue, type NativeTypeExpander, type PlanFieldEventOperationsOptions, type ResolveIdentityValueInput, type SqlControlAdapterDescriptor, type SqlControlExtensionDescriptor, type SqlControlFamilyInstance, type SqlControlTargetDescriptor, type SqlMigrationPlan, type SqlMigrationPlanContractInfo, type SqlMigrationPlanOperation, type SqlMigrationPlanOperationStep, type SqlMigrationPlanOperationTarget, type SqlMigrationPlanner, type SqlMigrationPlannerPlanOptions, type SqlMigrationRunner, type SqlMigrationRunnerErrorCode, type SqlMigrationRunnerExecuteCallbacks, type SqlMigrationRunnerExecuteOptions, type SqlMigrationRunnerFailure, type SqlMigrationRunnerResult, type SqlMigrationRunnerSuccessValue, type SqlPlanTargetDetails, type SqlPlannerConflict, type SqlPlannerConflictKind, type SqlPlannerConflictLocation, type SqlPlannerFailureResult, type SqlPlannerResult, type SqlPlannerSuccessResult, type StorageTypePlanResult, type TargetMigrationsCapability, assembleAuthoringContributions, contractToSchemaIR, createMigrationPlan, _default as default, detectDestructiveChanges, extractCodecControlHooks, planFieldEventOperations, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess, temporalAuthoringPresets, timestampNowControlDescriptor };
|
|
437
|
+
export { type CodecControlHooks, type ContractToSchemaIROptions, type CreateSqlMigrationPlanOptions, type DefaultRenderer, type EnumStorageKeyResolver, type ExpandNativeTypeInput, type FieldEvent, type FieldEventContext, INIT_ADDITIVE_POLICY, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerResult, type MultiSpaceRunnerFailure, type MultiSpaceRunnerResult, type MultiSpaceRunnerSuccessValue, type NativeTypeExpander, type PlanFieldEventOperationsOptions, type ResolveIdentityValueInput, type SqlControlAdapterDescriptor, type SqlControlExtensionDescriptor, type SqlControlFamilyInstance, type SqlControlTargetDescriptor, type SqlMigrationPlan, type SqlMigrationPlanContractInfo, type SqlMigrationPlanOperation, type SqlMigrationPlanOperationStep, type SqlMigrationPlanOperationTarget, type SqlMigrationPlanner, type SqlMigrationPlannerPlanOptions, type SqlMigrationRunner, type SqlMigrationRunnerErrorCode, type SqlMigrationRunnerExecuteCallbacks, type SqlMigrationRunnerExecuteOptions, type SqlMigrationRunnerFailure, type SqlMigrationRunnerResult, type SqlMigrationRunnerSuccessValue, type SqlPlanTargetDetails, type SqlPlannerConflict, type SqlPlannerConflictKind, type SqlPlannerConflictLocation, type SqlPlannerFailureResult, type SqlPlannerResult, type SqlPlannerSuccessResult, type StorageTypePlanResult, type TargetMigrationsCapability, assembleAuthoringContributions, contractToSchemaIR, createMigrationPlan, _default as default, detectDestructiveChanges, extractCodecControlHooks, planFieldEventOperations, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess, temporalAuthoringPresets, timestampNowControlDescriptor };
|
|
415
438
|
//# sourceMappingURL=control.d.mts.map
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/field-event-planner.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;cAUa,mBAAA,YACA,uBAAA,QAA+B,wBAAA;EAAA,SAEjC,IAAA;EAAA,SACA,EAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA,EAAU,WAAA;EAAA,SACV,SAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKT,MAAA,0BAAA,CACE,KAAA,EAAO,YAAA,QAAoB,SAAA,IAC1B,wBAAA;AAAA;;;iBCHW,wBAAA,CACd,WAAA,EAAa,aAAA,CAAc,8BAAA,mBAC1B,GAAA,SAAY,iBAAA;;;;;;;;;ADdf;;;;
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/field-event-planner.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;cAUa,mBAAA,YACA,uBAAA,QAA+B,wBAAA;EAAA,SAEjC,IAAA;EAAA,SACA,EAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA,EAAU,WAAA;EAAA,SACV,SAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKT,MAAA,0BAAA,CACE,KAAA,EAAO,YAAA,QAAoB,SAAA,IAC1B,wBAAA;AAAA;;;iBCHW,wBAAA,CACd,WAAA,EAAa,aAAA,CAAc,8BAAA,mBAC1B,GAAA,SAAY,iBAAA;;;;;;;;;ADdf;;;;KE4BY,kBAAA,IAAsB,KAAA;EAAA,SACvB,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;;;;;;;;;;KAYlB,eAAA,IAAmB,GAAA,EAAK,aAAA,EAAe,MAAA,EAAQ,aAAa;;;;;;;;;;;;;;;KAgB5D,sBAAA,IACV,OAAA,EAAS,UAAU,EACnB,WAAA,UACA,UAAA;;;;;;;;;;iBAmKc,wBAAA,CACd,IAAA,EAAM,UAAA,SACN,EAAA,EAAI,UAAA,YACM,0BAAA;AAAA,UA8CK,yBAAA;EAAA,SACN,mBAAA;EAAA,SACA,gBAAA,GAAmB,kBAAA;EAAA,SACnB,aAAA,GAAgB,eAAA;;;;;;;;WAQhB,qBAAA,GAAwB,sBAAA;AAAA;;;;;;;;;;;;;;;iBAiBnB,kBAAA,CACd,QAAA,EAAU,QAAA,CAAS,UAAA,UACnB,OAAA,EAAS,yBAAA,GACR,WAAA;;;UC9Rc,+BAAA;EHZI;;;;EAAA,SGiBV,aAAA,EAAe,QAAA,CAAS,UAAA;;;;WAIxB,WAAA,EAAa,QAAA,CAAS,UAAA;;;;;;;;;;WAUtB,UAAA,EAAY,WAAA,SAAoB,iBAAA;AAAA;AAAA,iBAa3B,wBAAA,CACd,OAAA,EAAS,+BAAA,YACC,aAAa;;;iBCgCT,mBAAA,gBAAA,CACd,OAAA,EAAS,6BAAA,CAA8B,cAAA,IACtC,gBAAA,CAAiB,cAAA;AAAA,iBAcJ,cAAA,gBAAA,CACd,IAAA,EAAM,gBAAA,CAAiB,cAAA,IACtB,uBAAA,CAAwB,cAAA;AAAA,iBAOX,cAAA,CAAe,SAAA,WAAoB,kBAAA,KAAuB,uBAAuB;;;;iBAoBjF,aAAA,CAAc,KAAA;EAC5B,iBAAA;EACA,kBAAA;AAAA,IACE,EAAE,CAAC,8BAAA;;;;iBAYS,aAAA,CACd,IAAA,EAAM,2BAAA,EACN,OAAA,UACA,OAAA;EAAY,GAAA;EAAc,IAAA,GAAO,SAAA;AAAA,IAChC,KAAA,CAAM,yBAAA;;;;;;cC1JI,oBAAA,EAAsB,0BAEjC;;;;;;;;;;;;;;iBCoBc,6BAAA,CAAA,GAAiC,kCAAkC;;;;;;;;;;;iBAoBnE,wBAAA,+DAAA,CAGd,KAAA;EAAA,SAAkB,OAAA,EAAS,OAAA;EAAA,SAAkB,UAAA,EAAY,UAAA;AAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cC0BlB,QAAA"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as sqlFamilyAuthoringFieldPresets, t as sqlFamilyAuthoringTypes } from "./authoring-type-constructors-F4JpCJl7.mjs";
|
|
2
2
|
import { t as SqlContractSerializer } from "./sql-contract-serializer-BXa6wp51.mjs";
|
|
3
|
-
import { a as extractCodecControlHooks, t as verifySqlSchema } from "./verify-sql-schema-
|
|
3
|
+
import { a as extractCodecControlHooks, t as verifySqlSchema } from "./verify-sql-schema-CYLsGCFO.mjs";
|
|
4
4
|
import { t as collectSupportedCodecTypeIds } from "./verify-Crewz6hG.mjs";
|
|
5
5
|
import { n as temporalAuthoringPresets, r as timestampNowControlDescriptor } from "./timestamp-now-generator-r7BP5n3l.mjs";
|
|
6
6
|
import { sqlEmission } from "@prisma-next/sql-contract-emitter";
|
|
@@ -9,6 +9,7 @@ import { assertDescriptorSelfConsistency } from "@prisma-next/migration-tools/sp
|
|
|
9
9
|
import { ensureSchemaStatement, ensureTableStatement, writeContractMarker } from "@prisma-next/sql-runtime";
|
|
10
10
|
import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
11
11
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
12
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
12
13
|
import { StorageTable, isPostgresEnumStorageEntry, isStorageTypeInstance, toStorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
13
14
|
import { UNSPECIFIED_PSL_NAMESPACE_ID } from "@prisma-next/framework-components/psl-ast";
|
|
14
15
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
@@ -1211,6 +1212,7 @@ function createSqlFamilyInstance(stack) {
|
|
|
1211
1212
|
verifySchema(options) {
|
|
1212
1213
|
const contract = deserializeWithTargetSerializer(options.contract);
|
|
1213
1214
|
const controlAdapter = getControlAdapter();
|
|
1215
|
+
const resolveExistingEnumValues = controlAdapter.resolveExistingEnumValuesForContract?.(contract) ?? controlAdapter.resolveExistingEnumValues;
|
|
1214
1216
|
return verifySqlSchema({
|
|
1215
1217
|
contract,
|
|
1216
1218
|
schema: options.schema,
|
|
@@ -1219,7 +1221,7 @@ function createSqlFamilyInstance(stack) {
|
|
|
1219
1221
|
frameworkComponents: options.frameworkComponents,
|
|
1220
1222
|
...ifDefined("normalizeDefault", controlAdapter.normalizeDefault),
|
|
1221
1223
|
...ifDefined("normalizeNativeType", controlAdapter.normalizeNativeType),
|
|
1222
|
-
...ifDefined("resolveExistingEnumValues",
|
|
1224
|
+
...ifDefined("resolveExistingEnumValues", resolveExistingEnumValues)
|
|
1223
1225
|
});
|
|
1224
1226
|
},
|
|
1225
1227
|
async sign(options) {
|
|
@@ -1572,30 +1574,44 @@ function contractToSchemaIR(contract, options) {
|
|
|
1572
1574
|
}
|
|
1573
1575
|
return {
|
|
1574
1576
|
tables,
|
|
1575
|
-
...ifDefined("annotations", deriveAnnotations(storage, options.annotationNamespace))
|
|
1577
|
+
...ifDefined("annotations", deriveAnnotations(storage, options.annotationNamespace, options.resolveEnumStorageKey))
|
|
1576
1578
|
};
|
|
1577
1579
|
}
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1580
|
+
/**
|
|
1581
|
+
* Normalises a native enum storage entry to the codec-typed annotation shape
|
|
1582
|
+
* `{codecId, nativeType, typeParams}` the introspector writes and
|
|
1583
|
+
* `readExistingEnumValues` reads (`existing.codecId` + `existing.typeParams.values`).
|
|
1584
|
+
* Without this the projector would emit the raw `PostgresEnumStorageEntry`
|
|
1585
|
+
* shape (top-level `values`, no `typeParams`) and the enum would read as new.
|
|
1586
|
+
*/
|
|
1587
|
+
function normalizeEnumAnnotation(entry) {
|
|
1588
|
+
return toStorageTypeInstance({
|
|
1589
|
+
codecId: entry.codecId,
|
|
1590
|
+
nativeType: entry.nativeType,
|
|
1591
|
+
typeParams: { values: entry.values }
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
function deriveAnnotations(storage, annotationNamespace, resolveEnumStorageKey) {
|
|
1595
|
+
const storageTypes = {};
|
|
1596
|
+
for (const typeInstance of Object.values(storage.types ?? {})) {
|
|
1588
1597
|
if (isPostgresEnumStorageEntry(typeInstance)) {
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
nativeType: typeInstance.nativeType,
|
|
1592
|
-
typeParams: { values: typeInstance.values }
|
|
1593
|
-
});
|
|
1598
|
+
const key = resolveEnumStorageKey ? resolveEnumStorageKey(storage, UNBOUND_NAMESPACE_ID, typeInstance.nativeType) : typeInstance.nativeType;
|
|
1599
|
+
storageTypes[key] = normalizeEnumAnnotation(typeInstance);
|
|
1594
1600
|
continue;
|
|
1595
1601
|
}
|
|
1596
|
-
if (isStorageTypeInstance(typeInstance))
|
|
1602
|
+
if (isStorageTypeInstance(typeInstance)) storageTypes[typeInstance.nativeType] = typeInstance;
|
|
1603
|
+
}
|
|
1604
|
+
for (const [namespaceId, ns] of Object.entries(storage.namespaces)) {
|
|
1605
|
+
const nsEnums = ns.enum;
|
|
1606
|
+
if (!nsEnums) continue;
|
|
1607
|
+
for (const entry of Object.values(nsEnums)) {
|
|
1608
|
+
if (!isPostgresEnumStorageEntry(entry)) continue;
|
|
1609
|
+
const key = resolveEnumStorageKey ? resolveEnumStorageKey(storage, namespaceId, entry.nativeType) : entry.nativeType;
|
|
1610
|
+
storageTypes[key] = normalizeEnumAnnotation(entry);
|
|
1611
|
+
}
|
|
1597
1612
|
}
|
|
1598
|
-
|
|
1613
|
+
if (Object.keys(storageTypes).length === 0) return void 0;
|
|
1614
|
+
return { [annotationNamespace]: { storageTypes } };
|
|
1599
1615
|
}
|
|
1600
1616
|
//#endregion
|
|
1601
1617
|
//#region src/core/migrations/field-event-planner.ts
|