joist-codegen 2.4.0 → 2.5.0-next.10
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/build/EntityDbMetadata.cjs +50 -8
- package/build/EntityDbMetadata.cjs.map +1 -1
- package/build/EntityDbMetadata.d.cts +36 -28
- package/build/EntityDbMetadata.d.cts.map +1 -1
- package/build/EntityDbMetadata.d.mts +36 -28
- package/build/EntityDbMetadata.d.mts.map +1 -1
- package/build/EntityDbMetadata.js +50 -9
- package/build/EntityDbMetadata.js.map +1 -1
- package/build/_virtual/_rolldown/runtime.cjs +1 -2
- package/build/_virtual/_rolldown/runtime.js +1 -2
- package/build/assignTags.cjs +2 -3
- package/build/assignTags.d.cts +1 -4
- package/build/assignTags.d.cts.map +1 -1
- package/build/assignTags.d.mts +1 -4
- package/build/assignTags.d.mts.map +1 -1
- package/build/assignTags.js +2 -3
- package/build/codemods/Codemod.d.cts +1 -4
- package/build/codemods/Codemod.d.cts.map +1 -1
- package/build/codemods/Codemod.d.mts +1 -4
- package/build/codemods/Codemod.d.mts.map +1 -1
- package/build/codemods/JscodeshiftMod.cjs +2 -3
- package/build/codemods/JscodeshiftMod.d.cts +1 -4
- package/build/codemods/JscodeshiftMod.d.cts.map +1 -1
- package/build/codemods/JscodeshiftMod.d.mts +1 -4
- package/build/codemods/JscodeshiftMod.d.mts.map +1 -1
- package/build/codemods/JscodeshiftMod.js +2 -3
- package/build/codemods/codemod_0001-rename_has_async_property.cjs +1 -2
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts +2 -4
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts +2 -4
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.js +1 -2
- package/build/codemods/codemod_0002-rename_async_query_fields.cjs +1 -2
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts +2 -4
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts.map +1 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts +2 -4
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts.map +1 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.js +1 -2
- package/build/codemods/codemod_0003-rename_find_paginated.cjs +1 -2
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts +2 -4
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts +2 -4
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.js +1 -2
- package/build/codemods/index.cjs +2 -3
- package/build/codemods/index.d.cts +3 -6
- package/build/codemods/index.d.cts.map +1 -1
- package/build/codemods/index.d.mts +3 -6
- package/build/codemods/index.d.mts.map +1 -1
- package/build/codemods/index.js +2 -3
- package/build/config.cjs +11 -7
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +30 -29
- package/build/config.d.cts.map +1 -1
- package/build/config.d.mts +30 -29
- package/build/config.d.mts.map +1 -1
- package/build/config.js +11 -7
- package/build/config.js.map +1 -1
- package/build/docs/cache.cjs +1 -2
- package/build/docs/cache.cjs.map +1 -1
- package/build/docs/cache.d.cts +2 -5
- package/build/docs/cache.d.cts.map +1 -1
- package/build/docs/cache.d.mts +2 -5
- package/build/docs/cache.d.mts.map +1 -1
- package/build/docs/cache.js +1 -2
- package/build/docs/cache.js.map +1 -1
- package/build/docs/generate-metadata-docs.cjs +2 -3
- package/build/docs/generate-metadata-docs.d.cts +1 -4
- package/build/docs/generate-metadata-docs.d.cts.map +1 -1
- package/build/docs/generate-metadata-docs.d.mts +1 -4
- package/build/docs/generate-metadata-docs.d.mts.map +1 -1
- package/build/docs/generate-metadata-docs.js +2 -3
- package/build/docs/index.cjs +1 -2
- package/build/docs/index.d.cts +3 -5
- package/build/docs/index.d.cts.map +1 -1
- package/build/docs/index.d.mts +3 -5
- package/build/docs/index.d.mts.map +1 -1
- package/build/docs/index.js +1 -2
- package/build/docs/markdown.cjs +1 -2
- package/build/docs/markdown.d.cts +8 -10
- package/build/docs/markdown.d.cts.map +1 -1
- package/build/docs/markdown.d.mts +8 -10
- package/build/docs/markdown.d.mts.map +1 -1
- package/build/docs/markdown.js +1 -2
- package/build/docs/parsing.cjs +1 -2
- package/build/docs/parsing.d.cts +9 -11
- package/build/docs/parsing.d.cts.map +1 -1
- package/build/docs/parsing.d.mts +9 -11
- package/build/docs/parsing.d.mts.map +1 -1
- package/build/docs/parsing.js +1 -2
- package/build/findEntityScopes.cjs +1 -2
- package/build/findEntityScopes.d.cts +3 -6
- package/build/findEntityScopes.d.cts.map +1 -1
- package/build/findEntityScopes.d.mts +3 -6
- package/build/findEntityScopes.d.mts.map +1 -1
- package/build/findEntityScopes.js +1 -2
- package/build/foreignKeyOrdering.cjs +4 -5
- package/build/foreignKeyOrdering.d.cts +1 -4
- package/build/foreignKeyOrdering.d.cts.map +1 -1
- package/build/foreignKeyOrdering.d.mts +1 -4
- package/build/foreignKeyOrdering.d.mts.map +1 -1
- package/build/foreignKeyOrdering.js +4 -5
- package/build/generate.cjs +4 -5
- package/build/generate.cjs.map +1 -1
- package/build/generate.d.cts +3 -6
- package/build/generate.d.cts.map +1 -1
- package/build/generate.d.mts +3 -6
- package/build/generate.d.mts.map +1 -1
- package/build/generate.js +4 -5
- package/build/generateEntitiesFile.cjs +4 -5
- package/build/generateEntitiesFile.d.cts +3 -6
- package/build/generateEntitiesFile.d.cts.map +1 -1
- package/build/generateEntitiesFile.d.mts +3 -6
- package/build/generateEntitiesFile.d.mts.map +1 -1
- package/build/generateEntitiesFile.js +4 -5
- package/build/generateEntityCodegenFile.cjs +39 -25
- package/build/generateEntityCodegenFile.cjs.map +1 -1
- package/build/generateEntityCodegenFile.d.cts +5 -8
- package/build/generateEntityCodegenFile.d.cts.map +1 -1
- package/build/generateEntityCodegenFile.d.mts +5 -8
- package/build/generateEntityCodegenFile.d.mts.map +1 -1
- package/build/generateEntityCodegenFile.js +39 -25
- package/build/generateEntityCodegenFile.js.map +1 -1
- package/build/generateEntityFile.cjs +1 -2
- package/build/generateEntityFile.d.cts +1 -4
- package/build/generateEntityFile.d.cts.map +1 -1
- package/build/generateEntityFile.d.mts +1 -4
- package/build/generateEntityFile.d.mts.map +1 -1
- package/build/generateEntityFile.js +1 -2
- package/build/generateEntityTestFile.cjs +1 -2
- package/build/generateEntityTestFile.d.cts +1 -4
- package/build/generateEntityTestFile.d.cts.map +1 -1
- package/build/generateEntityTestFile.d.mts +1 -4
- package/build/generateEntityTestFile.d.mts.map +1 -1
- package/build/generateEntityTestFile.js +1 -2
- package/build/generateEnumFile.cjs +2 -3
- package/build/generateEnumFile.d.cts +1 -4
- package/build/generateEnumFile.d.cts.map +1 -1
- package/build/generateEnumFile.d.mts +1 -4
- package/build/generateEnumFile.d.mts.map +1 -1
- package/build/generateEnumFile.js +2 -3
- package/build/generateFactoriesFiles.cjs +2 -3
- package/build/generateFactoriesFiles.d.cts +1 -4
- package/build/generateFactoriesFiles.d.cts.map +1 -1
- package/build/generateFactoriesFiles.d.mts +1 -4
- package/build/generateFactoriesFiles.d.mts.map +1 -1
- package/build/generateFactoriesFiles.js +2 -3
- package/build/generateFlushFunction.cjs +1 -2
- package/build/generateFlushFunction.d.cts +3 -6
- package/build/generateFlushFunction.d.cts.map +1 -1
- package/build/generateFlushFunction.d.mts +3 -6
- package/build/generateFlushFunction.d.mts.map +1 -1
- package/build/generateFlushFunction.js +1 -2
- package/build/generateMetadataFile.cjs +36 -5
- package/build/generateMetadataFile.cjs.map +1 -1
- package/build/generateMetadataFile.d.cts +2 -5
- package/build/generateMetadataFile.d.cts.map +1 -1
- package/build/generateMetadataFile.d.mts +2 -5
- package/build/generateMetadataFile.d.mts.map +1 -1
- package/build/generateMetadataFile.js +37 -6
- package/build/generateMetadataFile.js.map +1 -1
- package/build/generatePgEnumFile.cjs +1 -2
- package/build/generatePgEnumFile.d.cts +1 -4
- package/build/generatePgEnumFile.d.cts.map +1 -1
- package/build/generatePgEnumFile.d.mts +1 -4
- package/build/generatePgEnumFile.d.mts.map +1 -1
- package/build/generatePgEnumFile.js +1 -2
- package/build/index.cjs +8 -9
- package/build/index.d.cts +5 -7
- package/build/index.d.cts.map +1 -1
- package/build/index.d.mts +5 -7
- package/build/index.d.mts.map +1 -1
- package/build/index.js +8 -9
- package/build/inheritance.cjs +2 -3
- package/build/inheritance.d.cts +3 -5
- package/build/inheritance.d.cts.map +1 -1
- package/build/inheritance.d.mts +3 -5
- package/build/inheritance.d.mts.map +1 -1
- package/build/inheritance.js +2 -3
- package/build/installSkills.cjs +1 -2
- package/build/installSkills.d.cts +1 -4
- package/build/installSkills.d.cts.map +1 -1
- package/build/installSkills.d.mts +1 -4
- package/build/installSkills.d.mts.map +1 -1
- package/build/installSkills.js +1 -2
- package/build/keywords.cjs +1 -2
- package/build/keywords.d.cts +1 -4
- package/build/keywords.d.cts.map +1 -1
- package/build/keywords.d.mts +1 -4
- package/build/keywords.d.mts.map +1 -1
- package/build/keywords.js +1 -2
- package/build/loadMetadata.cjs +2 -3
- package/build/loadMetadata.d.cts +8 -11
- package/build/loadMetadata.d.cts.map +1 -1
- package/build/loadMetadata.d.mts +8 -11
- package/build/loadMetadata.d.mts.map +1 -1
- package/build/loadMetadata.js +2 -3
- package/build/logger.cjs +1 -2
- package/build/logger.d.cts +3 -6
- package/build/logger.d.cts.map +1 -1
- package/build/logger.d.mts +3 -6
- package/build/logger.d.mts.map +1 -1
- package/build/logger.js +1 -2
- package/build/pgMetadata.cjs +1 -2
- package/build/pgMetadata.d.cts +13 -16
- package/build/pgMetadata.d.cts.map +1 -1
- package/build/pgMetadata.d.mts +13 -16
- package/build/pgMetadata.d.mts.map +1 -1
- package/build/pgMetadata.js +1 -2
- package/build/scanEntityFiles.cjs +7 -3
- package/build/scanEntityFiles.cjs.map +1 -1
- package/build/scanEntityFiles.d.cts +2 -5
- package/build/scanEntityFiles.d.cts.map +1 -1
- package/build/scanEntityFiles.d.mts +2 -5
- package/build/scanEntityFiles.d.mts.map +1 -1
- package/build/scanEntityFiles.js +7 -3
- package/build/scanEntityFiles.js.map +1 -1
- package/build/sortForeignKeys.cjs +1 -2
- package/build/sortForeignKeys.d.cts +1 -4
- package/build/sortForeignKeys.d.cts.map +1 -1
- package/build/sortForeignKeys.d.mts +1 -4
- package/build/sortForeignKeys.d.mts.map +1 -1
- package/build/sortForeignKeys.js +1 -2
- package/build/symbols.cjs +3 -2
- package/build/symbols.cjs.map +1 -1
- package/build/symbols.d.cts +117 -119
- package/build/symbols.d.cts.map +1 -1
- package/build/symbols.d.mts +117 -119
- package/build/symbols.d.mts.map +1 -1
- package/build/symbols.js +3 -3
- package/build/symbols.js.map +1 -1
- package/build/tsdoc.cjs +1 -2
- package/build/tsdoc.d.cts +1 -4
- package/build/tsdoc.d.cts.map +1 -1
- package/build/tsdoc.d.mts +1 -4
- package/build/tsdoc.d.mts.map +1 -1
- package/build/tsdoc.js +1 -2
- package/build/utils.cjs +3 -3
- package/build/utils.cjs.map +1 -1
- package/build/utils.d.cts +22 -25
- package/build/utils.d.cts.map +1 -1
- package/build/utils.d.mts +22 -25
- package/build/utils.d.mts.map +1 -1
- package/build/utils.js +3 -3
- package/build/utils.js.map +1 -1
- package/build/write-json-schema.cjs +1 -2
- package/build/write-json-schema.js +1 -2
- package/package.json +10 -10
- package/skills/joist-test-factories/SKILL.md +93 -6
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { assertNever, fail, uncapitalize } from "./utils.js";
|
|
2
|
-
import { getStiEntities } from "./inheritance.js";
|
|
3
1
|
import "./config.js";
|
|
4
|
-
import { buildJSDocBlock, generatedTag } from "./docs/parsing.js";
|
|
5
2
|
import "./docs/index.js";
|
|
3
|
+
import { getFieldReadIndexes } from "./EntityDbMetadata.js";
|
|
4
|
+
import { buildJSDocBlock, generatedTag } from "./docs/parsing.js";
|
|
6
5
|
import "./findEntityScopes.js";
|
|
6
|
+
import { getStiEntities } from "./inheritance.js";
|
|
7
7
|
import { keywords } from "./keywords.js";
|
|
8
8
|
import { BaseEntity, BooleanFilter, BooleanGraphQLFilter, Changes, Collection, ConfigApi, DeepPartialOrNull, EntityFilter, EntityGraphQLFilter, EntityManager, EntityMetadata, EnumCollection, FieldsOf, FilterOf, Flavor, GraphQLFilterOf, IdOf, JsonPayload, LargeCollection, LazyField, Lens, LoadHint, Loaded, ManyToOneReference, MaybeAbstractEntityConstructor, OneToOneReference, OptsOf, OrderBy, PartialOrNull, PolymorphicReference, ProjectEntity, ReactiveField, ReactiveManyToMany, ReactiveManyToManyOtherSide, ReactiveReference, ReadOnlyCollection, RelationsOf, SSAssert, Scope, TaggedId, ToJsonHint, ValueFilter, ValueGraphQLFilter, Zod, cannotBeUpdated, failNoIdYet, getField, hasEnumCollection, hasLargeMany, hasLargeManyToMany, hasLazyField, hasMany, hasManyToMany, hasOne, hasOnePolymorphic, hasOneToOne, hasReactiveManyToManyOtherSide, hasRecursiveChildren, hasRecursiveM2m, hasRecursiveParents, isEntity, isLoaded, loadLens, mustBeSubType, newChangesProxy, newRequiredLazyFieldRule, newRequiredRule, newScopeFn, nowUTC, setField, setOpts, toIdOf, toJSON, updatePartial } from "./symbols.js";
|
|
9
9
|
import { tsdocComments } from "./tsdoc.js";
|
|
10
|
-
import "./
|
|
10
|
+
import { assertNever, fail, uncapitalize } from "./utils.js";
|
|
11
11
|
import { camelCase, pascalCase } from "change-case";
|
|
12
12
|
import pluralize from "pluralize";
|
|
13
13
|
import { code, imp, joinCode } from "ts-poet";
|
|
14
|
-
|
|
14
|
+
// src/generateEntityCodegenFile.ts
|
|
15
15
|
const { plural } = pluralize;
|
|
16
16
|
/** Creates the base class with the boilerplate annotations. */
|
|
17
17
|
function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs) {
|
|
@@ -20,17 +20,21 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
20
20
|
const entityName = entity.name;
|
|
21
21
|
const fieldDocs = docs?.fields ?? {};
|
|
22
22
|
const varName = keywords.includes(tagName) ? uncapitalize(entityName) : tagName;
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
primitives
|
|
26
|
-
primitives.push(...
|
|
23
|
+
const readIndexes = getFieldReadIndexes(meta);
|
|
24
|
+
const extraReadWords = meta.baseClassName ? [] : Array.from({ length: Math.ceil(readIndexes.size / 32) - 1 }, (_, word) => code`declare protected __readFields${word + 1}: number;`);
|
|
25
|
+
const primitives = createPrimitives(meta, entity, fieldDocs, readIndexes);
|
|
26
|
+
primitives.push(...createRegularEnums(meta, entity, fieldDocs, readIndexes));
|
|
27
|
+
primitives.push(...createArrayEnums(meta, fieldDocs, readIndexes));
|
|
28
|
+
primitives.push(...createPgEnums(meta, fieldDocs, readIndexes));
|
|
27
29
|
const relations = createRelations(config, meta, entity);
|
|
28
30
|
const configName = `${camelCase(entityName)}Config`;
|
|
29
31
|
const scopeFnName = `${camelCase(entityName)}Scope`;
|
|
30
32
|
const metadata = imp(`${camelCase(entityName)}Meta@./entities.ts`);
|
|
31
33
|
const contextType = config.contextType ? imp(`t:${config.contextType}`) : "{}";
|
|
32
34
|
const factoryMethod = imp(`new${entity.name}@./entities.ts`);
|
|
33
|
-
const idMaybeCode = config.idType === "tagged-string" ? code`return this.idTaggedMaybe;` : code`
|
|
35
|
+
const idMaybeCode = !config.idType || config.idType === "tagged-string" ? code`return this.idTaggedMaybe;` : code`
|
|
36
|
+
return (this.__data.idCache ??= ${toIdOf}(${metadata}, this.idTaggedMaybe)) as ${entity.idName} | undefined;
|
|
37
|
+
`;
|
|
34
38
|
const idType = getIdType(config);
|
|
35
39
|
const maybeSoftDeleteMethods = meta.deletedAt ? code`
|
|
36
40
|
get isSoftDeletedEntity(): boolean {
|
|
@@ -65,6 +69,7 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
65
69
|
const maybeBaseFilter = baseEntity ? code`extends ${imp("t:" + baseEntity.entity.filterName + "@./entities.ts")}` : "";
|
|
66
70
|
const maybeBaseGqlFilter = baseEntity ? code`extends ${imp("t:" + baseEntity.entity.graphqlFilterName + "@./entities.ts")}` : "";
|
|
67
71
|
const maybeBaseOrder = baseEntity ? code`extends ${baseEntity.entity.orderType}` : "";
|
|
72
|
+
const maybeBaseFactoryExtras = baseEntity ? code`extends ${imp("t:" + baseEntity.entity.factoryExtrasName + "@./entities.ts")}` : "";
|
|
68
73
|
meta.abstract && code`
|
|
69
74
|
if (this.constructor === ${entity.type} && !(em as any).fakeInstance) {
|
|
70
75
|
throw new Error(\`${entity.type} must be instantiated via a subtype\`);
|
|
@@ -108,7 +113,7 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
108
113
|
${generateOrderFields(meta)}
|
|
109
114
|
}
|
|
110
115
|
|
|
111
|
-
export interface ${entity.factoryExtrasName} {
|
|
116
|
+
export interface ${entity.factoryExtrasName} ${maybeBaseFactoryExtras} {
|
|
112
117
|
${generateFactoryExtrasType(meta)}
|
|
113
118
|
}
|
|
114
119
|
|
|
@@ -148,6 +153,8 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
148
153
|
static readonly tagName = "${tagName}";
|
|
149
154
|
static readonly metadata: ${EntityMetadata}<${entity.type}>;
|
|
150
155
|
|
|
156
|
+
${extraReadWords}
|
|
157
|
+
|
|
151
158
|
declare readonly __type: {
|
|
152
159
|
${baseEntity ? `0: "${baseEntity.name}",` : ""}
|
|
153
160
|
${baseEntity ? 1 : 0}: "${entityName}",
|
|
@@ -176,7 +183,7 @@ function generateEntityCodegenFile(config, dbMeta, meta, scopeMembers = [], docs
|
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
get idTaggedMaybe(): ${TaggedId} | undefined {
|
|
179
|
-
return ${
|
|
186
|
+
return ${fieldReadExpression(readIndexes, "id")};
|
|
180
187
|
}
|
|
181
188
|
|
|
182
189
|
${primitives}
|
|
@@ -352,8 +359,9 @@ function generateFieldsType(meta, idType) {
|
|
|
352
359
|
return code`${fieldName}: { kind: "primitive"; type: ${fieldType}; unique: ${unique}; nullable: ${undefinedOrNever(notNull)}, derived: ${derived !== false}; };`;
|
|
353
360
|
});
|
|
354
361
|
const enums = meta.enums.map((field) => {
|
|
355
|
-
const { fieldName, enumType, notNull, isArray } = field;
|
|
362
|
+
const { fieldName, enumType, notNull, isArray, hasTransitions } = field;
|
|
356
363
|
if (isArray) return code`${fieldName}: { kind: "enum"; type: ${enumType}[]; nullable: never; };`;
|
|
364
|
+
else if (hasTransitions) return code`${fieldName}: { kind: "enum"; type: ${enumType}; nullable: ${undefinedOrNever(notNull)}; accessors: keyof typeof ${enumType}; };`;
|
|
357
365
|
else return code`${fieldName}: { kind: "enum"; type: ${enumType}; nullable: ${undefinedOrNever(notNull)}; };`;
|
|
358
366
|
});
|
|
359
367
|
const pgEnums = meta.pgEnums.map((field) => {
|
|
@@ -596,14 +604,14 @@ function generateFactoryExtrasType(meta) {
|
|
|
596
604
|
const { fieldName, fieldType, notNull } = field;
|
|
597
605
|
return code`${withName(fieldName)}?: ${fieldType}${maybeUnionNull(notNull)};`;
|
|
598
606
|
});
|
|
599
|
-
const enums = meta.enums.filter((f) => f.derived === "async").map((field) => {
|
|
607
|
+
const enums = meta.enums.filter((f) => f.derived === "async" || f.hasTransitions).map((field) => {
|
|
600
608
|
const { fieldName, enumType, notNull, isArray } = field;
|
|
601
609
|
if (isArray) return code`${withName(fieldName)}?: ${enumType}[];`;
|
|
602
610
|
else return code`${withName(fieldName)}?: ${enumType}${maybeUnionNull(notNull)};`;
|
|
603
611
|
});
|
|
604
612
|
return [...primitives, ...enums];
|
|
605
613
|
}
|
|
606
|
-
function createPrimitives(meta, entity, fieldDocs) {
|
|
614
|
+
function createPrimitives(meta, entity, fieldDocs, readIndexes) {
|
|
607
615
|
return meta.primitives.map((p) => {
|
|
608
616
|
const { fieldName, fieldType, notNull } = p;
|
|
609
617
|
const maybeOptional = notNull ? "" : " | undefined";
|
|
@@ -617,12 +625,12 @@ function createPrimitives(meta, entity, fieldDocs) {
|
|
|
617
625
|
`;
|
|
618
626
|
else if (p.zodSchema) getter = code`
|
|
619
627
|
get ${fieldName}(): ${Zod}.output<typeof ${p.zodSchema}>${maybeOptional} {
|
|
620
|
-
return ${
|
|
628
|
+
return ${fieldReadExpression(readIndexes, fieldName)};
|
|
621
629
|
}
|
|
622
630
|
`;
|
|
623
631
|
else getter = code`
|
|
624
632
|
get ${fieldName}(): ${fieldType}${maybeOptional} {
|
|
625
|
-
return ${
|
|
633
|
+
return ${fieldReadExpression(readIndexes, fieldName)};
|
|
626
634
|
}
|
|
627
635
|
`;
|
|
628
636
|
let setter;
|
|
@@ -658,7 +666,7 @@ function createPrimitives(meta, entity, fieldDocs) {
|
|
|
658
666
|
return code`${fieldDocBlock(fieldDocs, fieldName, entity.name)}${getter} ${setter}`;
|
|
659
667
|
});
|
|
660
668
|
}
|
|
661
|
-
function createRegularEnums(meta, entity, fieldDocs) {
|
|
669
|
+
function createRegularEnums(meta, entity, fieldDocs, readIndexes) {
|
|
662
670
|
return meta.enums.filter((e) => !e.isArray).flatMap((e) => {
|
|
663
671
|
const { fieldName, enumType, enumDetailType, enumDetailsType, notNull, enumRows, derived } = e;
|
|
664
672
|
const maybeOptional = notNull ? "" : " | undefined";
|
|
@@ -672,7 +680,7 @@ function createRegularEnums(meta, entity, fieldDocs) {
|
|
|
672
680
|
`;
|
|
673
681
|
else getter = code`
|
|
674
682
|
get ${fieldName}(): ${enumType}${maybeOptional} {
|
|
675
|
-
return ${
|
|
683
|
+
return ${fieldReadExpression(readIndexes, fieldName)};
|
|
676
684
|
}
|
|
677
685
|
|
|
678
686
|
get ${fieldName}Details(): ${enumDetailsType}${maybeOptional} {
|
|
@@ -690,7 +698,7 @@ function createRegularEnums(meta, entity, fieldDocs) {
|
|
|
690
698
|
const shouldPrefixAccessors = meta.enums.filter((other) => other !== e).some((other) => other.enumRows.some((r) => codes.has(r.code)));
|
|
691
699
|
const accessors = enumRows.map((row) => code`
|
|
692
700
|
get is${shouldPrefixAccessors ? pascalCase(fieldName) : ""}${pascalCase(row.code)}(): boolean {
|
|
693
|
-
return ${getField}(this, "${fieldName}") === ${enumType}.${pascalCase(row.code)};
|
|
701
|
+
return ${derived ? code`${getField}(this, "${fieldName}")` : code`this.${fieldName}`} === ${enumType}.${pascalCase(row.code)};
|
|
694
702
|
}
|
|
695
703
|
`);
|
|
696
704
|
return [
|
|
@@ -700,12 +708,12 @@ function createRegularEnums(meta, entity, fieldDocs) {
|
|
|
700
708
|
];
|
|
701
709
|
});
|
|
702
710
|
}
|
|
703
|
-
function createArrayEnums(meta, fieldDocs) {
|
|
711
|
+
function createArrayEnums(meta, fieldDocs, readIndexes) {
|
|
704
712
|
return meta.enums.filter((e) => e.isArray).flatMap((e) => {
|
|
705
713
|
const { fieldName, enumType, enumDetailType, enumDetailsType, enumRows } = e;
|
|
706
714
|
const getter = code`
|
|
707
715
|
get ${fieldName}(): ${enumType}[] {
|
|
708
|
-
return ${
|
|
716
|
+
return (${fieldReadExpression(readIndexes, fieldName)}) || [];
|
|
709
717
|
}
|
|
710
718
|
|
|
711
719
|
get ${fieldName}Details(): ${enumDetailsType}[] {
|
|
@@ -731,13 +739,13 @@ function createArrayEnums(meta, fieldDocs) {
|
|
|
731
739
|
];
|
|
732
740
|
});
|
|
733
741
|
}
|
|
734
|
-
function createPgEnums(meta, fieldDocs) {
|
|
742
|
+
function createPgEnums(meta, fieldDocs, readIndexes) {
|
|
735
743
|
return meta.pgEnums.flatMap((e) => {
|
|
736
744
|
const { fieldName, enumType, enumValues, notNull } = e;
|
|
737
745
|
const maybeOptional = notNull ? "" : " | undefined";
|
|
738
746
|
const getter = code`
|
|
739
747
|
get ${fieldName}(): ${enumType}${maybeOptional} {
|
|
740
|
-
return ${
|
|
748
|
+
return ${fieldReadExpression(readIndexes, fieldName)};
|
|
741
749
|
}
|
|
742
750
|
`;
|
|
743
751
|
const setter = code`
|
|
@@ -1001,7 +1009,13 @@ function getIdType(config) {
|
|
|
1001
1009
|
default: return assertNever(config.idType);
|
|
1002
1010
|
}
|
|
1003
1011
|
}
|
|
1004
|
-
|
|
1012
|
+
/** Emits a conditional warm read directly from data, falling back to getField for the first read. */
|
|
1013
|
+
function fieldReadExpression(indexes, fieldName) {
|
|
1014
|
+
const index = indexes.get(fieldName) ?? fail(`Missing first-read index for ${fieldName}`);
|
|
1015
|
+
const bit = 1 << (index & 31);
|
|
1016
|
+
const word = index < 32 ? "__readFields" : `__readFields${index >>> 5}`;
|
|
1017
|
+
return code`(this.${word} & ${bit}) !== 0 ? this.__data.data.${fieldName} : ${getField}(this, "${fieldName}")`;
|
|
1018
|
+
}
|
|
1005
1019
|
export { generateEntityCodegenFile, getIdType };
|
|
1006
1020
|
|
|
1007
1021
|
//# sourceMappingURL=generateEntityCodegenFile.js.map
|