@tailor-platform/sdk 2.0.0-next.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/CHANGELOG.md +631 -0
  2. package/dist/{application-GzW98_Xr.mjs → application-CM6hKnSK.mjs} +489 -118
  3. package/dist/application-CM6hKnSK.mjs.map +1 -0
  4. package/dist/application-CXNaUNhv.mjs +3 -0
  5. package/dist/cli/commands/deploy/aigateway.d.mts +2 -2
  6. package/dist/cli/commands/deploy/application.d.mts +2 -2
  7. package/dist/cli/commands/deploy/auth.d.mts +2 -2
  8. package/dist/cli/commands/deploy/deploy.d.mts +1 -0
  9. package/dist/cli/commands/deploy/executor.d.mts +2 -2
  10. package/dist/cli/commands/deploy/function-registry.d.mts +1 -2
  11. package/dist/cli/commands/deploy/idp.d.mts +2 -2
  12. package/dist/cli/commands/deploy/label.d.mts +2 -0
  13. package/dist/cli/commands/deploy/resolver.d.mts +2 -2
  14. package/dist/cli/commands/deploy/secret-manager.d.mts +1 -1
  15. package/dist/cli/commands/deploy/staticwebsite.d.mts +2 -2
  16. package/dist/cli/commands/deploy/tailordb/index.d.mts +4 -2
  17. package/dist/cli/commands/deploy/types.d.mts +2 -1
  18. package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +1 -2
  19. package/dist/cli/commands/deploy/workflow.d.mts +2 -2
  20. package/dist/cli/commands/executor/get.d.mts +1 -10
  21. package/dist/cli/commands/executor/jobs.d.mts +1 -38
  22. package/dist/cli/commands/executor/trigger.d.mts +1 -11
  23. package/dist/cli/commands/generate/seed/bundler.d.mts +2 -1
  24. package/dist/cli/commands/tailordb/migrate/bundler.d.mts +3 -2
  25. package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +11 -1
  26. package/dist/cli/commands/tailordb/migrate/schema-checks.d.mts +5 -0
  27. package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +1 -1
  28. package/dist/cli/commands/workflow/executions.d.mts +1 -13
  29. package/dist/cli/commands/workflow/get.d.mts +1 -10
  30. package/dist/cli/commands/workflow/start.d.mts +2 -14
  31. package/dist/cli/index.mjs +12 -6552
  32. package/dist/cli/lib.d.mts +14 -15
  33. package/dist/cli/lib.mjs +203 -46
  34. package/dist/cli/lib.mjs.map +1 -1
  35. package/dist/cli/{index.d.mts → main.d.mts} +1 -1
  36. package/dist/cli/main.mjs +6777 -0
  37. package/dist/cli/main.mjs.map +1 -0
  38. package/dist/cli/services/http-adapter/bundler.d.mts +1 -0
  39. package/dist/cli/services/workflow/bundler.d.mts +2 -1
  40. package/dist/cli/shared/client.d.mts +28 -3
  41. package/dist/cli/shared/config-loader.d.mts +11 -4
  42. package/dist/cli/shared/error-json.d.mts +23 -0
  43. package/dist/cli/shared/script-executor.d.mts +6 -3
  44. package/dist/cli/shared/seed-chunker.d.mts +2 -7
  45. package/dist/cli/shared/seed-context.d.mts +49 -0
  46. package/dist/cli/shared/tailordb-namespaces.d.mts +7 -4
  47. package/dist/cli/shared/tsconfig-paths-plugin.d.mts +2 -0
  48. package/dist/cli/shared/type-generator.d.mts +4 -3
  49. package/dist/completion/zsh-worker.zsh +85 -22
  50. package/dist/configure/config/types.d.mts +29 -4
  51. package/dist/configure/index.d.mts +4 -3
  52. package/dist/configure/index.mjs +183 -6
  53. package/dist/configure/index.mjs.map +1 -1
  54. package/dist/configure/services/executor/index.d.mts +2 -2
  55. package/dist/configure/services/executor/trigger/event.d.mts +245 -2
  56. package/dist/configure/services/executor/trigger/index.d.mts +3 -3
  57. package/dist/configure/services/idp/index.d.mts +2 -2
  58. package/dist/configure/services/idp/permission.d.mts +1 -16
  59. package/dist/configure/services/idp/types.d.mts +5 -1
  60. package/dist/configure/services/index.d.mts +4 -3
  61. package/dist/configure/services/resolver/index.d.mts +2 -1
  62. package/dist/configure/services/resolver/permission.d.mts +64 -0
  63. package/dist/configure/services/resolver/resolver.d.mts +14 -2
  64. package/dist/configure/services/tailordb/index.d.mts +0 -1
  65. package/dist/configure/services/tailordb/permission.d.mts +1 -16
  66. package/dist/configure/services/workflow/execution-policy.d.mts +3 -3
  67. package/dist/configure/services/workflow/execution-policy.types.d.mts +1 -1
  68. package/dist/configure/services/workflow/job.d.mts +11 -2
  69. package/dist/configure/services/workflow/workflow.d.mts +10 -0
  70. package/dist/configure/types/permission-operand.types.d.mts +20 -0
  71. package/dist/{crashreport-CxHne11E.mjs → crashreport-B5LqCTfF.mjs} +2 -2
  72. package/dist/{crashreport-CxHne11E.mjs.map → crashreport-B5LqCTfF.mjs.map} +1 -1
  73. package/dist/{crashreport-0ioNRZ4K.mjs → crashreport-eI7ty7ok.mjs} +1 -1
  74. package/dist/{errors-DfnF4ibq.mjs → errors-D7583Zz7.mjs} +2 -44
  75. package/dist/errors-D7583Zz7.mjs.map +1 -0
  76. package/dist/{globals-CBZ0egXT.mjs → globals-TfAVItuK.mjs} +21 -5
  77. package/dist/globals-TfAVItuK.mjs.map +1 -0
  78. package/dist/logger-BtX0suGY.mjs +48 -0
  79. package/dist/logger-BtX0suGY.mjs.map +1 -0
  80. package/dist/{logger-BwS4ppwO.mjs → logger-CXQq9YIp.mjs} +110 -13
  81. package/dist/logger-CXQq9YIp.mjs.map +1 -0
  82. package/dist/node-builtins-CmaL2Cbq.mjs +36 -0
  83. package/dist/node-builtins-CmaL2Cbq.mjs.map +1 -0
  84. package/dist/plugin/builtin/enum-constants/index.mjs +115 -2
  85. package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -0
  86. package/dist/plugin/builtin/file-utils/index.mjs +149 -2
  87. package/dist/plugin/builtin/file-utils/index.mjs.map +1 -0
  88. package/dist/plugin/builtin/kysely-type/index.mjs +274 -2
  89. package/dist/plugin/builtin/kysely-type/index.mjs.map +1 -0
  90. package/dist/plugin/builtin/seed/index.d.mts +3 -2
  91. package/dist/plugin/builtin/seed/index.mjs +1 -1
  92. package/dist/plugin/builtin/seed/seed-type-processor.d.mts +21 -0
  93. package/dist/plugin/builtin/seed/types.d.mts +2 -0
  94. package/dist/{register-ts-hook-DvEs6YsL.mjs → register-ts-hook-LYV7zH-e.mjs} +2953 -996
  95. package/dist/register-ts-hook-LYV7zH-e.mjs.map +1 -0
  96. package/dist/{registry-i7EdJ-D5.mjs → registry-BIGVUrMB.mjs} +3 -3
  97. package/dist/registry-BIGVUrMB.mjs.map +1 -0
  98. package/dist/runtime/globals.d.mts +7 -0
  99. package/dist/runtime/index.d.mts +3 -1
  100. package/dist/runtime/index.mjs +3 -2
  101. package/dist/runtime/logger.d.mts +98 -0
  102. package/dist/runtime/logger.mjs +3 -0
  103. package/dist/runtime/workflow.d.mts +15 -7
  104. package/dist/runtime/workflow.mjs +1 -1
  105. package/dist/seed-B-yckgQY.mjs +483 -0
  106. package/dist/seed-B-yckgQY.mjs.map +1 -0
  107. package/dist/{service-DaeJlBoH.mjs → service-B5WynBHQ.mjs} +3 -3
  108. package/dist/{service-DaeJlBoH.mjs.map → service-B5WynBHQ.mjs.map} +1 -1
  109. package/dist/service-M7OYziQP.mjs +3 -0
  110. package/dist/{service-Dmxa2I4i.mjs → service-k1xy_A5G.mjs} +30 -4
  111. package/dist/service-k1xy_A5G.mjs.map +1 -0
  112. package/dist/{service_pb-BoLM0X4K.mjs → service_pb-D5--My_M.mjs} +5 -5
  113. package/dist/service_pb-D5--My_M.mjs.map +1 -0
  114. package/dist/{service_pb-r1T7kpJc.mjs → service_pb-i8CmnQP4.mjs} +1 -1
  115. package/dist/tailor-proto/src/tailor/v1/application_pb.d.mts +106 -1
  116. package/dist/tailor-proto/src/tailor/v1/auth_resource_pb.d.mts +6 -1
  117. package/dist/tailor-proto/src/tailor/v1/executor_resource_pb.d.mts +24 -1
  118. package/dist/tailor-proto/src/tailor/v1/function_pb.d.mts +49 -1
  119. package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +89 -6
  120. package/dist/tailor-proto/src/tailor/v1/telemetryrouter_resource_pb.d.mts +26 -1
  121. package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +101 -1
  122. package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +22 -1
  123. package/dist/types/auth.generated.d.mts +14 -2
  124. package/dist/types/executor.generated.d.mts +45 -3
  125. package/dist/types/http-adapter.generated.d.mts +5 -0
  126. package/dist/types/idp.generated.d.mts +31 -1
  127. package/dist/types/resolver.generated.d.mts +30 -2
  128. package/dist/types/tailordb.generated.d.mts +15 -3
  129. package/dist/utils/test/index.d.mts +1 -2
  130. package/dist/utils/test/index.mjs +1 -169
  131. package/dist/utils/test/index.mjs.map +1 -1
  132. package/dist/vitest/environment.mjs +1 -1
  133. package/dist/vitest/index.d.mts +6 -4
  134. package/dist/vitest/index.mjs +112 -62
  135. package/dist/vitest/index.mjs.map +1 -1
  136. package/dist/vitest/mock.d.mts +2 -1
  137. package/dist/vitest/mocks/logger.d.mts +45 -0
  138. package/dist/vitest/mocks/workflow.d.mts +8 -8
  139. package/dist/vitest/setup.mjs +1 -1
  140. package/dist/{workflow-CsBvRE3g.mjs → workflow-Bamae_Yc.mjs} +5 -5
  141. package/dist/workflow-Bamae_Yc.mjs.map +1 -0
  142. package/dist/{workspace_resource_pb-Db3fv68L.mjs → workspace_resource_pb-DXnO2AT-.mjs} +13 -8
  143. package/dist/workspace_resource_pb-DXnO2AT-.mjs.map +1 -0
  144. package/docs/cli/application.md +5 -1
  145. package/docs/cli/tailordb.md +47 -13
  146. package/docs/cli-reference.md +38 -30
  147. package/docs/configuration.md +54 -2
  148. package/docs/github-actions.md +2 -2
  149. package/docs/migration/v2.md +408 -5
  150. package/docs/runtime.md +5 -1
  151. package/docs/services/executor.md +83 -3
  152. package/docs/services/idp.md +8 -6
  153. package/docs/services/resolver.md +60 -4
  154. package/docs/services/tailordb-migration.md +31 -7
  155. package/docs/services/tailordb.md +7 -5
  156. package/docs/services/workflow.md +33 -3
  157. package/docs/testing.md +34 -7
  158. package/package.json +31 -24
  159. package/dist/application-GzW98_Xr.mjs.map +0 -1
  160. package/dist/application-OM0taSPn.mjs +0 -3
  161. package/dist/cli/index.mjs.map +0 -1
  162. package/dist/enum-constants-j9QBF0cB.mjs +0 -116
  163. package/dist/enum-constants-j9QBF0cB.mjs.map +0 -1
  164. package/dist/errors-DfnF4ibq.mjs.map +0 -1
  165. package/dist/file-utils-yEiIS4nJ.mjs +0 -150
  166. package/dist/file-utils-yEiIS4nJ.mjs.map +0 -1
  167. package/dist/globals-CBZ0egXT.mjs.map +0 -1
  168. package/dist/kysely-type-DqIRgDYR.mjs +0 -275
  169. package/dist/kysely-type-DqIRgDYR.mjs.map +0 -1
  170. package/dist/logger-BwS4ppwO.mjs.map +0 -1
  171. package/dist/register-ts-hook-DvEs6YsL.mjs.map +0 -1
  172. package/dist/registry-i7EdJ-D5.mjs.map +0 -1
  173. package/dist/seed-CRSQJI_z.mjs +0 -1170
  174. package/dist/seed-CRSQJI_z.mjs.map +0 -1
  175. package/dist/service-BJAQ70e5.mjs +0 -3
  176. package/dist/service-Dmxa2I4i.mjs.map +0 -1
  177. package/dist/service_pb-BoLM0X4K.mjs.map +0 -1
  178. package/dist/utils/test/mock.d.mts +0 -86
  179. package/dist/workflow-CsBvRE3g.mjs.map +0 -1
  180. package/dist/workspace_resource_pb-Db3fv68L.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-CXQq9YIp.mjs","names":[],"sources":["../src/cli/shared/ascii-table.ts","../src/cli/shared/parse-boolean.ts","../src/cli/shared/logger.ts"],"sourcesContent":["import { eastAsianWidth } from \"get-east-asian-width\";\n\n// eslint-disable-next-line no-control-regex\nconst ANSI_ESCAPE_PATTERN = /\\x1b\\[[0-9;]*m/g;\nconst CARRIAGE_RETURN_PATTERN = /\\r\\n?/g;\n\nconst graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\n\nexport interface AsciiTableConfig {\n /** Suppress horizontal lines between rows, keeping only the outer border. */\n singleLine?: boolean;\n /** Decide whether to draw the horizontal line at `lineIndex` (range `[0, rowCount]` inclusive). */\n drawHorizontalLine?: (lineIndex: number, rowCount: number) => boolean;\n}\n\ninterface CellLine {\n text: string;\n width: number;\n}\n\nfunction maxOf(values: number[], fallback = 0): number {\n return values.reduce((max, value) => (value > max ? value : max), fallback);\n}\n\nconst TAB_WIDTH = 8;\n\nfunction isStrippableControlCharacter(char: string): boolean {\n const codePoint = char.codePointAt(0) ?? 0;\n if (char === \"\\n\") {\n return false;\n }\n return codePoint <= 0x1f || codePoint === 0x7f;\n}\n\n// Only SGR (color/style) escape sequences are meant to survive; a bare ESC\n// that isn't part of a recognized SGR sequence (e.g. a screen-clear CSI\n// sequence, or a BEL-terminated OSC sequence) is treated like any other\n// control character below and stripped, rather than passed through to the\n// terminal or left with its terminator removed.\nfunction normalizeControlCharacters(value: string): string {\n const sgrSequences = value.match(ANSI_ESCAPE_PATTERN) ?? [];\n return value\n .split(ANSI_ESCAPE_PATTERN)\n .map((segment) => {\n const chars: string[] = [];\n for (const char of segment) {\n if (char === \"\\t\") {\n chars.push(\" \".repeat(TAB_WIDTH));\n } else if (!isStrippableControlCharacter(char)) {\n chars.push(char);\n }\n }\n return chars.join(\"\");\n })\n .reduce((result, segment, i) => result + segment + (sgrSequences[i] ?? \"\"), \"\");\n}\n\nfunction sanitizeCell(cell: unknown): string {\n return normalizeControlCharacters(String(cell ?? \"\").replace(CARRIAGE_RETURN_PATTERN, \"\\n\"));\n}\n\n// Clusters made up entirely of non-printing code points (lone joiners,\n// variation selectors, combining marks, etc.) render with no visible glyph.\nconst ZERO_WIDTH_CLUSTER_PATTERN =\n /^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Format}|\\p{Nonspacing_Mark}|\\p{Enclosing_Mark}|\\p{Surrogate})+$/v;\n// RGI_Emoji covers flags, keycaps, and VS16-forced presentation sequences,\n// which render as 2 columns in terminals even though their first code point\n// alone would measure as narrow/neutral.\nconst RGI_EMOJI_PATTERN = /^\\p{RGI_Emoji}$/v;\n\nfunction displayWidth(value: string): number {\n let width = 0;\n for (const { segment } of graphemeSegmenter.segment(value.replace(ANSI_ESCAPE_PATTERN, \"\"))) {\n if (ZERO_WIDTH_CLUSTER_PATTERN.test(segment)) {\n continue;\n }\n if (RGI_EMOJI_PATTERN.test(segment)) {\n width += 2;\n continue;\n }\n const codePoint = segment.codePointAt(0);\n width += codePoint === undefined ? 0 : eastAsianWidth(codePoint);\n }\n return width;\n}\n\nfunction toCellLines(cell: string): CellLine[] {\n return cell.split(\"\\n\").map((text) => ({ text, width: displayWidth(text) }));\n}\n\nfunction padCell(cellLine: CellLine, width: number): string {\n return cellLine.text + \" \".repeat(Math.max(0, width - cellLine.width));\n}\n\nfunction renderBorder(left: string, join: string, right: string, columnWidths: number[]): string {\n return left + columnWidths.map((width) => \"─\".repeat(width + 2)).join(join) + right;\n}\n\nfunction validateConsistentColumnCount(rows: string[][]): void {\n const columnCount = rows[0]?.length;\n if (columnCount === undefined) {\n return;\n }\n rows.forEach((row, index) => {\n if (row.length !== columnCount) {\n throw new Error(\n `renderTable: all rows must have the same number of columns (expected ${columnCount}, row ${index} has ${row.length}).`,\n );\n }\n });\n}\n\n/**\n * Renders a 2D array of values as a table using single-line Unicode box-drawing borders.\n * Column widths account for East Asian wide characters (measured per grapheme cluster,\n * so combining marks and ZWJ emoji sequences aren't overcounted, non-printing clusters\n * such as a lone joiner or combining mark measure as 0, and flags, keycaps, and\n * VS16-forced emoji presentation are measured as 2 columns) and strip ANSI SGR (color/style)\n * escape codes before measuring. Use this instead of importing a table-rendering package\n * directly.\n * @param data - Table rows; every row must have the same number of columns. Each cell is\n * stringified (`null`/`undefined` become an empty string rather than the literal text\n * \"null\"/\"undefined\"), may contain embedded newlines, has `\\r`/`\\r\\n` normalized to `\\n`,\n * has tabs expanded to spaces, and has other control characters stripped.\n * @param config - Rendering options\n * @returns The rendered table terminated with a trailing newline, or `\"\"` when there are no\n * rows or no columns to display\n */\nexport function renderTable(data: unknown[][], config: AsciiTableConfig = {}): string {\n const rows = data.map((row) => row.map(sanitizeCell));\n validateConsistentColumnCount(rows);\n\n const rowCount = rows.length;\n const columnCount = rows[0]?.length ?? 0;\n if (rowCount === 0 || columnCount === 0) {\n return \"\";\n }\n\n const rowsCellLines = rows.map((row) =>\n Array.from({ length: columnCount }, (_, col) => toCellLines(row[col] ?? \"\")),\n );\n const columnWidths = Array.from({ length: columnCount }, (_, col) =>\n maxOf(rowsCellLines.map((row) => maxOf((row[col] ?? []).map((line) => line.width)))),\n );\n\n const shouldDrawLine = (lineIndex: number): boolean =>\n config.singleLine\n ? lineIndex === 0 || lineIndex === rowCount\n : (config.drawHorizontalLine ?? (() => true))(lineIndex, rowCount);\n\n const lines: string[] = [];\n if (shouldDrawLine(0)) {\n lines.push(renderBorder(\"┌\", \"┬\", \"┐\", columnWidths));\n }\n\n rowsCellLines.forEach((cellLines, rowIndex) => {\n const rowHeight = maxOf(\n cellLines.map((columnLines) => columnLines.length),\n 1,\n );\n for (let line = 0; line < rowHeight; line++) {\n const cells = cellLines.map((columnLines, col) =>\n padCell(columnLines[line] ?? { text: \"\", width: 0 }, columnWidths[col] ?? 0),\n );\n lines.push(`│ ${cells.join(\" │ \")} │`);\n }\n if (rowIndex < rowCount - 1 && shouldDrawLine(rowIndex + 1)) {\n lines.push(renderBorder(\"├\", \"┼\", \"┤\", columnWidths));\n }\n });\n\n if (shouldDrawLine(rowCount)) {\n lines.push(renderBorder(\"└\", \"┴\", \"┘\", columnWidths));\n }\n\n return `${lines.join(\"\\n\")}\\n`;\n}\n","const TRUTHY_VALUES = new Set([\"true\", \"t\", \"yes\", \"y\", \"on\", \"1\"]);\nconst FALSY_VALUES = new Set([\"false\", \"f\", \"no\", \"n\", \"off\", \"0\"]);\n\n/**\n * Parse a string value as a boolean.\n *\n * Recognized values (case-insensitive, trimmed) follow Python's\n * `distutils.util.strtobool` convention:\n * - truthy: `true, t, yes, y, on, 1`\n * - falsy: `false, f, no, n, off, 0`\n *\n * Undefined, empty strings, and unrecognized values return `undefined` so\n * that callers can fall back to their own defaults.\n * @param value - The input string (e.g. an environment variable or CLI flag value)\n * @returns `true`, `false`, or `undefined` when the value is unset or unrecognized\n */\nexport function parseBoolean(value: string | undefined): boolean | undefined {\n if (value === undefined) return undefined;\n const normalized = value.trim().toLowerCase();\n if (normalized === \"\") return undefined;\n if (TRUTHY_VALUES.has(normalized)) return true;\n if (FALSY_VALUES.has(normalized)) return false;\n return undefined;\n}\n","import { formatWithOptions, type InspectOptions } from \"node:util\";\nimport chalk from \"chalk\";\nimport { formatDistanceToNowStrict } from \"date-fns\";\nimport { renderTable } from \"./ascii-table\";\nimport { parseBoolean } from \"./parse-boolean\";\n\n/**\n * Error thrown when a prompt is attempted in a non-interactive environment\n */\nexport class CIPromptError extends Error {\n constructor(message?: string) {\n super(\n message ??\n \"Interactive prompts are not available in this environment. Provide the required options explicitly.\",\n );\n this.name = \"CIPromptError\";\n }\n}\n\n/**\n * Semantic style functions for inline text styling\n */\nexport const styles = {\n // Status colors\n success: chalk.green,\n error: chalk.red,\n warning: chalk.yellow,\n info: chalk.cyan,\n\n // Action colors (for change sets)\n create: chalk.green,\n update: chalk.yellow,\n delete: chalk.red,\n unchanged: chalk.gray,\n\n // Emphasis\n bold: chalk.bold,\n dim: chalk.gray,\n highlight: chalk.cyanBright,\n successBright: chalk.greenBright,\n errorBright: chalk.redBright,\n\n // Resource types\n resourceType: chalk.bold,\n resourceName: chalk.cyan,\n\n // File paths\n path: chalk.cyan,\n\n // Values\n value: chalk.white,\n placeholder: chalk.gray.italic,\n};\n\n/**\n * Standardized symbols for CLI output\n */\nexport const symbols = {\n success: chalk.green(\"\\u2713\"),\n error: chalk.red(\"\\u2716\"),\n warning: chalk.yellow(\"\\u26a0\"),\n info: chalk.cyan(\"i\"),\n create: chalk.green(\"+\"),\n update: chalk.yellow(\"~\"),\n delete: chalk.red(\"-\"),\n replace: chalk.magenta(\"\\u00b1\"),\n bullet: chalk.gray(\"\\u2022\"),\n arrow: chalk.gray(\"\\u2192\"),\n};\n\n/**\n * Log output modes\n */\nexport type LogMode = \"default\" | \"stream\" | \"plain\";\n\nexport interface LogOptions {\n /** Output mode (default: \"default\") */\n mode?: LogMode;\n /** Number of spaces to indent the entire line (default: 0) */\n indent?: number;\n}\n\n/** Field transformer function. null excludes the field from table output. */\nexport type FieldTransformer = ((value: unknown, item: object) => string) | null;\n\nexport interface OutOptions {\n /** Table display field transform/exclude settings. Only applied in table mode (not JSON). */\n display?: Record<string, FieldTransformer>;\n\n /** Show null values in table output (default: false) */\n showNull?: boolean;\n}\n\n// In JSON mode, all logs go to stderr to keep stdout clean for JSON data\nlet _jsonMode = false;\n\n// Type icons for log output\nconst TYPE_ICONS: Record<string, string> = {\n info: \"ℹ\",\n success: \"✔\",\n warn: \"⚠\",\n error: \"✖\",\n debug: \"⚙\",\n trace: \"→\",\n log: \"\",\n};\n\n// Color functions for icon and message text\nconst TYPE_COLORS: Record<string, (text: string) => string> = {\n info: chalk.cyan,\n success: chalk.green,\n warn: chalk.yellow,\n error: chalk.red,\n debug: chalk.gray,\n trace: chalk.gray,\n log: (text) => text,\n};\n\ninterface FormatLogLineOptions {\n mode: string;\n indent: number;\n type: string;\n message: string;\n timestamp?: string;\n}\n\n/**\n * Formats a log line with the appropriate prefix and indentation\n * @param opts - Formatting options\n * @returns Formatted log line\n */\nexport function formatLogLine(opts: FormatLogLineOptions): string {\n const { mode, indent, type, message, timestamp } = opts;\n const indentPrefix = indent > 0 ? \" \".repeat(indent) : \"\";\n const colorFn = TYPE_COLORS[type] || ((text: string) => text);\n\n // Plain mode: color only, no icon, no timestamp\n if (mode === \"plain\") {\n return `${indentPrefix}${colorFn(message)}\\n`;\n }\n\n // Default/Stream mode: with icon and color\n const icon = TYPE_ICONS[type] || \"\";\n const prefix = icon ? `${icon} ` : \"\";\n const coloredOutput = colorFn(`${prefix}${message}`);\n const timestampPrefix = timestamp ?? \"\";\n\n return `${indentPrefix}${timestampPrefix}${coloredOutput}\\n`;\n}\n\n/**\n * Writes a formatted log line to stderr.\n * @param type - Log type (info, success, warn, error, log)\n * @param message - Log message\n * @param opts - Log options (mode and indent)\n */\nfunction writeLog(type: string, message: string, opts?: LogOptions): void {\n const mode = opts?.mode ?? \"default\";\n const indent = opts?.indent ?? 0;\n const inspectOpts: InspectOptions = {\n breakLength: process.stdout.columns || 80,\n };\n const formattedMessage = formatWithOptions(inspectOpts, message);\n const timestamp = mode === \"stream\" ? `${new Date().toLocaleTimeString()} ` : \"\";\n const output = formatLogLine({ mode, indent, type, message: formattedMessage, timestamp });\n process.stderr.write(output);\n}\n\nexport const logger = {\n get jsonMode(): boolean {\n return _jsonMode;\n },\n set jsonMode(value: boolean) {\n _jsonMode = value;\n },\n\n info(message: string, opts?: LogOptions): void {\n writeLog(\"info\", message, opts);\n },\n\n success(message: string, opts?: LogOptions): void {\n writeLog(\"success\", message, opts);\n },\n\n warn(message: string, opts?: LogOptions): void {\n writeLog(\"warn\", message, opts);\n },\n\n error(message: string, opts?: LogOptions): void {\n writeLog(\"error\", message, opts);\n },\n\n log(message: string): void {\n writeLog(\"log\", message, { mode: \"plain\" });\n },\n\n newline(): void {\n process.stderr.write(\"\\n\");\n },\n\n debug(message: string): void {\n if (parseBoolean(process.env.DEBUG) === true) {\n writeLog(\"log\", styles.dim(message), { mode: \"plain\" });\n }\n },\n\n out(data: string | object | object[], options?: OutOptions): void {\n if (typeof data === \"string\") {\n process.stdout.write(data.endsWith(\"\\n\") ? data : data + \"\\n\");\n return;\n }\n\n if (this.jsonMode) {\n // eslint-disable-next-line no-restricted-syntax\n console.log(JSON.stringify(data));\n return;\n }\n\n const display = options?.display;\n\n // Helper to format a value for table display\n const formatValue = (value: unknown, pretty = false): string => {\n if (options?.showNull && value === null) return \"NULL\";\n if (value === null || value === undefined) return \"N/A\";\n if (value instanceof Date) {\n return formatDistanceToNowStrict(value, { addSuffix: true });\n }\n if (typeof value === \"object\") {\n return pretty ? JSON.stringify(value, null, 2) : JSON.stringify(value);\n }\n return String(value);\n };\n\n // Helper to check if field should be excluded\n const isExcluded = (key: string): boolean => {\n return display !== undefined && key in display && display[key] === null;\n };\n\n // Helper to apply transformer or default formatting\n const transformValue = (key: string, value: unknown, item: object, pretty = false): string => {\n if (display && key in display) {\n const transformer = display[key];\n if (transformer) {\n return transformer(value, item);\n }\n }\n return formatValue(value, pretty);\n };\n\n if (!Array.isArray(data)) {\n const entries = Object.entries(data).filter(([key]) => !isExcluded(key));\n const formattedEntries = entries.map(([key, value]) => [\n key,\n transformValue(key, value, data, true),\n ]);\n const t = renderTable(formattedEntries, { singleLine: false });\n process.stdout.write(t);\n return;\n }\n\n if (data.length === 0) {\n return;\n }\n\n const allHeaders = Array.from(new Set(data.flatMap((item) => Object.keys(item))));\n const headers = allHeaders.filter((h) => !isExcluded(h));\n if (headers.length === 0) {\n return;\n }\n const rows = data.map((item) =>\n headers.map((header) =>\n transformValue(header, (item as Record<string, unknown>)[header], item),\n ),\n );\n\n const t = renderTable([headers, ...rows], {\n drawHorizontalLine: (lineIndex, rowCount) => {\n return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;\n },\n });\n process.stdout.write(t);\n },\n};\n"],"mappings":";;;;;;AAGA,MAAM,sBAAsB;AAC5B,MAAM,0BAA0B;AAEhC,MAAM,oBAAoB,IAAI,KAAK,UAAU,QAAW,EAAE,aAAa,WAAW,CAAC;AAcnF,SAAS,MAAM,QAAkB,WAAW,GAAW;CACrD,OAAO,OAAO,QAAQ,KAAK,UAAW,QAAQ,MAAM,QAAQ,KAAM,QAAQ;AAC5E;AAEA,MAAM,YAAY;AAElB,SAAS,6BAA6B,MAAuB;CAC3D,MAAM,YAAY,KAAK,YAAY,CAAC,KAAK;CACzC,IAAI,SAAS,MACX,OAAO;CAET,OAAO,aAAa,MAAQ,cAAc;AAC5C;AAOA,SAAS,2BAA2B,OAAuB;CACzD,MAAM,eAAe,MAAM,MAAM,mBAAmB,KAAK,CAAC;CAC1D,OAAO,MACJ,MAAM,mBAAmB,CAAC,CAC1B,KAAK,YAAY;EAChB,MAAM,QAAkB,CAAC;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QAAyB;GAC3C,OAAO,YAAY,UAAa,OAAO,WAAW,QAAQ,SAAS;EACrE;EAGA,MAAM,kBAAkB,KAAa,OAAgB,MAAc,SAAS,UAAkB;GAC5F,IAAI,WAAW,OAAO,SAAS;IAC7B,MAAM,cAAc,QAAQ;IAC5B,IAAI,aACF,OAAO,YAAY,OAAO,IAAI;GAElC;GACA,OAAO,YAAY,OAAO,MAAM;EAClC;EAEA,IAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;GAMxB,MAAM,IAAI,YALM,OAAO,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,GAAG,CACvC,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CACrD,KACA,eAAe,KAAK,OAAO,MAAM,IAAI,CACvC,CACqC,GAAG,EAAE,YAAY,MAAM,CAAC;GAC7D,QAAQ,OAAO,MAAM,CAAC;GACtB;EACF;EAEA,IAAI,KAAK,WAAW,GAClB;EAIF,MAAM,UADa,MAAM,KAAK,IAAI,IAAI,KAAK,SAAS,SAAS,OAAO,KAAK,IAAI,CAAC,CAAC,CACtD,CAAC,CAAC,QAAQ,MAAM,CAAC,WAAW,CAAC,CAAC;EACvD,IAAI,QAAQ,WAAW,GACrB;EAQF,MAAM,IAAI,YAAY,CAAC,SAAS,GANnB,KAAK,KAAK,SACrB,QAAQ,KAAK,WACX,eAAe,QAAS,KAAiC,SAAS,IAAI,CACxE,CAGoC,CAAC,GAAG,EACxC,qBAAqB,WAAW,aAAa;GAC3C,OAAO,cAAc,KAAK,cAAc,KAAK,cAAc;EAC7D,EACF,CAAC;EACD,QAAQ,OAAO,MAAM,CAAC;CACxB;AACF"}
@@ -0,0 +1,36 @@
1
+ import { isBuiltin } from "node:module";
2
+
3
+ //#region src/utils/node-builtins.ts
4
+ const SUGGESTIONS = {
5
+ crypto: "Use the Web Crypto API (globalThis.crypto) instead.",
6
+ buffer: "Use Uint8Array or ArrayBuffer instead.",
7
+ fs: "File system access is not available in the Tailor Platform runtime.",
8
+ "fs/promises": "File system access is not available in the Tailor Platform runtime.",
9
+ path: "Use URL or URLPattern for path manipulation.",
10
+ http: "Use the Fetch API (globalThis.fetch) for HTTP requests instead.",
11
+ https: "Use the Fetch API (globalThis.fetch) for HTTPS requests instead.",
12
+ url: "Use the URL and URLSearchParams Web APIs instead.",
13
+ util: "Use Web Standard APIs instead.",
14
+ stream: "Use Web Streams API (ReadableStream, WritableStream, TransformStream) instead.",
15
+ "stream/web": "Use Web Streams API (ReadableStream, WritableStream, TransformStream) instead.",
16
+ events: "Use EventTarget instead.",
17
+ zlib: "Use CompressionStream and DecompressionStream Web APIs instead.",
18
+ querystring: "Use URLSearchParams instead.",
19
+ string_decoder: "Use TextDecoder instead."
20
+ };
21
+ function isNodeBuiltinImport(specifier) {
22
+ return isBuiltin(specifier);
23
+ }
24
+ function getNodeBuiltinMessage(specifier) {
25
+ const bare = normalizeNodeBuiltinSpecifier(specifier);
26
+ const suggestion = SUGGESTIONS[bare];
27
+ const base = `"${specifier}" is not available in the Tailor Platform runtime.`;
28
+ return suggestion ? `${base} ${suggestion}` : base;
29
+ }
30
+ function normalizeNodeBuiltinSpecifier(specifier) {
31
+ return specifier.startsWith("node:") ? specifier.slice(5) : specifier;
32
+ }
33
+
34
+ //#endregion
35
+ export { isNodeBuiltinImport as n, getNodeBuiltinMessage as t };
36
+ //# sourceMappingURL=node-builtins-CmaL2Cbq.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-builtins-CmaL2Cbq.mjs","names":[],"sources":["../src/utils/node-builtins.ts"],"sourcesContent":["import { isBuiltin } from \"node:module\";\n\nconst SUGGESTIONS: Record<string, string> = {\n crypto: \"Use the Web Crypto API (globalThis.crypto) instead.\",\n buffer: \"Use Uint8Array or ArrayBuffer instead.\",\n fs: \"File system access is not available in the Tailor Platform runtime.\",\n \"fs/promises\": \"File system access is not available in the Tailor Platform runtime.\",\n path: \"Use URL or URLPattern for path manipulation.\",\n http: \"Use the Fetch API (globalThis.fetch) for HTTP requests instead.\",\n https: \"Use the Fetch API (globalThis.fetch) for HTTPS requests instead.\",\n url: \"Use the URL and URLSearchParams Web APIs instead.\",\n util: \"Use Web Standard APIs instead.\",\n stream: \"Use Web Streams API (ReadableStream, WritableStream, TransformStream) instead.\",\n \"stream/web\": \"Use Web Streams API (ReadableStream, WritableStream, TransformStream) instead.\",\n events: \"Use EventTarget instead.\",\n zlib: \"Use CompressionStream and DecompressionStream Web APIs instead.\",\n querystring: \"Use URLSearchParams instead.\",\n string_decoder: \"Use TextDecoder instead.\",\n};\n\nexport function isNodeBuiltinImport(specifier: string): boolean {\n return isBuiltin(specifier);\n}\n\nexport function getNodeBuiltinMessage(specifier: string): string {\n const bare = normalizeNodeBuiltinSpecifier(specifier);\n const suggestion = SUGGESTIONS[bare];\n const base = `\"${specifier}\" is not available in the Tailor Platform runtime.`;\n return suggestion ? `${base} ${suggestion}` : base;\n}\n\nfunction normalizeNodeBuiltinSpecifier(specifier: string): string {\n return specifier.startsWith(\"node:\") ? specifier.slice(5) : specifier;\n}\n"],"mappings":";;;AAEA,MAAM,cAAsC;CAC1C,QAAQ;CACR,QAAQ;CACR,IAAI;CACJ,eAAe;CACf,MAAM;CACN,MAAM;CACN,OAAO;CACP,KAAK;CACL,MAAM;CACN,QAAQ;CACR,cAAc;CACd,QAAQ;CACR,MAAM;CACN,aAAa;CACb,gBAAgB;AAClB;AAEA,SAAgB,oBAAoB,WAA4B;CAC9D,OAAO,UAAU,SAAS;AAC5B;AAEA,SAAgB,sBAAsB,WAA2B;CAC/D,MAAM,OAAO,8BAA8B,SAAS;CACpD,MAAM,aAAa,YAAY;CAC/B,MAAM,OAAO,IAAI,UAAU;CAC3B,OAAO,aAAa,GAAG,KAAK,GAAG,eAAe;AAChD;AAEA,SAAS,8BAA8B,WAA2B;CAChE,OAAO,UAAU,WAAW,OAAO,IAAI,UAAU,MAAM,CAAC,IAAI;AAC9D"}
@@ -1,3 +1,116 @@
1
- import { n as enumConstantsPlugin, t as EnumConstantsGeneratorID } from "../../../enum-constants-j9QBF0cB.mjs";
1
+ //#region src/plugin/builtin/enum-constants/generate-enum-constants.ts
2
+ /**
3
+ * Generate enum constant definitions from collected metadata.
4
+ * @param allEnums - All collected enum definitions
5
+ * @returns Generated enum constant definitions
6
+ */
7
+ function generateUnifiedEnumConstants(allEnums) {
8
+ if (allEnums.length === 0) return "";
9
+ const enumMap = /* @__PURE__ */ new Map();
10
+ for (const enumDef of allEnums) enumMap.set(enumDef.name, enumDef);
11
+ const enumDefs = Array.from(enumMap.values()).map((e) => {
12
+ const members = e.values.map((v) => {
13
+ return ` "${v.value.replace(/[-\s]/g, "_")}": "${v.value}"`;
14
+ }).join(",\n");
15
+ const hasDescriptions = e.values.some((v) => v.description);
16
+ let jsDoc = "";
17
+ if (e.fieldDescription || hasDescriptions) {
18
+ const lines = [];
19
+ if (e.fieldDescription) {
20
+ lines.push(` * ${e.fieldDescription}`);
21
+ if (hasDescriptions) lines.push(" *");
22
+ }
23
+ if (hasDescriptions) {
24
+ const propertyDocs = e.values.map((v) => {
25
+ return ` * @property ${[v.value.replace(/[-\s]/g, "_"), v.description].filter(Boolean).join(" - ")}`;
26
+ });
27
+ lines.push(...propertyDocs);
28
+ }
29
+ if (lines.length > 0) jsDoc = `/**\n${lines.join("\n")}\n */\n`;
30
+ }
31
+ return `${`${jsDoc}export const ${e.name} = {\n${members}\n} as const;`}\n${`export type ${e.name} = (typeof ${e.name})[keyof typeof ${e.name}];`}`;
32
+ }).join("\n\n");
33
+ if (!enumDefs) return "";
34
+ return enumDefs + "\n";
35
+ }
2
36
 
3
- export { EnumConstantsGeneratorID, enumConstantsPlugin };
37
+ //#endregion
38
+ //#region src/plugin/builtin/enum-constants/process-enum-type.ts
39
+ function capitalizeFirst(str) {
40
+ return str.charAt(0).toUpperCase() + str.slice(1);
41
+ }
42
+ function collectEnums(type) {
43
+ const enums = [];
44
+ for (const [fieldName, parsedField] of Object.entries(type.fields)) {
45
+ if (parsedField.config.type === "enum" && parsedField.config.allowedValues) {
46
+ const enumTypeName = `${type.name}${capitalizeFirst(fieldName)}`;
47
+ enums.push({
48
+ name: enumTypeName,
49
+ values: parsedField.config.allowedValues,
50
+ fieldDescription: parsedField.config.description
51
+ });
52
+ }
53
+ if (parsedField.config.type === "nested" && parsedField.config.fields) {
54
+ for (const [nestedFieldName, nestedFieldConfig] of Object.entries(parsedField.config.fields)) if (nestedFieldConfig.type === "enum" && nestedFieldConfig.allowedValues) {
55
+ const fullFieldName = `${fieldName}${capitalizeFirst(nestedFieldName)}`;
56
+ const enumTypeName = `${type.name}${capitalizeFirst(fullFieldName)}`;
57
+ enums.push({
58
+ name: enumTypeName,
59
+ values: nestedFieldConfig.allowedValues,
60
+ fieldDescription: nestedFieldConfig.description
61
+ });
62
+ }
63
+ }
64
+ }
65
+ return enums;
66
+ }
67
+ /**
68
+ * Process a TailorDB type and extract enum metadata.
69
+ * @param type - The parsed TailorDB type to process
70
+ * @returns Enum constant metadata for the type
71
+ */
72
+ async function processEnumType(type) {
73
+ const enums = collectEnums(type);
74
+ return {
75
+ name: type.name,
76
+ enums
77
+ };
78
+ }
79
+
80
+ //#endregion
81
+ //#region src/plugin/builtin/enum-constants/index.ts
82
+ /** Unique identifier for the enum constants generator plugin. */
83
+ const EnumConstantsGeneratorID = "@tailor-platform/enum-constants";
84
+ /**
85
+ * Plugin that generates enum constants from TailorDB type definitions.
86
+ * @param options - Plugin options
87
+ * @param options.distPath - Output file path for generated constants
88
+ * @returns Plugin instance with onTailorDBReady hook
89
+ */
90
+ function enumConstantsPlugin(options) {
91
+ return {
92
+ id: EnumConstantsGeneratorID,
93
+ description: "Generates enum constants from TailorDB type definitions",
94
+ pluginConfig: options,
95
+ async onTailorDBReady(ctx) {
96
+ const allEnums = [];
97
+ for (const ns of ctx.tailordb) for (const type of Object.values(ns.types)) {
98
+ const metadata = await processEnumType(type);
99
+ allEnums.push(...metadata.enums);
100
+ }
101
+ const files = [];
102
+ if (allEnums.length > 0) {
103
+ const content = generateUnifiedEnumConstants(allEnums);
104
+ files.push({
105
+ path: ctx.pluginConfig.distPath,
106
+ content
107
+ });
108
+ }
109
+ return { files };
110
+ }
111
+ };
112
+ }
113
+
114
+ //#endregion
115
+ export { EnumConstantsGeneratorID, enumConstantsPlugin };
116
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/plugin/builtin/enum-constants/generate-enum-constants.ts","../../../../src/plugin/builtin/enum-constants/process-enum-type.ts","../../../../src/plugin/builtin/enum-constants/index.ts"],"sourcesContent":["import type { EnumDefinition } from \"./types\";\n\n/**\n * Generate enum constant definitions from collected metadata.\n * @param allEnums - All collected enum definitions\n * @returns Generated enum constant definitions\n */\nexport function generateUnifiedEnumConstants(allEnums: EnumDefinition[]): string {\n if (allEnums.length === 0) {\n return \"\";\n }\n\n const enumMap = new Map<string, EnumDefinition>();\n for (const enumDef of allEnums) {\n enumMap.set(enumDef.name, enumDef);\n }\n\n const enumDefs = Array.from(enumMap.values())\n .map((e) => {\n const members = e.values\n .map((v) => {\n const key = v.value.replace(/[-\\s]/g, \"_\");\n return ` \"${key}\": \"${v.value}\"`;\n })\n .join(\",\\n\");\n\n const hasDescriptions = e.values.some((v) => v.description);\n let jsDoc = \"\";\n if (e.fieldDescription || hasDescriptions) {\n const lines: string[] = [];\n\n if (e.fieldDescription) {\n lines.push(` * ${e.fieldDescription}`);\n if (hasDescriptions) {\n lines.push(\" *\");\n }\n }\n\n if (hasDescriptions) {\n const propertyDocs = e.values.map((v) => {\n const key = v.value.replace(/[-\\s]/g, \"_\");\n return ` * @property ${[key, v.description].filter(Boolean).join(\" - \")}`;\n });\n lines.push(...propertyDocs);\n }\n\n if (lines.length > 0) {\n jsDoc = `/**\\n${lines.join(\"\\n\")}\\n */\\n`;\n }\n }\n\n const constDef = `${jsDoc}export const ${e.name} = {\\n${members}\\n} as const;`;\n const typeDef = `export type ${e.name} = (typeof ${e.name})[keyof typeof ${e.name}];`;\n return `${constDef}\\n${typeDef}`;\n })\n .join(\"\\n\\n\");\n\n if (!enumDefs) {\n return \"\";\n }\n\n return enumDefs + \"\\n\";\n}\n","import type { TailorDBType } from \"#/parser/service/tailordb/types\";\nimport type { EnumConstantMetadata } from \"./types\";\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nfunction collectEnums(type: TailorDBType): EnumConstantMetadata[\"enums\"] {\n const enums: EnumConstantMetadata[\"enums\"] = [];\n\n for (const [fieldName, parsedField] of Object.entries(type.fields)) {\n if (parsedField.config.type === \"enum\" && parsedField.config.allowedValues) {\n const enumTypeName = `${type.name}${capitalizeFirst(fieldName)}`;\n enums.push({\n name: enumTypeName,\n values: parsedField.config.allowedValues,\n fieldDescription: parsedField.config.description,\n });\n }\n\n // Process nested fields\n if (parsedField.config.type === \"nested\" && parsedField.config.fields) {\n for (const [nestedFieldName, nestedFieldConfig] of Object.entries(\n parsedField.config.fields,\n )) {\n if (nestedFieldConfig.type === \"enum\" && nestedFieldConfig.allowedValues) {\n const fullFieldName = `${fieldName}${capitalizeFirst(nestedFieldName)}`;\n const enumTypeName = `${type.name}${capitalizeFirst(fullFieldName)}`;\n enums.push({\n name: enumTypeName,\n values: nestedFieldConfig.allowedValues,\n fieldDescription: nestedFieldConfig.description,\n });\n }\n }\n }\n }\n\n return enums;\n}\n\n/**\n * Process a TailorDB type and extract enum metadata.\n * @param type - The parsed TailorDB type to process\n * @returns Enum constant metadata for the type\n */\nexport async function processEnumType(type: TailorDBType): Promise<EnumConstantMetadata> {\n const enums = collectEnums(type);\n\n return {\n name: type.name,\n enums,\n };\n}\n","import { generateUnifiedEnumConstants } from \"./generate-enum-constants\";\nimport { processEnumType } from \"./process-enum-type\";\nimport type { Plugin, GeneratorResult, TailorDBReadyContext } from \"#/plugin/types\";\nimport type { EnumDefinition } from \"./types\";\n\n/** Unique identifier for the enum constants generator plugin. */\nexport const EnumConstantsGeneratorID = \"@tailor-platform/enum-constants\";\n\ntype EnumConstantsPluginOptions = {\n distPath: string;\n};\n\n/**\n * Plugin that generates enum constants from TailorDB type definitions.\n * @param options - Plugin options\n * @param options.distPath - Output file path for generated constants\n * @returns Plugin instance with onTailorDBReady hook\n */\nexport function enumConstantsPlugin(\n options: EnumConstantsPluginOptions,\n): Plugin<unknown, EnumConstantsPluginOptions> {\n return {\n id: EnumConstantsGeneratorID,\n description: \"Generates enum constants from TailorDB type definitions\",\n pluginConfig: options,\n\n async onTailorDBReady(\n ctx: TailorDBReadyContext<EnumConstantsPluginOptions>,\n ): Promise<GeneratorResult> {\n const allEnums: EnumDefinition[] = [];\n\n for (const ns of ctx.tailordb) {\n for (const type of Object.values(ns.types)) {\n const metadata = await processEnumType(type);\n allEnums.push(...metadata.enums);\n }\n }\n\n const files: GeneratorResult[\"files\"] = [];\n if (allEnums.length > 0) {\n const content = generateUnifiedEnumConstants(allEnums);\n files.push({\n path: ctx.pluginConfig.distPath,\n content,\n });\n }\n\n return { files };\n },\n };\n}\n"],"mappings":";;;;;;AAOA,SAAgB,6BAA6B,UAAoC;CAC/E,IAAI,SAAS,WAAW,GACtB,OAAO;CAGT,MAAM,0BAAU,IAAI,IAA4B;CAChD,KAAK,MAAM,WAAW,UACpB,QAAQ,IAAI,QAAQ,MAAM,OAAO;CAGnC,MAAM,WAAW,MAAM,KAAK,QAAQ,OAAO,CAAC,CAAC,CAC1C,KAAK,MAAM;EACV,MAAM,UAAU,EAAE,OACf,KAAK,MAAM;GAEV,OAAO,MADK,EAAE,MAAM,QAAQ,UAAU,GACvB,EAAE,MAAM,EAAE,MAAM;EACjC,CAAC,CAAC,CACD,KAAK,KAAK;EAEb,MAAM,kBAAkB,EAAE,OAAO,MAAM,MAAM,EAAE,WAAW;EAC1D,IAAI,QAAQ;EACZ,IAAI,EAAE,oBAAoB,iBAAiB;GACzC,MAAM,QAAkB,CAAC;GAEzB,IAAI,EAAE,kBAAkB;IACtB,MAAM,KAAK,MAAM,E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eAAe;IACpE,MAAM,eAAe,GAAG,KAAK,OAAO,gBAAgB,aAAa;IACjE,MAAM,KAAK;KACT,MAAM;KACN,QAAQ,kBAAkB;KAC1B,kBAAkB,kBAAkB;IACtC,CAAC;GACH;EACF;CAEJ;CAEA,OAAO;AACT;;;;;;AAOA,eAAsB,gBAAgB,MAAmD;CACvF,MAAM,QAAQ,aAAa,IAAI;CAE/B,OAAO;EACL,MAAM,KAAK;EACX;CACF;AACF;;;;;AC/CA,MAAa,2BAA2B;;;;;;;AAYxC,SAAgB,oBACd,SAC6C;CAC7C,OAAO;EACL,IAAI;EACJ,aAAa;EACb,cAAc;EAEd,MAAM,gBACJ,KAC0B;GAC1B,MAAM,WAA6B,CAAC;GAEpC,KAAK,MAAM,MAAM,IAAI,UACnB,KAAK,MAAM,QAAQ,OAAO,OAAO,GAAG,KAAK,GAAG;IAC1C,MAAM,WAAW,MAAM,gBAAgB,IAAI;IAC3C,SAAS,KAAK,GAAG,SAAS,KAAK;GACjC;GAGF,MAAM,QAAkC,CAAC;GACzC,IAAI,SAAS,SAAS,GAAG;IACvB,MAAM,UAAU,6BAA6B,QAAQ;IACrD,MAAM,KAAK;KACT,MAAM,IAAI,aAAa;KACvB;IACF,CAAC;GACH;GAEA,OAAO,EAAE,MAAM;EACjB;CACF;AACF"}
@@ -1,3 +1,150 @@
1
- import { n as fileUtilsPlugin, t as FileUtilsGeneratorID } from "../../../file-utils-yEiIS4nJ.mjs";
1
+ import { t as multiline } from "../../../multiline-sfHpTZZK.mjs";
2
2
 
3
- export { FileUtilsGeneratorID, fileUtilsPlugin };
3
+ //#region src/plugin/builtin/file-utils/generate-file-utils.ts
4
+ /**
5
+ * Generate unified file utility functions from collected metadata.
6
+ * @param namespaceData - Namespace data with file utility metadata
7
+ * @returns Generated file utility code
8
+ */
9
+ function generateUnifiedFileUtils(namespaceData) {
10
+ if (namespaceData.length === 0) return "";
11
+ const typeNamespaceMap = /* @__PURE__ */ new Map();
12
+ const typeFieldsMap = /* @__PURE__ */ new Map();
13
+ for (const { namespace, types } of namespaceData) for (const type of types) {
14
+ typeNamespaceMap.set(type.name, namespace);
15
+ typeFieldsMap.set(type.name, type.fileFields);
16
+ }
17
+ if (typeNamespaceMap.size === 0) return "";
18
+ const interfaceFields = Array.from(typeFieldsMap.entries()).map(([typeName, fields]) => {
19
+ return ` ${typeName}: {\n fields: ${fields.map((field) => `"${field}"`).join(" | ")};\n };`;
20
+ }).join("\n");
21
+ return [
22
+ multiline`
23
+ import { file } from "@tailor-platform/sdk/runtime/file";
24
+ import type {
25
+ FileUploadOptions,
26
+ FileUploadResponse,
27
+ FileMetadata,
28
+ FileDownloadStreamResponse,
29
+ } from "@tailor-platform/sdk/runtime/file";
30
+ ` + "\n",
31
+ multiline`
32
+ export interface TypeWithFiles {
33
+ ${interfaceFields}
34
+ }
35
+ ` + "\n",
36
+ multiline`
37
+ const namespaces: Record<keyof TypeWithFiles, string> = {
38
+ ${Array.from(typeNamespaceMap.entries()).map(([typeName, namespace]) => ` ${typeName}: "${namespace}"`).join(",\n")},
39
+ };
40
+ ` + "\n",
41
+ multiline`
42
+ export async function downloadFile<T extends keyof TypeWithFiles>(
43
+ type: T,
44
+ field: TypeWithFiles[T]["fields"],
45
+ recordId: string,
46
+ ) {
47
+ return await file.download(namespaces[type], type, field, recordId);
48
+ }
49
+ ` + "\n",
50
+ multiline`
51
+ export async function uploadFile<T extends keyof TypeWithFiles>(
52
+ type: T,
53
+ field: TypeWithFiles[T]["fields"],
54
+ recordId: string,
55
+ data: string | ArrayBuffer | Uint8Array<ArrayBufferLike> | number[],
56
+ options?: FileUploadOptions,
57
+ ): Promise<FileUploadResponse> {
58
+ return await file.upload(namespaces[type], type, field, recordId, data, options);
59
+ }
60
+ ` + "\n",
61
+ multiline`
62
+ export async function deleteFile<T extends keyof TypeWithFiles>(
63
+ type: T,
64
+ field: TypeWithFiles[T]["fields"],
65
+ recordId: string,
66
+ ): Promise<void> {
67
+ return await file.delete(namespaces[type], type, field, recordId);
68
+ }
69
+ ` + "\n",
70
+ multiline`
71
+ export async function getFileMetadata<T extends keyof TypeWithFiles>(
72
+ type: T,
73
+ field: TypeWithFiles[T]["fields"],
74
+ recordId: string,
75
+ ): Promise<FileMetadata> {
76
+ return await file.getMetadata(namespaces[type], type, field, recordId);
77
+ }
78
+ ` + "\n",
79
+ multiline`
80
+ export async function downloadFileStream<T extends keyof TypeWithFiles>(
81
+ type: T,
82
+ field: TypeWithFiles[T]["fields"],
83
+ recordId: string,
84
+ ): Promise<FileDownloadStreamResponse> {
85
+ return await file.downloadStream(namespaces[type], type, field, recordId);
86
+ }
87
+ ` + "\n"
88
+ ].join("\n");
89
+ }
90
+
91
+ //#endregion
92
+ //#region src/plugin/builtin/file-utils/process-file-type.ts
93
+ /**
94
+ * Process a TailorDB type and extract file field metadata.
95
+ * @param type - The parsed TailorDB type to process
96
+ * @returns File utility metadata for the type
97
+ */
98
+ async function processFileType(type) {
99
+ const fileFields = [];
100
+ if (type.files) for (const fileFieldName of Object.keys(type.files)) fileFields.push(fileFieldName);
101
+ return {
102
+ name: type.name,
103
+ fileFields
104
+ };
105
+ }
106
+
107
+ //#endregion
108
+ //#region src/plugin/builtin/file-utils/index.ts
109
+ /** Unique identifier for the file utilities generator plugin. */
110
+ const FileUtilsGeneratorID = "@tailor-platform/file-utils";
111
+ /**
112
+ * Plugin that generates TypeWithFiles interface from TailorDB type definitions.
113
+ * @param options - Plugin options
114
+ * @param options.distPath - Output file path for generated file utilities
115
+ * @returns Plugin instance with onTailorDBReady hook
116
+ */
117
+ function fileUtilsPlugin(options) {
118
+ return {
119
+ id: FileUtilsGeneratorID,
120
+ description: "Generates TypeWithFiles interface from TailorDB type definitions",
121
+ pluginConfig: options,
122
+ async onTailorDBReady(ctx) {
123
+ const namespaceData = [];
124
+ for (const ns of ctx.tailordb) {
125
+ const typesWithFiles = [];
126
+ for (const type of Object.values(ns.types)) {
127
+ const metadata = await processFileType(type);
128
+ if (metadata.fileFields.length > 0) typesWithFiles.push(metadata);
129
+ }
130
+ if (typesWithFiles.length > 0) namespaceData.push({
131
+ namespace: ns.namespace,
132
+ types: typesWithFiles
133
+ });
134
+ }
135
+ const files = [];
136
+ if (namespaceData.length > 0) {
137
+ const content = generateUnifiedFileUtils(namespaceData);
138
+ if (content) files.push({
139
+ path: ctx.pluginConfig.distPath,
140
+ content
141
+ });
142
+ }
143
+ return { files };
144
+ }
145
+ };
146
+ }
147
+
148
+ //#endregion
149
+ export { FileUtilsGeneratorID, fileUtilsPlugin };
150
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/plugin/builtin/file-utils/generate-file-utils.ts","../../../../src/plugin/builtin/file-utils/process-file-type.ts","../../../../src/plugin/builtin/file-utils/index.ts"],"sourcesContent":["import multiline from \"#/utils/multiline\";\nimport type { FileUtilMetadata } from \"./types\";\n\n/**\n * Generate unified file utility functions from collected metadata.\n * @param namespaceData - Namespace data with file utility metadata\n * @returns Generated file utility code\n */\nexport function generateUnifiedFileUtils(\n namespaceData: { namespace: string; types: FileUtilMetadata[] }[],\n): string {\n if (namespaceData.length === 0) {\n return \"\";\n }\n\n // Collect all types with their namespace\n const typeNamespaceMap = new Map<string, string>();\n const typeFieldsMap = new Map<string, string[]>();\n\n for (const { namespace, types } of namespaceData) {\n for (const type of types) {\n typeNamespaceMap.set(type.name, namespace);\n typeFieldsMap.set(type.name, type.fileFields);\n }\n }\n\n if (typeNamespaceMap.size === 0) {\n return \"\";\n }\n\n // Generate interface fields\n const interfaceFields = Array.from(typeFieldsMap.entries())\n .map(([typeName, fields]) => {\n const fieldNamesUnion = fields.map((field) => `\"${field}\"`).join(\" | \");\n return ` ${typeName}: {\\n fields: ${fieldNamesUnion};\\n };`;\n })\n .join(\"\\n\");\n\n const importStatement =\n multiline /* ts */ `\n import { file } from \"@tailor-platform/sdk/runtime/file\";\n import type {\n FileUploadOptions,\n FileUploadResponse,\n FileMetadata,\n FileDownloadStreamResponse,\n } from \"@tailor-platform/sdk/runtime/file\";\n ` + \"\\n\";\n\n const interfaceDefinition =\n multiline /* ts */ `\n export interface TypeWithFiles {\n ${interfaceFields}\n }\n ` + \"\\n\";\n\n // Generate namespaces object\n const namespaceEntries = Array.from(typeNamespaceMap.entries())\n .map(([typeName, namespace]) => ` ${typeName}: \"${namespace}\"`)\n .join(\",\\n\");\n\n const namespacesDefinition =\n multiline /* ts */ `\n const namespaces: Record<keyof TypeWithFiles, string> = {\n ${namespaceEntries},\n };\n ` + \"\\n\";\n\n // Generate downloadFile helper function\n const downloadFunction =\n multiline /* ts */ `\n export async function downloadFile<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n ) {\n return await file.download(namespaces[type], type, field, recordId);\n }\n ` + \"\\n\";\n\n // Generate uploadFile helper function\n const uploadFunction =\n multiline /* ts */ `\n export async function uploadFile<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n data: string | ArrayBuffer | Uint8Array<ArrayBufferLike> | number[],\n options?: FileUploadOptions,\n ): Promise<FileUploadResponse> {\n return await file.upload(namespaces[type], type, field, recordId, data, options);\n }\n ` + \"\\n\";\n\n // Generate deleteFile helper function\n const deleteFunction =\n multiline /* ts */ `\n export async function deleteFile<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n ): Promise<void> {\n return await file.delete(namespaces[type], type, field, recordId);\n }\n ` + \"\\n\";\n\n // Generate getFileMetadata helper function\n const getMetadataFunction =\n multiline /* ts */ `\n export async function getFileMetadata<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n ): Promise<FileMetadata> {\n return await file.getMetadata(namespaces[type], type, field, recordId);\n }\n ` + \"\\n\";\n\n // Generate downloadFileStream helper function\n const downloadStreamFunction =\n multiline /* ts */ `\n export async function downloadFileStream<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n ): Promise<FileDownloadStreamResponse> {\n return await file.downloadStream(namespaces[type], type, field, recordId);\n }\n ` + \"\\n\";\n\n return [\n importStatement,\n interfaceDefinition,\n namespacesDefinition,\n downloadFunction,\n uploadFunction,\n deleteFunction,\n getMetadataFunction,\n downloadStreamFunction,\n ].join(\"\\n\");\n}\n","import type { TailorDBType } from \"#/parser/service/tailordb/types\";\nimport type { FileUtilMetadata } from \"./types\";\n\n/**\n * Process a TailorDB type and extract file field metadata.\n * @param type - The parsed TailorDB type to process\n * @returns File utility metadata for the type\n */\nexport async function processFileType(type: TailorDBType): Promise<FileUtilMetadata> {\n const fileFields: string[] = [];\n\n if (type.files) {\n for (const fileFieldName of Object.keys(type.files)) {\n fileFields.push(fileFieldName);\n }\n }\n\n return {\n name: type.name,\n fileFields,\n };\n}\n","import { generateUnifiedFileUtils } from \"./generate-file-utils\";\nimport { processFileType } from \"./process-file-type\";\nimport type { Plugin, GeneratorResult, TailorDBReadyContext } from \"#/plugin/types\";\nimport type { FileUtilMetadata } from \"./types\";\n\n/** Unique identifier for the file utilities generator plugin. */\nexport const FileUtilsGeneratorID = \"@tailor-platform/file-utils\";\n\ntype FileUtilsPluginOptions = {\n distPath: string;\n};\n\n/**\n * Plugin that generates TypeWithFiles interface from TailorDB type definitions.\n * @param options - Plugin options\n * @param options.distPath - Output file path for generated file utilities\n * @returns Plugin instance with onTailorDBReady hook\n */\nexport function fileUtilsPlugin(\n options: FileUtilsPluginOptions,\n): Plugin<unknown, FileUtilsPluginOptions> {\n return {\n id: FileUtilsGeneratorID,\n description: \"Generates TypeWithFiles interface from TailorDB type definitions\",\n pluginConfig: options,\n\n async onTailorDBReady(\n ctx: TailorDBReadyContext<FileUtilsPluginOptions>,\n ): Promise<GeneratorResult> {\n const namespaceData: { namespace: string; types: FileUtilMetadata[] }[] = [];\n\n for (const ns of ctx.tailordb) {\n const typesWithFiles: FileUtilMetadata[] = [];\n\n for (const type of Object.values(ns.types)) {\n const metadata = await processFileType(type);\n if (metadata.fileFields.length > 0) {\n typesWithFiles.push(metadata);\n }\n }\n\n if (typesWithFiles.length > 0) {\n namespaceData.push({\n namespace: ns.namespace,\n types: typesWithFiles,\n });\n }\n }\n\n const files: GeneratorResult[\"files\"] = [];\n if (namespaceData.length > 0) {\n const content = generateUnifiedFileUtils(namespaceData);\n if (content) {\n files.push({\n path: ctx.pluginConfig.distPath,\n content,\n });\n }\n }\n\n return { files };\n },\n };\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,yBACd,eACQ;CACR,IAAI,cAAc,WAAW,GAC3B,OAAO;CAIT,MAAM,mCAAmB,IAAI,IAAoB;CACjD,MAAM,gCAAgB,IAAI,IAAsB;CAEhD,KAAK,MAAM,EAAE,WAAW,WAAW,eACjC,KAAK,MAAM,QAAQ,OAAO;EACxB,iBAAiB,IAAI,KAAK,MAAM,SAAS;EACzC,cAAc,IAAI,KAAK,MAAM,KAAK,UAAU;CAC9C;CAGF,IAAI,iBAAiB,SAAS,GAC5B,OAAO;CAIT,MAAM,kBAAkB,MAAM,KAAK,cAAc,QAAQ,CAAC,CAAC,CACxD,KAAK,CAAC,UAAU,YAAY;EAE3B,OAAO,KAAK,SAAS,mBADG,OAAO,KAAK,UAAU,IAAI,MAAM,EAAE,CAAC,CAAC,KAAK,KACX,EAAE;CAC1D,CAAC,CAAC,CACD,KAAK,IAAI;CA8FZ,OAAO;EA3FL,SAAmB;;;;;;;;QAQf;EAGJ,SAAmB;;QAEf,gBAAgB;;QAEhB;EAQJ,SAAmB;;QALI,MAAM,KAAK,iBAAiB,QAAQ,CAAC,CAAC,CAC5D,KAAK,CAAC,UAAU,eAAe,KAAK,SAAS,KAAK,UAAU,EAAE,CAAC,CAC/D,KAAK,KAKa,EAAE;;QAEjB;EAIJ,SAAmB;;;;;;;;QAQf;EAIJ,SAAmB;;;;;;;;;;QAUf;EAIJ,SAAmB;;;;;;;;QAQf;EAIJ,SAAmB;;;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