@tailor-platform/sdk 1.14.0 → 1.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +19 -0
- package/dist/application-BznueWxG.mjs +4 -0
- package/dist/{application-DnWZVbDO.mjs → application-DhwHYQ3H.mjs} +95 -44
- package/dist/application-DhwHYQ3H.mjs.map +1 -0
- package/dist/cli/index.mjs +4 -4
- package/dist/cli/lib.d.mts +13 -49
- package/dist/cli/lib.mjs +4 -4
- package/dist/cli/skills.d.mts +2 -0
- package/dist/cli/skills.mjs +51 -0
- package/dist/cli/skills.mjs.map +1 -0
- package/dist/configure/index.d.mts +4 -4
- package/dist/configure/index.mjs +2 -2
- package/dist/configure/index.mjs.map +1 -1
- package/dist/index-YzESrtj0.d.mts +396 -0
- package/dist/{index-DMoFYBhB.d.mts → index-q3n7wQOs.d.mts} +13 -12
- package/dist/{jiti-DuCiUfMj.mjs → jiti-BrELlEYT.mjs} +2 -2
- package/dist/{jiti-DuCiUfMj.mjs.map → jiti-BrELlEYT.mjs.map} +1 -1
- package/dist/{job-zGAXCidt.mjs → job-XiwGyFJt.mjs} +1 -1
- package/dist/{job-zGAXCidt.mjs.map → job-XiwGyFJt.mjs.map} +1 -1
- package/dist/plugin/index.d.mts +16 -2
- package/dist/plugin/index.mjs +208 -1
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/{schema-BmKdDzr1.mjs → schema-DRYB-nzA.mjs} +1 -1
- package/dist/{schema-BmKdDzr1.mjs.map → schema-DRYB-nzA.mjs.map} +1 -1
- package/dist/{src-QNTCsO6J.mjs → src-DMROgdcL.mjs} +2 -2
- package/dist/{src-QNTCsO6J.mjs.map → src-DMROgdcL.mjs.map} +1 -1
- package/dist/{index-Bw_huFr7.d.mts → types-DbvONSS-.d.mts} +576 -460
- package/dist/{types-r-ZratAg.mjs → types-b-ig8nW_.mjs} +1 -1
- package/dist/types-b-ig8nW_.mjs.map +1 -0
- package/dist/{update-BnKKm4aR.mjs → update-Dm8ERWHJ.mjs} +312 -151
- package/dist/update-Dm8ERWHJ.mjs.map +1 -0
- package/dist/utils/test/index.d.mts +3 -3
- package/dist/utils/test/index.mjs +1 -1
- package/docs/plugin/custom.md +105 -49
- package/docs/plugin/index.md +2 -2
- package/package.json +5 -3
- package/skills/tailor-sdk/SKILL.md +34 -0
- package/dist/application-DM4zTgXU.mjs +0 -4
- package/dist/application-DnWZVbDO.mjs.map +0 -1
- package/dist/env-4RO7szrH.d.mts +0 -66
- package/dist/types-r-ZratAg.mjs.map +0 -1
- package/dist/update-BnKKm4aR.mjs.map +0 -1
- /package/dist/{chunk-C3Kl5s5P.mjs → chunk-GMkBE123.mjs} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-
|
|
1
|
+
{"version":3,"file":"job-XiwGyFJt.mjs","names":[],"sources":["../src/configure/services/workflow/job.ts"],"sourcesContent":["import type { TailorEnv } from \"@/configure/types/env\";\nimport type { JsonCompatible } from \"@/configure/types/helpers\";\nimport type { Jsonifiable, Jsonify, JsonPrimitive } from \"type-fest\";\n\n/**\n * Context object passed as the second argument to workflow job body functions.\n */\nexport type WorkflowJobContext = {\n env: TailorEnv;\n};\n\n/**\n * Allowed output types for workflow job body functions.\n * Includes Jsonifiable (JSON-serializable values including objects with toJSON like Date),\n * undefined, and void.\n */\nexport type WorkflowJobOutput = Jsonifiable | undefined | void;\n\n/**\n * Convert output type to what trigger returns after JSON serialization.\n * - Jsonifiable values are converted via Jsonify (Date -> string, etc.)\n * - undefined remains undefined\n * - void becomes void\n */\ntype JsonifyOutput<T> = T extends Jsonifiable ? Jsonify<T> : T;\n\n/**\n * Input type constraint for workflow jobs.\n * Accepts any type that is JSON-compatible (primitives, arrays, objects with JSON-compatible values).\n * Excludes objects with toJSON method (like Date) since they won't be serialized in input.\n */\nexport type WorkflowJobInput = undefined | JsonCompatible<unknown>;\n\n/**\n * WorkflowJob represents a job that can be triggered in a workflow.\n *\n * Type constraints:\n * - Input: Must be JSON-compatible (no Date/toJSON objects) or undefined. Interfaces are allowed.\n * - Output: Must be Jsonifiable, undefined, or void\n * - Trigger returns Jsonify<Output> (Date becomes string after JSON.stringify)\n */\nexport interface WorkflowJob<Name extends string = string, Input = undefined, Output = undefined> {\n name: Name;\n /**\n * Trigger this job with the given input.\n * At runtime, this is a placeholder that calls the body function.\n * During bundling, calls to .trigger() are transformed to\n * tailor.workflow.triggerJobFunction(\"<job-name>\", args).\n *\n * Returns Jsonify<Output> because the value passes through JSON.stringify.\n */\n trigger: [Input] extends [undefined]\n ? () => Promise<JsonifyOutput<Awaited<Output>>>\n : (input: Input) => Promise<JsonifyOutput<Awaited<Output>>>;\n body: (input: Input, context: WorkflowJobContext) => Output | Promise<Output>;\n}\n\n/**\n * Helper type to check if all property types are valid.\n * Uses -? to remove optional modifiers so all properties are treated uniformly.\n */\ntype AllPropertiesValid<T> = {\n [K in keyof T]-?: IsValidInput<T[K]> extends true ? true : false;\n}[keyof T] extends true\n ? true\n : false;\n\n/**\n * Check if a type contains any non-JSON-compatible values.\n * Returns `true` if the type is valid for input, `false` otherwise.\n *\n * Accepts:\n * - JSON primitives (string, number, boolean, null)\n * - undefined\n * - Optional primitives (e.g., string | undefined)\n * - Arrays of valid types\n * - Objects with valid field types\n *\n * Rejects:\n * - Objects with toJSON methods (like Date)\n * - Other non-JSON-serializable types\n */\ntype IsValidInput<T> = T extends undefined\n ? true\n : T extends JsonPrimitive\n ? true\n : T extends readonly (infer U)[]\n ? IsValidInput<U>\n : T extends object\n ? T extends { toJSON: () => unknown }\n ? false\n : AllPropertiesValid<T>\n : false;\n\n/**\n * Helper type to check if all property types are valid for output.\n * Uses -? to remove optional modifiers so all properties are treated uniformly.\n */\ntype AllPropertiesValidOutput<T> = {\n [K in keyof T]-?: IsValidOutput<T[K]> extends true ? true : false;\n}[keyof T] extends true\n ? true\n : false;\n\n/**\n * Check if a type is valid for output.\n * Returns `true` if the type is valid, `false` otherwise.\n *\n * Accepts:\n * - JSON primitives (string, number, boolean, null)\n * - undefined and void\n * - Optional primitives (e.g., string | undefined)\n * - Jsonifiable types (Date, objects with toJSON)\n * - Arrays of valid types\n * - Objects with valid field types\n */\ntype IsValidOutput<T> = T extends undefined | void\n ? true\n : T extends JsonPrimitive\n ? true\n : T extends readonly (infer U)[]\n ? IsValidOutput<U>\n : T extends object\n ? AllPropertiesValidOutput<T>\n : false;\n\n/**\n * Body function type with conditional constraint.\n * If input contains invalid types (like Date), the body type becomes `never` to cause an error.\n */\ntype WorkflowJobBody<I, O> =\n IsValidInput<I> extends true\n ? IsValidOutput<O> extends true\n ? (input: I, context: WorkflowJobContext) => O | Promise<O>\n : never\n : never;\n\n/**\n * Environment variable key for workflow testing.\n * Contains JSON-serialized TailorEnv object.\n */\nexport const WORKFLOW_TEST_ENV_KEY = \"TAILOR_TEST_WORKFLOW_ENV\";\n\nexport const createWorkflowJob = <const Name extends string, I = undefined, O = undefined>(config: {\n readonly name: Name;\n readonly body: WorkflowJobBody<I, O>;\n}): WorkflowJob<Name, I, Awaited<O>> => {\n return {\n name: config.name,\n // JSON.parse(JSON.stringify(...)) ensures the return value matches Jsonify<Output> type.\n // This converts Date objects to strings, matching actual runtime behavior.\n // In production, bundler transforms .trigger() calls to tailor.workflow.triggerJobFunction().\n trigger: async (args?: unknown) => {\n const env: TailorEnv = JSON.parse(process.env[WORKFLOW_TEST_ENV_KEY] || \"{}\");\n const result = await config.body(args as I, { env });\n return result ? JSON.parse(JSON.stringify(result)) : result;\n },\n body: config.body,\n } as WorkflowJob<Name, I, Awaited<O>>;\n};\n"],"mappings":";;;;;AA6IA,MAAa,wBAAwB;AAErC,MAAa,qBAA8E,WAGnD;AACtC,QAAO;EACL,MAAM,OAAO;EAIb,SAAS,OAAO,SAAmB;GACjC,MAAM,MAAiB,KAAK,MAAM,QAAQ,IAAI,0BAA0B,KAAK;GAC7E,MAAM,SAAS,MAAM,OAAO,KAAK,MAAW,EAAE,KAAK,CAAC;AACpD,UAAO,SAAS,KAAK,MAAM,KAAK,UAAU,OAAO,CAAC,GAAG;;EAEvD,MAAM,OAAO;EACd"}
|
package/dist/plugin/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="./../user-defined.d.ts" />
|
|
2
|
-
import {
|
|
2
|
+
import { _t as TailorEnv, k as TailorAnyDBType, vt as TailorActor } from "../types-DbvONSS-.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin/with-context.d.ts
|
|
5
5
|
|
|
@@ -101,5 +101,19 @@ type PluginRecord = {
|
|
|
101
101
|
*/
|
|
102
102
|
declare function withPluginContext<Ctx>(factory: PluginExecutorFactory<Ctx>): PluginExecutorFactory<Ctx>;
|
|
103
103
|
//#endregion
|
|
104
|
-
|
|
104
|
+
//#region src/plugin/get-generated-type.d.ts
|
|
105
|
+
/**
|
|
106
|
+
* Get a generated type from a plugin by loading the config and resolving everything automatically.
|
|
107
|
+
* For type-attached plugins, calls processType() with the sourceType.
|
|
108
|
+
* For namespace plugins, calls processNamespace() with auto-resolved namespace.
|
|
109
|
+
* Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.
|
|
110
|
+
* @param configPath - Path to tailor.config.ts (absolute or relative to cwd)
|
|
111
|
+
* @param pluginId - The plugin's unique identifier
|
|
112
|
+
* @param sourceType - The source TailorDB type (null for namespace plugins)
|
|
113
|
+
* @param kind - The generated type kind (e.g., "request", "step")
|
|
114
|
+
* @returns The generated TailorDB type
|
|
115
|
+
*/
|
|
116
|
+
declare function getGeneratedType(configPath: string, pluginId: string, sourceType: TailorAnyDBType | null, kind: string): Promise<TailorAnyDBType>;
|
|
117
|
+
//#endregion
|
|
118
|
+
export { type PluginDBSchema, type PluginExecutorFactory, type PluginFunctionArgs, type PluginRecord, type PluginRecordCreatedArgs, type PluginRecordDeletedArgs, type PluginRecordUpdatedArgs, getGeneratedType, withPluginContext };
|
|
105
119
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/plugin/index.mjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import * as fs$1 from "node:fs";
|
|
2
|
+
import * as path from "pathe";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
|
|
1
5
|
//#region src/plugin/with-context.ts
|
|
2
6
|
/**
|
|
3
7
|
* Define a plugin executor that receives context at runtime.
|
|
@@ -41,5 +45,208 @@ function withPluginContext(factory) {
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
//#endregion
|
|
44
|
-
|
|
48
|
+
//#region src/plugin/get-generated-type.ts
|
|
49
|
+
/** Cache: resolved config path -> loaded config data */
|
|
50
|
+
const configCacheMap = /* @__PURE__ */ new Map();
|
|
51
|
+
/**
|
|
52
|
+
* Check if a value is a Plugin instance.
|
|
53
|
+
* @param value - Value to check
|
|
54
|
+
* @returns True if value has the shape of Plugin
|
|
55
|
+
*/
|
|
56
|
+
function isPlugin(value) {
|
|
57
|
+
return typeof value === "object" && value !== null && typeof value.id === "string" && typeof value.importPath === "string";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Load and cache config module from the given path.
|
|
61
|
+
* Extracts plugins from all array exports using definePlugins() format.
|
|
62
|
+
* Returns null if the config file does not exist (e.g., in bundled executor on platform server).
|
|
63
|
+
* @param configPath - Absolute or relative path to tailor.config.ts
|
|
64
|
+
* @returns Cached config data with plugins map, or null if config file is not available
|
|
65
|
+
*/
|
|
66
|
+
async function loadAndCacheConfig(configPath) {
|
|
67
|
+
const resolvedPath = path.resolve(configPath);
|
|
68
|
+
const cached = configCacheMap.get(resolvedPath);
|
|
69
|
+
if (cached) return cached;
|
|
70
|
+
if (!fs$1.existsSync(resolvedPath)) return null;
|
|
71
|
+
const configModule = await import(pathToFileURL(resolvedPath).href);
|
|
72
|
+
if (!configModule?.default) throw new Error(`Invalid config module at "${resolvedPath}": default export not found`);
|
|
73
|
+
const config = configModule.default;
|
|
74
|
+
const configDir = path.dirname(resolvedPath);
|
|
75
|
+
const plugins = /* @__PURE__ */ new Map();
|
|
76
|
+
for (const value of Object.values(configModule)) {
|
|
77
|
+
if (!Array.isArray(value)) continue;
|
|
78
|
+
for (const item of value) if (isPlugin(item)) plugins.set(item.id, {
|
|
79
|
+
plugin: item,
|
|
80
|
+
pluginConfig: item.pluginConfig
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const result = {
|
|
84
|
+
config,
|
|
85
|
+
plugins,
|
|
86
|
+
configDir
|
|
87
|
+
};
|
|
88
|
+
configCacheMap.set(resolvedPath, result);
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolve the namespace for a type-attached sourceType by checking config.db file patterns.
|
|
93
|
+
* Uses ESM module cache identity: same file path yields same object references.
|
|
94
|
+
* @param config - App config with db namespace definitions
|
|
95
|
+
* @param config.db - DB namespace definitions
|
|
96
|
+
* @param configDir - Directory containing the config file
|
|
97
|
+
* @param sourceType - The TailorDB type to look up
|
|
98
|
+
* @returns The namespace name
|
|
99
|
+
*/
|
|
100
|
+
async function resolveNamespaceForType(config, configDir, sourceType) {
|
|
101
|
+
if (!config.db) throw new Error(`No db configuration found in config`);
|
|
102
|
+
for (const [namespace, nsConfig] of Object.entries(config.db)) {
|
|
103
|
+
const dbConfig = nsConfig;
|
|
104
|
+
if (dbConfig.external || !dbConfig.files) continue;
|
|
105
|
+
for (const pattern of dbConfig.files) {
|
|
106
|
+
const absolutePattern = path.resolve(configDir, pattern);
|
|
107
|
+
let matchedFiles;
|
|
108
|
+
try {
|
|
109
|
+
matchedFiles = fs$1.globSync(absolutePattern);
|
|
110
|
+
} catch {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
for (const file of matchedFiles) {
|
|
114
|
+
const mod = await import(pathToFileURL(file).href);
|
|
115
|
+
for (const exported of Object.values(mod)) if (exported === sourceType) return namespace;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
throw new Error(`Could not resolve namespace for type "${sourceType.name}". Ensure the type file is included in a db namespace's files pattern.`);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Resolve the namespace for a namespace plugin by trying each namespace.
|
|
123
|
+
* Calls processNamespace() for each and returns the first whose output contains the requested kind.
|
|
124
|
+
* @param config - App config with db namespace definitions
|
|
125
|
+
* @param config.db - DB namespace definitions
|
|
126
|
+
* @param plugin - Plugin instance
|
|
127
|
+
* @param kind - The generated type kind to look for
|
|
128
|
+
* @param pluginConfig - Plugin-level configuration
|
|
129
|
+
* @returns The namespace name
|
|
130
|
+
*/
|
|
131
|
+
async function resolveNamespaceForNamespacePlugin(config, plugin, kind, pluginConfig) {
|
|
132
|
+
if (!config.db) throw new Error(`No db configuration found in config`);
|
|
133
|
+
if (!plugin.processNamespace) throw new Error(`Plugin "${plugin.id}" does not have a processNamespace() method`);
|
|
134
|
+
for (const namespace of Object.keys(config.db)) {
|
|
135
|
+
if (config.db[namespace].external) continue;
|
|
136
|
+
const output = await plugin.processNamespace({
|
|
137
|
+
pluginConfig,
|
|
138
|
+
namespace
|
|
139
|
+
});
|
|
140
|
+
if (output.types?.[kind]) return {
|
|
141
|
+
namespace,
|
|
142
|
+
output
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
throw new Error(`Could not resolve namespace for plugin "${plugin.id}" with kind "${kind}". No namespace produced a type with that kind.`);
|
|
146
|
+
}
|
|
147
|
+
const processCache = /* @__PURE__ */ new WeakMap();
|
|
148
|
+
const namespaceProcessCache = /* @__PURE__ */ new WeakMap();
|
|
149
|
+
/**
|
|
150
|
+
* Generate a cache key that includes pluginConfig.
|
|
151
|
+
* @param baseKey - Base key for the cache
|
|
152
|
+
* @param pluginConfig - Plugin configuration to include in the key
|
|
153
|
+
* @returns Cache key string
|
|
154
|
+
*/
|
|
155
|
+
function getCacheKey(baseKey, pluginConfig) {
|
|
156
|
+
if (pluginConfig === void 0) return baseKey;
|
|
157
|
+
try {
|
|
158
|
+
return `${baseKey}:${JSON.stringify(pluginConfig)}`;
|
|
159
|
+
} catch {
|
|
160
|
+
throw new Error(`pluginConfig must be JSON-serializable for caching. Received non-serializable value.`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get a generated type from a plugin by loading the config and resolving everything automatically.
|
|
165
|
+
* For type-attached plugins, calls processType() with the sourceType.
|
|
166
|
+
* For namespace plugins, calls processNamespace() with auto-resolved namespace.
|
|
167
|
+
* Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.
|
|
168
|
+
* @param configPath - Path to tailor.config.ts (absolute or relative to cwd)
|
|
169
|
+
* @param pluginId - The plugin's unique identifier
|
|
170
|
+
* @param sourceType - The source TailorDB type (null for namespace plugins)
|
|
171
|
+
* @param kind - The generated type kind (e.g., "request", "step")
|
|
172
|
+
* @returns The generated TailorDB type
|
|
173
|
+
*/
|
|
174
|
+
async function getGeneratedType(configPath, pluginId, sourceType, kind) {
|
|
175
|
+
const cache = await loadAndCacheConfig(configPath);
|
|
176
|
+
if (!cache) return {
|
|
177
|
+
name: `__placeholder_${kind}__`,
|
|
178
|
+
fields: {}
|
|
179
|
+
};
|
|
180
|
+
const { config, configDir, plugins } = cache;
|
|
181
|
+
const pluginEntry = plugins.get(pluginId);
|
|
182
|
+
if (!pluginEntry) throw new Error(`Plugin "${pluginId}" not found in config at "${configPath}". Ensure the plugin is registered via definePlugins().`);
|
|
183
|
+
const { plugin, pluginConfig } = pluginEntry;
|
|
184
|
+
if (sourceType === null) return getGeneratedTypeForNamespacePlugin(config, plugin, kind, pluginConfig);
|
|
185
|
+
return getGeneratedTypeForTypeAttachedPlugin(plugin, sourceType, kind, pluginConfig, await resolveNamespaceForType(config, configDir, sourceType));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get a generated type from a type-attached plugin.
|
|
189
|
+
* @param plugin - The plugin instance (must have processType() method)
|
|
190
|
+
* @param sourceType - The source TailorDB type
|
|
191
|
+
* @param kind - The generated type kind
|
|
192
|
+
* @param pluginConfig - Plugin-level configuration
|
|
193
|
+
* @param namespace - Resolved namespace
|
|
194
|
+
* @returns The generated TailorDB type
|
|
195
|
+
*/
|
|
196
|
+
async function getGeneratedTypeForTypeAttachedPlugin(plugin, sourceType, kind, pluginConfig, namespace) {
|
|
197
|
+
if (!plugin.processType) throw new Error(`Plugin "${plugin.id}" does not have a processType() method`);
|
|
198
|
+
let pluginCache = processCache.get(plugin);
|
|
199
|
+
if (!pluginCache) {
|
|
200
|
+
pluginCache = /* @__PURE__ */ new Map();
|
|
201
|
+
processCache.set(plugin, pluginCache);
|
|
202
|
+
}
|
|
203
|
+
const cacheKey = getCacheKey(`${sourceType.name}:ns=${namespace}`, pluginConfig);
|
|
204
|
+
let output = pluginCache.get(cacheKey);
|
|
205
|
+
if (!output) {
|
|
206
|
+
const typeConfig = sourceType.plugins?.find((p) => p.pluginId === plugin.id)?.config;
|
|
207
|
+
output = await plugin.processType({
|
|
208
|
+
type: sourceType,
|
|
209
|
+
typeConfig: typeConfig ?? {},
|
|
210
|
+
pluginConfig,
|
|
211
|
+
namespace
|
|
212
|
+
});
|
|
213
|
+
pluginCache.set(cacheKey, output);
|
|
214
|
+
}
|
|
215
|
+
const generatedType = output.types?.[kind];
|
|
216
|
+
if (!generatedType) throw new Error(`Generated type not found: plugin=${plugin.id}, sourceType=${sourceType.name}, kind=${kind}`);
|
|
217
|
+
return generatedType;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get a generated type from a namespace plugin.
|
|
221
|
+
* Auto-resolves the namespace by trying each one.
|
|
222
|
+
* @param config - App config with db namespace definitions
|
|
223
|
+
* @param config.db - DB namespace definitions
|
|
224
|
+
* @param plugin - The plugin instance (must have processNamespace() method)
|
|
225
|
+
* @param kind - The generated type kind
|
|
226
|
+
* @param pluginConfig - Plugin-level configuration
|
|
227
|
+
* @returns The generated TailorDB type
|
|
228
|
+
*/
|
|
229
|
+
async function getGeneratedTypeForNamespacePlugin(config, plugin, kind, pluginConfig) {
|
|
230
|
+
if (!plugin.processNamespace) throw new Error(`Plugin "${plugin.id}" does not have a processNamespace() method`);
|
|
231
|
+
let pluginCache = namespaceProcessCache.get(plugin);
|
|
232
|
+
if (!pluginCache) {
|
|
233
|
+
pluginCache = /* @__PURE__ */ new Map();
|
|
234
|
+
namespaceProcessCache.set(plugin, pluginCache);
|
|
235
|
+
}
|
|
236
|
+
if (config.db) for (const namespace$1 of Object.keys(config.db)) {
|
|
237
|
+
if (config.db[namespace$1].external) continue;
|
|
238
|
+
const cacheKey$1 = getCacheKey(`namespace:ns=${namespace$1}`, pluginConfig);
|
|
239
|
+
const cached = pluginCache.get(cacheKey$1);
|
|
240
|
+
if (cached?.types?.[kind]) return cached.types[kind];
|
|
241
|
+
}
|
|
242
|
+
const { namespace, output } = await resolveNamespaceForNamespacePlugin(config, plugin, kind, pluginConfig);
|
|
243
|
+
const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);
|
|
244
|
+
pluginCache.set(cacheKey, output);
|
|
245
|
+
const generatedType = output.types?.[kind];
|
|
246
|
+
if (!generatedType) throw new Error(`Generated type not found: plugin=${plugin.id}, kind=${kind}`);
|
|
247
|
+
return generatedType;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
//#endregion
|
|
251
|
+
export { getGeneratedType, withPluginContext };
|
|
45
252
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/with-context.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 type references and namespace) at runtime.\n */\n\nimport type { TailorActor, TailorEnv } from \"@/parser/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 /** Actor (user) who triggered the event, null for system events */\n actor: TailorActor | null;\n /** Name of the TailorDB type */\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 * sourceType: TailorAnyDBType;\n * historyType: TailorAnyDBType;\n * namespace: string;\n * }\n *\n * export default withPluginContext<MyContext>((ctx) =>\n * createExecutor({\n * name: `${ctx.sourceType.name.toLowerCase()}-on-create`,\n * trigger: recordCreatedTrigger({ type: ctx.sourceType }),\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,SAAgB,kBACd,SAC4B;AAC5B,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["fs","namespace","cacheKey"],"sources":["../../src/plugin/with-context.ts","../../src/plugin/get-generated-type.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 type references and namespace) at runtime.\n */\n\nimport type { TailorActor, TailorEnv } from \"@/parser/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 /** Actor (user) who triggered the event, null for system events */\n actor: TailorActor | null;\n /** Name of the TailorDB type */\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 * sourceType: TailorAnyDBType;\n * historyType: TailorAnyDBType;\n * namespace: string;\n * }\n *\n * export default withPluginContext<MyContext>((ctx) =>\n * createExecutor({\n * name: `${ctx.sourceType.name.toLowerCase()}-on-create`,\n * trigger: recordCreatedTrigger({ type: ctx.sourceType }),\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 { NamespacePluginOutput, Plugin, PluginOutput } from \"@/parser/plugin-config/types\";\nimport type { TailorAnyDBType } from \"@/parser/service/tailordb/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>).importPath === \"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 type-attached sourceType 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 sourceType - The TailorDB type to look up\n * @returns The namespace name\n */\nasync function resolveNamespaceForType(\n config: { db?: Record<string, unknown> },\n configDir: string,\n sourceType: 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 === sourceType) {\n return namespace;\n }\n }\n }\n }\n }\n\n throw new Error(\n `Could not resolve namespace for type \"${sourceType.name}\". ` +\n `Ensure the type 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 processNamespace() 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 type 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: NamespacePluginOutput }> {\n if (!config.db) {\n throw new Error(`No db configuration found in config`);\n }\n\n if (!plugin.processNamespace) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a processNamespace() 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.processNamespace({\n pluginConfig,\n namespace,\n });\n\n if (output.types?.[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 type with that kind.`,\n );\n}\n\n// ========================================\n// Process caching\n// ========================================\n\n// Cache: plugin -> cacheKey -> PluginOutput\nconst processCache = new WeakMap<Plugin, Map<string, PluginOutput>>();\n\n// Cache for namespace plugins: plugin -> cacheKey -> NamespacePluginOutput\nconst namespaceProcessCache = new WeakMap<Plugin, Map<string, NamespacePluginOutput>>();\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 type from a plugin by loading the config and resolving everything automatically.\n * For type-attached plugins, calls processType() with the sourceType.\n * For namespace plugins, calls processNamespace() 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 sourceType - The source TailorDB type (null for namespace plugins)\n * @param kind - The generated type kind (e.g., \"request\", \"step\")\n * @returns The generated TailorDB type\n */\nexport async function getGeneratedType(\n configPath: string,\n pluginId: string,\n sourceType: 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 type 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 (sourceType === null) {\n return getGeneratedTypeForNamespacePlugin(config, plugin, kind, pluginConfig);\n }\n\n const namespace = await resolveNamespaceForType(config, configDir, sourceType);\n return getGeneratedTypeForTypeAttachedPlugin(plugin, sourceType, kind, pluginConfig, namespace);\n}\n\n/**\n * Get a generated type from a type-attached plugin.\n * @param plugin - The plugin instance (must have processType() method)\n * @param sourceType - The source TailorDB type\n * @param kind - The generated type kind\n * @param pluginConfig - Plugin-level configuration\n * @param namespace - Resolved namespace\n * @returns The generated TailorDB type\n */\nasync function getGeneratedTypeForTypeAttachedPlugin(\n plugin: Plugin,\n sourceType: TailorAnyDBType,\n kind: string,\n pluginConfig: unknown,\n namespace: string,\n): Promise<TailorAnyDBType> {\n if (!plugin.processType) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a processType() 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(`${sourceType.name}:ns=${namespace}`, pluginConfig);\n let output = pluginCache.get(cacheKey);\n\n if (!output) {\n const typeConfig = sourceType.plugins?.find((p) => p.pluginId === plugin.id)?.config;\n output = await plugin.processType({\n type: sourceType,\n typeConfig: typeConfig ?? {},\n pluginConfig,\n namespace,\n });\n pluginCache.set(cacheKey, output);\n }\n\n const generatedType = output.types?.[kind];\n if (!generatedType) {\n throw new Error(\n `Generated type not found: plugin=${plugin.id}, sourceType=${sourceType.name}, kind=${kind}`,\n );\n }\n\n return generatedType as TailorAnyDBType;\n}\n\n/**\n * Get a generated type 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 processNamespace() method)\n * @param kind - The generated type kind\n * @param pluginConfig - Plugin-level configuration\n * @returns The generated TailorDB type\n */\nasync function getGeneratedTypeForNamespacePlugin(\n config: { db?: Record<string, unknown> },\n plugin: Plugin,\n kind: string,\n pluginConfig: unknown,\n): Promise<TailorAnyDBType> {\n if (!plugin.processNamespace) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a processNamespace() 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?.types?.[kind]) {\n return cached.types[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 generatedType = output.types?.[kind];\n if (!generatedType) {\n throw new Error(`Generated type not found: plugin=${plugin.id}, kind=${kind}`);\n }\n\n return generatedType as TailorAnyDBType;\n}\n\n/**\n * Clear all internal caches. For testing only.\n * @lintignore\n */\nexport function _clearCacheForTesting(): void {\n configCacheMap.clear();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,SAAgB,kBACd,SAC4B;AAC5B,QAAO;;;;;;AC9FT,MAAM,iCAAiB,IAAI,KAA0B;;;;;;AAOrD,SAAS,SAAS,OAAiC;AACjD,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAkC,OAAO,YACjD,O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