@tailor-platform/sdk 1.66.1 → 2.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -2
- package/dist/application-DB2r36Et.mjs +3 -0
- package/dist/{application-DGDmL8i_.mjs → application-DqS1yBg3.mjs} +188 -128
- package/dist/application-DqS1yBg3.mjs.map +1 -0
- package/dist/{assert-CKfwrmCV.mjs → assert-DBxo8jPo.mjs} +1 -2
- package/dist/{assert-CKfwrmCV.mjs.map → assert-DBxo8jPo.mjs.map} +1 -1
- package/dist/{authconnection-D8SJGMpj.mjs → authconnection-D2MhtTN5.mjs} +2 -3
- package/dist/{authconnection-D8SJGMpj.mjs.map → authconnection-D2MhtTN5.mjs.map} +1 -1
- package/dist/{authconnection-BIYzEh2p.d.mts → authconnection-DvUQAjQS.d.mts} +1 -1
- package/dist/{brand-DlnJ375c.mjs → brand-Eo4pLXPJ.mjs} +1 -2
- package/dist/{brand-DlnJ375c.mjs.map → brand-Eo4pLXPJ.mjs.map} +1 -1
- package/dist/cli/index.mjs +78 -131
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lib.d.mts +15 -154
- package/dist/cli/lib.mjs +9 -10
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/{client-boxXYevx.mjs → client-Dbohmtkv.mjs} +1 -2
- package/dist/{client-F0a4cWUM.mjs → client-z_oHGVNy.mjs} +8 -6
- package/dist/client-z_oHGVNy.mjs.map +1 -0
- package/dist/completion/zsh-worker.zsh +5 -19
- package/dist/configure/index.d.mts +8 -7
- package/dist/configure/index.mjs +11 -28
- package/dist/configure/index.mjs.map +1 -1
- package/dist/{context-s0lxhu8_.mjs → context-Bd266-ru.mjs} +2 -3
- package/dist/{context-s0lxhu8_.mjs.map → context-Bd266-ru.mjs.map} +1 -1
- package/dist/{context-CUBwSBq4.d.mts → context-BuuIb8CC.d.mts} +1 -1
- package/dist/{crashreport-0EHy-ayY.mjs → crashreport-BsjAkFWw.mjs} +19 -10
- package/dist/{crashreport-0EHy-ayY.mjs.map → crashreport-BsjAkFWw.mjs.map} +1 -1
- package/dist/{crashreport-Bf6uT6mf.mjs → crashreport-pr6Rhvza.mjs} +1 -2
- package/dist/{enum-constants-C7DaWeQo.mjs → enum-constants-j9QBF0cB.mjs} +1 -2
- package/dist/enum-constants-j9QBF0cB.mjs.map +1 -0
- package/dist/{errors-EsY4XO6O.mjs → errors-Dtf2WPaW.mjs} +1 -2
- package/dist/{errors-EsY4XO6O.mjs.map → errors-Dtf2WPaW.mjs.map} +1 -1
- package/dist/{field-C4zdJLW5.mjs → field-DOsJCPFa.mjs} +1 -2
- package/dist/field-DOsJCPFa.mjs.map +1 -0
- package/dist/{file-BzK8z3X-.d.mts → file-BB8Vs9O_.d.mts} +1 -1
- package/dist/{file-B58Dm-2P.mjs → file-_oUZo76X.mjs} +2 -3
- package/dist/{file-B58Dm-2P.mjs.map → file-_oUZo76X.mjs.map} +1 -1
- package/dist/{file-utils-BHPxPXmn.mjs → file-utils-DcyIPFQh.mjs} +2 -3
- package/dist/{file-utils-BHPxPXmn.mjs.map → file-utils-DcyIPFQh.mjs.map} +1 -1
- package/dist/{globals-ByrCoDip.mjs → globals-Crz8o65k.mjs} +53 -5
- package/dist/globals-Crz8o65k.mjs.map +1 -0
- package/dist/http-adapter.generated-WgMnb7Sb.d.mts +580 -0
- package/dist/{iconv-kwrmd1U_.d.mts → iconv-Co-TOPuH.d.mts} +1 -1
- package/dist/{iconv-DreIffeM.mjs → iconv-D2vi8G36.mjs} +2 -3
- package/dist/{iconv-DreIffeM.mjs.map → iconv-D2vi8G36.mjs.map} +1 -1
- package/dist/{idp-Ch95ag8h.mjs → idp-BDbK5gjm.mjs} +2 -3
- package/dist/{idp-Ch95ag8h.mjs.map → idp-BDbK5gjm.mjs.map} +1 -1
- package/dist/{idp-BlBPtXJ-.d.mts → idp-DrhVrLmV.d.mts} +1 -1
- package/dist/{index-QpC0TNbH.d.mts → index-5vPyRu1y.d.mts} +2 -2
- package/dist/{index-Bhjep8cS.d.mts → index-B7AKc18V.d.mts} +2 -2
- package/dist/{index-BdLqzJDu.d.mts → index-BlpzXncY.d.mts} +25 -247
- package/dist/{index-DRhMpdnA.d.mts → index-CK7u9isy.d.mts} +8 -8
- package/dist/{index-CZ2r3qiO.d.mts → index-CNYe5lnW.d.mts} +2 -2
- package/dist/{index-Db2RvnEH.d.mts → index-DjUdWlzf.d.mts} +2 -2
- package/dist/index-ZePLwxw7.d.mts +208 -0
- package/dist/{interceptor-DOqRkCya.mjs → interceptor-D-q1rvRl.mjs} +1 -2
- package/dist/{interceptor-DOqRkCya.mjs.map → interceptor-D-q1rvRl.mjs.map} +1 -1
- package/dist/{job-BpsFXPbi.mjs → job-fuc3j1Ma.mjs} +9 -10
- package/dist/job-fuc3j1Ma.mjs.map +1 -0
- package/dist/kysely/index.mjs +0 -1
- package/dist/kysely/index.mjs.map +1 -1
- package/dist/{kysely-type-D1e0Vwkd.mjs → kysely-type-DR8uzZTA.mjs} +2 -3
- package/dist/kysely-type-DR8uzZTA.mjs.map +1 -0
- package/dist/{logger-DpJyJvNz.mjs → logger-CxF-Ex5d.mjs} +1 -2
- package/dist/{logger-DpJyJvNz.mjs.map → logger-CxF-Ex5d.mjs.map} +1 -1
- package/dist/{mock-DMgIygjE.mjs → mock-BjFj5o1I.mjs} +9 -11
- package/dist/mock-BjFj5o1I.mjs.map +1 -0
- package/dist/{multiline-Cf9ODpr1.mjs → multiline-sfHpTZZK.mjs} +1 -2
- package/dist/{multiline-Cf9ODpr1.mjs.map → multiline-sfHpTZZK.mjs.map} +1 -1
- package/dist/{package-json-DcQApfPQ.mjs → package-json-8b0O9TlX.mjs} +1 -2
- package/dist/{package-json-DcQApfPQ.mjs.map → package-json-8b0O9TlX.mjs.map} +1 -1
- package/dist/package-json-Cv2Z-TqQ.mjs +3 -0
- package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
- package/dist/plugin/builtin/enum-constants/index.mjs +1 -2
- package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
- package/dist/plugin/builtin/file-utils/index.mjs +1 -2
- package/dist/plugin/builtin/kysely-type/index.d.mts +1 -1
- package/dist/plugin/builtin/kysely-type/index.mjs +1 -2
- package/dist/plugin/builtin/seed/index.d.mts +1 -1
- package/dist/plugin/builtin/seed/index.mjs +1 -2
- package/dist/plugin/index.d.mts +1 -3
- package/dist/plugin/index.mjs +0 -1
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/registry-DdsYlL_P.mjs +51 -0
- package/dist/registry-DdsYlL_P.mjs.map +1 -0
- package/dist/{repl-editor-CJG3sz7A.mjs → repl-editor-DmGr9zMw.mjs} +2 -3
- package/dist/{repl-editor-CJG3sz7A.mjs.map → repl-editor-DmGr9zMw.mjs.map} +1 -1
- package/dist/{chunk-BkoGK1jX.mjs → rolldown-runtime-DXywRVcq.mjs} +0 -1
- package/dist/runtime/authconnection.d.mts +1 -1
- package/dist/runtime/authconnection.mjs +1 -2
- package/dist/runtime/context.d.mts +1 -1
- package/dist/runtime/context.mjs +1 -2
- package/dist/runtime/file.d.mts +1 -1
- package/dist/runtime/file.mjs +1 -2
- package/dist/runtime/globals.d.mts +6 -39
- package/dist/runtime/globals.mjs +0 -1
- package/dist/runtime/iconv.d.mts +1 -1
- package/dist/runtime/iconv.mjs +1 -2
- package/dist/runtime/idp.d.mts +1 -1
- package/dist/runtime/idp.mjs +1 -2
- package/dist/runtime/index.d.mts +8 -8
- package/dist/runtime/index.mjs +7 -8
- package/dist/runtime/secretmanager.d.mts +1 -1
- package/dist/runtime/secretmanager.mjs +1 -2
- package/dist/runtime/workflow.d.mts +1 -1
- package/dist/runtime/workflow.mjs +1 -2
- package/dist/{runtime-2nzOZCUb.mjs → runtime-n9NCkjee.mjs} +65 -232
- package/dist/runtime-n9NCkjee.mjs.map +1 -0
- package/dist/{schema-1msIhXwA.mjs → schema-BhkpP5Hw.mjs} +3 -4
- package/dist/schema-BhkpP5Hw.mjs.map +1 -0
- package/dist/{secret-file-CWzF8rry.mjs → secret-file-DBqZhjFQ.mjs} +1 -2
- package/dist/{secret-file-CWzF8rry.mjs.map → secret-file-DBqZhjFQ.mjs.map} +1 -1
- package/dist/{secretmanager-CKLB3wAQ.d.mts → secretmanager-B3n4KHfm.d.mts} +1 -1
- package/dist/{secretmanager-B9h-U_8U.mjs → secretmanager-BVxw3ih_.mjs} +2 -3
- package/dist/{secretmanager-B9h-U_8U.mjs.map → secretmanager-BVxw3ih_.mjs.map} +1 -1
- package/dist/seed/index.mjs +0 -1
- package/dist/seed/index.mjs.map +1 -1
- package/dist/{seed-BH2FbrPV.mjs → seed-jf3008-h.mjs} +5 -16
- package/dist/seed-jf3008-h.mjs.map +1 -0
- package/dist/{service-wI3Hvrgx.mjs → service-CCL8ruDf.mjs} +3 -4
- package/dist/service-CCL8ruDf.mjs.map +1 -0
- package/dist/service-D6yonf2I.mjs +3 -0
- package/dist/{service-DMohAx8a2.mjs → service-DU1mVzri.mjs} +3 -4
- package/dist/service-DU1mVzri.mjs.map +1 -0
- package/dist/{telemetry-BQbbVo2t.mjs → telemetry-CdqJEzkj.mjs} +2 -3
- package/dist/{telemetry-BQbbVo2t.mjs.map → telemetry-CdqJEzkj.mjs.map} +1 -1
- package/dist/telemetry-ClwW5ohF.mjs +3 -0
- package/dist/test-env-key-D9kM6ETE.mjs +49 -0
- package/dist/test-env-key-D9kM6ETE.mjs.map +1 -0
- package/dist/type-source-DH_LH20p.mjs +13 -0
- package/dist/type-source-DH_LH20p.mjs.map +1 -0
- package/dist/{types-CmzfQP_m.mjs → types-B2RpYyA_.mjs} +2 -3
- package/dist/types-B2RpYyA_.mjs.map +1 -0
- package/dist/types-ClhIrW_C.mjs +4 -0
- package/dist/{tailordb-C-ar4XCX.d.mts → types-DCUhgpyI.d.mts} +142 -221
- package/dist/{plugin-DylAsA4Z.d.mts → types-DhO_VEZd.d.mts} +119 -179
- package/dist/types-DwDgacni.d.mts +338 -0
- package/dist/utils/test/index.d.mts +4 -3
- package/dist/utils/test/index.mjs +1 -2
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/vitest/environment.mjs +1 -2
- package/dist/vitest/environment.mjs.map +1 -1
- package/dist/vitest/index.d.mts +42 -5
- package/dist/vitest/index.mjs +133 -4
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/setup.mjs +2 -3
- package/dist/vitest/setup.mjs.map +1 -1
- package/dist/{workflow-CMamswkK.d.mts → workflow-BbKvGLQg.d.mts} +1 -1
- package/dist/{workflow--aPbA8Uq.mjs → workflow-DgemCAz3.mjs} +2 -3
- package/dist/{workflow--aPbA8Uq.mjs.map → workflow-DgemCAz3.mjs.map} +1 -1
- package/dist/workflow.generated-DtQwEo-x.d.mts +671 -0
- package/docs/cli/application.md +0 -2
- package/docs/cli/crashreport.md +0 -2
- package/docs/cli/function.md +1 -1
- package/docs/cli/user.md +3 -3
- package/docs/cli/workspace.md +3 -3
- package/docs/configuration.md +0 -2
- package/docs/plugin/custom.md +2 -2
- package/docs/plugin/index.md +1 -1
- package/docs/runtime.md +3 -3
- package/docs/services/auth.md +0 -2
- package/docs/services/executor.md +0 -2
- package/docs/services/resolver.md +2 -4
- package/docs/services/tailordb.md +1 -1
- package/docs/services/workflow.md +13 -15
- package/docs/testing.md +18 -11
- package/package.json +9 -8
- package/dist/actor-D_2aJjYO.d.mts +0 -24
- package/dist/application-DGDmL8i_.mjs.map +0 -1
- package/dist/application-nTydHJm8.mjs +0 -4
- package/dist/cli/skills.d.mts +0 -1
- package/dist/cli/skills.mjs +0 -22
- package/dist/cli/skills.mjs.map +0 -1
- package/dist/client-F0a4cWUM.mjs.map +0 -1
- package/dist/enum-constants-C7DaWeQo.mjs.map +0 -1
- package/dist/env-B-g-qgE4.d.mts +0 -7
- package/dist/field-C4zdJLW5.mjs.map +0 -1
- package/dist/globals-ByrCoDip.mjs.map +0 -1
- package/dist/job-BpsFXPbi.mjs.map +0 -1
- package/dist/kysely-type-D1e0Vwkd.mjs.map +0 -1
- package/dist/mock-DMgIygjE.mjs.map +0 -1
- package/dist/package-json-wzO6nV9O.mjs +0 -4
- package/dist/registry-D0uB0OrK.mjs +0 -178
- package/dist/registry-D0uB0OrK.mjs.map +0 -1
- package/dist/runtime-2nzOZCUb.mjs.map +0 -1
- package/dist/schema-1msIhXwA.mjs.map +0 -1
- package/dist/seed-BH2FbrPV.mjs.map +0 -1
- package/dist/service-BHQIerYh.mjs +0 -4
- package/dist/service-DMohAx8a2.mjs.map +0 -1
- package/dist/service-wI3Hvrgx.mjs.map +0 -1
- package/dist/telemetry-w92bvGdC.mjs +0 -4
- package/dist/types-2Be3wSMc.mjs +0 -5
- package/dist/types-CmzfQP_m.mjs.map +0 -1
- package/dist/workflow.generated--1Qc15Et.d.mts +0 -1471
- package/docs/generator/builtin.md +0 -257
- package/docs/generator/custom.md +0 -147
- package/docs/generator/index.md +0 -66
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum-constants-C7DaWeQo.mjs","names":[],"sources":["../src/plugin/builtin/enum-constants/generate-enum-constants.ts","../src/plugin/builtin/enum-constants/process-enum-type.ts","../src/plugin/builtin/enum-constants/index.ts"],"sourcesContent":["import type { EnumDefinition } from \"./types\";\n\n/**\n * Generate enum constant definitions from collected metadata.\n * @param allEnums - All collected enum definitions\n * @returns Generated enum constant definitions\n */\nexport function generateUnifiedEnumConstants(allEnums: EnumDefinition[]): string {\n if (allEnums.length === 0) {\n return \"\";\n }\n\n const enumMap = new Map<string, EnumDefinition>();\n for (const enumDef of allEnums) {\n enumMap.set(enumDef.name, enumDef);\n }\n\n const enumDefs = Array.from(enumMap.values())\n .map((e) => {\n const members = e.values\n .map((v) => {\n const key = v.value.replace(/[-\\s]/g, \"_\");\n return ` \"${key}\": \"${v.value}\"`;\n })\n .join(\",\\n\");\n\n const hasDescriptions = e.values.some((v) => v.description);\n let jsDoc = \"\";\n if (e.fieldDescription || hasDescriptions) {\n const lines: string[] = [];\n\n if (e.fieldDescription) {\n lines.push(` * ${e.fieldDescription}`);\n if (hasDescriptions) {\n lines.push(\" *\");\n }\n }\n\n if (hasDescriptions) {\n const propertyDocs = e.values.map((v) => {\n const key = v.value.replace(/[-\\s]/g, \"_\");\n return ` * @property ${[key, v.description].filter(Boolean).join(\" - \")}`;\n });\n lines.push(...propertyDocs);\n }\n\n if (lines.length > 0) {\n jsDoc = `/**\\n${lines.join(\"\\n\")}\\n */\\n`;\n }\n }\n\n const constDef = `${jsDoc}export const ${e.name} = {\\n${members}\\n} as const;`;\n const typeDef = `export type ${e.name} = (typeof ${e.name})[keyof typeof ${e.name}];`;\n return `${constDef}\\n${typeDef}`;\n })\n .join(\"\\n\\n\");\n\n if (!enumDefs) {\n return \"\";\n }\n\n return enumDefs + \"\\n\";\n}\n","import type { EnumConstantMetadata } from \"./types\";\nimport type { TailorDBType } from \"@/types/tailordb\";\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nfunction collectEnums(type: TailorDBType): EnumConstantMetadata[\"enums\"] {\n const enums: EnumConstantMetadata[\"enums\"] = [];\n\n for (const [fieldName, parsedField] of Object.entries(type.fields)) {\n if (parsedField.config.type === \"enum\" && parsedField.config.allowedValues) {\n const enumTypeName = `${type.name}${capitalizeFirst(fieldName)}`;\n enums.push({\n name: enumTypeName,\n values: parsedField.config.allowedValues,\n fieldDescription: parsedField.config.description,\n });\n }\n\n // Process nested fields\n if (parsedField.config.type === \"nested\" && parsedField.config.fields) {\n for (const [nestedFieldName, nestedFieldConfig] of Object.entries(\n parsedField.config.fields,\n )) {\n if (nestedFieldConfig.type === \"enum\" && nestedFieldConfig.allowedValues) {\n const fullFieldName = `${fieldName}${capitalizeFirst(nestedFieldName)}`;\n const enumTypeName = `${type.name}${capitalizeFirst(fullFieldName)}`;\n enums.push({\n name: enumTypeName,\n values: nestedFieldConfig.allowedValues,\n fieldDescription: nestedFieldConfig.description,\n });\n }\n }\n }\n }\n\n return enums;\n}\n\n/**\n * Process a TailorDB type and extract enum metadata.\n * @param type - The parsed TailorDB type to process\n * @returns Enum constant metadata for the type\n */\nexport async function processEnumType(type: TailorDBType): Promise<EnumConstantMetadata> {\n const enums = collectEnums(type);\n\n return {\n name: type.name,\n enums,\n };\n}\n","import { generateUnifiedEnumConstants } from \"./generate-enum-constants\";\nimport { processEnumType } from \"./process-enum-type\";\nimport type { EnumDefinition } from \"./types\";\nimport type { Plugin } from \"@/types/plugin\";\nimport type { GeneratorResult, TailorDBReadyContext } from \"@/types/plugin-generation\";\n\n/** Unique identifier for the enum constants generator plugin. */\nexport const EnumConstantsGeneratorID = \"@tailor-platform/enum-constants\";\n\ntype EnumConstantsPluginOptions = {\n distPath: string;\n};\n\n/**\n * Plugin that generates enum constants from TailorDB type definitions.\n * @param options - Plugin options\n * @param options.distPath - Output file path for generated constants\n * @returns Plugin instance with onTailorDBReady hook\n */\nexport function enumConstantsPlugin(\n options: EnumConstantsPluginOptions,\n): Plugin<unknown, EnumConstantsPluginOptions> {\n return {\n id: EnumConstantsGeneratorID,\n description: \"Generates enum constants from TailorDB type definitions\",\n pluginConfig: options,\n\n async onTailorDBReady(\n ctx: TailorDBReadyContext<EnumConstantsPluginOptions>,\n ): Promise<GeneratorResult> {\n const allEnums: EnumDefinition[] = [];\n\n for (const ns of ctx.tailordb) {\n for (const type of Object.values(ns.types)) {\n const metadata = await processEnumType(type);\n allEnums.push(...metadata.enums);\n }\n }\n\n const files: GeneratorResult[\"files\"] = [];\n if (allEnums.length > 0) {\n const content = generateUnifiedEnumConstants(allEnums);\n files.push({\n path: ctx.pluginConfig.distPath,\n content,\n });\n }\n\n return { files };\n },\n };\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,6BAA6B,UAAoC;CAC/E,IAAI,SAAS,WAAW,GACtB,OAAO;CAGT,MAAM,0BAAU,IAAI,IAA4B;CAChD,KAAK,MAAM,WAAW,UACpB,QAAQ,IAAI,QAAQ,MAAM,OAAO;CAGnC,MAAM,WAAW,MAAM,KA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@@ -1,7 +0,0 @@
|
|
|
1
|
-
//#region src/types/env.d.ts
|
|
2
|
-
interface Env {}
|
|
3
|
-
/** Represents environment variables in the Tailor platform. */
|
|
4
|
-
type TailorEnv = keyof Env extends never ? Record<string, string | number | boolean> : Env;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { TailorEnv as n, Env as t };
|
|
7
|
-
//# sourceMappingURL=env-B-g-qgE4.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-C4zdJLW5.mjs","names":[],"sources":["../src/configure/types/field.ts"],"sourcesContent":["import type { EnumValue } from \"@/types/field-types\";\n\nexport type AllowedValues = readonly [string | EnumValue, ...(string | EnumValue)[]];\n\n/**\n * Normalize allowed values into EnumValue objects with descriptions.\n * @param values - Allowed values as strings or EnumValue objects\n * @returns Normalized allowed values\n */\nexport function mapAllowedValues(values: AllowedValues): EnumValue[] {\n return values.map((value) => {\n if (typeof value === \"string\") {\n return { value, description: \"\" };\n }\n return { ...value, description: value.description ?? \"\" };\n });\n}\n\nexport type AllowedValuesOutput<V extends AllowedValues> = V[number] extends infer T\n ? T extends string\n ? T\n : T extends { value: infer K }\n ? K\n : never\n : never;\n"],"mappings":";;;;;;;AASA,SAAgB,iBAAiB,QAAoC;CACnE,OAAO,OAAO,KAAK,UAAU;EAC3B,IAAI,OAAO,UAAU,UACnB,OAAO;GAAE;GAAO,aAAa;EAAG;EAElC,OAAO;GAAE,GAAG;GAAO,aAAa,MAAM,eAAe;EAAG;CAC1D,CAAC;AACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"globals-ByrCoDip.mjs","names":[],"sources":["../src/vitest/workflow-runtime.ts","../src/vitest/globals.ts"],"sourcesContent":["// Default `tailor.workflow` runner installed by the `tailor-runtime` environment.\n// Must stay free of `vitest` (`vi`): it loads via `./globals` in the environment\n// realm where `vi` is unavailable, hence relative imports only (no `@/` alias).\nimport { runRegisteredJob, runRegisteredWorkflow } from \"../configure/services/workflow/registry\";\n\nexport interface DefaultWorkflowRuntime {\n triggerJobFunction: (name: string, args?: unknown) => unknown;\n triggerWorkflow: (name: string, args?: unknown, options?: unknown) => Promise<string>;\n wait: (key: string, payload?: unknown) => unknown;\n resolve: (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => Promise<void>;\n}\n\nexport function createDefaultWorkflowRuntime(): DefaultWorkflowRuntime {\n return {\n triggerJobFunction: (name, args) => runRegisteredJob(name, args),\n triggerWorkflow: (name, args) => runRegisteredWorkflow(name, args),\n wait: (key: string): unknown => {\n throw new Error(\n `No wait handler for \"${key}\". Acquire mockWorkflow() and call setWaitHandler(...).`,\n );\n },\n resolve: async (): Promise<void> => {\n throw new Error(\n \"No resolve handler. Acquire mockWorkflow() and call setResolveHandler(...).\",\n );\n },\n };\n}\n","/**\n * Base platform globals for the tailor-runtime test environment.\n *\n * This module is intentionally free of any `vitest` (`vi`) dependency so it can\n * be imported from the Vitest *environment* module (which runs in a realm where\n * `vi` is not available). It installs only the always-present structural pieces:\n *\n * - `globalThis.tailor` / `globalThis.tailordb` container objects\n * - `globalThis.tailor.context.getInvoker` default stub\n * - the platform error classes (`TailorErrors`, `TailorErrorMessage`,\n * `TailorDBFileError`)\n * - the `__tailorRuntimeActive` sentinel flag\n *\n * The per-namespace mock behavior (TailorDB client, workflow, secretmanager, …)\n * is installed on demand by the `xMock()` factories in `./mock`, which run in\n * test context where `vi` *is* available.\n */\n\nimport { createDefaultWorkflowRuntime } from \"./workflow-runtime\";\nimport type { ContextInvoker } from \"../runtime/context\";\nimport type { TailorDBFileErrorCode } from \"../runtime/file\";\n\n// Sentinel set when the tailor-runtime environment is active. setup.ts reads it\n// to decide whether to run its blocked-globals lifecycle and config-secret\n// loading.\nexport const RUNTIME_FLAG_KEY = \"__tailorRuntimeActive\";\n\n// ---------------------------------------------------------------------------\n// Error class mocks\n// ---------------------------------------------------------------------------\n\ninterface TailorErrorItem {\n message: string;\n path: (string | number)[];\n}\n\nclass TailorErrorsMock extends Error {\n errors: TailorErrorItem[];\n\n constructor(errors: TailorErrorItem[]) {\n if (!Array.isArray(errors)) {\n throw new TypeError(\"TailorErrors: errors must be an array\");\n }\n const validated = errors.map((e, i) => {\n if (typeof e.message !== \"string\") {\n throw new TypeError(`TailorErrors: errors[${i}].message must be a string`);\n }\n if (!Array.isArray(e.path)) {\n throw new TypeError(`TailorErrors: errors[${i}].path must be an array`);\n }\n return { message: e.message, path: e.path };\n });\n // Match the PF runtime's TailorErrors serialization, which prefixes the\n // JSON payload with \"TailorErrors: \". Other SDK code (e.g. apply\n // integration fixtures) strips this prefix before JSON.parse.\n super(`TailorErrors: ${JSON.stringify({ errors: validated })}`);\n this.name = \"TailorErrors\";\n this.errors = validated;\n }\n}\n\nclass TailorErrorMessageMock extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"TailorErrorMessage\";\n }\n}\n\nclass TailorDBFileErrorMock extends Error {\n code?: TailorDBFileErrorCode;\n override cause: unknown;\n\n constructor(message: string, code?: TailorDBFileErrorCode, cause?: unknown) {\n super(message);\n this.name = \"TailorDBFileError\";\n this.code = code;\n this.cause = cause;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Base install / cleanup\n// ---------------------------------------------------------------------------\n\n// Stub-only injection. SDK consumers configure invokers at the body level\n// (resolver/executor/workflow `.body()` `invoker` arg) or, for bundled tests,\n// via `vi.spyOn(globalThis.tailor.context, \"getInvoker\")`.\nfunction defaultGetInvoker(): ContextInvoker | null {\n return null;\n}\n\n/**\n * Install the always-present base platform globals (containers, context stub,\n * error classes, runtime flag). Per-namespace mocks are layered on top by the\n * `xMock()` factories in `./mock`.\n * @param global - The global object to install into (typically `globalThis`)\n */\nexport function installPlatformGlobals(global: typeof globalThis): void {\n const g = global as Record<string, unknown>;\n\n g[RUNTIME_FLAG_KEY] = true;\n\n // Containers. Namespace mocks (secretmanager, …) are added to these by the\n // corresponding `xMock()` on acquisition. `workflow` carries a default runner\n // so `.trigger()` runs the real job chain locally without `mockWorkflow()`;\n // `mockWorkflow()` overlays and restores it.\n g.tailor = {\n context: { getInvoker: defaultGetInvoker },\n workflow: createDefaultWorkflowRuntime(),\n };\n g.tailordb = {};\n\n g.TailorErrors = TailorErrorsMock;\n g.TailorErrorMessage = TailorErrorMessageMock;\n g.TailorDBFileError = TailorDBFileErrorMock;\n}\n\n/**\n * Remove the base platform globals (and anything the namespace mocks layered on\n * top, since they live under the same containers).\n * @param global - The global object to clean up (typically `globalThis`)\n */\nexport function cleanupPlatformGlobals(global: typeof globalThis): void {\n const g = global as Record<string, unknown>;\n delete g.tailordb;\n delete g.tailor;\n delete g.TailorErrors;\n delete g.TailorErrorMessage;\n delete g.TailorDBFileError;\n delete g[RUNTIME_FLAG_KEY];\n}\n"],"mappings":";;;;AAgBA,SAAgB,+BAAuD;CACrE,OAAO;EACL,qBAAqB,MAAM,SAAS,iBAAiB,MAAM,IAAI;EAC/D,kBAAkB,MAAM,SAAS,sBAAsB,MAAM,IAAI;EACjE,OAAO,QAAyB;GAC9B,MAAM,IAAI,MACR,wBAAwB,IAAI,wDAC9B;EACF;EACA,SAAS,YAA2B;GAClC,MAAM,IAAI,MACR,6EACF;EACF;CACF;AACF;;;;;;;;;;;;;;;;;;;;;ACNA,MAAa,mBAAmB;AAWhC,IAAM,mBAAN,cAA+B,MAAM;CACnC;CAEA,YAAY,QAA2B;EACrC,IAAI,CAAC,MAAM,QAAQ,MAAM,GACvB,MAAM,IAAI,UAAU,uCAAuC;EAE7D,MAAM,YAAY,OAAO,KAAK,GAAG,MAAM;GACrC,IAAI,OAAO,EAAE,YAAY,UACvB,MAAM,IAAI,UAAU,wBAAwB,EAAE,2BAA2B;GAE3E,IAAI,CAAC,MAAM,QAAQ,EAAE,IAAI,GACvB,MAAM,IAAI,UAAU,wBAAwB,EAAE,wBAAwB;GAExE,OAAO;IAAE,SAAS,EAAE;IAAS,MAAM,EAAE;GAAK;EAC5C,CAAC;EAID,MAAM,iBAAiB,KAAK,UAAU,EAAE,QAAQ,UAAU,CAAC,GAAG;EAC9D,KAAK,OAAO;EACZ,KAAK,SAAS;CAChB;AACF;AAEA,IAAM,yBAAN,cAAqC,MAAM;CACzC,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;AAEA,IAAM,wBAAN,cAAoC,MAAM;CACxC;CACA,AAAS;CAET,YAAY,SAAiB,MAA8B,OAAiB;EAC1E,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,QAAQ;CACf;AACF;AASA,SAAS,oBAA2C;CAClD,OAAO;AACT;;;;;;;AAQA,SAAgB,uBAAuB,QAAiC;CACtE,MAAM,IAAI;CAEV,EAAE,oBAAoB;CAMtB,EAAE,SAAS;EACT,SAAS,EAAE,YAAY,kBAAkB;EACzC,UAAU,6BAA6B;CACzC;CACA,EAAE,WAAW,CAAC;CAEd,EAAE,eAAe;CACjB,EAAE,qBAAqB;CACvB,EAAE,oBAAoB;AACxB;;;;;;AAOA,SAAgB,uBAAuB,QAAiC;CACtE,MAAM,IAAI;CACV,OAAO,EAAE;CACT,OAAO,EAAE;CACT,OAAO,EAAE;CACT,OAAO,EAAE;CACT,OAAO,EAAE;CACT,OAAO,EAAE;AACX"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"job-BpsFXPbi.mjs","names":[],"sources":["../src/configure/services/workflow/job.ts"],"sourcesContent":["import { brandValue } from \"@/utils/brand\";\nimport { dispatchTriggerJob, registerJob, type RegisteredJobBody } from \"./registry\";\nimport type { TailorEnv } from \"@/types/env\";\nimport type { JsonCompatible } from \"@/types/helpers\";\nimport type { TailorInvoker } from \"@/types/user\";\n\n/**\n * Context object passed as the second argument to workflow job body functions.\n */\nexport type WorkflowJobContext = {\n env: TailorEnv;\n invoker?: TailorInvoker;\n};\n\n/**\n * The body function type for a workflow job.\n * Resolves to the callable signature when `I` / `O` are JsonValue-compatible,\n * or to a template-literal error string that surfaces at the `body:` property.\n */\ntype JobBody<I, O> = [null] extends [I]\n ? \"ERROR: Input cannot be null at the top level\"\n : [I] extends [undefined]\n ? [O] extends [JsonCompatible<O> | undefined | void]\n ? (input: I, context: WorkflowJobContext) => O | Promise<O>\n : \"ERROR: Output must be JsonValue-compatible (plain objects/arrays; no class instances or functions)\"\n : [undefined] extends [I]\n ? \"ERROR: Input cannot include undefined at the top level\"\n : [I] extends [JsonCompatible<I>]\n ? [O] extends [JsonCompatible<O> | undefined | void]\n ? (input: I, context: WorkflowJobContext) => O | Promise<O>\n : \"ERROR: Output must be JsonValue-compatible (plain objects/arrays; no class instances or functions)\"\n : \"ERROR: Input must be JsonValue-compatible (plain objects/arrays; no class instances or functions)\";\n\n/**\n * WorkflowJob represents a job that can be triggered in a workflow.\n *\n * Type constraints:\n * - Input: Must be JsonValue-compatible (plain objects/arrays; no class instances or functions) or undefined.\n * - Output: Must be JsonValue-compatible (plain objects/arrays; no class instances or functions), undefined, or void.\n * - Trigger returns `Awaited<Output>` as-is (no Jsonify transformation).\n */\nexport interface WorkflowJob<Name extends string = string, Input = undefined, Output = undefined> {\n name: Name;\n /**\n * Trigger this job with the given input. Returns a Promise that resolves\n * to the job's output value.\n * @example\n * body: async (input) => {\n * const a = await jobA.trigger({ id: input.id });\n * const b = await jobB.trigger({ id: input.id });\n * return { a, b };\n * }\n */\n trigger: [Input] extends [undefined]\n ? () => Promise<Awaited<Output>>\n : (input: Input) => Promise<Awaited<Output>>;\n body: (input: Input, context: WorkflowJobContext) => Output | Promise<Output>;\n}\n\nexport { WORKFLOW_TEST_ENV_KEY } from \"./test-env-key\";\n\ninterface CreateWorkflowJobConfig<Name extends string, I, O> {\n readonly name: Name;\n readonly body: JobBody<I, O>;\n}\n\n/**\n * Create a workflow job definition.\n *\n * All jobs must be named exports from the workflow file.\n * Job names must be unique across the entire project.\n *\n * Input and output must be JsonValue-compatible (primitives, plain objects, arrays).\n * Functions and objects with a `toJSON` method are rejected at the type level;\n * class instances exposing methods are rejected via the property walk.\n * @param config - Job configuration with name and body function.\n * @param config.name - Unique job name across the project.\n * @param config.body - Async function that processes the job input.\n * @returns A WorkflowJob that can be triggered from other jobs.\n * @example\n * // Simple job with async body:\n * export const fetchData = createWorkflowJob({\n * name: \"fetch-data\",\n * body: async (input: { id: string }) => {\n * const db = getDB(\"tailordb\");\n * return await db.selectFrom(\"Table\").selectAll().where(\"id\", \"=\", input.id).executeTakeFirst();\n * },\n * });\n * @example\n * // Orchestrator job that fans out to other jobs.\n * export const orchestrate = createWorkflowJob({\n * name: \"orchestrate\",\n * body: async (input: { orderId: string }) => {\n * const inventory = await checkInventory.trigger({ orderId: input.orderId });\n * const payment = await processPayment.trigger({ orderId: input.orderId });\n * return { inventory, payment };\n * },\n * });\n */\nexport function createWorkflowJob<const Name extends string, I = undefined, O = undefined>(\n config: CreateWorkflowJobConfig<Name, I, O>,\n): WorkflowJob<Name, I, Awaited<O>> {\n const body = config.body as (input: I, context: WorkflowJobContext) => O | Promise<O>;\n\n // Test-only registry/trigger shim; the platform bundle sets the flag so it is DCE'd.\n if (!process.env.TAILOR_PLATFORM_BUNDLE) {\n registerJob(config.name, body as RegisteredJobBody);\n }\n\n const trigger = process.env.TAILOR_PLATFORM_BUNDLE\n ? async () => {\n throw new Error(\n \"This workflow job's .trigger() is rewritten at build time and is unavailable in the bundle\",\n );\n }\n : async (args?: unknown) => (await dispatchTriggerJob(config.name, args)) as Awaited<O>;\n\n return brandValue(\n { name: config.name, trigger, body } as WorkflowJob<Name, I, Awaited<O>>,\n \"workflow-job\",\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,SAAgB,kBACd,QACkC;CAClC,MAAM,OAAO,OAAO;CAGpB,IAAI,CAAC,QAAQ,IAAI,wBACf,YAAY,OAAO,MAAM,IAAyB;CAGpD,MAAM,UAAU,QAAQ,IAAI,yBACxB,YAAY;EACV,MAAM,IAAI,MACR,4FACF;CACF,IACA,OAAO,SAAoB,MAAM,mBAAmB,OAAO,MAAM,IAAI;CAEzE,OAAO,WACL;EAAE,MAAM,OAAO;EAAM;EAAS;CAAK,GACnC,cACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-type-D1e0Vwkd.mjs","names":[],"sources":["../src/plugin/builtin/kysely-type/type-processor.ts","../src/plugin/builtin/kysely-type/index.ts"],"sourcesContent":["import multiline from \"@/utils/multiline\";\nimport { type KyselyNamespaceMetadata, type KyselyTypeMetadata } from \"./types\";\nimport type { OperatorFieldConfig, TailorDBType } from \"@/types/tailordb\";\n\ntype UsedUtilityTypes = { Timestamp: boolean; Serial: boolean };\n\ntype FieldTypeResult = {\n type: string;\n usedUtilityTypes: UsedUtilityTypes;\n};\n\n/**\n * Get the enum type definition.\n * @param fieldConfig - The field configuration\n * @returns The enum type as a string union\n */\nfunction getEnumType(fieldConfig: OperatorFieldConfig): string {\n const allowedValues = fieldConfig.allowedValues;\n\n if (allowedValues && Array.isArray(allowedValues)) {\n return allowedValues\n .map((v: string | { value: string }) => {\n const value = typeof v === \"string\" ? v : v.value;\n return `\"${value}\"`;\n })\n .join(\" | \");\n }\n return \"string\";\n}\n\n/**\n * Get the nested object type definition.\n * @param fieldConfig - The field configuration\n * @returns The nested type with used utility types\n */\nfunction getNestedType(fieldConfig: OperatorFieldConfig): FieldTypeResult {\n const fields = fieldConfig.fields;\n if (!fields || typeof fields !== \"object\") {\n return {\n type: \"string\",\n usedUtilityTypes: { Timestamp: false, Serial: false },\n };\n }\n\n const fieldResults = Object.entries(fields).map(([fieldName, config]) => {\n const result = generateFieldType(config);\n const optional = config.required !== true ? \"?\" : \"\";\n return {\n fieldType: `${fieldName}${optional}: ${result.type}`,\n usedUtilityTypes: result.usedUtilityTypes,\n };\n });\n\n const aggregatedUtilityTypes = fieldResults.reduce(\n (acc, result) => ({\n Timestamp: acc.Timestamp || result.usedUtilityTypes.Timestamp,\n Serial: acc.Serial || result.usedUtilityTypes.Serial,\n }),\n { Timestamp: false, Serial: false },\n );\n\n const fieldTypes = fieldResults.map((r) => r.fieldType);\n const obj = `{\\n ${fieldTypes.join(\";\\n \")}${fieldTypes.length > 0 ? \";\" : \"\"}\\n}`;\n\n const hasOptionalFields = Object.values(fields).some((config) => config.required !== true);\n if (aggregatedUtilityTypes.Timestamp || hasOptionalFields) {\n return { type: `ObjectColumnType<${obj}>`, usedUtilityTypes: aggregatedUtilityTypes };\n }\n return { type: obj, usedUtilityTypes: aggregatedUtilityTypes };\n}\n\n/**\n * Get the base Kysely type for a field (without array/null modifiers).\n * @param fieldConfig - The field configuration\n * @returns The base type with used utility types\n */\nfunction getBaseType(fieldConfig: OperatorFieldConfig): FieldTypeResult {\n const fieldType = fieldConfig.type;\n const usedUtilityTypes = { Timestamp: false, Serial: false };\n\n let type: string;\n switch (fieldType) {\n case \"uuid\":\n case \"string\":\n case \"decimal\":\n type = \"string\";\n break;\n case \"integer\":\n case \"float\":\n type = \"number\";\n break;\n case \"date\":\n case \"datetime\":\n usedUtilityTypes.Timestamp = true;\n type = \"Timestamp\";\n break;\n case \"bool\":\n case \"boolean\":\n type = \"boolean\";\n break;\n case \"enum\":\n type = getEnumType(fieldConfig);\n break;\n case \"nested\": {\n const nestedResult = getNestedType(fieldConfig);\n return nestedResult;\n }\n default:\n type = \"string\";\n break;\n }\n\n return { type, usedUtilityTypes };\n}\n\n/**\n * Generate the complete field type including array and null modifiers.\n * @param fieldConfig - The field configuration\n * @returns The complete field type with used utility types\n */\nfunction generateFieldType(fieldConfig: OperatorFieldConfig): FieldTypeResult {\n const baseTypeResult = getBaseType(fieldConfig);\n const usedUtilityTypes = { ...baseTypeResult.usedUtilityTypes };\n\n const isArray = fieldConfig.array === true;\n const isNullable = fieldConfig.required !== true;\n\n // Types that use ColumnType internally (Timestamp, ObjectColumnType) cannot be\n // directly wrapped with [] for arrays, because Kysely only resolves ColumnType at\n // the top-level table property. Use ArrayColumnType/ObjectArrayColumnType to keep\n // the ColumnType at the top level with arrays inside.\n const columnTypeBaseTypes = new Set([\"Timestamp\"]);\n const isColumnTypeBase = columnTypeBaseTypes.has(baseTypeResult.type);\n\n let finalType = baseTypeResult.type;\n if (isArray) {\n if (isColumnTypeBase || finalType.startsWith(\"ObjectColumnType<\")) {\n finalType = `ArrayColumnType<${baseTypeResult.type}>`;\n } else {\n const needsParens = fieldConfig.type === \"enum\";\n finalType = needsParens ? `(${baseTypeResult.type})[]` : `${baseTypeResult.type}[]`;\n }\n }\n if (isNullable) {\n finalType = `${finalType} | null`;\n }\n\n if (fieldConfig.serial) {\n usedUtilityTypes.Serial = true;\n finalType = `Serial<${finalType}>`;\n }\n if (fieldConfig.hooks?.create) {\n finalType = `Generated<${finalType}>`;\n }\n\n return { type: finalType, usedUtilityTypes };\n}\n\n/**\n * Generate the table interface.\n * @param type - The parsed TailorDB type\n * @returns The type definition and used utility types\n */\nfunction generateTableInterface(type: TailorDBType): {\n typeDef: string;\n usedUtilityTypes: UsedUtilityTypes;\n} {\n const fieldEntries = Object.entries(type.fields).filter(([fieldName]) => fieldName !== \"id\");\n\n const fieldResults = fieldEntries.map(([fieldName, parsedField]) => ({\n fieldName,\n ...generateFieldType(parsedField.config),\n }));\n\n const fields = [\n \"id: Generated<string>;\",\n ...fieldResults.map((result) => `${result.fieldName}: ${result.type};`),\n ];\n\n const aggregatedUtilityTypes = fieldResults.reduce(\n (acc, result) => ({\n Timestamp: acc.Timestamp || result.usedUtilityTypes.Timestamp,\n\n Serial: acc.Serial || result.usedUtilityTypes.Serial,\n }),\n { Timestamp: false, Serial: false },\n );\n\n const typeDef = multiline /* ts */ `\n ${type.name}: {\n ${fields.join(\"\\n\")}\n }\n `;\n\n return { typeDef, usedUtilityTypes: aggregatedUtilityTypes };\n}\n\n/**\n * Convert a TailorDBType into KyselyTypeMetadata.\n * @param type - Parsed TailorDB type\n * @returns Generated Kysely type metadata\n */\nexport async function processKyselyType(type: TailorDBType): Promise<KyselyTypeMetadata> {\n const result = generateTableInterface(type);\n\n return {\n name: type.name,\n typeDef: result.typeDef,\n usedUtilityTypes: result.usedUtilityTypes,\n };\n}\n\n/**\n * Generate unified types file from multiple namespaces.\n * @param namespaceData - Namespace metadata\n * @returns Generated types file contents\n */\nexport function generateUnifiedKyselyTypes(namespaceData: KyselyNamespaceMetadata[]): string {\n if (namespaceData.length === 0) {\n return \"\";\n }\n\n // Aggregate used utility types from all namespaces\n const globalUsedUtilityTypes = namespaceData.reduce(\n (acc, ns) => ({\n Timestamp: acc.Timestamp || ns.usedUtilityTypes.Timestamp,\n Serial: acc.Serial || ns.usedUtilityTypes.Serial,\n }),\n { Timestamp: false, Serial: false },\n );\n\n const utilityTypeImports: string[] = [\"type Generated\"];\n if (globalUsedUtilityTypes.Timestamp) {\n utilityTypeImports.push(\"type Timestamp\");\n }\n const hasObjectColumnType = namespaceData.some((ns) =>\n ns.types.some((t) => t.typeDef.includes(\"ObjectColumnType<\")),\n );\n if (hasObjectColumnType) {\n utilityTypeImports.push(\"type ObjectColumnType\");\n }\n const hasArrayColumnType = namespaceData.some((ns) =>\n ns.types.some((t) => t.typeDef.includes(\"ArrayColumnType<\")),\n );\n if (hasArrayColumnType) {\n utilityTypeImports.push(\"type ArrayColumnType\");\n }\n if (globalUsedUtilityTypes.Serial) {\n utilityTypeImports.push(\"type Serial\");\n }\n\n const importsSection = multiline /* ts */ `\n import {\n createGetDB,\n ${utilityTypeImports.join(\",\\n\")},\n type NamespaceDB,\n type NamespaceInsertable,\n type NamespaceSelectable,\n type NamespaceTable,\n type NamespaceTableName,\n type NamespaceTransaction,\n type NamespaceUpdateable,\n } from \"@tailor-platform/sdk/kysely\";\n `;\n\n // Generate Namespace interface with multiple namespaces\n const namespaceInterfaces = namespaceData\n .map(({ namespace, types }) => {\n const typeDefsWithIndent = types\n .map((type) => {\n return type.typeDef\n .split(\"\\n\")\n .map((line) => (line.trim() ? ` ${line}` : \"\"))\n .join(\"\\n\");\n })\n .join(\"\\n\\n\");\n\n return ` \"${namespace}\": {\\n${typeDefsWithIndent}\\n }`;\n })\n .join(\",\\n\");\n\n const namespaceInterface = `export interface Namespace {\\n${namespaceInterfaces}\\n}`;\n\n const getDBFunction = multiline /* ts */ `\n export const getDB = createGetDB<Namespace>();\n\n export type DB<N extends keyof Namespace = keyof Namespace> = NamespaceDB<Namespace, N>;\n `;\n\n const utilityTypeExports = multiline /* ts */ `\n export type Transaction<K extends keyof Namespace | DB = keyof Namespace> =\n NamespaceTransaction<Namespace, K>;\n\n type TableName = NamespaceTableName<Namespace>;\n export type Table<T extends TableName> = NamespaceTable<Namespace, T>;\n\n export type Insertable<T extends TableName> = NamespaceInsertable<Namespace, T>;\n export type Selectable<T extends TableName> = NamespaceSelectable<Namespace, T>;\n export type Updateable<T extends TableName> = NamespaceUpdateable<Namespace, T>;\n `;\n\n return (\n [importsSection, namespaceInterface, getDBFunction, utilityTypeExports].join(\"\\n\\n\") + \"\\n\"\n );\n}\n","import { processKyselyType, generateUnifiedKyselyTypes } from \"./type-processor\";\nimport type { KyselyTypeMetadata, KyselyNamespaceMetadata } from \"./types\";\nimport type { Plugin } from \"@/types/plugin\";\nimport type { GeneratorResult, TailorDBReadyContext } from \"@/types/plugin-generation\";\n\n/** Unique identifier for the Kysely type generator plugin. */\nexport const KyselyGeneratorID = \"@tailor-platform/kysely-type\";\n\ntype KyselyTypePluginOptions = {\n distPath: string;\n};\n\n/**\n * Plugin that generates Kysely type definitions for TailorDB types.\n * @param options - Plugin options\n * @param options.distPath - Output file path for generated types\n * @returns Plugin instance with onTailorDBReady hook\n */\nexport function kyselyTypePlugin(\n options: KyselyTypePluginOptions,\n): Plugin<unknown, KyselyTypePluginOptions> {\n return {\n id: KyselyGeneratorID,\n description: \"Generates Kysely type definitions for TailorDB types\",\n pluginConfig: options,\n\n async onTailorDBReady(\n ctx: TailorDBReadyContext<KyselyTypePluginOptions>,\n ): Promise<GeneratorResult> {\n const allNamespaceData: KyselyNamespaceMetadata[] = [];\n\n for (const ns of ctx.tailordb) {\n const typeMetadataList: KyselyTypeMetadata[] = [];\n\n for (const type of Object.values(ns.types)) {\n const metadata = await processKyselyType(type);\n typeMetadataList.push(metadata);\n }\n\n if (typeMetadataList.length === 0) continue;\n\n const usedUtilityTypes = typeMetadataList.reduce(\n (acc, type) => ({\n Timestamp: acc.Timestamp || type.usedUtilityTypes.Timestamp,\n Serial: acc.Serial || type.usedUtilityTypes.Serial,\n }),\n { Timestamp: false, Serial: false },\n );\n\n allNamespaceData.push({\n namespace: ns.namespace,\n types: typeMetadataList,\n usedUtilityTypes,\n });\n }\n\n const files: GeneratorResult[\"files\"] = [];\n if (allNamespaceData.length > 0) {\n const content = generateUnifiedKyselyTypes(allNamespaceData);\n files.push({\n path: ctx.pluginConfig.distPath,\n content,\n });\n }\n\n return { files };\n },\n };\n}\n"],"mappings":";;;;;;;;;AAgBA,SAAS,YAAY,aAA0C;CAC7D,MAAM,gBAAgB,YAAY;CAElC,IAAI,iBAAiB,MAAM,QAAQ,aAAa,GAC9C,OAAO,cACJ,KAAK,MAAkC;EAEtC,OAAO,IADO,OAAO,MAAM,WAAW,IAAI,EAAE,MAC3B;CACnB,CAAC,CAAC,CACD,KAAK,KAAK;CAEf,OAAO;AACT;;;;;;AAOA,SAAS,cAAc,aAAmD;CACxE,MAAM,SAAS,YAAY;CAC3B,IAAI,CAAC,UAAU,OAAO,WAAW,UAC/B,OAAO;EACL,MAAM;EACN,kBAAkB;GAAE,WAAW;GAAO,QAAQ;EAAM;CACtD;CAGF,MAAM,eAAe,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,WAAW,YAAY;EACvE,MAAM,SAAS,kBAAkB,MAAM;EAEvC,OAAO;GACL,WAAW,GAAG,YAFC,OAAO,aAAa,OAAO,MAAM,GAEb,IAAI,OAAO;GAC9C,kBAAkB,OAAO;EAC3B;CACF,CAAC;CAED,MAAM,yBAAyB,aAAa,QACzC,KAAK,YAAY;EAChB,WAAW,IAAI,aAAa,OAAO,iBAAiB;EACpD,QAAQ,IAAI,UAAU,OAAO,iBA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7C,iBAAiB,KAAK,QAAQ;IAChC;IAEA,IAAI,iBAAiB,WAAW,GAAG;IAEnC,MAAM,mBAAmB,iBAAiB,QACvC,KAAK,UAAU;KACd,WAAW,IAAI,aAAa,KAAK,iBAAiB;KAClD,QAAQ,IAAI,UAAU,KAAK,iBAAiB;IAC9C,IACA;KAAE,WAAW;KAAO,QAAQ;IAAM,CACpC;IAEA,iBAAiB,KAAK;KACpB,WAAW,GAAG;KACd,OAAO;KACP;IACF,CAAC;GACH;GAEA,MAAM,QAAkC,CAAC;GACzC,IAAI,iBAAiB,SAAS,GAAG;IAC/B,MAAM,UAAU,2BAA2B,gBAAgB;IAC3D,MAAM,KAAK;KACT,MAAM,IAAI,aAAa;KACvB;IACF,CAAC;GACH;GAEA,OAAO,EAAE,MAAM;EACjB;CACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-DMgIygjE.mjs","names":["#fromEncoding","#toEncoding"],"sources":["../src/vitest/mock.ts"],"sourcesContent":["/**\n * Mock controls for Tailor Platform APIs (vitest).\n *\n * Each `xMock()` factory installs `vi.fn()`-backed mocks for one platform\n * namespace onto `globalThis` when acquired, and restores the previous value\n * when the `using` scope exits. State lives in the per-acquisition vi.fns /\n * closures — there is no shared global state bag — so nested/sequential scopes\n * are isolated and namespaces never interfere with each other.\n *\n * Acquire a mock with a `using` declaration:\n *\n * ```ts\n * test(\"...\", () => {\n * using wf = mockWorkflow();\n * wf.setJobHandler(() => ({ ok: true }));\n * }); // previous workflow mock restored here\n * ```\n *\n * The friendly helpers (`setJobHandler`, `enqueueResult`, `triggeredJobs`, …)\n * are thin wrappers over the underlying vi.fns, which are also exposed directly\n * (`wf.triggerJobFunction`) for native matchers like\n * `expect(wf.triggerJobFunction).toHaveBeenCalledWith(...)`.\n */\n\nimport { type Mock, vi } from \"vitest\";\nimport {\n getRegisteredJob,\n getRegisteredWorkflow,\n TRIGGER_DEFAULT,\n} from \"@/configure/services/workflow/registry\";\nimport { assertDefined } from \"@/utils/assert\";\nimport { platformSerialize } from \"@/utils/test/platform-serialize\";\nimport {\n buildJobContext,\n clearWorkflowTestEnv,\n writeWorkflowTestEnv,\n} from \"../configure/services/workflow/test-env-key\";\nimport type { User as IdpUser } from \"../runtime/idp\";\nimport type { TailorEnv } from \"../types/env\";\n\nexport { RUNTIME_FLAG_KEY } from \"./globals\";\n\n// Re-export the base globals install/cleanup under their historical names so\n// non-environment tests (which run in the plain `node` environment) can set up\n// the base platform surface — `globalThis.tailor`, error classes — themselves.\nexport {\n installPlatformGlobals as injectMocks,\n cleanupPlatformGlobals as cleanupMocks,\n} from \"./globals\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\ntype IdpResolver = (method: string, args: unknown[], namespace: string) => unknown;\ntype FileResolver = (method: string, call: FileCall) => unknown;\ntype IconvResolver = (method: string, args: unknown[]) => unknown;\n\ntype TriggerWorkflowOptions = {\n authInvoker?: { namespace: string; machineUserName: string };\n};\ntype TriggerHandlerFn = (\n workflowName: string,\n args: unknown,\n options?: TriggerWorkflowOptions,\n) => string;\ntype WaitHandlerFn = (key: string, payload: unknown) => unknown;\ntype ResolveHandler = (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n) => unknown | Promise<unknown>;\n\n// Overloaded so TypeScript narrows to WaitHandlerFn first (giving inferred\n// `(key: string, payload: unknown) => …` for callers) before falling back\n// to the static-value form. A union type would let `unknown` swallow the\n// function variant and break inference.\ntype SetWaitHandler = {\n (handler: WaitHandlerFn): void;\n (handler: unknown): void;\n};\n\ninterface ExecutedQuery {\n query: string;\n params: unknown[];\n}\n\ninterface CreatedClient {\n namespace: string | undefined;\n ended: boolean;\n}\n\ninterface TriggeredJob {\n jobName: string;\n args: unknown;\n}\n\ninterface SecretCall {\n method: \"getSecret\" | \"getSecrets\";\n vault: string;\n name?: string;\n names?: readonly string[];\n}\n\ninterface AuthConnectionCall {\n connectionName: string;\n}\n\ninterface IdpCall {\n method: string;\n args: unknown[];\n namespace: string;\n}\n\ninterface FileCall {\n method: string;\n namespace: string;\n typeName: string;\n fieldName: string;\n recordId: string;\n}\n\ninterface IconvCall {\n method: string;\n args: unknown[];\n}\n\n// ---------------------------------------------------------------------------\n// Shared helpers\n// ---------------------------------------------------------------------------\n\n// Attach a non-enumerable `Symbol.dispose` to a facade so it works with `using`.\nfunction withDispose<T extends object>(facade: T, dispose: () => void): T & Disposable {\n Object.defineProperty(facade, Symbol.dispose, {\n value: dispose,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n return facade as T & Disposable;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction tailorRoot(): Record<string, any> {\n const g = globalThis as Record<string, unknown>;\n if (!g.tailor) {\n // Ensure the container (and the always-present context stub) exists even if\n // the base globals were not installed (e.g. a unit test that only acquires\n // a single mock without the tailor-runtime environment).\n g.tailor = { context: { getInvoker: () => null } };\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return g.tailor as Record<string, any>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction tailordbRoot(): Record<string, any> {\n const g = globalThis as Record<string, unknown>;\n if (!g.tailordb) {\n g.tailordb = {};\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return g.tailordb as Record<string, any>;\n}\n\nclass MockQueryResult {\n command: string;\n rowCount: number;\n rows: unknown[];\n\n constructor(rows: unknown[]) {\n this.command = \"\";\n this.rowCount = rows.length;\n this.rows = rows;\n }\n}\n\n// ---------------------------------------------------------------------------\n// TailorDB Mock\n// ---------------------------------------------------------------------------\n\n/**\n * Acquire a disposable mock for TailorDB operations. Installs a mock\n * `tailordb.Client` whose `queryObject` is a shared `vi.fn()` (so query\n * responses can be staged before the client is constructed). Restored on\n * dispose.\n * @returns Disposable TailorDB mock control object\n * @example\n * ```typescript\n * import { mockTailordb } from \"@tailor-platform/sdk/vitest\";\n *\n * test(\"order-based\", async () => {\n * using db = mockTailordb();\n * db.enqueueResults([], [{ age: 30 }], []); // BEGIN / SELECT / COMMIT\n * // …\n * expect(db.queryObject).toHaveBeenCalledTimes(3);\n * expect(db.Client).toHaveBeenCalledWith({ namespace: \"tailordb\" });\n * });\n * ```\n */\nexport function mockTailordb() {\n const root = tailordbRoot();\n const prevClient = root.Client;\n\n const queryObject = vi.fn(\n async (_query: string, _params: unknown[] = []): Promise<MockQueryResult> =>\n new MockQueryResult([]),\n );\n const connect = vi.fn(async (): Promise<void> => {});\n const createdClients: CreatedClient[] = [];\n\n const Client = vi.fn(function (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n config?: { namespace?: string },\n ) {\n const record: CreatedClient = { namespace: config?.namespace, ended: false };\n createdClients.push(record);\n this.connect = connect;\n this.end = vi.fn(async (): Promise<void> => {\n record.ended = true;\n });\n this.queryObject = queryObject;\n this.createTransaction = (name: string) => {\n if (!name) {\n throw new Error(\"Transaction name must be a non-empty string\");\n }\n return {\n begin: async (): Promise<void> => {},\n commit: async (): Promise<void> => {},\n rollback: async (): Promise<void> => {},\n queryObject,\n };\n };\n });\n\n root.Client = Client;\n\n const facade = {\n /** The mock `tailordb.Client` constructor (`vi.fn`). */\n Client,\n /** The shared `queryObject` `vi.fn` used by every client and transaction. */\n queryObject,\n\n /**\n * Set a fallback query resolver. Called when the enqueue queue is empty.\n * @param resolver - Function that returns rows for a given query and params\n */\n setQueryResolver(resolver: QueryResolver): void {\n queryObject.mockImplementation(\n async (query: string, params: unknown[] = []) =>\n // user resolvers may return undefined\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n new MockQueryResult(resolver(query, params) ?? []),\n );\n },\n\n /**\n * Enqueue rows for the next `queryObject` call (FIFO; takes priority over\n * `setQueryResolver`). Call with no arguments for an empty result.\n * @param rows - Row objects to return from the next `queryObject` call\n */\n enqueueResult(...rows: unknown[]): void {\n queryObject.mockImplementationOnce(async () => new MockQueryResult(rows));\n },\n\n /**\n * Enqueue rows for multiple subsequent `queryObject` calls (FIFO).\n * @param rowsList - Rows arrays, one per upcoming query\n */\n enqueueResults(...rowsList: unknown[][]): void {\n for (const rows of rowsList) {\n queryObject.mockImplementationOnce(async () => new MockQueryResult(rows));\n }\n },\n\n /**\n * All queries executed via `queryObject`, in order, derived from the vi.fn\n * call records.\n * @returns Executed queries array\n */\n get executedQueries(): ExecutedQuery[] {\n return queryObject.mock.calls.map(([query, params]) => ({\n query: query as string,\n // vitest records an omitted argument as undefined\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n params: (params as unknown[]) ?? [],\n }));\n },\n\n /**\n * All TailorDB clients created, with their namespace and end state.\n * @returns Created clients array\n */\n get createdClients(): CreatedClient[] {\n return createdClients;\n },\n\n /** Reset query responses and recorded calls (keeps the mock installed). */\n reset(): void {\n queryObject.mockReset();\n queryObject.mockImplementation(async () => new MockQueryResult([]));\n connect.mockClear();\n Client.mockClear();\n createdClients.length = 0;\n },\n };\n\n return withDispose(facade, () => {\n root.Client = prevClient;\n });\n}\n\n// ---------------------------------------------------------------------------\n// Workflow Mock\n// ---------------------------------------------------------------------------\n\n/**\n * Acquire a disposable mock for workflow operations (`tailor.workflow`).\n * Restored on dispose.\n * @returns Disposable workflow mock control object\n * @example\n * ```typescript\n * import { mockWorkflow } from \"@tailor-platform/sdk/vitest\";\n *\n * test(\"job handler\", async () => {\n * using wf = mockWorkflow();\n * wf.setJobHandler((name) => (name === \"validate\" ? { valid: true } : null));\n * await runWorkflowUnderTest(); // calls tailor.workflow.triggerJobFunction(\"validate\", {})\n * expect(wf.triggerJobFunction).toHaveBeenCalledWith(\"validate\", {});\n * });\n * ```\n */\nexport function mockWorkflow() {\n const root = tailorRoot();\n const prev = root.workflow;\n\n // Default impls (also restored by reset): run the registered body by name so a\n // `.trigger()` with no handler/result executes the real job locally.\n const defaultTriggerJob = (jobName: string, args?: unknown): unknown => {\n const body = getRegisteredJob(jobName);\n return body ? body(args, buildJobContext()) : null;\n };\n const defaultTriggerWorkflow = async (\n workflowName: string,\n args?: unknown,\n _options?: TriggerWorkflowOptions,\n ): Promise<string> => {\n const wf = getRegisteredWorkflow(workflowName);\n if (wf) await installedTriggerJobFunction(wf.mainJobName, args);\n return TRIGGER_DEFAULT;\n };\n\n // Inner vi.fns hold the overridable behavior + call recording; the installed\n // shims below cross the platform JSON boundary (serialize args + results) once\n // so every path (default body, setJobHandler, enqueueResult) is covered.\n const triggerJobFunction = vi.fn(defaultTriggerJob);\n const triggerWorkflow = vi.fn(defaultTriggerWorkflow);\n const wait = vi.fn((_key: string, _payload?: unknown): unknown => null);\n const resolve = vi.fn(\n async (\n _executionId: string,\n _key: string,\n _callback: (payload: unknown) => unknown,\n ): Promise<void> => {},\n );\n\n const installedTriggerJobFunction = (jobName: string, args?: unknown): unknown => {\n const out = triggerJobFunction(jobName, platformSerialize(args));\n return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);\n };\n\n root.workflow = {\n triggerJobFunction: installedTriggerJobFunction,\n // Preserve arity so a forwarded third `options` arg — even `undefined` — is\n // recorded, matching the real `.trigger(args, options)` call shape.\n triggerWorkflow: (...call: [string, unknown?, TriggerWorkflowOptions?]) =>\n call.length >= 3\n ? triggerWorkflow(call[0], platformSerialize(call[1]), call[2])\n : triggerWorkflow(call[0], platformSerialize(call[1])),\n wait: (key: string, payload?: unknown) => wait(key, platformSerialize(payload)),\n resolve: (executionId: string, key: string, callback: (payload: unknown) => unknown) =>\n resolve(executionId, key, (payload: unknown) => {\n const out = callback(payload);\n return out instanceof Promise\n ? out.then((v) => platformSerialize(v))\n : platformSerialize(out);\n }),\n };\n\n const facade = {\n /** The `triggerJobFunction` `vi.fn`. */\n triggerJobFunction,\n /** The `triggerWorkflow` `vi.fn`. */\n triggerWorkflow,\n /** The `wait` `vi.fn`. */\n wait,\n /** The `resolve` `vi.fn`. */\n resolve,\n\n /**\n * Set a fallback job handler. Called when the enqueue queue is empty.\n * @param handler - Function returning a result for a job name and args\n */\n setJobHandler(handler: JobHandler): void {\n triggerJobFunction.mockImplementation((name, args) => handler(name, args));\n },\n\n /**\n * Enqueue a single result for the next `triggerJobFunction` call (FIFO;\n * takes priority over `setJobHandler`).\n * @param result - Result to return from the next call\n */\n enqueueResult(result: unknown): void {\n triggerJobFunction.mockImplementationOnce(() => result);\n },\n\n /**\n * Enqueue results for multiple subsequent `triggerJobFunction` calls (FIFO).\n * @param results - Results to enqueue, one per upcoming call\n */\n enqueueResults(...results: unknown[]): void {\n for (const result of results) {\n triggerJobFunction.mockImplementationOnce(() => result);\n }\n },\n\n /**\n * All jobs triggered via `triggerJobFunction`, in order.\n * @returns Triggered jobs array\n */\n get triggeredJobs(): TriggeredJob[] {\n return triggerJobFunction.mock.calls.map(([jobName, args]) => ({\n jobName: jobName as string,\n args,\n }));\n },\n\n /**\n * Configure what `triggerWorkflow` returns. Pass a string (same id every\n * call) or `(name, args, options) => string`. Default: a placeholder UUID.\n * @param handler - Static execution ID or a function returning one\n */\n setTriggerHandler(handler: string | TriggerHandlerFn): void {\n triggerWorkflow.mockImplementation(\n typeof handler === \"function\"\n ? async (name, args, options) => handler(name, args, options)\n : async () => handler,\n );\n },\n\n /**\n * Configure what `wait` returns. Pass `(key, payload) => unknown` or any\n * other value to return it for every call. Default: `null`.\n * @param handler - Static value or a function returning one\n */\n setWaitHandler: ((handler: unknown) => {\n wait.mockImplementation(\n typeof handler === \"function\"\n ? (key, payload) => (handler as WaitHandlerFn)(key, payload)\n : () => handler,\n );\n }) as SetWaitHandler,\n\n /**\n * Set the `env` passed to job bodies invoked via `createWorkflowJob().trigger()`.\n * Cleared on dispose / reset.\n * @param env - Env passed to job bodies.\n */\n setEnv(env: TailorEnv): void {\n writeWorkflowTestEnv({ ...env });\n },\n\n /**\n * Configure how `resolve` runs the user-supplied callback. Default: callback\n * is not invoked (records the call only).\n * @param handler - Function invoked per `resolve` call\n */\n setResolveHandler(handler: ResolveHandler): void {\n resolve.mockImplementation(async (executionId, key, callback) => {\n await handler(executionId, key, callback);\n });\n },\n\n /**\n * `wait` calls reshaped as `{ key, payload }` for assertions.\n * @returns Wait call records\n */\n get waitCalls(): { key: string; payload: unknown }[] {\n return wait.mock.calls.map(([key, payload]) => ({ key: key as string, payload }));\n },\n\n /**\n * `resolve` calls reshaped as `{ executionId, key }` for assertions.\n * @returns Resolve call records\n */\n get resolveCalls(): { executionId: string; key: string }[] {\n return resolve.mock.calls.map(([executionId, key]) => ({\n executionId: executionId as string,\n key: key as string,\n }));\n },\n\n /** Reset all workflow responses and recorded calls (keeps the mock installed). */\n reset(): void {\n triggerJobFunction.mockReset();\n triggerJobFunction.mockImplementation(defaultTriggerJob);\n triggerWorkflow.mockReset();\n triggerWorkflow.mockImplementation(defaultTriggerWorkflow);\n wait.mockReset();\n wait.mockImplementation(() => null);\n resolve.mockReset();\n resolve.mockImplementation(async () => {});\n clearWorkflowTestEnv();\n },\n };\n\n return withDispose(facade, () => {\n root.workflow = prev;\n clearWorkflowTestEnv();\n });\n}\n\n// ---------------------------------------------------------------------------\n// SecretManager Mock\n// ---------------------------------------------------------------------------\n\n// Hidden accessor key used to inherit the previous scope's secret store on\n// acquisition (so secrets seeded once outside tests — e.g. from tailor.config.ts\n// via setup.ts — remain visible) while still isolating per-test overrides.\nconst SECRET_STORE = Symbol(\"tailorSecretStore\");\n\n/**\n * Acquire a disposable mock for `tailor.secretmanager`. The secret store is\n * inherited (cloned) from the currently-installed mock on acquisition and\n * restored on dispose, so secrets seeded outside the test survive across\n * `using` scopes while per-test `setSecrets()` overrides stay isolated.\n * @returns Disposable SecretManager mock control object\n * @example\n * ```typescript\n * import { mockSecretmanager } from \"@tailor-platform/sdk/vitest\";\n *\n * test(\"reads secrets from vault\", async () => {\n * using sm = mockSecretmanager();\n * sm.setSecrets({ \"my-vault\": { API_KEY: \"sk-123\" } });\n * // …\n * });\n * ```\n */\nexport function mockSecretmanager() {\n const root = tailorRoot();\n const prev = root.secretmanager;\n\n const holder: { store: Record<string, Record<string, string>> } = {\n // prior mock state may be absent\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n store: structuredClone((prev?.[SECRET_STORE]?.store as typeof holder.store) ?? {}),\n };\n\n const getSecret = vi.fn(\n async (vault: string, name: string): Promise<string | undefined> => holder.store[vault]?.[name],\n );\n const getSecrets = vi.fn(\n async <const T extends readonly string[]>(\n vault: string,\n names: T,\n ): Promise<Partial<Record<T[number], string>>> => {\n const vaultData = holder.store[vault] ?? {};\n const result: Record<string, string> = {};\n for (const name of names) {\n if (name in vaultData) {\n result[name] = assertDefined(vaultData[name], `vault entry missing for: ${name}`);\n }\n }\n return result as Partial<Record<T[number], string>>;\n },\n );\n\n root.secretmanager = { getSecret, getSecrets, [SECRET_STORE]: holder };\n\n const facade = {\n /** The `getSecret` `vi.fn`. */\n getSecret,\n /** The `getSecrets` `vi.fn`. */\n getSecrets,\n\n setSecrets(secrets: Record<string, Record<string, string>>): void {\n holder.store = secrets;\n },\n\n get calls(): SecretCall[] {\n // Merge both methods' calls back into chronological order via vi.fn's\n // global invocationCallOrder, so a test mixing getSecret/getSecrets sees\n // them in the order they actually ran (not all getSecret, then all getSecrets).\n const entries: { order: number; call: SecretCall }[] = [\n ...getSecret.mock.calls.map((args, i) => ({\n order: getSecret.mock.invocationCallOrder[i] ?? 0,\n call: { method: \"getSecret\" as const, vault: args[0] as string, name: args[1] as string },\n })),\n ...getSecrets.mock.calls.map((args, i) => ({\n order: getSecrets.mock.invocationCallOrder[i] ?? 0,\n call: {\n method: \"getSecrets\" as const,\n vault: args[0] as string,\n names: args[1] as readonly string[],\n },\n })),\n ];\n return entries.toSorted((a, b) => a.order - b.order).map((e) => e.call);\n },\n\n reset(): void {\n holder.store = {};\n getSecret.mockClear();\n getSecrets.mockClear();\n },\n };\n\n return withDispose(facade, () => {\n root.secretmanager = prev;\n });\n}\n\n// ---------------------------------------------------------------------------\n// AuthConnection Mock\n// ---------------------------------------------------------------------------\n\n/**\n * Acquire a disposable mock for `tailor.authconnection`. Restored on dispose.\n * @returns Disposable AuthConnection mock control object\n * @example\n * ```typescript\n * import { mockAuthconnection } from \"@tailor-platform/sdk/vitest\";\n *\n * test(\"returns configured token\", async () => {\n * using ac = mockAuthconnection();\n * ac.setTokens({ google: { access_token: \"ya29.xxx\" } });\n * // …\n * });\n * ```\n */\nexport function mockAuthconnection() {\n const root = tailorRoot();\n const prev = root.authconnection;\n\n let tokens: Record<string, unknown> = {};\n const getConnectionToken = vi.fn(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async (connectionName: string): Promise<any> =>\n tokens[connectionName] ?? { access_token: \"mock-token\" },\n );\n\n root.authconnection = { getConnectionToken };\n\n const facade = {\n /** The `getConnectionToken` `vi.fn`. */\n getConnectionToken,\n\n setTokens(value: Record<string, unknown>): void {\n tokens = value;\n },\n\n get calls(): AuthConnectionCall[] {\n return getConnectionToken.mock.calls.map(([connectionName]) => ({\n connectionName: connectionName as string,\n }));\n },\n\n reset(): void {\n tokens = {};\n getConnectionToken.mockClear();\n },\n };\n\n return withDispose(facade, () => {\n root.authconnection = prev;\n });\n}\n\n// ---------------------------------------------------------------------------\n// IDP Mock\n// ---------------------------------------------------------------------------\n\nconst IDP_DEFAULTS: Record<string, unknown> = {\n users: { users: [], nextPageToken: null, totalCount: 0 },\n user: { id: \"mock-id\", name: \"mock-user\", disabled: false },\n userByName: { id: \"mock-id\", name: \"mock-user\", disabled: false },\n createUser: { id: \"mock-id\", name: \"mock-user\", disabled: false },\n updateUser: { id: \"mock-id\", name: \"mock-user\", disabled: false },\n deleteUser: true,\n sendPasswordResetEmail: true,\n};\n\n/**\n * Acquire a disposable mock for `tailor.idp`. Restored on dispose.\n * @returns Disposable IDP mock control object\n * @example\n * ```typescript\n * import { mockIdp } from \"@tailor-platform/sdk/vitest\";\n *\n * test(\"resolver-based\", async () => {\n * using idp = mockIdp();\n * idp.setResolver((method) =>\n * method === \"user\" ? { id: \"u-1\", name: \"alice\", disabled: false } : null,\n * );\n * // …\n * });\n * ```\n */\nexport function mockIdp() {\n const root = tailorRoot();\n const prev = root.idp;\n\n const queue: unknown[] = [];\n let resolver: IdpResolver = () => null;\n const calls: IdpCall[] = [];\n\n function handle(method: string, args: unknown[], namespace: string): unknown {\n calls.push({ method, args, namespace });\n if (queue.length > 0) return queue.shift();\n const resolved = resolver(method, args, namespace);\n // Treat null and undefined alike as \"no override\".\n if (resolved != null) return resolved;\n // Clone the default so a test mutating the returned value cannot corrupt\n // the shared module-level object for subsequent tests.\n const fallback = IDP_DEFAULTS[method];\n return fallback === undefined ? undefined : structuredClone(fallback);\n }\n\n const Client = vi.fn(function (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this: any,\n config: { namespace: string },\n ) {\n const namespace = config.namespace;\n this.users = async (options?: unknown) => handle(\"users\", [options], namespace);\n this.user = async (userId: string) => handle(\"user\", [userId], namespace);\n this.userByName = async (name: string) => handle(\"userByName\", [name], namespace);\n this.createUser = async (input: unknown) => handle(\"createUser\", [input], namespace);\n this.updateUser = async (input: unknown) => handle(\"updateUser\", [input], namespace);\n this.deleteUser = async (userId: string) => handle(\"deleteUser\", [userId], namespace);\n this.sendPasswordResetEmail = async (input: unknown) =>\n handle(\"sendPasswordResetEmail\", [input], namespace);\n }) as unknown as new (config: { namespace: string }) => {\n users(options?: {\n first?: number;\n after?: string;\n query?: { ids?: string[]; names?: string[] };\n }): Promise<{ users: IdpUser[]; nextPageToken: string | null; totalCount: number }>;\n user(userId: string): Promise<IdpUser>;\n userByName(name: string): Promise<IdpUser>;\n createUser(input: { name: string; password?: string; disabled?: boolean }): Promise<IdpUser>;\n updateUser(input: {\n id: string;\n name?: string;\n password?: string;\n clearPassword?: boolean;\n disabled?: boolean;\n }): Promise<IdpUser>;\n deleteUser(userId: string): Promise<boolean>;\n sendPasswordResetEmail(input: { userId: string; redirectUri: string }): Promise<boolean>;\n };\n\n root.idp = { Client };\n\n const facade = {\n /** The mock IDP `Client` constructor (`vi.fn`). */\n Client: Client as unknown as Mock,\n\n setResolver(value: IdpResolver): void {\n resolver = value;\n },\n\n /**\n * Enqueue a single result for the next IDP call (FIFO; falls back to\n * `setResolver` when exhausted).\n * @param result - Result to return from the next IDP call\n */\n enqueueResult(result: unknown): void {\n queue.push(result);\n },\n\n /**\n * Enqueue results for multiple subsequent IDP calls.\n * @param results - Results to enqueue, one per upcoming call\n */\n enqueueResults(...results: unknown[]): void {\n queue.push(...results);\n },\n\n get calls(): IdpCall[] {\n return calls;\n },\n\n reset(): void {\n queue.length = 0;\n resolver = () => null;\n calls.length = 0;\n },\n };\n\n return withDispose(facade, () => {\n root.idp = prev;\n });\n}\n\n// ---------------------------------------------------------------------------\n// Iconv Mock\n// ---------------------------------------------------------------------------\n\n// Iconv methods return `string` for UTF-8 target encodings and `Uint8Array`\n// for any other byte-producing encoding (the platform API mirrors this).\nfunction isUtf8(encoding: unknown): boolean {\n return encoding === \"UTF8\" || encoding === \"UTF-8\";\n}\n\nfunction defaultIconvResult(method: string, args: unknown[]): unknown {\n switch (method) {\n case \"convert\":\n case \"convertBuffer\":\n return isUtf8(args[2]) ? \"\" : new Uint8Array();\n case \"decode\":\n return \"\";\n case \"encode\":\n return isUtf8(args[1]) ? \"\" : new Uint8Array();\n case \"encodings\":\n return [];\n default:\n return undefined;\n }\n}\n\n/**\n * Acquire a disposable mock for `tailor.iconv`. Restored on dispose.\n * @returns Disposable Iconv mock control object\n * @example\n * ```typescript\n * import { mockIconv } from \"@tailor-platform/sdk/vitest\";\n *\n * test(\"mock encoding conversion\", () => {\n * using iconv = mockIconv();\n * iconv.setResolver((method) => (method === \"decode\" ? \"decoded-text\" : null));\n * // …\n * });\n * ```\n */\nexport function mockIconv() {\n const root = tailorRoot();\n const prev = root.iconv;\n\n let resolver: IconvResolver | null = null;\n const calls: IconvCall[] = [];\n\n function handle(method: string, args: unknown[]): unknown {\n calls.push({ method, args: [...args] });\n if (resolver) {\n const result = resolver(method, args);\n if (result != null) return result;\n }\n return defaultIconvResult(method, args);\n }\n\n class MockIconv {\n #fromEncoding: string;\n #toEncoding: string;\n constructor(fromEncoding: string, toEncoding: string) {\n this.#fromEncoding = fromEncoding;\n this.#toEncoding = toEncoding;\n }\n convert(input: string | Uint8Array | ArrayBuffer): string | Uint8Array {\n return handle(\"convert\", [input, this.#fromEncoding, this.#toEncoding]) as\n | string\n | Uint8Array;\n }\n }\n\n root.iconv = {\n convert: (str: unknown, from: string, to: string) => handle(\"convert\", [str, from, to]),\n convertBuffer: (buf: unknown, from: string, to: string) =>\n handle(\"convertBuffer\", [buf, from, to]),\n decode: (buf: unknown, encoding: string) => handle(\"decode\", [buf, encoding]),\n encode: (str: string, encoding: string) => handle(\"encode\", [str, encoding]),\n encodings: () => handle(\"encodings\", []),\n Iconv: MockIconv,\n };\n\n const facade = {\n setResolver(value: IconvResolver): void {\n resolver = value;\n },\n\n get calls(): IconvCall[] {\n return calls;\n },\n\n reset(): void {\n resolver = null;\n calls.length = 0;\n },\n };\n\n return withDispose(facade, () => {\n root.iconv = prev;\n });\n}\n\n// ---------------------------------------------------------------------------\n// File Mock (tailordb.file)\n// ---------------------------------------------------------------------------\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst FILE_DEFAULTS: Record<string, any> = {\n upload: { metadata: { fileSize: 0, sha256sum: \"\" } },\n download: {\n data: new Uint8Array(),\n metadata: { contentType: \"\", fileSize: 0, sha256sum: \"\", lastUploadedAt: \"\" },\n },\n downloadAsBase64: {\n data: \"\",\n metadata: { contentType: \"\", fileSize: 0, sha256sum: \"\", lastUploadedAt: \"\" },\n },\n delete: undefined,\n getMetadata: { contentType: \"\", fileSize: 0, sha256sum: \"\", urlPath: \"\" },\n downloadStream: null,\n uploadStream: { metadata: { fileSize: 0, sha256sum: \"\" } },\n};\n\ntype FileStream = AsyncIterableIterator<unknown> & { close(): Promise<void> };\n\nfunction toFileStream(value: unknown): FileStream {\n if (\n value !== null &&\n typeof value === \"object\" &&\n Symbol.asyncIterator in value &&\n typeof (value as { close?: unknown }).close === \"function\"\n ) {\n return value as FileStream;\n }\n if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {\n throw new TypeError(\n \"openDownloadStream expects an iterable of StreamValue items \" +\n '(e.g. [{ type: \"chunk\", data, position }, { type: \"complete\" }]); ' +\n \"got raw bytes. Wrap the bytes in a structured chunk first.\",\n );\n }\n if (\n value !== null &&\n typeof value === \"object\" &&\n (Symbol.iterator in value || Symbol.asyncIterator in value)\n ) {\n const source = value as Iterable<unknown> | AsyncIterable<unknown>;\n const inner =\n Symbol.asyncIterator in source\n ? (source as AsyncIterable<unknown>)[Symbol.asyncIterator]()\n : (source as Iterable<unknown>)[Symbol.iterator]();\n const stream: FileStream = {\n async next() {\n const r = await inner.next();\n if (!r.done) {\n assertStreamValue(r.value);\n }\n return r.done ? { done: true as const, value: undefined } : r;\n },\n async close() {},\n [Symbol.asyncIterator]() {\n return stream;\n },\n };\n return stream;\n }\n const empty: FileStream = {\n async next() {\n return { done: true as const, value: undefined };\n },\n async close() {},\n [Symbol.asyncIterator]() {\n return empty;\n },\n };\n return empty;\n}\n\nfunction assertStreamValue(v: unknown): void {\n if (v === null || typeof v !== \"object\") {\n throw new TypeError(\n 'openDownloadStream expected a StreamValue item ({ type: \"metadata\" | \"chunk\" | \"complete\", ... }); ' +\n `got ${typeof v === \"object\" ? \"null\" : typeof v}.`,\n );\n }\n if (v instanceof ArrayBuffer || ArrayBuffer.isView(v)) {\n throw new TypeError(\n \"openDownloadStream expected a StreamValue item, got raw bytes. \" +\n 'Wrap the bytes in a structured chunk first (e.g. { type: \"chunk\", data, position }).',\n );\n }\n const type = (v as { type?: unknown }).type;\n if (type !== \"metadata\" && type !== \"chunk\" && type !== \"complete\") {\n throw new TypeError(\n 'openDownloadStream expected a StreamValue item with type \"metadata\" | \"chunk\" | \"complete\"; ' +\n `got ${JSON.stringify(type)}.`,\n );\n }\n}\n\n/**\n * Acquire a disposable mock for `tailordb.file`. Restored on dispose.\n * @returns Disposable File mock control object\n * @example\n * ```typescript\n * import { mockFile } from \"@tailor-platform/sdk/vitest\";\n *\n * test(\"mock file download\", async () => {\n * using file = mockFile();\n * file.enqueueResult({ data: new Uint8Array([1, 2, 3]), metadata: { ... } });\n * // …\n * });\n * ```\n */\nexport function mockFile() {\n const root = tailordbRoot();\n const prev = root.file;\n\n const queue: unknown[] = [];\n let resolver: FileResolver = () => null;\n const calls: FileCall[] = [];\n\n function handle(\n method: string,\n namespace: string,\n typeName: string,\n fieldName: string,\n recordId: string,\n ): unknown {\n const call: FileCall = { method, namespace, typeName, fieldName, recordId };\n calls.push(call);\n if (queue.length > 0) return queue.shift();\n const resolved = resolver(method, call);\n if (resolved != null) return resolved;\n const fallback = FILE_DEFAULTS[method];\n return fallback === undefined ? undefined : structuredClone(fallback);\n }\n\n root.file = {\n async upload(namespace: string, typeName: string, fieldName: string, recordId: string) {\n return handle(\"upload\", namespace, typeName, fieldName, recordId);\n },\n async download(namespace: string, typeName: string, fieldName: string, recordId: string) {\n return handle(\"download\", namespace, typeName, fieldName, recordId);\n },\n async downloadAsBase64(\n namespace: string,\n typeName: string,\n fieldName: string,\n recordId: string,\n ) {\n return handle(\"downloadAsBase64\", namespace, typeName, fieldName, recordId);\n },\n async delete(namespace: string, typeName: string, fieldName: string, recordId: string) {\n handle(\"delete\", namespace, typeName, fieldName, recordId);\n },\n async getMetadata(namespace: string, typeName: string, fieldName: string, recordId: string) {\n return handle(\"getMetadata\", namespace, typeName, fieldName, recordId);\n },\n async openDownloadStream(\n namespace: string,\n typeName: string,\n fieldName: string,\n recordId: string,\n ) {\n return toFileStream(handle(\"openDownloadStream\", namespace, typeName, fieldName, recordId));\n },\n async downloadStream(namespace: string, typeName: string, fieldName: string, recordId: string) {\n const resolved = handle(\"downloadStream\", namespace, typeName, fieldName, recordId);\n if (resolved != null) return resolved;\n return {\n body: new ReadableStream({\n start(c) {\n c.close();\n },\n }),\n metadata: { contentType: \"\", fileSize: 0, sha256sum: \"\", lastUploadedAt: \"\" },\n };\n },\n async uploadStream(namespace: string, typeName: string, fieldName: string, recordId: string) {\n return handle(\"uploadStream\", namespace, typeName, fieldName, recordId);\n },\n };\n\n const facade = {\n setResolver(value: FileResolver): void {\n resolver = value;\n },\n\n /**\n * Enqueue a single result for the next `tailordb.file` call (FIFO; falls\n * back to `setResolver` when exhausted).\n * @param result - Result to return from the next file call\n */\n enqueueResult(result: unknown): void {\n queue.push(result);\n },\n\n /**\n * Enqueue results for multiple subsequent `tailordb.file` calls.\n * @param results - Results to enqueue, one per upcoming call\n */\n enqueueResults(...results: unknown[]): void {\n queue.push(...results);\n },\n\n get calls(): FileCall[] {\n return calls;\n },\n\n reset(): void {\n queue.length = 0;\n resolver = () => null;\n calls.length = 0;\n },\n };\n\n return withDispose(facade, () => {\n root.file = prev;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsIA,SAAS,YAA8B,QAAW,SAAqC;CACrF,OAAO,eAAe,QAAQ,OAAO,SAAS;EAC5C,OAAO;EACP,YAAY;EACZ,UAAU;EACV,cAAc;CAChB,CAAC;CACD,OAAO;AACT;AAGA,SAAS,aAAkC;CACzC,MAAM,IAAI;CACV,IAAI,CAAC,EAAE,QAIL,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,KAAK,EAAE;CAGnD,OAAO,EAAE;AACX;AAGA,SAAS,eAAoC;CAC3C,MAAM,IAAI;CACV,IAAI,CAAC,EAAE,UACL,EAAE,WAAW,CAAC;CAGhB,OAAO,EAAE;AACX;AAEA,IAAM,kBAAN,MAAsB;CACpB;CACA;CACA;CAEA,YAAY,MAAiB;EAC3B,KAAK,UAAU;EACf,KAAK,WAAW,KAAK;EACrB,KAAK,OAAO;CACd;AACF;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,eAAe;CAC7B,MAAM,OAAO,aAAa;CAC1B,MAAM,aAAa,KAAK;CAExB,MAAM,cAAc,GAAG,GACrB,OAAO,QAAgB,UAAqB,CAAC,MAC3C,IAAI,gBAAgB,CAAC,CAAC,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A,OAAO,OAAO,oBAAoB,WAAW,UAAU,WAAW,QAAQ;EAC5E;EACA,MAAM,OAAO,WAAmB,UAAkB,WAAmB,UAAkB;GACrF,OAAO,UAAU,WAAW,UAAU,WAAW,QAAQ;EAC3D;EACA,MAAM,YAAY,WAAmB,UAAkB,WAAmB,UAAkB;GAC1F,OAAO,OAAO,eAAe,WAAW,UAAU,WAAW,QAAQ;EACvE;EACA,MAAM,mBACJ,WACA,UACA,WACA,UACA;GACA,OAAO,aAAa,OAAO,sBAAsB,WAAW,UAAU,WAAW,QAAQ,CAAC;EAC5F;EACA,MAAM,eAAe,WAAmB,UAAkB,WAAmB,UAAkB;GAC7F,MAAM,WAAW,OAAO,kBAAkB,WAAW,UAAU,WAAW,QAAQ;GAClF,IAAI,YAAY,MAAM,OAAO;GAC7B,OAAO;IACL,MAAM,IAAI,eAAe,EACvB,MAAM,GAAG;KACP,EAAE,MAAM;IACV,EACF,CAAC;IACD,UAAU;KAAE,aAAa;KAAI,UAAU;KAAG,WAAW;KAAI,gBAAgB;IAAG;GAC9E;EACF;EACA,MAAM,aAAa,WAAmB,UAAkB,WAAmB,UAAkB;GAC3F,OAAO,OAAO,gBAAgB,WAAW,UAAU,WAAW,QAAQ;EACxE;CACF;CAmCA,OAAO,YAAY;EAhCjB,YAAY,OAA2B;GACrC,WAAW;EACb;;;;;;EAOA,cAAc,QAAuB;GACnC,MAAM,KAAK,MAAM;EACnB;;;;;EAMA,eAAe,GAAG,SAA0B;GAC1C,MAAM,KAAK,GAAG,OAAO;EACvB;EAEA,IAAI,QAAoB;GACtB,OAAO;EACT;EAEA,QAAc;GACZ,MAAM,SAAS;GACf,iBAAiB;GACjB,MAAM,SAAS;EACjB;CAGsB,SAAS;EAC/B,KAAK,OAAO;CACd,CAAC;AACH"}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/utils/test/platform-serialize.ts
|
|
3
|
-
/**
|
|
4
|
-
* Validate and serialize a value as it would cross the Platform JSON boundary.
|
|
5
|
-
*
|
|
6
|
-
* Mirrors the runtime checks the platform performs on workflow arguments,
|
|
7
|
-
* wait payloads, and trigger inputs so that local tests fail in the same
|
|
8
|
-
* places production fails.
|
|
9
|
-
*
|
|
10
|
-
* Throws on:
|
|
11
|
-
* - `NaN` / `Infinity` / `-Infinity` (`JSON.stringify` would silently emit `null`)
|
|
12
|
-
* - `BigInt` (TypeError is thrown by `JSON.stringify`; we emit a clearer message)
|
|
13
|
-
* - Non-plain objects (class instances, including `Date`, `Map`, `Set`, `Error`,
|
|
14
|
-
* and user-defined DTOs whose prototype is not `Object.prototype`)
|
|
15
|
-
*
|
|
16
|
-
* The replacer reads `this[key]` so the check sees the original value before
|
|
17
|
-
* any `toJSON` conversion (e.g. `Date.prototype.toJSON`).
|
|
18
|
-
* @param value - Value to validate and round-trip
|
|
19
|
-
* @returns The JSON-normalized value (undefined/function properties stripped, etc.)
|
|
20
|
-
*/
|
|
21
|
-
function platformSerialize(value) {
|
|
22
|
-
if (value === void 0) return void 0;
|
|
23
|
-
if (typeof value === "function") throw new TypeError("platformSerialize: function is not JSON-serializable at <root>");
|
|
24
|
-
if (typeof value === "symbol") throw new TypeError("platformSerialize: Symbol is not JSON-serializable at <root>");
|
|
25
|
-
const serialized = JSON.stringify(value, function(key, val) {
|
|
26
|
-
if (typeof val === "number" && !Number.isFinite(val)) throw new TypeError(`platformSerialize: non-finite number at ${formatPath(key)}: ${String(val)}`);
|
|
27
|
-
if (typeof val === "bigint") throw new TypeError(`platformSerialize: BigInt is not JSON-serializable at ${formatPath(key)}`);
|
|
28
|
-
const raw = this[key];
|
|
29
|
-
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
|
|
30
|
-
const proto = Object.getPrototypeOf(raw);
|
|
31
|
-
if (proto !== Object.prototype && proto !== null) {
|
|
32
|
-
const ctor = raw.constructor?.name ?? "anonymous";
|
|
33
|
-
throw new TypeError(`platformSerialize: non-plain object at ${formatPath(key)} (${ctor} instance)`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return val;
|
|
37
|
-
});
|
|
38
|
-
if (serialized === void 0) throw new TypeError("platformSerialize: value is not JSON-serializable at <root>");
|
|
39
|
-
return JSON.parse(serialized);
|
|
40
|
-
}
|
|
41
|
-
function formatPath(key) {
|
|
42
|
-
return key === "" ? "<root>" : `"${key}"`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/configure/services/workflow/test-env-key.ts
|
|
47
|
-
const SLOT_KEY = "__tailorWorkflowTestEnv";
|
|
48
|
-
/**
|
|
49
|
-
* Read the test-time env slot.
|
|
50
|
-
* @returns Current env, or `undefined` when unset.
|
|
51
|
-
* @internal
|
|
52
|
-
*/
|
|
53
|
-
function readWorkflowTestEnv() {
|
|
54
|
-
return globalThis[SLOT_KEY];
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Write the test-time env slot.
|
|
58
|
-
* @param env - Env value to expose to `.trigger()` bodies.
|
|
59
|
-
* @internal
|
|
60
|
-
*/
|
|
61
|
-
function writeWorkflowTestEnv(env) {
|
|
62
|
-
globalThis[SLOT_KEY] = env;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Clear the test-time env slot.
|
|
66
|
-
* @internal
|
|
67
|
-
*/
|
|
68
|
-
function clearWorkflowTestEnv() {
|
|
69
|
-
delete globalThis[SLOT_KEY];
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Env-var fallback read by `.trigger()` when `mockWorkflow().setEnv()` is unset.
|
|
73
|
-
* @deprecated Use `mockWorkflow().setEnv()` from `@tailor-platform/sdk/vitest`.
|
|
74
|
-
* @internal
|
|
75
|
-
*/
|
|
76
|
-
const WORKFLOW_TEST_ENV_KEY = "TAILOR_TEST_WORKFLOW_ENV";
|
|
77
|
-
function buildJobContext() {
|
|
78
|
-
const fromGlobal = readWorkflowTestEnv();
|
|
79
|
-
if (fromGlobal !== void 0) return { env: { ...fromGlobal } };
|
|
80
|
-
const raw = process.env[WORKFLOW_TEST_ENV_KEY];
|
|
81
|
-
if (!raw) return { env: {} };
|
|
82
|
-
let parsed;
|
|
83
|
-
try {
|
|
84
|
-
parsed = JSON.parse(raw);
|
|
85
|
-
} catch (cause) {
|
|
86
|
-
throw new Error(`Invalid JSON in ${WORKFLOW_TEST_ENV_KEY}; provide valid JSON or use mockWorkflow().setEnv().`, { cause });
|
|
87
|
-
}
|
|
88
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(`${WORKFLOW_TEST_ENV_KEY} must be a JSON object; provide a record or use mockWorkflow().setEnv().`);
|
|
89
|
-
return { env: { ...parsed } };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/configure/services/workflow/registry.ts
|
|
94
|
-
const JOB_REGISTRY_KEY = Symbol.for("tailor-platform/sdk:job-registry");
|
|
95
|
-
const WORKFLOW_REGISTRY_KEY = Symbol.for("tailor-platform/sdk:workflow-registry");
|
|
96
|
-
function jobs() {
|
|
97
|
-
const g = globalThis;
|
|
98
|
-
let map = g[JOB_REGISTRY_KEY];
|
|
99
|
-
if (!map) {
|
|
100
|
-
map = /* @__PURE__ */ new Map();
|
|
101
|
-
g[JOB_REGISTRY_KEY] = map;
|
|
102
|
-
}
|
|
103
|
-
return map;
|
|
104
|
-
}
|
|
105
|
-
function workflows() {
|
|
106
|
-
const g = globalThis;
|
|
107
|
-
let map = g[WORKFLOW_REGISTRY_KEY];
|
|
108
|
-
if (!map) {
|
|
109
|
-
map = /* @__PURE__ */ new Map();
|
|
110
|
-
g[WORKFLOW_REGISTRY_KEY] = map;
|
|
111
|
-
}
|
|
112
|
-
return map;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Register a job body keyed by job name. Called as a side effect by
|
|
116
|
-
* `createWorkflowJob` so the vitest mock can execute the body when
|
|
117
|
-
* `globalThis.tailor.workflow.triggerJobFunction(name, args)` is invoked.
|
|
118
|
-
*
|
|
119
|
-
* In production builds the bundler rewrites `.trigger()` calls so this registry
|
|
120
|
-
* is never read; the gated write is dropped as dead code.
|
|
121
|
-
* @param name - Job name
|
|
122
|
-
* @param body - Job body function
|
|
123
|
-
*/
|
|
124
|
-
function registerJob(name, body) {
|
|
125
|
-
jobs().set(name, body);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Look up a registered job body by name.
|
|
129
|
-
* @param name - Job name
|
|
130
|
-
* @returns The registered body, or undefined when no job is registered
|
|
131
|
-
*/
|
|
132
|
-
function getRegisteredJob(name) {
|
|
133
|
-
return jobs().get(name);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Register a workflow's main job name so the mock can run the workflow locally.
|
|
137
|
-
* @param name - Workflow name
|
|
138
|
-
* @param mainJobName - Name of the workflow's main job
|
|
139
|
-
*/
|
|
140
|
-
function registerWorkflow(name, mainJobName) {
|
|
141
|
-
workflows().set(name, { mainJobName });
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Look up a registered workflow by name.
|
|
145
|
-
* @param name - Workflow name
|
|
146
|
-
* @returns The registered workflow, or undefined
|
|
147
|
-
*/
|
|
148
|
-
function getRegisteredWorkflow(name) {
|
|
149
|
-
return workflows().get(name);
|
|
150
|
-
}
|
|
151
|
-
function currentPlatformWorkflow() {
|
|
152
|
-
return globalThis.tailor?.workflow;
|
|
153
|
-
}
|
|
154
|
-
const TRIGGER_DEFAULT = "00000000-0000-4000-8000-000000000000";
|
|
155
|
-
function serializeReturn(out) {
|
|
156
|
-
return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);
|
|
157
|
-
}
|
|
158
|
-
function runRegisteredJob(name, args) {
|
|
159
|
-
const body = getRegisteredJob(name);
|
|
160
|
-
return serializeReturn(body ? body(platformSerialize(args), buildJobContext()) : null);
|
|
161
|
-
}
|
|
162
|
-
async function runRegisteredWorkflow(name, args) {
|
|
163
|
-
const workflow = getRegisteredWorkflow(name);
|
|
164
|
-
if (workflow) await runRegisteredJob(workflow.mainJobName, args);
|
|
165
|
-
return TRIGGER_DEFAULT;
|
|
166
|
-
}
|
|
167
|
-
function dispatchTriggerJob(name, args) {
|
|
168
|
-
const workflow = currentPlatformWorkflow();
|
|
169
|
-
return workflow ? workflow.triggerJobFunction(name, args) : runRegisteredJob(name, args);
|
|
170
|
-
}
|
|
171
|
-
function dispatchTriggerWorkflow(name, args, options) {
|
|
172
|
-
const workflow = currentPlatformWorkflow();
|
|
173
|
-
return workflow ? workflow.triggerWorkflow(name, args, options) : runRegisteredWorkflow(name, args);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
//#endregion
|
|
177
|
-
export { getRegisteredWorkflow as a, runRegisteredJob as c, buildJobContext as d, clearWorkflowTestEnv as f, getRegisteredJob as i, runRegisteredWorkflow as l, platformSerialize as m, dispatchTriggerJob as n, registerJob as o, writeWorkflowTestEnv as p, dispatchTriggerWorkflow as r, registerWorkflow as s, TRIGGER_DEFAULT as t, WORKFLOW_TEST_ENV_KEY as u };
|
|
178
|
-
//# sourceMappingURL=registry-D0uB0OrK.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry-D0uB0OrK.mjs","names":[],"sources":["../src/utils/test/platform-serialize.ts","../src/configure/services/workflow/test-env-key.ts","../src/configure/services/workflow/registry.ts"],"sourcesContent":["/**\n * Validate and serialize a value as it would cross the Platform JSON boundary.\n *\n * Mirrors the runtime checks the platform performs on workflow arguments,\n * wait payloads, and trigger inputs so that local tests fail in the same\n * places production fails.\n *\n * Throws on:\n * - `NaN` / `Infinity` / `-Infinity` (`JSON.stringify` would silently emit `null`)\n * - `BigInt` (TypeError is thrown by `JSON.stringify`; we emit a clearer message)\n * - Non-plain objects (class instances, including `Date`, `Map`, `Set`, `Error`,\n * and user-defined DTOs whose prototype is not `Object.prototype`)\n *\n * The replacer reads `this[key]` so the check sees the original value before\n * any `toJSON` conversion (e.g. `Date.prototype.toJSON`).\n * @param value - Value to validate and round-trip\n * @returns The JSON-normalized value (undefined/function properties stripped, etc.)\n */\nexport function platformSerialize<T>(value: T): T {\n // Top-level undefined is allowed (jobs may take no input).\n if (value === undefined) return undefined as T;\n\n // Root function/symbol stringify to `undefined`; throw a specific message here.\n if (typeof value === \"function\") {\n throw new TypeError(\"platformSerialize: function is not JSON-serializable at <root>\");\n }\n if (typeof value === \"symbol\") {\n throw new TypeError(\"platformSerialize: Symbol is not JSON-serializable at <root>\");\n }\n\n const serialized = JSON.stringify(value, function (key, val) {\n if (typeof val === \"number\" && !Number.isFinite(val)) {\n throw new TypeError(\n `platformSerialize: non-finite number at ${formatPath(key)}: ${String(val)}`,\n );\n }\n if (typeof val === \"bigint\") {\n throw new TypeError(\n `platformSerialize: BigInt is not JSON-serializable at ${formatPath(key)}`,\n );\n }\n // Look at the pre-toJSON value so Date/Map/Set/etc. can be detected.\n const raw = (this as Record<string, unknown>)[key];\n if (raw !== null && typeof raw === \"object\" && !Array.isArray(raw)) {\n const proto = Object.getPrototypeOf(raw);\n if (proto !== Object.prototype && proto !== null) {\n const ctor = (raw as { constructor?: { name?: string } }).constructor?.name ?? \"anonymous\";\n throw new TypeError(\n `platformSerialize: non-plain object at ${formatPath(key)} (${ctor} instance)`,\n );\n }\n }\n return val;\n });\n\n // `JSON.stringify` returns `undefined` when the root collapses (e.g. a `toJSON`\n // returning `undefined`); parsing that would throw opaquely.\n // JSON.stringify returns undefined for non-serializable values\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (serialized === undefined) {\n throw new TypeError(\"platformSerialize: value is not JSON-serializable at <root>\");\n }\n\n return JSON.parse(serialized) as T;\n}\n\nfunction formatPath(key: string): string {\n return key === \"\" ? \"<root>\" : `\"${key}\"`;\n}\n","/**\n * Typed accessors for the test-time globalThis slot used to pass `env` from\n * `mockWorkflow().setEnv()` (in `@tailor-platform/sdk/vitest`) to\n * `createWorkflowJob().trigger()` bodies. The slot key is private to this\n * module; callers go through the get/set/clear functions below so both sides\n * share the same access path.\n *\n * Lives in its own file (with no `@/` imports) so `vitest/mock.ts` can load\n * it from nested Vitest configs that do not resolve `@/` aliases.\n * @internal\n */\nimport type { TailorEnv } from \"../../../types/env\";\nimport type { TailorInvoker } from \"../../../types/user\";\n\nconst SLOT_KEY = \"__tailorWorkflowTestEnv\";\n\n/**\n * Read the test-time env slot.\n * @returns Current env, or `undefined` when unset.\n * @internal\n */\nexport function readWorkflowTestEnv(): TailorEnv | undefined {\n return (globalThis as unknown as Record<string, TailorEnv | undefined>)[SLOT_KEY];\n}\n\n/**\n * Write the test-time env slot.\n * @param env - Env value to expose to `.trigger()` bodies.\n * @internal\n */\nexport function writeWorkflowTestEnv(env: TailorEnv): void {\n (globalThis as unknown as Record<string, TailorEnv>)[SLOT_KEY] = env;\n}\n\n/**\n * Clear the test-time env slot.\n * @internal\n */\nexport function clearWorkflowTestEnv(): void {\n delete (globalThis as unknown as Record<string, unknown>)[SLOT_KEY];\n}\n\n/**\n * Env-var fallback read by `.trigger()` when `mockWorkflow().setEnv()` is unset.\n * @deprecated Use `mockWorkflow().setEnv()` from `@tailor-platform/sdk/vitest`.\n * @internal\n */\nexport const WORKFLOW_TEST_ENV_KEY = \"TAILOR_TEST_WORKFLOW_ENV\";\n\n// env from `mockWorkflow().setEnv()`, else the deprecated env-var. Shallow-copied\n// to isolate against cross-trigger mutation.\nexport function buildJobContext(): { env: TailorEnv; invoker?: TailorInvoker } {\n const fromGlobal = readWorkflowTestEnv();\n if (fromGlobal !== undefined) return { env: { ...fromGlobal } };\n const raw = process.env[WORKFLOW_TEST_ENV_KEY];\n if (!raw) return { env: {} as TailorEnv };\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (cause) {\n throw new Error(\n `Invalid JSON in ${WORKFLOW_TEST_ENV_KEY}; provide valid JSON or use mockWorkflow().setEnv().`,\n { cause },\n );\n }\n if (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n throw new Error(\n `${WORKFLOW_TEST_ENV_KEY} must be a JSON object; provide a record or use mockWorkflow().setEnv().`,\n );\n }\n return { env: { ...(parsed as TailorEnv) } };\n}\n","import { platformSerialize } from \"@/utils/test/platform-serialize\";\nimport { buildJobContext } from \"./test-env-key\";\nimport type { TailorEnv } from \"@/types/env\";\nimport type { TailorInvoker } from \"@/types/user\";\n\n/**\n * Body signature shared by workflow jobs at registry-write time.\n * The user's `createWorkflowJob`/`createWorkflow` body uses concrete types,\n * but the registry erases them for storage.\n */\nexport type RegisteredJobBody = (\n args: unknown,\n context: { env: TailorEnv; invoker?: TailorInvoker },\n) => unknown | Promise<unknown>;\n\nexport interface RegisteredWorkflow {\n mainJobName: string;\n}\n\nconst JOB_REGISTRY_KEY: unique symbol = Symbol.for(\"tailor-platform/sdk:job-registry\");\nconst WORKFLOW_REGISTRY_KEY: unique symbol = Symbol.for(\"tailor-platform/sdk:workflow-registry\");\n\ntype PlatformWorkflow = {\n triggerWorkflow: (name: string, args?: unknown, options?: unknown) => Promise<string>;\n triggerJobFunction: (name: string, args?: unknown) => unknown;\n};\n\ntype GlobalWithRegistry = typeof globalThis & {\n [JOB_REGISTRY_KEY]?: Map<string, RegisteredJobBody>;\n [WORKFLOW_REGISTRY_KEY]?: Map<string, RegisteredWorkflow>;\n tailor?: { workflow?: PlatformWorkflow };\n};\n\nfunction jobs(): Map<string, RegisteredJobBody> {\n const g = globalThis as GlobalWithRegistry;\n let map = g[JOB_REGISTRY_KEY];\n if (!map) {\n map = new Map();\n g[JOB_REGISTRY_KEY] = map;\n }\n return map;\n}\n\nfunction workflows(): Map<string, RegisteredWorkflow> {\n const g = globalThis as GlobalWithRegistry;\n let map = g[WORKFLOW_REGISTRY_KEY];\n if (!map) {\n map = new Map();\n g[WORKFLOW_REGISTRY_KEY] = map;\n }\n return map;\n}\n\n/**\n * Register a job body keyed by job name. Called as a side effect by\n * `createWorkflowJob` so the vitest mock can execute the body when\n * `globalThis.tailor.workflow.triggerJobFunction(name, args)` is invoked.\n *\n * In production builds the bundler rewrites `.trigger()` calls so this registry\n * is never read; the gated write is dropped as dead code.\n * @param name - Job name\n * @param body - Job body function\n */\nexport function registerJob(name: string, body: RegisteredJobBody): void {\n jobs().set(name, body);\n}\n\n/**\n * Look up a registered job body by name.\n * @param name - Job name\n * @returns The registered body, or undefined when no job is registered\n */\nexport function getRegisteredJob(name: string): RegisteredJobBody | undefined {\n return jobs().get(name);\n}\n\n/**\n * Register a workflow's main job name so the mock can run the workflow locally.\n * @param name - Workflow name\n * @param mainJobName - Name of the workflow's main job\n */\nexport function registerWorkflow(name: string, mainJobName: string): void {\n workflows().set(name, { mainJobName });\n}\n\n/**\n * Look up a registered workflow by name.\n * @param name - Workflow name\n * @returns The registered workflow, or undefined\n */\nexport function getRegisteredWorkflow(name: string): RegisteredWorkflow | undefined {\n return workflows().get(name);\n}\n\nfunction currentPlatformWorkflow(): PlatformWorkflow | undefined {\n // globalThis may not have the tailor property at runtime\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n return (globalThis as GlobalWithRegistry).tailor?.workflow;\n}\n\n// A valid placeholder UUID, so callers that validate the execution id behave the\n// same locally as against the platform.\nexport const TRIGGER_DEFAULT = \"00000000-0000-4000-8000-000000000000\";\n\nfunction serializeReturn(out: unknown): unknown {\n return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);\n}\n\n// Runs the registered body across the platform JSON boundary. Shared by the\n// `tailor-runtime` default runner and the no-shim `.trigger()` fallback below.\nexport function runRegisteredJob(name: string, args?: unknown): unknown {\n const body = getRegisteredJob(name);\n const out = body ? body(platformSerialize(args), buildJobContext()) : null;\n return serializeReturn(out);\n}\n\nexport async function runRegisteredWorkflow(name: string, args?: unknown): Promise<string> {\n const workflow = getRegisteredWorkflow(name);\n if (workflow) await runRegisteredJob(workflow.mainJobName, args);\n return TRIGGER_DEFAULT;\n}\n\n// `.trigger()` routes through the installed `tailor.workflow` shim, falling back\n// to running the registered body/workflow locally when none is installed.\nexport function dispatchTriggerJob(name: string, args?: unknown): unknown {\n const workflow = currentPlatformWorkflow();\n return workflow ? workflow.triggerJobFunction(name, args) : runRegisteredJob(name, args);\n}\n\nexport function dispatchTriggerWorkflow(\n name: string,\n args?: unknown,\n options?: unknown,\n): Promise<string> {\n const workflow = currentPlatformWorkflow();\n return workflow\n ? workflow.triggerWorkflow(name, args, options)\n : runRegisteredWorkflow(name, args);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBAAqB,OAAa;CAEhD,IAAI,UAAU,QAAW,OAAO;CAGhC,IAAI,OAAO,UAAU,YACnB,MAAM,IAAI,UAAU,gEAAgE;CAEtF,IAAI,OAAO,UAAU,UACnB,MAAM,IAAI,UAAU,8DAA8D;CAGpF,MAAM,aAAa,KAAK,UAAU,OAAO,SAAU,KAAK,KAAK;EAC3D,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,SAAS,GAAG,GACjD,MAAM,IAAI,UACR,2CAA2C,WAAW,GAAG,EAAE,IAAI,OAAO,GAAG,GAC3E;EAEF,IAAI,OAAO,QAAQ,UACjB,MAAM,IAAI,UACR,yDAAyD,WAAW,GAAG,GACzE;EAGF,MAAM,MAAO,KAAiC;EAC9C,IAAI,QAAQ,QAAQ,OAAO,QAAQ,YAAY,CAAC,MAAM,QAAQ,GAAG,GAAG;GAClE,MAAM,QAAQ,OAAO,eAAe,GAAG;GACvC,IAAI,UAAU,OAAO,aAAa,UAAU,MAAM;IAChD,MAAM,OAAQ,IAA4C,aAAa,QAAQ;IAC/E,MAAM,IAAI,UACR,0CAA0C,WAAW,GAAG,EAAE,IAAI,KAAK,WACrE;GACF;EACF;EACA,OAAO;CACT,CAAC;CAMD,IAAI,eAAe,QACjB,MAAM,IAAI,UAAU,6DAA6D;CAGnF,OAAO,KAAK,MAAM,UAAU;AAC9B;AAEA,SAAS,WAAW,KAAqB;CACvC,OAAO,QAAQ,KAAK,WAAW,IAAI,IAAI;AACzC;;;;ACtDA,MAAM,WAAW;;;;;;AAOjB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