@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
@@ -3,11 +3,12 @@ import { PluginAttachment } from "../configure/services/tailordb/types.mjs";
3
3
  import { OperatorFieldConfig, ParsedField, PluginGeneratedTypeSource, TailorDBType, TypeSourceInfoEntry } from "../parser/service/tailordb/types.mjs";
4
4
  import { Executor } from "../types/executor.generated.mjs";
5
5
  import { Resolver } from "../types/resolver.generated.mjs";
6
- import { GeneratorResult, TailorDBNamespaceData } from "../plugin/types.mjs";
6
+ import { GeneratorResult, Plugin, TailorDBNamespaceData } from "../plugin/types.mjs";
7
7
  import { LoadedConfig, loadConfig } from "./shared/config-loader.mjs";
8
8
  import { AuthInvoker } from "../tailor-proto/src/tailor/v1/auth_resource_pb.mjs";
9
9
  import { OperatorClient, initOperatorClient } from "./shared/client.mjs";
10
10
  import "./commands/deploy/function-registry.mjs";
11
+ import { NamespaceWithMigrations, getNamespacesWithMigrations } from "./commands/tailordb/migrate/config.mjs";
11
12
  import { NormalizedSchemaSnapshot, SchemaSnapshot, SnapshotFieldConfig, TailorDBSnapshotType } from "./commands/tailordb/migrate/snapshot-types.mjs";
12
13
  import { BreakingChangeInfo, MigrationDiff, formatDiffSummary, formatMigrationDiff, hasChanges } from "./commands/tailordb/migrate/diff-calculator.mjs";
13
14
  import { MIGRATION_LABEL_KEY } from "./commands/tailordb/migrate/types.mjs";
@@ -15,15 +16,12 @@ import { DB_TYPES_FILE_NAME, DIFF_FILE_NAME, INITIAL_SCHEMA_NUMBER, MIGRATE_FILE
15
16
  import { DeployOptions, deploy } from "./commands/deploy/deploy.mjs";
16
17
  import { GenerateOptions } from "./commands/generate/options.mjs";
17
18
  import { generate } from "./commands/generate/service.mjs";
19
+ import { ErrorToJsonOptions, errorToJson, serializeError } from "./shared/error-json.mjs";
18
20
  import { generateUserTypes } from "./shared/type-generator.mjs";
19
21
  import { LoadTailorDBNamespacesOptions, LoadedTailorDBNamespaces, TailorDBNamespaceSelector, loadTailorDBNamespaces } from "./shared/tailordb-namespaces.mjs";
20
22
  import { DeployResult, deployStaticWebsite } from "./commands/staticwebsite/deploy.mjs";
21
23
  import { assertWritable } from "./shared/readonly-guard.mjs";
22
24
  import { isPluginGeneratedType } from "../parser/service/tailordb/type-source.mjs";
23
- import { kyselyTypePlugin } from "../plugin/builtin/kysely-type/index.mjs";
24
- import { enumConstantsPlugin } from "../plugin/builtin/enum-constants/index.mjs";
25
- import { fileUtilsPlugin } from "../plugin/builtin/file-utils/index.mjs";
26
- import { seedPlugin } from "../plugin/builtin/seed/index.mjs";
27
25
  import { AIGatewayInfo, ApplicationInfo, ShowInfo, ShowOptions, show } from "./commands/show.mjs";
28
26
  import { RemoveOptions, remove } from "./commands/remove.mjs";
29
27
  import { WorkspaceDetails, WorkspaceInfo } from "./commands/workspace/transform.mjs";
@@ -50,17 +48,17 @@ import { GetOAuth2ClientOptions, getOAuth2Client } from "./commands/oauth2client
50
48
  import { ListOAuth2ClientsOptions, listOAuth2Clients } from "./commands/oauth2client/list.mjs";
51
49
  import { WorkflowExecutionInfo, WorkflowInfo, WorkflowJobExecutionInfo, WorkflowListInfo } from "./commands/workflow/transform.mjs";
52
50
  import { ListWorkflowsOptions, listWorkflows } from "./commands/workflow/list.mjs";
53
- import { GetWorkflowOptions, GetWorkflowTypedOptions, getWorkflow } from "./commands/workflow/get.mjs";
51
+ import { GetWorkflowTypedOptions, getWorkflow } from "./commands/workflow/get.mjs";
54
52
  import { WaitWorkflowExecutionOptions, WorkflowWaitResult } from "./commands/workflow/waiter.mjs";
55
- import { StartWorkflowOptions, StartWorkflowResultWithWait, StartWorkflowTypedOptions, WaitOptions, startWorkflow } from "./commands/workflow/start.mjs";
56
- import { GetWorkflowExecutionOptions, GetWorkflowExecutionResult, ListWorkflowExecutionsOptions, ListWorkflowExecutionsTypedOptions, WorkflowExecutionWaitInfo, getWorkflowExecution, listWorkflowExecutions } from "./commands/workflow/executions.mjs";
53
+ import { StartWorkflowResultWithWait, StartWorkflowTypedOptions, WaitOptions, startWorkflow } from "./commands/workflow/start.mjs";
54
+ import { GetWorkflowExecutionOptions, GetWorkflowExecutionResult, ListWorkflowExecutionsTypedOptions, WorkflowExecutionWaitInfo, getWorkflowExecution, listWorkflowExecutions } from "./commands/workflow/executions.mjs";
57
55
  import { WorkflowWaitOutput, waitWorkflowExecution } from "./commands/workflow/wait.mjs";
58
56
  import { ResumeWorkflowOptions, ResumeWorkflowResultWithWait, resumeWorkflow } from "./commands/workflow/resume.mjs";
59
- import { TriggerExecutorOptions, TriggerExecutorResult, TriggerExecutorTypedOptions, triggerExecutor } from "./commands/executor/trigger.mjs";
57
+ import { TriggerExecutorResult, TriggerExecutorTypedOptions, triggerExecutor } from "./commands/executor/trigger.mjs";
60
58
  import { ExecutorInfo, ExecutorJobAttemptInfo, ExecutorJobInfo, ExecutorJobListInfo, ExecutorListInfo } from "./commands/executor/transform.mjs";
61
- import { ExecutorJobDetailInfo, GetExecutorJobOptions, GetExecutorJobTypedOptions, ListExecutorJobsOptions, ListExecutorJobsTypedOptions, WatchExecutorJobOptions, WatchExecutorJobResult, WatchExecutorJobTypedOptions, getExecutorJob, getExecutorWaitFailureMessage, listExecutorJobs, watchExecutorJob } from "./commands/executor/jobs.mjs";
59
+ import { ExecutorJobDetailInfo, GetExecutorJobTypedOptions, ListExecutorJobsTypedOptions, WatchExecutorJobResult, WatchExecutorJobTypedOptions, getExecutorJob, getExecutorWaitFailureMessage, listExecutorJobs, watchExecutorJob } from "./commands/executor/jobs.mjs";
62
60
  import { ListExecutorsOptions, listExecutors } from "./commands/executor/list.mjs";
63
- import { GetExecutorOptions, GetExecutorTypedOptions, getExecutor } from "./commands/executor/get.mjs";
61
+ import { GetExecutorTypedOptions, getExecutor } from "./commands/executor/get.mjs";
64
62
  import { ListWebhookExecutorsOptions, WebhookExecutorInfo, listWebhookExecutors } from "./commands/executor/webhook.mjs";
65
63
  import { FolderInfo, FolderListInfo, OrganizationInfo, UserOrganizationInfo } from "./commands/organization/transform.mjs";
66
64
  import { ListOrganizationsOptions, listOrganizations } from "./commands/organization/list.mjs";
@@ -78,10 +76,11 @@ import "./commands/api/index.mjs";
78
76
  import { query } from "./query/index.mjs";
79
77
  import { TruncateOptions, truncate } from "./commands/tailordb/truncate.mjs";
80
78
  import { GenerateOptions as GenerateOptions$1, generate as generate$1 } from "./commands/tailordb/migrate/generate.mjs";
81
- import { NamespaceWithMigrations, getNamespacesWithMigrations } from "./commands/tailordb/migrate/config.mjs";
82
- import { ChunkSeedDataOptions, SeedChunk, chunkSeedData } from "./shared/seed-chunker.mjs";
79
+ import { SeedNamespaceConfig } from "../plugin/builtin/seed/seed-type-processor.mjs";
80
+ import { LoadSeedContextOptions, SeedContext, SeedIdpUserContext, loadSeedContext } from "./shared/seed-context.mjs";
81
+ import { ChunkSeedDataOptions, SeedChunk, SeedData, chunkSeedData } from "./shared/seed-chunker.mjs";
83
82
  import { SeedBundleResult, bundleSeedScript } from "./commands/generate/seed/bundler.mjs";
84
83
  import { MigrationBundleResult, bundleMigrationScript } from "./commands/tailordb/migrate/bundler.mjs";
85
- import { ExecutionWaitResult, ScriptExecutionOptions, ScriptExecutionResult, executeScript, waitForExecution } from "./shared/script-executor.mjs";
84
+ import { ExecutionWaitResult, ScriptExecutionOptions, ScriptExecutionResult, ScriptInvoker, executeScript, waitForExecution } from "./shared/script-executor.mjs";
86
85
  import { MachineUserName } from "@tailor-platform/sdk";
87
- export { type AIGatewayInfo, type ApiCallOptions, type ApiCallResult, type AppHealthInfo, type AppInfo, type ApplicationInfo, type DeployOptions as ApplyOptions, type AuthInvoker, type BreakingChangeInfo, type BundledScripts, type ChunkSeedDataOptions, type CreateFolderOptions, type CreateWorkspaceOptions, DB_TYPES_FILE_NAME, DIFF_FILE_NAME, type DeleteFolderOptions, type DeleteWorkspaceOptions, type DeployOptions, type ExecutionWaitResult, type Executor, type ExecutorInfo, type ExecutorJobAttemptInfo, type ExecutorJobDetailInfo, type ExecutorJobInfo, type ExecutorJobListInfo, type ExecutorListInfo, type FolderInfo, type FolderListInfo, type FunctionRegistryInfo, type GenerateOptions, type GeneratorResult, type HealthOptions as GetAppHealthOptions, type GetExecutorJobOptions, type GetExecutorJobTypedOptions, type GetExecutorOptions, type GetExecutorTypedOptions, type GetFolderOptions, type GetFunctionRegistryOptions, type GetMachineUserTokenOptions, type GetOAuth2ClientOptions, type GetOrganizationOptions, type GetWorkflowExecutionOptions, type GetWorkflowExecutionResult, type GetWorkflowOptions, type GetWorkflowTypedOptions, type GetWorkspaceOptions, INITIAL_SCHEMA_NUMBER, type InviteUserOptions, type ListAppsOptions, type ListExecutorJobsOptions, type ListExecutorJobsTypedOptions, type ListExecutorsOptions, type ListFoldersOptions, type ListFunctionRegistriesOptions, type ListMachineUsersOptions, type ListOAuth2ClientsOptions, type ListOrganizationsOptions, type ListUsersOptions, type ListWebhookExecutorsOptions, type ListWorkflowExecutionsOptions, type ListWorkflowExecutionsTypedOptions, type ListWorkflowsOptions, type ListWorkspacesOptions, type LoadTailorDBNamespacesOptions, type LoadedConfig, type LoadedTailorDBNamespaces, MIGRATE_FILE_NAME, MIGRATION_LABEL_KEY, type MachineUserInfo, type MachineUserName, type MachineUserTokenInfo, type GenerateOptions$1 as MigrateGenerateOptions, type MigrationBundleResult, type MigrationDiff, type NamespaceWithMigrations, type NormalizedSchemaSnapshot, type OAuth2ClientCredentials, type OAuth2ClientInfo, type OperatorClient, type OperatorFieldConfig, type OrganizationInfo, type OrganizationTreeOptions, type ParsedField, type PluginAttachment, type PluginGeneratedTypeSource, type RemoveOptions, type RemoveUserOptions, type Resolver, type RestoreWorkspaceOptions, type ResumeWorkflowOptions, type ResumeWorkflowResultWithWait, SCHEMA_FILE_NAME, type SchemaSnapshot, type ScriptExecutionOptions, type ScriptExecutionResult, type SeedBundleResult, type SeedChunk, type ShowInfo, type ShowOptions, type SnapshotFieldConfig, type StartWorkflowOptions, type StartWorkflowResultWithWait, type StartWorkflowTypedOptions, type DeployResult as StaticWebsiteDeployResult, type TailorDBNamespaceData, type TailorDBNamespaceSelector, type TailorDBSnapshotType, type TailorDBType, type TriggerExecutorOptions, type TriggerExecutorResult, type TriggerExecutorTypedOptions, type TruncateOptions, type TypeSourceInfoEntry, type UpdateFolderOptions, type UpdateOrganizationOptions, type UpdateUserOptions, type UserInfo, type UserOrganizationInfo, type WaitOptions, type WaitWorkflowExecutionOptions, type WatchExecutorJobOptions, type WatchExecutorJobResult, type WatchExecutorJobTypedOptions, type WebhookExecutorInfo, type WorkflowExecutionInfo, type WorkflowExecutionWaitInfo, type WorkflowInfo, type WorkflowJobExecutionInfo, type WorkflowListInfo, type WorkflowWaitOutput, type WorkflowWaitResult, type WorkspaceDetails, type WorkspaceInfo, apiCall, deploy as apply, assertWritable, bundleMigrationScript, bundleSeedScript, chunkSeedData, compareLocalTypesWithSnapshot, compareSnapshots, createFolder, createSnapshotFromLocalTypes, createWorkspace, deleteFolder, deleteWorkspace, deploy, deployStaticWebsite, enumConstantsPlugin, executeScript, fileUtilsPlugin, formatDiffSummary, formatMigrationDiff, generate, generateUserTypes, getAppHealth, getExecutor, getExecutorJob, getExecutorWaitFailureMessage, getFolder, getFunctionRegistry, getLatestMigrationNumber, getMachineUserToken, getMigrationDirPath, getMigrationFilePath, getMigrationFiles, getNamespacesWithMigrations, getNextMigrationNumber, getOAuth2Client, getOrganization, getWorkflow, getWorkflowExecution, getWorkspace, hasChanges, initOperatorClient, inviteUser, isPluginGeneratedType, kyselyTypePlugin, listApps, listExecutorJobs, listExecutors, listFolders, listFunctionRegistries, listMachineUsers, listOAuth2Clients, listOrganizations, listUsers, listWebhookExecutors, listWorkflowExecutions, listWorkflows, listWorkspaces, loadAccessToken, loadConfig, loadTailorDBNamespaces, loadWorkspaceId, generate$1 as migrateGenerate, organizationTree, query, reconstructSnapshotFromMigrations, remove, removeUser, restoreWorkspace, resumeWorkflow, seedPlugin, show, startWorkflow, triggerExecutor, truncate, updateFolder, updateOrganization, updateUser, waitForExecution, waitWorkflowExecution, watchExecutorJob };
86
+ export { type AIGatewayInfo, type ApiCallOptions, type ApiCallResult, type AppHealthInfo, type AppInfo, type ApplicationInfo, type DeployOptions as ApplyOptions, type AuthInvoker, type BreakingChangeInfo, type BundledScripts, type ChunkSeedDataOptions, type CreateFolderOptions, type CreateWorkspaceOptions, DB_TYPES_FILE_NAME, DIFF_FILE_NAME, type DeleteFolderOptions, type DeleteWorkspaceOptions, type DeployOptions, type ErrorToJsonOptions, type ExecutionWaitResult, type Executor, type ExecutorInfo, type ExecutorJobAttemptInfo, type ExecutorJobDetailInfo, type ExecutorJobInfo, type ExecutorJobListInfo, type ExecutorListInfo, type FolderInfo, type FolderListInfo, type FunctionRegistryInfo, type GenerateOptions, type GeneratorResult, type HealthOptions as GetAppHealthOptions, type GetExecutorJobTypedOptions, type GetExecutorTypedOptions, type GetFolderOptions, type GetFunctionRegistryOptions, type GetMachineUserTokenOptions, type GetOAuth2ClientOptions, type GetOrganizationOptions, type GetWorkflowExecutionOptions, type GetWorkflowExecutionResult, type GetWorkflowTypedOptions, type GetWorkspaceOptions, INITIAL_SCHEMA_NUMBER, type InviteUserOptions, type ListAppsOptions, type ListExecutorJobsTypedOptions, type ListExecutorsOptions, type ListFoldersOptions, type ListFunctionRegistriesOptions, type ListMachineUsersOptions, type ListOAuth2ClientsOptions, type ListOrganizationsOptions, type ListUsersOptions, type ListWebhookExecutorsOptions, type ListWorkflowExecutionsTypedOptions, type ListWorkflowsOptions, type ListWorkspacesOptions, type LoadSeedContextOptions, type LoadTailorDBNamespacesOptions, type LoadedConfig, type LoadedTailorDBNamespaces, MIGRATE_FILE_NAME, MIGRATION_LABEL_KEY, type MachineUserInfo, type MachineUserName, type MachineUserTokenInfo, type GenerateOptions$1 as MigrateGenerateOptions, type MigrationBundleResult, type MigrationDiff, type NamespaceWithMigrations, type NormalizedSchemaSnapshot, type OAuth2ClientCredentials, type OAuth2ClientInfo, type OperatorClient, type OperatorFieldConfig, type OrganizationInfo, type OrganizationTreeOptions, type ParsedField, type Plugin, type PluginAttachment, type PluginGeneratedTypeSource, type RemoveOptions, type RemoveUserOptions, type Resolver, type RestoreWorkspaceOptions, type ResumeWorkflowOptions, type ResumeWorkflowResultWithWait, SCHEMA_FILE_NAME, type SchemaSnapshot, type ScriptExecutionOptions, type ScriptExecutionResult, type ScriptInvoker, type SeedBundleResult, type SeedChunk, type SeedContext, type SeedData, type SeedIdpUserContext, type SeedNamespaceConfig, type ShowInfo, type ShowOptions, type SnapshotFieldConfig, type StartWorkflowResultWithWait, type StartWorkflowTypedOptions, type DeployResult as StaticWebsiteDeployResult, type TailorDBNamespaceData, type TailorDBNamespaceSelector, type TailorDBSnapshotType, type TailorDBType, type TriggerExecutorResult, type TriggerExecutorTypedOptions, type TruncateOptions, type TypeSourceInfoEntry, type UpdateFolderOptions, type UpdateOrganizationOptions, type UpdateUserOptions, type UserInfo, type UserOrganizationInfo, type WaitOptions, type WaitWorkflowExecutionOptions, type WatchExecutorJobResult, type WatchExecutorJobTypedOptions, type WebhookExecutorInfo, type WorkflowExecutionInfo, type WorkflowExecutionWaitInfo, type WorkflowInfo, type WorkflowJobExecutionInfo, type WorkflowListInfo, type WorkflowWaitOutput, type WorkflowWaitResult, type WorkspaceDetails, type WorkspaceInfo, apiCall, deploy as apply, assertWritable, bundleMigrationScript, bundleSeedScript, chunkSeedData, compareLocalTypesWithSnapshot, compareSnapshots, createFolder, createSnapshotFromLocalTypes, createWorkspace, deleteFolder, deleteWorkspace, deploy, deployStaticWebsite, errorToJson, executeScript, formatDiffSummary, formatMigrationDiff, generate, generateUserTypes, getAppHealth, getExecutor, getExecutorJob, getExecutorWaitFailureMessage, getFolder, getFunctionRegistry, getLatestMigrationNumber, getMachineUserToken, getMigrationDirPath, getMigrationFilePath, getMigrationFiles, getNamespacesWithMigrations, getNextMigrationNumber, getOAuth2Client, getOrganization, getWorkflow, getWorkflowExecution, getWorkspace, hasChanges, initOperatorClient, inviteUser, isPluginGeneratedType, listApps, listExecutorJobs, listExecutors, listFolders, listFunctionRegistries, listMachineUsers, listOAuth2Clients, listOrganizations, listUsers, listWebhookExecutors, listWorkflowExecutions, listWorkflows, listWorkspaces, loadAccessToken, loadConfig, loadSeedContext, loadTailorDBNamespaces, loadWorkspaceId, generate$1 as migrateGenerate, organizationTree, query, reconstructSnapshotFromMigrations, remove, removeUser, restoreWorkspace, resumeWorkflow, serializeError, show, startWorkflow, triggerExecutor, truncate, updateFolder, updateOrganization, updateUser, waitForExecution, waitWorkflowExecution, watchExecutorJob };
package/dist/cli/lib.mjs CHANGED
@@ -1,12 +1,9 @@
1
1
  import { t as assertDefined } from "../assert-DBxo8jPo.mjs";
2
- import { $ as updateFolder, $t as bundleMigrationScript, A as generate$1, At as listExecutorJobs, C as waitWorkflowExecution, D as listWorkflows, Dn as hasChanges, Dt as getExecutorJob, En as formatMigrationDiff, Et as listExecutors, Fn as assertWritable, Ft as getWorkflow, G as updateOrganization, Gt as listWorkspaces, H as remove, Ht as deploy, In as loadConfig, K as organizationTree, L as deployStaticWebsite, Lt as getWorkflowExecution, Mn as generateUserTypes, Nt as startWorkflow, O as truncate, On as getNamespacesWithMigrations, Ot as getExecutorWaitFailureMessage, Pn as apiCall, Qt as waitForExecution, R as show, Rt as listWorkflowExecutions, Sn as reconstructSnapshotFromMigrations, T as resumeWorkflow, Tn as formatDiffSummary, Vn as loadAccessToken, Vt as getExecutor, Y as listOrganizations, Z as getOrganization, Zt as executeScript, _ as deleteWorkspace, _n as getMigrationFilePath, a as updateUser, at as deleteFolder, b as getAppHealth, bt as getFunctionRegistry, cn as INITIAL_SCHEMA_NUMBER, d as inviteUser, dt as getOAuth2Client, en as MIGRATION_LABEL_KEY, fn as compareLocalTypesWithSnapshot, ft as getMachineUserToken, gn as getMigrationDirPath, gt as generate, h as getWorkspace, hn as getLatestMigrationNumber, ht as listMachineUsers, jn as PluginManager, jt as watchExecutorJob, l as listUsers, ln as MIGRATE_FILE_NAME, lt as listOAuth2Clients, mn as createSnapshotFromLocalTypes, n as query, on as DB_TYPES_FILE_NAME, p as restoreWorkspace, pn as compareSnapshots, qn as loadWorkspaceId, qt as createWorkspace, rt as getFolder, s as removeUser, sn as DIFF_FILE_NAME, st as createFolder, t as registerTsHook, tt as listFolders, un as SCHEMA_FILE_NAME, v as listApps, vn as getMigrationFiles, vt as listFunctionRegistries, wt as triggerExecutor, xt as listWebhookExecutors, yn as getNextMigrationNumber } from "../register-ts-hook-DvEs6YsL.mjs";
3
- import { B as initOperatorClient, _ as platformBundleDefinePlugin, t as defineApplication, w as getDistDir } from "../application-GzW98_Xr.mjs";
2
+ import { $ as getOrganization, A as truncate, At as getExecutorJob, B as show, Bt as getWorkflowExecution, Cn as createSnapshotFromLocalTypes, Ct as getFunctionRegistry, D as resumeWorkflow, Dn as getMigrationFilePath, Dt as triggerExecutor, En as getMigrationDirPath, Fn as formatMigrationDiff, Gn as generateUserTypes, Gt as deploy, In as hasChanges, It as startWorkflow, J as organizationTree, Jn as assertWritable, Jt as listWorkspaces, Ln as getNamespacesWithMigrations, M as generate$1, Nt as listExecutorJobs, On as getMigrationFiles, Pn as formatDiffSummary, Pt as watchExecutorJob, Rt as getWorkflow, S as getAppHealth, Sn as compareSnapshots, T as waitWorkflowExecution, Tn as getLatestMigrationNumber, Vt as listWorkflowExecutions, W as remove, Wn as PluginManager, Wt as getExecutor, Xt as createWorkspace, Yn as loadConfig, Z as listOrganizations, _ as getWorkspace, _n as MIGRATE_FILE_NAME, _t as listMachineUsers, at as getFolder, b as listApps, d as listUsers, dt as listOAuth2Clients, en as executeScript, er as loadAccessToken, gn as INITIAL_SCHEMA_NUMBER, h as restoreWorkspace, hn as DIFF_FILE_NAME, i as query, jn as reconstructSnapshotFromMigrations, jt as getExecutorWaitFailureMessage, k as listWorkflows, kn as getNextMigrationNumber, kt as listExecutors, l as removeUser, lt as createFolder, mn as DB_TYPES_FILE_NAME, mt as getMachineUserToken, n as errorToJson, nn as bundleMigrationScript, or as loadWorkspaceId, p as inviteUser, pt as getOAuth2Client, q as updateOrganization, qn as apiCall, r as serializeError, rt as listFolders, s as updateUser, sn as MIGRATION_LABEL_KEY, st as deleteFolder, t as registerTsHook, tn as waitForExecution, tt as updateFolder, vn as SCHEMA_FILE_NAME, vt as generate, wt as listWebhookExecutors, xn as compareLocalTypesWithSnapshot, xt as listFunctionRegistries, y as deleteWorkspace, yt as getAuthInput, z as deployStaticWebsite } from "../register-ts-hook-LYV7zH-e.mjs";
3
+ import { G as initOperatorClient, T as createBundleLog, h as assertUniqueLocalTailorDBTypeNames, k as getDistDir, t as defineApplication, v as createGeneratedEntryResolverPlugin, x as platformBundleDefinePlugin, y as createTsconfigPathsPlugin } from "../application-CM6hKnSK.mjs";
4
4
  import { t as multiline } from "../multiline-sfHpTZZK.mjs";
5
5
  import { t as isPluginGeneratedType } from "../type-source-DH_LH20p.mjs";
6
- import { n as kyselyTypePlugin } from "../kysely-type-DqIRgDYR.mjs";
7
- import { n as enumConstantsPlugin } from "../enum-constants-j9QBF0cB.mjs";
8
- import { n as fileUtilsPlugin } from "../file-utils-yEiIS4nJ.mjs";
9
- import { n as seedPlugin } from "../seed-CRSQJI_z.mjs";
6
+ import { a as generateIdpTruncateScriptCode, i as generateIdpSeedScriptCode, o as processIdpUser, r as processLinesDb, t as SeedGeneratorID } from "../seed-B-yckgQY.mjs";
10
7
  import * as path from "pathe";
11
8
  import { resolveTSConfig } from "pkg-types";
12
9
  import * as fs from "node:fs";
@@ -14,13 +11,12 @@ import * as rolldown from "rolldown";
14
11
 
15
12
  //#region src/cli/shared/tailordb-namespaces.ts
16
13
  /**
17
- * Load local TailorDB namespaces exactly as SDK generation/deploy sees them:
18
- * the config is loaded, user types are generated, and each selected
19
- * namespace's types are loaded with namespace plugins applied.
14
+ * Load local TailorDB namespaces along with the config plugins and the
15
+ * defined application. Internal superset of {@link loadTailorDBNamespaces}.
20
16
  * @param options - Namespace loading options.
21
- * @returns The loaded config and TailorDB namespace data.
17
+ * @returns The loaded config, plugins, application, and TailorDB namespace data.
22
18
  */
23
- async function loadTailorDBNamespaces(options = {}) {
19
+ async function loadApplicationNamespaces(options = {}) {
24
20
  const { config, plugins } = await loadConfig(options.configPath);
25
21
  await generateUserTypes({
26
22
  config,
@@ -30,7 +26,7 @@ async function loadTailorDBNamespaces(options = {}) {
30
26
  config,
31
27
  pluginManager: plugins.length > 0 ? new PluginManager(plugins) : void 0
32
28
  });
33
- const namespaceNames = typeof options.namespaces === "function" ? options.namespaces(config) : options.namespaces;
29
+ const namespaceNames = typeof options.namespaces === "function" ? options.namespaces(config, plugins) : options.namespaces;
34
30
  const namespaceFilter = namespaceNames ? new Set(namespaceNames) : void 0;
35
31
  const services = namespaceFilter ? application.tailorDBServices.filter((db) => namespaceFilter.has(db.namespace)) : application.tailorDBServices;
36
32
  if (namespaceFilter && services.length !== namespaceFilter.size) {
@@ -52,10 +48,115 @@ async function loadTailorDBNamespaces(options = {}) {
52
48
  }
53
49
  return {
54
50
  config,
51
+ plugins,
52
+ application,
53
+ namespaces
54
+ };
55
+ }
56
+ /**
57
+ * Load local TailorDB namespaces exactly as SDK generation/deploy sees them:
58
+ * the config is loaded, user types are generated, and each selected
59
+ * namespace's types are loaded with namespace plugins applied.
60
+ * @param options - Namespace loading options.
61
+ * @returns The loaded config and TailorDB namespace data.
62
+ */
63
+ async function loadTailorDBNamespaces(options = {}) {
64
+ const { config, plugins, namespaces } = await loadApplicationNamespaces(options);
65
+ return {
66
+ config,
67
+ plugins,
55
68
  namespaces
56
69
  };
57
70
  }
58
71
 
72
+ //#endregion
73
+ //#region src/plugin/builtin/seed/seed-type-processor.ts
74
+ /**
75
+ * Processes TailorDB types to extract seed type information
76
+ * @param type - Parsed TailorDB type
77
+ * @param namespace - Namespace of the type
78
+ * @returns Seed type information
79
+ */
80
+ function processSeedTypeInfo(type, namespace) {
81
+ const dependencies = /* @__PURE__ */ new Set();
82
+ const selfRefFields = [];
83
+ for (const [fieldName, field] of Object.entries(type.fields)) {
84
+ const targetType = field.relation?.targetType ?? field.config.foreignKeyType;
85
+ if (!targetType) continue;
86
+ if (targetType === type.name) selfRefFields.push(fieldName);
87
+ else dependencies.add(targetType);
88
+ }
89
+ return {
90
+ name: type.name,
91
+ namespace,
92
+ dependencies: Array.from(dependencies),
93
+ selfRefFields,
94
+ dataFile: `data/${type.name}.jsonl`
95
+ };
96
+ }
97
+ /**
98
+ * Build per-namespace seed ordering information from TailorDB namespace data.
99
+ * @param tailordb - TailorDB namespaces with their types
100
+ * @returns Seed namespace configs, in namespace order
101
+ */
102
+ function buildSeedNamespaceConfigs(tailordb) {
103
+ return tailordb.map((ns) => {
104
+ const types = [];
105
+ const dependencies = {};
106
+ const selfRefTypes = [];
107
+ const requiredFields = {};
108
+ for (const [typeName, type] of Object.entries(ns.types)) {
109
+ const typeInfo = processSeedTypeInfo(type, ns.namespace);
110
+ types.push(typeInfo.name);
111
+ dependencies[typeInfo.name] = typeInfo.dependencies;
112
+ if (typeInfo.selfRefFields.length > 0) selfRefTypes.push(typeInfo.name);
113
+ const linesDb = processLinesDb(type, assertDefined(ns.sourceInfo.get(typeName), `source info missing for type: ${typeName}`));
114
+ requiredFields[typeInfo.name] = Object.entries(type.fields).filter(([fieldName, field]) => field.config.required !== false && !linesDb.optionalFields.includes(fieldName) && !linesDb.omitFields.includes(fieldName)).map(([fieldName]) => fieldName);
115
+ }
116
+ return {
117
+ namespace: ns.namespace,
118
+ types,
119
+ dependencies,
120
+ selfRefTypes,
121
+ requiredFields
122
+ };
123
+ });
124
+ }
125
+
126
+ //#endregion
127
+ //#region src/cli/shared/seed-context.ts
128
+ /**
129
+ * Load the seed context from the local config. Requires `seedPlugin` to be
130
+ * configured in the config's plugins. A relative `distPath` in the seedPlugin
131
+ * options is resolved against the current working directory — the same base
132
+ * `tailor generate` writes it to.
133
+ * @param options - Seed context loading options.
134
+ * @returns The seed context computed from the local config.
135
+ */
136
+ async function loadSeedContext(options = {}) {
137
+ const { config, plugins, application, namespaces } = await loadApplicationNamespaces({ configPath: options.configPath });
138
+ assertUniqueLocalTailorDBTypeNames({ tailorDBServices: application.tailorDBServices });
139
+ const seedPlugin = plugins.find((plugin) => plugin.id === SeedGeneratorID);
140
+ if (!seedPlugin) throw new Error(`seedPlugin is not configured in ${config.path}. Add seedPlugin({ distPath: "./seed" }) from "@tailor-platform/sdk/plugin/seed" to definePlugins().`);
141
+ const pluginOptions = seedPlugin.pluginConfig;
142
+ if (typeof pluginOptions?.distPath !== "string" || pluginOptions.distPath === "") throw new Error(`seedPlugin in ${config.path} has no distPath option. Pass seedPlugin({ distPath: "./seed" }) so seed data has a location.`);
143
+ await application.authService?.resolveNamespaces();
144
+ const authInput = getAuthInput(application);
145
+ const idpUserMeta = authInput ? processIdpUser(authInput) : void 0;
146
+ const idpUser = idpUserMeta ? {
147
+ idpNamespace: idpUserMeta.idpNamespace,
148
+ seedScriptCode: generateIdpSeedScriptCode(idpUserMeta.idpNamespace),
149
+ truncateScriptCode: generateIdpTruncateScriptCode(idpUserMeta.idpNamespace)
150
+ } : null;
151
+ return {
152
+ config,
153
+ distPath: path.resolve(pluginOptions.distPath),
154
+ machineUserName: pluginOptions.machineUserName,
155
+ namespaces: buildSeedNamespaceConfigs(namespaces),
156
+ idpUser
157
+ };
158
+ }
159
+
59
160
  //#endregion
60
161
  //#region src/cli/shared/seed-chunker.ts
61
162
  /**
@@ -210,11 +311,12 @@ function generateSeedScriptContent(namespace) {
210
311
  data: Record<string, Record<string, unknown>[]>;
211
312
  order: string[];
212
313
  selfRefTypes: string[];
314
+ upsert?: boolean;
213
315
  };
214
316
 
215
317
  type SeedResult = {
216
318
  success: boolean;
217
- processed: Record<string, number>;
319
+ processed: Record<string, { inserted: number; updated: number; skipped: number }>;
218
320
  errors: string[];
219
321
  };
220
322
 
@@ -227,9 +329,13 @@ function generateSeedScriptContent(namespace) {
227
329
 
228
330
  export async function main(input: SeedInput): Promise<SeedResult> {
229
331
  const db = getDB("${namespace}");
230
- const processed: Record<string, number> = {};
332
+ const processed: Record<
333
+ string,
334
+ { inserted: number; updated: number; skipped: number }
335
+ > = {};
231
336
  const errors: string[] = [];
232
337
  const BATCH_SIZE = ${String(BATCH_SIZE)};
338
+ const upsert = input.upsert === true;
233
339
 
234
340
  for (const typeName of input.order) {
235
341
  const records = input.data[typeName];
@@ -238,25 +344,68 @@ function generateSeedScriptContent(namespace) {
238
344
  continue;
239
345
  }
240
346
 
241
- processed[typeName] = 0;
347
+ processed[typeName] = { inserted: 0, updated: 0, skipped: 0 };
242
348
  const hasSelfRef = (input.selfRefTypes || []).includes(typeName);
243
349
 
244
350
  try {
351
+ let recordsToInsert = records;
352
+ let recordsToUpdate: Record<string, unknown>[] = [];
353
+ if (upsert) {
354
+ const existing = await db
355
+ .selectFrom(typeName)
356
+ .select("id")
357
+ .where(
358
+ "id",
359
+ "in",
360
+ records.map((record) => record.id),
361
+ )
362
+ .execute();
363
+ const existingIds = new Set(existing.map((record) => record.id));
364
+ recordsToInsert = records.filter((record) => !existingIds.has(record.id));
365
+ recordsToUpdate = records.filter((record) => existingIds.has(record.id));
366
+ }
367
+
245
368
  if (hasSelfRef) {
246
369
  // Insert one-by-one to respect self-referencing foreign key order
247
- for (const record of records) {
370
+ for (const record of recordsToInsert) {
248
371
  await db.insertInto(typeName).values(record).execute();
249
- processed[typeName] += 1;
372
+ processed[typeName].inserted += 1;
373
+ }
374
+ if (!upsert) {
375
+ console.log(
376
+ \`[${namespace}] \${typeName}: \${processed[typeName].inserted}/\${records.length} (one-by-one)\`,
377
+ );
250
378
  }
251
- console.log(\`[${namespace}] \${typeName}: \${processed[typeName]}/\${records.length} (one-by-one)\`);
252
379
  } else {
253
- for (let i = 0; i < records.length; i += BATCH_SIZE) {
254
- const batch = records.slice(i, i + BATCH_SIZE);
380
+ for (let i = 0; i < recordsToInsert.length; i += BATCH_SIZE) {
381
+ const batch = recordsToInsert.slice(i, i + BATCH_SIZE);
255
382
  await db.insertInto(typeName).values(batch).execute();
256
- processed[typeName] += batch.length;
257
- console.log(\`[${namespace}] \${typeName}: \${processed[typeName]}/\${records.length}\`);
383
+ processed[typeName].inserted += batch.length;
384
+ if (!upsert) {
385
+ console.log(
386
+ \`[${namespace}] \${typeName}: \${processed[typeName].inserted}/\${records.length}\`,
387
+ );
388
+ }
258
389
  }
259
390
  }
391
+
392
+ for (const record of recordsToUpdate) {
393
+ const { id, ...values } = record;
394
+ if (Object.keys(values).length === 0) {
395
+ processed[typeName].skipped += 1;
396
+ continue;
397
+ }
398
+ await db.updateTable(typeName).set(values).where("id", "=", id).execute();
399
+ processed[typeName].updated += 1;
400
+ }
401
+
402
+ const counts = processed[typeName];
403
+ if (upsert) {
404
+ const skipped = counts.skipped > 0 ? \`, \${counts.skipped} skipped\` : "";
405
+ console.log(
406
+ \`[${namespace}] \${typeName}: \${counts.inserted} inserted, \${counts.updated} updated\${skipped}\`,
407
+ );
408
+ }
260
409
  } catch (error) {
261
410
  const message = error instanceof Error ? error.message : String(error);
262
411
  errors.push(\`\${typeName}: \${message}\`);
@@ -282,9 +431,10 @@ function generateSeedScriptContent(namespace) {
282
431
  * 4. Exports as main() for TestExecScript
283
432
  * @param namespace - TailorDB namespace
284
433
  * @param typeNames - List of type names to include in the seed
434
+ * @param baseDir - Directory whose dependencies and tsconfig the generated entry uses
285
435
  * @returns Bundled seed script result
286
436
  */
287
- async function bundleSeedScript(namespace, typeNames) {
437
+ async function bundleSeedScript(namespace, typeNames, baseDir = process.cwd()) {
288
438
  const outputDir = path.resolve(getDistDir(), "seed");
289
439
  fs.mkdirSync(outputDir, { recursive: true });
290
440
  const entryPath = path.join(outputDir, `seed_${namespace}.entry.ts`);
@@ -292,33 +442,40 @@ async function bundleSeedScript(namespace, typeNames) {
292
442
  fs.writeFileSync(entryPath, entryContent);
293
443
  let tsconfig;
294
444
  try {
295
- tsconfig = await resolveTSConfig();
445
+ tsconfig = await resolveTSConfig(baseDir);
296
446
  } catch {
297
447
  tsconfig = void 0;
298
448
  }
449
+ const bundleLog = createBundleLog({ tsconfig });
450
+ const result = await rolldown.build({
451
+ plugins: [
452
+ createGeneratedEntryResolverPlugin(entryPath, baseDir),
453
+ createTsconfigPathsPlugin(),
454
+ platformBundleDefinePlugin
455
+ ],
456
+ input: entryPath,
457
+ write: false,
458
+ output: {
459
+ format: "esm",
460
+ sourcemap: false,
461
+ minify: false,
462
+ codeSplitting: false,
463
+ globals: { tailordb: "tailordb" }
464
+ },
465
+ external: ["tailordb"],
466
+ resolve: { conditionNames: ["node", "import"] },
467
+ tsconfig,
468
+ treeshake: {
469
+ moduleSideEffects: false,
470
+ annotations: true,
471
+ unknownGlobalSideEffects: false
472
+ },
473
+ ...bundleLog.options
474
+ });
475
+ bundleLog.assertAllResolved();
299
476
  return {
300
477
  namespace,
301
- bundledCode: (await rolldown.build({
302
- plugins: [platformBundleDefinePlugin],
303
- input: entryPath,
304
- write: false,
305
- output: {
306
- format: "esm",
307
- sourcemap: false,
308
- minify: false,
309
- codeSplitting: false,
310
- globals: { tailordb: "tailordb" }
311
- },
312
- external: ["tailordb"],
313
- resolve: { conditionNames: ["node", "import"] },
314
- tsconfig,
315
- treeshake: {
316
- moduleSideEffects: false,
317
- annotations: true,
318
- unknownGlobalSideEffects: false
319
- },
320
- logLevel: "silent"
321
- })).output[0].code,
478
+ bundledCode: result.output[0].code,
322
479
  typesIncluded: typeNames
323
480
  };
324
481
  }
@@ -328,5 +485,5 @@ async function bundleSeedScript(namespace, typeNames) {
328
485
  await registerTsHook(new URL("./ts-hook.mjs", import.meta.url));
329
486
 
330
487
  //#endregion
331
- export { DB_TYPES_FILE_NAME, DIFF_FILE_NAME, INITIAL_SCHEMA_NUMBER, MIGRATE_FILE_NAME, MIGRATION_LABEL_KEY, SCHEMA_FILE_NAME, apiCall, deploy as apply, deploy, assertWritable, bundleMigrationScript, bundleSeedScript, chunkSeedData, compareLocalTypesWithSnapshot, compareSnapshots, createFolder, createSnapshotFromLocalTypes, createWorkspace, deleteFolder, deleteWorkspace, deployStaticWebsite, enumConstantsPlugin, executeScript, fileUtilsPlugin, formatDiffSummary, formatMigrationDiff, generate, generateUserTypes, getAppHealth, getExecutor, getExecutorJob, getExecutorWaitFailureMessage, getFolder, getFunctionRegistry, getLatestMigrationNumber, getMachineUserToken, getMigrationDirPath, getMigrationFilePath, getMigrationFiles, getNamespacesWithMigrations, getNextMigrationNumber, getOAuth2Client, getOrganization, getWorkflow, getWorkflowExecution, getWorkspace, hasChanges, initOperatorClient, inviteUser, isPluginGeneratedType, kyselyTypePlugin, listApps, listExecutorJobs, listExecutors, listFolders, listFunctionRegistries, listMachineUsers, listOAuth2Clients, listOrganizations, listUsers, listWebhookExecutors, listWorkflowExecutions, listWorkflows, listWorkspaces, loadAccessToken, loadConfig, loadTailorDBNamespaces, loadWorkspaceId, generate$1 as migrateGenerate, organizationTree, query, reconstructSnapshotFromMigrations, remove, removeUser, restoreWorkspace, resumeWorkflow, seedPlugin, show, startWorkflow, triggerExecutor, truncate, updateFolder, updateOrganization, updateUser, waitForExecution, waitWorkflowExecution, watchExecutorJob };
488
+ export { DB_TYPES_FILE_NAME, DIFF_FILE_NAME, INITIAL_SCHEMA_NUMBER, MIGRATE_FILE_NAME, MIGRATION_LABEL_KEY, SCHEMA_FILE_NAME, apiCall, deploy as apply, deploy, assertWritable, bundleMigrationScript, bundleSeedScript, chunkSeedData, compareLocalTypesWithSnapshot, compareSnapshots, createFolder, createSnapshotFromLocalTypes, createWorkspace, deleteFolder, deleteWorkspace, deployStaticWebsite, errorToJson, executeScript, formatDiffSummary, formatMigrationDiff, generate, generateUserTypes, getAppHealth, getExecutor, getExecutorJob, getExecutorWaitFailureMessage, getFolder, getFunctionRegistry, getLatestMigrationNumber, getMachineUserToken, getMigrationDirPath, getMigrationFilePath, getMigrationFiles, getNamespacesWithMigrations, getNextMigrationNumber, getOAuth2Client, getOrganization, getWorkflow, getWorkflowExecution, getWorkspace, hasChanges, initOperatorClient, inviteUser, isPluginGeneratedType, listApps, listExecutorJobs, listExecutors, listFolders, listFunctionRegistries, listMachineUsers, listOAuth2Clients, listOrganizations, listUsers, listWebhookExecutors, listWorkflowExecutions, listWorkflows, listWorkspaces, loadAccessToken, loadConfig, loadSeedContext, loadTailorDBNamespaces, loadWorkspaceId, generate$1 as migrateGenerate, organizationTree, query, reconstructSnapshotFromMigrations, remove, removeUser, restoreWorkspace, resumeWorkflow, serializeError, show, startWorkflow, triggerExecutor, truncate, updateFolder, updateOrganization, updateUser, waitForExecution, waitWorkflowExecution, watchExecutorJob };
332
489
  //# sourceMappingURL=lib.mjs.map