@tailor-platform/sdk 0.8.5 → 0.8.6

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @tailor-platform/sdk
2
2
 
3
+ ## 0.8.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#24](https://github.com/tailor-platform/sdk/pull/24) [`ffa71fe`](https://github.com/tailor-platform/sdk/commit/ffa71feba26b36be84292dbaaadc0d2a37dc6b96) Thanks [@riku99](https://github.com/riku99)! - Fix generator bugs with multiple TailorDB namespaces and refactor to object-based data passing
8
+
3
9
  ## 0.8.5
4
10
 
5
11
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  /// <reference path="./../plugin-generated.d.ts" />
2
2
 
3
- import { AppConfig, CodeGeneratorBase, Executor, Generator, Resolver, TailorDBTypeConfig } from "../types-BP7g8Bh3.mjs";
3
+ import { AppConfig, CodeGeneratorBase, Executor, Generator, Resolver, TailorDBTypeConfig } from "../types-CPcmGK_X.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-B9zkxSMS.mjs";
1
+ import { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList } from "../token-Cbs_El75.mjs";
2
2
  import "../auth-Di3vQUrT.mjs";
3
3
 
4
4
  export { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList };
@@ -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-B9zkxSMS.mjs";
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-Cbs_El75.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-BP7g8Bh3.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-Bwrm8M8p.mjs";
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-CPcmGK_X.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-DHpKRtq3.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-BP7g8Bh3.mjs";
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-CPcmGK_X.mjs";
4
4
  import { EmptyObject } from "type-fest";
5
5
  import { Client } from "@urql/core";
6
6
  import { StandardCRON } from "ts-cron-validator";
@@ -867,10 +867,11 @@ var EnumProcessor = class {
867
867
  /**
868
868
  * Generate enum constant definitions from collected metadata.
869
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) => {
870
+ static generateUnifiedEnumConstants(allEnums) {
871
+ if (allEnums.length === 0) return "";
872
+ const enumMap = /* @__PURE__ */ new Map();
873
+ for (const enumDef of allEnums) enumMap.set(enumDef.name, enumDef);
874
+ const enumDefs = Array.from(enumMap.values()).map((e) => {
874
875
  const members = e.values.map((v) => {
875
876
  return ` "${v.value.replace(/[-\s]/g, "_")}": "${v.value}"`;
876
877
  }).join(",\n");
@@ -920,17 +921,27 @@ var EnumConstantsGenerator = class {
920
921
  processResolver() {}
921
922
  processExecutor() {}
922
923
  async processTailorDBNamespace(args) {
923
- return await EnumProcessor.generateEnumConstants(args.types);
924
+ const allEnums = [];
925
+ for (const enumConstantMetadata of Object.values(args.types)) allEnums.push(...enumConstantMetadata.enums);
926
+ return {
927
+ namespace: args.namespace,
928
+ enums: allEnums
929
+ };
924
930
  }
925
931
  processIdProvider() {}
926
932
  processAuth() {}
927
933
  processStaticWebsite() {}
928
934
  aggregate(args) {
929
935
  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
- });
936
+ const allEnums = [];
937
+ for (const input of args.inputs) for (const nsResult of input.tailordb) if (nsResult.types && nsResult.types.enums.length > 0) allEnums.push(...nsResult.types.enums);
938
+ if (allEnums.length > 0) {
939
+ const content = EnumProcessor.generateUnifiedEnumConstants(allEnums);
940
+ files.push({
941
+ path: this.options.distPath,
942
+ content
943
+ });
944
+ }
934
945
  return { files };
935
946
  }
936
947
  };
@@ -1083,7 +1094,7 @@ var FileUtilsGenerator = class {
1083
1094
  /**
1084
1095
  * Processor that converts a ParsedTailorDBType into Kysely type metadata.
1085
1096
  */
1086
- var TypeProcessor = class TypeProcessor {
1097
+ var TypeProcessor = class {
1087
1098
  /**
1088
1099
  * Convert a ParsedTailorDBType into KyselyTypeMetadata.
1089
1100
  */
@@ -1221,49 +1232,52 @@ var TypeProcessor = class TypeProcessor {
1221
1232
  usedUtilityTypes: aggregatedUtilityTypes
1222
1233
  };
1223
1234
  }
1224
- static async processTypes(types, namespace) {
1225
- const aggregatedUtilityTypes = Object.values(types).reduce((acc, type) => ({
1226
- Timestamp: acc.Timestamp || type.usedUtilityTypes.Timestamp,
1227
- Serial: acc.Serial || type.usedUtilityTypes.Serial
1235
+ /**
1236
+ * Generate unified types file from multiple namespaces.
1237
+ */
1238
+ static generateUnifiedTypes(namespaceData) {
1239
+ if (namespaceData.length === 0) return "";
1240
+ const globalUsedUtilityTypes = namespaceData.reduce((acc, ns) => ({
1241
+ Timestamp: acc.Timestamp || ns.usedUtilityTypes.Timestamp,
1242
+ Serial: acc.Serial || ns.usedUtilityTypes.Serial
1228
1243
  }), {
1229
1244
  Timestamp: false,
1230
1245
  Serial: false
1231
1246
  });
1232
1247
  const utilityTypeDeclarations = [];
1233
- if (aggregatedUtilityTypes.Timestamp) utilityTypeDeclarations.push(`type Timestamp = ColumnType<Date, Date | string, Date | string>;`);
1248
+ if (globalUsedUtilityTypes.Timestamp) utilityTypeDeclarations.push(`type Timestamp = ColumnType<Date, Date | string, Date | string>;`);
1234
1249
  utilityTypeDeclarations.push(ml`
1235
1250
  type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
1236
1251
  ? ColumnType<S, I | undefined, U>
1237
1252
  : ColumnType<T, T | undefined, T>;
1238
1253
  `);
1239
- if (aggregatedUtilityTypes.Serial) utilityTypeDeclarations.push(`type Serial<T = string | number> = ColumnType<T, never, never>;`);
1240
- return [
1241
- ml`
1242
- import { type ColumnType, Kysely } from "kysely";
1243
- import { TailordbDialect } from "@tailor-platform/function-kysely-tailordb";
1254
+ if (globalUsedUtilityTypes.Serial) utilityTypeDeclarations.push(`type Serial<T = string | number> = ColumnType<T, never, never>;`);
1255
+ const importsSection = ml`
1256
+ import { type ColumnType, Kysely } from "kysely";
1257
+ import { TailordbDialect } from "@tailor-platform/function-kysely-tailordb";
1244
1258
 
1245
- ${utilityTypeDeclarations.join("\n")}
1246
- `,
1247
- TypeProcessor.generateNamespaceInterface(Object.values(types), namespace),
1248
- ml`
1249
- export function getDB<const N extends keyof Namespace>(namespace: N): Kysely<Namespace[N]> {
1250
- const client = new tailordb.Client({ namespace });
1251
- return new Kysely<Namespace[N]>({ dialect: new TailordbDialect(client) });
1252
- }
1259
+ ${utilityTypeDeclarations.join("\n")}
1260
+ `;
1261
+ const namespaceInterface = `export interface Namespace {\n${namespaceData.map(({ namespace, types }) => {
1262
+ const typeDefsWithIndent = types.map((type) => {
1263
+ return type.typeDef.split("\n").map((line) => line.trim() ? ` ${line}` : "").join("\n");
1264
+ }).join("\n\n");
1265
+ return ` "${namespace}": {\n${typeDefsWithIndent}\n }`;
1266
+ }).join(",\n")}\n}`;
1267
+ const getDBFunction = ml`
1268
+ export function getDB<const N extends keyof Namespace>(namespace: N): Kysely<Namespace[N]> {
1269
+ const client = new tailordb.Client({ namespace });
1270
+ return new Kysely<Namespace[N]>({ dialect: new TailordbDialect(client) });
1271
+ }
1253
1272
 
1254
- export type DB<N extends keyof Namespace = keyof Namespace> = ReturnType<typeof getDB<N>>;
1255
- `
1273
+ export type DB<N extends keyof Namespace = keyof Namespace> = ReturnType<typeof getDB<N>>;
1274
+ `;
1275
+ return [
1276
+ importsSection,
1277
+ namespaceInterface,
1278
+ getDBFunction
1256
1279
  ].join("\n\n") + "\n";
1257
1280
  }
1258
- /**
1259
- * Generate the Namespace interface.
1260
- */
1261
- static generateNamespaceInterface(types, namespace) {
1262
- const typeDefsWithIndent = types.map((type) => {
1263
- return type.typeDef.split("\n").map((line) => line.trim() ? ` ${line}` : "").join("\n");
1264
- }).join("\n\n");
1265
- return `export interface Namespace {\n "${namespace}": {\n${typeDefsWithIndent}\n }\n}`;
1266
- }
1267
1281
  };
1268
1282
 
1269
1283
  //#endregion
@@ -1284,14 +1298,31 @@ var KyselyGenerator = class {
1284
1298
  processResolver() {}
1285
1299
  processExecutor() {}
1286
1300
  async processTailorDBNamespace(args) {
1287
- return await TypeProcessor.processTypes(args.types, args.namespace);
1301
+ const typesList = Object.values(args.types);
1302
+ const usedUtilityTypes = typesList.reduce((acc, type) => ({
1303
+ Timestamp: acc.Timestamp || type.usedUtilityTypes.Timestamp,
1304
+ Serial: acc.Serial || type.usedUtilityTypes.Serial
1305
+ }), {
1306
+ Timestamp: false,
1307
+ Serial: false
1308
+ });
1309
+ return {
1310
+ namespace: args.namespace,
1311
+ types: typesList,
1312
+ usedUtilityTypes
1313
+ };
1288
1314
  }
1289
1315
  aggregate(args) {
1290
1316
  const files = [];
1291
- for (const input of args.inputs) for (const nsResult of input.tailordb) if (nsResult.types) files.push({
1292
- path: this.options.distPath,
1293
- content: nsResult.types
1294
- });
1317
+ const allNamespaceData = [];
1318
+ for (const input of args.inputs) for (const nsResult of input.tailordb) if (nsResult.types && nsResult.types.types.length > 0) allNamespaceData.push(nsResult.types);
1319
+ if (allNamespaceData.length > 0) {
1320
+ const content = TypeProcessor.generateUnifiedTypes(allNamespaceData);
1321
+ files.push({
1322
+ path: this.options.distPath,
1323
+ content
1324
+ });
1325
+ }
1295
1326
  return { files };
1296
1327
  }
1297
1328
  };
@@ -1,11 +1,11 @@
1
1
  /// <reference path="./plugin-generated.d.ts" />
2
2
 
3
- import * as zod0 from "zod";
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 zod_v4_core0 from "zod/v4/core";
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] } & {};
@@ -1277,12 +1277,12 @@ declare function defineGenerators(...configs: GeneratorConfig[]): (["@tailor-pla
1277
1277
  }] | {
1278
1278
  id: string;
1279
1279
  description: string;
1280
- processType: zod_v4_core0.$InferInnerFunctionType<zod_v4_core0.$ZodFunctionArgs, zod_v4_core0.$ZodFunctionOut>;
1281
- processResolver: zod_v4_core0.$InferInnerFunctionType<zod_v4_core0.$ZodFunctionArgs, zod_v4_core0.$ZodFunctionOut>;
1282
- processExecutor: zod_v4_core0.$InferInnerFunctionType<zod_v4_core0.$ZodFunctionArgs, zod_v4_core0.$ZodFunctionOut>;
1283
- aggregate: zod_v4_core0.$InferInnerFunctionType<zod_v4_core0.$ZodFunctionArgs, zod0.ZodAny>;
1284
- processTailorDBNamespace?: zod_v4_core0.$InferInnerFunctionType<zod_v4_core0.$ZodFunctionArgs, zod_v4_core0.$ZodFunctionOut> | undefined;
1285
- processResolverNamespace?: zod_v4_core0.$InferInnerFunctionType<zod_v4_core0.$ZodFunctionArgs, zod_v4_core0.$ZodFunctionOut> | undefined;
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;
1286
1286
  })[];
1287
1287
  //#endregion
1288
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-BP7g8Bh3.mjs";
4
- import { output } from "../../index-Bwrm8M8p.mjs";
3
+ import { TailorDBType, TailorField, TailorUser } from "../../types-CPcmGK_X.mjs";
4
+ import { output } from "../../index-DHpKRtq3.mjs";
5
5
  import { StandardSchemaV1 } from "@standard-schema/spec";
6
6
 
7
7
  //#region src/utils/test/index.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailor-platform/sdk",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "description": "Tailor Platform SDK - The SDK to work with Tailor Platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/configure/index.mjs",