@tailor-platform/sdk 2.14.0 → 2.14.1

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 (239) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/application-BWOMdL3D.mjs +1 -0
  3. package/dist/{application-CiN_er9X.mjs → application-CfevPO-k.mjs} +8 -8
  4. package/dist/application-CfevPO-k.mjs.map +1 -0
  5. package/dist/cli/commands/api/api-call.d.mts +4 -5
  6. package/dist/cli/commands/deploy/config-id-injector.d.mts +3 -4
  7. package/dist/cli/commands/deploy/deploy.d.mts +3 -4
  8. package/dist/cli/commands/deploy/function-registry-types.d.mts +2 -3
  9. package/dist/cli/commands/executor/get.d.mts +3 -4
  10. package/dist/cli/commands/executor/jobs.d.mts +10 -11
  11. package/dist/cli/commands/executor/list.d.mts +3 -4
  12. package/dist/cli/commands/executor/transform.d.mts +6 -7
  13. package/dist/cli/commands/executor/trigger.d.mts +4 -5
  14. package/dist/cli/commands/executor/webhook.d.mts +4 -5
  15. package/dist/cli/commands/function/get.d.mts +3 -4
  16. package/dist/cli/commands/function/list.d.mts +3 -4
  17. package/dist/cli/commands/function/transform.d.mts +2 -3
  18. package/dist/cli/commands/generate/options.d.mts +2 -3
  19. package/dist/cli/commands/generate/seed/bundler.d.mts +3 -4
  20. package/dist/cli/commands/generate/service.d.mts +2 -3
  21. package/dist/cli/commands/machineuser/list.d.mts +4 -5
  22. package/dist/cli/commands/machineuser/token.d.mts +4 -5
  23. package/dist/cli/commands/oauth2client/get.d.mts +3 -4
  24. package/dist/cli/commands/oauth2client/list.d.mts +3 -4
  25. package/dist/cli/commands/oauth2client/transform.d.mts +3 -4
  26. package/dist/cli/commands/organization/folder/create.d.mts +3 -4
  27. package/dist/cli/commands/organization/folder/delete.d.mts +3 -4
  28. package/dist/cli/commands/organization/folder/get.d.mts +3 -4
  29. package/dist/cli/commands/organization/folder/list.d.mts +3 -4
  30. package/dist/cli/commands/organization/folder/update.d.mts +3 -4
  31. package/dist/cli/commands/organization/get.d.mts +3 -4
  32. package/dist/cli/commands/organization/list.d.mts +3 -4
  33. package/dist/cli/commands/organization/transform.d.mts +5 -6
  34. package/dist/cli/commands/organization/tree.d.mts +3 -4
  35. package/dist/cli/commands/organization/update.d.mts +3 -4
  36. package/dist/cli/commands/remove.d.mts +3 -4
  37. package/dist/cli/commands/show.d.mts +6 -7
  38. package/dist/cli/commands/staticwebsite/deploy.d.mts +3 -4
  39. package/dist/cli/commands/tailordb/migrate/bundler.d.mts +3 -4
  40. package/dist/cli/commands/tailordb/migrate/config.d.mts +3 -4
  41. package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +34 -35
  42. package/dist/cli/commands/tailordb/migrate/generate.d.mts +3 -4
  43. package/dist/cli/commands/tailordb/migrate/rename-detection.d.mts +3 -4
  44. package/dist/cli/commands/tailordb/migrate/snapshot-comparison.d.mts +4 -5
  45. package/dist/cli/commands/tailordb/migrate/snapshot-files.d.mts +13 -14
  46. package/dist/cli/commands/tailordb/migrate/snapshot-local.d.mts +2 -3
  47. package/dist/cli/commands/tailordb/migrate/snapshot-migrations.d.mts +2 -3
  48. package/dist/cli/commands/tailordb/migrate/snapshot-types.d.mts +21 -22
  49. package/dist/cli/commands/tailordb/migrate/types.d.mts +2 -3
  50. package/dist/cli/commands/tailordb/truncate.d.mts +3 -4
  51. package/dist/cli/commands/workflow/executions.d.mts +8 -9
  52. package/dist/cli/commands/workflow/get.d.mts +3 -4
  53. package/dist/cli/commands/workflow/list.d.mts +3 -4
  54. package/dist/cli/commands/workflow/resume.d.mts +4 -5
  55. package/dist/cli/commands/workflow/start.d.mts +5 -6
  56. package/dist/cli/commands/workflow/status.d.mts +3 -4
  57. package/dist/cli/commands/workflow/transform.d.mts +5 -6
  58. package/dist/cli/commands/workflow/wait.d.mts +3 -4
  59. package/dist/cli/commands/workflow/waiter.d.mts +3 -4
  60. package/dist/cli/commands/workspace/app/health.d.mts +3 -4
  61. package/dist/cli/commands/workspace/app/list.d.mts +3 -4
  62. package/dist/cli/commands/workspace/app/transform.d.mts +3 -4
  63. package/dist/cli/commands/workspace/create.d.mts +3 -4
  64. package/dist/cli/commands/workspace/delete.d.mts +3 -4
  65. package/dist/cli/commands/workspace/get.d.mts +3 -4
  66. package/dist/cli/commands/workspace/list.d.mts +3 -4
  67. package/dist/cli/commands/workspace/restore.d.mts +3 -4
  68. package/dist/cli/commands/workspace/transform.d.mts +3 -4
  69. package/dist/cli/commands/workspace/user/invite.d.mts +3 -4
  70. package/dist/cli/commands/workspace/user/list.d.mts +3 -4
  71. package/dist/cli/commands/workspace/user/remove.d.mts +3 -4
  72. package/dist/cli/commands/workspace/user/transform.d.mts +2 -3
  73. package/dist/cli/commands/workspace/user/update.d.mts +3 -4
  74. package/dist/cli/lib.mjs +1 -1
  75. package/dist/cli/main.d.mts +2 -3
  76. package/dist/cli/main.mjs +18 -18
  77. package/dist/cli/main.mjs.map +1 -1
  78. package/dist/cli/query/index.d.mts +2 -3
  79. package/dist/cli/shared/args.d.mts +11 -12
  80. package/dist/cli/shared/beta.d.mts +2 -3
  81. package/dist/cli/shared/client.d.mts +4 -5
  82. package/dist/cli/shared/command.d.mts +2 -3
  83. package/dist/cli/shared/config-loader.d.mts +5 -6
  84. package/dist/cli/shared/config.d.mts +2 -3
  85. package/dist/cli/shared/context.d.mts +3 -4
  86. package/dist/cli/shared/error-json.d.mts +4 -5
  87. package/dist/cli/shared/logger.d.mts +7 -8
  88. package/dist/cli/shared/prompt.d.mts +7 -8
  89. package/dist/cli/shared/readonly-guard.d.mts +2 -3
  90. package/dist/cli/shared/script-executor.d.mts +7 -8
  91. package/dist/cli/shared/seed-chunker.d.mts +5 -6
  92. package/dist/cli/shared/seed-context.d.mts +5 -5
  93. package/dist/cli/shared/tailordb-namespaces.d.mts +5 -6
  94. package/dist/cli/shared/type-generator.d.mts +2 -3
  95. package/dist/cli/shared/workspace-name.d.mts +2 -3
  96. package/dist/completion/zsh-worker.zsh +1 -1
  97. package/dist/configure/config/index.d.mts +3 -4
  98. package/dist/configure/config/types.d.mts +14 -15
  99. package/dist/configure/index.d.mts +6 -6
  100. package/dist/configure/services/aigateway/index.d.mts +2 -2
  101. package/dist/configure/services/aigateway/types.d.mts +4 -5
  102. package/dist/configure/services/auth/index.d.mts +3 -3
  103. package/dist/configure/services/auth/types.d.mts +24 -25
  104. package/dist/configure/services/executor/executor.d.mts +3 -4
  105. package/dist/configure/services/executor/operation.d.mts +6 -7
  106. package/dist/configure/services/executor/trigger/event.d.mts +56 -57
  107. package/dist/configure/services/executor/trigger/index.d.mts +2 -2
  108. package/dist/configure/services/executor/trigger/schedule.d.mts +4 -5
  109. package/dist/configure/services/executor/trigger/webhook.d.mts +8 -9
  110. package/dist/configure/services/http-adapter/http-adapter.d.mts +12 -13
  111. package/dist/configure/services/idp/index.d.mts +2 -2
  112. package/dist/configure/services/idp/permission.d.mts +4 -5
  113. package/dist/configure/services/idp/types.d.mts +5 -6
  114. package/dist/configure/services/resolver/permission.d.mts +4 -5
  115. package/dist/configure/services/resolver/resolver.d.mts +3 -4
  116. package/dist/configure/services/resolver/types.d.mts +2 -3
  117. package/dist/configure/services/secrets/index.d.mts +3 -3
  118. package/dist/configure/services/secrets/types.d.mts +3 -4
  119. package/dist/configure/services/staticwebsite/index.d.mts +2 -2
  120. package/dist/configure/services/staticwebsite/types.d.mts +3 -4
  121. package/dist/configure/services/tailordb/permission.d.mts +6 -7
  122. package/dist/configure/services/tailordb/schema.d.mts +7 -8
  123. package/dist/configure/services/tailordb/types.d.mts +25 -26
  124. package/dist/configure/services/workflow/execution-policy.d.mts +3 -3
  125. package/dist/configure/services/workflow/execution-policy.types.d.mts +8 -9
  126. package/dist/configure/services/workflow/job.d.mts +4 -5
  127. package/dist/configure/services/workflow/wait-point.d.mts +5 -6
  128. package/dist/configure/services/workflow/workflow.d.mts +4 -4
  129. package/dist/configure/types/aigateway-name.d.mts +3 -4
  130. package/dist/configure/types/auth-namespace-name.d.mts +3 -4
  131. package/dist/configure/types/connection-name.d.mts +3 -4
  132. package/dist/configure/types/field.d.mts +3 -4
  133. package/dist/configure/types/field.types.d.mts +13 -14
  134. package/dist/configure/types/idp-name.d.mts +3 -4
  135. package/dist/configure/types/permission-operand.types.d.mts +7 -8
  136. package/dist/configure/types/type.d.mts +3 -4
  137. package/dist/kysely/index.d.mts +18 -18
  138. package/dist/parser/service/idp/types.d.mts +2 -3
  139. package/dist/parser/service/tailordb/type-source.d.mts +2 -3
  140. package/dist/parser/service/tailordb/types.d.mts +13 -14
  141. package/dist/plugin/builtin/enum-constants/index.d.mts +3 -4
  142. package/dist/plugin/builtin/file-utils/index.d.mts +3 -4
  143. package/dist/plugin/builtin/kysely-type/index.d.mts +4 -5
  144. package/dist/plugin/builtin/seed/index.d.mts +4 -5
  145. package/dist/plugin/builtin/seed/seed-type-processor.d.mts +2 -3
  146. package/dist/plugin/get-generated-table.d.mts +2 -3
  147. package/dist/plugin/index.mjs +1 -1
  148. package/dist/plugin/index.mjs.map +1 -1
  149. package/dist/plugin/types.d.mts +29 -29
  150. package/dist/plugin/with-context.d.mts +9 -10
  151. package/dist/{register-ts-hook-DS1zYiCV.mjs → register-ts-hook-DZ1Kpt4s.mjs} +44 -44
  152. package/dist/register-ts-hook-DZ1Kpt4s.mjs.map +1 -0
  153. package/dist/runtime/aigateway.d.mts +4 -5
  154. package/dist/runtime/authconnection.d.mts +3 -4
  155. package/dist/runtime/context.d.mts +6 -7
  156. package/dist/runtime/date.d.mts +2 -3
  157. package/dist/runtime/field-parse.d.mts +2 -3
  158. package/dist/runtime/file.d.mts +14 -15
  159. package/dist/runtime/globals.d.mts +2 -1
  160. package/dist/runtime/iconv.d.mts +5 -6
  161. package/dist/runtime/idp.d.mts +14 -15
  162. package/dist/runtime/index.d.mts +7 -7
  163. package/dist/runtime/logger.d.mts +10 -11
  164. package/dist/runtime/secretmanager.d.mts +3 -4
  165. package/dist/runtime/types.d.mts +7 -8
  166. package/dist/runtime/workflow.d.mts +7 -8
  167. package/dist/seed/index.d.mts +3 -3
  168. package/dist/shared/src/color.d.mts +2 -3
  169. package/dist/tailor-proto/src/tailor/v1/aigateway_pb.d.mts +21 -22
  170. package/dist/tailor-proto/src/tailor/v1/aigateway_resource_pb.d.mts +2 -3
  171. package/dist/tailor-proto/src/tailor/v1/application_pb.d.mts +35 -36
  172. package/dist/tailor-proto/src/tailor/v1/application_resource_pb.d.mts +6 -7
  173. package/dist/tailor-proto/src/tailor/v1/auth_pb.d.mts +229 -230
  174. package/dist/tailor-proto/src/tailor/v1/auth_resource_pb.d.mts +40 -41
  175. package/dist/tailor-proto/src/tailor/v1/events_pb.d.mts +9 -10
  176. package/dist/tailor-proto/src/tailor/v1/events_resource_pb.d.mts +3 -4
  177. package/dist/tailor-proto/src/tailor/v1/executor_pb.d.mts +45 -46
  178. package/dist/tailor-proto/src/tailor/v1/executor_resource_pb.d.mts +24 -25
  179. package/dist/tailor-proto/src/tailor/v1/function_pb.d.mts +17 -18
  180. package/dist/tailor-proto/src/tailor/v1/function_registry_pb.d.mts +29 -30
  181. package/dist/tailor-proto/src/tailor/v1/function_resource_pb.d.mts +8 -9
  182. package/dist/tailor-proto/src/tailor/v1/http_adapter_resource_pb.d.mts +2 -3
  183. package/dist/tailor-proto/src/tailor/v1/idp_pb.d.mts +37 -38
  184. package/dist/tailor-proto/src/tailor/v1/idp_resource_pb.d.mts +13 -14
  185. package/dist/tailor-proto/src/tailor/v1/metadata_pb.d.mts +19 -20
  186. package/dist/tailor-proto/src/tailor/v1/metadata_resource_pb.d.mts +2 -3
  187. package/dist/tailor-proto/src/tailor/v1/meter_pb.d.mts +25 -26
  188. package/dist/tailor-proto/src/tailor/v1/pipeline_pb.d.mts +59 -60
  189. package/dist/tailor-proto/src/tailor/v1/pipeline_resource_pb.d.mts +10 -11
  190. package/dist/tailor-proto/src/tailor/v1/resource_pb.d.mts +7 -8
  191. package/dist/tailor-proto/src/tailor/v1/secret_manager_pb.d.mts +37 -38
  192. package/dist/tailor-proto/src/tailor/v1/secret_manager_resource_pb.d.mts +4 -5
  193. package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +6 -7
  194. package/dist/tailor-proto/src/tailor/v1/stateflow_pb.d.mts +21 -22
  195. package/dist/tailor-proto/src/tailor/v1/stateflow_resource_pb.d.mts +3 -4
  196. package/dist/tailor-proto/src/tailor/v1/staticwebsite_pb.d.mts +50 -51
  197. package/dist/tailor-proto/src/tailor/v1/staticwebsite_resource_pb.d.mts +4 -5
  198. package/dist/tailor-proto/src/tailor/v1/tailordb_pb.d.mts +74 -75
  199. package/dist/tailor-proto/src/tailor/v1/tailordb_resource_pb.d.mts +35 -36
  200. package/dist/tailor-proto/src/tailor/v1/telemetryrouter_pb.d.mts +41 -42
  201. package/dist/tailor-proto/src/tailor/v1/telemetryrouter_resource_pb.d.mts +11 -12
  202. package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +97 -98
  203. package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +11 -12
  204. package/dist/tailor-proto/src/tailor/v1/workspace_pb.d.mts +209 -210
  205. package/dist/tailor-proto/src/tailor/v1/workspace_resource_pb.d.mts +24 -25
  206. package/dist/types/aigateway.generated.d.mts +3 -4
  207. package/dist/types/app-config.generated.d.mts +2 -3
  208. package/dist/types/auth-connection.generated.d.mts +3 -4
  209. package/dist/types/auth.generated.d.mts +15 -16
  210. package/dist/types/executor.generated.d.mts +26 -27
  211. package/dist/types/helpers.d.mts +15 -13
  212. package/dist/types/http-adapter.generated.d.mts +2 -3
  213. package/dist/types/idp.generated.d.mts +7 -8
  214. package/dist/types/resolver.generated.d.mts +4 -5
  215. package/dist/types/secrets.generated.d.mts +3 -4
  216. package/dist/types/staticwebsite.generated.d.mts +3 -4
  217. package/dist/types/tailordb.generated.d.mts +7 -8
  218. package/dist/types/workflow.generated.d.mts +3 -4
  219. package/dist/utils/test/index.d.mts +3 -4
  220. package/dist/vitest/index.d.mts +2 -2
  221. package/dist/vitest/mock-kysely.d.mts +4 -5
  222. package/dist/vitest/mocks/aigateway.d.mts +3 -4
  223. package/dist/vitest/mocks/authconnection.d.mts +3 -4
  224. package/dist/vitest/mocks/file.d.mts +3 -4
  225. package/dist/vitest/mocks/iconv.d.mts +3 -4
  226. package/dist/vitest/mocks/idp.d.mts +3 -4
  227. package/dist/vitest/mocks/logger.d.mts +3 -4
  228. package/dist/vitest/mocks/secretmanager.d.mts +3 -4
  229. package/dist/vitest/mocks/tailordb-pglite.d.mts +4 -5
  230. package/dist/vitest/mocks/tailordb.d.mts +6 -7
  231. package/dist/vitest/mocks/workflow.d.mts +2 -3
  232. package/dist/vitest/pglite-kysely.d.mts +5 -6
  233. package/dist/vitest/setup.d.mts +6 -7
  234. package/dist/vitest/workflow-local.d.mts +5 -6
  235. package/docs/services/idp.md +6 -3
  236. package/package.json +12 -12
  237. package/dist/application-CiN_er9X.mjs.map +0 -1
  238. package/dist/application-_8rjQRx8.mjs +0 -1
  239. package/dist/register-ts-hook-DS1zYiCV.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/with-context.ts","../../src/plugin/get-generated-table.ts"],"sourcesContent":["/**\n * Plugin executor context support for defining plugin executors in separate files.\n * This module provides utilities for creating type-safe plugin executors that receive\n * context (like table references and namespace) at runtime.\n */\n\nimport type { TailorEnv, TailorPrincipal } from \"#/runtime/types\";\n\n/**\n * Plugin executor factory function type.\n * Takes context and returns an executor configuration.\n * Returns unknown since the exact return type depends on createExecutor's generic params.\n */\nexport type PluginExecutorFactory<Ctx> = (ctx: Ctx) => unknown;\n\n// ============================================================================\n// Plugin Executor Args Types\n// ============================================================================\n\n/**\n * Base args for plugin executor function operations.\n * Provides typed access to runtime context without requiring specific record types.\n */\nexport interface PluginFunctionArgs {\n /** Workspace ID where the executor runs */\n workspaceId: string;\n /** Application namespace */\n appNamespace: string;\n /** Environment variables */\n env: TailorEnv;\n /** Principal that triggered the event, null for system events */\n actor: TailorPrincipal | null;\n /** Name of the TailorDB table */\n typeName: string;\n /** TailorDB connections by namespace */\n tailordb: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record creation.\n */\nexport interface PluginRecordCreatedArgs extends PluginFunctionArgs {\n /** The newly created record */\n newRecord: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record update.\n */\nexport interface PluginRecordUpdatedArgs extends PluginFunctionArgs {\n /** The record after update */\n newRecord: Record<string, unknown>;\n /** The record before update */\n oldRecord: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record deletion.\n */\nexport interface PluginRecordDeletedArgs extends PluginFunctionArgs {\n /** The deleted record */\n oldRecord: Record<string, unknown>;\n}\n\n/**\n * Database schema type for plugins.\n * Since plugins work with dynamic types, the schema uses Record types.\n */\nexport type PluginDBSchema = Record<string, Record<string, unknown>>;\n\n/**\n * Base record type for TailorDB records.\n * All records have an id field.\n */\nexport type PluginRecord = { id: string } & Record<string, unknown>;\n\n/**\n * Define a plugin executor that receives context at runtime.\n * This allows executor definitions to be in separate files while\n * still receiving dynamic values like typeName, generated types, and namespace.\n * @param factory - Function that takes context and returns executor configuration\n * @returns The same factory function (for type inference)\n * @example\n * ```typescript\n * // executors/on-create.ts\n * import { withPluginContext } from \"@tailor-platform/sdk/plugin\";\n * import { createExecutor, recordCreatedTrigger } from \"@tailor-platform/sdk\";\n * import { getDB } from \"@tailor-platform/function-kysely-tailordb\";\n *\n * interface MyContext {\n * sourceTable: TailorAnyDBType;\n * historyType: TailorAnyDBType;\n * namespace: string;\n * }\n *\n * export default withPluginContext<MyContext>((ctx) =>\n * createExecutor({\n * name: `${ctx.sourceTable.name.toLowerCase()}-on-create`,\n * trigger: recordCreatedTrigger({ type: ctx.sourceTable }),\n * operation: {\n * kind: \"function\",\n * body: async (args) => {\n * const db = getDB(ctx.namespace);\n * await db.insertInto(ctx.historyType.name).values({\n * recordId: args.newRecord.id,\n * // ...\n * }).execute();\n * },\n * },\n * })\n * );\n * ```\n */\nexport function withPluginContext<Ctx>(\n factory: PluginExecutorFactory<Ctx>,\n): PluginExecutorFactory<Ctx> {\n return factory;\n}\n","import * as fs from \"node:fs\";\nimport { pathToFileURL } from \"node:url\";\nimport * as path from \"pathe\";\nimport type { TailorAnyDBType } from \"#/configure/services/tailordb/types\";\nimport type { Plugin, PluginOutput, TablePluginOutput } from \"#/plugin/types\";\n\n// ========================================\n// Config loading and caching\n// ========================================\n\ninterface PluginEntry {\n plugin: Plugin;\n pluginConfig: unknown;\n}\n\ninterface ConfigCache {\n config: { db?: Record<string, unknown> };\n plugins: Map<string, PluginEntry>;\n configDir: string;\n}\n\n/** Cache: resolved config path -> loaded config data */\nconst configCacheMap = new Map<string, ConfigCache>();\n\n/**\n * Check if a value is a Plugin instance.\n * @param value - Value to check\n * @returns True if value has the shape of Plugin\n */\nfunction isPlugin(value: unknown): value is Plugin {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as Record<string, unknown>).id === \"string\" &&\n typeof (value as Record<string, unknown>).description === \"string\"\n );\n}\n\n/**\n * Load and cache config module from the given path.\n * Extracts plugins from all array exports using definePlugins() format.\n * Returns null if the config file does not exist (e.g., in bundled executor on platform server).\n * @param configPath - Absolute or relative path to tailor.config.ts\n * @returns Cached config data with plugins map, or null if config file is not available\n */\nasync function loadAndCacheConfig(configPath: string): Promise<ConfigCache | null> {\n const resolvedPath = path.resolve(configPath);\n\n const cached = configCacheMap.get(resolvedPath);\n if (cached) return cached;\n\n // Config file may not exist in bundled environments (e.g., platform server)\n if (!fs.existsSync(resolvedPath)) {\n return null;\n }\n\n const configModule = await import(pathToFileURL(resolvedPath).href);\n if (!configModule?.default) {\n throw new Error(`Invalid config module at \"${resolvedPath}\": default export not found`);\n }\n\n const config = configModule.default as { db?: Record<string, unknown> };\n const configDir = path.dirname(resolvedPath);\n const plugins = new Map<string, PluginEntry>();\n\n // Find plugin arrays from exports (definePlugins returns PluginConfig[])\n for (const value of Object.values(configModule)) {\n if (!Array.isArray(value)) continue;\n\n for (const item of value) {\n if (isPlugin(item)) {\n plugins.set(item.id, { plugin: item, pluginConfig: item.pluginConfig });\n }\n }\n }\n\n const result: ConfigCache = { config, plugins, configDir };\n configCacheMap.set(resolvedPath, result);\n return result;\n}\n\n// ========================================\n// Namespace resolution\n// ========================================\n\ninterface DbNamespaceConfig {\n files?: string[];\n external?: boolean;\n}\n\n/**\n * Resolve the namespace for a table-attached source table by checking config.db file patterns.\n * Uses ESM module cache identity: same file path yields same object references.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param configDir - Directory containing the config file\n * @param sourceTable - The TailorDB table to look up\n * @returns The namespace name\n */\nasync function resolveNamespaceForTable(\n config: { db?: Record<string, unknown> },\n configDir: string,\n sourceTable: TailorAnyDBType,\n): Promise<string> {\n if (!config.db) {\n throw new Error(`No db configuration found in config`);\n }\n\n for (const [namespace, nsConfig] of Object.entries(config.db)) {\n const dbConfig = nsConfig as DbNamespaceConfig;\n // Skip external namespaces (no files to resolve)\n if (dbConfig.external || !dbConfig.files) continue;\n\n for (const pattern of dbConfig.files) {\n const absolutePattern = path.resolve(configDir, pattern);\n let matchedFiles: string[];\n try {\n matchedFiles = fs.globSync(absolutePattern);\n } catch {\n continue;\n }\n\n for (const file of matchedFiles) {\n const mod = await import(pathToFileURL(file).href);\n for (const exported of Object.values(mod)) {\n if (exported === sourceTable) {\n return namespace;\n }\n }\n }\n }\n }\n\n throw new Error(\n `Could not resolve namespace for table \"${sourceTable.name}\". ` +\n `Ensure the table file is included in a db namespace's files pattern.`,\n );\n}\n\n/**\n * Resolve the namespace for a namespace plugin by trying each namespace.\n * Calls onNamespaceLoaded() for each and returns the first whose output contains the requested kind.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param plugin - Plugin instance\n * @param kind - The generated table kind to look for\n * @param pluginConfig - Plugin-level configuration\n * @returns The namespace name\n */\nasync function resolveNamespaceForNamespacePlugin(\n config: { db?: Record<string, unknown> },\n plugin: Plugin,\n kind: string,\n pluginConfig: unknown,\n): Promise<{ namespace: string; output: PluginOutput }> {\n if (!config.db) {\n throw new Error(`No db configuration found in config`);\n }\n\n if (!plugin.onNamespaceLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onNamespaceLoaded() method`);\n }\n\n for (const namespace of Object.keys(config.db)) {\n const dbConfig = config.db[namespace] as DbNamespaceConfig;\n if (dbConfig.external) continue;\n\n const output = await plugin.onNamespaceLoaded({\n pluginConfig,\n namespace,\n });\n\n if (output.tables?.[kind]) {\n return { namespace, output };\n }\n }\n\n throw new Error(\n `Could not resolve namespace for plugin \"${plugin.id}\" with kind \"${kind}\". ` +\n `No namespace produced a table with that kind.`,\n );\n}\n\n// ========================================\n// Process caching\n// ========================================\n\n// Cache: plugin -> cacheKey -> TablePluginOutput\nconst processCache = new WeakMap<Plugin, Map<string, TablePluginOutput>>();\n\n// Cache for namespace plugins: plugin -> cacheKey -> PluginOutput\nconst namespaceProcessCache = new WeakMap<Plugin, Map<string, PluginOutput>>();\n\n/**\n * Generate a cache key that includes pluginConfig.\n * @param baseKey - Base key for the cache\n * @param pluginConfig - Plugin configuration to include in the key\n * @returns Cache key string\n */\nfunction getCacheKey(baseKey: string, pluginConfig: unknown): string {\n if (pluginConfig === undefined) {\n return baseKey;\n }\n try {\n return `${baseKey}:${JSON.stringify(pluginConfig)}`;\n } catch {\n throw new Error(\n `pluginConfig must be JSON-serializable for caching. Received non-serializable value.`,\n );\n }\n}\n\n// ========================================\n// Main API\n// ========================================\n\n/**\n * Get a generated table from a plugin by loading the config and resolving everything automatically.\n * For table-attached plugins, calls onTableLoaded() with the source table.\n * For namespace plugins, calls onNamespaceLoaded() with auto-resolved namespace.\n * Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.\n * @param configPath - Path to tailor.config.ts (absolute or relative to cwd)\n * @param pluginId - The plugin's unique identifier\n * @param sourceTable - The source TailorDB table (null for namespace plugins)\n * @param kind - The generated table kind (e.g., \"request\", \"step\")\n * @returns The generated TailorDB table\n */\nexport async function getGeneratedTable(\n configPath: string,\n pluginId: string,\n sourceTable: TailorAnyDBType | null,\n kind: string,\n): Promise<TailorAnyDBType> {\n const cache = await loadAndCacheConfig(configPath);\n\n if (!cache) {\n // Config not available (e.g., running in bundled executor on platform server).\n // Return a placeholder. The actual table is resolved at generate/apply time.\n return { name: `__placeholder_${kind}__`, fields: {} } as TailorAnyDBType;\n }\n\n const { config, configDir, plugins } = cache;\n\n const pluginEntry = plugins.get(pluginId);\n if (!pluginEntry) {\n throw new Error(\n `Plugin \"${pluginId}\" not found in config at \"${configPath}\". ` +\n `Ensure the plugin is registered via definePlugins().`,\n );\n }\n\n const { plugin, pluginConfig } = pluginEntry;\n\n if (sourceTable === null) {\n return getGeneratedTableForNamespacePlugin(config, plugin, kind, pluginConfig);\n }\n\n const namespace = await resolveNamespaceForTable(config, configDir, sourceTable);\n return getGeneratedTableForTableAttachedPlugin(\n plugin,\n sourceTable,\n kind,\n pluginConfig,\n namespace,\n );\n}\n\n/**\n * Get a generated table from a table-attached plugin.\n * @param plugin - The plugin instance (must have onTableLoaded() method)\n * @param sourceTable - The source TailorDB table\n * @param kind - The generated table kind\n * @param pluginConfig - Plugin-level configuration\n * @param namespace - Resolved namespace\n * @returns The generated TailorDB table\n */\nasync function getGeneratedTableForTableAttachedPlugin(\n plugin: Plugin,\n sourceTable: TailorAnyDBType,\n kind: string,\n pluginConfig: unknown,\n namespace: string,\n): Promise<TailorAnyDBType> {\n if (!plugin.onTableLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have an onTableLoaded() method`);\n }\n\n // Check cache first\n let pluginCache = processCache.get(plugin);\n if (!pluginCache) {\n pluginCache = new Map();\n processCache.set(plugin, pluginCache);\n }\n\n const cacheKey = getCacheKey(`${sourceTable.name}:ns=${namespace}`, pluginConfig);\n let output = pluginCache.get(cacheKey);\n\n if (!output) {\n const tableConfig = sourceTable.plugins.find((p) => p.pluginId === plugin.id)?.config;\n output = await plugin.onTableLoaded({\n table: sourceTable,\n tableConfig: tableConfig ?? {},\n pluginConfig,\n namespace,\n });\n pluginCache.set(cacheKey, output);\n }\n\n const generatedTable = output.tables?.[kind];\n if (!generatedTable) {\n throw new Error(\n `Generated table not found: plugin=${plugin.id}, sourceTable=${sourceTable.name}, kind=${kind}`,\n );\n }\n\n return generatedTable as TailorAnyDBType;\n}\n\n/**\n * Get a generated table from a namespace plugin.\n * Auto-resolves the namespace by trying each one.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param plugin - The plugin instance (must have onNamespaceLoaded() method)\n * @param kind - The generated table kind\n * @param pluginConfig - Plugin-level configuration\n * @returns The generated TailorDB table\n */\nasync function getGeneratedTableForNamespacePlugin(\n config: { db?: Record<string, unknown> },\n plugin: Plugin,\n kind: string,\n pluginConfig: unknown,\n): Promise<TailorAnyDBType> {\n if (!plugin.onNamespaceLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onNamespaceLoaded() method`);\n }\n\n // Check cache first - try all namespaces\n let pluginCache = namespaceProcessCache.get(plugin);\n if (!pluginCache) {\n pluginCache = new Map();\n namespaceProcessCache.set(plugin, pluginCache);\n }\n\n // Try cached results first\n if (config.db) {\n for (const namespace of Object.keys(config.db)) {\n const dbConfig = config.db[namespace] as DbNamespaceConfig;\n if (dbConfig.external) continue;\n\n const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);\n const cached = pluginCache.get(cacheKey);\n if (cached?.tables?.[kind]) {\n return cached.tables[kind] as TailorAnyDBType;\n }\n }\n }\n\n // Not in cache - resolve namespace and process\n const { namespace, output } = await resolveNamespaceForNamespacePlugin(\n config,\n plugin,\n kind,\n pluginConfig,\n );\n\n const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);\n pluginCache.set(cacheKey, output);\n\n const generatedTable = output.tables?.[kind];\n if (!generatedTable) {\n throw new Error(`Generated table not found: plugin=${plugin.id}, kind=${kind}`);\n }\n\n return generatedTable as TailorAnyDBType;\n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C,GAAI,GAAQ,SAAS,GACnB,OAAO,EAAO,OAAO,EAEzB,CAIF,GAAM,CAAE,YAAW,UAAW,MAAM,mCAClC,EACA,EACA,EACA,CACF,EAEM,EAAW,YAAY,gBAAgB,IAAa,CAAY,EACtE,EAAY,IAAI,EAAU,CAAM,EAEhC,IAAM,EAAiB,EAAO,SAAS,GACvC,GAAI,CAAC,EACH,MAAU,MAAM,qCAAqC,EAAO,GAAG,SAAS,GAAM,EAGhF,OAAO,CACT"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/with-context.ts","../../src/plugin/get-generated-table.ts"],"sourcesContent":["/**\n * Plugin executor context support for defining plugin executors in separate files.\n * This module provides utilities for creating type-safe plugin executors that receive\n * context (like table references and namespace) at runtime.\n */\n\nimport type { TailorEnv, TailorPrincipal } from \"#/runtime/types\";\n\n/**\n * Plugin executor factory function type.\n * Takes context and returns an executor configuration.\n * Returns unknown since the exact return type depends on createExecutor's generic params.\n */\nexport type PluginExecutorFactory<Ctx> = (ctx: Ctx) => unknown;\n\n// ============================================================================\n// Plugin Executor Args Types\n// ============================================================================\n\n/**\n * Base args for plugin executor function operations.\n * Provides typed access to runtime context without requiring specific record types.\n */\nexport interface PluginFunctionArgs {\n /** Workspace ID where the executor runs */\n workspaceId: string;\n /** Application namespace */\n appNamespace: string;\n /** Environment variables */\n env: TailorEnv;\n /** Principal that triggered the event, null for system events */\n actor: TailorPrincipal | null;\n /** Name of the TailorDB table */\n typeName: string;\n /** TailorDB connections by namespace */\n tailordb: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record creation.\n */\nexport interface PluginRecordCreatedArgs extends PluginFunctionArgs {\n /** The newly created record */\n newRecord: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record update.\n */\nexport interface PluginRecordUpdatedArgs extends PluginFunctionArgs {\n /** The record after update */\n newRecord: Record<string, unknown>;\n /** The record before update */\n oldRecord: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record deletion.\n */\nexport interface PluginRecordDeletedArgs extends PluginFunctionArgs {\n /** The deleted record */\n oldRecord: Record<string, unknown>;\n}\n\n/**\n * Database schema type for plugins.\n * Since plugins work with dynamic types, the schema uses Record types.\n */\nexport type PluginDBSchema = Record<string, Record<string, unknown>>;\n\n/**\n * Base record type for TailorDB records.\n * All records have an id field.\n */\nexport type PluginRecord = { id: string } & Record<string, unknown>;\n\n/**\n * Define a plugin executor that receives context at runtime.\n * This allows executor definitions to be in separate files while\n * still receiving dynamic values like typeName, generated types, and namespace.\n * @param factory - Function that takes context and returns executor configuration\n * @returns The same factory function (for type inference)\n * @example\n * ```typescript\n * // executors/on-create.ts\n * import { withPluginContext } from \"@tailor-platform/sdk/plugin\";\n * import { createExecutor, recordCreatedTrigger } from \"@tailor-platform/sdk\";\n * import { getDB } from \"@tailor-platform/function-kysely-tailordb\";\n *\n * interface MyContext {\n * sourceTable: TailorAnyDBType;\n * historyType: TailorAnyDBType;\n * namespace: string;\n * }\n *\n * export default withPluginContext<MyContext>((ctx) =>\n * createExecutor({\n * name: `${ctx.sourceTable.name.toLowerCase()}-on-create`,\n * trigger: recordCreatedTrigger({ type: ctx.sourceTable }),\n * operation: {\n * kind: \"function\",\n * body: async (args) => {\n * const db = getDB(ctx.namespace);\n * await db.insertInto(ctx.historyType.name).values({\n * recordId: args.newRecord.id,\n * // ...\n * }).execute();\n * },\n * },\n * })\n * );\n * ```\n */\nexport function withPluginContext<Ctx>(\n factory: PluginExecutorFactory<Ctx>,\n): PluginExecutorFactory<Ctx> {\n return factory;\n}\n","import * as fs from \"node:fs\";\nimport { pathToFileURL } from \"node:url\";\nimport * as path from \"pathe\";\nimport type { TailorAnyDBType } from \"#/configure/services/tailordb/types\";\nimport type { Plugin, PluginOutput, TablePluginOutput } from \"#/plugin/types\";\n\n// ========================================\n// Config loading and caching\n// ========================================\n\ninterface PluginEntry {\n plugin: Plugin;\n pluginConfig: unknown;\n}\n\ninterface ConfigCache {\n config: { db?: Record<string, unknown> };\n plugins: Map<string, PluginEntry>;\n configDir: string;\n}\n\n/** Cache: resolved config path -> loaded config data */\nconst configCacheMap = new Map<string, ConfigCache>();\n\n/**\n * Check if a value is a Plugin instance.\n * @param value - Value to check\n * @returns True if value has the shape of Plugin\n */\nfunction isPlugin(value: unknown): value is Plugin {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as Record<string, unknown>).id === \"string\" &&\n typeof (value as Record<string, unknown>).description === \"string\"\n );\n}\n\n/**\n * Load and cache config module from the given path.\n * Extracts plugins from all array exports using definePlugins() format.\n * Returns null if the config file does not exist (e.g., in bundled executor on platform server).\n * @param configPath - Absolute or relative path to tailor.config.ts\n * @returns Cached config data with plugins map, or null if config file is not available\n */\nasync function loadAndCacheConfig(configPath: string): Promise<ConfigCache | null> {\n const resolvedPath = path.resolve(configPath);\n\n const cached = configCacheMap.get(resolvedPath);\n if (cached) return cached;\n\n // Config file may not exist in bundled environments (e.g., platform server)\n if (!fs.existsSync(resolvedPath)) {\n return null;\n }\n\n const configModule = await import(pathToFileURL(resolvedPath).href);\n if (!configModule?.default) {\n throw new Error(`Invalid config module at \"${resolvedPath}\": default export not found`);\n }\n\n const config = configModule.default as { db?: Record<string, unknown> };\n const configDir = path.dirname(resolvedPath);\n const plugins = new Map<string, PluginEntry>();\n\n // Find plugin arrays from exports (definePlugins returns PluginConfig[])\n for (const value of Object.values(configModule)) {\n if (!Array.isArray(value)) continue;\n\n for (const item of value) {\n if (isPlugin(item)) {\n plugins.set(item.id, { plugin: item, pluginConfig: item.pluginConfig });\n }\n }\n }\n\n const result: ConfigCache = { config, plugins, configDir };\n configCacheMap.set(resolvedPath, result);\n return result;\n}\n\n// ========================================\n// Namespace resolution\n// ========================================\n\ninterface DbNamespaceConfig {\n files?: string[];\n external?: boolean;\n}\n\n/**\n * Resolve the namespace for a table-attached source table by checking config.db file patterns.\n * Uses ESM module cache identity: same file path yields same object references.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param configDir - Directory containing the config file\n * @param sourceTable - The TailorDB table to look up\n * @returns The namespace name\n */\nasync function resolveNamespaceForTable(\n config: { db?: Record<string, unknown> },\n configDir: string,\n sourceTable: TailorAnyDBType,\n): Promise<string> {\n if (!config.db) {\n throw new Error(`No db configuration found in config`);\n }\n\n for (const [namespace, nsConfig] of Object.entries(config.db)) {\n const dbConfig = nsConfig as DbNamespaceConfig;\n // Skip external namespaces (no files to resolve)\n if (dbConfig.external || !dbConfig.files) continue;\n\n for (const pattern of dbConfig.files) {\n const absolutePattern = path.resolve(configDir, pattern);\n let matchedFiles: string[];\n try {\n matchedFiles = fs.globSync(absolutePattern);\n } catch {\n continue;\n }\n\n for (const file of matchedFiles) {\n const mod = await import(pathToFileURL(file).href);\n for (const exported of Object.values(mod)) {\n if (exported === sourceTable) {\n return namespace;\n }\n }\n }\n }\n }\n\n throw new Error(\n `Could not resolve namespace for table \"${sourceTable.name}\". ` +\n `Ensure the table file is included in a db namespace's files pattern.`,\n );\n}\n\n/**\n * Resolve the namespace for a namespace plugin by trying each namespace.\n * Calls onNamespaceLoaded() for each and returns the first whose output contains the requested kind.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param plugin - Plugin instance\n * @param kind - The generated table kind to look for\n * @param pluginConfig - Plugin-level configuration\n * @returns The namespace name\n */\nasync function resolveNamespaceForNamespacePlugin(\n config: { db?: Record<string, unknown> },\n plugin: Plugin,\n kind: string,\n pluginConfig: unknown,\n): Promise<{ namespace: string; output: PluginOutput }> {\n if (!config.db) {\n throw new Error(`No db configuration found in config`);\n }\n\n if (!plugin.onNamespaceLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onNamespaceLoaded() method`);\n }\n\n for (const namespace of Object.keys(config.db)) {\n const dbConfig = config.db[namespace] as DbNamespaceConfig;\n if (dbConfig.external) continue;\n\n const output = await plugin.onNamespaceLoaded({\n pluginConfig,\n namespace,\n });\n\n if (output.tables?.[kind]) {\n return { namespace, output };\n }\n }\n\n throw new Error(\n `Could not resolve namespace for plugin \"${plugin.id}\" with kind \"${kind}\". ` +\n `No namespace produced a table with that kind.`,\n );\n}\n\n// ========================================\n// Process caching\n// ========================================\n\n// Cache: plugin -> cacheKey -> TablePluginOutput\nconst processCache = new WeakMap<Plugin, Map<string, TablePluginOutput>>();\n\n// Cache for namespace plugins: plugin -> cacheKey -> PluginOutput\nconst namespaceProcessCache = new WeakMap<Plugin, Map<string, PluginOutput>>();\n\n/**\n * Generate a cache key that includes pluginConfig.\n * @param baseKey - Base key for the cache\n * @param pluginConfig - Plugin configuration to include in the key\n * @returns Cache key string\n */\nfunction getCacheKey(baseKey: string, pluginConfig: unknown): string {\n if (pluginConfig === undefined) {\n return baseKey;\n }\n try {\n return `${baseKey}:${JSON.stringify(pluginConfig)}`;\n } catch {\n throw new Error(\n `pluginConfig must be JSON-serializable for caching. Received non-serializable value.`,\n );\n }\n}\n\n// ========================================\n// Main API\n// ========================================\n\n/**\n * Get a generated table from a plugin by loading the config and resolving everything automatically.\n * For table-attached plugins, calls onTableLoaded() with the source table.\n * For namespace plugins, calls onNamespaceLoaded() with auto-resolved namespace.\n * Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.\n * @param configPath - Path to tailor.config.ts (absolute or relative to cwd)\n * @param pluginId - The plugin's unique identifier\n * @param sourceTable - The source TailorDB table (null for namespace plugins)\n * @param kind - The generated table kind (e.g., \"request\", \"step\")\n * @returns The generated TailorDB table\n */\nexport async function getGeneratedTable(\n configPath: string,\n pluginId: string,\n sourceTable: TailorAnyDBType | null,\n kind: string,\n): Promise<TailorAnyDBType> {\n const cache = await loadAndCacheConfig(configPath);\n\n if (!cache) {\n // Config not available (e.g., running in bundled executor on platform server).\n // Return a placeholder. The actual table is resolved at generate/apply time.\n return { name: `__placeholder_${kind}__`, fields: {} } as TailorAnyDBType;\n }\n\n const { config, configDir, plugins } = cache;\n\n const pluginEntry = plugins.get(pluginId);\n if (!pluginEntry) {\n throw new Error(\n `Plugin \"${pluginId}\" not found in config at \"${configPath}\". ` +\n `Ensure the plugin is registered via definePlugins().`,\n );\n }\n\n const { plugin, pluginConfig } = pluginEntry;\n\n if (sourceTable === null) {\n return getGeneratedTableForNamespacePlugin(config, plugin, kind, pluginConfig);\n }\n\n const namespace = await resolveNamespaceForTable(config, configDir, sourceTable);\n return getGeneratedTableForTableAttachedPlugin(\n plugin,\n sourceTable,\n kind,\n pluginConfig,\n namespace,\n );\n}\n\n/**\n * Get a generated table from a table-attached plugin.\n * @param plugin - The plugin instance (must have onTableLoaded() method)\n * @param sourceTable - The source TailorDB table\n * @param kind - The generated table kind\n * @param pluginConfig - Plugin-level configuration\n * @param namespace - Resolved namespace\n * @returns The generated TailorDB table\n */\nasync function getGeneratedTableForTableAttachedPlugin(\n plugin: Plugin,\n sourceTable: TailorAnyDBType,\n kind: string,\n pluginConfig: unknown,\n namespace: string,\n): Promise<TailorAnyDBType> {\n if (!plugin.onTableLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have an onTableLoaded() method`);\n }\n\n // Check cache first\n let pluginCache = processCache.get(plugin);\n if (!pluginCache) {\n pluginCache = new Map();\n processCache.set(plugin, pluginCache);\n }\n\n const cacheKey = getCacheKey(`${sourceTable.name}:ns=${namespace}`, pluginConfig);\n let output = pluginCache.get(cacheKey);\n\n if (!output) {\n const tableConfig = sourceTable.plugins.find((p) => p.pluginId === plugin.id)?.config;\n output = await plugin.onTableLoaded({\n table: sourceTable,\n tableConfig: tableConfig ?? {},\n pluginConfig,\n namespace,\n });\n pluginCache.set(cacheKey, output);\n }\n\n const generatedTable = output.tables?.[kind];\n if (!generatedTable) {\n throw new Error(\n `Generated table not found: plugin=${plugin.id}, sourceTable=${sourceTable.name}, kind=${kind}`,\n );\n }\n\n return generatedTable as TailorAnyDBType;\n}\n\n/**\n * Get a generated table from a namespace plugin.\n * Auto-resolves the namespace by trying each one.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param plugin - The plugin instance (must have onNamespaceLoaded() method)\n * @param kind - The generated table kind\n * @param pluginConfig - Plugin-level configuration\n * @returns The generated TailorDB table\n */\nasync function getGeneratedTableForNamespacePlugin(\n config: { db?: Record<string, unknown> },\n plugin: Plugin,\n kind: string,\n pluginConfig: unknown,\n): Promise<TailorAnyDBType> {\n if (!plugin.onNamespaceLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onNamespaceLoaded() method`);\n }\n\n // Check cache first - try all namespaces\n let pluginCache = namespaceProcessCache.get(plugin);\n if (!pluginCache) {\n pluginCache = new Map();\n namespaceProcessCache.set(plugin, pluginCache);\n }\n\n // Try cached results first\n if (config.db) {\n for (const namespace of Object.keys(config.db)) {\n const dbConfig = config.db[namespace] as DbNamespaceConfig;\n if (dbConfig.external) continue;\n\n const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);\n const cached = pluginCache.get(cacheKey);\n if (cached?.tables?.[kind]) {\n return cached.tables[kind] as TailorAnyDBType;\n }\n }\n }\n\n // Not in cache - resolve namespace and process\n const { namespace, output } = await resolveNamespaceForNamespacePlugin(\n config,\n plugin,\n kind,\n pluginConfig,\n );\n\n const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);\n pluginCache.set(cacheKey, output);\n\n const generatedTable = output.tables?.[kind];\n if (!generatedTable) {\n throw new Error(`Generated table not found: plugin=${plugin.id}, kind=${kind}`);\n }\n\n return generatedTable as TailorAnyDBType;\n}\n\n/**\n * Clear all internal caches. For testing only.\n */\nexport function _clearCacheForTesting(): void {\n configCacheMap.clear();\n}\n"],"mappings":"2FAiHA,SAAgB,kBACd,EAC4B,CAC5B,OAAO,CACT,CC/FA,MAAM,EAAiB,IAAI,IAO3B,SAAS,SAAS,EAAiC,CACjD,OACE,OAAO,GAAU,YACjB,GACA,OAAQ,EAAkC,IAAO,UACjD,OAAQ,EAAkC,aAAgB,QAE9D,CASA,eAAe,mBAAmB,EAAiD,CACjF,IAAM,EAAe,EAAK,QAAQ,CAAU,EAEtC,E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* Result returned by generation-time hooks.
18
18
  */
19
- interface GeneratorResult {
19
+ export interface GeneratorResult {
20
20
  files: GeneratedFile[];
21
21
  errors?: string[];
22
22
  }
23
23
  /**
24
24
  * Auth configuration available to generation-time hooks.
25
25
  */
26
- interface GeneratorAuthInput {
26
+ export interface GeneratorAuthInput {
27
27
  name: string;
28
28
  userProfile?: {
29
29
  tableName: string;
@@ -39,7 +39,7 @@ interface GeneratorAuthInput {
39
39
  /**
40
40
  * Namespace-level TailorDB data available to generation-time hooks.
41
41
  */
42
- interface TailorDBNamespaceData {
42
+ export interface TailorDBNamespaceData {
43
43
  /** Namespace name */
44
44
  namespace: string;
45
45
  /** All TailorDB tables in this namespace, keyed by table name */
@@ -52,7 +52,7 @@ interface TailorDBNamespaceData {
52
52
  /**
53
53
  * Namespace-level resolver data available to generation-time hooks.
54
54
  */
55
- interface ResolverNamespaceData {
55
+ export interface ResolverNamespaceData {
56
56
  /** Namespace name */
57
57
  namespace: string;
58
58
  /** All resolvers in this namespace, keyed by resolver name */
@@ -62,7 +62,7 @@ interface ResolverNamespaceData {
62
62
  * Context passed to plugin's onTailorDBReady hook.
63
63
  * @template PluginConfig - Plugin-level configuration type
64
64
  */
65
- interface TailorDBReadyContext<PluginConfig = unknown> {
65
+ export interface TailorDBReadyContext<PluginConfig = unknown> {
66
66
  /** All TailorDB namespaces with their tables and metadata */
67
67
  tailordb: TailorDBNamespaceData[];
68
68
  /** Auth configuration */
@@ -78,7 +78,7 @@ interface TailorDBReadyContext<PluginConfig = unknown> {
78
78
  * Context passed to plugin's onResolverReady hook.
79
79
  * @template PluginConfig - Plugin-level configuration type
80
80
  */
81
- interface ResolverReadyContext<PluginConfig = unknown> {
81
+ export interface ResolverReadyContext<PluginConfig = unknown> {
82
82
  /** All TailorDB namespaces with their tables and metadata */
83
83
  tailordb: TailorDBNamespaceData[];
84
84
  /** All resolver namespaces with their resolvers */
@@ -96,7 +96,7 @@ interface ResolverReadyContext<PluginConfig = unknown> {
96
96
  * Context passed to plugin's onExecutorReady hook.
97
97
  * @template PluginConfig - Plugin-level configuration type
98
98
  */
99
- interface ExecutorReadyContext<PluginConfig = unknown> {
99
+ export interface ExecutorReadyContext<PluginConfig = unknown> {
100
100
  /** All TailorDB namespaces with their tables and metadata */
101
101
  tailordb: TailorDBNamespaceData[];
102
102
  /** All resolver namespaces with their resolvers */
@@ -113,12 +113,12 @@ interface ExecutorReadyContext<PluginConfig = unknown> {
113
113
  pluginConfig: PluginConfig;
114
114
  }
115
115
  /** @lintignore kept exported for the zinfer-generated reference in src/types/plugin-config.generated.ts */
116
- type TableConfigRequired<PluginConfig = unknown> = boolean | ((pluginConfig: PluginConfig | undefined) => boolean);
116
+ export type TableConfigRequired<PluginConfig = unknown> = boolean | ((pluginConfig: PluginConfig | undefined) => boolean);
117
117
  /**
118
118
  * Interface for plugin configuration mapping.
119
119
  * Extend this interface via declaration merging to add typed plugin configs.
120
120
  */
121
- interface PluginConfigs<Fields extends string = string> {}
121
+ export interface PluginConfigs<Fields extends string = string> {}
122
122
  /**
123
123
  * Registry mapping a plugin's `id` literal to the fields it injects into the
124
124
  * attached table's static type, computed from the literal per-call config
@@ -127,17 +127,17 @@ interface PluginConfigs<Fields extends string = string> {}
127
127
  * `Record<string, TailorAnyDBField>` of the fields to add — it is merged
128
128
  * into the table's existing fields, not a replacement for them.
129
129
  */
130
- interface PluginFieldExtensions<Fields extends string = string, Config = unknown> {}
130
+ export interface PluginFieldExtensions<Fields extends string = string, Config = unknown> {}
131
131
  /**
132
132
  * Registry mapping a plugin's `id` literal to its plugin-level config type.
133
133
  * Extend via declaration merging, keyed by the `id` string, from the
134
134
  * owning plugin's own module.
135
135
  */
136
- interface PluginConfigRegistry {}
136
+ export interface PluginConfigRegistry {}
137
137
  /**
138
138
  * Context passed to plugin's process method
139
139
  */
140
- interface PluginTableProcessContext<TableConfig = unknown, PluginConfig = unknown> {
140
+ export interface PluginTableProcessContext<TableConfig = unknown, PluginConfig = unknown> {
141
141
  table: TailorAnyDBType;
142
142
  tableConfig: TableConfig;
143
143
  pluginConfig: PluginConfig;
@@ -146,20 +146,20 @@ interface PluginTableProcessContext<TableConfig = unknown, PluginConfig = unknow
146
146
  /**
147
147
  * Context passed to plugin's onNamespaceLoaded hook.
148
148
  */
149
- interface PluginNamespaceProcessContext<PluginConfig = unknown> {
149
+ export interface PluginNamespaceProcessContext<PluginConfig = unknown> {
150
150
  pluginConfig: PluginConfig;
151
151
  namespace: string;
152
152
  }
153
153
  /**
154
154
  * Interface representing a TailorDB table for plugin output.
155
155
  */
156
- interface TailorDBTableForPlugin {
156
+ export interface TailorDBTableForPlugin {
157
157
  readonly name: string;
158
158
  readonly fields: Record<string, unknown>;
159
159
  }
160
- type PluginGeneratedTable = TailorDBTableForPlugin;
160
+ export type PluginGeneratedTable = TailorDBTableForPlugin;
161
161
  type PluginGeneratedTables = Record<string, PluginGeneratedTable>;
162
- interface PluginGeneratedResolver {
162
+ export interface PluginGeneratedResolver {
163
163
  name: string;
164
164
  operation: "query" | "mutation";
165
165
  inputFields?: Record<string, unknown>;
@@ -179,9 +179,9 @@ interface PluginScheduleTriggerConfig {
179
179
  interface PluginIncomingWebhookTriggerConfig {
180
180
  kind: "incomingWebhook";
181
181
  }
182
- type PluginTriggerConfig = PluginRecordTriggerConfig | PluginScheduleTriggerConfig | PluginIncomingWebhookTriggerConfig;
182
+ export type PluginTriggerConfig = PluginRecordTriggerConfig | PluginScheduleTriggerConfig | PluginIncomingWebhookTriggerConfig;
183
183
  type PluginInjectValue = string | number | boolean | null;
184
- type PluginInjectMap = Record<string, PluginInjectValue>;
184
+ export type PluginInjectMap = Record<string, PluginInjectValue>;
185
185
  interface PluginFunctionOperationConfig {
186
186
  kind: "function";
187
187
  body: string;
@@ -201,49 +201,49 @@ interface PluginWorkflowOperationConfig {
201
201
  kind: "workflow";
202
202
  workflowName: string;
203
203
  }
204
- type PluginOperationConfig = PluginFunctionOperationConfig | PluginGraphQLOperationConfig | PluginWebhookOperationConfig | PluginWorkflowOperationConfig;
204
+ export type PluginOperationConfig = PluginFunctionOperationConfig | PluginGraphQLOperationConfig | PluginWebhookOperationConfig | PluginWorkflowOperationConfig;
205
205
  type PluginExecutorContextValue = TailorAnyDBType | string | number | boolean | null | undefined;
206
- interface PluginExecutorContextBase {
206
+ export interface PluginExecutorContextBase {
207
207
  sourceTable: TailorAnyDBType | null;
208
208
  namespace: string;
209
209
  }
210
- type PluginExecutorContext = PluginExecutorContextBase & {
210
+ export type PluginExecutorContext = PluginExecutorContextBase & {
211
211
  [key: string]: PluginExecutorContextValue;
212
212
  };
213
213
  interface PluginExecutorModule {
214
214
  default: unknown;
215
215
  }
216
- interface PluginGeneratedExecutorWithFile<Ctx = PluginExecutorContext> {
216
+ export interface PluginGeneratedExecutorWithFile<Ctx = PluginExecutorContext> {
217
217
  name: string;
218
218
  resolve: () => Promise<PluginExecutorModule>;
219
219
  context: Ctx;
220
220
  }
221
- interface PluginGeneratedExecutorLegacy {
221
+ export interface PluginGeneratedExecutorLegacy {
222
222
  name: string;
223
223
  description?: string;
224
224
  trigger: PluginTriggerConfig;
225
225
  operation: PluginOperationConfig;
226
226
  }
227
- type PluginGeneratedExecutor = PluginGeneratedExecutorWithFile | PluginGeneratedExecutorLegacy;
227
+ export type PluginGeneratedExecutor = PluginGeneratedExecutorWithFile | PluginGeneratedExecutorLegacy;
228
228
  interface PluginExtends<FieldExtension extends Record<string, TailorAnyDBField>> {
229
229
  fields?: FieldExtension;
230
230
  }
231
- interface PluginOutput {
231
+ export interface PluginOutput {
232
232
  tables?: PluginGeneratedTables;
233
233
  resolvers?: PluginGeneratedResolver[];
234
234
  executors?: PluginGeneratedExecutor[];
235
235
  }
236
- interface TablePluginOutput<FieldExtension extends Record<string, TailorAnyDBField> = Record<string, TailorAnyDBField>> extends PluginOutput {
236
+ export interface TablePluginOutput<FieldExtension extends Record<string, TailorAnyDBField> = Record<string, TailorAnyDBField>> extends PluginOutput {
237
237
  extends?: PluginExtends<FieldExtension>;
238
238
  }
239
- type NamespacePluginOutput = PluginOutput;
239
+ export type NamespacePluginOutput = PluginOutput;
240
240
  /**
241
241
  * Plugin interface that all plugins must implement.
242
242
  * @template TableConfig - Type for per-table configuration passed via .plugin() method
243
243
  * @template PluginConfig - Type for plugin-level configuration passed via definePlugins()
244
244
  * @template FieldExtension - Type of the fields injected into the attached table via `extends.fields`. Should match the corresponding {@link PluginFieldExtensions} entry.
245
245
  */
246
- interface Plugin<TableConfig = unknown, PluginConfig = unknown, FieldExtension extends Record<string, TailorAnyDBField> = Record<string, TailorAnyDBField>> {
246
+ export interface Plugin<TableConfig = unknown, PluginConfig = unknown, FieldExtension extends Record<string, TailorAnyDBField> = Record<string, TailorAnyDBField>> {
247
247
  readonly id: string;
248
248
  readonly description: string;
249
249
  readonly importPath?: string;
@@ -256,4 +256,4 @@ interface Plugin<TableConfig = unknown, PluginConfig = unknown, FieldExtension e
256
256
  onExecutorReady?(context: ExecutorReadyContext<PluginConfig>): GeneratorResult | Promise<GeneratorResult>;
257
257
  }
258
258
  //#endregion
259
- export { ExecutorReadyContext, GeneratorAuthInput, GeneratorResult, NamespacePluginOutput, Plugin, type PluginAttachment, PluginConfigRegistry, PluginConfigs, PluginExecutorContext, PluginExecutorContextBase, PluginFieldExtensions, PluginGeneratedExecutor, PluginGeneratedExecutorLegacy, PluginGeneratedExecutorWithFile, PluginGeneratedResolver, PluginGeneratedTable, PluginInjectMap, PluginNamespaceProcessContext, PluginOperationConfig, PluginOutput, PluginTableProcessContext, PluginTriggerConfig, ResolverNamespaceData, ResolverReadyContext, TableConfigRequired, TablePluginOutput, TailorDBNamespaceData, TailorDBReadyContext, TailorDBTableForPlugin };
259
+ export type { PluginAttachment };
@@ -5,12 +5,12 @@ import { TailorEnv, TailorPrincipal } from "../runtime/types.mjs";
5
5
  * Takes context and returns an executor configuration.
6
6
  * Returns unknown since the exact return type depends on createExecutor's generic params.
7
7
  */
8
- type PluginExecutorFactory<Ctx> = (ctx: Ctx) => unknown;
8
+ export type PluginExecutorFactory<Ctx> = (ctx: Ctx) => unknown;
9
9
  /**
10
10
  * Base args for plugin executor function operations.
11
11
  * Provides typed access to runtime context without requiring specific record types.
12
12
  */
13
- interface PluginFunctionArgs {
13
+ export interface PluginFunctionArgs {
14
14
  /** Workspace ID where the executor runs */
15
15
  workspaceId: string;
16
16
  /** Application namespace */
@@ -27,14 +27,14 @@ interface PluginFunctionArgs {
27
27
  /**
28
28
  * Args for plugin executors triggered on record creation.
29
29
  */
30
- interface PluginRecordCreatedArgs extends PluginFunctionArgs {
30
+ export interface PluginRecordCreatedArgs extends PluginFunctionArgs {
31
31
  /** The newly created record */
32
32
  newRecord: Record<string, unknown>;
33
33
  }
34
34
  /**
35
35
  * Args for plugin executors triggered on record update.
36
36
  */
37
- interface PluginRecordUpdatedArgs extends PluginFunctionArgs {
37
+ export interface PluginRecordUpdatedArgs extends PluginFunctionArgs {
38
38
  /** The record after update */
39
39
  newRecord: Record<string, unknown>;
40
40
  /** The record before update */
@@ -43,7 +43,7 @@ interface PluginRecordUpdatedArgs extends PluginFunctionArgs {
43
43
  /**
44
44
  * Args for plugin executors triggered on record deletion.
45
45
  */
46
- interface PluginRecordDeletedArgs extends PluginFunctionArgs {
46
+ export interface PluginRecordDeletedArgs extends PluginFunctionArgs {
47
47
  /** The deleted record */
48
48
  oldRecord: Record<string, unknown>;
49
49
  }
@@ -51,12 +51,12 @@ interface PluginRecordDeletedArgs extends PluginFunctionArgs {
51
51
  * Database schema type for plugins.
52
52
  * Since plugins work with dynamic types, the schema uses Record types.
53
53
  */
54
- type PluginDBSchema = Record<string, Record<string, unknown>>;
54
+ export type PluginDBSchema = Record<string, Record<string, unknown>>;
55
55
  /**
56
56
  * Base record type for TailorDB records.
57
57
  * All records have an id field.
58
58
  */
59
- type PluginRecord = {
59
+ export type PluginRecord = {
60
60
  id: string;
61
61
  } & Record<string, unknown>;
62
62
  /**
@@ -96,6 +96,5 @@ type PluginRecord = {
96
96
  * );
97
97
  * ```
98
98
  */
99
- declare function withPluginContext<Ctx>(factory: PluginExecutorFactory<Ctx>): PluginExecutorFactory<Ctx>;
100
- //#endregion
101
- export { PluginDBSchema, PluginExecutorFactory, PluginFunctionArgs, PluginRecord, PluginRecordCreatedArgs, PluginRecordDeletedArgs, PluginRecordUpdatedArgs, withPluginContext };
99
+ export declare function withPluginContext<Ctx>(factory: PluginExecutorFactory<Ctx>): PluginExecutorFactory<Ctx>;
100
+ //#endregion