@tailor-platform/sdk 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +103 -0
- package/dist/aigateway-DsWDjzk4.mjs +2 -0
- package/dist/{aigateway-DR4Kwuik.mjs.map → aigateway-DsWDjzk4.mjs.map} +1 -1
- package/dist/application-DFOUovmN.mjs +1 -0
- package/dist/application-D_4vg1KR.mjs +192 -0
- package/dist/application-D_4vg1KR.mjs.map +1 -0
- package/dist/assert-WeXvmG4j.mjs +2 -0
- package/dist/{assert-DBxo8jPo.mjs.map → assert-WeXvmG4j.mjs.map} +1 -1
- package/dist/authconnection-CynFBIv8.mjs +2 -0
- package/dist/{authconnection-CZvi9ANm.mjs.map → authconnection-CynFBIv8.mjs.map} +1 -1
- package/dist/brand-C8nMKhJC.mjs +2 -0
- package/dist/{brand-Eo4pLXPJ.mjs.map → brand-C8nMKhJC.mjs.map} +1 -1
- package/dist/cli/commands/deploy/deploy.d.mts +2 -2
- package/dist/cli/commands/deploy/deployment-target.d.mts +2 -0
- package/dist/cli/commands/deploy/event-subscriptions.d.mts +3 -0
- package/dist/cli/commands/deploy/tailordb/apply.d.mts +3 -0
- package/dist/cli/commands/deploy/tailordb/index.d.mts +3 -10
- package/dist/cli/commands/deploy/tailordb/migration-validation.d.mts +5 -0
- package/dist/cli/commands/deploy/tailordb/plan.d.mts +8 -0
- package/dist/cli/commands/executor/jobs.d.mts +1 -1
- package/dist/cli/commands/generate/seed/bundler.d.mts +2 -2
- package/dist/cli/commands/show.d.mts +1 -1
- package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +11 -11
- package/dist/cli/commands/tailordb/migrate/generate.d.mts +4 -0
- package/dist/cli/commands/tailordb/migrate/rename-detection.d.mts +1 -1
- package/dist/cli/commands/tailordb/migrate/snapshot-comparison.d.mts +43 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-files.d.mts +62 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-local.d.mts +12 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-migrations.d.mts +12 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-remote.d.mts +1 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-types.d.mts +3 -1
- package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +5 -117
- package/dist/cli/lib.d.mts +8 -4
- package/dist/cli/lib.mjs +1 -9
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/cli/main.mjs +1170 -7754
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/shared/seed-chunker.d.mts +5 -5
- package/dist/completion/zsh-worker.zsh +82 -9
- package/dist/configure/config/index.d.mts +1 -1
- package/dist/configure/config/types.d.mts +2 -2
- package/dist/configure/index.d.mts +48 -12
- package/dist/configure/index.mjs +1 -1267
- package/dist/configure/index.mjs.map +1 -1
- package/dist/configure/services/auth/types.d.mts +1 -1
- package/dist/configure/services/idp/types.d.mts +1 -1
- package/dist/configure/services/tailordb/schema.d.mts +4 -8
- package/dist/configure/services/tailordb/types.d.mts +1 -1
- package/dist/configure/services/workflow/execution-policy.d.mts +3 -3
- package/dist/configure/services/workflow/job.d.mts +12 -2
- package/dist/configure/types/field.types.d.mts +1 -1
- package/dist/configure/types/permission-operand.types.d.mts +1 -1
- package/dist/context-D0QjfxzD.mjs +2 -0
- package/dist/{context-DYQVYWqZ.mjs.map → context-D0QjfxzD.mjs.map} +1 -1
- package/dist/crashreport-B-_HTKLr.mjs +42 -0
- package/dist/{crashreport-Q0pDAlrj.mjs.map → crashreport-B-_HTKLr.mjs.map} +1 -1
- package/dist/crashreport-BmsRIdpy.mjs +1 -0
- package/dist/errors-DSEXKRVD.mjs +2 -0
- package/dist/errors-DSEXKRVD.mjs.map +1 -0
- package/dist/file-COPYfju_.mjs +2 -0
- package/dist/file-COPYfju_.mjs.map +1 -0
- package/dist/globals-CMHSnj4w.mjs +2 -0
- package/dist/{globals-B2nlxBrz.mjs.map → globals-CMHSnj4w.mjs.map} +1 -1
- package/dist/iconv-DlFMt2gW.mjs +2 -0
- package/dist/{iconv-QWaZh0TT.mjs.map → iconv-DlFMt2gW.mjs.map} +1 -1
- package/dist/idp-G_ojPBB5.mjs +2 -0
- package/dist/{idp-RA_swu-h.mjs.map → idp-G_ojPBB5.mjs.map} +1 -1
- package/dist/interceptor-DQg3cR_9.mjs +2 -0
- package/dist/{interceptor-e33JtsC-.mjs.map → interceptor-DQg3cR_9.mjs.map} +1 -1
- package/dist/kysely/index.mjs +1 -32
- package/dist/kysely/index.mjs.map +1 -1
- package/dist/kysely-type-BTi3BMtL.mjs +43 -0
- package/dist/kysely-type-BTi3BMtL.mjs.map +1 -0
- package/dist/logger-BcGy-u7G.mjs +9 -0
- package/dist/{logger-D0bEznPv.mjs.map → logger-BcGy-u7G.mjs.map} +1 -1
- package/dist/logger-DP2BjQ93.mjs +2 -0
- package/dist/{logger-BtX0suGY.mjs.map → logger-DP2BjQ93.mjs.map} +1 -1
- package/dist/multiline-EyzjEwn9.mjs +3 -0
- package/dist/{multiline-sfHpTZZK.mjs.map → multiline-EyzjEwn9.mjs.map} +1 -1
- package/dist/node-builtins-oBl7EbyV.mjs +2 -0
- package/dist/{node-builtins-CmaL2Cbq.mjs.map → node-builtins-oBl7EbyV.mjs.map} +1 -1
- package/dist/package-json-C690ceex.mjs +2 -0
- package/dist/{package-json-8b0O9TlX.mjs.map → package-json-C690ceex.mjs.map} +1 -1
- package/dist/package-json-CmqhDJ__.mjs +1 -0
- package/dist/parser/service/tailordb/type-source.d.mts +5 -5
- package/dist/parser/service/tailordb/types.d.mts +4 -4
- package/dist/platform-serialize-DkiTdHOt.mjs +2 -0
- package/dist/{platform-serialize-RoRtBS0v.mjs.map → platform-serialize-DkiTdHOt.mjs.map} +1 -1
- package/dist/plugin/builtin/enum-constants/index.mjs +5 -114
- package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -1
- package/dist/plugin/builtin/file-utils/index.mjs +22 -104
- package/dist/plugin/builtin/file-utils/index.mjs.map +1 -1
- package/dist/plugin/builtin/kysely-type/index.d.mts +8 -1
- package/dist/plugin/builtin/kysely-type/index.mjs +1 -275
- package/dist/plugin/builtin/seed/index.d.mts +5 -0
- package/dist/plugin/builtin/seed/index.mjs +1 -3
- package/dist/plugin/builtin/seed/seed-type-processor.d.mts +0 -2
- package/dist/plugin/{get-generated-type.d.mts → get-generated-table.d.mts} +5 -5
- package/dist/plugin/index.d.mts +3 -2
- package/dist/plugin/index.mjs +1 -251
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/types.d.mts +30 -23
- package/dist/plugin/with-context.d.mts +3 -3
- package/dist/register-ts-hook-Drnaproy.mjs +640 -0
- package/dist/register-ts-hook-Drnaproy.mjs.map +1 -0
- package/dist/registry-HlEaGvl5.mjs +2 -0
- package/dist/{registry-BIGVUrMB.mjs.map → registry-HlEaGvl5.mjs.map} +1 -1
- package/dist/repl-editor-BG1aDOfH.mjs +2 -0
- package/dist/{repl-editor-F9LotMNx.mjs.map → repl-editor-BG1aDOfH.mjs.map} +1 -1
- package/dist/runtime/aigateway.mjs +1 -3
- package/dist/runtime/authconnection.mjs +1 -3
- package/dist/runtime/context.mjs +1 -3
- package/dist/runtime/file.d.mts +21 -21
- package/dist/runtime/file.mjs +1 -3
- package/dist/runtime/globals.mjs +1 -1
- package/dist/runtime/iconv.mjs +1 -3
- package/dist/runtime/idp.mjs +1 -3
- package/dist/runtime/index.mjs +1 -11
- package/dist/runtime/logger.mjs +1 -3
- package/dist/runtime/secretmanager.mjs +1 -3
- package/dist/runtime/types.d.mts +1 -1
- package/dist/runtime/workflow.mjs +1 -3
- package/dist/schema-Ze_dI5VX.mjs +2 -0
- package/dist/schema-Ze_dI5VX.mjs.map +1 -0
- package/dist/secret-file-C9wp_FCX.mjs +2 -0
- package/dist/{secret-file-C3J4Gy8r.mjs.map → secret-file-C9wp_FCX.mjs.map} +1 -1
- package/dist/secretmanager-5olfnI1b.mjs +2 -0
- package/dist/{secretmanager-IY4UvinW.mjs.map → secretmanager-5olfnI1b.mjs.map} +1 -1
- package/dist/secretmanager-vHQoXdQz.mjs +2 -0
- package/dist/{secretmanager-CYlpffsz.mjs.map → secretmanager-vHQoXdQz.mjs.map} +1 -1
- package/dist/seed/index.mjs +8 -244
- package/dist/seed/index.mjs.map +1 -1
- package/dist/seed-DwqRFdqP.mjs +207 -0
- package/dist/seed-DwqRFdqP.mjs.map +1 -0
- package/dist/service-BVe9u2Rt.mjs +7 -0
- package/dist/service-BVe9u2Rt.mjs.map +1 -0
- package/dist/service-CpZELSBa.mjs +1 -0
- package/dist/service-DlgaUO4V.mjs +2 -0
- package/dist/{service-LTfp03ZZ.mjs.map → service-DlgaUO4V.mjs.map} +1 -1
- package/dist/service_pb-DGKCLuAs.mjs +2 -0
- package/dist/{service_pb-BEWj1pOV.mjs.map → service_pb-DGKCLuAs.mjs.map} +1 -1
- package/dist/service_pb-_aeFE-Nv.mjs +1 -0
- package/dist/telemetry-Bklv9kQY.mjs +2 -0
- package/dist/{telemetry-BRVdwh14.mjs.map → telemetry-Bklv9kQY.mjs.map} +1 -1
- package/dist/telemetry-DXHP3VVi.mjs +1 -0
- package/dist/type-source--ZNcV8RJ.mjs +2 -0
- package/dist/type-source--ZNcV8RJ.mjs.map +1 -0
- package/dist/types/executor.generated.d.mts +1 -1
- package/dist/user-agent-vdHYF3QL.mjs +2 -0
- package/dist/{user-agent-Bgsszb5I.mjs.map → user-agent-vdHYF3QL.mjs.map} +1 -1
- package/dist/utils/test/index.mjs +1 -109
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/vitest/environment.mjs +1 -41
- package/dist/vitest/environment.mjs.map +1 -1
- package/dist/vitest/index.mjs +1 -1986
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mocks/file.d.mts +8 -8
- package/dist/vitest/setup.mjs +1 -140
- package/dist/vitest/setup.mjs.map +1 -1
- package/dist/wait-point-invoker-eiP-IIux.mjs +2 -0
- package/dist/wait-point-invoker-eiP-IIux.mjs.map +1 -0
- package/dist/wait-point-registry-BrkwfyjS.mjs +2 -0
- package/dist/{wait-point-registry-TL99zotw.mjs.map → wait-point-registry-BrkwfyjS.mjs.map} +1 -1
- package/dist/workflow-Cs9ISw6j.mjs +2 -0
- package/dist/{workflow-Bamae_Yc.mjs.map → workflow-Cs9ISw6j.mjs.map} +1 -1
- package/dist/workspace_resource_pb--GeYQPXu.mjs +2 -0
- package/dist/{workspace_resource_pb-HNIL_Vfj.mjs.map → workspace_resource_pb--GeYQPXu.mjs.map} +1 -1
- package/docs/cli/function.md +66 -6
- package/docs/cli/setup.md +24 -14
- package/docs/cli/tailordb.md +2 -0
- package/docs/cli-reference.md +9 -8
- package/docs/github-actions.md +10 -9
- package/docs/migration/v2.md +13 -1
- package/docs/migration/v3.md +82 -0
- package/docs/plugin/custom.md +130 -85
- package/docs/plugin/index.md +3 -3
- package/docs/services/tailordb-migration.md +21 -7
- package/docs/services/workflow.md +10 -9
- package/package.json +11 -11
- package/postinstall.mjs +1 -1
- package/dist/aigateway-DR4Kwuik.mjs +0 -9
- package/dist/application-C8a0UJ-z.mjs +0 -6071
- package/dist/application-C8a0UJ-z.mjs.map +0 -1
- package/dist/application-D4zOiLLa.mjs +0 -3
- package/dist/assert-DBxo8jPo.mjs +0 -9
- package/dist/authconnection-CZvi9ANm.mjs +0 -9
- package/dist/brand-Eo4pLXPJ.mjs +0 -36
- package/dist/context-DYQVYWqZ.mjs +0 -23
- package/dist/crashreport-Cd4TqfZq.mjs +0 -3
- package/dist/crashreport-Q0pDAlrj.mjs +0 -427
- package/dist/errors-Bxut5_Sy.mjs +0 -89
- package/dist/errors-Bxut5_Sy.mjs.map +0 -1
- package/dist/file-BUcmVIH2.mjs +0 -58
- package/dist/file-BUcmVIH2.mjs.map +0 -1
- package/dist/globals-B2nlxBrz.mjs +0 -126
- package/dist/iconv-QWaZh0TT.mjs +0 -38
- package/dist/idp-RA_swu-h.mjs +0 -82
- package/dist/interceptor-e33JtsC-.mjs +0 -33
- package/dist/logger-BtX0suGY.mjs +0 -48
- package/dist/logger-D0bEznPv.mjs +0 -362
- package/dist/multiline-sfHpTZZK.mjs +0 -38
- package/dist/node-builtins-CmaL2Cbq.mjs +0 -36
- package/dist/package-json-8b0O9TlX.mjs +0 -17
- package/dist/package-json-Cv2Z-TqQ.mjs +0 -3
- package/dist/platform-serialize-RoRtBS0v.mjs +0 -46
- package/dist/plugin/builtin/kysely-type/index.mjs.map +0 -1
- package/dist/plugin/builtin/seed/types.d.mts +0 -2
- package/dist/register-ts-hook-Vqjza10T.mjs +0 -25679
- package/dist/register-ts-hook-Vqjza10T.mjs.map +0 -1
- package/dist/registry-BIGVUrMB.mjs +0 -54
- package/dist/repl-editor-F9LotMNx.mjs +0 -252
- package/dist/schema-D4TC4BC3.mjs +0 -640
- package/dist/schema-D4TC4BC3.mjs.map +0 -1
- package/dist/secret-file-C3J4Gy8r.mjs +0 -64
- package/dist/secretmanager-CYlpffsz.mjs +0 -13
- package/dist/secretmanager-IY4UvinW.mjs +0 -131
- package/dist/seed-Cibjmtry.mjs +0 -489
- package/dist/seed-Cibjmtry.mjs.map +0 -1
- package/dist/service-2grcAOCJ.mjs +0 -898
- package/dist/service-2grcAOCJ.mjs.map +0 -1
- package/dist/service-CaBPNDIZ.mjs +0 -3
- package/dist/service-LTfp03ZZ.mjs +0 -133
- package/dist/service_pb-BEWj1pOV.mjs +0 -167
- package/dist/service_pb-BjlhvK9E.mjs +0 -3
- package/dist/telemetry-BRVdwh14.mjs +0 -84
- package/dist/telemetry-CkbkeJxl.mjs +0 -3
- package/dist/type-source-DH_LH20p.mjs +0 -13
- package/dist/type-source-DH_LH20p.mjs.map +0 -1
- package/dist/user-agent-Bgsszb5I.mjs +0 -28
- package/dist/wait-point-invoker-__oE88_P.mjs +0 -148
- package/dist/wait-point-invoker-__oE88_P.mjs.map +0 -1
- package/dist/wait-point-registry-TL99zotw.mjs +0 -47
- package/dist/workflow-Bamae_Yc.mjs +0 -34
- package/dist/workspace_resource_pb-HNIL_Vfj.mjs +0 -860
|
@@ -1,116 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @param allEnums - All collected enum definitions
|
|
5
|
-
* @returns Generated enum constant definitions
|
|
6
|
-
*/
|
|
7
|
-
function generateUnifiedEnumConstants(allEnums) {
|
|
8
|
-
if (allEnums.length === 0) return "";
|
|
9
|
-
const enumMap = /* @__PURE__ */ new Map();
|
|
10
|
-
for (const enumDef of allEnums) enumMap.set(enumDef.name, enumDef);
|
|
11
|
-
const enumDefs = Array.from(enumMap.values()).map((e) => {
|
|
12
|
-
const members = e.values.map((v) => {
|
|
13
|
-
return ` "${v.value.replace(/[-\s]/g, "_")}": "${v.value}"`;
|
|
14
|
-
}).join(",\n");
|
|
15
|
-
const hasDescriptions = e.values.some((v) => v.description);
|
|
16
|
-
let jsDoc = "";
|
|
17
|
-
if (e.fieldDescription || hasDescriptions) {
|
|
18
|
-
const lines = [];
|
|
19
|
-
if (e.fieldDescription) {
|
|
20
|
-
lines.push(` * ${e.fieldDescription}`);
|
|
21
|
-
if (hasDescriptions) lines.push(" *");
|
|
22
|
-
}
|
|
23
|
-
if (hasDescriptions) {
|
|
24
|
-
const propertyDocs = e.values.map((v) => {
|
|
25
|
-
return ` * @property ${[v.value.replace(/[-\s]/g, "_"), v.description].filter(Boolean).join(" - ")}`;
|
|
26
|
-
});
|
|
27
|
-
lines.push(...propertyDocs);
|
|
28
|
-
}
|
|
29
|
-
if (lines.length > 0) jsDoc = `/**\n${lines.join("\n")}\n */\n`;
|
|
30
|
-
}
|
|
31
|
-
return `${`${jsDoc}export const ${e.name} = {\n${members}\n} as const;`}\n${`export type ${e.name} = (typeof ${e.name})[keyof typeof ${e.name}];`}`;
|
|
32
|
-
}).join("\n\n");
|
|
33
|
-
if (!enumDefs) return "";
|
|
34
|
-
return enumDefs + "\n";
|
|
35
|
-
}
|
|
1
|
+
function generateUnifiedEnumConstants(e){if(e.length===0)return``;let t=new Map;for(let n of e)t.set(n.name,n);let n=Array.from(t.values()).map(e=>{let t=e.values.map(e=>` "${e.value.replace(/[-\s]/g,`_`)}": "${e.value}"`).join(`,
|
|
2
|
+
`),n=e.values.some(e=>e.description),r=``;if(e.fieldDescription||n){let t=[];if(e.fieldDescription&&(t.push(` * ${e.fieldDescription}`),n&&t.push(` *`)),n){let n=e.values.map(e=>` * @property ${[e.value.replace(/[-\s]/g,`_`),e.description].filter(Boolean).join(` - `)}`);t.push(...n)}t.length>0&&(r=`/**\n${t.join(`
|
|
3
|
+
`)}\n */\n`)}return`${`${r}export const ${e.name} = {\n${t}\n} as const;`}\n${`export type ${e.name} = (typeof ${e.name})[keyof typeof ${e.name}];`}`}).join(`
|
|
36
4
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function capitalizeFirst(str) {
|
|
40
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
41
|
-
}
|
|
42
|
-
function collectEnums(type) {
|
|
43
|
-
const enums = [];
|
|
44
|
-
for (const [fieldName, parsedField] of Object.entries(type.fields)) {
|
|
45
|
-
if (parsedField.config.type === "enum" && parsedField.config.allowedValues) {
|
|
46
|
-
const enumTypeName = `${type.name}${capitalizeFirst(fieldName)}`;
|
|
47
|
-
enums.push({
|
|
48
|
-
name: enumTypeName,
|
|
49
|
-
values: parsedField.config.allowedValues,
|
|
50
|
-
fieldDescription: parsedField.config.description
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (parsedField.config.type === "nested" && parsedField.config.fields) {
|
|
54
|
-
for (const [nestedFieldName, nestedFieldConfig] of Object.entries(parsedField.config.fields)) if (nestedFieldConfig.type === "enum" && nestedFieldConfig.allowedValues) {
|
|
55
|
-
const fullFieldName = `${fieldName}${capitalizeFirst(nestedFieldName)}`;
|
|
56
|
-
const enumTypeName = `${type.name}${capitalizeFirst(fullFieldName)}`;
|
|
57
|
-
enums.push({
|
|
58
|
-
name: enumTypeName,
|
|
59
|
-
values: nestedFieldConfig.allowedValues,
|
|
60
|
-
fieldDescription: nestedFieldConfig.description
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return enums;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Process a TailorDB table and extract enum metadata.
|
|
69
|
-
* @param type - The parsed TailorDB table to process
|
|
70
|
-
* @returns Enum constant metadata for the table
|
|
71
|
-
*/
|
|
72
|
-
async function processEnumType(type) {
|
|
73
|
-
const enums = collectEnums(type);
|
|
74
|
-
return {
|
|
75
|
-
name: type.name,
|
|
76
|
-
enums
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/plugin/builtin/enum-constants/index.ts
|
|
82
|
-
/** Unique identifier for the enum constants generator plugin. */
|
|
83
|
-
const EnumConstantsGeneratorID = "@tailor-platform/enum-constants";
|
|
84
|
-
/**
|
|
85
|
-
* Plugin that generates enum constants from TailorDB table definitions.
|
|
86
|
-
* @param options - Plugin options
|
|
87
|
-
* @param options.distPath - Output file path for generated constants
|
|
88
|
-
* @returns Plugin instance with onTailorDBReady hook
|
|
89
|
-
*/
|
|
90
|
-
function enumConstantsPlugin(options) {
|
|
91
|
-
return {
|
|
92
|
-
id: EnumConstantsGeneratorID,
|
|
93
|
-
description: "Generates enum constants from TailorDB table definitions",
|
|
94
|
-
pluginConfig: options,
|
|
95
|
-
async onTailorDBReady(ctx) {
|
|
96
|
-
const allEnums = [];
|
|
97
|
-
for (const ns of ctx.tailordb) for (const type of Object.values(ns.types)) {
|
|
98
|
-
const metadata = await processEnumType(type);
|
|
99
|
-
allEnums.push(...metadata.enums);
|
|
100
|
-
}
|
|
101
|
-
const files = [];
|
|
102
|
-
if (allEnums.length > 0) {
|
|
103
|
-
const content = generateUnifiedEnumConstants(allEnums);
|
|
104
|
-
files.push({
|
|
105
|
-
path: ctx.pluginConfig.distPath,
|
|
106
|
-
content
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return { files };
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
//#endregion
|
|
115
|
-
export { EnumConstantsGeneratorID, enumConstantsPlugin };
|
|
5
|
+
`);return n?n+`
|
|
6
|
+
`:``}function capitalizeFirst(e){return e.charAt(0).toUpperCase()+e.slice(1)}function collectEnums(e){let t=[];for(let[n,r]of Object.entries(e.fields)){if(r.config.type===`enum`&&r.config.allowedValues){let i=`${e.name}${capitalizeFirst(n)}`;t.push({name:i,values:r.config.allowedValues,fieldDescription:r.config.description})}if(r.config.type===`nested`&&r.config.fields){for(let[i,a]of Object.entries(r.config.fields))if(a.type===`enum`&&a.allowedValues){let r=`${n}${capitalizeFirst(i)}`,o=`${e.name}${capitalizeFirst(r)}`;t.push({name:o,values:a.allowedValues,fieldDescription:a.description})}}}return t}async function processEnumType(e){let t=collectEnums(e);return{name:e.name,enums:t}}const e=`@tailor-platform/enum-constants`;function enumConstantsPlugin(t){return{id:e,description:`Generates enum constants from TailorDB table definitions`,pluginConfig:t,async onTailorDBReady(e){let t=[];for(let n of e.tailordb)for(let e of Object.values(n.tables)){let n=await processEnumType(e);t.push(...n.enums)}let n=[];if(t.length>0){let r=generateUnifiedEnumConstants(t);n.push({path:e.pluginConfig.distPath,content:r})}return{files:n}}}}export{e as EnumConstantsGeneratorID,enumConstantsPlugin};
|
|
116
7
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/plugin/builtin/enum-constants/generate-enum-constants.ts","../../../../src/plugin/builtin/enum-constants/process-enum-type.ts","../../../../src/plugin/builtin/enum-constants/index.ts"],"sourcesContent":["import type { EnumDefinition } from \"./types\";\n\n/**\n * Generate enum constant definitions from collected metadata.\n * @param allEnums - All collected enum definitions\n * @returns Generated enum constant definitions\n */\nexport function generateUnifiedEnumConstants(allEnums: EnumDefinition[]): string {\n if (allEnums.length === 0) {\n return \"\";\n }\n\n const enumMap = new Map<string, EnumDefinition>();\n for (const enumDef of allEnums) {\n enumMap.set(enumDef.name, enumDef);\n }\n\n const enumDefs = Array.from(enumMap.values())\n .map((e) => {\n const members = e.values\n .map((v) => {\n const key = v.value.replace(/[-\\s]/g, \"_\");\n return ` \"${key}\": \"${v.value}\"`;\n })\n .join(\",\\n\");\n\n const hasDescriptions = e.values.some((v) => v.description);\n let jsDoc = \"\";\n if (e.fieldDescription || hasDescriptions) {\n const lines: string[] = [];\n\n if (e.fieldDescription) {\n lines.push(` * ${e.fieldDescription}`);\n if (hasDescriptions) {\n lines.push(\" *\");\n }\n }\n\n if (hasDescriptions) {\n const propertyDocs = e.values.map((v) => {\n const key = v.value.replace(/[-\\s]/g, \"_\");\n return ` * @property ${[key, v.description].filter(Boolean).join(\" - \")}`;\n });\n lines.push(...propertyDocs);\n }\n\n if (lines.length > 0) {\n jsDoc = `/**\\n${lines.join(\"\\n\")}\\n */\\n`;\n }\n }\n\n const constDef = `${jsDoc}export const ${e.name} = {\\n${members}\\n} as const;`;\n const typeDef = `export type ${e.name} = (typeof ${e.name})[keyof typeof ${e.name}];`;\n return `${constDef}\\n${typeDef}`;\n })\n .join(\"\\n\\n\");\n\n if (!enumDefs) {\n return \"\";\n }\n\n return enumDefs + \"\\n\";\n}\n","import type { TailorDBType } from \"#/parser/service/tailordb/types\";\nimport type { EnumConstantMetadata } from \"./types\";\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nfunction collectEnums(type: TailorDBType): EnumConstantMetadata[\"enums\"] {\n const enums: EnumConstantMetadata[\"enums\"] = [];\n\n for (const [fieldName, parsedField] of Object.entries(type.fields)) {\n if (parsedField.config.type === \"enum\" && parsedField.config.allowedValues) {\n const enumTypeName = `${type.name}${capitalizeFirst(fieldName)}`;\n enums.push({\n name: enumTypeName,\n values: parsedField.config.allowedValues,\n fieldDescription: parsedField.config.description,\n });\n }\n\n // Process nested fields\n if (parsedField.config.type === \"nested\" && parsedField.config.fields) {\n for (const [nestedFieldName, nestedFieldConfig] of Object.entries(\n parsedField.config.fields,\n )) {\n if (nestedFieldConfig.type === \"enum\" && nestedFieldConfig.allowedValues) {\n const fullFieldName = `${fieldName}${capitalizeFirst(nestedFieldName)}`;\n const enumTypeName = `${type.name}${capitalizeFirst(fullFieldName)}`;\n enums.push({\n name: enumTypeName,\n values: nestedFieldConfig.allowedValues,\n fieldDescription: nestedFieldConfig.description,\n });\n }\n }\n }\n }\n\n return enums;\n}\n\n/**\n * Process a TailorDB table and extract enum metadata.\n * @param type - The parsed TailorDB table to process\n * @returns Enum constant metadata for the table\n */\nexport async function processEnumType(type: TailorDBType): Promise<EnumConstantMetadata> {\n const enums = collectEnums(type);\n\n return {\n name: type.name,\n enums,\n };\n}\n","import { generateUnifiedEnumConstants } from \"./generate-enum-constants\";\nimport { processEnumType } from \"./process-enum-type\";\nimport type { Plugin, GeneratorResult, TailorDBReadyContext } from \"#/plugin/types\";\nimport type { EnumDefinition } from \"./types\";\n\n/** Unique identifier for the enum constants generator plugin. */\nexport const EnumConstantsGeneratorID = \"@tailor-platform/enum-constants\";\n\ntype EnumConstantsPluginOptions = {\n distPath: string;\n};\n\n/**\n * Plugin that generates enum constants from TailorDB table 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 table 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.
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/plugin/builtin/enum-constants/generate-enum-constants.ts","../../../../src/plugin/builtin/enum-constants/process-enum-type.ts","../../../../src/plugin/builtin/enum-constants/index.ts"],"sourcesContent":["import type { EnumDefinition } from \"./types\";\n\n/**\n * Generate enum constant definitions from collected metadata.\n * @param allEnums - All collected enum definitions\n * @returns Generated enum constant definitions\n */\nexport function generateUnifiedEnumConstants(allEnums: EnumDefinition[]): string {\n if (allEnums.length === 0) {\n return \"\";\n }\n\n const enumMap = new Map<string, EnumDefinition>();\n for (const enumDef of allEnums) {\n enumMap.set(enumDef.name, enumDef);\n }\n\n const enumDefs = Array.from(enumMap.values())\n .map((e) => {\n const members = e.values\n .map((v) => {\n const key = v.value.replace(/[-\\s]/g, \"_\");\n return ` \"${key}\": \"${v.value}\"`;\n })\n .join(\",\\n\");\n\n const hasDescriptions = e.values.some((v) => v.description);\n let jsDoc = \"\";\n if (e.fieldDescription || hasDescriptions) {\n const lines: string[] = [];\n\n if (e.fieldDescription) {\n lines.push(` * ${e.fieldDescription}`);\n if (hasDescriptions) {\n lines.push(\" *\");\n }\n }\n\n if (hasDescriptions) {\n const propertyDocs = e.values.map((v) => {\n const key = v.value.replace(/[-\\s]/g, \"_\");\n return ` * @property ${[key, v.description].filter(Boolean).join(\" - \")}`;\n });\n lines.push(...propertyDocs);\n }\n\n if (lines.length > 0) {\n jsDoc = `/**\\n${lines.join(\"\\n\")}\\n */\\n`;\n }\n }\n\n const constDef = `${jsDoc}export const ${e.name} = {\\n${members}\\n} as const;`;\n const typeDef = `export type ${e.name} = (typeof ${e.name})[keyof typeof ${e.name}];`;\n return `${constDef}\\n${typeDef}`;\n })\n .join(\"\\n\\n\");\n\n if (!enumDefs) {\n return \"\";\n }\n\n return enumDefs + \"\\n\";\n}\n","import type { TailorDBType } from \"#/parser/service/tailordb/types\";\nimport type { EnumConstantMetadata } from \"./types\";\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nfunction collectEnums(type: TailorDBType): EnumConstantMetadata[\"enums\"] {\n const enums: EnumConstantMetadata[\"enums\"] = [];\n\n for (const [fieldName, parsedField] of Object.entries(type.fields)) {\n if (parsedField.config.type === \"enum\" && parsedField.config.allowedValues) {\n const enumTypeName = `${type.name}${capitalizeFirst(fieldName)}`;\n enums.push({\n name: enumTypeName,\n values: parsedField.config.allowedValues,\n fieldDescription: parsedField.config.description,\n });\n }\n\n // Process nested fields\n if (parsedField.config.type === \"nested\" && parsedField.config.fields) {\n for (const [nestedFieldName, nestedFieldConfig] of Object.entries(\n parsedField.config.fields,\n )) {\n if (nestedFieldConfig.type === \"enum\" && nestedFieldConfig.allowedValues) {\n const fullFieldName = `${fieldName}${capitalizeFirst(nestedFieldName)}`;\n const enumTypeName = `${type.name}${capitalizeFirst(fullFieldName)}`;\n enums.push({\n name: enumTypeName,\n values: nestedFieldConfig.allowedValues,\n fieldDescription: nestedFieldConfig.description,\n });\n }\n }\n }\n }\n\n return enums;\n}\n\n/**\n * Process a TailorDB table and extract enum metadata.\n * @param type - The parsed TailorDB table to process\n * @returns Enum constant metadata for the table\n */\nexport async function processEnumType(type: TailorDBType): Promise<EnumConstantMetadata> {\n const enums = collectEnums(type);\n\n return {\n name: type.name,\n enums,\n };\n}\n","import { generateUnifiedEnumConstants } from \"./generate-enum-constants\";\nimport { processEnumType } from \"./process-enum-type\";\nimport type { Plugin, GeneratorResult, TailorDBReadyContext } from \"#/plugin/types\";\nimport type { EnumDefinition } from \"./types\";\n\n/** Unique identifier for the enum constants generator plugin. */\nexport const EnumConstantsGeneratorID = \"@tailor-platform/enum-constants\";\n\ntype EnumConstantsPluginOptions = {\n distPath: string;\n};\n\n/**\n * Plugin that generates enum constants from TailorDB table 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 table 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.tables)) {\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":"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"}
|
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/plugin/builtin/file-utils/generate-file-utils.ts
|
|
4
|
-
/**
|
|
5
|
-
* Generate unified file utility functions from collected metadata.
|
|
6
|
-
* @param namespaceData - Namespace data with file utility metadata
|
|
7
|
-
* @returns Generated file utility code
|
|
8
|
-
*/
|
|
9
|
-
function generateUnifiedFileUtils(namespaceData) {
|
|
10
|
-
if (namespaceData.length === 0) return "";
|
|
11
|
-
const typeNamespaceMap = /* @__PURE__ */ new Map();
|
|
12
|
-
const typeFieldsMap = /* @__PURE__ */ new Map();
|
|
13
|
-
for (const { namespace, types } of namespaceData) for (const type of types) {
|
|
14
|
-
typeNamespaceMap.set(type.name, namespace);
|
|
15
|
-
typeFieldsMap.set(type.name, type.fileFields);
|
|
16
|
-
}
|
|
17
|
-
if (typeNamespaceMap.size === 0) return "";
|
|
18
|
-
const interfaceFields = Array.from(typeFieldsMap.entries()).map(([typeName, fields]) => {
|
|
19
|
-
return ` ${typeName}: {\n fields: ${fields.map((field) => `"${field}"`).join(" | ")};\n };`;
|
|
20
|
-
}).join("\n");
|
|
21
|
-
const importStatement = multiline`
|
|
1
|
+
import{t as e}from"../../../multiline-EyzjEwn9.mjs";function generateUnifiedFileUtils(t){if(t.length===0)return``;let n=new Map,r=new Map;for(let{namespace:e,types:i}of t)for(let t of i)n.set(t.name,e),r.set(t.name,t.fileFields);if(n.size===0)return``;let i=Array.from(r.entries()).map(([e,t])=>` ${e}: {\n fields: ${t.map(e=>`"${e}"`).join(` | `)};\n };`).join(`
|
|
2
|
+
`),a=e`
|
|
22
3
|
import { file } from "@tailor-platform/sdk/runtime/file";
|
|
23
4
|
import type {
|
|
24
5
|
FileUploadOptions,
|
|
@@ -26,22 +7,19 @@ function generateUnifiedFileUtils(namespaceData) {
|
|
|
26
7
|
FileMetadata,
|
|
27
8
|
FileDownloadStreamResponse,
|
|
28
9
|
} from "@tailor-platform/sdk/runtime/file";
|
|
29
|
-
|
|
30
|
-
|
|
10
|
+
`+`
|
|
11
|
+
`,o=e`
|
|
31
12
|
export interface TypeWithFiles {
|
|
32
|
-
${
|
|
13
|
+
${i}
|
|
33
14
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
importStatement,
|
|
38
|
-
interfaceDefinition,
|
|
39
|
-
multiline`
|
|
15
|
+
`+`
|
|
16
|
+
`,s=Array.from(n.entries()).map(([e,t])=>` ${e}: "${t}"`).join(`,
|
|
17
|
+
`);return[a,o,e`
|
|
40
18
|
const namespaces: Record<keyof TypeWithFiles, string> = {
|
|
41
|
-
${
|
|
19
|
+
${s},
|
|
42
20
|
};
|
|
43
|
-
|
|
44
|
-
|
|
21
|
+
`+`
|
|
22
|
+
`,e`
|
|
45
23
|
export async function downloadFile<T extends keyof TypeWithFiles>(
|
|
46
24
|
type: T,
|
|
47
25
|
field: TypeWithFiles[T]["fields"],
|
|
@@ -49,8 +27,8 @@ function generateUnifiedFileUtils(namespaceData) {
|
|
|
49
27
|
) {
|
|
50
28
|
return await file.download(namespaces[type], type, field, recordId);
|
|
51
29
|
}
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
`+`
|
|
31
|
+
`,e`
|
|
54
32
|
export async function uploadFile<T extends keyof TypeWithFiles>(
|
|
55
33
|
type: T,
|
|
56
34
|
field: TypeWithFiles[T]["fields"],
|
|
@@ -60,8 +38,8 @@ function generateUnifiedFileUtils(namespaceData) {
|
|
|
60
38
|
): Promise<FileUploadResponse> {
|
|
61
39
|
return await file.upload(namespaces[type], type, field, recordId, data, options);
|
|
62
40
|
}
|
|
63
|
-
|
|
64
|
-
|
|
41
|
+
`+`
|
|
42
|
+
`,e`
|
|
65
43
|
export async function deleteFile<T extends keyof TypeWithFiles>(
|
|
66
44
|
type: T,
|
|
67
45
|
field: TypeWithFiles[T]["fields"],
|
|
@@ -69,8 +47,8 @@ function generateUnifiedFileUtils(namespaceData) {
|
|
|
69
47
|
): Promise<void> {
|
|
70
48
|
return await file.delete(namespaces[type], type, field, recordId);
|
|
71
49
|
}
|
|
72
|
-
|
|
73
|
-
|
|
50
|
+
`+`
|
|
51
|
+
`,e`
|
|
74
52
|
export async function getFileMetadata<T extends keyof TypeWithFiles>(
|
|
75
53
|
type: T,
|
|
76
54
|
field: TypeWithFiles[T]["fields"],
|
|
@@ -78,8 +56,8 @@ function generateUnifiedFileUtils(namespaceData) {
|
|
|
78
56
|
): Promise<FileMetadata> {
|
|
79
57
|
return await file.getMetadata(namespaces[type], type, field, recordId);
|
|
80
58
|
}
|
|
81
|
-
|
|
82
|
-
|
|
59
|
+
`+`
|
|
60
|
+
`,e`
|
|
83
61
|
export async function downloadFileStream<T extends keyof TypeWithFiles>(
|
|
84
62
|
type: T,
|
|
85
63
|
field: TypeWithFiles[T]["fields"],
|
|
@@ -87,67 +65,7 @@ function generateUnifiedFileUtils(namespaceData) {
|
|
|
87
65
|
): Promise<FileDownloadStreamResponse> {
|
|
88
66
|
return await file.downloadStream(namespaces[type], type, field, recordId);
|
|
89
67
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/plugin/builtin/file-utils/process-file-type.ts
|
|
96
|
-
/**
|
|
97
|
-
* Process a TailorDB table and extract file field metadata.
|
|
98
|
-
* @param type - The parsed TailorDB table to process
|
|
99
|
-
* @returns File utility metadata for the table
|
|
100
|
-
*/
|
|
101
|
-
async function processFileType(type) {
|
|
102
|
-
const fileFields = [];
|
|
103
|
-
if (type.files) for (const fileFieldName of Object.keys(type.files)) fileFields.push(fileFieldName);
|
|
104
|
-
return {
|
|
105
|
-
name: type.name,
|
|
106
|
-
fileFields
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region src/plugin/builtin/file-utils/index.ts
|
|
112
|
-
/** Unique identifier for the file utilities generator plugin. */
|
|
113
|
-
const FileUtilsGeneratorID = "@tailor-platform/file-utils";
|
|
114
|
-
/**
|
|
115
|
-
* Plugin that generates TypeWithFiles interface from TailorDB table definitions.
|
|
116
|
-
* @param options - Plugin options
|
|
117
|
-
* @param options.distPath - Output file path for generated file utilities
|
|
118
|
-
* @returns Plugin instance with onTailorDBReady hook
|
|
119
|
-
*/
|
|
120
|
-
function fileUtilsPlugin(options) {
|
|
121
|
-
return {
|
|
122
|
-
id: FileUtilsGeneratorID,
|
|
123
|
-
description: "Generates TypeWithFiles interface from TailorDB table definitions",
|
|
124
|
-
pluginConfig: options,
|
|
125
|
-
async onTailorDBReady(ctx) {
|
|
126
|
-
const namespaceData = [];
|
|
127
|
-
for (const ns of ctx.tailordb) {
|
|
128
|
-
const typesWithFiles = [];
|
|
129
|
-
for (const type of Object.values(ns.types)) {
|
|
130
|
-
const metadata = await processFileType(type);
|
|
131
|
-
if (metadata.fileFields.length > 0) typesWithFiles.push(metadata);
|
|
132
|
-
}
|
|
133
|
-
if (typesWithFiles.length > 0) namespaceData.push({
|
|
134
|
-
namespace: ns.namespace,
|
|
135
|
-
types: typesWithFiles
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
const files = [];
|
|
139
|
-
if (namespaceData.length > 0) {
|
|
140
|
-
const content = generateUnifiedFileUtils(namespaceData);
|
|
141
|
-
if (content) files.push({
|
|
142
|
-
path: ctx.pluginConfig.distPath,
|
|
143
|
-
content
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
return { files };
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
//#endregion
|
|
152
|
-
export { FileUtilsGeneratorID, fileUtilsPlugin };
|
|
68
|
+
`+`
|
|
69
|
+
`].join(`
|
|
70
|
+
`)}async function processFileType(e){let t=[];if(e.files)for(let n of Object.keys(e.files))t.push(n);return{name:e.name,fileFields:t}}const t=`@tailor-platform/file-utils`;function fileUtilsPlugin(e){return{id:t,description:`Generates TypeWithFiles interface from TailorDB table definitions`,pluginConfig:e,async onTailorDBReady(e){let t=[];for(let n of e.tailordb){let e=[];for(let t of Object.values(n.tables)){let n=await processFileType(t);n.fileFields.length>0&&e.push(n)}e.length>0&&t.push({namespace:n.namespace,types:e})}let n=[];if(t.length>0){let r=generateUnifiedFileUtils(t);r&&n.push({path:e.pluginConfig.distPath,content:r})}return{files:n}}}}export{t as FileUtilsGeneratorID,fileUtilsPlugin};
|
|
153
71
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/plugin/builtin/file-utils/generate-file-utils.ts","../../../../src/plugin/builtin/file-utils/process-file-type.ts","../../../../src/plugin/builtin/file-utils/index.ts"],"sourcesContent":["import multiline from \"#/utils/multiline\";\nimport type { FileUtilMetadata } from \"./types\";\n\n/**\n * Generate unified file utility functions from collected metadata.\n * @param namespaceData - Namespace data with file utility metadata\n * @returns Generated file utility code\n */\nexport function generateUnifiedFileUtils(\n namespaceData: { namespace: string; types: FileUtilMetadata[] }[],\n): string {\n if (namespaceData.length === 0) {\n return \"\";\n }\n\n // Collect all
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/plugin/builtin/file-utils/generate-file-utils.ts","../../../../src/plugin/builtin/file-utils/process-file-type.ts","../../../../src/plugin/builtin/file-utils/index.ts"],"sourcesContent":["import multiline from \"#/utils/multiline\";\nimport type { FileUtilMetadata } from \"./types\";\n\n/**\n * Generate unified file utility functions from collected metadata.\n * @param namespaceData - Namespace data with file utility metadata\n * @returns Generated file utility code\n */\nexport function generateUnifiedFileUtils(\n namespaceData: { namespace: string; types: FileUtilMetadata[] }[],\n): string {\n if (namespaceData.length === 0) {\n return \"\";\n }\n\n // Collect all tables with their namespace\n const tableNamespaceMap = new Map<string, string>();\n const typeFieldsMap = new Map<string, string[]>();\n\n for (const { namespace, types } of namespaceData) {\n for (const type of types) {\n tableNamespaceMap.set(type.name, namespace);\n typeFieldsMap.set(type.name, type.fileFields);\n }\n }\n\n if (tableNamespaceMap.size === 0) {\n return \"\";\n }\n\n // Generate interface fields\n const interfaceFields = Array.from(typeFieldsMap.entries())\n .map(([tableName, fields]) => {\n const fieldNamesUnion = fields.map((field) => `\"${field}\"`).join(\" | \");\n return ` ${tableName}: {\\n fields: ${fieldNamesUnion};\\n };`;\n })\n .join(\"\\n\");\n\n const importStatement =\n multiline /* ts */ `\n import { file } from \"@tailor-platform/sdk/runtime/file\";\n import type {\n FileUploadOptions,\n FileUploadResponse,\n FileMetadata,\n FileDownloadStreamResponse,\n } from \"@tailor-platform/sdk/runtime/file\";\n ` + \"\\n\";\n\n const interfaceDefinition =\n multiline /* ts */ `\n export interface TypeWithFiles {\n ${interfaceFields}\n }\n ` + \"\\n\";\n\n // Generate namespaces object\n const namespaceEntries = Array.from(tableNamespaceMap.entries())\n .map(([tableName, namespace]) => ` ${tableName}: \"${namespace}\"`)\n .join(\",\\n\");\n\n const namespacesDefinition =\n multiline /* ts */ `\n const namespaces: Record<keyof TypeWithFiles, string> = {\n ${namespaceEntries},\n };\n ` + \"\\n\";\n\n // Generate downloadFile helper function\n const downloadFunction =\n multiline /* ts */ `\n export async function downloadFile<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n ) {\n return await file.download(namespaces[type], type, field, recordId);\n }\n ` + \"\\n\";\n\n // Generate uploadFile helper function\n const uploadFunction =\n multiline /* ts */ `\n export async function uploadFile<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n data: string | ArrayBuffer | Uint8Array<ArrayBufferLike> | number[],\n options?: FileUploadOptions,\n ): Promise<FileUploadResponse> {\n return await file.upload(namespaces[type], type, field, recordId, data, options);\n }\n ` + \"\\n\";\n\n // Generate deleteFile helper function\n const deleteFunction =\n multiline /* ts */ `\n export async function deleteFile<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n ): Promise<void> {\n return await file.delete(namespaces[type], type, field, recordId);\n }\n ` + \"\\n\";\n\n // Generate getFileMetadata helper function\n const getMetadataFunction =\n multiline /* ts */ `\n export async function getFileMetadata<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n ): Promise<FileMetadata> {\n return await file.getMetadata(namespaces[type], type, field, recordId);\n }\n ` + \"\\n\";\n\n // Generate downloadFileStream helper function\n const downloadStreamFunction =\n multiline /* ts */ `\n export async function downloadFileStream<T extends keyof TypeWithFiles>(\n type: T,\n field: TypeWithFiles[T][\"fields\"],\n recordId: string,\n ): Promise<FileDownloadStreamResponse> {\n return await file.downloadStream(namespaces[type], type, field, recordId);\n }\n ` + \"\\n\";\n\n return [\n importStatement,\n interfaceDefinition,\n namespacesDefinition,\n downloadFunction,\n uploadFunction,\n deleteFunction,\n getMetadataFunction,\n downloadStreamFunction,\n ].join(\"\\n\");\n}\n","import type { TailorDBType } from \"#/parser/service/tailordb/types\";\nimport type { FileUtilMetadata } from \"./types\";\n\n/**\n * Process a TailorDB table and extract file field metadata.\n * @param type - The parsed TailorDB table to process\n * @returns File utility metadata for the table\n */\nexport async function processFileType(type: TailorDBType): Promise<FileUtilMetadata> {\n const fileFields: string[] = [];\n\n if (type.files) {\n for (const fileFieldName of Object.keys(type.files)) {\n fileFields.push(fileFieldName);\n }\n }\n\n return {\n name: type.name,\n fileFields,\n };\n}\n","import { generateUnifiedFileUtils } from \"./generate-file-utils\";\nimport { processFileType } from \"./process-file-type\";\nimport type { Plugin, GeneratorResult, TailorDBReadyContext } from \"#/plugin/types\";\nimport type { FileUtilMetadata } from \"./types\";\n\n/** Unique identifier for the file utilities generator plugin. */\nexport const FileUtilsGeneratorID = \"@tailor-platform/file-utils\";\n\ntype FileUtilsPluginOptions = {\n distPath: string;\n};\n\n/**\n * Plugin that generates TypeWithFiles interface from TailorDB table definitions.\n * @param options - Plugin options\n * @param options.distPath - Output file path for generated file utilities\n * @returns Plugin instance with onTailorDBReady hook\n */\nexport function fileUtilsPlugin(\n options: FileUtilsPluginOptions,\n): Plugin<unknown, FileUtilsPluginOptions> {\n return {\n id: FileUtilsGeneratorID,\n description: \"Generates TypeWithFiles interface from TailorDB table definitions\",\n pluginConfig: options,\n\n async onTailorDBReady(\n ctx: TailorDBReadyContext<FileUtilsPluginOptions>,\n ): Promise<GeneratorResult> {\n const namespaceData: { namespace: string; types: FileUtilMetadata[] }[] = [];\n\n for (const ns of ctx.tailordb) {\n const typesWithFiles: FileUtilMetadata[] = [];\n\n for (const type of Object.values(ns.tables)) {\n const metadata = await processFileType(type);\n if (metadata.fileFields.length > 0) {\n typesWithFiles.push(metadata);\n }\n }\n\n if (typesWithFiles.length > 0) {\n namespaceData.push({\n namespace: ns.namespace,\n types: typesWithFiles,\n });\n }\n }\n\n const files: GeneratorResult[\"files\"] = [];\n if (namespaceData.length > 0) {\n const content = generateUnifiedFileUtils(namespaceData);\n if (content) {\n files.push({\n path: ctx.pluginConfig.distPath,\n content,\n });\n }\n }\n\n return { files };\n },\n };\n}\n"],"mappings":"oDAQA,SAAgB,yBACd,EACQ,CACR,GAAI,EAAc,SAAW,EAC3B,MAAO,GAIT,IAAM,EAAoB,IAAI,IACxB,EAAgB,IAAI,IAE1B,IAAK,GAAM,CAAE,YAAW,WAAW,EACjC,IAAK,IAAM,KAAQ,EACjB,EAAkB,IAAI,EAAK,KAAM,CAAS,EAC1C,EAAc,IAAI,EAAK,KAAM,EAAK,UAAU,EAIhD,GAAI,EAAkB,OAAS,EAC7B,MAAO,GAIT,IAAM,EAAkB,MAAM,KAAK,EAAc,QAAQ,CAAC,CAAC,CACxD,KAAK,CAAC,EAAW,KAET,KAAK,EAAU,mBADE,EAAO,IAAK,GAAU,IAAI,EAAM,EAAE,CAAC,CAAC,KAAK,KACV,EAAE,QAC1D,CAAC,CACD,KAAK;CAAI,EAEN,EACJ,CAAmB;;;;;;;;MAQf;EAEA,EACJ,CAAmB;;QAEf,EAAgB;;MAEhB;EAGA,EAAmB,MAAM,KAAK,EAAkB,QAAQ,CAAC,CAAC,CAC7D,KAAK,CAAC,EAAW,KAAe,KAAK,EAAU,KAAK,EAAU,EAAE,CAAC,CACjE,KAAK;CAAK,EAuEb,MAAO,CACL,EACA,EAtEA,CAAmB;;QAEf,EAAiB;;MAEjB;EAIJ,CAAmB;;;;;;;;MAQf;EAIJ,CAAmB;;;;;;;;;;MAUf;EAIJ,CAAmB;;;;;;;;MAQf;EAIJ,CAAmB;;;;;;;;MAQf;EAIJ,CAAmB;;;;;;;;MAQf;CAWN,CAAC,CAAC,KAAK;CAAI,CACb,CCpIA,eAAsB,gBAAgB,EAA+C,CACnF,IAAM,EAAuB,CAAC,EAE9B,GAAI,EAAK,MACP,IAAK,IAAM,KAAiB,OAAO,KAAK,EAAK,KAAK,EAChD,EAAW,KAAK,CAAa,EAIjC,MAAO,CACL,KAAM,EAAK,KACX,YACF,CACF,CCfA,MAAa,EAAuB,8BAYpC,SAAgB,gBACd,EACyC,CACzC,MAAO,CACL,GAAI,EACJ,YAAa,oEACb,aAAc,EAEd,MAAM,gBACJ,EAC0B,CAC1B,IAAM,EAAoE,CAAC,EAE3E,IAAK,IAAM,KAAM,EAAI,SAAU,CAC7B,IAAM,EAAqC,CAAC,EAE5C,IAAK,IAAM,KAAQ,OAAO,OAAO,EAAG,MAAM,EAAG,CAC3C,IAAM,EAAW,MAAM,gBAAgB,CAAI,EACvC,EAAS,WAAW,OAAS,GAC/B,EAAe,KAAK,CAAQ,CAEhC,CAEI,EAAe,OAAS,GAC1B,EAAc,KAAK,CACjB,UAAW,EAAG,UACd,MAAO,CACT,CAAC,CAEL,CAEA,IAAM,EAAkC,CAAC,EACzC,GAAI,EAAc,OAAS,EAAG,CAC5B,IAAM,EAAU,yBAAyB,CAAa,EAClD,GACF,EAAM,KAAK,CACT,KAAM,EAAI,aAAa,SACvB,SACF,CAAC,CAEL,CAEA,MAAO,CAAE,OAAM,CACjB,CACF,CACF"}
|
|
@@ -5,6 +5,13 @@ declare const KyselyGeneratorID = "@tailor-platform/kysely-type";
|
|
|
5
5
|
type KyselyTypePluginOptions = {
|
|
6
6
|
distPath: string;
|
|
7
7
|
};
|
|
8
|
+
declare module "@tailor-platform/sdk/plugin" {
|
|
9
|
+
interface PluginConfigRegistry {
|
|
10
|
+
"@tailor-platform/kysely-type": KyselyTypePluginOptions;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Conventional output path used when `kyselyTypePlugin` has no `distPath` configured. */
|
|
14
|
+
declare const DEFAULT_KYSELY_TYPES_DIST_PATH = "./generated/tailordb.ts";
|
|
8
15
|
/**
|
|
9
16
|
* Plugin that generates Kysely type definitions for TailorDB tables.
|
|
10
17
|
* @param options - Plugin options
|
|
@@ -13,4 +20,4 @@ type KyselyTypePluginOptions = {
|
|
|
13
20
|
*/
|
|
14
21
|
declare function kyselyTypePlugin(options: KyselyTypePluginOptions): Plugin<unknown, KyselyTypePluginOptions>;
|
|
15
22
|
//#endregion
|
|
16
|
-
export { KyselyGeneratorID, kyselyTypePlugin };
|
|
23
|
+
export { DEFAULT_KYSELY_TYPES_DIST_PATH, KyselyGeneratorID, kyselyTypePlugin };
|