joist-codegen 2.5.0-next.3 → 2.5.0-next.31
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 +29 -5
- package/build/EntityDbMetadata.cjs.map +1 -1
- package/build/EntityDbMetadata.d.cts +8 -3
- package/build/EntityDbMetadata.d.cts.map +1 -1
- package/build/EntityDbMetadata.d.mts +8 -3
- package/build/EntityDbMetadata.d.mts.map +1 -1
- package/build/EntityDbMetadata.js +29 -6
- 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.cjs.map +1 -1
- package/build/assignTags.d.cts +0 -2
- package/build/assignTags.d.cts.map +1 -1
- package/build/assignTags.d.mts +0 -2
- package/build/assignTags.d.mts.map +1 -1
- package/build/assignTags.js +2 -3
- package/build/codemods/Codemod.d.cts +0 -2
- package/build/codemods/Codemod.d.cts.map +1 -1
- package/build/codemods/Codemod.d.mts +0 -2
- package/build/codemods/Codemod.d.mts.map +1 -1
- package/build/codemods/JscodeshiftMod.cjs +2 -3
- package/build/codemods/JscodeshiftMod.cjs.map +1 -1
- package/build/codemods/JscodeshiftMod.d.cts +0 -2
- package/build/codemods/JscodeshiftMod.d.cts.map +1 -1
- package/build/codemods/JscodeshiftMod.d.mts +0 -2
- package/build/codemods/JscodeshiftMod.d.mts.map +1 -1
- package/build/codemods/JscodeshiftMod.js +2 -3
- package/build/codemods/JscodeshiftMod.js.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.cjs +1 -2
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts +0 -2
- 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 +0 -2
- 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 +0 -2
- 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 +0 -2
- 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 +0 -2
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts +0 -2
- 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 +0 -2
- package/build/codemods/index.d.cts.map +1 -1
- package/build/codemods/index.d.mts +0 -2
- package/build/codemods/index.d.mts.map +1 -1
- package/build/codemods/index.js +2 -3
- package/build/config.cjs +5 -4
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +1 -2
- package/build/config.d.cts.map +1 -1
- package/build/config.d.mts +1 -2
- package/build/config.d.mts.map +1 -1
- package/build/config.js +5 -4
- 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 +0 -2
- package/build/docs/cache.d.cts.map +1 -1
- package/build/docs/cache.d.mts +0 -2
- 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.cjs.map +1 -1
- package/build/docs/generate-metadata-docs.d.cts +0 -2
- package/build/docs/generate-metadata-docs.d.cts.map +1 -1
- package/build/docs/generate-metadata-docs.d.mts +0 -2
- 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.cjs.map +1 -1
- package/build/docs/index.d.cts +0 -2
- package/build/docs/index.d.cts.map +1 -1
- package/build/docs/index.d.mts +0 -2
- 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.cjs.map +1 -1
- package/build/docs/markdown.d.cts +0 -2
- package/build/docs/markdown.d.cts.map +1 -1
- package/build/docs/markdown.d.mts +0 -2
- 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.cjs.map +1 -1
- package/build/docs/parsing.d.cts +1 -3
- package/build/docs/parsing.d.cts.map +1 -1
- package/build/docs/parsing.d.mts +0 -2
- 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.cjs.map +1 -1
- package/build/findEntityScopes.d.cts +0 -2
- package/build/findEntityScopes.d.cts.map +1 -1
- package/build/findEntityScopes.d.mts +0 -2
- package/build/findEntityScopes.d.mts.map +1 -1
- package/build/findEntityScopes.js +1 -2
- package/build/foreignKeyOrdering.cjs +4 -5
- package/build/foreignKeyOrdering.cjs.map +1 -1
- package/build/foreignKeyOrdering.d.cts +0 -2
- package/build/foreignKeyOrdering.d.cts.map +1 -1
- package/build/foreignKeyOrdering.d.mts +0 -2
- package/build/foreignKeyOrdering.d.mts.map +1 -1
- package/build/foreignKeyOrdering.js +4 -5
- package/build/generate.cjs +21 -18
- package/build/generate.cjs.map +1 -1
- package/build/generate.d.cts +0 -2
- package/build/generate.d.cts.map +1 -1
- package/build/generate.d.mts +0 -2
- package/build/generate.d.mts.map +1 -1
- package/build/generate.js +21 -18
- package/build/generate.js.map +1 -1
- package/build/generateEntitiesFile.cjs +4 -5
- package/build/generateEntitiesFile.cjs.map +1 -1
- package/build/generateEntitiesFile.d.cts +2 -4
- package/build/generateEntitiesFile.d.cts.map +1 -1
- package/build/generateEntitiesFile.d.mts +2 -4
- package/build/generateEntitiesFile.d.mts.map +1 -1
- package/build/generateEntitiesFile.js +4 -5
- package/build/generateEntityCodegenFile.cjs +36 -23
- package/build/generateEntityCodegenFile.cjs.map +1 -1
- package/build/generateEntityCodegenFile.d.cts +1 -3
- package/build/generateEntityCodegenFile.d.cts.map +1 -1
- package/build/generateEntityCodegenFile.d.mts +2 -4
- package/build/generateEntityCodegenFile.d.mts.map +1 -1
- package/build/generateEntityCodegenFile.js +36 -23
- package/build/generateEntityCodegenFile.js.map +1 -1
- package/build/generateEntityFile.cjs +1 -2
- package/build/generateEntityFile.cjs.map +1 -1
- package/build/generateEntityFile.d.cts +0 -2
- package/build/generateEntityFile.d.cts.map +1 -1
- package/build/generateEntityFile.d.mts +0 -2
- package/build/generateEntityFile.d.mts.map +1 -1
- package/build/generateEntityFile.js +1 -2
- package/build/generateEntityTestFile.cjs +1 -2
- package/build/generateEntityTestFile.cjs.map +1 -1
- package/build/generateEntityTestFile.d.cts +0 -2
- package/build/generateEntityTestFile.d.cts.map +1 -1
- package/build/generateEntityTestFile.d.mts +0 -2
- package/build/generateEntityTestFile.d.mts.map +1 -1
- package/build/generateEntityTestFile.js +1 -2
- package/build/generateEnumFile.cjs +2 -3
- package/build/generateEnumFile.cjs.map +1 -1
- package/build/generateEnumFile.d.cts +0 -2
- package/build/generateEnumFile.d.cts.map +1 -1
- package/build/generateEnumFile.d.mts +0 -2
- package/build/generateEnumFile.d.mts.map +1 -1
- package/build/generateEnumFile.js +2 -3
- package/build/generateFactoriesFiles.cjs +2 -3
- package/build/generateFactoriesFiles.cjs.map +1 -1
- package/build/generateFactoriesFiles.d.cts +0 -2
- package/build/generateFactoriesFiles.d.cts.map +1 -1
- package/build/generateFactoriesFiles.d.mts +0 -2
- 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 +0 -2
- package/build/generateFlushFunction.d.cts.map +1 -1
- package/build/generateFlushFunction.d.mts +0 -2
- package/build/generateFlushFunction.d.mts.map +1 -1
- package/build/generateFlushFunction.js +1 -2
- package/build/generateMetadataFile.cjs +6 -4
- package/build/generateMetadataFile.cjs.map +1 -1
- package/build/generateMetadataFile.d.cts +0 -2
- package/build/generateMetadataFile.d.cts.map +1 -1
- package/build/generateMetadataFile.d.mts +0 -2
- package/build/generateMetadataFile.d.mts.map +1 -1
- package/build/generateMetadataFile.js +6 -4
- package/build/generateMetadataFile.js.map +1 -1
- package/build/generatePgEnumFile.cjs +1 -2
- package/build/generatePgEnumFile.cjs.map +1 -1
- package/build/generatePgEnumFile.d.cts +0 -2
- package/build/generatePgEnumFile.d.cts.map +1 -1
- package/build/generatePgEnumFile.d.mts +0 -2
- package/build/generatePgEnumFile.d.mts.map +1 -1
- package/build/generatePgEnumFile.js +1 -2
- package/build/index.cjs +8 -9
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +2 -3
- package/build/index.d.mts +1 -3
- package/build/index.d.mts.map +1 -1
- package/build/index.js +8 -9
- package/build/inheritance.cjs +2 -3
- package/build/inheritance.cjs.map +1 -1
- package/build/inheritance.d.cts +0 -2
- package/build/inheritance.d.cts.map +1 -1
- package/build/inheritance.d.mts +0 -2
- package/build/inheritance.d.mts.map +1 -1
- package/build/inheritance.js +2 -3
- package/build/installSkills.cjs +1 -2
- package/build/installSkills.cjs.map +1 -1
- package/build/installSkills.d.cts +0 -2
- package/build/installSkills.d.cts.map +1 -1
- package/build/installSkills.d.mts +0 -2
- 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 +0 -2
- package/build/keywords.d.cts.map +1 -1
- package/build/keywords.d.mts +0 -2
- 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 +1 -3
- package/build/loadMetadata.d.cts.map +1 -1
- package/build/loadMetadata.d.mts +1 -3
- 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 +0 -2
- package/build/logger.d.cts.map +1 -1
- package/build/logger.d.mts +0 -2
- package/build/logger.d.mts.map +1 -1
- package/build/logger.js +1 -2
- package/build/pgMetadata.cjs +1 -2
- package/build/pgMetadata.cjs.map +1 -1
- package/build/pgMetadata.d.cts +0 -2
- package/build/pgMetadata.d.cts.map +1 -1
- package/build/pgMetadata.d.mts +0 -2
- package/build/pgMetadata.d.mts.map +1 -1
- package/build/pgMetadata.js +1 -2
- package/build/pgMetadata.js.map +1 -1
- package/build/scanEntityFiles.cjs +1 -2
- package/build/scanEntityFiles.d.cts +0 -2
- package/build/scanEntityFiles.d.cts.map +1 -1
- package/build/scanEntityFiles.d.mts +0 -2
- package/build/scanEntityFiles.d.mts.map +1 -1
- package/build/scanEntityFiles.js +1 -2
- package/build/sortForeignKeys.cjs +1 -2
- package/build/sortForeignKeys.d.cts +0 -2
- package/build/sortForeignKeys.d.cts.map +1 -1
- package/build/sortForeignKeys.d.mts +0 -2
- package/build/sortForeignKeys.d.mts.map +1 -1
- package/build/sortForeignKeys.js +1 -2
- package/build/symbols.cjs +1 -2
- package/build/symbols.d.cts +0 -2
- package/build/symbols.d.cts.map +1 -1
- package/build/symbols.d.mts +0 -2
- package/build/symbols.d.mts.map +1 -1
- package/build/symbols.js +1 -2
- package/build/tsdoc.cjs +1 -2
- package/build/tsdoc.d.cts +0 -2
- package/build/tsdoc.d.cts.map +1 -1
- package/build/tsdoc.d.mts +0 -2
- package/build/tsdoc.d.mts.map +1 -1
- package/build/tsdoc.js +1 -2
- package/build/utils.cjs +2 -3
- package/build/utils.cjs.map +1 -1
- package/build/utils.d.cts +1 -3
- package/build/utils.d.cts.map +1 -1
- package/build/utils.d.mts +1 -3
- package/build/utils.d.mts.map +1 -1
- package/build/utils.js +2 -3
- package/build/write-json-schema.cjs +1 -2
- package/build/write-json-schema.cjs.map +1 -1
- package/build/write-json-schema.js +1 -2
- package/package.json +6 -6
package/build/docs/parsing.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
3
|
let jscodeshift = require("jscodeshift");
|
|
4
4
|
jscodeshift = require_runtime.__toESM(jscodeshift, 1);
|
|
5
|
-
|
|
5
|
+
// src/docs/parsing.ts
|
|
6
6
|
const j = jscodeshift.default.withParser("ts");
|
|
7
7
|
/** Parse an entity .ts file and extract class + member JSDoc. */
|
|
8
8
|
function parseEntityJSDocs(source) {
|
|
@@ -107,7 +107,6 @@ function classMethodKind(node) {
|
|
|
107
107
|
if (node.kind === "set") return "setter";
|
|
108
108
|
return "method";
|
|
109
109
|
}
|
|
110
|
-
//#endregion
|
|
111
110
|
exports.applyEdits = applyEdits;
|
|
112
111
|
exports.buildJSDocBlock = buildJSDocBlock;
|
|
113
112
|
exports.buildJSDocEdit = buildJSDocEdit;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsing.cjs","names":[],"sources":["../../src/docs/parsing.ts"],"sourcesContent":["import type { namedTypes } from \"ast-types\";\nimport jscodeshift, { type ASTNode } from \"jscodeshift\";\n\nconst j = jscodeshift.withParser(\"ts\");\n\ntype CommentKind = (namedTypes.CommentBlock | namedTypes.CommentLine | namedTypes.Block | namedTypes.Line) & {\n start?: number;\n end?: number;\n};\nj;\ntype Commented = ASTNode & {\n comments?: CommentKind[] | null;\n start?: number;\n end?: number;\n loc?: namedTypes.SourceLocation | null;\n};\n\nexport type MemberKind = \"property\" | \"getter\" | \"setter\" | \"method\";\n\nexport interface MemberInfo {\n kind: MemberKind;\n name: string;\n doc: string | undefined;\n node: Commented;\n}\n\nexport interface SourceEdit {\n start: number;\n end: number;\n text: string;\n}\n\n/** Parse an entity .ts file and extract class + member JSDoc. */\nexport function parseEntityJSDocs(source: string) {\n const root = j(source);\n let classDoc: string | undefined;\n let classNode: Commented | undefined;\n const members: MemberInfo[] = [];\n\n root.find(j.ExportNamedDeclaration).forEach((p) => {\n if (p.node.declaration?.type === \"ClassDeclaration\") {\n classDoc = extractJSDoc(p.node as Commented);\n classNode = p.node as Commented;\n }\n });\n\n root.find(j.ClassProperty).forEach((p) => {\n const name = (p.node.key as namedTypes.Identifier)?.name;\n if (name) {\n members.push({ name, kind: \"property\", doc: extractJSDoc(p.node as Commented), node: p.node as Commented });\n }\n });\n\n root.find(j.ClassMethod).forEach((p) => {\n const name = (p.node.key as namedTypes.Identifier)?.name;\n if (name) {\n members.push({\n name,\n kind: classMethodKind(p.node),\n doc: extractJSDoc(p.node as Commented),\n node: p.node as Commented,\n });\n }\n });\n\n return { classDoc, classNode, members, fieldDocs: collectFieldDocs(members) };\n}\n\n/**\n * Collect field docs from members for backfill.\n * When a getter and setter share the same name, prefer the getter's doc.\n */\nfunction collectFieldDocs(members: MemberInfo[]): Record<string, string> {\n const result: Record<string, string> = {};\n for (const m of members) {\n if (!m.doc || m.kind === \"method\") continue;\n if (result[m.name] && m.kind === \"setter\") continue;\n result[m.name] = m.doc;\n }\n return result;\n}\n\n/**\n * Build a source edit that sets the JSDoc on a node (replacing existing or inserting new).\n *\n * (This is bizarre, but this `SourceEdit` + `applyEdits` leaves all existing formatting\n * alone better than doing a `node.toSource()` or other AST-based updates. :grimmacing:)\n */\nexport function buildJSDocEdit(node: Commented, text: string): SourceEdit {\n const column = node.loc!.start.column;\n const existingComment = node.comments?.find((c) => c.leading && \"value\" in c && c.value.startsWith(\"*\"));\n if (existingComment) {\n return { start: existingComment.start!, end: existingComment.end!, text: buildJSDocBlock(text, column) };\n }\n const indent = \" \".repeat(column);\n return { start: node.start!, end: node.start!, text: buildJSDocBlock(text, column) + \"\\n\" + indent };\n}\n\n/** Apply edits to source by splicing in reverse order. */\nexport function applyEdits(source: string, edits: SourceEdit[]): string {\n const sorted = [...edits].sort((a, b) => b.start - a.start);\n let result = source;\n for (const edit of sorted) {\n result = result.slice(0, edit.start) + edit.text + result.slice(edit.end);\n }\n return result;\n}\n\n/** Build a JSDoc block comment string from plain text. */\nexport function buildJSDocBlock(text: string, indent: number): string {\n const pad = \" \".repeat(indent);\n const lines = text.split(\"\\n\");\n if (lines.length === 1) return `/** ${lines[0]} */`;\n return `/**\\n` + lines.map((l) => (l ? `${pad} * ${l}` : `${pad} *`)).join(\"\\n\") + `\\n${pad} */`;\n}\n\n/** The `@generated Entity.md` marker, i.e. so readers know a JSDoc is sourced from (and edited in) the `.md`. */\nexport function generatedTag(entityName: string): string {\n return `@generated ${entityName}.md`;\n}\n\n/** Extract text from a JSDoc-style leading block comment (i.e. one starting with `*`). */\nfunction extractJSDoc(node: Commented): string | undefined {\n const block = node.comments?.find((c) => c.leading && \"value\" in c && c.value.startsWith(\"*\"));\n if (!block || !(\"value\" in block)) return undefined;\n const lines = block.value.split(\"\\n\").map((l) => l.replace(/^\\s*\\*\\s?/, \"\").trimEnd());\n while (lines.length > 0 && lines[0].trim() === \"\") lines.shift();\n while (lines.length > 0 && lines[lines.length - 1].trim() === \"\") lines.pop();\n return lines.join(\"\\n\") || undefined;\n}\n\nfunction classMethodKind(node: namedTypes.ClassMethod): MemberKind {\n if (node.kind === \"get\") return \"getter\";\n if (node.kind === \"set\") return \"setter\";\n return \"method\";\n}\n"],"mappings":";;;;;AAGA,MAAM,
|
|
1
|
+
{"version":3,"file":"parsing.cjs","names":["jscodeshift"],"sources":["../../src/docs/parsing.ts"],"sourcesContent":["import type { namedTypes } from \"ast-types\";\nimport jscodeshift, { type ASTNode } from \"jscodeshift\";\n\nconst j = jscodeshift.withParser(\"ts\");\n\ntype CommentKind = (namedTypes.CommentBlock | namedTypes.CommentLine | namedTypes.Block | namedTypes.Line) & {\n start?: number;\n end?: number;\n};\nj;\ntype Commented = ASTNode & {\n comments?: CommentKind[] | null;\n start?: number;\n end?: number;\n loc?: namedTypes.SourceLocation | null;\n};\n\nexport type MemberKind = \"property\" | \"getter\" | \"setter\" | \"method\";\n\nexport interface MemberInfo {\n kind: MemberKind;\n name: string;\n doc: string | undefined;\n node: Commented;\n}\n\nexport interface SourceEdit {\n start: number;\n end: number;\n text: string;\n}\n\n/** Parse an entity .ts file and extract class + member JSDoc. */\nexport function parseEntityJSDocs(source: string) {\n const root = j(source);\n let classDoc: string | undefined;\n let classNode: Commented | undefined;\n const members: MemberInfo[] = [];\n\n root.find(j.ExportNamedDeclaration).forEach((p) => {\n if (p.node.declaration?.type === \"ClassDeclaration\") {\n classDoc = extractJSDoc(p.node as Commented);\n classNode = p.node as Commented;\n }\n });\n\n root.find(j.ClassProperty).forEach((p) => {\n const name = (p.node.key as namedTypes.Identifier)?.name;\n if (name) {\n members.push({ name, kind: \"property\", doc: extractJSDoc(p.node as Commented), node: p.node as Commented });\n }\n });\n\n root.find(j.ClassMethod).forEach((p) => {\n const name = (p.node.key as namedTypes.Identifier)?.name;\n if (name) {\n members.push({\n name,\n kind: classMethodKind(p.node),\n doc: extractJSDoc(p.node as Commented),\n node: p.node as Commented,\n });\n }\n });\n\n return { classDoc, classNode, members, fieldDocs: collectFieldDocs(members) };\n}\n\n/**\n * Collect field docs from members for backfill.\n * When a getter and setter share the same name, prefer the getter's doc.\n */\nfunction collectFieldDocs(members: MemberInfo[]): Record<string, string> {\n const result: Record<string, string> = {};\n for (const m of members) {\n if (!m.doc || m.kind === \"method\") continue;\n if (result[m.name] && m.kind === \"setter\") continue;\n result[m.name] = m.doc;\n }\n return result;\n}\n\n/**\n * Build a source edit that sets the JSDoc on a node (replacing existing or inserting new).\n *\n * (This is bizarre, but this `SourceEdit` + `applyEdits` leaves all existing formatting\n * alone better than doing a `node.toSource()` or other AST-based updates. :grimmacing:)\n */\nexport function buildJSDocEdit(node: Commented, text: string): SourceEdit {\n const column = node.loc!.start.column;\n const existingComment = node.comments?.find((c) => c.leading && \"value\" in c && c.value.startsWith(\"*\"));\n if (existingComment) {\n return { start: existingComment.start!, end: existingComment.end!, text: buildJSDocBlock(text, column) };\n }\n const indent = \" \".repeat(column);\n return { start: node.start!, end: node.start!, text: buildJSDocBlock(text, column) + \"\\n\" + indent };\n}\n\n/** Apply edits to source by splicing in reverse order. */\nexport function applyEdits(source: string, edits: SourceEdit[]): string {\n const sorted = [...edits].sort((a, b) => b.start - a.start);\n let result = source;\n for (const edit of sorted) {\n result = result.slice(0, edit.start) + edit.text + result.slice(edit.end);\n }\n return result;\n}\n\n/** Build a JSDoc block comment string from plain text. */\nexport function buildJSDocBlock(text: string, indent: number): string {\n const pad = \" \".repeat(indent);\n const lines = text.split(\"\\n\");\n if (lines.length === 1) return `/** ${lines[0]} */`;\n return `/**\\n` + lines.map((l) => (l ? `${pad} * ${l}` : `${pad} *`)).join(\"\\n\") + `\\n${pad} */`;\n}\n\n/** The `@generated Entity.md` marker, i.e. so readers know a JSDoc is sourced from (and edited in) the `.md`. */\nexport function generatedTag(entityName: string): string {\n return `@generated ${entityName}.md`;\n}\n\n/** Extract text from a JSDoc-style leading block comment (i.e. one starting with `*`). */\nfunction extractJSDoc(node: Commented): string | undefined {\n const block = node.comments?.find((c) => c.leading && \"value\" in c && c.value.startsWith(\"*\"));\n if (!block || !(\"value\" in block)) return undefined;\n const lines = block.value.split(\"\\n\").map((l) => l.replace(/^\\s*\\*\\s?/, \"\").trimEnd());\n while (lines.length > 0 && lines[0].trim() === \"\") lines.shift();\n while (lines.length > 0 && lines[lines.length - 1].trim() === \"\") lines.pop();\n return lines.join(\"\\n\") || undefined;\n}\n\nfunction classMethodKind(node: namedTypes.ClassMethod): MemberKind {\n if (node.kind === \"get\") return \"getter\";\n if (node.kind === \"set\") return \"setter\";\n return \"method\";\n}\n"],"mappings":";;;;;AAGA,MAAM,IAAIA,YAAAA,QAAY,WAAW,IAAI;;AA8BrC,SAAgB,kBAAkB,QAAgB;CAChD,MAA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MAAM,SAAS,EAAE,CAAC,KAAK,MAAM,IAAI,MAAM,IAAI;CAC5E,OAAO,MAAM,KAAK,IAAI,KAAK,KAAA;AAC7B;AAEA,SAAS,gBAAgB,MAA0C;CACjE,IAAI,KAAK,SAAS,OAAO,OAAO;CAChC,IAAI,KAAK,SAAS,OAAO,OAAO;CAChC,OAAO;AACT"}
|
package/build/docs/parsing.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ASTNode } from "jscodeshift";
|
|
2
1
|
import { namedTypes } from "ast-types";
|
|
3
|
-
|
|
2
|
+
import { ASTNode } from "jscodeshift";
|
|
4
3
|
type CommentKind = (namedTypes.CommentBlock | namedTypes.CommentLine | namedTypes.Block | namedTypes.Line) & {
|
|
5
4
|
start?: number;
|
|
6
5
|
end?: number;
|
|
@@ -43,6 +42,5 @@ export declare function applyEdits(source: string, edits: SourceEdit[]): string;
|
|
|
43
42
|
export declare function buildJSDocBlock(text: string, indent: number): string;
|
|
44
43
|
/** The `@generated Entity.md` marker, i.e. so readers know a JSDoc is sourced from (and edited in) the `.md`. */
|
|
45
44
|
export declare function generatedTag(entityName: string): string;
|
|
46
|
-
//#endregion
|
|
47
45
|
export {};
|
|
48
46
|
//# sourceMappingURL=parsing.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsing.d.cts","names":[],"sources":["../../src/docs/parsing.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"parsing.d.cts","names":[],"sources":["../../src/docs/parsing.ts"],"mappings":";;KAKK,eAAe,WAAW,eAAe,WAAW,cAAc,WAAW,QAAQ,WAAW;EACnG;EACA;;KAGG,YAAY;EACf,WAAW;EACX;EACA;EACA,MAAM,WAAW;;YAGP;iBAEK;EACf,MAAM;EACN;EACA;EACA,MAAM;;iBAGS;EACf;EACA;EACA;;;wBAIc,kBAAkB;;;;;;;;;;;;wBAuDlB,eAAe,MAAM,WAAW,eAAe;;wBAW/C,WAAW,gBAAgB,OAAO;;wBAUlC,gBAAgB,cAAc;;wBAQ9B,aAAa"}
|
package/build/docs/parsing.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ASTNode } from "jscodeshift";
|
|
2
2
|
import { namedTypes } from "ast-types";
|
|
3
|
-
//#region src/docs/parsing.d.ts
|
|
4
3
|
type CommentKind = (namedTypes.CommentBlock | namedTypes.CommentLine | namedTypes.Block | namedTypes.Line) & {
|
|
5
4
|
start?: number;
|
|
6
5
|
end?: number;
|
|
@@ -43,6 +42,5 @@ export declare function applyEdits(source: string, edits: SourceEdit[]): string;
|
|
|
43
42
|
export declare function buildJSDocBlock(text: string, indent: number): string;
|
|
44
43
|
/** The `@generated Entity.md` marker, i.e. so readers know a JSDoc is sourced from (and edited in) the `.md`. */
|
|
45
44
|
export declare function generatedTag(entityName: string): string;
|
|
46
|
-
//#endregion
|
|
47
45
|
export {};
|
|
48
46
|
//# sourceMappingURL=parsing.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsing.d.mts","names":[],"sources":["../../src/docs/parsing.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"parsing.d.mts","names":[],"sources":["../../src/docs/parsing.ts"],"mappings":";;KAKK,eAAe,WAAW,eAAe,WAAW,cAAc,WAAW,QAAQ,WAAW;EACnG;EACA;;KAGG,YAAY;EACf,WAAW;EACX;EACA;EACA,MAAM,WAAW;;YAGP;iBAEK;EACf,MAAM;EACN;EACA;EACA,MAAM;;iBAGS;EACf;EACA;EACA;;;wBAIc,kBAAkB;;;;;;;;;;;;wBAuDlB,eAAe,MAAM,WAAW,eAAe;;wBAW/C,WAAW,gBAAgB,OAAO;;wBAUlC,gBAAgB,cAAc;;wBAQ9B,aAAa"}
|
package/build/docs/parsing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import jscodeshift from "jscodeshift";
|
|
2
|
-
|
|
2
|
+
// src/docs/parsing.ts
|
|
3
3
|
const j = jscodeshift.withParser("ts");
|
|
4
4
|
/** Parse an entity .ts file and extract class + member JSDoc. */
|
|
5
5
|
function parseEntityJSDocs(source) {
|
|
@@ -104,7 +104,6 @@ function classMethodKind(node) {
|
|
|
104
104
|
if (node.kind === "set") return "setter";
|
|
105
105
|
return "method";
|
|
106
106
|
}
|
|
107
|
-
//#endregion
|
|
108
107
|
export { applyEdits, buildJSDocBlock, buildJSDocEdit, generatedTag, parseEntityJSDocs };
|
|
109
108
|
|
|
110
109
|
//# sourceMappingURL=parsing.js.map
|
|
@@ -8,7 +8,7 @@ let jscodeshift = require("jscodeshift");
|
|
|
8
8
|
jscodeshift = require_runtime.__toESM(jscodeshift, 1);
|
|
9
9
|
let fs_promises = require("fs/promises");
|
|
10
10
|
require("ast-types");
|
|
11
|
-
|
|
11
|
+
// src/findEntityScopes.ts
|
|
12
12
|
const j = jscodeshift.default.withParser("ts");
|
|
13
13
|
/** Finds static scope declarations for all entity files. */
|
|
14
14
|
async function findAllEntityScopes(config, entities) {
|
|
@@ -113,7 +113,6 @@ function isScopeRootedExpression(expression, entityName) {
|
|
|
113
113
|
if (j.MemberExpression.check(expression) && !expression.computed) return isScopeRootedExpression(expression.object, entityName);
|
|
114
114
|
return false;
|
|
115
115
|
}
|
|
116
|
-
//#endregion
|
|
117
116
|
exports.findAllEntityScopes = findAllEntityScopes;
|
|
118
117
|
|
|
119
118
|
//# sourceMappingURL=findEntityScopes.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findEntityScopes.cjs","names":["camelCase","join","readFile"],"sources":["../src/findEntityScopes.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type namedTypes } from \"ast-types\";\nimport { camelCase } from \"change-case\";\nimport jscodeshift from \"jscodeshift\";\n\nimport { type Config } from \"./config.ts\";\nimport { type Entity } from \"./EntityDbMetadata.ts\";\n\nconst j = jscodeshift.withParser(\"ts\");\n\ntype Expression = NonNullable<namedTypes.ClassProperty[\"value\"]>;\ntype Parameter = namedTypes.ArrowFunctionExpression[\"params\"][number];\ntype TypeNode = namedTypes.TSTypeAnnotation[\"typeAnnotation\"];\n\n/** Each `static active = ...` scope in an entity. */\nexport interface ScopeMember {\n // I.e. \"adult\" from `static adult: AuthorScope = scope(...)`.\n name: string;\n // I.e. \"AuthorScope\" or \"(prefix: string) => AuthorScope\".\n type: string;\n}\n\nexport type ScopeMembersByEntity = Record<string, ScopeMember[]>;\n\n/** Finds static scope declarations for all entity files. */\nexport async function findAllEntityScopes(config: Config, entities: Entity[]): Promise<ScopeMembersByEntity> {\n return Object.fromEntries(await Promise.all(entities.map((entity) => findEntityScopes(config, entity))));\n}\n\n/** Finds static scope declarations a given entity file. */\nasync function findEntityScopes(config: Config, entity: Entity): Promise<[string, ScopeMember[]]> {\n const { name: entityName, scopeName: scopeTypeName } = entity;\n // i.e. `authorScope`, the conventional renamed-to-`scope` import users put in their entity files.\n const scopeFnName = `${camelCase(entityName)}Scope`;\n\n // i.e. `packages/tests/integration/src/entities/Author.ts` when `entityName` is \"Author\".\n const fileName = join(config.entitiesDirectory, `${entityName}.ts`);\n const contents = await readEntityFile(fileName);\n if (contents === undefined) return [entityName, []];\n if (contents.indexOf(scopeFnName) === -1) return [entityName, []];\n\n const program = j(contents).find(j.Program).nodes()[0];\n for (const statement of program.body) {\n const declaration =\n j.ExportNamedDeclaration.check(statement) || j.ExportDefaultDeclaration.check(statement)\n ? statement.declaration\n : statement;\n // i.e. `export class Author extends AuthorCodegen { ... }`.\n if (declaration && j.ClassDeclaration.check(declaration) && declaration.id?.name === entityName) {\n return [\n entityName,\n declaration.body.body.flatMap((member) => maybeScopeMember(member, entityName, scopeTypeName)),\n ];\n }\n }\n return [entityName, []];\n}\n\n/** Reads an entity file if it already exists. */\nasync function readEntityFile(fileName: string): Promise<string | undefined> {\n try {\n return await readFile(fileName, \"utf8\");\n } catch (e) {\n if (isNoSuchFileError(e)) return undefined;\n throw e;\n }\n}\n\n/** Returns true for a missing user-owned entity file. */\nfunction isNoSuchFileError(e: unknown): boolean {\n return typeof e === \"object\" && e !== null && \"code\" in e && e.code === \"ENOENT\";\n}\n\n/** Converts a static property declaration into a generated scope member. */\nfunction maybeScopeMember(member: namedTypes.Node, entityName: string, scopeTypeName: string): ScopeMember[] {\n if (!j.ClassProperty.check(member) || !member.static) return [];\n // i.e. accept `static adult = scope(...)`, but skip methods/getters/unsupported fields.\n if (!member.value || !j.Identifier.check(member.key)) return [];\n if (!isScopeInitializer(member.value, entityName)) return [];\n if (member.typeAnnotation) {\n if (!j.TSTypeAnnotation.check(member.typeAnnotation)) return [];\n const type = member.typeAnnotation.typeAnnotation;\n if (!isScopeType(type, scopeTypeName)) return [];\n return [{ name: member.key.name, type: j(type).toSource() }];\n }\n const type = inferScopeType(member.value, scopeTypeName);\n return type ? [{ name: member.key.name, type }] : [];\n}\n\n/** Infers a generated scope member type from an untyped static scope initializer. */\nfunction inferScopeType(initializer: Expression, scopeTypeName: string): string | undefined {\n return isParameterizedScopeInitializer(initializer)\n ? maybeParameterizedScope(initializer, scopeTypeName)\n : scopeTypeName;\n}\n\n/** Returns true for `scope.fn(...)` initializers. */\nfunction isParameterizedScopeInitializer(initializer: Expression): boolean {\n return (\n j.CallExpression.check(initializer) &&\n j.MemberExpression.check(initializer.callee) &&\n !initializer.callee.computed &&\n j.Identifier.check(initializer.callee.property) &&\n initializer.callee.property.name === \"fn\"\n );\n}\n\n/** Returns a function type for `scope.fn((prefix: string) => ...)` initializers. */\nfunction maybeParameterizedScope(initializer: Expression, scopeTypeName: string): string | undefined {\n if (!j.CallExpression.check(initializer)) return undefined;\n if (!j.MemberExpression.check(initializer.callee)) return undefined;\n if (initializer.callee.computed || !j.Identifier.check(initializer.callee.property)) return undefined;\n if (initializer.callee.property.name !== \"fn\") return undefined;\n const fn = initializer.arguments[0];\n if (!fn || (!j.ArrowFunctionExpression.check(fn) && !j.FunctionExpression.check(fn))) return undefined;\n const params = fn.params.map(parameterType);\n if (params.some((param) => param === undefined)) return undefined;\n return `(${params.join(\", \")}) => ${scopeTypeName}`;\n}\n\n/** Returns a function-type parameter, i.e. `prefix: string`, when syntax-only inference is safe. */\nfunction parameterType(param: Parameter): string | undefined {\n if (j.Identifier.check(param)) {\n if (!param.typeAnnotation || !j.TSTypeAnnotation.check(param.typeAnnotation)) return undefined;\n const optional = param.optional ? \"?\" : \"\";\n return `${param.name}${optional}: ${j(param.typeAnnotation.typeAnnotation).toSource()}`;\n }\n if (j.RestElement.check(param) && j.Identifier.check(param.argument)) {\n const typeAnnotation = param.typeAnnotation ?? param.argument.typeAnnotation;\n if (!typeAnnotation || !j.TSTypeAnnotation.check(typeAnnotation)) return undefined;\n return `...${param.argument.name}: ${j(typeAnnotation.typeAnnotation).toSource()}`;\n }\n return undefined;\n}\n\n/** Returns true for `EntityScope` and function types returning `EntityScope`. */\nfunction isScopeType(type: TypeNode, scopeTypeName: string): boolean {\n // i.e. `AuthorScope`.\n if (j.TSTypeReference.check(type) && j.Identifier.check(type.typeName)) return type.typeName.name === scopeTypeName;\n // i.e. `(prefix: string) => AuthorScope`.\n if (j.TSFunctionType.check(type) && type.typeAnnotation && j.TSTypeAnnotation.check(type.typeAnnotation)) {\n return isScopeType(type.typeAnnotation.typeAnnotation, scopeTypeName);\n }\n if (j.TSParenthesizedType.check(type)) return isScopeType(type.typeAnnotation, scopeTypeName);\n return false;\n}\n\n/** Returns true for scope initializers, I.e. `scope(...)`, `scope(...).orderBy(...)`, or `Author.adult...`. */\nfunction isScopeInitializer(initializer: Expression, entityName: string): boolean {\n if (!j.CallExpression.check(initializer) && !j.MemberExpression.check(initializer)) return false;\n return isScopeRootedExpression(initializer, entityName);\n}\n\n/** Returns true for a call/property expression chain rooted at `scope` or the current entity. */\nfunction isScopeRootedExpression(expression: Expression, entityName: string): boolean {\n // i.e. `scope({ age: { gte: 18 } })`.\n if (j.Identifier.check(expression)) return expression.name === \"scope\" || expression.name === entityName;\n if (j.CallExpression.check(expression)) return isScopeRootedExpression(expression.callee, entityName);\n // i.e. `scope.fn((prefix) => (a) => a.firstName.like(`${prefix}%`))` or `Author.adult.orderBy(...)`.\n if (j.MemberExpression.check(expression) && !expression.computed) {\n return isScopeRootedExpression(expression.object, entityName);\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,IAAI,YAAA,QAAY,WAAW,IAAI;;AAiBrC,eAAsB,oBAAoB,QAAgB,UAAmD;CAC3G,OAAO,OAAO,YAAY,MAAM,QAAQ,IAAI,SAAS,KAAK,WAAW,iBAAiB,QAAQ,MAAM,CAAC,CAAC,CAAC;AACzG;;AAGA,eAAe,iBAAiB,QAAgB,QAAkD;CAChG,MAAM,EAAE,MAAM,YAAY,WAAW,kBAAkB;CAEvD,MAAM,cAAc,IAAA,GAAGA,YAAAA,UAAAA,CAAU,UAAU,EAAE;CAI7C,MAAM,WAAW,MAAM,gBAAA,GADNC,KAAAA,KAAAA,CAAK,OAAO,mBAAmB,GAAG,WAAW,IACjB,CAAC;CAC9C,IAAI,aAAa,KAAA,GAAW,OAAO,CAAC,YAAY,CAAC,CAAC;CAClD,IAAI,SAAS,QAAQ,WAAW,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;CAEhE,MAAM,UAAU,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;CACpD,KAAK,MAAM,aAAa,QAAQ,MAAM;EACpC,MAAM,cACJ,EAAE,uBAAuB,MAAM,SAAS,KAAK,EAAE,yBAAyB,MAAM,SAAS,IACnF,UAAU,cACV;EAEN,IAAI,eAAe,EAAE,iBAAiB,MAAM,WAAW,KAAK,YAAY,IAAI,SAAS,YACnF,OAAO,CACL,YACA,YAAY,KAAK,KAAK,SAAS,WAAW,iBAAiB,QAAQ,YAAY,aAAa,CAAC,CAC/F;CAEJ;CACA,OAAO,CAAC,YAAY,CAAC,CAAC;AACxB;;AAGA,eAAe,eAAe,UAA+C;CAC3E,IAAI;EACF,OAAO,OAA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,IAAI,EAAE,gBAAgB,MAAM,IAAI,KAAK,EAAE,WAAW,MAAM,KAAK,QAAQ,GAAG,OAAO,KAAK,SAAS,SAAS;CAEtG,IAAI,EAAE,eAAe,MAAM,IAAI,KAAK,KAAK,kBAAkB,EAAE,iBAAiB,MAAM,KAAK,cAAc,GACrG,OAAO,YAAY,KAAK,eAAe,gBAAgB,aAAa;CAEtE,IAAI,EAAE,oBAAoB,MAAM,IAAI,GAAG,OAAO,YAAY,KAAK,gBAAgB,aAAa;CAC5F,OAAO;AACT;;AAGA,SAAS,mBAAmB,aAAyB,YAA6B;CAChF,IAAI,CAAC,EAAE,eAAe,MAAM,WAAW,KAAK,CAAC,EAAE,iBAAiB,MAAM,WAAW,GAAG,OAAO;CAC3F,OAAO,wBAAwB,aAAa,UAAU;AACxD;;AAGA,SAAS,wBAAwB,YAAwB,YAA6B;CAEpF,IAAI,EAAE,WAAW,MAAM,UAAU,GAAG,OAAO,WAAW,SAAS,WAAW,WAAW,SAAS;CAC9F,IAAI,EAAE,eAAe,MAAM,UAAU,GAAG,OAAO,wBAAwB,WAAW,QAAQ,UAAU;CAEpG,IAAI,EAAE,iBAAiB,MAAM,UAAU,KAAK,CAAC,WAAW,UACtD,OAAO,wBAAwB,WAAW,QAAQ,UAAU;CAE9D,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"findEntityScopes.cjs","names":["jscodeshift","camelCase","join","readFile"],"sources":["../src/findEntityScopes.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type namedTypes } from \"ast-types\";\nimport { camelCase } from \"change-case\";\nimport jscodeshift from \"jscodeshift\";\n\nimport { type Config } from \"./config.ts\";\nimport { type Entity } from \"./EntityDbMetadata.ts\";\n\nconst j = jscodeshift.withParser(\"ts\");\n\ntype Expression = NonNullable<namedTypes.ClassProperty[\"value\"]>;\ntype Parameter = namedTypes.ArrowFunctionExpression[\"params\"][number];\ntype TypeNode = namedTypes.TSTypeAnnotation[\"typeAnnotation\"];\n\n/** Each `static active = ...` scope in an entity. */\nexport interface ScopeMember {\n // I.e. \"adult\" from `static adult: AuthorScope = scope(...)`.\n name: string;\n // I.e. \"AuthorScope\" or \"(prefix: string) => AuthorScope\".\n type: string;\n}\n\nexport type ScopeMembersByEntity = Record<string, ScopeMember[]>;\n\n/** Finds static scope declarations for all entity files. */\nexport async function findAllEntityScopes(config: Config, entities: Entity[]): Promise<ScopeMembersByEntity> {\n return Object.fromEntries(await Promise.all(entities.map((entity) => findEntityScopes(config, entity))));\n}\n\n/** Finds static scope declarations a given entity file. */\nasync function findEntityScopes(config: Config, entity: Entity): Promise<[string, ScopeMember[]]> {\n const { name: entityName, scopeName: scopeTypeName } = entity;\n // i.e. `authorScope`, the conventional renamed-to-`scope` import users put in their entity files.\n const scopeFnName = `${camelCase(entityName)}Scope`;\n\n // i.e. `packages/tests/integration/src/entities/Author.ts` when `entityName` is \"Author\".\n const fileName = join(config.entitiesDirectory, `${entityName}.ts`);\n const contents = await readEntityFile(fileName);\n if (contents === undefined) return [entityName, []];\n if (contents.indexOf(scopeFnName) === -1) return [entityName, []];\n\n const program = j(contents).find(j.Program).nodes()[0];\n for (const statement of program.body) {\n const declaration =\n j.ExportNamedDeclaration.check(statement) || j.ExportDefaultDeclaration.check(statement)\n ? statement.declaration\n : statement;\n // i.e. `export class Author extends AuthorCodegen { ... }`.\n if (declaration && j.ClassDeclaration.check(declaration) && declaration.id?.name === entityName) {\n return [\n entityName,\n declaration.body.body.flatMap((member) => maybeScopeMember(member, entityName, scopeTypeName)),\n ];\n }\n }\n return [entityName, []];\n}\n\n/** Reads an entity file if it already exists. */\nasync function readEntityFile(fileName: string): Promise<string | undefined> {\n try {\n return await readFile(fileName, \"utf8\");\n } catch (e) {\n if (isNoSuchFileError(e)) return undefined;\n throw e;\n }\n}\n\n/** Returns true for a missing user-owned entity file. */\nfunction isNoSuchFileError(e: unknown): boolean {\n return typeof e === \"object\" && e !== null && \"code\" in e && e.code === \"ENOENT\";\n}\n\n/** Converts a static property declaration into a generated scope member. */\nfunction maybeScopeMember(member: namedTypes.Node, entityName: string, scopeTypeName: string): ScopeMember[] {\n if (!j.ClassProperty.check(member) || !member.static) return [];\n // i.e. accept `static adult = scope(...)`, but skip methods/getters/unsupported fields.\n if (!member.value || !j.Identifier.check(member.key)) return [];\n if (!isScopeInitializer(member.value, entityName)) return [];\n if (member.typeAnnotation) {\n if (!j.TSTypeAnnotation.check(member.typeAnnotation)) return [];\n const type = member.typeAnnotation.typeAnnotation;\n if (!isScopeType(type, scopeTypeName)) return [];\n return [{ name: member.key.name, type: j(type).toSource() }];\n }\n const type = inferScopeType(member.value, scopeTypeName);\n return type ? [{ name: member.key.name, type }] : [];\n}\n\n/** Infers a generated scope member type from an untyped static scope initializer. */\nfunction inferScopeType(initializer: Expression, scopeTypeName: string): string | undefined {\n return isParameterizedScopeInitializer(initializer)\n ? maybeParameterizedScope(initializer, scopeTypeName)\n : scopeTypeName;\n}\n\n/** Returns true for `scope.fn(...)` initializers. */\nfunction isParameterizedScopeInitializer(initializer: Expression): boolean {\n return (\n j.CallExpression.check(initializer) &&\n j.MemberExpression.check(initializer.callee) &&\n !initializer.callee.computed &&\n j.Identifier.check(initializer.callee.property) &&\n initializer.callee.property.name === \"fn\"\n );\n}\n\n/** Returns a function type for `scope.fn((prefix: string) => ...)` initializers. */\nfunction maybeParameterizedScope(initializer: Expression, scopeTypeName: string): string | undefined {\n if (!j.CallExpression.check(initializer)) return undefined;\n if (!j.MemberExpression.check(initializer.callee)) return undefined;\n if (initializer.callee.computed || !j.Identifier.check(initializer.callee.property)) return undefined;\n if (initializer.callee.property.name !== \"fn\") return undefined;\n const fn = initializer.arguments[0];\n if (!fn || (!j.ArrowFunctionExpression.check(fn) && !j.FunctionExpression.check(fn))) return undefined;\n const params = fn.params.map(parameterType);\n if (params.some((param) => param === undefined)) return undefined;\n return `(${params.join(\", \")}) => ${scopeTypeName}`;\n}\n\n/** Returns a function-type parameter, i.e. `prefix: string`, when syntax-only inference is safe. */\nfunction parameterType(param: Parameter): string | undefined {\n if (j.Identifier.check(param)) {\n if (!param.typeAnnotation || !j.TSTypeAnnotation.check(param.typeAnnotation)) return undefined;\n const optional = param.optional ? \"?\" : \"\";\n return `${param.name}${optional}: ${j(param.typeAnnotation.typeAnnotation).toSource()}`;\n }\n if (j.RestElement.check(param) && j.Identifier.check(param.argument)) {\n const typeAnnotation = param.typeAnnotation ?? param.argument.typeAnnotation;\n if (!typeAnnotation || !j.TSTypeAnnotation.check(typeAnnotation)) return undefined;\n return `...${param.argument.name}: ${j(typeAnnotation.typeAnnotation).toSource()}`;\n }\n return undefined;\n}\n\n/** Returns true for `EntityScope` and function types returning `EntityScope`. */\nfunction isScopeType(type: TypeNode, scopeTypeName: string): boolean {\n // i.e. `AuthorScope`.\n if (j.TSTypeReference.check(type) && j.Identifier.check(type.typeName)) return type.typeName.name === scopeTypeName;\n // i.e. `(prefix: string) => AuthorScope`.\n if (j.TSFunctionType.check(type) && type.typeAnnotation && j.TSTypeAnnotation.check(type.typeAnnotation)) {\n return isScopeType(type.typeAnnotation.typeAnnotation, scopeTypeName);\n }\n if (j.TSParenthesizedType.check(type)) return isScopeType(type.typeAnnotation, scopeTypeName);\n return false;\n}\n\n/** Returns true for scope initializers, I.e. `scope(...)`, `scope(...).orderBy(...)`, or `Author.adult...`. */\nfunction isScopeInitializer(initializer: Expression, entityName: string): boolean {\n if (!j.CallExpression.check(initializer) && !j.MemberExpression.check(initializer)) return false;\n return isScopeRootedExpression(initializer, entityName);\n}\n\n/** Returns true for a call/property expression chain rooted at `scope` or the current entity. */\nfunction isScopeRootedExpression(expression: Expression, entityName: string): boolean {\n // i.e. `scope({ age: { gte: 18 } })`.\n if (j.Identifier.check(expression)) return expression.name === \"scope\" || expression.name === entityName;\n if (j.CallExpression.check(expression)) return isScopeRootedExpression(expression.callee, entityName);\n // i.e. `scope.fn((prefix) => (a) => a.firstName.like(`${prefix}%`))` or `Author.adult.orderBy(...)`.\n if (j.MemberExpression.check(expression) && !expression.computed) {\n return isScopeRootedExpression(expression.object, entityName);\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,IAAIA,YAAAA,QAAY,WAAW,IAAI;;AAiBrC,eAAsB,oBAAoB,QAAgB,UAAmD;CAC3G,OAAO,OAAO,YAAY,MAAM,QAAQ,IAAI,SAAS,KAAK,WAAW,iBAAiB,QAAQ,MAAM,CAAC,CAAC,CAAC;AACzG;;AAGA,eAAe,iBAAiB,QAAgB,QAAkD;CAChG,MAAM,EAAE,MAAM,YAAY,WAAW,kBAAkB;CAEvD,MAAM,cAAc,IAAA,GAAGC,YAAAA,UAAAA,CAAU,UAAU,EAAE;CAI7C,MAAM,WAAW,MAAM,gBAAA,GADNC,KAAAA,KAAAA,CAAK,OAAO,mBAAmB,GAAG,WAAW,IACjB,CAAC;CAC9C,IAAI,aAAa,KAAA,GAAW,OAAO,CAAC,YAAY,CAAC,CAAC;CAClD,IAAI,SAAS,QAAQ,WAAW,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;CAEhE,MAAM,UAAU,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;CACpD,KAAK,MAAM,aAAa,QAAQ,MAAM;EACpC,MAAM,cACJ,EAAE,uBAAuB,MAAM,SAAS,KAAK,EAAE,yBAAyB,MAAM,SAAS,IACnF,UAAU,cACV;EAEN,IAAI,eAAe,EAAE,iBAAiB,MAAM,WAAW,KAAK,YAAY,IAAI,SAAS,YACnF,OAAO,CACL,YACA,YAAY,KAAK,KAAK,SAAS,WAAW,iBAAiB,QAAQ,YAAY,aAAa,CAAC,CAC/F;CAEJ;CACA,OAAO,CAAC,YAAY,CAAC,CAAC;AACxB;;AAGA,eAAe,eAAe,UAA+C;CAC3E,IAAI;EACF,OAAO,OAAA,GAAMC,YAAAA,SAAAA,CAAS,UAAU,MAAM;CACxC,SAAS,GAAG;EACV,IAAI,kBAAkB,CA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,KAAK,SAAS,SAAS;CAEtG,IAAI,EAAE,eAAe,MAAM,IAAI,KAAK,KAAK,kBAAkB,EAAE,iBAAiB,MAAM,KAAK,cAAc,GACrG,OAAO,YAAY,KAAK,eAAe,gBAAgB,aAAa;CAEtE,IAAI,EAAE,oBAAoB,MAAM,IAAI,GAAG,OAAO,YAAY,KAAK,gBAAgB,aAAa;CAC5F,OAAO;AACT;;AAGA,SAAS,mBAAmB,aAAyB,YAA6B;CAChF,IAAI,CAAC,EAAE,eAAe,MAAM,WAAW,KAAK,CAAC,EAAE,iBAAiB,MAAM,WAAW,GAAG,OAAO;CAC3F,OAAO,wBAAwB,aAAa,UAAU;AACxD;;AAGA,SAAS,wBAAwB,YAAwB,YAA6B;CAEpF,IAAI,EAAE,WAAW,MAAM,UAAU,GAAG,OAAO,WAAW,SAAS,WAAW,WAAW,SAAS;CAC9F,IAAI,EAAE,eAAe,MAAM,UAAU,GAAG,OAAO,wBAAwB,WAAW,QAAQ,UAAU;CAEpG,IAAI,EAAE,iBAAiB,MAAM,UAAU,KAAK,CAAC,WAAW,UACtD,OAAO,wBAAwB,WAAW,QAAQ,UAAU;CAE9D,OAAO;AACT"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Config } from "./config.cjs";
|
|
2
2
|
import { Entity } from "./EntityDbMetadata.cjs";
|
|
3
|
-
//#region src/findEntityScopes.d.ts
|
|
4
3
|
/** Each `static active = ...` scope in an entity. */
|
|
5
4
|
export interface ScopeMember {
|
|
6
5
|
name: string;
|
|
@@ -9,5 +8,4 @@ export interface ScopeMember {
|
|
|
9
8
|
export type ScopeMembersByEntity = Record<string, ScopeMember[]>;
|
|
10
9
|
/** Finds static scope declarations for all entity files. */
|
|
11
10
|
export declare function findAllEntityScopes(config: Config, entities: Entity[]): Promise<ScopeMembersByEntity>;
|
|
12
|
-
//#endregion
|
|
13
11
|
//# sourceMappingURL=findEntityScopes.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findEntityScopes.d.cts","names":[],"sources":["../src/findEntityScopes.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"findEntityScopes.d.cts","names":[],"sources":["../src/findEntityScopes.ts"],"mappings":";;;iBAiBiB;EAEf;EAEA;;YAGU,uBAAuB,eAAe;;wBAG5B,oBAAoB,QAAQ,QAAQ,UAAU,WAAW,QAAQ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Config } from "./config.mjs";
|
|
2
2
|
import { Entity } from "./EntityDbMetadata.mjs";
|
|
3
|
-
//#region src/findEntityScopes.d.ts
|
|
4
3
|
/** Each `static active = ...` scope in an entity. */
|
|
5
4
|
export interface ScopeMember {
|
|
6
5
|
name: string;
|
|
@@ -9,5 +8,4 @@ export interface ScopeMember {
|
|
|
9
8
|
export type ScopeMembersByEntity = Record<string, ScopeMember[]>;
|
|
10
9
|
/** Finds static scope declarations for all entity files. */
|
|
11
10
|
export declare function findAllEntityScopes(config: Config, entities: Entity[]): Promise<ScopeMembersByEntity>;
|
|
12
|
-
//#endregion
|
|
13
11
|
//# sourceMappingURL=findEntityScopes.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findEntityScopes.d.mts","names":[],"sources":["../src/findEntityScopes.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"findEntityScopes.d.mts","names":[],"sources":["../src/findEntityScopes.ts"],"mappings":";;;iBAiBiB;EAEf;EAEA;;YAGU,uBAAuB,eAAe;;wBAG5B,oBAAoB,QAAQ,QAAQ,UAAU,WAAW,QAAQ"}
|
|
@@ -5,7 +5,7 @@ import { join } from "path";
|
|
|
5
5
|
import jscodeshift from "jscodeshift";
|
|
6
6
|
import { readFile } from "fs/promises";
|
|
7
7
|
import "ast-types";
|
|
8
|
-
|
|
8
|
+
// src/findEntityScopes.ts
|
|
9
9
|
const j = jscodeshift.withParser("ts");
|
|
10
10
|
/** Finds static scope declarations for all entity files. */
|
|
11
11
|
async function findAllEntityScopes(config, entities) {
|
|
@@ -110,7 +110,6 @@ function isScopeRootedExpression(expression, entityName) {
|
|
|
110
110
|
if (j.MemberExpression.check(expression) && !expression.computed) return isScopeRootedExpression(expression.object, entityName);
|
|
111
111
|
return false;
|
|
112
112
|
}
|
|
113
|
-
//#endregion
|
|
114
113
|
export { findAllEntityScopes };
|
|
115
114
|
|
|
116
115
|
//# sourceMappingURL=findEntityScopes.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
require("./EntityDbMetadata.cjs");
|
|
3
|
+
require("./index.cjs");
|
|
3
4
|
const require_logger = require("./logger.cjs");
|
|
4
5
|
const require_sortForeignKeys = require("./sortForeignKeys.cjs");
|
|
5
|
-
require("./
|
|
6
|
-
require("./EntityDbMetadata.cjs");
|
|
6
|
+
const require_utils = require("./utils.cjs");
|
|
7
7
|
let fs = require("fs");
|
|
8
|
-
|
|
8
|
+
// src/foreignKeyOrdering.ts
|
|
9
9
|
async function maybeSetForeignKeyOrdering(config, entities) {
|
|
10
10
|
if (!entities.some((e) => e.nonDeferredFks.length > 0)) {
|
|
11
11
|
for (const entity of entities) entity.nonDeferredFkOrder = 0;
|
|
@@ -46,7 +46,6 @@ async function writeAlterTables(nonDeferredFks) {
|
|
|
46
46
|
});
|
|
47
47
|
await fs.promises.writeFile("./alter-foreign-keys.sql", queries.join("\n"));
|
|
48
48
|
}
|
|
49
|
-
//#endregion
|
|
50
49
|
exports.maybeSetForeignKeyOrdering = maybeSetForeignKeyOrdering;
|
|
51
50
|
|
|
52
51
|
//# sourceMappingURL=foreignKeyOrdering.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foreignKeyOrdering.cjs","names":["sortByNonDeferredForeignKeys"],"sources":["../src/foreignKeyOrdering.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\n\nimport { type ManyToOneField, type PolymorphicFieldComponent } from \"./EntityDbMetadata.ts\";\nimport { type Config, type EntityDbMetadata } from \"./index.ts\";\nimport { logger } from \"./logger.ts\";\nimport { sortByNonDeferredForeignKeys } from \"./sortForeignKeys.ts\";\nimport { assertNever } from \"./utils.ts\";\n\nexport async function maybeSetForeignKeyOrdering(config: Config, entities: EntityDbMetadata[]): Promise<void> {\n // Hopefully all FKs are deferred, but if not...\n const hasAnyNonDeferredFks = entities.some((e) => e.nonDeferredFks.length > 0);\n if (!hasAnyNonDeferredFks) {\n // Great, nothing to do\n for (const entity of entities) entity.nonDeferredFkOrder = 0;\n return;\n }\n\n // Topo sort the non-deferred FKs into a DAG to establish insert/flush order\n const { notNullCycles } = sortByNonDeferredForeignKeys(entities);\n\n const { nonDeferredForeignKeys: setting = \"warn\" } = config;\n const nonDeferredFks = entities.flatMap((e) => e.nonDeferredFks.map((m2o) => ({ entity: e, m2o })));\n\n if (setting === \"error\" || setting === \"warn\") {\n logger[setting](`Found ${nonDeferredFks.length} foreign keys that are not DEFERRABLE/INITIALLY DEFERRED`);\n for (const { entity, m2o } of nonDeferredFks) console.log(`${entity.tableName}.${m2o.columnName}`);\n console.log(\"\");\n\n console.log(\"Please either:\");\n console.log(\" - Alter your migration to create the FKs as deferred (ideal)\");\n console.log(\" - Execute the generated alter-foreign-keys.sql file (one-time fix)\");\n console.log(\" - Set 'nonDeferredFks: ignore' in joist-config.json\");\n console.log(\"\");\n\n console.log(\"See https://joist-orm.io/getting-started/schema-assumptions#deferred-constraints\");\n console.log(\"\");\n\n await writeAlterTables(nonDeferredFks);\n } else if (setting === \"ignore\") {\n // We trust the user to know what they're doing\n } else {\n assertNever(setting);\n }\n\n // Always treat these as errors, even if `ignore` is set; maybe we need a `ignore-even-not-null-cycles`?\n // But they would still probably break flush_test_database. Unless we tell it to disable constraints,\n // like `ALTER TABLE your_table_name DISABLE TRIGGER ALL;`. But still unsure how we'd insert new rows.\n if (notNullCycles.length > 0) {\n logger.error(`Found a schema cycle of not-null foreign keys:`);\n notNullCycles.forEach((cycle) => console.log(cycle));\n console.log(\"\");\n console.log(\"These cycles can cause fatal em.flush & flush_test_database errors.\");\n console.log(\"\");\n console.log(\"Please make one of the FKs involved in the cycle nullable.\");\n console.log(\"\");\n }\n}\n\nasync function writeAlterTables(\n nonDeferredFks: Array<{\n entity: EntityDbMetadata;\n m2o: ManyToOneField | PolymorphicFieldComponent;\n }>,\n): Promise<void> {\n const queries = nonDeferredFks.map(({ entity, m2o }) => {\n return `ALTER TABLE ${entity.tableName} ALTER CONSTRAINT ${m2o.constraintName} DEFERRABLE INITIALLY DEFERRED;`;\n });\n await fs.writeFile(\"./alter-foreign-keys.sql\", queries.join(\"\\n\"));\n}\n"],"mappings":";;;;;;;;AAQA,eAAsB,2BAA2B,QAAgB,UAA6C;CAG5G,IAAI,CADyB,SAAS,MAAM,MAAM,EAAE,eAAe,SAAS,CACpD,GAAG;EAEzB,KAAK,MAAM,UAAU,UAAU,OAAO,qBAAqB;EAC3D;CACF;CAGA,MAAM,EAAE,kBAAkBA,wBAAAA,6BAA6B,QAAQ;CAE/D,MAAM,EAAE,wBAAwB,UAAU,WAAW;CACrD,MAAM,iBAAiB,SAAS,SAAS,MAAM,EAAE,eAAe,KAAK,SAAS;EAAE,QAAQ;EAAG;CAAI,EAAE,CAAC;CAElG,IAAI,YAAY,WAAW,YAAY,QAAQ;
|
|
1
|
+
{"version":3,"file":"foreignKeyOrdering.cjs","names":["sortByNonDeferredForeignKeys","logger","assertNever","fs"],"sources":["../src/foreignKeyOrdering.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\n\nimport { type ManyToOneField, type PolymorphicFieldComponent } from \"./EntityDbMetadata.ts\";\nimport { type Config, type EntityDbMetadata } from \"./index.ts\";\nimport { logger } from \"./logger.ts\";\nimport { sortByNonDeferredForeignKeys } from \"./sortForeignKeys.ts\";\nimport { assertNever } from \"./utils.ts\";\n\nexport async function maybeSetForeignKeyOrdering(config: Config, entities: EntityDbMetadata[]): Promise<void> {\n // Hopefully all FKs are deferred, but if not...\n const hasAnyNonDeferredFks = entities.some((e) => e.nonDeferredFks.length > 0);\n if (!hasAnyNonDeferredFks) {\n // Great, nothing to do\n for (const entity of entities) entity.nonDeferredFkOrder = 0;\n return;\n }\n\n // Topo sort the non-deferred FKs into a DAG to establish insert/flush order\n const { notNullCycles } = sortByNonDeferredForeignKeys(entities);\n\n const { nonDeferredForeignKeys: setting = \"warn\" } = config;\n const nonDeferredFks = entities.flatMap((e) => e.nonDeferredFks.map((m2o) => ({ entity: e, m2o })));\n\n if (setting === \"error\" || setting === \"warn\") {\n logger[setting](`Found ${nonDeferredFks.length} foreign keys that are not DEFERRABLE/INITIALLY DEFERRED`);\n for (const { entity, m2o } of nonDeferredFks) console.log(`${entity.tableName}.${m2o.columnName}`);\n console.log(\"\");\n\n console.log(\"Please either:\");\n console.log(\" - Alter your migration to create the FKs as deferred (ideal)\");\n console.log(\" - Execute the generated alter-foreign-keys.sql file (one-time fix)\");\n console.log(\" - Set 'nonDeferredFks: ignore' in joist-config.json\");\n console.log(\"\");\n\n console.log(\"See https://joist-orm.io/getting-started/schema-assumptions#deferred-constraints\");\n console.log(\"\");\n\n await writeAlterTables(nonDeferredFks);\n } else if (setting === \"ignore\") {\n // We trust the user to know what they're doing\n } else {\n assertNever(setting);\n }\n\n // Always treat these as errors, even if `ignore` is set; maybe we need a `ignore-even-not-null-cycles`?\n // But they would still probably break flush_test_database. Unless we tell it to disable constraints,\n // like `ALTER TABLE your_table_name DISABLE TRIGGER ALL;`. But still unsure how we'd insert new rows.\n if (notNullCycles.length > 0) {\n logger.error(`Found a schema cycle of not-null foreign keys:`);\n notNullCycles.forEach((cycle) => console.log(cycle));\n console.log(\"\");\n console.log(\"These cycles can cause fatal em.flush & flush_test_database errors.\");\n console.log(\"\");\n console.log(\"Please make one of the FKs involved in the cycle nullable.\");\n console.log(\"\");\n }\n}\n\nasync function writeAlterTables(\n nonDeferredFks: Array<{\n entity: EntityDbMetadata;\n m2o: ManyToOneField | PolymorphicFieldComponent;\n }>,\n): Promise<void> {\n const queries = nonDeferredFks.map(({ entity, m2o }) => {\n return `ALTER TABLE ${entity.tableName} ALTER CONSTRAINT ${m2o.constraintName} DEFERRABLE INITIALLY DEFERRED;`;\n });\n await fs.writeFile(\"./alter-foreign-keys.sql\", queries.join(\"\\n\"));\n}\n"],"mappings":";;;;;;;;AAQA,eAAsB,2BAA2B,QAAgB,UAA6C;CAG5G,IAAI,CADyB,SAAS,MAAM,MAAM,EAAE,eAAe,SAAS,CACpD,GAAG;EAEzB,KAAK,MAAM,UAAU,UAAU,OAAO,qBAAqB;EAC3D;CACF;CAGA,MAAM,EAAE,kBAAkBA,wBAAAA,6BAA6B,QAAQ;CAE/D,MAAM,EAAE,wBAAwB,UAAU,WAAW;CACrD,MAAM,iBAAiB,SAAS,SAAS,MAAM,EAAE,eAAe,KAAK,SAAS;EAAE,QAAQ;EAAG;CAAI,EAAE,CAAC;CAElG,IAAI,YAAY,WAAW,YAAY,QAAQ;EAC7CC,eAAAA,OAAO,QAAQ,CAAC,SAAS,eAAe,OAAO,yDAAyD;EACxG,KAAK,MAAM,EAAE,QAAQ,SAAS,gBAAgB,QAAQ,IAAI,GAAG,OAAO,UAAU,GAAG,IAAI,YAAY;EACjG,QAAQ,IAAI,EAAE;EAEd,QAAQ,IAAI,gBAAgB;EAC5B,QAAQ,IAAI,+DAA+D;EAC3E,QAAQ,IAAI,qEAAqE;EACjF,QAAQ,IAAI,sDAAsD;EAClE,QAAQ,IAAI,EAAE;EAEd,QAAQ,IAAI,kFAAkF;EAC9F,QAAQ,IAAI,EAAE;EAEd,MAAM,iBAAiB,cAAc;CACvC,OAAO,IAAI,YAAY,UAAU,CAEjC,OACEC,cAAAA,YAAY,OAAO;CAMrB,IAAI,cAAc,SAAS,GAAG;EAC5BD,eAAAA,OAAO,MAAM,gDAAgD;EAC7D,cAAc,SAAS,UAAU,QAAQ,IAAI,KAAK,CAAC;EACnD,QAAQ,IAAI,EAAE;EACd,QAAQ,IAAI,qEAAqE;EACjF,QAAQ,IAAI,EAAE;EACd,QAAQ,IAAI,4DAA4D;EACxE,QAAQ,IAAI,EAAE;CAChB;AACF;AAEA,eAAe,iBACb,gBAIe;CACf,MAAM,UAAU,eAAe,KAAK,EAAE,QAAQ,UAAU;EACtD,OAAO,eAAe,OAAO,UAAU,oBAAoB,IAAI,eAAe;CAChF,CAAC;CACD,MAAME,GAAAA,SAAG,UAAU,4BAA4B,QAAQ,KAAK,IAAI,CAAC;AACnE"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Config } from "./config.cjs";
|
|
2
2
|
import "./index.cjs";
|
|
3
3
|
import { EntityDbMetadata } from "./EntityDbMetadata.cjs";
|
|
4
|
-
//#region src/foreignKeyOrdering.d.ts
|
|
5
4
|
export declare function maybeSetForeignKeyOrdering(config: Config, entities: EntityDbMetadata[]): Promise<void>;
|
|
6
|
-
//#endregion
|
|
7
5
|
//# sourceMappingURL=foreignKeyOrdering.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foreignKeyOrdering.d.cts","names":[],"sources":["../src/foreignKeyOrdering.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"foreignKeyOrdering.d.cts","names":[],"sources":["../src/foreignKeyOrdering.ts"],"mappings":";;;wBAQsB,2BAA2B,QAAQ,QAAQ,UAAU,qBAAqB"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Config } from "./config.mjs";
|
|
2
2
|
import "./index.mjs";
|
|
3
3
|
import { EntityDbMetadata } from "./EntityDbMetadata.mjs";
|
|
4
|
-
//#region src/foreignKeyOrdering.d.ts
|
|
5
4
|
export declare function maybeSetForeignKeyOrdering(config: Config, entities: EntityDbMetadata[]): Promise<void>;
|
|
6
|
-
//#endregion
|
|
7
5
|
//# sourceMappingURL=foreignKeyOrdering.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foreignKeyOrdering.d.mts","names":[],"sources":["../src/foreignKeyOrdering.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"foreignKeyOrdering.d.mts","names":[],"sources":["../src/foreignKeyOrdering.ts"],"mappings":";;;wBAQsB,2BAA2B,QAAQ,QAAQ,UAAU,qBAAqB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./EntityDbMetadata.js";
|
|
2
|
+
import "./index.js";
|
|
2
3
|
import { logger } from "./logger.js";
|
|
3
4
|
import { sortByNonDeferredForeignKeys } from "./sortForeignKeys.js";
|
|
4
|
-
import "./
|
|
5
|
-
import "./EntityDbMetadata.js";
|
|
5
|
+
import { assertNever } from "./utils.js";
|
|
6
6
|
import { promises } from "fs";
|
|
7
|
-
|
|
7
|
+
// src/foreignKeyOrdering.ts
|
|
8
8
|
async function maybeSetForeignKeyOrdering(config, entities) {
|
|
9
9
|
if (!entities.some((e) => e.nonDeferredFks.length > 0)) {
|
|
10
10
|
for (const entity of entities) entity.nonDeferredFkOrder = 0;
|
|
@@ -45,7 +45,6 @@ async function writeAlterTables(nonDeferredFks) {
|
|
|
45
45
|
});
|
|
46
46
|
await promises.writeFile("./alter-foreign-keys.sql", queries.join("\n"));
|
|
47
47
|
}
|
|
48
|
-
//#endregion
|
|
49
48
|
export { maybeSetForeignKeyOrdering };
|
|
50
49
|
|
|
51
50
|
//# sourceMappingURL=foreignKeyOrdering.js.map
|
package/build/generate.cjs
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_utils = require("./utils.cjs");
|
|
3
|
-
const require_docs_generate_metadata_docs = require("./docs/generate-metadata-docs.cjs");
|
|
4
2
|
const require_docs_index = require("./docs/index.cjs");
|
|
3
|
+
const require_docs_generate_metadata_docs = require("./docs/generate-metadata-docs.cjs");
|
|
5
4
|
const require_findEntityScopes = require("./findEntityScopes.cjs");
|
|
6
5
|
const require_generateEntitiesFile = require("./generateEntitiesFile.cjs");
|
|
7
|
-
const require_symbols = require("./symbols.cjs");
|
|
8
6
|
const require_generateEntityCodegenFile = require("./generateEntityCodegenFile.cjs");
|
|
9
7
|
const require_generateEntityFile = require("./generateEntityFile.cjs");
|
|
10
8
|
const require_generateEntityTestFile = require("./generateEntityTestFile.cjs");
|
|
@@ -13,9 +11,11 @@ const require_generateFactoriesFiles = require("./generateFactoriesFiles.cjs");
|
|
|
13
11
|
const require_generateMetadataFile = require("./generateMetadataFile.cjs");
|
|
14
12
|
const require_generatePgEnumFile = require("./generatePgEnumFile.cjs");
|
|
15
13
|
require("./index.cjs");
|
|
14
|
+
const require_symbols = require("./symbols.cjs");
|
|
15
|
+
const require_utils = require("./utils.cjs");
|
|
16
16
|
let ts_poet = require("ts-poet");
|
|
17
17
|
let fs_promises = require("fs/promises");
|
|
18
|
-
|
|
18
|
+
// src/generate.ts
|
|
19
19
|
const runtimeRequire = (0, require("node:module").createRequire)(require("url").pathToFileURL(__filename).href);
|
|
20
20
|
/** Generates our `${Entity}` and `${Entity}Codegen` files based on the `db` schema. */
|
|
21
21
|
async function generateFiles(config, dbMeta) {
|
|
@@ -28,19 +28,23 @@ async function generateFiles(config, dbMeta) {
|
|
|
28
28
|
const entityFiles = entities.map((meta) => {
|
|
29
29
|
const entityName = meta.entity.name;
|
|
30
30
|
const hasEntityFile = files.includes(`${entityName}.ts`);
|
|
31
|
-
return [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
name: `./codegen/${entityName}Codegen.ts`,
|
|
34
|
+
contents: require_generateEntityCodegenFile.generateEntityCodegenFile(config, dbMeta, meta, scopeMembersByEntity[entityName] ?? [], config.docs ? entityDocs[entityName] : void 0),
|
|
35
|
+
overwrite: true
|
|
36
|
+
},
|
|
37
|
+
...hasEntityFile ? [] : [{
|
|
38
|
+
name: `${entityName}.ts`,
|
|
39
|
+
contents: require_generateEntityFile.generateEntityFile(config, meta),
|
|
40
|
+
overwrite: false
|
|
41
|
+
}],
|
|
42
|
+
...hasEntityFile || config.scaffoldTests === false ? [] : [{
|
|
43
|
+
name: `${entityName}.test.ts`,
|
|
44
|
+
contents: require_generateEntityTestFile.generateEntityTestFile(config, meta),
|
|
45
|
+
overwrite: false
|
|
46
|
+
}]
|
|
47
|
+
];
|
|
44
48
|
}).reduce(require_utils.merge, []);
|
|
45
49
|
const enumFiles = Object.values(enums).map((enumData) => {
|
|
46
50
|
const enumName = require_utils.tableToEntityName(config, enumData.table);
|
|
@@ -122,7 +126,6 @@ async function readExistingFiles(config) {
|
|
|
122
126
|
return [];
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
|
-
//#endregion
|
|
126
129
|
exports.generateFiles = generateFiles;
|
|
127
130
|
|
|
128
131
|
//# sourceMappingURL=generate.cjs.map
|
package/build/generate.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.cjs","names":["createRequire","syncDocs","loadEntityDocs","findAllEntityScopes","generateEntityCodegenFile","generateEntityFile","generateEntityTestFile","merge","tableToEntityName","generateEnumFile","generatePgEnumFile","imp","setRuntimeConfig","def","JoistEntityManager","Entity","getIdType","generateColumnDeclarations","generateMetadataFile","configureMetadata","generateEntitiesFile","generateFactoriesFiles","generateMetadataDocsFile","readdir"],"sources":["../src/generate.ts"],"sourcesContent":["import { readdir } from \"fs/promises\";\nimport { createRequire } from \"node:module\";\n\nimport { type CodegenFile, code, def, imp } from \"ts-poet\";\n\nimport { generateMetadataDocsFile, loadEntityDocs, syncDocs } from \"./docs/index.ts\";\nimport { findAllEntityScopes } from \"./findEntityScopes.ts\";\nimport { generateEntitiesFile } from \"./generateEntitiesFile.ts\";\nimport { generateEntityCodegenFile, getIdType } from \"./generateEntityCodegenFile.ts\";\nimport { generateEntityFile } from \"./generateEntityFile.ts\";\nimport { generateEntityTestFile } from \"./generateEntityTestFile.ts\";\nimport { generateEnumFile } from \"./generateEnumFile.ts\";\nimport { generateFactoriesFiles } from \"./generateFactoriesFiles.ts\";\nimport { generateColumnDeclarations, generateMetadataFile } from \"./generateMetadataFile.ts\";\nimport { generatePgEnumFile } from \"./generatePgEnumFile.ts\";\nimport { type Config, type DbMetadata } from \"./index.ts\";\nimport { Entity, JoistEntityManager, configureMetadata, setRuntimeConfig } from \"./symbols.ts\";\nimport { merge, tableToEntityName } from \"./utils.ts\";\n\nconst runtimeRequire = createRequire(import.meta.url);\n\nexport type DPrintOptions = Record<string, unknown>;\n\n/**\n * Provides an API for hooking into the codegen build step.\n */\nexport interface CodegenPlugin {\n run(config: Config, dbMeta: DbMetadata): Promise<CodegenFile>;\n}\n\n/** Generates our `${Entity}` and `${Entity}Codegen` files based on the `db` schema. */\nexport async function generateFiles(config: Config, dbMeta: DbMetadata): Promise<CodegenFile[]> {\n const { entities, enums, pgEnums } = dbMeta;\n const entityNames = entities.map((meta) => meta.entity.name);\n\n // Find existing entities so that, besides just using `overwrite: false`, we can completely\n // skip making test files except for the _first_ time we create an entity. This achieves\n // `.history`-like \"create once\" behavior without the need for the `.history` file.\n const files = await readExistingFiles(config);\n\n // Sync documentation: backfill .md from existing JSDocs, then sync MD -> JSDoc\n if (config.docs) {\n await syncDocs(config.entitiesDirectory, entityNames);\n }\n\n // Load the .md docs once (post-sync) to inject into codegen JSDocs and the runtime metadata-docs.ts\n const entityDocs =\n config.docs || config.outputDocs ? await loadEntityDocs(config.entitiesDirectory, entityNames) : {};\n\n const scopeMembersByEntity = await findAllEntityScopes(\n config,\n entities.map((meta) => meta.entity),\n );\n\n const entityFiles = entities\n .map((meta) => {\n const entityName = meta.entity.name;\n const hasEntityFile = files.includes(`${entityName}.ts`);\n return [\n {\n name: `./codegen/${entityName}Codegen.ts`,\n contents: generateEntityCodegenFile(\n config,\n dbMeta,\n meta,\n scopeMembersByEntity[entityName] ?? [],\n config.docs ? entityDocs[entityName] : undefined,\n ),\n overwrite: true,\n },\n ...(hasEntityFile\n ? []\n : [\n { name: `${entityName}.ts`, contents: generateEntityFile(config, meta), overwrite: false },\n { name: `${entityName}.test.ts`, contents: generateEntityTestFile(config, meta), overwrite: false },\n ]),\n ];\n })\n .reduce(merge, []);\n\n const enumFiles = Object.values(enums)\n .map((enumData) => {\n const enumName = tableToEntityName(config, enumData.table);\n return [\n {\n name: `./enums/${enumName}.ts`,\n contents: generateEnumFile(config, enumData, enumName),\n overwrite: true,\n },\n ];\n })\n .reduce(merge, []);\n const pgEnumFiles = Object.values(pgEnums)\n .map((enumData) => {\n return [\n {\n name: `./enums/${enumData.name}.ts`,\n contents: generatePgEnumFile(config, enumData),\n overwrite: true,\n },\n ];\n })\n .reduce(merge, []);\n\n const contextType = config.contextType ? imp(`t:${config.contextType}`) : \"{}\";\n const txnType = config.transactionType ? imp(`t:${config.transactionType}`) : \"unknown\";\n const maybeTagDelimiter =\n config.tagDelimiter === undefined\n ? code``\n : code`tagDelimiter: ${config.tagDelimiter === \"\" ? \"undefined\" : JSON.stringify(config.tagDelimiter)},`;\n\n const metadataFile: CodegenFile = {\n name: \"./codegen/metadata.ts\",\n contents: code`\n ${setRuntimeConfig}({\n temporal: ${config.temporal ? { timeZone: typeof config.temporal === \"boolean\" ? \"UTC\" : config.temporal.timeZone } : \"false\"},\n ${maybeTagDelimiter}\n });\n \n export class ${def(\"EntityManager\")} extends ${JoistEntityManager}<${contextType}, Entity, ${txnType}> {}\n\n export interface ${def(\"Entity\")} extends ${Entity} {\n id: ${getIdType(config)};\n em: EntityManager;\n }\n\n ${entities.map((meta) => generateColumnDeclarations(config, dbMeta, meta))}\n ${entities.map((meta) => generateMetadataFile(config, dbMeta, meta))}\n\n export const allMetadata = [${entities.map((meta) => meta.entity.metaName).join(\", \")}];\n ${configureMetadata}(allMetadata);\n `,\n overwrite: true,\n toStringOpts: { dprintOptions: { lineWidth: 400 } },\n };\n\n const enumsTables = Object.values(enums)\n .map(({ table }) => table)\n .sort((a, b) => a.name.localeCompare(b.name));\n\n const entitiesFile: CodegenFile = {\n name: \"./entities.ts\",\n contents: generateEntitiesFile(config, entities, enumsTables, Object.values(pgEnums)),\n overwrite: true,\n toStringOpts: { dprintOptions: { \"module.sortExportDeclarations\": \"maintain\" } },\n };\n\n const factoriesFiles: CodegenFile[] = generateFactoriesFiles(entities);\n\n const esmExt = config.esm ? (config.allowImportingTsExtensions ? \".ts\" : \".js\") : \"\";\n const indexFile: CodegenFile = {\n name: \"./index.ts\",\n contents: code`export * from \"./entities${esmExt}\"`,\n overwrite: false,\n };\n\n // Look for modules to require and call the exported `.run(Config, DbMeta)` method\n const pluginFiles: CodegenFile[] = (\n await Promise.all(\n (config.codegenPlugins ?? []).map((p) => {\n const plugin = runtimeRequire(p) as CodegenPlugin;\n return plugin.run(config, dbMeta);\n }),\n )\n ).flat();\n\n // Generate metadata-docs.ts if enabled\n const docsFile = config.outputDocs ? generateMetadataDocsFile(dbMeta, entityDocs) : undefined;\n\n return [\n ...entityFiles,\n ...enumFiles,\n ...pgEnumFiles,\n entitiesFile,\n ...factoriesFiles,\n metadataFile,\n ...(docsFile ? [docsFile] : []),\n indexFile,\n ...pluginFiles,\n ];\n}\n\n/** Reads the `entitiesDirectory` but just ignores if it doesn't exist yet. */\nasync function readExistingFiles(config: Config): Promise<string[]> {\n try {\n return await readdir(config.entitiesDirectory);\n } catch (e) {\n return [];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAM,kBAAA,wBAAiBA,CAAAA,CAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B;;AAYpD,eAAsB,cAAc,QAAgB,QAA4C;CAC9F,MAAM,EAAE,UAAU,OAAO,YAAY;CACrC,MAAM,cAAc,SAAS,KAAK,SAAS,KAAK,OAAO,IAAI;CAK3D,MAAM,QAAQ,MAAM,kBAAkB,MAAM;CAG5C,IAAI,O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AE9C,MAAM,eAA4B;EAChC,MAAM;EACN,UAAUC,6BAAAA,qBAAqB,QAAQ,UAAU,aAAa,OAAO,OAAO,OAAO,CAAC;EACpF,WAAW;EACX,cAAc,EAAE,eAAe,EAAE,iCAAiC,WAAW,EAAE;CACjF;CAEA,MAAM,iBAAgCC,+BAAAA,uBAAuB,QAAQ;CAErE,MAAM,SAAS,OAAO,MAAO,OAAO,6BAA6B,QAAQ,QAAS;CAClF,MAAM,YAAyB;EAC7B,MAAM;EACN,UAAU,QAAA,IAAI,4BAA4B,OAAO;EACjD,WAAW;CACb;CAGA,MAAM,eACJ,MAAM,QAAQ,KACX,OAAO,kBAAkB,CAAC,EAAA,CAAG,KAAK,MAAM;EAEvC,OADe,eAAe,CAClB,CAAC,CAAC,IAAI,QAAQ,MAAM;CAClC,CAAC,CACH,EAAA,CACA,KAAK;CAGP,MAAM,WAAW,OAAO,aAAaC,oCAAAA,yBAAyB,QAAQ,UAAU,IAAI,KAAA;CAEpF,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;EACH;EACA,GAAG;EACH;EACA,GAAI,WAAW,CAAC,QAAQ,IAAI,CAAC;EAC7B;EACA,GAAG;CACL;AACF;;AAGA,eAAe,kBAAkB,QAAmC;CAClE,IAAI;EACF,OAAO,OAAA,GAAMC,YAAAA,QAAAA,CAAQ,OAAO,iBAAiB;CAC/C,SAAS,GAAG;EACV,OAAO,CAAC;CACV;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.cjs","names":["createRequire","syncDocs","loadEntityDocs","findAllEntityScopes","generateEntityCodegenFile","generateEntityFile","generateEntityTestFile","merge","tableToEntityName","generateEnumFile","generatePgEnumFile","imp","code","setRuntimeConfig","def","JoistEntityManager","Entity","getIdType","generateColumnDeclarations","generateMetadataFile","configureMetadata","generateEntitiesFile","generateFactoriesFiles","generateMetadataDocsFile","readdir"],"sources":["../src/generate.ts"],"sourcesContent":["import { readdir } from \"fs/promises\";\nimport { createRequire } from \"node:module\";\n\nimport { type CodegenFile, code, def, imp } from \"ts-poet\";\n\nimport { generateMetadataDocsFile, loadEntityDocs, syncDocs } from \"./docs/index.ts\";\nimport { findAllEntityScopes } from \"./findEntityScopes.ts\";\nimport { generateEntitiesFile } from \"./generateEntitiesFile.ts\";\nimport { generateEntityCodegenFile, getIdType } from \"./generateEntityCodegenFile.ts\";\nimport { generateEntityFile } from \"./generateEntityFile.ts\";\nimport { generateEntityTestFile } from \"./generateEntityTestFile.ts\";\nimport { generateEnumFile } from \"./generateEnumFile.ts\";\nimport { generateFactoriesFiles } from \"./generateFactoriesFiles.ts\";\nimport { generateColumnDeclarations, generateMetadataFile } from \"./generateMetadataFile.ts\";\nimport { generatePgEnumFile } from \"./generatePgEnumFile.ts\";\nimport { type Config, type DbMetadata } from \"./index.ts\";\nimport { Entity, JoistEntityManager, configureMetadata, setRuntimeConfig } from \"./symbols.ts\";\nimport { merge, tableToEntityName } from \"./utils.ts\";\n\nconst runtimeRequire = createRequire(import.meta.url);\n\nexport type DPrintOptions = Record<string, unknown>;\n\n/**\n * Provides an API for hooking into the codegen build step.\n */\nexport interface CodegenPlugin {\n run(config: Config, dbMeta: DbMetadata): Promise<CodegenFile>;\n}\n\n/** Generates our `${Entity}` and `${Entity}Codegen` files based on the `db` schema. */\nexport async function generateFiles(config: Config, dbMeta: DbMetadata): Promise<CodegenFile[]> {\n const { entities, enums, pgEnums } = dbMeta;\n const entityNames = entities.map((meta) => meta.entity.name);\n\n // Find existing entities so that, besides just using `overwrite: false`, we can completely\n // skip making test files except for the _first_ time we create an entity. This achieves\n // `.history`-like \"create once\" behavior without the need for the `.history` file.\n const files = await readExistingFiles(config);\n\n // Sync documentation: backfill .md from existing JSDocs, then sync MD -> JSDoc\n if (config.docs) {\n await syncDocs(config.entitiesDirectory, entityNames);\n }\n\n // Load the .md docs once (post-sync) to inject into codegen JSDocs and the runtime metadata-docs.ts\n const entityDocs =\n config.docs || config.outputDocs ? await loadEntityDocs(config.entitiesDirectory, entityNames) : {};\n\n const scopeMembersByEntity = await findAllEntityScopes(\n config,\n entities.map((meta) => meta.entity),\n );\n\n const entityFiles = entities\n .map((meta) => {\n const entityName = meta.entity.name;\n const hasEntityFile = files.includes(`${entityName}.ts`);\n return [\n {\n name: `./codegen/${entityName}Codegen.ts`,\n contents: generateEntityCodegenFile(\n config,\n dbMeta,\n meta,\n scopeMembersByEntity[entityName] ?? [],\n config.docs ? entityDocs[entityName] : undefined,\n ),\n overwrite: true,\n },\n ...(hasEntityFile\n ? []\n : [{ name: `${entityName}.ts`, contents: generateEntityFile(config, meta), overwrite: false }]),\n ...(hasEntityFile || config.scaffoldTests === false\n ? []\n : [{ name: `${entityName}.test.ts`, contents: generateEntityTestFile(config, meta), overwrite: false }]),\n ];\n })\n .reduce(merge, []);\n\n const enumFiles = Object.values(enums)\n .map((enumData) => {\n const enumName = tableToEntityName(config, enumData.table);\n return [\n {\n name: `./enums/${enumName}.ts`,\n contents: generateEnumFile(config, enumData, enumName),\n overwrite: true,\n },\n ];\n })\n .reduce(merge, []);\n const pgEnumFiles = Object.values(pgEnums)\n .map((enumData) => {\n return [\n {\n name: `./enums/${enumData.name}.ts`,\n contents: generatePgEnumFile(config, enumData),\n overwrite: true,\n },\n ];\n })\n .reduce(merge, []);\n\n const contextType = config.contextType ? imp(`t:${config.contextType}`) : \"{}\";\n const txnType = config.transactionType ? imp(`t:${config.transactionType}`) : \"unknown\";\n const maybeTagDelimiter =\n config.tagDelimiter === undefined\n ? code``\n : code`tagDelimiter: ${config.tagDelimiter === \"\" ? \"undefined\" : JSON.stringify(config.tagDelimiter)},`;\n\n const metadataFile: CodegenFile = {\n name: \"./codegen/metadata.ts\",\n contents: code`\n ${setRuntimeConfig}({\n temporal: ${config.temporal ? { timeZone: typeof config.temporal === \"boolean\" ? \"UTC\" : config.temporal.timeZone } : \"false\"},\n ${maybeTagDelimiter}\n });\n \n export class ${def(\"EntityManager\")} extends ${JoistEntityManager}<${contextType}, Entity, ${txnType}> {}\n\n export interface ${def(\"Entity\")} extends ${Entity} {\n id: ${getIdType(config)};\n em: EntityManager;\n }\n\n ${entities.map((meta) => generateColumnDeclarations(config, dbMeta, meta))}\n ${entities.map((meta) => generateMetadataFile(config, dbMeta, meta))}\n\n export const allMetadata = [${entities.map((meta) => meta.entity.metaName).join(\", \")}];\n ${configureMetadata}(allMetadata);\n `,\n overwrite: true,\n toStringOpts: { dprintOptions: { lineWidth: 400 } },\n };\n\n const enumsTables = Object.values(enums)\n .map(({ table }) => table)\n .sort((a, b) => a.name.localeCompare(b.name));\n\n const entitiesFile: CodegenFile = {\n name: \"./entities.ts\",\n contents: generateEntitiesFile(config, entities, enumsTables, Object.values(pgEnums)),\n overwrite: true,\n toStringOpts: { dprintOptions: { \"module.sortExportDeclarations\": \"maintain\" } },\n };\n\n const factoriesFiles: CodegenFile[] = generateFactoriesFiles(entities);\n\n const esmExt = config.esm ? (config.allowImportingTsExtensions ? \".ts\" : \".js\") : \"\";\n const indexFile: CodegenFile = {\n name: \"./index.ts\",\n contents: code`export * from \"./entities${esmExt}\"`,\n overwrite: false,\n };\n\n // Look for modules to require and call the exported `.run(Config, DbMeta)` method\n const pluginFiles: CodegenFile[] = (\n await Promise.all(\n (config.codegenPlugins ?? []).map((p) => {\n const plugin = runtimeRequire(p) as CodegenPlugin;\n return plugin.run(config, dbMeta);\n }),\n )\n ).flat();\n\n // Generate metadata-docs.ts if enabled\n const docsFile = config.outputDocs ? generateMetadataDocsFile(dbMeta, entityDocs) : undefined;\n\n return [\n ...entityFiles,\n ...enumFiles,\n ...pgEnumFiles,\n entitiesFile,\n ...factoriesFiles,\n metadataFile,\n ...(docsFile ? [docsFile] : []),\n indexFile,\n ...pluginFiles,\n ];\n}\n\n/** Reads the `entitiesDirectory` but just ignores if it doesn't exist yet. */\nasync function readExistingFiles(config: Config): Promise<string[]> {\n try {\n return await readdir(config.entitiesDirectory);\n } catch (e) {\n return [];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAM,kBAAA,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CAAC;CACV;AACF"}
|
package/build/generate.d.cts
CHANGED
|
@@ -2,7 +2,6 @@ import { Config } from "./config.cjs";
|
|
|
2
2
|
import "./index.cjs";
|
|
3
3
|
import { DbMetadata } from "./EntityDbMetadata.cjs";
|
|
4
4
|
import { CodegenFile } from "ts-poet";
|
|
5
|
-
//#region src/generate.d.ts
|
|
6
5
|
export type DPrintOptions = Record<string, unknown>;
|
|
7
6
|
/**
|
|
8
7
|
* Provides an API for hooking into the codegen build step.
|
|
@@ -12,5 +11,4 @@ export interface CodegenPlugin {
|
|
|
12
11
|
}
|
|
13
12
|
/** Generates our `${Entity}` and `${Entity}Codegen` files based on the `db` schema. */
|
|
14
13
|
export declare function generateFiles(config: Config, dbMeta: DbMetadata): Promise<CodegenFile[]>;
|
|
15
|
-
//#endregion
|
|
16
14
|
//# sourceMappingURL=generate.d.cts.map
|
package/build/generate.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.cts","names":[],"sources":["../src/generate.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate.d.cts","names":[],"sources":["../src/generate.ts"],"mappings":";;;;YAqBY,gBAAgB;;;;iBAKX;EACf,IAAI,QAAQ,QAAQ,QAAQ,aAAa,QAAQ;;;wBAI7B,cAAc,QAAQ,QAAQ,QAAQ,aAAa,QAAQ"}
|
package/build/generate.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { Config } from "./config.mjs";
|
|
|
2
2
|
import "./index.mjs";
|
|
3
3
|
import { DbMetadata } from "./EntityDbMetadata.mjs";
|
|
4
4
|
import { CodegenFile } from "ts-poet";
|
|
5
|
-
//#region src/generate.d.ts
|
|
6
5
|
export type DPrintOptions = Record<string, unknown>;
|
|
7
6
|
/**
|
|
8
7
|
* Provides an API for hooking into the codegen build step.
|
|
@@ -12,5 +11,4 @@ export interface CodegenPlugin {
|
|
|
12
11
|
}
|
|
13
12
|
/** Generates our `${Entity}` and `${Entity}Codegen` files based on the `db` schema. */
|
|
14
13
|
export declare function generateFiles(config: Config, dbMeta: DbMetadata): Promise<CodegenFile[]>;
|
|
15
|
-
//#endregion
|
|
16
14
|
//# sourceMappingURL=generate.d.mts.map
|
package/build/generate.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.mts","names":[],"sources":["../src/generate.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate.d.mts","names":[],"sources":["../src/generate.ts"],"mappings":";;;;YAqBY,gBAAgB;;;;iBAKX;EACf,IAAI,QAAQ,QAAQ,QAAQ,aAAa,QAAQ;;;wBAI7B,cAAc,QAAQ,QAAQ,QAAQ,aAAa,QAAQ"}
|
package/build/generate.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { merge, tableToEntityName } from "./utils.js";
|
|
2
|
-
import { generateMetadataDocsFile } from "./docs/generate-metadata-docs.js";
|
|
3
1
|
import { loadEntityDocs, syncDocs } from "./docs/index.js";
|
|
2
|
+
import { generateMetadataDocsFile } from "./docs/generate-metadata-docs.js";
|
|
4
3
|
import { findAllEntityScopes } from "./findEntityScopes.js";
|
|
5
4
|
import { generateEntitiesFile } from "./generateEntitiesFile.js";
|
|
6
|
-
import { Entity, JoistEntityManager, configureMetadata, setRuntimeConfig } from "./symbols.js";
|
|
7
5
|
import { generateEntityCodegenFile, getIdType } from "./generateEntityCodegenFile.js";
|
|
8
6
|
import { generateEntityFile } from "./generateEntityFile.js";
|
|
9
7
|
import { generateEntityTestFile } from "./generateEntityTestFile.js";
|
|
@@ -12,10 +10,12 @@ import { generateFactoriesFiles } from "./generateFactoriesFiles.js";
|
|
|
12
10
|
import { generateColumnDeclarations, generateMetadataFile } from "./generateMetadataFile.js";
|
|
13
11
|
import { generatePgEnumFile } from "./generatePgEnumFile.js";
|
|
14
12
|
import "./index.js";
|
|
13
|
+
import { Entity, JoistEntityManager, configureMetadata, setRuntimeConfig } from "./symbols.js";
|
|
14
|
+
import { merge, tableToEntityName } from "./utils.js";
|
|
15
15
|
import { createRequire } from "node:module";
|
|
16
16
|
import { code, def, imp } from "ts-poet";
|
|
17
17
|
import { readdir } from "fs/promises";
|
|
18
|
-
|
|
18
|
+
// src/generate.ts
|
|
19
19
|
const runtimeRequire = createRequire(import.meta.url);
|
|
20
20
|
/** Generates our `${Entity}` and `${Entity}Codegen` files based on the `db` schema. */
|
|
21
21
|
async function generateFiles(config, dbMeta) {
|
|
@@ -28,19 +28,23 @@ async function generateFiles(config, dbMeta) {
|
|
|
28
28
|
const entityFiles = entities.map((meta) => {
|
|
29
29
|
const entityName = meta.entity.name;
|
|
30
30
|
const hasEntityFile = files.includes(`${entityName}.ts`);
|
|
31
|
-
return [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
name: `./codegen/${entityName}Codegen.ts`,
|
|
34
|
+
contents: generateEntityCodegenFile(config, dbMeta, meta, scopeMembersByEntity[entityName] ?? [], config.docs ? entityDocs[entityName] : void 0),
|
|
35
|
+
overwrite: true
|
|
36
|
+
},
|
|
37
|
+
...hasEntityFile ? [] : [{
|
|
38
|
+
name: `${entityName}.ts`,
|
|
39
|
+
contents: generateEntityFile(config, meta),
|
|
40
|
+
overwrite: false
|
|
41
|
+
}],
|
|
42
|
+
...hasEntityFile || config.scaffoldTests === false ? [] : [{
|
|
43
|
+
name: `${entityName}.test.ts`,
|
|
44
|
+
contents: generateEntityTestFile(config, meta),
|
|
45
|
+
overwrite: false
|
|
46
|
+
}]
|
|
47
|
+
];
|
|
44
48
|
}).reduce(merge, []);
|
|
45
49
|
const enumFiles = Object.values(enums).map((enumData) => {
|
|
46
50
|
const enumName = tableToEntityName(config, enumData.table);
|
|
@@ -122,7 +126,6 @@ async function readExistingFiles(config) {
|
|
|
122
126
|
return [];
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
|
-
//#endregion
|
|
126
129
|
export { generateFiles };
|
|
127
130
|
|
|
128
131
|
//# sourceMappingURL=generate.js.map
|