@tailor-platform/sdk 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/cli/api.d.mts +1 -1
- package/dist/cli/api.mjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/configure/index.d.mts +2 -2
- package/dist/{index-BWN4RmSt.d.mts → index-BPsMM95X.d.mts} +1 -1
- package/dist/{token-B9YK0eTP.mjs → token-CWUhl5wa.mjs} +264 -1
- package/dist/{types-DWQxkbYl.d.mts → types-gceLFf_Y.d.mts} +24 -8
- package/dist/utils/test/index.d.mts +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @tailor-platform/sdk
|
|
2
2
|
|
|
3
|
+
## 0.8.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#12](https://github.com/tailor-platform/sdk/pull/12) [`d861a04`](https://github.com/tailor-platform/sdk/commit/d861a0448081566cd7e9ae1ba7eb837f1634c6a9) Thanks [@riku99](https://github.com/riku99)! - Add enum-constants and file-utils built-in generators for type-safe code generation
|
|
8
|
+
|
|
3
9
|
## 0.8.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/cli/api.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference path="./../plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { AppConfig, CodeGeneratorBase, Executor, Generator, Resolver, TailorDBTypeConfig } from "../types-
|
|
3
|
+
import { AppConfig, CodeGeneratorBase, Executor, Generator, Resolver, TailorDBTypeConfig } from "../types-gceLFf_Y.mjs";
|
|
4
4
|
import "citty";
|
|
5
5
|
import "zod";
|
|
6
6
|
import "@bufbuild/protobuf/wkt";
|
package/dist/cli/api.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList } from "../token-
|
|
1
|
+
import { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList } from "../token-CWUhl5wa.mjs";
|
|
2
2
|
import "../auth-Di3vQUrT.mjs";
|
|
3
3
|
|
|
4
4
|
export { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList };
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { PATScope, applyCommand, commonArgs, createCommand, deleteCommand, fetchAll, fetchLatestToken, formatArgs, generateCommand, initOperatorClient, listCommand as listCommand$4, listCommand$1 as listCommand, loadAccessToken, loadConfig, loadConfigPath, loadWorkspaceId, parseFormat, printWithFormat, readPlatformConfig, showCommand, tokenCommand, userAgent, withCommonArgs, writePlatformConfig } from "../token-
|
|
2
|
+
import { PATScope, applyCommand, commonArgs, createCommand, deleteCommand, fetchAll, fetchLatestToken, formatArgs, generateCommand, initOperatorClient, listCommand as listCommand$4, listCommand$1 as listCommand, loadAccessToken, loadConfig, loadConfigPath, loadWorkspaceId, parseFormat, printWithFormat, readPlatformConfig, showCommand, tokenCommand, userAgent, withCommonArgs, writePlatformConfig } from "../token-CWUhl5wa.mjs";
|
|
3
3
|
import "../auth-Di3vQUrT.mjs";
|
|
4
4
|
import { register } from "node:module";
|
|
5
5
|
import { defineCommand, runCommand, runMain } from "citty";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="./../plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { AuthConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, IDToken, IdPConfig, IdProviderConfig, OAuth2Client, OAuth2ClientGrantType, OIDC, PermissionCondition, QueryType, Resolver, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, StaticWebsiteConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, unauthenticatedTailorUser } from "../types-
|
|
4
|
-
import { FunctionOperation, GqlOperation, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, Operation, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, ResolverExecutedArgs, ResolverExecutedTrigger, ScheduleTrigger, Trigger, WebhookOperation, createExecutor, createResolver, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t } from "../index-
|
|
3
|
+
import { AuthConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, IDToken, IdPConfig, IdProviderConfig, OAuth2Client, OAuth2ClientGrantType, OIDC, PermissionCondition, QueryType, Resolver, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, StaticWebsiteConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, unauthenticatedTailorUser } from "../types-gceLFf_Y.mjs";
|
|
4
|
+
import { FunctionOperation, GqlOperation, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, Operation, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, ResolverExecutedArgs, ResolverExecutedTrigger, ScheduleTrigger, Trigger, WebhookOperation, createExecutor, createResolver, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t } from "../index-BPsMM95X.mjs";
|
|
5
5
|
export { AuthConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, FunctionOperation, GqlOperation, IDToken, IdPConfig, IdProviderConfig, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, OAuth2Client, OAuth2ClientGrantType, OIDC, Operation, PermissionCondition, QueryType, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, Resolver, ResolverExecutedArgs, ResolverExecutedTrigger, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, ScheduleTrigger, StaticWebsiteConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, Trigger, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, WebhookOperation, createExecutor, createResolver, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t, unauthenticatedTailorUser };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference path="./plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { AllowedValues, AllowedValuesOutput, ArrayFieldOutput, ExecutorInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, GqlOperation, IncomingWebhookTrigger as IncomingWebhookTrigger$1, InferFieldsOutput, RecordTrigger as RecordTrigger$1, ResolverExecutedTrigger as ResolverExecutedTrigger$1, ResolverInput, ScheduleTriggerInput, TailorDBType, TailorField, TailorUser, WebhookOperation, output as output$1 } from "./types-
|
|
3
|
+
import { AllowedValues, AllowedValuesOutput, ArrayFieldOutput, ExecutorInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, GqlOperation, IncomingWebhookTrigger as IncomingWebhookTrigger$1, InferFieldsOutput, RecordTrigger as RecordTrigger$1, ResolverExecutedTrigger as ResolverExecutedTrigger$1, ResolverInput, ScheduleTriggerInput, TailorDBType, TailorField, TailorUser, WebhookOperation, output as output$1 } from "./types-gceLFf_Y.mjs";
|
|
4
4
|
import { EmptyObject } from "type-fest";
|
|
5
5
|
import { Client } from "@urql/core";
|
|
6
6
|
import { StandardCRON } from "ts-cron-validator";
|
|
@@ -785,6 +785,8 @@ const SeedConfigSchema = z.tuple([z.literal("@tailor-platform/seed"), z.object({
|
|
|
785
785
|
distPath: z.string(),
|
|
786
786
|
machineUserName: z.string().optional()
|
|
787
787
|
})]);
|
|
788
|
+
const EnumConstantsConfigSchema = z.tuple([z.literal("@tailor-platform/enum-constants"), z.object({ distPath: z.string() })]);
|
|
789
|
+
const FileUtilsConfigSchema = z.tuple([z.literal("@tailor-platform/file-utils"), z.object({ distPath: z.string() })]);
|
|
788
790
|
const CodeGeneratorSchema = z.object({
|
|
789
791
|
id: z.string(),
|
|
790
792
|
description: z.string(),
|
|
@@ -798,6 +800,8 @@ const CodeGeneratorSchema = z.object({
|
|
|
798
800
|
const BaseGeneratorConfigSchema = z.union([
|
|
799
801
|
KyselyTypeConfigSchema,
|
|
800
802
|
SeedConfigSchema,
|
|
803
|
+
EnumConstantsConfigSchema,
|
|
804
|
+
FileUtilsConfigSchema,
|
|
801
805
|
CodeGeneratorSchema
|
|
802
806
|
]);
|
|
803
807
|
/**
|
|
@@ -808,6 +812,8 @@ function createGeneratorConfigSchema(builtinGenerators$1) {
|
|
|
808
812
|
return z.union([
|
|
809
813
|
KyselyTypeConfigSchema,
|
|
810
814
|
SeedConfigSchema,
|
|
815
|
+
EnumConstantsConfigSchema,
|
|
816
|
+
FileUtilsConfigSchema,
|
|
811
817
|
CodeGeneratorSchema
|
|
812
818
|
]).transform((gen) => {
|
|
813
819
|
if (Array.isArray(gen)) {
|
|
@@ -820,6 +826,258 @@ function createGeneratorConfigSchema(builtinGenerators$1) {
|
|
|
820
826
|
}).brand("CodeGenerator");
|
|
821
827
|
}
|
|
822
828
|
|
|
829
|
+
//#endregion
|
|
830
|
+
//#region src/cli/generator/builtin/enum-constants/enum-processor.ts
|
|
831
|
+
/**
|
|
832
|
+
* Processor that collects enum fields and generates enum constants.
|
|
833
|
+
*/
|
|
834
|
+
var EnumProcessor = class {
|
|
835
|
+
static async processType(type) {
|
|
836
|
+
const enums = this.collectEnums(type);
|
|
837
|
+
return {
|
|
838
|
+
name: type.name,
|
|
839
|
+
enums
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
static collectEnums(type) {
|
|
843
|
+
const enums = [];
|
|
844
|
+
for (const [fieldName, parsedField] of Object.entries(type.fields)) {
|
|
845
|
+
if (parsedField.config.type === "enum" && parsedField.config.allowedValues) {
|
|
846
|
+
const enumTypeName = `${type.name}${this.capitalizeFirst(fieldName)}`;
|
|
847
|
+
enums.push({
|
|
848
|
+
name: enumTypeName,
|
|
849
|
+
values: parsedField.config.allowedValues,
|
|
850
|
+
fieldDescription: parsedField.config.description
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
if (parsedField.config.type === "nested" && parsedField.config.fields) {
|
|
854
|
+
for (const [nestedFieldName, nestedFieldConfig] of Object.entries(parsedField.config.fields)) if (nestedFieldConfig.type === "enum" && nestedFieldConfig.allowedValues) {
|
|
855
|
+
const fullFieldName = `${fieldName}${this.capitalizeFirst(nestedFieldName)}`;
|
|
856
|
+
const enumTypeName = `${type.name}${this.capitalizeFirst(fullFieldName)}`;
|
|
857
|
+
enums.push({
|
|
858
|
+
name: enumTypeName,
|
|
859
|
+
values: nestedFieldConfig.allowedValues,
|
|
860
|
+
fieldDescription: nestedFieldConfig.description
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return enums;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Generate enum constant definitions from collected metadata.
|
|
869
|
+
*/
|
|
870
|
+
static async generateEnumConstants(types) {
|
|
871
|
+
const allEnums = /* @__PURE__ */ new Map();
|
|
872
|
+
for (const typeMetadata of Object.values(types)) if (typeMetadata.enums) for (const enumDef of typeMetadata.enums) allEnums.set(enumDef.name, enumDef);
|
|
873
|
+
const enumDefs = Array.from(allEnums.values()).map((e) => {
|
|
874
|
+
const members = e.values.map((v) => {
|
|
875
|
+
return ` "${v.value.replace(/[-\s]/g, "_")}": "${v.value}"`;
|
|
876
|
+
}).join(",\n");
|
|
877
|
+
const hasDescriptions = e.values.some((v) => v.description);
|
|
878
|
+
let jsDoc = "";
|
|
879
|
+
if (e.fieldDescription || hasDescriptions) {
|
|
880
|
+
const lines = [];
|
|
881
|
+
if (e.fieldDescription) {
|
|
882
|
+
lines.push(` * ${e.fieldDescription}`);
|
|
883
|
+
if (hasDescriptions) lines.push(" *");
|
|
884
|
+
}
|
|
885
|
+
if (hasDescriptions) {
|
|
886
|
+
const propertyDocs = e.values.map((v) => {
|
|
887
|
+
return ` * @property ${[v.value.replace(/[-\s]/g, "_"), v.description].filter(Boolean).join(" - ")}`;
|
|
888
|
+
});
|
|
889
|
+
lines.push(...propertyDocs);
|
|
890
|
+
}
|
|
891
|
+
if (lines.length > 0) jsDoc = `/**\n${lines.join("\n")}\n */\n`;
|
|
892
|
+
}
|
|
893
|
+
const constDef = `${jsDoc}export const ${e.name} = {\n${members}\n} as const;`;
|
|
894
|
+
const typeDef = `export type ${e.name} = (typeof ${e.name})[keyof typeof ${e.name}];`;
|
|
895
|
+
return `${constDef}\n${typeDef}`;
|
|
896
|
+
}).join("\n\n");
|
|
897
|
+
if (!enumDefs) return "";
|
|
898
|
+
return enumDefs + "\n";
|
|
899
|
+
}
|
|
900
|
+
static capitalizeFirst(str) {
|
|
901
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
//#endregion
|
|
906
|
+
//#region src/cli/generator/builtin/enum-constants/index.ts
|
|
907
|
+
const EnumConstantsGeneratorID = "@tailor-platform/enum-constants";
|
|
908
|
+
/**
|
|
909
|
+
* Generator for enum constants from TailorDB type definitions.
|
|
910
|
+
*/
|
|
911
|
+
var EnumConstantsGenerator = class {
|
|
912
|
+
id = EnumConstantsGeneratorID;
|
|
913
|
+
description = "Generates enum constants from TailorDB type definitions";
|
|
914
|
+
constructor(options) {
|
|
915
|
+
this.options = options;
|
|
916
|
+
}
|
|
917
|
+
async processType(args) {
|
|
918
|
+
return await EnumProcessor.processType(args.type);
|
|
919
|
+
}
|
|
920
|
+
processResolver() {}
|
|
921
|
+
processExecutor() {}
|
|
922
|
+
async processTailorDBNamespace(args) {
|
|
923
|
+
return await EnumProcessor.generateEnumConstants(args.types);
|
|
924
|
+
}
|
|
925
|
+
processIdProvider() {}
|
|
926
|
+
processAuth() {}
|
|
927
|
+
processStaticWebsite() {}
|
|
928
|
+
aggregate(args) {
|
|
929
|
+
const files = [];
|
|
930
|
+
for (const input of args.inputs) for (const nsResult of input.tailordb) if (nsResult.types) files.push({
|
|
931
|
+
path: this.options.distPath,
|
|
932
|
+
content: nsResult.types
|
|
933
|
+
});
|
|
934
|
+
return { files };
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
//#endregion
|
|
939
|
+
//#region src/cli/generator/builtin/file-utils/file-processor.ts
|
|
940
|
+
/**
|
|
941
|
+
* Processor that collects file fields and generates TypeWithFiles interface.
|
|
942
|
+
*/
|
|
943
|
+
var FileProcessor = class {
|
|
944
|
+
static async processType(type) {
|
|
945
|
+
const fileFields = [];
|
|
946
|
+
if (type.files) for (const fileFieldName of Object.keys(type.files)) fileFields.push(fileFieldName);
|
|
947
|
+
return {
|
|
948
|
+
name: type.name,
|
|
949
|
+
fileFields
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
static generateUnifiedFileUtils(namespaceData) {
|
|
953
|
+
if (namespaceData.length === 0) return "";
|
|
954
|
+
const typeNamespaceMap = /* @__PURE__ */ new Map();
|
|
955
|
+
const typeFieldsMap = /* @__PURE__ */ new Map();
|
|
956
|
+
for (const { namespace, types } of namespaceData) for (const type of types) {
|
|
957
|
+
typeNamespaceMap.set(type.name, namespace);
|
|
958
|
+
typeFieldsMap.set(type.name, type.fileFields);
|
|
959
|
+
}
|
|
960
|
+
if (typeNamespaceMap.size === 0) return "";
|
|
961
|
+
const interfaceFields = Array.from(typeFieldsMap.entries()).map(([typeName, fields]) => {
|
|
962
|
+
const fieldNamesUnion = fields.map((field) => `"${field}"`).join(" | ");
|
|
963
|
+
return ` ${typeName}: {\n fields: ${fieldNamesUnion};\n };`;
|
|
964
|
+
}).join("\n");
|
|
965
|
+
const interfaceDefinition = ml`
|
|
966
|
+
export interface TypeWithFiles {
|
|
967
|
+
${interfaceFields}
|
|
968
|
+
}
|
|
969
|
+
` + "\n";
|
|
970
|
+
const namespaceEntries = Array.from(typeNamespaceMap.entries()).map(([typeName, namespace]) => ` ${typeName}: "${namespace}"`).join(",\n");
|
|
971
|
+
const namespacesDefinition = ml`
|
|
972
|
+
const namespaces: Record<keyof TypeWithFiles, string> = {
|
|
973
|
+
${namespaceEntries},
|
|
974
|
+
};
|
|
975
|
+
` + "\n";
|
|
976
|
+
const downloadFunction = ml`
|
|
977
|
+
export async function downloadFile<T extends keyof TypeWithFiles>(
|
|
978
|
+
type: T,
|
|
979
|
+
field: TypeWithFiles[T]["fields"],
|
|
980
|
+
recordId: string,
|
|
981
|
+
) {
|
|
982
|
+
return await tailordb.file.download(namespaces[type], type, field, recordId);
|
|
983
|
+
}
|
|
984
|
+
` + "\n";
|
|
985
|
+
const uploadFunction = ml`
|
|
986
|
+
export async function uploadFile<T extends keyof TypeWithFiles>(
|
|
987
|
+
type: T,
|
|
988
|
+
field: TypeWithFiles[T]["fields"],
|
|
989
|
+
recordId: string,
|
|
990
|
+
data: string | ArrayBuffer | Uint8Array<ArrayBufferLike> | number[],
|
|
991
|
+
options?: FileUploadOptions,
|
|
992
|
+
): Promise<FileUploadResponse> {
|
|
993
|
+
return await tailordb.file.upload(namespaces[type], type, field, recordId, data, options);
|
|
994
|
+
}
|
|
995
|
+
` + "\n";
|
|
996
|
+
const deleteFunction = ml`
|
|
997
|
+
export async function deleteFile<T extends keyof TypeWithFiles>(
|
|
998
|
+
type: T,
|
|
999
|
+
field: TypeWithFiles[T]["fields"],
|
|
1000
|
+
recordId: string,
|
|
1001
|
+
): Promise<void> {
|
|
1002
|
+
return await tailordb.file.delete(namespaces[type], type, field, recordId);
|
|
1003
|
+
}
|
|
1004
|
+
` + "\n";
|
|
1005
|
+
const getMetadataFunction = ml`
|
|
1006
|
+
export async function getFileMetadata<T extends keyof TypeWithFiles>(
|
|
1007
|
+
type: T,
|
|
1008
|
+
field: TypeWithFiles[T]["fields"],
|
|
1009
|
+
recordId: string,
|
|
1010
|
+
): Promise<FileMetadata> {
|
|
1011
|
+
return await tailordb.file.getMetadata(namespaces[type], type, field, recordId);
|
|
1012
|
+
}
|
|
1013
|
+
` + "\n";
|
|
1014
|
+
const openDownloadStreamFunction = ml`
|
|
1015
|
+
export async function openFileDownloadStream<T extends keyof TypeWithFiles>(
|
|
1016
|
+
type: T,
|
|
1017
|
+
field: TypeWithFiles[T]["fields"],
|
|
1018
|
+
recordId: string,
|
|
1019
|
+
): Promise<FileStreamIterator> {
|
|
1020
|
+
return await tailordb.file.openDownloadStream(namespaces[type], type, field, recordId);
|
|
1021
|
+
}
|
|
1022
|
+
` + "\n";
|
|
1023
|
+
return [
|
|
1024
|
+
interfaceDefinition,
|
|
1025
|
+
namespacesDefinition,
|
|
1026
|
+
downloadFunction,
|
|
1027
|
+
uploadFunction,
|
|
1028
|
+
deleteFunction,
|
|
1029
|
+
getMetadataFunction,
|
|
1030
|
+
openDownloadStreamFunction
|
|
1031
|
+
].join("\n");
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
//#endregion
|
|
1036
|
+
//#region src/cli/generator/builtin/file-utils/index.ts
|
|
1037
|
+
const FileUtilsGeneratorID = "@tailor-platform/file-utils";
|
|
1038
|
+
/**
|
|
1039
|
+
* Generator for file utility functions from TailorDB type definitions.
|
|
1040
|
+
*/
|
|
1041
|
+
var FileUtilsGenerator = class {
|
|
1042
|
+
id = FileUtilsGeneratorID;
|
|
1043
|
+
description = "Generates TypeWithFiles interface from TailorDB type definitions";
|
|
1044
|
+
constructor(options) {
|
|
1045
|
+
this.options = options;
|
|
1046
|
+
}
|
|
1047
|
+
async processType(args) {
|
|
1048
|
+
return await FileProcessor.processType(args.type);
|
|
1049
|
+
}
|
|
1050
|
+
processResolver() {}
|
|
1051
|
+
processExecutor() {}
|
|
1052
|
+
async processTailorDBNamespace(args) {
|
|
1053
|
+
const typesWithFiles = Object.values(args.types).filter((t) => t.fileFields.length > 0);
|
|
1054
|
+
if (typesWithFiles.length === 0) return "";
|
|
1055
|
+
return JSON.stringify({
|
|
1056
|
+
namespace: args.namespace,
|
|
1057
|
+
types: typesWithFiles
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
processIdProvider() {}
|
|
1061
|
+
processAuth() {}
|
|
1062
|
+
processStaticWebsite() {}
|
|
1063
|
+
aggregate(args) {
|
|
1064
|
+
const files = [];
|
|
1065
|
+
const allNamespaceData = [];
|
|
1066
|
+
for (const input of args.inputs) for (const nsResult of input.tailordb) if (nsResult.types) try {
|
|
1067
|
+
const parsed = JSON.parse(nsResult.types);
|
|
1068
|
+
if (parsed.namespace && parsed.types) allNamespaceData.push(parsed);
|
|
1069
|
+
} catch {}
|
|
1070
|
+
if (allNamespaceData.length > 0) {
|
|
1071
|
+
const content = FileProcessor.generateUnifiedFileUtils(allNamespaceData);
|
|
1072
|
+
if (content) files.push({
|
|
1073
|
+
path: this.options.distPath,
|
|
1074
|
+
content
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
return { files };
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
|
|
823
1081
|
//#endregion
|
|
824
1082
|
//#region src/cli/generator/builtin/kysely-type/type-processor.ts
|
|
825
1083
|
/**
|
|
@@ -1183,7 +1441,12 @@ globalThis.tailordb = { Client: class {
|
|
|
1183
1441
|
|
|
1184
1442
|
//#endregion
|
|
1185
1443
|
//#region src/cli/config-loader.ts
|
|
1186
|
-
const builtinGenerators = new Map([
|
|
1444
|
+
const builtinGenerators = new Map([
|
|
1445
|
+
[KyselyGeneratorID, (options) => new KyselyGenerator(options)],
|
|
1446
|
+
[SeedGeneratorID, (options) => createSeedGenerator(options)],
|
|
1447
|
+
[EnumConstantsGeneratorID, (options) => new EnumConstantsGenerator(options)],
|
|
1448
|
+
[FileUtilsGeneratorID, (options) => new FileUtilsGenerator(options)]
|
|
1449
|
+
]);
|
|
1187
1450
|
const GeneratorConfigSchema = createGeneratorConfigSchema(builtinGenerators);
|
|
1188
1451
|
async function loadConfig(configPath) {
|
|
1189
1452
|
const resolvedPath = path.resolve(process.cwd(), configPath);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference path="./plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as zod34 from "zod";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
6
|
import * as type_fest0 from "type-fest";
|
|
7
7
|
import { IsAny, NonEmptyObject } from "type-fest";
|
|
8
|
-
import * as
|
|
8
|
+
import * as zod_v4_core50 from "zod/v4/core";
|
|
9
9
|
|
|
10
10
|
//#region src/configure/types/helpers.d.ts
|
|
11
11
|
type Prettify<T> = { [K in keyof T as string extends K ? never : K]: T[K] } & {};
|
|
@@ -1180,6 +1180,10 @@ declare const BaseGeneratorConfigSchema: z.ZodUnion<readonly [z.ZodTuple<[z.ZodL
|
|
|
1180
1180
|
}, z.core.$strip>], null>, z.ZodTuple<[z.ZodLiteral<"@tailor-platform/seed">, z.ZodObject<{
|
|
1181
1181
|
distPath: z.ZodString;
|
|
1182
1182
|
machineUserName: z.ZodOptional<z.ZodString>;
|
|
1183
|
+
}, z.core.$strip>], null>, z.ZodTuple<[z.ZodLiteral<"@tailor-platform/enum-constants">, z.ZodObject<{
|
|
1184
|
+
distPath: z.ZodString;
|
|
1185
|
+
}, z.core.$strip>], null>, z.ZodTuple<[z.ZodLiteral<"@tailor-platform/file-utils">, z.ZodObject<{
|
|
1186
|
+
distPath: z.ZodString;
|
|
1183
1187
|
}, z.core.$strip>], null>, z.ZodObject<{
|
|
1184
1188
|
id: z.ZodString;
|
|
1185
1189
|
description: z.ZodString;
|
|
@@ -1199,6 +1203,10 @@ declare function createGeneratorConfigSchema(builtinGenerators: Map<string, (opt
|
|
|
1199
1203
|
}, z.core.$strip>], null>, z.ZodTuple<[z.ZodLiteral<"@tailor-platform/seed">, z.ZodObject<{
|
|
1200
1204
|
distPath: z.ZodString;
|
|
1201
1205
|
machineUserName: z.ZodOptional<z.ZodString>;
|
|
1206
|
+
}, z.core.$strip>], null>, z.ZodTuple<[z.ZodLiteral<"@tailor-platform/enum-constants">, z.ZodObject<{
|
|
1207
|
+
distPath: z.ZodString;
|
|
1208
|
+
}, z.core.$strip>], null>, z.ZodTuple<[z.ZodLiteral<"@tailor-platform/file-utils">, z.ZodObject<{
|
|
1209
|
+
distPath: z.ZodString;
|
|
1202
1210
|
}, z.core.$strip>], null>, z.ZodObject<{
|
|
1203
1211
|
id: z.ZodString;
|
|
1204
1212
|
description: z.ZodString;
|
|
@@ -1222,6 +1230,10 @@ declare function createGeneratorConfigSchema(builtinGenerators: Map<string, (opt
|
|
|
1222
1230
|
}] | ["@tailor-platform/seed", {
|
|
1223
1231
|
distPath: string;
|
|
1224
1232
|
machineUserName?: string | undefined;
|
|
1233
|
+
}] | ["@tailor-platform/enum-constants", {
|
|
1234
|
+
distPath: string;
|
|
1235
|
+
}] | ["@tailor-platform/file-utils", {
|
|
1236
|
+
distPath: string;
|
|
1225
1237
|
}] | {
|
|
1226
1238
|
id: string;
|
|
1227
1239
|
description: string;
|
|
@@ -1258,15 +1270,19 @@ declare function defineGenerators(...configs: GeneratorConfig[]): (["@tailor-pla
|
|
|
1258
1270
|
}] | ["@tailor-platform/seed", {
|
|
1259
1271
|
distPath: string;
|
|
1260
1272
|
machineUserName?: string | undefined;
|
|
1273
|
+
}] | ["@tailor-platform/enum-constants", {
|
|
1274
|
+
distPath: string;
|
|
1275
|
+
}] | ["@tailor-platform/file-utils", {
|
|
1276
|
+
distPath: string;
|
|
1261
1277
|
}] | {
|
|
1262
1278
|
id: string;
|
|
1263
1279
|
description: string;
|
|
1264
|
-
processType:
|
|
1265
|
-
processResolver:
|
|
1266
|
-
processExecutor:
|
|
1267
|
-
aggregate:
|
|
1268
|
-
processTailorDBNamespace?:
|
|
1269
|
-
processResolverNamespace?:
|
|
1280
|
+
processType: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut>;
|
|
1281
|
+
processResolver: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut>;
|
|
1282
|
+
processExecutor: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut>;
|
|
1283
|
+
aggregate: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod34.ZodAny>;
|
|
1284
|
+
processTailorDBNamespace?: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut> | undefined;
|
|
1285
|
+
processResolverNamespace?: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut> | undefined;
|
|
1270
1286
|
})[];
|
|
1271
1287
|
//#endregion
|
|
1272
1288
|
//#region src/parser/service/executor/schema.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference path="./../../plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { TailorDBType, TailorField, TailorUser } from "../../types-
|
|
4
|
-
import { output } from "../../index-
|
|
3
|
+
import { TailorDBType, TailorField, TailorUser } from "../../types-gceLFf_Y.mjs";
|
|
4
|
+
import { output } from "../../index-BPsMM95X.mjs";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
6
|
|
|
7
7
|
//#region src/utils/test/index.d.ts
|