@tailor-platform/sdk 1.76.2 → 1.79.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 +38 -0
- package/dist/application-BB6BlUfk.mjs +3 -0
- package/dist/{application-CqjCcZ2n.mjs → application-fjqb-Gh8.mjs} +57 -10
- package/dist/application-fjqb-Gh8.mjs.map +1 -0
- package/dist/cli/commands/deploy/deploy.d.mts +8 -3
- package/dist/cli/commands/show.d.mts +9 -3
- package/dist/cli/commands/workspace/create.d.mts +3 -0
- package/dist/cli/commands/workspace/list.d.mts +1 -0
- package/dist/cli/commands/workspace/transform.d.mts +2 -0
- package/dist/cli/index.mjs +47 -22
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lib.d.mts +2 -2
- package/dist/cli/lib.mjs +2 -2
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/cli/shared/workspace-name.d.mts +1 -0
- package/dist/cli/skills.mjs +1 -1
- package/dist/completion/zsh-worker.zsh +18 -1
- package/dist/configure/index.mjs +202 -7
- package/dist/configure/index.mjs.map +1 -1
- package/dist/configure/services/idp/index.d.mts +1 -4
- package/dist/configure/services/tailordb/schema.d.mts +1 -7
- package/dist/configure/services/workflow/execution-policy.d.mts +2 -2
- package/dist/configure/types/type.d.mts +1 -9
- package/dist/{crashreport-DZDr-TvH.mjs → crashreport-BNWUM6Kf.mjs} +2 -2
- package/dist/{crashreport-DZDr-TvH.mjs.map → crashreport-BNWUM6Kf.mjs.map} +1 -1
- package/dist/{crashreport-np4-_DX2.mjs → crashreport-BafWvjjX.mjs} +1 -1
- package/dist/errors-DVFS0AZk.mjs +100 -0
- package/dist/errors-DVFS0AZk.mjs.map +1 -0
- package/dist/{globals-z6zYMjlr.mjs → globals-B-n_3uYu.mjs} +11 -5
- package/dist/globals-B-n_3uYu.mjs.map +1 -0
- package/dist/{logger-BEiZZ3qT.mjs → logger-BwS4ppwO.mjs} +3 -3
- package/dist/logger-BwS4ppwO.mjs.map +1 -0
- package/dist/{registry-CTgoVWc_.mjs → registry-CXi7rJq7.mjs} +4 -3
- package/dist/registry-CXi7rJq7.mjs.map +1 -0
- package/dist/runtime/field-parse.d.mts +11 -0
- package/dist/runtime/globals.d.mts +4 -1
- package/dist/runtime/index.mjs +1 -1
- package/dist/runtime/workflow.d.mts +79 -15
- package/dist/runtime/workflow.mjs +2 -2
- package/dist/{runtime-DlklyuHN.mjs → runtime-CjMeYuPA.mjs} +1169 -539
- package/dist/runtime-CjMeYuPA.mjs.map +1 -0
- package/dist/{schema-DbTR1c6M.mjs → schema-CYrle8JZ.mjs} +222 -4
- package/dist/schema-CYrle8JZ.mjs.map +1 -0
- package/dist/{secretmanager-Bd45j7an.mjs → secretmanager-IY4UvinW.mjs} +42 -9
- package/dist/secretmanager-IY4UvinW.mjs.map +1 -0
- package/dist/service-CghpdV-9.mjs +3 -0
- package/dist/{service-DBFZQloR.mjs → service-Cp0I7ZFe.mjs} +3 -3
- package/dist/{service-DBFZQloR.mjs.map → service-Cp0I7ZFe.mjs.map} +1 -1
- package/dist/{service-BCRJ-3NV.mjs → service-D12iQGcS.mjs} +2 -2
- package/dist/{service-BCRJ-3NV.mjs.map → service-D12iQGcS.mjs.map} +1 -1
- package/dist/{test-env-key-IPapa1KJ.mjs → test-env-key-DuZycyWM.mjs} +2 -2
- package/dist/{test-env-key-IPapa1KJ.mjs.map → test-env-key-DuZycyWM.mjs.map} +1 -1
- package/dist/types/auth.generated.d.mts +9 -36
- package/dist/types/executor.generated.d.mts +19 -59
- package/dist/types/idp.generated.d.mts +518 -517
- package/dist/types/resolver.generated.d.mts +6 -2
- package/dist/types/tailordb.generated.d.mts +8 -7
- package/dist/utils/test/index.mjs +1 -1
- package/dist/vitest/environment.mjs +1 -1
- package/dist/vitest/index.d.mts +8 -8
- package/dist/vitest/index.mjs +635 -195
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mock.d.mts +8 -8
- package/dist/vitest/mocks/aigateway.d.mts +14 -4
- package/dist/vitest/mocks/authconnection.d.mts +14 -4
- package/dist/vitest/mocks/file.d.mts +24 -6
- package/dist/vitest/mocks/iconv.d.mts +28 -4
- package/dist/vitest/mocks/idp.d.mts +25 -9
- package/dist/vitest/mocks/secretmanager.d.mts +13 -4
- package/dist/vitest/mocks/tailordb.d.mts +48 -7
- package/dist/vitest/mocks/workflow.d.mts +68 -22
- package/dist/vitest/setup.mjs +2 -2
- package/dist/workflow-CkIDJpdg.mjs +69 -0
- package/dist/workflow-CkIDJpdg.mjs.map +1 -0
- package/docs/cli/application.md +58 -11
- package/docs/cli/setup.md +1 -1
- package/docs/cli/workspace.md +6 -4
- package/docs/cli-reference.md +12 -8
- package/docs/runtime.md +5 -6
- package/docs/services/aigateway.md +2 -0
- package/docs/services/tailordb.md +44 -0
- package/docs/services/workflow.md +3 -3
- package/docs/testing.md +105 -91
- package/package.json +7 -7
- package/dist/application-6zsDLGKv.mjs +0 -3
- package/dist/application-CqjCcZ2n.mjs.map +0 -1
- package/dist/configure/types/field-runtime.d.mts +0 -17
- package/dist/errors-Dtf2WPaW.mjs +0 -42
- package/dist/errors-Dtf2WPaW.mjs.map +0 -1
- package/dist/field-runtime-D4QWRiB1.mjs +0 -203
- package/dist/field-runtime-D4QWRiB1.mjs.map +0 -1
- package/dist/globals-z6zYMjlr.mjs.map +0 -1
- package/dist/logger-BEiZZ3qT.mjs.map +0 -1
- package/dist/registry-CTgoVWc_.mjs.map +0 -1
- package/dist/runtime-DlklyuHN.mjs.map +0 -1
- package/dist/schema-DbTR1c6M.mjs.map +0 -1
- package/dist/secretmanager-Bd45j7an.mjs.map +0 -1
- package/dist/service-CPMlIg3X.mjs +0 -3
- package/dist/types-BzJ7A_fn.mjs +0 -199
- package/dist/types-BzJ7A_fn.mjs.map +0 -1
- package/dist/types-CG9H7HuE.mjs +0 -4
- package/dist/workflow-DSwnYPPP.mjs +0 -45
- package/dist/workflow-DSwnYPPP.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-DbTR1c6M.mjs","names":["parseInternal","parseFieldInternal"],"sources":["../src/configure/services/tailordb/schema.ts"],"sourcesContent":["import { cloneDeep } from \"es-toolkit\";\nimport {\n type AllowedValues,\n type AllowedValuesOutput,\n mapAllowedValues,\n} from \"#/configure/types/field\";\nimport {\n parseInternal as parseFieldInternal,\n type FieldParseArgs,\n type FieldParseInternalArgs,\n} from \"#/configure/types/field-runtime\";\nimport { brandValue } from \"#/utils/brand\";\nimport type {\n TailorDBField as TailorDBFieldBase,\n TailorDBType as TailorDBTypeBase,\n DBFieldMetadata,\n DefinedDBFieldMetadata,\n SerialConfig,\n IndexDef,\n TailorDBTypeMetadata,\n RawRelationConfig,\n RelationType,\n} from \"#/configure/services/tailordb/types\";\nimport type {\n FieldOptions,\n FieldOutput,\n TailorFieldType,\n TailorToTs,\n FieldValidateInput,\n ValidateConfig,\n Validators,\n} from \"#/configure/types/field.types\";\nimport type { PluginAttachment, PluginConfigs } from \"#/plugin/types\";\nimport type { InferredAttributeMap } from \"#/runtime/types\";\nimport type { output, InferFieldsOutput, TypeLevelError } from \"#/types/helpers\";\nimport type { RawPermissions } from \"#/types/tailordb.generated\";\nimport type { TailorTypeGqlPermission, TailorTypePermission } from \"./permission\";\nimport type { Hook, Hooks, ExcludeNestedDBFields, TypeFeatures } from \"./types\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n// Erased DB fields stay assignable across builder method-state changes.\n// oxlint-disable-next-line no-explicit-any\ntype AnyBuilderMethod = any;\n\nexport type TailorAnyDBField = Omit<\n TailorDBFieldBase<AnyBuilderMethod, AnyBuilderMethod>,\n \"fields\"\n> & {\n readonly fields: Record<string, AnyBuilderMethod>;\n _metadata: DBFieldMetadata;\n parse: AnyBuilderMethod;\n _parseInternal: AnyBuilderMethod;\n readonly typeName: TypeLevelError<string>;\n description: AnyBuilderMethod;\n relation: AnyBuilderMethod;\n index: AnyBuilderMethod;\n unique: AnyBuilderMethod;\n vector: AnyBuilderMethod;\n hooks: AnyBuilderMethod;\n validate: AnyBuilderMethod;\n serial: AnyBuilderMethod;\n clone: AnyBuilderMethod;\n};\n\n// Helper alias\n// oxlint-disable-next-line no-explicit-any\nexport type TailorAnyDBType = TailorDBType<any, any, any>;\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\ntype DBFieldTypeNameMethod<Defined extends DefinedDBFieldMetadata> =\n IsAny<Defined> extends true\n ? TypeLevelError<string>\n : TypeLevelError<\"typeName cannot be used on TailorDB fields\">;\n\ntype WithDBFieldDescription<Defined> = Defined & { description: true };\ntype WithDBFieldRelation<Defined, S extends RelationType | RelationSelfConfig> = S extends\n | \"oneToOne\"\n | \"1-1\"\n ? Defined & { unique: true; index: true; relation: true }\n : S extends { type: \"oneToOne\" | \"1-1\" }\n ? Defined & { unique: true; index: true; relation: true }\n : Defined & { index: true; relation: true };\ntype WithDBFieldIndex<Defined> = Defined & { index: true };\ntype WithDBFieldUnique<Defined> = Defined & { unique: true; index: true };\ntype WithDBFieldVector<Defined> = Defined & { vector: true };\ntype WithDBFieldHooks<Defined, H> = Defined & {\n hooks: {\n create: H extends { create: unknown } ? true : false;\n update: H extends { update: unknown } ? true : false;\n };\n serial: false;\n};\ntype WithDBFieldValidate<Defined> = Defined & { validate: true };\ntype WithDBFieldSerial<Defined> = Defined & {\n serial: true;\n hooks: { create: false; update: false };\n};\ntype WithDBFieldCloneOptions<Defined extends DefinedDBFieldMetadata, NewOpt extends FieldOptions> =\n IsAny<Defined> extends true\n ? Defined\n : Omit<Defined, \"array\"> & {\n array: NewOpt extends { array: true } ? true : Defined[\"array\"];\n };\ntype DBFieldCloneOptions<Defined extends DefinedDBFieldMetadata> = Omit<FieldOptions, \"array\"> & {\n array?: Defined extends { validate: unknown } ? Defined[\"array\"] : boolean;\n};\ntype InvalidValidatedArrayCloneKeys<\n Fields extends Record<string, TailorAnyDBField>,\n K extends keyof Fields,\n Opt extends FieldOptions,\n> = Opt extends { array: infer ArrayOption }\n ? {\n [P in K]: Fields[P] extends TailorDBField<infer Defined, infer _Output>\n ? Defined extends { validate: unknown }\n ? ArrayOption extends Defined[\"array\"]\n ? never\n : P\n : never\n : never;\n }[K]\n : never;\ntype DBFieldsCloneOptionsGuard<\n Fields extends Record<string, TailorAnyDBField>,\n K extends keyof Fields,\n Opt extends FieldOptions,\n> = [InvalidValidatedArrayCloneKeys<Fields, K, Opt>] extends [never]\n ? unknown\n : TypeLevelError<\"array cannot be changed on fields with custom validation\">;\ntype DefinedDBTypeMetadata = {\n hooks?: true;\n validate?: true;\n features?: true;\n indexes?: true;\n files?: true;\n permission?: true;\n gqlPermission?: true;\n description?: true;\n};\ntype WithDBTypeMetadata<\n Defined extends DefinedDBTypeMetadata,\n Key extends keyof DefinedDBTypeMetadata,\n> = Defined & Record<Key, true>;\ntype DBTypeDuplicateInputGuard<\n Defined extends DefinedDBTypeMetadata,\n Key extends keyof DefinedDBTypeMetadata,\n Input,\n Message extends string,\n> =\n IsAny<Defined> extends true\n ? Input\n : Defined extends Record<Key, unknown>\n ? TypeLevelError<Message>\n : Input;\ntype DBTypeDuplicateRestGuard<\n Defined extends DefinedDBTypeMetadata,\n Key extends keyof DefinedDBTypeMetadata,\n Input extends unknown[],\n Message extends string,\n> =\n IsAny<Defined> extends true\n ? Input\n : Defined extends Record<Key, unknown>\n ? [TypeLevelError<Message>, ...TypeLevelError<Message>[]]\n : Input;\ntype FileKeyConflictError<\n Fields extends Record<string, TailorAnyDBField>,\n User extends object,\n> = Partial<\n Record<\n keyof output<TailorDBType<Fields, User>> & string,\n TypeLevelError<\"file keys cannot use existing field names\">\n >\n>;\ntype DBFieldDescriptionFn<Defined extends DefinedDBFieldMetadata, Output> = (\n description: string,\n) => TailorDBField<WithDBFieldDescription<Defined>, Output>;\ntype DBFieldRelationFn<Defined extends DefinedDBFieldMetadata, Output> = {\n <S extends RelationType, T extends TailorAnyDBType>(\n config: RelationConfig<S, T>,\n ): TailorDBField<WithDBFieldRelation<Defined, S>, Output>;\n <S extends RelationSelfConfig>(config: S): TailorDBField<WithDBFieldRelation<Defined, S>, Output>;\n};\ntype DBFieldIndexFn<Defined extends DefinedDBFieldMetadata, Output> = () => TailorDBField<\n WithDBFieldIndex<Defined>,\n Output\n>;\ntype DBFieldUniqueFn<Defined extends DefinedDBFieldMetadata, Output> = () => TailorDBField<\n WithDBFieldUnique<Defined>,\n Output\n>;\ntype DBFieldVectorFn<Defined extends DefinedDBFieldMetadata, Output> = () => TailorDBField<\n WithDBFieldVector<Defined>,\n Output\n>;\ntype DBFieldHooksFn<Defined extends DefinedDBFieldMetadata, Output> = <\n const H extends Hook<unknown, Output>,\n>(\n hooks: H,\n) => TailorDBField<WithDBFieldHooks<Defined, H>, Output>;\ntype DBFieldValidateFn<Defined extends DefinedDBFieldMetadata, Output> = (\n ...validate: FieldValidateInput<Output>[]\n) => TailorDBField<WithDBFieldValidate<Defined>, Output>;\ntype DBFieldSerialFn<Defined extends DefinedDBFieldMetadata, Output> = (\n config: SerialConfig<Defined[\"type\"] & (\"integer\" | \"string\")>,\n) => TailorDBField<WithDBFieldSerial<Defined>, Output>;\ntype DBFieldDescriptionMethod<Defined extends DefinedDBFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? DBFieldDescriptionFn<Defined, Output>\n : Defined extends { description: unknown }\n ? TypeLevelError<\".description() has already been set\">\n : DBFieldDescriptionFn<Defined, Output>;\ntype DBFieldRelationMethod<Defined extends DefinedDBFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? DBFieldRelationFn<Defined, Output>\n : Defined extends { relation: unknown }\n ? TypeLevelError<\".relation() has already been set\">\n : DBFieldRelationFn<Defined, Output>;\ntype DBFieldArrayCheck<A extends boolean, Ok, Msg extends string> = A extends true\n ? TypeLevelError<Msg>\n : Ok;\ntype DBFieldIndexMethod<Defined extends DefinedDBFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? DBFieldIndexFn<Defined, Output>\n : Defined extends { index: unknown }\n ? TypeLevelError<\".index() has already been set\">\n : DBFieldArrayCheck<\n Defined[\"array\"],\n DBFieldIndexFn<Defined, Output>,\n \"index cannot be set on array fields\"\n >;\ntype DBFieldUniqueMethod<Defined extends DefinedDBFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? DBFieldUniqueFn<Defined, Output>\n : Defined extends { unique: unknown }\n ? TypeLevelError<\".unique() has already been set\">\n : DBFieldArrayCheck<\n Defined[\"array\"],\n DBFieldUniqueFn<Defined, Output>,\n \"unique cannot be set on array fields\"\n >;\ntype DBFieldVectorMethod<Defined extends DefinedDBFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? DBFieldVectorFn<Defined, Output>\n : Defined extends { vector: unknown }\n ? TypeLevelError<\".vector() has already been set\">\n : Defined extends { type: \"string\"; array: false }\n ? DBFieldVectorFn<Defined, Output>\n : TypeLevelError<\"vector can only be set on non-array string fields\">;\ntype DBFieldHooksMethod<Defined extends DefinedDBFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? DBFieldHooksFn<Defined, Output>\n : Defined extends {\n serial: true;\n hooks: { create: false; update: false };\n }\n ? TypeLevelError<\"hooks cannot be set after serial\">\n : Defined extends {\n hooks: unknown;\n }\n ? TypeLevelError<\".hooks() has already been set\">\n : Defined extends { type: \"nested\" }\n ? TypeLevelError<\"hooks cannot be set on nested type fields\">\n : DBFieldHooksFn<Defined, Output>;\ntype DBFieldValidateMethod<Defined extends DefinedDBFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? DBFieldValidateFn<Defined, Output>\n : Defined extends { validate: unknown }\n ? TypeLevelError<\".validate() has already been set\">\n : DBFieldValidateFn<Defined, Output>;\ntype DBFieldSerialMethod<Defined extends DefinedDBFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? DBFieldSerialFn<Defined, Output>\n : Defined extends { serial: true }\n ? TypeLevelError<\".serial() has already been set\">\n : Defined extends { serial: false }\n ? TypeLevelError<\"serial cannot be set after hooks\">\n : IsAny<Output> extends true\n ? Defined extends { type: \"integer\" | \"string\"; array: false }\n ? DBFieldSerialFn<Defined, Output>\n : TypeLevelError<\"serial can only be set on non-array integer or string fields\">\n : null extends Output\n ? TypeLevelError<\"serial can only be set on non-array integer or string fields\">\n : Defined extends { type: \"integer\" | \"string\"; array: false }\n ? DBFieldSerialFn<Defined, Output>\n : TypeLevelError<\"serial can only be set on non-array integer or string fields\">;\n/**\n * Full TailorDBField interface with builder methods.\n * Extends the minimal structural interface from types/ with fluent API methods.\n */\nexport interface TailorDBField<\n Defined extends DefinedDBFieldMetadata = DefinedDBFieldMetadata,\n // oxlint-disable-next-line no-explicit-any\n Output = any,\n> extends Omit<TailorDBFieldBase<Defined, Output>, \"fields\"> {\n readonly fields: Record<string, TailorAnyDBField>;\n _metadata: DBFieldMetadata;\n\n /**\n * Parse and validate a value against this field's validation rules\n */\n parse(args: FieldParseArgs): StandardSchemaV1.Result<Output>;\n\n /**\n * Internal parse method that tracks field path for nested validation\n * @private\n */\n _parseInternal(args: FieldParseInternalArgs): StandardSchemaV1.Result<Output>;\n\n /**\n * typeName is not available on TailorDB fields.\n * Use typeName on pipeline fields (t.enum / t.object) instead.\n */\n typeName: DBFieldTypeNameMethod<Defined>;\n\n /**\n * Set a description for the field\n */\n description: DBFieldDescriptionMethod<Defined, Output>;\n\n /**\n * Define a relation to another type.\n */\n relation: DBFieldRelationMethod<Defined, Output>;\n\n /**\n * Add an index to the field\n */\n index: DBFieldIndexMethod<Defined, Output>;\n\n /**\n * Make the field unique (also adds an index)\n */\n unique: DBFieldUniqueMethod<Defined, Output>;\n\n /**\n * Enable vector search on the field (string type only)\n */\n vector: DBFieldVectorMethod<Defined, Output>;\n\n /**\n * Add hooks for create/update operations on this field.\n */\n hooks: DBFieldHooksMethod<Defined, Output>;\n\n /**\n * Add validation functions to the field.\n *\n * Validators receive `{ value, data, user }` and run after hooks and\n * built-in type validation; they are skipped when built-in validation\n * fails. For array fields, `value` is the complete array.\n */\n validate: DBFieldValidateMethod<Defined, Output>;\n\n /**\n * Configure serial/auto-increment behavior\n */\n serial: DBFieldSerialMethod<Defined, Output>;\n\n /**\n * Clone the field with optional overrides for field options.\n * The `array` option cannot change on fields with custom validation.\n */\n clone<const NewOpt extends DBFieldCloneOptions<Defined>>(\n options?: NewOpt,\n ): TailorDBField<\n WithDBFieldCloneOptions<Defined, NewOpt>,\n FieldOutput<TailorToTs[Defined[\"type\"]], NewOpt>\n >;\n}\n\n/**\n * Full TailorDBType interface with builder methods.\n * Extends the minimal structural interface from types/ with fluent API methods.\n */\nexport interface TailorDBType<\n // oxlint-disable-next-line no-explicit-any\n Fields extends Record<string, TailorAnyDBField> = any,\n User extends object = InferredAttributeMap,\n // oxlint-disable-next-line no-explicit-any\n Defined extends DefinedDBTypeMetadata = any,\n> extends TailorDBTypeBase<Fields, User> {\n _description?: string;\n\n hooks(\n hooks: DBTypeDuplicateInputGuard<\n Defined,\n \"hooks\",\n Hooks<Fields>,\n \".hooks() has already been set\"\n >,\n ): TailorDBType<Fields, User, WithDBTypeMetadata<Defined, \"hooks\">>;\n validate(\n validators: DBTypeDuplicateInputGuard<\n Defined,\n \"validate\",\n Validators<Fields>,\n \".validate() has already been set\"\n >,\n ): TailorDBType<Fields, User, WithDBTypeMetadata<Defined, \"validate\">>;\n features(\n features: DBTypeDuplicateInputGuard<\n Defined,\n \"features\",\n Omit<TypeFeatures, \"pluralForm\">,\n \".features() has already been set\"\n >,\n ): TailorDBType<Fields, User, WithDBTypeMetadata<Defined, \"features\">>;\n indexes(\n ...indexes: DBTypeDuplicateRestGuard<\n Defined,\n \"indexes\",\n IndexDef<TailorDBType<Fields, User, Defined>>[],\n \".indexes() has already been set\"\n >\n ): TailorDBType<Fields, User, WithDBTypeMetadata<Defined, \"indexes\">>;\n files<const F extends string>(\n files: DBTypeDuplicateInputGuard<\n Defined,\n \"files\",\n Record<F, string> & FileKeyConflictError<Fields, User>,\n \".files() has already been set\"\n >,\n ): TailorDBType<Fields, User, WithDBTypeMetadata<Defined, \"files\">>;\n permission<\n U extends object = User,\n P extends TailorTypePermission<U, output<TailorDBType<Fields, User, Defined>>> =\n TailorTypePermission<U, output<TailorDBType<Fields, User, Defined>>>,\n >(\n permission: DBTypeDuplicateInputGuard<\n Defined,\n \"permission\",\n P,\n \".permission() has already been set\"\n >,\n ): TailorDBType<Fields, U, WithDBTypeMetadata<Defined, \"permission\">>;\n gqlPermission<\n U extends object = User,\n P extends TailorTypeGqlPermission<U> = TailorTypeGqlPermission<U>,\n >(\n permission: DBTypeDuplicateInputGuard<\n Defined,\n \"gqlPermission\",\n P,\n \".gqlPermission() has already been set\"\n >,\n ): TailorDBType<Fields, U, WithDBTypeMetadata<Defined, \"gqlPermission\">>;\n description(\n description: DBTypeDuplicateInputGuard<\n Defined,\n \"description\",\n string,\n \".description() has already been set\"\n >,\n ): TailorDBType<Fields, User, WithDBTypeMetadata<Defined, \"description\">>;\n pickFields<K extends keyof Fields>(keys: K[]): Pick<Fields, K>;\n pickFields<K extends keyof Fields, const Opt extends FieldOptions>(\n keys: K[],\n options: Opt & DBFieldsCloneOptionsGuard<Fields, K, Opt>,\n ): {\n [P in K]: Fields[P] extends TailorDBField<infer D, infer _O>\n ? TailorDBField<WithDBFieldCloneOptions<D, Opt>, FieldOutput<TailorToTs[D[\"type\"]], Opt>>\n : never;\n };\n omitFields<K extends keyof Fields>(keys: K[]): Omit<Fields, K>;\n plugin<P extends keyof PluginConfigs<keyof Fields & string>>(config: {\n [K in P]: PluginConfigs<keyof Fields & string>[K];\n }): TailorDBType<Fields, User, Defined>;\n}\n\nexport type TailorDBInstance<\n // oxlint-disable-next-line no-explicit-any\n Fields extends Record<string, TailorAnyDBField> = any,\n User extends object = InferredAttributeMap,\n // oxlint-disable-next-line no-explicit-any\n Defined extends DefinedDBTypeMetadata = any,\n> = TailorDBType<Fields, User, Defined>;\n\ninterface RelationConfig<S extends RelationType, T extends TailorDBType> {\n type: S;\n toward: {\n type: T;\n as?: string;\n key?: keyof T[\"fields\"] & string;\n };\n backward?: string;\n}\n\n// Special config variant for self-referencing relations\ntype RelationSelfConfig = {\n type: RelationType;\n toward: {\n type: \"self\";\n as?: string;\n key?: string;\n };\n backward?: string;\n};\n\nfunction isRelationSelfConfig(\n config: RelationConfig<RelationType, TailorDBType> | RelationSelfConfig,\n): config is RelationSelfConfig {\n return config.toward.type === \"self\";\n}\n\ntype DBFieldDefined<T extends TailorFieldType, Opt extends FieldOptions> = {\n type: T;\n array: Opt extends { array: true } ? true : false;\n};\ntype DBFieldOutput<\n T extends TailorFieldType,\n Opt extends FieldOptions,\n OutputBase = TailorToTs[T],\n> = FieldOutput<OutputBase, Opt>;\ntype TailorDBFieldInstance<\n T extends TailorFieldType,\n Opt extends FieldOptions,\n OutputBase = TailorToTs[T],\n> = TailorDBField<DBFieldDefined<T, Opt>, DBFieldOutput<T, Opt, OutputBase>>;\ntype TailorDBFieldRuntimeInstance<\n T extends TailorFieldType,\n Opt extends FieldOptions,\n OutputBase = TailorToTs[T],\n> = TailorDBFieldRuntime<DBFieldDefined<T, Opt>, DBFieldOutput<T, Opt, OutputBase>>;\ntype TailorDBFieldRuntime<Defined extends DefinedDBFieldMetadata, Output> = Omit<\n TailorDBFieldBase<Defined, Output>,\n \"fields\"\n> & {\n readonly fields: Record<string, TailorAnyDBField>;\n _metadata: DBFieldMetadata;\n description(description: string): object;\n typeName(typeName: string): object;\n validate(...validate: FieldValidateInput<Output>[]): object;\n relation(config: RelationConfig<RelationType, TailorDBType> | RelationSelfConfig): object;\n index(): object;\n unique(): object;\n vector(): object;\n hooks(hooks: Hook<unknown, Output>): object;\n serial(config: SerialConfig): object;\n clone(options?: FieldOptions): TailorDBFieldRuntime<DefinedDBFieldMetadata, AnyBuilderMethod>;\n parse(args: FieldParseArgs): StandardSchemaV1.Result<Output>;\n _parseInternal(args: FieldParseInternalArgs): StandardSchemaV1.Result<Output>;\n _setRawRelation(relation: RawRelationConfig): void;\n};\n\n/**\n * Creates a new TailorDBField instance.\n * @param type - Field type\n * @param options - Field options\n * @param fields - Nested fields for object-like types\n * @param values - Allowed values for enum-like fields\n * @returns A new TailorDBField\n */\nfunction createTailorDBField<\n const T extends TailorFieldType,\n const TOptions extends FieldOptions,\n const OutputBase = TailorToTs[T],\n>(\n type: T,\n options?: TOptions,\n fields?: Record<string, TailorAnyDBField>,\n values?: AllowedValues,\n): TailorDBFieldInstance<T, TOptions, OutputBase>;\nfunction createTailorDBField<const T extends TailorFieldType, const TOptions extends FieldOptions>(\n type: T,\n options?: TOptions,\n fields?: Record<string, TailorAnyDBField>,\n values?: AllowedValues,\n): object {\n return createTailorDBFieldRuntime(type, options, fields, values);\n}\n\nfunction createTailorDBFieldRuntime<\n const T extends TailorFieldType,\n const TOptions extends FieldOptions,\n const OutputBase = TailorToTs[T],\n>(\n type: T,\n options?: TOptions,\n fields?: Record<string, TailorAnyDBField>,\n values?: AllowedValues,\n): TailorDBFieldRuntimeInstance<T, TOptions, OutputBase> {\n type FieldValue = DBFieldOutput<T, TOptions, OutputBase>;\n type FieldType = TailorDBFieldRuntimeInstance<T, TOptions, OutputBase>;\n\n const _metadata: DBFieldMetadata = { required: true };\n let _rawRelation: RawRelationConfig | undefined;\n\n if (options) {\n if (options.optional === true) {\n _metadata.required = false;\n }\n if (options.array === true) {\n _metadata.array = true;\n }\n }\n if (values) {\n _metadata.allowedValues = mapAllowedValues(values);\n }\n\n function parseInternal(args: FieldParseInternalArgs): StandardSchemaV1.Result<FieldValue> {\n return parseFieldInternal<T, FieldValue>({\n ...args,\n field,\n });\n }\n\n function cloneWith(metadataUpdates: Partial<DBFieldMetadata>) {\n const cloned = field.clone();\n Object.assign(cloned._metadata, metadataUpdates);\n return cloned;\n }\n\n const field: FieldType = {\n type,\n fields: fields ?? {},\n _defined: undefined as unknown as DBFieldDefined<T, TOptions>,\n _output: undefined as FieldValue,\n _metadata,\n\n get metadata() {\n return { ...this._metadata };\n },\n\n get rawRelation(): Readonly<RawRelationConfig> | undefined {\n return _rawRelation ? { ..._rawRelation, toward: { ..._rawRelation.toward } } : undefined;\n },\n\n description(description: string) {\n return cloneWith({ description });\n },\n\n typeName(typeName: string) {\n return cloneWith({ typeName });\n },\n\n validate(...validateInputs: FieldValidateInput<FieldValue>[]) {\n return cloneWith({ validate: validateInputs });\n },\n\n parse(args: FieldParseArgs): StandardSchemaV1.Result<FieldValue> {\n return parseInternal({\n value: args.value,\n data: args.data,\n user: args.user,\n pathArray: [],\n });\n },\n\n _parseInternal: parseInternal,\n\n // TailorDBField specific methods\n relation(config: RelationConfig<RelationType, TailorDBType> | RelationSelfConfig) {\n const cloned = field.clone();\n const targetType = isRelationSelfConfig(config) ? \"self\" : config.toward.type.name;\n cloned._setRawRelation({\n type: config.type,\n toward: {\n type: targetType,\n as: config.toward.as,\n key: config.toward.key,\n },\n backward: config.backward,\n });\n return cloned;\n },\n\n index() {\n return cloneWith({ index: true });\n },\n\n unique() {\n return cloneWith({ unique: true, index: true });\n },\n\n vector() {\n return cloneWith({ vector: true });\n },\n\n hooks(hooks: Hook<unknown, FieldValue>) {\n return cloneWith({ hooks });\n },\n\n serial(config: SerialConfig) {\n return cloneWith({ serial: config });\n },\n\n clone(cloneOptions?: FieldOptions) {\n if (\n this._metadata.validate?.length &&\n cloneOptions?.array !== undefined &&\n cloneOptions.array !== (this._metadata.array === true)\n ) {\n throw new Error(\"Cannot change the array option on a field with custom validation\");\n }\n\n // Deep clone nested object fields if present\n let clonedFields = fields;\n if (fields) {\n const cloned: Record<string, TailorAnyDBField> = {};\n for (const [key, field] of Object.entries(fields)) {\n cloned[key] = field.clone();\n }\n clonedFields = cloned;\n }\n\n // Create a new field with cloned configuration\n const clonedField = createTailorDBFieldRuntime(type, options, clonedFields, values);\n\n // Deep copy metadata using cloneDeep (preserves function references)\n Object.assign(clonedField._metadata, cloneDeep(this._metadata));\n\n // Apply new options if provided\n if (cloneOptions) {\n if (cloneOptions.optional !== undefined) {\n clonedField._metadata.required = !cloneOptions.optional;\n }\n if (cloneOptions.array !== undefined) {\n clonedField._metadata.array = cloneOptions.array;\n }\n }\n\n // Copy raw relation if exists\n if (_rawRelation) {\n clonedField._setRawRelation(cloneDeep(_rawRelation));\n }\n\n return clonedField;\n },\n\n _setRawRelation(relation: RawRelationConfig) {\n _rawRelation = relation;\n },\n };\n\n return field;\n}\n\nconst createField = createTailorDBField;\n\n/**\n * Create a UUID field.\n * @param options - Field configuration options\n * @returns A UUID field\n * @example db.uuid()\n * @example db.uuid({ optional: true })\n */\nfunction uuid<const Opt extends FieldOptions>(options?: Opt) {\n return createField(\"uuid\", options);\n}\n\n/**\n * Create a string field.\n * @param options - Field configuration options\n * @returns A string field\n * @example db.string()\n * @example db.string({ optional: true })\n */\nfunction string<const Opt extends FieldOptions>(options?: Opt) {\n return createField(\"string\", options);\n}\n\n/**\n * Create a boolean field.\n * Note: The method name is `bool` but creates a `boolean` type field.\n * @param options - Field configuration options\n * @returns A boolean field\n * @example db.bool()\n * @example db.bool({ optional: true })\n */\nfunction bool<const Opt extends FieldOptions>(options?: Opt) {\n return createField(\"boolean\", options);\n}\n\n/**\n * Create an integer field.\n * @param options - Field configuration options\n * @returns An integer field\n * @example db.int()\n * @example db.int({ optional: true })\n */\nfunction int<const Opt extends FieldOptions>(options?: Opt) {\n return createField(\"integer\", options);\n}\n\n/**\n * Create a float (decimal number) field.\n * @param options - Field configuration options\n * @returns A float field\n * @example db.float()\n * @example db.float({ optional: true })\n */\nfunction float<const Opt extends FieldOptions>(options?: Opt) {\n return createField(\"float\", options);\n}\n\ninterface DecimalFieldOptions extends FieldOptions {\n scale?: number;\n}\n\n/**\n * Create a decimal field (stored as string for precision).\n * @param options - Field configuration options including optional scale (0-12)\n * @returns A decimal field\n * @example db.decimal()\n * @example db.decimal({ scale: 2 })\n * @example db.decimal({ scale: 2, optional: true })\n */\nfunction decimal<const Opt extends DecimalFieldOptions>(options?: Opt) {\n if (options?.scale !== undefined) {\n if (!Number.isInteger(options.scale) || options.scale < 0 || options.scale > 12) {\n throw new Error(\"scale must be an integer between 0 and 12\");\n }\n }\n const field = createField(\"decimal\", options);\n if (options?.scale !== undefined) {\n field._metadata.scale = options.scale;\n }\n return field;\n}\n\n/**\n * Create a date field (date only, no time component).\n * Format: \"yyyy-MM-dd\"\n * @param options - Field configuration options\n * @returns A date field\n * @example db.date()\n */\nfunction date<const Opt extends FieldOptions>(options?: Opt) {\n return createField(\"date\", options);\n}\n\n/**\n * Create a datetime field (date and time).\n * Format: ISO 8601 \"yyyy-MM-ddTHH:mm:ssZ\"\n * @param options - Field configuration options\n * @returns A datetime field\n * @example db.datetime()\n */\nfunction datetime<const Opt extends FieldOptions>(options?: Opt) {\n return createField(\"datetime\", options);\n}\n\n/**\n * Create a time field (time only, no date component).\n * Format: \"HH:mm\"\n * @param options - Field configuration options\n * @returns A time field\n * @example db.time()\n */\nfunction time<const Opt extends FieldOptions>(options?: Opt) {\n return createField(\"time\", options);\n}\n\n/**\n * Create an enum field with a fixed set of allowed string values.\n * @param values - Array of allowed string values, or array of `{ value, description }` objects\n * @param options - Field configuration options\n * @returns An enum field\n * @example db.enum([\"active\", \"inactive\", \"suspended\"])\n * @example db.enum([\"small\", \"medium\", \"large\"], { optional: true })\n */\nfunction _enum<const V extends AllowedValues, const Opt extends FieldOptions>(\n values: V,\n options?: Opt,\n): TailorDBField<\n { type: \"enum\"; array: Opt extends { array: true } ? true : false },\n FieldOutput<AllowedValuesOutput<V>, Opt>\n> {\n return createField<\"enum\", Opt, AllowedValuesOutput<V>>(\"enum\", options, undefined, values);\n}\n\n/**\n * Create a nested object field with sub-fields.\n * @param fields - Record of nested field definitions\n * @param options - Field configuration options\n * @returns A nested object field\n * @example db.object({ street: db.string(), city: db.string(), zip: db.string() })\n * @example db.object({ name: db.string() }, { optional: true })\n */\nfunction object<\n const F extends Record<string, TailorAnyDBField> & ExcludeNestedDBFields<F>,\n const Opt extends FieldOptions,\n>(fields: F, options?: Opt) {\n return createField(\"nested\", options, fields) as unknown as TailorDBField<\n { type: \"nested\"; array: Opt extends { array: true } ? true : false },\n FieldOutput<InferFieldsOutput<F>, Opt>\n >;\n}\n\n/**\n * Creates a new TailorDBType instance.\n * @param name - Type name\n * @param fields - Field definitions\n * @param options - Type options\n * @param options.pluralForm - Optional plural form\n * @param options.description - Optional description\n * @returns A new TailorDBType\n */\nfunction createTailorDBType<\n // oxlint-disable-next-line no-explicit-any\n const Fields extends Record<string, TailorAnyDBField> = any,\n User extends object = InferredAttributeMap,\n>(\n name: string,\n fields: Fields,\n options: { pluralForm?: string; description?: string },\n): TailorDBType<Fields, User, DefinedDBTypeMetadata> {\n let _description = options.description;\n let _settings: TypeFeatures = {};\n let _indexes: IndexDef<TailorDBType<Fields, User, DefinedDBTypeMetadata>>[] = [];\n const _permissions: RawPermissions = {};\n let _files: Record<string, string> = {};\n const _plugins: PluginAttachment[] = [];\n const _definedMethods = new Set<keyof DefinedDBTypeMetadata>();\n if (options.description !== undefined) {\n _definedMethods.add(\"description\");\n }\n\n function runMethodOnce<T>(method: keyof DefinedDBTypeMetadata, action: () => T): T {\n if (_definedMethods.has(method)) {\n throw new Error(`.${method}() has already been set`);\n }\n const result = action();\n _definedMethods.add(method);\n return result;\n }\n type TypeAfter<Key extends keyof DefinedDBTypeMetadata> = TailorDBType<\n Fields,\n User,\n WithDBTypeMetadata<DefinedDBTypeMetadata, Key>\n >;\n type TypeAfterUser<\n NextUser extends object,\n Key extends keyof DefinedDBTypeMetadata,\n > = TailorDBType<Fields, NextUser, WithDBTypeMetadata<DefinedDBTypeMetadata, Key>>;\n\n if (options.pluralForm) {\n if (name === options.pluralForm) {\n throw new Error(`The name and the plural form must be different. name=${name}`);\n }\n _settings.pluralForm = options.pluralForm;\n }\n\n const dbType: TailorDBType<Fields, User, DefinedDBTypeMetadata> = {\n name,\n fields: { ...fields },\n _output: null as unknown as InferFieldsOutput<Fields>,\n _description,\n\n get metadata(): TailorDBTypeMetadata {\n // Convert indexes to the format expected by the manifest\n const indexes: Record<string, { fields: string[]; unique?: boolean }> = {};\n if (_indexes.length > 0) {\n _indexes.forEach((index) => {\n const fieldNames = index.fields.map((field) => String(field));\n const key = index.name || `idx_${fieldNames.join(\"_\")}`;\n indexes[key] = {\n fields: fieldNames,\n unique: index.unique,\n };\n });\n }\n\n return {\n name: this.name,\n description: _description,\n settings: _settings,\n permissions: _permissions,\n files: _files,\n ...(Object.keys(indexes).length > 0 && { indexes }),\n };\n },\n\n hooks(hooks: Hooks<Fields>): TypeAfter<\"hooks\"> {\n return runMethodOnce(\"hooks\", () => {\n // `Hooks<Fields>` is strongly typed, but `Object.entries()` loses that information.\n // oxlint-disable-next-line no-explicit-any\n Object.entries(hooks).forEach(([fieldName, fieldHooks]: [string, any]) => {\n const field = this.fields[fieldName];\n if (field === undefined) throw new Error(`field not found: ${fieldName}`);\n (this.fields as Record<string, TailorAnyDBField>)[fieldName] = (\n field as TailorAnyDBField\n ).hooks(fieldHooks);\n });\n return this as TypeAfter<\"hooks\">;\n });\n },\n\n validate(validators: Validators<Fields>): TypeAfter<\"validate\"> {\n return runMethodOnce(\"validate\", () => {\n Object.entries(validators).forEach(([fieldName, fieldValidators]) => {\n const field = this.fields[fieldName] as TailorAnyDBField;\n\n const validators = fieldValidators as\n | FieldValidateInput<unknown>\n | FieldValidateInput<unknown>[];\n\n const isValidateConfig = (v: unknown): v is ValidateConfig<unknown> => {\n return Array.isArray(v) && v.length === 2 && typeof v[1] === \"string\";\n };\n\n let updatedField: TailorAnyDBField;\n if (Array.isArray(validators)) {\n if (isValidateConfig(validators)) {\n updatedField = field.validate(validators);\n } else {\n updatedField = field.validate(...validators);\n }\n } else {\n updatedField = field.validate(validators);\n }\n (this.fields as Record<string, TailorAnyDBField>)[fieldName] = updatedField;\n });\n return this as TypeAfter<\"validate\">;\n });\n },\n\n features(features: Omit<TypeFeatures, \"pluralForm\">): TypeAfter<\"features\"> {\n return runMethodOnce(\"features\", () => {\n _settings = {\n ..._settings,\n ...features,\n };\n return this as TypeAfter<\"features\">;\n });\n },\n\n indexes(\n ...indexes: IndexDef<TailorDBType<Fields, User, DefinedDBTypeMetadata>>[]\n ): TypeAfter<\"indexes\"> {\n return runMethodOnce(\"indexes\", () => {\n _indexes = indexes;\n return this as TypeAfter<\"indexes\">;\n });\n },\n\n files<const F extends string>(\n files: Record<F, string> & FileKeyConflictError<Fields, User>,\n ): TypeAfter<\"files\"> {\n return runMethodOnce(\"files\", () => {\n _files = files;\n return this as TypeAfter<\"files\">;\n });\n },\n\n permission<\n U extends object = User,\n P extends TailorTypePermission<U, output<TailorDBType<Fields, User, DefinedDBTypeMetadata>>> =\n TailorTypePermission<U, output<TailorDBType<Fields, User, DefinedDBTypeMetadata>>>,\n >(permission: P): TypeAfterUser<U, \"permission\"> {\n return runMethodOnce(\"permission\", () => {\n const ret = this as unknown as TypeAfterUser<U, \"permission\">;\n _permissions.record = permission as RawPermissions[\"record\"];\n return ret;\n });\n },\n\n gqlPermission<\n U extends object = User,\n P extends TailorTypeGqlPermission<U> = TailorTypeGqlPermission<U>,\n >(permission: P): TypeAfterUser<U, \"gqlPermission\"> {\n return runMethodOnce(\"gqlPermission\", () => {\n const ret = this as unknown as TypeAfterUser<U, \"gqlPermission\">;\n _permissions.gql = permission as RawPermissions[\"gql\"];\n return ret;\n });\n },\n\n description(description: string): TypeAfter<\"description\"> {\n return runMethodOnce(\"description\", () => {\n _description = description;\n this._description = description;\n return this as TypeAfter<\"description\">;\n });\n },\n\n pickFields<K extends keyof Fields, const Opt extends FieldOptions>(keys: K[], options?: Opt) {\n const result = {} as Record<K, TailorAnyDBField>;\n for (const key of keys) {\n const field = this.fields[key] as TailorAnyDBField;\n if (options) {\n result[key] = field.clone(options);\n } else {\n result[key] = field;\n }\n }\n // oxlint-disable-next-line no-explicit-any\n return result as any;\n },\n\n omitFields<K extends keyof Fields>(keys: K[]): Omit<Fields, K> {\n const keysSet = new Set(keys);\n const result = {} as Record<string, TailorAnyDBField>;\n for (const key in this.fields) {\n if (Object.hasOwn(this.fields, key) && !keysSet.has(key as unknown as K)) {\n result[key] = this.fields[key] as TailorAnyDBField;\n }\n }\n return result as Omit<Fields, K>;\n },\n\n get plugins(): PluginAttachment[] {\n return _plugins;\n },\n\n plugin<P extends keyof PluginConfigs<keyof Fields & string>>(config: {\n [K in P]: PluginConfigs<keyof Fields & string>[K];\n }): TailorDBType<Fields, User, AnyBuilderMethod> {\n for (const [pluginId, pluginConfig] of Object.entries(config)) {\n _plugins.push({ pluginId, config: pluginConfig });\n }\n return this;\n },\n };\n\n return brandValue(dbType, \"tailordb-type\");\n}\n\nconst idField = uuid();\ntype idField = typeof idField;\ntype DBType<\n F extends { id?: never } & Record<string, TailorAnyDBField>,\n Defined extends DefinedDBTypeMetadata = DefinedDBTypeMetadata,\n> = TailorDBInstance<{ id: idField } & F, InferredAttributeMap, Defined>;\n\n/**\n * Creates a new database type with the specified fields.\n * An `id` field (UUID) is automatically added to every type.\n * @param name - The name of the type, or a tuple of [name, pluralForm]\n * @param fields - The field definitions for the type\n * @returns A new TailorDBType instance\n * @example\n * export const user = db.type(\"User\", {\n * name: db.string(),\n * email: db.string(),\n * age: db.int({ optional: true }),\n * role: db.enum([\"admin\", \"member\"]),\n * ...db.fields.timestamps(),\n * });\n * // Always export both the value and type:\n * export type user = typeof user;\n */\nfunction dbType<const F extends { id?: never } & Record<string, TailorAnyDBField>>(\n name: string | [string, string],\n fields: F,\n): DBType<F>;\n/**\n * Creates a new database type with the specified fields and description.\n * An `id` field (UUID) is automatically added to every type.\n * @param name - The name of the type, or a tuple of [name, pluralForm]\n * @param description - A description of the type\n * @param fields - The field definitions for the type\n * @returns A new TailorDBType instance\n */\nfunction dbType<const F extends { id?: never } & Record<string, TailorAnyDBField>>(\n name: string | [string, string],\n description: string,\n fields: F,\n): DBType<F, WithDBTypeMetadata<DefinedDBTypeMetadata, \"description\">>;\nfunction dbType<const F extends { id?: never } & Record<string, TailorAnyDBField>>(\n name: string | [string, string],\n fieldsOrDescription: string | F,\n fields?: F,\n): DBType<F> | DBType<F, WithDBTypeMetadata<DefinedDBTypeMetadata, \"description\">> {\n const typeName = Array.isArray(name) ? name[0] : name;\n const pluralForm = Array.isArray(name) ? name[1] : undefined;\n\n let description: string | undefined;\n let fieldDef: F;\n if (typeof fieldsOrDescription === \"string\") {\n description = fieldsOrDescription;\n fieldDef = fields as F;\n } else {\n fieldDef = fieldsOrDescription;\n }\n return createTailorDBType<{ id: idField } & F>(\n typeName,\n {\n id: idField,\n ...fieldDef,\n },\n { pluralForm, description },\n ) as DBType<F>;\n}\n\n/** TailorDB schema builder utilities for defining types and fields. */\nexport const db = {\n type: dbType,\n uuid,\n string,\n bool,\n int,\n float,\n decimal,\n date,\n datetime,\n time,\n enum: _enum,\n object,\n fields: {\n /**\n * Creates standard timestamp fields (createdAt, updatedAt) with auto-hooks.\n * createdAt is set on create, updatedAt is set on update.\n * A user-specified createdAt is respected when provided (e.g. seeding historical\n * records); the current time is used only when the value is omitted.\n * @returns An object with createdAt and updatedAt fields\n * @example\n * const model = db.type(\"Model\", {\n * name: db.string(),\n * ...db.fields.timestamps(),\n * });\n */\n timestamps: () => ({\n createdAt: datetime()\n .hooks({ create: ({ value }) => value ?? new Date() })\n .description(\"Record creation timestamp\"),\n updatedAt: datetime({ optional: true })\n .hooks({ update: () => new Date() })\n .description(\"Record last update timestamp\"),\n }),\n },\n};\n"],"mappings":";;;;;AAkfA,SAAS,qBACP,QAC8B;CAC9B,OAAO,OAAO,OAAO,SAAS;AAChC;AA4DA,SAAS,oBACP,MACA,SACA,QACA,QACQ;CACR,OAAO,2BAA2B,MAAM,SAAS,QAAQ,MAAM;AACjE;AAEA,SAAS,2BAKP,MACA,SACA,QACA,QACuD;CAIvD,MAAM,YAA6B,EAAE,UAAU,KAAK;CACpD,IAAI;CAEJ,IAAI,SAAS;EACX,IAAI,QAAQ,aAAa,MACvB,UAAU,WAAW;EAEvB,IAAI,QAAQ,UAAU,MACpB,UAAU,QAAQ;CAEtB;CACA,IAAI,QACF,UAAU,gBAAgB,iBAAiB,MAAM;CAGnD,SAASA,gBAAc,MAAmE;EACxF,OAAOC,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;GAAa,CAAC;GAElD,OAAO;EACT;CAGqB,GAAG,eAAe;AAC3C;AAEA,MAAM,UAAU,KAAK;AAyCrB,SAAS,OACP,MACA,qBACA,QACiF;CACjF,MAAM,WAAW,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK;CACjD,MAAM,aAAa,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK;CAEnD,IAAI;CACJ,IAAI;CACJ,IAAI,OAAO,wBAAwB,UAAU;EAC3C,cAAc;EACd,WAAW;CACb,OACE,WAAW;CAEb,OAAO,mBACL,UACA;EACE,IAAI;EACJ,GAAG;CACL,GACA;EAAE;EAAY;CAAY,CAC5B;AACF;;AAGA,MAAa,KAAK;CAChB,MAAM;CACN;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM;CACN;CACA,QAAQ;;;;;;;;;;;;;AAaN,mBAAmB;EACjB,WAAW,SAAS,CAAC,CAClB,MAAM,EAAE,SAAS,EAAE,YAAY,yBAAS,IAAI,KAAK,EAAE,CAAC,CAAC,CACrD,YAAY,2BAA2B;EAC1C,WAAW,SAAS,EAAE,UAAU,KAAK,CAAC,CAAC,CACpC,MAAM,EAAE,8BAAc,IAAI,KAAK,EAAE,CAAC,CAAC,CACnC,YAAY,8BAA8B;CAC/C,GACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"secretmanager-Bd45j7an.mjs","names":[],"sources":["../src/vitest/mocks/shared.ts","../src/vitest/mocks/secretmanager.ts"],"sourcesContent":["// ---------------------------------------------------------------------------\n// Shared helpers\n// ---------------------------------------------------------------------------\n\n// Attach a non-enumerable `Symbol.dispose` to a facade so it works with `using`.\nexport function withDispose<T extends object>(facade: T, dispose: () => void): T & Disposable {\n Object.defineProperty(facade, Symbol.dispose, {\n value: dispose,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n return facade as T & Disposable;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function tailorRoot(): Record<string, any> {\n const g = globalThis as Record<string, unknown>;\n if (!g.tailor) {\n // Ensure the container (and the always-present context stub) exists even if\n // the base globals were not installed (e.g. a unit test that only acquires\n // a single mock without the tailor-runtime environment).\n g.tailor = { context: { getInvoker: () => null } };\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return g.tailor as Record<string, any>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function tailordbRoot(): Record<string, any> {\n const g = globalThis as Record<string, unknown>;\n if (!g.tailordb) {\n g.tailordb = {};\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return g.tailordb as Record<string, any>;\n}\n","import { vi } from \"vitest\";\nimport { assertDefined } from \"#/utils/assert\";\nimport { tailorRoot, withDispose } from \"./shared\";\n\ninterface SecretCall {\n method: \"getSecret\" | \"getSecrets\";\n vault: string;\n name?: string;\n names?: readonly string[];\n}\n\n// ---------------------------------------------------------------------------\n// SecretManager Mock\n// ---------------------------------------------------------------------------\n\n// Hidden accessor key used to inherit the previous scope's secret store on\n// acquisition (so secrets seeded once outside tests — e.g. from tailor.config.ts\n// via setup.ts — remain visible) while still isolating per-test overrides.\nconst SECRET_STORE = Symbol(\"tailorSecretStore\");\n\n/**\n * Acquire a disposable mock for `tailor.secretmanager`. The secret store is\n * inherited (cloned) from the currently-installed mock on acquisition and\n * restored on dispose, so secrets seeded outside the test survive across\n * `using` scopes while per-test `setSecrets()` overrides stay isolated.\n * @returns Disposable SecretManager mock control object\n * @example\n * ```typescript\n * import { mockSecretmanager } from \"@tailor-platform/sdk/vitest\";\n *\n * test(\"reads secrets from vault\", async () => {\n * using sm = mockSecretmanager();\n * sm.setSecrets({ \"my-vault\": { API_KEY: \"sk-123\" } });\n * // …\n * });\n * ```\n */\nexport function mockSecretmanager() {\n const root = tailorRoot();\n const prev = root.secretmanager;\n\n const holder: { store: Record<string, Record<string, string>> } = {\n // prior mock state may be absent\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n store: structuredClone((prev?.[SECRET_STORE]?.store as typeof holder.store) ?? {}),\n };\n\n const getSecret = vi.fn(\n async (vault: string, name: string): Promise<string | undefined> => holder.store[vault]?.[name],\n );\n const getSecrets = vi.fn(\n async <const T extends readonly string[]>(\n vault: string,\n names: T,\n ): Promise<Partial<Record<T[number], string>>> => {\n const vaultData = holder.store[vault] ?? {};\n const result: Record<string, string> = {};\n for (const name of names) {\n if (name in vaultData) {\n result[name] = assertDefined(vaultData[name], `vault entry missing for: ${name}`);\n }\n }\n return result as Partial<Record<T[number], string>>;\n },\n );\n\n root.secretmanager = { getSecret, getSecrets, [SECRET_STORE]: holder };\n\n const facade = {\n /** The `getSecret` `vi.fn`. */\n getSecret,\n /** The `getSecrets` `vi.fn`. */\n getSecrets,\n\n setSecrets(secrets: Record<string, Record<string, string>>): void {\n holder.store = secrets;\n },\n\n get calls(): SecretCall[] {\n // Merge both methods' calls back into chronological order via vi.fn's\n // global invocationCallOrder, so a test mixing getSecret/getSecrets sees\n // them in the order they actually ran (not all getSecret, then all getSecrets).\n const entries: { order: number; call: SecretCall }[] = [\n ...getSecret.mock.calls.map((args, i) => ({\n order: getSecret.mock.invocationCallOrder[i] ?? 0,\n call: { method: \"getSecret\" as const, vault: args[0] as string, name: args[1] as string },\n })),\n ...getSecrets.mock.calls.map((args, i) => ({\n order: getSecrets.mock.invocationCallOrder[i] ?? 0,\n call: {\n method: \"getSecrets\" as const,\n vault: args[0] as string,\n names: args[1] as readonly string[],\n },\n })),\n ];\n return entries.toSorted((a, b) => a.order - b.order).map((e) => e.call);\n },\n\n reset(): void {\n holder.store = {};\n getSecret.mockClear();\n getSecrets.mockClear();\n },\n };\n\n return withDispose(facade, () => {\n root.secretmanager = prev;\n });\n}\n"],"mappings":";;;;AAKA,SAAgB,YAA8B,QAAW,SAAqC;CAC5F,OAAO,eAAe,QAAQ,OAAO,SAAS;EAC5C,OAAO;EACP,YAAY;EACZ,UAAU;EACV,cAAc;CAChB,CAAC;CACD,OAAO;AACT;AAGA,SAAgB,aAAkC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K;IACd;GACF,EAAE,CAES,CAAC,CAAC,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,KAAK,MAAM,EAAE,IAAI;EACxE;EAEA,QAAc;GACZ,OAAO,QAAQ,CAAC;GAChB,UAAU,UAAU;GACpB,WAAW,UAAU;EACvB;CAGsB,SAAS;EAC/B,KAAK,gBAAgB;CACvB,CAAC;AACH"}
|
package/dist/types-BzJ7A_fn.mjs
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { n as mapAllowedValues, t as parseInternal } from "./field-runtime-D4QWRiB1.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/configure/types/type.ts
|
|
4
|
-
function createTailorField(type, options, fields, values, metadata) {
|
|
5
|
-
const _metadata = metadata ? {
|
|
6
|
-
...metadata,
|
|
7
|
-
...metadata.allowedValues && { allowedValues: metadata.allowedValues.map((v) => ({ ...v })) },
|
|
8
|
-
...metadata.validate && { validate: metadata.validate.map((v) => Array.isArray(v) ? [...v] : v) }
|
|
9
|
-
} : { required: true };
|
|
10
|
-
if (!metadata) {
|
|
11
|
-
if (options) {
|
|
12
|
-
if (options.optional === true) _metadata.required = false;
|
|
13
|
-
if (options.array === true) _metadata.array = true;
|
|
14
|
-
}
|
|
15
|
-
if (values) _metadata.allowedValues = mapAllowedValues(values);
|
|
16
|
-
}
|
|
17
|
-
function parseInternal$1(args) {
|
|
18
|
-
return parseInternal({
|
|
19
|
-
...args,
|
|
20
|
-
field
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Clone the field and apply metadata updates to the clone.
|
|
25
|
-
* The original instance is never mutated, so a field shared across places
|
|
26
|
-
* cannot leak metadata between them.
|
|
27
|
-
* @param metadataUpdates - Metadata properties to overwrite on the clone
|
|
28
|
-
* @returns A new field with the updated metadata
|
|
29
|
-
*/
|
|
30
|
-
function cloneWith(metadataUpdates) {
|
|
31
|
-
const cloned = field.clone();
|
|
32
|
-
Object.assign(cloned._metadata, metadataUpdates);
|
|
33
|
-
return cloned;
|
|
34
|
-
}
|
|
35
|
-
const field = {
|
|
36
|
-
type,
|
|
37
|
-
fields: fields ?? {},
|
|
38
|
-
_defined: void 0,
|
|
39
|
-
_output: void 0,
|
|
40
|
-
_metadata,
|
|
41
|
-
get metadata() {
|
|
42
|
-
return { ...this._metadata };
|
|
43
|
-
},
|
|
44
|
-
description(description) {
|
|
45
|
-
return cloneWith({ description });
|
|
46
|
-
},
|
|
47
|
-
typeName(typeName) {
|
|
48
|
-
return cloneWith({ typeName });
|
|
49
|
-
},
|
|
50
|
-
validate(...validateInputs) {
|
|
51
|
-
return cloneWith({ validate: validateInputs });
|
|
52
|
-
},
|
|
53
|
-
parse(args) {
|
|
54
|
-
return parseInternal$1({
|
|
55
|
-
value: args.value,
|
|
56
|
-
data: args.data,
|
|
57
|
-
user: args.user,
|
|
58
|
-
pathArray: []
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
_parseInternal: parseInternal$1,
|
|
62
|
-
clone() {
|
|
63
|
-
let clonedFields = fields;
|
|
64
|
-
if (fields) {
|
|
65
|
-
const cloned = {};
|
|
66
|
-
for (const [key, nestedField] of Object.entries(fields)) cloned[key] = nestedField.clone();
|
|
67
|
-
clonedFields = cloned;
|
|
68
|
-
}
|
|
69
|
-
return createTailorField(type, options, clonedFields, values, this._metadata);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
return field;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Create a UUID field for resolver input/output.
|
|
76
|
-
* @param options - Field configuration options
|
|
77
|
-
* @returns A UUID field
|
|
78
|
-
* @example t.uuid()
|
|
79
|
-
*/
|
|
80
|
-
function uuid(options) {
|
|
81
|
-
return createTailorField("uuid", options);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Create a string field for resolver input/output.
|
|
85
|
-
* @param options - Field configuration options
|
|
86
|
-
* @returns A string field
|
|
87
|
-
* @example t.string()
|
|
88
|
-
* @example t.string({ optional: true })
|
|
89
|
-
* @example t.string({ array: true })
|
|
90
|
-
*/
|
|
91
|
-
function string(options) {
|
|
92
|
-
return createTailorField("string", options);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Create a boolean field for resolver input/output.
|
|
96
|
-
* @param options - Field configuration options
|
|
97
|
-
* @returns A boolean field
|
|
98
|
-
* @example t.bool()
|
|
99
|
-
*/
|
|
100
|
-
function bool(options) {
|
|
101
|
-
return createTailorField("boolean", options);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Create an integer field for resolver input/output.
|
|
105
|
-
* @param options - Field configuration options
|
|
106
|
-
* @returns An integer field
|
|
107
|
-
* @example t.int()
|
|
108
|
-
*/
|
|
109
|
-
function int(options) {
|
|
110
|
-
return createTailorField("integer", options);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Create a float field for resolver input/output.
|
|
114
|
-
* @param options - Field configuration options
|
|
115
|
-
* @returns A float field
|
|
116
|
-
* @example t.float()
|
|
117
|
-
*/
|
|
118
|
-
function float(options) {
|
|
119
|
-
return createTailorField("float", options);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Create a decimal field for resolver input/output (stored as string for precision).
|
|
123
|
-
* @param options - Field configuration options
|
|
124
|
-
* @returns A decimal field
|
|
125
|
-
* @example t.decimal()
|
|
126
|
-
* @example t.decimal({ optional: true })
|
|
127
|
-
*/
|
|
128
|
-
function decimal(options) {
|
|
129
|
-
return createTailorField("decimal", options);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Create a date field for resolver input/output.
|
|
133
|
-
* @param options - Field configuration options
|
|
134
|
-
* @returns A date field
|
|
135
|
-
* @example t.date()
|
|
136
|
-
*/
|
|
137
|
-
function date(options) {
|
|
138
|
-
return createTailorField("date", options);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Create a datetime field for resolver input/output.
|
|
142
|
-
* @param options - Field configuration options
|
|
143
|
-
* @returns A datetime field
|
|
144
|
-
* @example t.datetime()
|
|
145
|
-
*/
|
|
146
|
-
function datetime(options) {
|
|
147
|
-
return createTailorField("datetime", options);
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Create a time field for resolver input/output.
|
|
151
|
-
* @param options - Field configuration options
|
|
152
|
-
* @returns A time field
|
|
153
|
-
* @example t.time()
|
|
154
|
-
*/
|
|
155
|
-
function time(options) {
|
|
156
|
-
return createTailorField("time", options);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Create an enum field for resolver input/output.
|
|
160
|
-
* @param values - Array of allowed string values
|
|
161
|
-
* @param options - Field configuration options
|
|
162
|
-
* @returns An enum field
|
|
163
|
-
* @example t.enum(["active", "inactive"])
|
|
164
|
-
*/
|
|
165
|
-
function _enum(values, options) {
|
|
166
|
-
return createTailorField("enum", options, void 0, values);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Create a nested object field for resolver input/output.
|
|
170
|
-
* @param fields - Record of field definitions
|
|
171
|
-
* @param options - Field options (optional, array)
|
|
172
|
-
* @returns A nested object field
|
|
173
|
-
* @example
|
|
174
|
-
* // Single object:
|
|
175
|
-
* output: t.object({ name: t.string(), email: t.string() })
|
|
176
|
-
* @example
|
|
177
|
-
* // Array of objects:
|
|
178
|
-
* items: t.object({ name: t.string() }, { array: true })
|
|
179
|
-
*/
|
|
180
|
-
function object(fields, options) {
|
|
181
|
-
return createTailorField("nested", options, fields);
|
|
182
|
-
}
|
|
183
|
-
const t = {
|
|
184
|
-
uuid,
|
|
185
|
-
string,
|
|
186
|
-
bool,
|
|
187
|
-
int,
|
|
188
|
-
float,
|
|
189
|
-
decimal,
|
|
190
|
-
date,
|
|
191
|
-
datetime,
|
|
192
|
-
time,
|
|
193
|
-
enum: _enum,
|
|
194
|
-
object
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
//#endregion
|
|
198
|
-
export { t };
|
|
199
|
-
//# sourceMappingURL=types-BzJ7A_fn.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-BzJ7A_fn.mjs","names":["parseInternal","parseFieldInternal"],"sources":["../src/configure/types/type.ts"],"sourcesContent":["import { type AllowedValues, type AllowedValuesOutput, mapAllowedValues } from \"./field\";\nimport {\n parseInternal as parseFieldInternal,\n type FieldParseArgs,\n type FieldParseInternalArgs,\n} from \"./field-runtime\";\nimport type {\n DefinedFieldMetadata,\n TailorFieldType,\n TailorToTs,\n FieldMetadata,\n FieldOptions,\n FieldOutput,\n TailorField as TailorFieldBase,\n FieldValidateInput,\n} from \"#/configure/types/field.types\";\nimport type { InferFieldsOutput, TypeLevelError } from \"#/types/helpers\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n// Erased fields stay assignable across builder method-state changes.\n// oxlint-disable-next-line no-explicit-any\ntype AnyBuilderMethod = any;\n\nexport type TailorAnyField = Omit<\n TailorFieldBase<AnyBuilderMethod, AnyBuilderMethod, FieldMetadata, TailorFieldType>,\n \"fields\"\n> & {\n readonly fields: Record<string, AnyBuilderMethod>;\n _metadata: FieldMetadata;\n description: AnyBuilderMethod;\n typeName: AnyBuilderMethod;\n validate: AnyBuilderMethod;\n parse: AnyBuilderMethod;\n _parseInternal: AnyBuilderMethod;\n};\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\ntype WithFieldDescription<Defined> = Defined & { description: true };\ntype WithFieldTypeName<Defined> = Defined & { typeName: true };\ntype WithFieldValidate<Defined> = Defined & { validate: true };\ntype FieldDescriptionFn<Defined extends DefinedFieldMetadata, Output> = (\n description: string,\n) => TailorField<WithFieldDescription<Defined>, Output>;\ntype FieldTypeNameFn<Defined extends DefinedFieldMetadata, Output> = (\n typeName: string,\n) => TailorField<WithFieldTypeName<Defined>, Output>;\ntype FieldValidateFn<Defined extends DefinedFieldMetadata, Output> = (\n ...validate: FieldValidateInput<Output>[]\n) => TailorField<WithFieldValidate<Defined>, Output>;\ntype FieldDescriptionMethod<Defined extends DefinedFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? FieldDescriptionFn<Defined, Output>\n : Defined extends { description: unknown }\n ? TypeLevelError<\".description() has already been set\">\n : FieldDescriptionFn<Defined, Output>;\ntype FieldTypeNameMethod<Defined extends DefinedFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? TypeLevelError<string>\n : Defined extends { typeName: unknown }\n ? TypeLevelError<\".typeName() has already been set\">\n : Defined extends { type: \"enum\" | \"nested\" }\n ? FieldTypeNameFn<Defined, Output>\n : TypeLevelError<\"typeName can only be set on enum or object fields\">;\ntype FieldValidateMethod<Defined extends DefinedFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? FieldValidateFn<Defined, Output>\n : Defined extends { validate: unknown }\n ? TypeLevelError<\".validate() has already been set\">\n : FieldValidateFn<Defined, Output>;\n\n/**\n * Full TailorField interface with builder methods.\n * Extends the minimal structural interface from types/ with fluent API methods.\n */\nexport interface TailorField<\n Defined extends DefinedFieldMetadata = DefinedFieldMetadata,\n // Generic default output type (kept loose on purpose for library ergonomics).\n // oxlint-disable-next-line no-explicit-any\n Output = any,\n M extends FieldMetadata = FieldMetadata,\n T extends TailorFieldType = TailorFieldType,\n> extends TailorFieldBase<Defined, Output, M, T> {\n readonly fields: Record<string, TailorAnyField>;\n _metadata: M;\n\n /**\n * Set a description for the field\n * @param description - The description text\n * @returns The field with updated metadata\n */\n description: FieldDescriptionMethod<Defined, Output>;\n\n /**\n * Set a custom type name for enum or nested types\n * @param typeName - The custom type name\n * @returns The field with updated metadata\n */\n typeName: FieldTypeNameMethod<Defined, Output>;\n\n /**\n * Add validation functions to the field\n * @param validate - One or more validation functions\n * @returns The field with updated metadata\n */\n validate: FieldValidateMethod<Defined, Output>;\n\n /**\n * Parse and validate a value against this field's validation rules\n * Returns StandardSchema Result type with success or failure\n * @param args - Value, context data, and user\n * @returns Validation result\n */\n parse(args: FieldParseArgs): StandardSchemaV1.Result<Output>;\n\n /**\n * Internal parse method that tracks field path for nested validation\n * @private\n * @param args - Parse arguments\n * @returns Validation result\n */\n _parseInternal(args: FieldParseInternalArgs): StandardSchemaV1.Result<Output>;\n}\n\n/**\n * Internal shape carried by every runtime field for clone-on-write support.\n *\n * `clone()` is intentionally kept off the public {@link TailorField} interface:\n * adding it there would force `TailorDBField` (which has a differently-typed\n * `clone`) to stop being assignable to `TailorField`, breaking the supported\n * `t.object({ field: db.string() })` usage. Every `t.*` and `db.*` field carries\n * a `clone()` at runtime, so the internal cast in `clone()` is safe.\n */\ntype CloneableField = { clone(): TailorAnyField };\n\ntype TailorFieldRuntime<\n Defined extends DefinedFieldMetadata,\n Output,\n M extends FieldMetadata = FieldMetadata,\n T extends TailorFieldType = TailorFieldType,\n> = TailorFieldBase<Defined, Output, M, T> & {\n readonly fields: Record<string, TailorAnyField>;\n _metadata: M;\n description(description: string): object;\n typeName(typeName: string): object;\n validate(...validate: FieldValidateInput<Output>[]): object;\n parse(args: FieldParseArgs): StandardSchemaV1.Result<Output>;\n _parseInternal(args: FieldParseInternalArgs): StandardSchemaV1.Result<Output>;\n clone(): TailorAnyField;\n};\n\n/**\n * Creates a new TailorField instance.\n * @param type - Field type\n * @param options - Field options\n * @param fields - Nested fields for object-like types\n * @param values - Allowed values for enum-like fields\n * @param metadata - Pre-built metadata to clone from (used by `clone()`); when\n * given, the mutable containers are deep-copied here and `options`/`values` are\n * ignored for metadata construction\n * @returns A new TailorField\n */\nfunction createTailorField<\n const T extends TailorFieldType,\n const TOptions extends FieldOptions,\n const OutputBase = TailorToTs[T],\n>(\n type: T,\n options?: TOptions,\n fields?: Record<string, TailorAnyField>,\n values?: AllowedValues,\n metadata?: FieldMetadata,\n): TailorField<\n { type: T; array: TOptions extends { array: true } ? true : false },\n FieldOutput<OutputBase, TOptions>\n>;\nfunction createTailorField<\n const T extends TailorFieldType,\n const TOptions extends FieldOptions,\n const OutputBase = TailorToTs[T],\n>(\n type: T,\n options?: TOptions,\n fields?: Record<string, TailorAnyField>,\n values?: AllowedValues,\n metadata?: FieldMetadata,\n): object {\n type FieldValue = FieldOutput<OutputBase, TOptions>;\n\n // When cloning, take ownership of the source metadata and deep-copy its mutable\n // containers (enum value objects and `[fn, message]` validator tuples; validator\n // functions are kept by reference) so no two instances share mutable state.\n const _metadata: FieldMetadata = metadata\n ? {\n ...metadata,\n ...(metadata.allowedValues && {\n allowedValues: metadata.allowedValues.map((v) => ({ ...v })),\n }),\n ...(metadata.validate && {\n validate: metadata.validate.map((v) => (Array.isArray(v) ? ([...v] as typeof v) : v)),\n }),\n }\n : { required: true };\n\n if (!metadata) {\n if (options) {\n if (options.optional === true) {\n _metadata.required = false;\n }\n if (options.array === true) {\n _metadata.array = true;\n }\n }\n if (values) {\n _metadata.allowedValues = mapAllowedValues(values);\n }\n }\n\n function parseInternal(\n args: FieldParseInternalArgs,\n ): StandardSchemaV1.Result<FieldOutput<OutputBase, TOptions>> {\n return parseFieldInternal<T, FieldOutput<OutputBase, TOptions>>({\n ...args,\n field,\n });\n }\n\n /**\n * Clone the field and apply metadata updates to the clone.\n * The original instance is never mutated, so a field shared across places\n * cannot leak metadata between them.\n * @param metadataUpdates - Metadata properties to overwrite on the clone\n * @returns A new field with the updated metadata\n */\n function cloneWith(metadataUpdates: Partial<FieldMetadata>) {\n const cloned = field.clone();\n Object.assign(cloned._metadata, metadataUpdates);\n return cloned;\n }\n\n const field: TailorFieldRuntime<\n { type: T; array: TOptions extends { array: true } ? true : false },\n FieldValue,\n FieldMetadata,\n T\n > = {\n type,\n fields: fields ?? {},\n _defined: undefined as unknown as {\n type: T;\n array: TOptions extends { array: true } ? true : false;\n },\n _output: undefined as FieldOutput<OutputBase, TOptions>,\n _metadata,\n\n get metadata() {\n return { ...this._metadata };\n },\n\n description(description: string) {\n // Clone-on-write so a shared field instance never leaks metadata.\n return cloneWith({ description });\n },\n\n typeName(typeName: string) {\n // Clone-on-write so a shared field instance never leaks metadata.\n return cloneWith({ typeName });\n },\n\n validate(...validateInputs: FieldValidateInput<FieldValue>[]) {\n // Clone-on-write so a shared field instance never leaks metadata.\n return cloneWith({ validate: validateInputs });\n },\n\n parse(args: FieldParseArgs): StandardSchemaV1.Result<FieldOutput<OutputBase, TOptions>> {\n return parseInternal({\n value: args.value,\n data: args.data,\n user: args.user,\n pathArray: [],\n });\n },\n\n _parseInternal: parseInternal,\n\n clone() {\n // Deep clone nested object fields so the new instance shares no mutable state.\n let clonedFields = fields;\n if (fields) {\n const cloned: Record<string, TailorAnyField> = {};\n for (const [key, nestedField] of Object.entries(fields)) {\n // Both t.* and db.* fields carry clone() at runtime (see CloneableField).\n cloned[key] = (nestedField as TailorAnyField & CloneableField).clone();\n }\n clonedFields = cloned;\n }\n\n // Rebuild via the factory, handing it this field's metadata so the new\n // parseInternal closure rebinds to the clone and the factory owns the metadata deep-copy.\n // oxlint-disable-next-line no-explicit-any\n return createTailorField(type, options, clonedFields, values, this._metadata) as any;\n },\n };\n\n return field;\n}\n\n/**\n * Create a UUID field for resolver input/output.\n * @param options - Field configuration options\n * @returns A UUID field\n * @example t.uuid()\n */\nfunction uuid<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"uuid\", options);\n}\n\n/**\n * Create a string field for resolver input/output.\n * @param options - Field configuration options\n * @returns A string field\n * @example t.string()\n * @example t.string({ optional: true })\n * @example t.string({ array: true })\n */\nfunction string<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"string\", options);\n}\n\n/**\n * Create a boolean field for resolver input/output.\n * @param options - Field configuration options\n * @returns A boolean field\n * @example t.bool()\n */\nfunction bool<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"boolean\", options);\n}\n\n/**\n * Create an integer field for resolver input/output.\n * @param options - Field configuration options\n * @returns An integer field\n * @example t.int()\n */\nfunction int<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"integer\", options);\n}\n\n/**\n * Create a float field for resolver input/output.\n * @param options - Field configuration options\n * @returns A float field\n * @example t.float()\n */\nfunction float<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"float\", options);\n}\n\n/**\n * Create a decimal field for resolver input/output (stored as string for precision).\n * @param options - Field configuration options\n * @returns A decimal field\n * @example t.decimal()\n * @example t.decimal({ optional: true })\n */\nfunction decimal<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"decimal\", options);\n}\n\n/**\n * Create a date field for resolver input/output.\n * @param options - Field configuration options\n * @returns A date field\n * @example t.date()\n */\nfunction date<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"date\", options);\n}\n\n/**\n * Create a datetime field for resolver input/output.\n * @param options - Field configuration options\n * @returns A datetime field\n * @example t.datetime()\n */\nfunction datetime<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"datetime\", options);\n}\n\n/**\n * Create a time field for resolver input/output.\n * @param options - Field configuration options\n * @returns A time field\n * @example t.time()\n */\nfunction time<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"time\", options);\n}\n\n/**\n * Create an enum field for resolver input/output.\n * @param values - Array of allowed string values\n * @param options - Field configuration options\n * @returns An enum field\n * @example t.enum([\"active\", \"inactive\"])\n */\nfunction _enum<const V extends AllowedValues, const Opt extends FieldOptions>(\n values: V,\n options?: Opt,\n): TailorField<\n { type: \"enum\"; array: Opt extends { array: true } ? true : false },\n FieldOutput<AllowedValuesOutput<V>, Opt>\n> {\n return createTailorField<\"enum\", Opt, AllowedValuesOutput<V>>(\"enum\", options, undefined, values);\n}\n\n/**\n * Create a nested object field for resolver input/output.\n * @param fields - Record of field definitions\n * @param options - Field options (optional, array)\n * @returns A nested object field\n * @example\n * // Single object:\n * output: t.object({ name: t.string(), email: t.string() })\n * @example\n * // Array of objects:\n * items: t.object({ name: t.string() }, { array: true })\n */\nfunction object<const F extends Record<string, TailorAnyField>, const Opt extends FieldOptions>(\n fields: F,\n options?: Opt,\n) {\n const objectField = createTailorField(\"nested\", options, fields) as TailorField<\n { type: \"nested\"; array: Opt extends { array: true } ? true : false },\n FieldOutput<InferFieldsOutput<F>, Opt>\n >;\n return objectField;\n}\n\nexport const t = {\n uuid,\n string,\n bool,\n int,\n float,\n decimal,\n date,\n datetime,\n time,\n enum: _enum,\n object,\n};\n"],"mappings":";;;AA+KA,SAAS,kBAKP,MACA,SACA,QACA,QACA,UACQ;CAMR,MAAM,YAA2B,WAC7B;EACE,GAAG;EACH,GAAI,SAAS,iBAAiB,EAC5B,eAAe,SAAS,cAAc,KAAK,OAAO,EAAE,GAAG,EAAE,EAAE,EAC7D;EACA,GAAI,SAAS,YAAY,EACvB,UAAU,SAAS,SAAS,KAAK,MAAO,MAAM,QAAQ,CAAC,IAAK,CAAC,GAAG,CAAC,IAAiB,CAAE,EACtF;CACF,IACA,EAAE,UAAU,KAAK;CAErB,IAAI,CAAC,UAAU;EACb,IAAI,SAAS;GACX,IAAI,QAAQ,aAAa,MACvB,UAAU,WAAW;GAEvB,IAAI,QAAQ,UAAU,MACpB,UAAU,QAAQ;EAEtB;EACA,IAAI,QACF,UAAU,gBAAgB,iBAAiB,MAAM;CAErD;CAEA,SAASA,gBACP,MAC4D;EAC5D,OAAOC,cAAyD;GAC9D,GAAG;GACH;EACF,CAAC;CACH;;;;;;;;CASA,SAAS,UAAU,iBAAyC;EAC1D,MAAM,SAAS,MAAM,MAAM;EAC3B,OAAO,OAAO,OAAO,WAAW,eAAe;EAC/C,OAAO;CACT;CAEA,MAAM,QAKF;EACF;EACA,QAAQ,UAAU,CAAC;EACnB,UAAU;EAIV,SAAS;EACT;EAEA,IAAI,WAAW;GACb,OAAO,EAAE,GAAG,KAAK,UAAU;EAC7B;EAEA,YAAY,aAAqB;GAE/B,OAAO,UAAU,EAAE,YAAY,CAAC;EAClC;EAEA,SAAS,UAAkB;GAEzB,OAAO,UAAU,EAAE,SAAS,CAAC;EAC/B;EAEA,SAAS,GAAG,gBAAkD;GAE5D,OAAO,UAAU,EAAE,UAAU,eAAe,CAAC;EAC/C;EAEA,MAAM,MAAkF;GACtF,OAAOD,gBAAc;IACnB,OAAO,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A;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM;CACN;AACF"}
|
package/dist/types-CG9H7HuE.mjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-DXywRVcq.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/runtime/workflow.ts
|
|
4
|
-
var workflow_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
-
resolve: () => resolve,
|
|
6
|
-
resumeWorkflow: () => resumeWorkflow,
|
|
7
|
-
triggerJobFunction: () => triggerJobFunction,
|
|
8
|
-
triggerWorkflow: () => triggerWorkflow,
|
|
9
|
-
wait: () => wait
|
|
10
|
-
});
|
|
11
|
-
const api = () => globalThis.tailor.workflow;
|
|
12
|
-
/**
|
|
13
|
-
* See {@link TailorWorkflowAPI.triggerWorkflow}.
|
|
14
|
-
* @param args - Forwarded to {@link TailorWorkflowAPI.triggerWorkflow}
|
|
15
|
-
* @returns The execution ID of the triggered workflow
|
|
16
|
-
*/
|
|
17
|
-
const triggerWorkflow = (...args) => api().triggerWorkflow(...args);
|
|
18
|
-
/**
|
|
19
|
-
* See {@link TailorWorkflowAPI.resumeWorkflow}.
|
|
20
|
-
* @param args - Forwarded to {@link TailorWorkflowAPI.resumeWorkflow}
|
|
21
|
-
* @returns The execution ID of the resumed workflow
|
|
22
|
-
*/
|
|
23
|
-
const resumeWorkflow = (...args) => api().resumeWorkflow(...args);
|
|
24
|
-
/**
|
|
25
|
-
* See {@link TailorWorkflowAPI.triggerJobFunction}.
|
|
26
|
-
* @param args - Forwarded to {@link TailorWorkflowAPI.triggerJobFunction}
|
|
27
|
-
* @returns The job's return value
|
|
28
|
-
*/
|
|
29
|
-
const triggerJobFunction = (...args) => api().triggerJobFunction(...args);
|
|
30
|
-
/**
|
|
31
|
-
* See {@link TailorWorkflowAPI.wait}.
|
|
32
|
-
* @param args - Forwarded to {@link TailorWorkflowAPI.wait}
|
|
33
|
-
* @returns The payload supplied by the corresponding `resolve` call
|
|
34
|
-
*/
|
|
35
|
-
const wait = (...args) => api().wait(...args);
|
|
36
|
-
/**
|
|
37
|
-
* See {@link TailorWorkflowAPI.resolve}.
|
|
38
|
-
* @param args - Forwarded to {@link TailorWorkflowAPI.resolve}
|
|
39
|
-
* @returns A promise that resolves once the resolve has been recorded
|
|
40
|
-
*/
|
|
41
|
-
const resolve = (...args) => api().resolve(...args);
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
export { wait as a, triggerWorkflow as i, resumeWorkflow as n, workflow_exports as o, triggerJobFunction as r, resolve as t };
|
|
45
|
-
//# sourceMappingURL=workflow-DSwnYPPP.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-DSwnYPPP.mjs","names":[],"sources":["../src/runtime/workflow.ts"],"sourcesContent":["/**\n * Workflow utilities.\n *\n * Thin typed wrapper around the platform-provided `tailor.workflow` runtime API.\n * At runtime this delegates to `globalThis.tailor.workflow`. Use `mockWorkflow`\n * from `@tailor-platform/sdk/vitest` to mock these calls in unit tests.\n * @example\n * import { workflow } from \"@tailor-platform/sdk/runtime\";\n *\n * const executionId = await workflow.triggerWorkflow(\"myWorkflow\", { data: \"value\" });\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Specifies the machine user that should be used to execute the workflow.\n * This allows workflows to run with specific authentication context.\n */\nexport interface AuthInvoker {\n /** The namespace where the machine user is defined */\n namespace: string;\n /** The name of the machine user to use for workflow execution */\n machineUserName: string;\n}\n\n/** Options for {@link triggerWorkflow}. */\nexport interface TriggerWorkflowOptions {\n /** Optional authentication invoker to specify which machine user should execute the workflow */\n authInvoker?: AuthInvoker;\n}\n\ndeclare const executionPolicyKeyBrand: unique symbol;\n\n/**\n * A concrete runtime key produced by an execution policy instance — either an\n * exact-match policy's `.key`, or a wildcard policy's `.keyFor(suffix)` (see\n * `defineWorkflowExecutionPolicies`). Branded so an arbitrary string that\n * wasn't derived from a declared policy can't be passed as `executionPolicyKey`.\n */\nexport type ExecutionPolicyKey = string & { readonly [executionPolicyKeyBrand]: never };\n\n/** Options for {@link triggerJobFunction}. */\nexport interface TriggerJobFunctionOptions {\n /**\n * Execution policy key matched by the platform against the policies\n * declared with `defineWorkflowExecutionPolicies` in `tailor.config.ts`.\n */\n executionPolicyKey?: ExecutionPolicyKey;\n}\n\n/**\n * Platform API surface for `tailor.workflow`. Describes the shape the platform\n * runtime injects on `globalThis.tailor.workflow`.\n *\n * Each method below is also re-exported as a top-level named export from this\n * module so callers can either `import * as workflow from\n * \"@tailor-platform/sdk/runtime/workflow\"` or pick individual methods.\n */\nexport interface TailorWorkflowAPI {\n /**\n * Triggers a workflow and returns its execution ID.\n * @param workflowName - Workflow name as defined in tailor.config\n * @param args - Arguments forwarded to the workflow's main job\n * @param options - Optional trigger options (e.g. `authInvoker`)\n * @returns The execution ID of the triggered workflow\n */\n triggerWorkflow(\n workflowName: string,\n args?: any,\n options?: TriggerWorkflowOptions,\n ): Promise<string>;\n\n /**\n * Resumes a failed or pending-retry workflow execution and returns its execution ID.\n * @param executionId - The execution to resume\n * @returns The execution ID of the resumed workflow\n */\n resumeWorkflow(executionId: string): Promise<string>;\n\n /**\n * Triggers a job function and returns its result.\n * @param jobName - Job name as defined in the workflow\n * @param args - Arguments forwarded to the job\n * @param options - Optional trigger options (e.g. `executionPolicyKey`)\n * @returns The job's return value\n */\n triggerJobFunction(jobName: string, args?: any, options?: TriggerJobFunctionOptions): any;\n\n /**\n * Suspends the current workflow execution and waits for an external signal to resume.\n * @param key - Wait point key\n * @param payload - Optional payload to record with the wait point\n * @returns The payload supplied by the corresponding `resolve` call\n */\n wait(key: string, payload?: any): any;\n\n /**\n * Resolves a waiting workflow execution, causing it to resume.\n * @param executionId - The execution to resume\n * @param key - Wait point key to resolve\n * @param callback - Callback receiving the wait payload; its return value is forwarded to `wait`\n * @returns A promise that resolves once the resolve has been recorded\n */\n resolve(executionId: string, key: string, callback: (waitPayload: any) => any): Promise<void>;\n}\n\nconst api = (): TailorWorkflowAPI =>\n (globalThis as { tailor: { workflow: TailorWorkflowAPI } }).tailor.workflow;\n\n/**\n * See {@link TailorWorkflowAPI.triggerWorkflow}.\n * @param args - Forwarded to {@link TailorWorkflowAPI.triggerWorkflow}\n * @returns The execution ID of the triggered workflow\n */\nexport const triggerWorkflow: TailorWorkflowAPI[\"triggerWorkflow\"] = (...args) =>\n api().triggerWorkflow(...args);\n\n/**\n * See {@link TailorWorkflowAPI.resumeWorkflow}.\n * @param args - Forwarded to {@link TailorWorkflowAPI.resumeWorkflow}\n * @returns The execution ID of the resumed workflow\n */\nexport const resumeWorkflow: TailorWorkflowAPI[\"resumeWorkflow\"] = (...args) =>\n api().resumeWorkflow(...args);\n\n/**\n * See {@link TailorWorkflowAPI.triggerJobFunction}.\n * @param args - Forwarded to {@link TailorWorkflowAPI.triggerJobFunction}\n * @returns The job's return value\n */\nexport const triggerJobFunction: TailorWorkflowAPI[\"triggerJobFunction\"] = (...args) =>\n api().triggerJobFunction(...args);\n\n/**\n * See {@link TailorWorkflowAPI.wait}.\n * @param args - Forwarded to {@link TailorWorkflowAPI.wait}\n * @returns The payload supplied by the corresponding `resolve` call\n */\nexport const wait: TailorWorkflowAPI[\"wait\"] = (...args) => api().wait(...args);\n\n/**\n * See {@link TailorWorkflowAPI.resolve}.\n * @param args - Forwarded to {@link TailorWorkflowAPI.resolve}\n * @returns A promise that resolves once the resolve has been recorded\n */\nexport const resolve: TailorWorkflowAPI[\"resolve\"] = (...args) => api().resolve(...args);\n"],"mappings":";;;;;;;;;;AA0GA,MAAM,YACH,WAA2D,OAAO;;;;;;AAOrE,MAAa,mBAAyD,GAAG,SACvE,IAAI,CAAC,CAAC,gBAAgB,GAAG,IAAI;;;;;;AAO/B,MAAa,kBAAuD,GAAG,SACrE,IAAI,CAAC,CAAC,eAAe,GAAG,IAAI;;;;;;AAO9B,MAAa,sBAA+D,GAAG,SAC7E,IAAI,CAAC,CAAC,mBAAmB,GAAG,IAAI;;;;;;AAOlC,MAAa,QAAmC,GAAG,SAAS,IAAI,CAAC,CAAC,KAAK,GAAG,IAAI;;;;;;AAO9E,MAAa,WAAyC,GAAG,SAAS,IAAI,CAAC,CAAC,QAAQ,GAAG,IAAI"}
|