functional-models 3.9.5 → 3.11.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/cjs/errors.cjs +38 -0
- package/cjs/errors.cjs.map +7 -0
- package/cjs/index.cjs +2426 -0
- package/cjs/index.cjs.map +7 -0
- package/cjs/lib.cjs +431 -0
- package/cjs/lib.cjs.map +7 -0
- package/cjs/models.cjs +571 -0
- package/cjs/models.cjs.map +7 -0
- package/cjs/orm/index.cjs +1765 -0
- package/cjs/orm/index.cjs.map +7 -0
- package/cjs/orm/internal-libs.cjs +136 -0
- package/cjs/orm/internal-libs.cjs.map +7 -0
- package/cjs/orm/libs.cjs +88 -0
- package/cjs/orm/libs.cjs.map +7 -0
- package/cjs/orm/models.cjs +1027 -0
- package/cjs/orm/models.cjs.map +7 -0
- package/cjs/orm/properties.cjs +989 -0
- package/cjs/orm/properties.cjs.map +7 -0
- package/cjs/orm/query.cjs +376 -0
- package/cjs/orm/query.cjs.map +7 -0
- package/cjs/orm/types.cjs +59 -0
- package/cjs/orm/types.cjs.map +7 -0
- package/cjs/orm/validation.cjs +301 -0
- package/cjs/orm/validation.cjs.map +7 -0
- package/cjs/properties.cjs +998 -0
- package/cjs/properties.cjs.map +7 -0
- package/cjs/serialization.cjs +75 -0
- package/cjs/serialization.cjs.map +7 -0
- package/cjs/types.cjs +65 -0
- package/cjs/types.cjs.map +7 -0
- package/cjs/utils.cjs +187 -0
- package/cjs/utils.cjs.map +7 -0
- package/cjs/validation.cjs +431 -0
- package/cjs/validation.cjs.map +7 -0
- package/errors.js +3 -4
- package/errors.js.map +1 -1
- package/index.d.ts +13 -13
- package/index.js +13 -52
- package/index.js.map +1 -1
- package/lib.d.ts +5 -5
- package/lib.js +45 -65
- package/lib.js.map +1 -1
- package/models.d.ts +1 -1
- package/models.js +22 -30
- package/models.js.map +1 -1
- package/orm/index.d.ts +9 -9
- package/orm/index.js +9 -48
- package/orm/index.js.map +1 -1
- package/orm/internal-libs.js +7 -11
- package/orm/internal-libs.js.map +1 -1
- package/orm/libs.d.ts +1 -1
- package/orm/libs.js +8 -16
- package/orm/libs.js.map +1 -1
- package/orm/models.d.ts +2 -2
- package/orm/models.js +20 -26
- package/orm/models.js.map +1 -1
- package/orm/properties.d.ts +28 -28
- package/orm/properties.js +28 -36
- package/orm/properties.js.map +1 -1
- package/orm/query.d.ts +1 -1
- package/orm/query.js +31 -52
- package/orm/query.js.map +1 -1
- package/orm/types.d.ts +2 -2
- package/orm/types.js +7 -10
- package/orm/types.js.map +1 -1
- package/orm/validation.d.ts +2 -2
- package/orm/validation.js +5 -13
- package/orm/validation.js.map +1 -1
- package/package.json +50 -65
- package/properties.d.ts +133 -133
- package/properties.js +66 -94
- package/properties.js.map +1 -1
- package/serialization.d.ts +1 -1
- package/serialization.js +3 -9
- package/serialization.js.map +1 -1
- package/types.d.ts +6 -1
- package/types.js +4 -6
- package/types.js.map +1 -1
- package/utils.d.ts +2 -1
- package/utils.js +8 -23
- package/utils.js.map +1 -1
- package/validation.d.ts +1 -1
- package/validation.js +19 -50
- package/validation.js.map +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/models.ts", "../../src/serialization.ts", "../../src/validation.ts", "../../src/types.ts", "../../src/utils.ts", "../../node_modules/uuid/dist-node/stringify.js", "../../node_modules/uuid/dist-node/rng.js", "../../node_modules/uuid/dist-node/v4.js", "../../src/lib.ts"],
|
|
4
|
+
"sourcesContent": ["import merge from 'lodash/merge.js'\nimport z, { ZodObject, ZodType } from 'zod'\nimport { toJsonAble } from './serialization.js'\nimport { createModelValidator } from './validation.js'\nimport {\n CreateParams,\n DataDescription,\n MinimalModelDefinition,\n ModelDefinition,\n ModelErrors,\n ModelFactory,\n ModelInstance,\n ModelFactoryOptions,\n ModelReferenceType,\n ModelReferenceFunctions,\n ModelReferencePropertyInstance,\n ModelType,\n Nullable,\n PropertyGetters,\n PropertyInstance,\n PropertyValidators,\n RestInfo,\n ToObjectFunction,\n ModelInstanceFetcher,\n} from './types.js'\nimport {\n getModelName,\n NULL_ENDPOINT,\n NULL_METHOD,\n populateApiInformation,\n} from './lib.js'\nimport { memoizeAsync, memoizeSync, singularize, toTitleCase } from './utils.js'\n\nconst _defaultOptions = <\n T extends DataDescription,\n>(): ModelFactoryOptions<T> => ({\n instanceCreatedCallback: undefined,\n})\n\nconst _convertOptions = <T extends DataDescription>(\n options?: ModelFactoryOptions<T>\n) => {\n const r: ModelFactoryOptions<T> = merge({}, _defaultOptions(), options)\n return r\n}\n\nconst _addDescription = (\n schema: ZodObject<DataDescription>,\n description?: string\n) => {\n if (!description) {\n return schema\n }\n // @ts-ignore\n if (typeof schema.openapi === 'function') {\n // @ts-ignore\n return schema.openapi({ description: description })\n }\n return schema.meta\n ? schema.meta({ description: description })\n : schema.describe(description)\n}\n\nconst _createZod = <T extends DataDescription>(\n modelDefinition: MinimalModelDefinition<T>\n): ZodObject<DataDescription> => {\n if (modelDefinition.schema) {\n return _addDescription(modelDefinition.schema, modelDefinition.description)\n }\n const properties = Object.entries(modelDefinition.properties).reduce(\n (acc, [key, property]) => {\n const asProp = property as PropertyInstance<any>\n return merge(acc, {\n [key]: asProp.getZod(),\n })\n },\n {} as Record<string, ZodType>\n )\n const obj = z.object(properties) as ZodObject<DataDescription>\n return _addDescription(obj, modelDefinition.description)\n}\n\nconst _toModelDefinition = <T extends DataDescription>(\n minimal: MinimalModelDefinition<T>\n): ModelDefinition<T> => {\n return {\n singularName: singularize(minimal.pluralName),\n displayName: toTitleCase(minimal.pluralName),\n description: '',\n primaryKeyName: 'id',\n modelValidators: [],\n schema: _createZod(minimal),\n ...minimal,\n }\n}\n\nconst _validateModelDefinition = <T extends DataDescription>(\n modelDefinition: MinimalModelDefinition<T>\n) => {\n const primaryKeyName = modelDefinition.primaryKeyName || 'id'\n const primaryKeyProperty =\n // @ts-ignore\n modelDefinition.properties[primaryKeyName]\n if (!primaryKeyProperty) {\n throw new Error(`Property missing for primaryKey named ${primaryKeyName}`)\n }\n if (!modelDefinition.pluralName) {\n throw new Error(`Must include pluralName for model.`)\n }\n if (!modelDefinition.namespace) {\n throw new Error(`Must include namespace for model.`)\n }\n}\n\n/**\n * An out of the box ModelFactory that can create Models.\n * @param options - Any additional model options\n * @returns A simple Model function ready for creating models. See {@link ModelType}\n */\nconst Model: ModelFactory = <T extends DataDescription>(\n minimalModelDefinitions: MinimalModelDefinition<T>,\n options?: ModelFactoryOptions<T>\n): ModelType<T> => {\n _validateModelDefinition(minimalModelDefinitions)\n /*\n * This non-functional approach is specifically used to\n * allow instances to be able to refer back to its parent without\n * having to duplicate it for every instance.\n * This is set at the very end and returned, so it can be referenced\n * throughout instance methods.\n */\n // eslint-disable-next-line functional/no-let\n let model: Nullable<ModelType<T>> = null\n const theOptions = _convertOptions(options)\n const modelDefinition = _toModelDefinition(minimalModelDefinitions)\n\n const getPrimaryKeyName = () => modelDefinition.primaryKeyName\n const getPrimaryKey = (loadedInternals: any) => {\n const property = loadedInternals.get[getPrimaryKeyName()]\n return property()\n }\n\n const create = <IgnorePrimaryKeyName extends string = ''>(\n instanceValues: CreateParams<T, IgnorePrimaryKeyName>\n ) => {\n // eslint-disable-next-line functional/no-let\n let instance: Nullable<ModelInstance<T>> = null\n const startingInternals: Readonly<{\n get: PropertyGetters<T>\n validators: PropertyValidators<T>\n references: ModelReferenceFunctions\n }> = {\n get: {} as PropertyGetters<T> & Readonly<{ id: () => string }>,\n validators: {},\n references: {},\n }\n\n const prop: [string, PropertyInstance<any>][] = Object.entries(\n modelDefinition.properties\n )\n const loadedInternals = prop.reduce(\n (acc, [key, property]) => {\n const propertyGetter = memoizeSync(() =>\n property.createGetter(\n //@ts-ignore\n instanceValues[key],\n instanceValues,\n // NOTE: By the time it gets here, it has already been implemented.\n instance as ModelInstance<any>\n )()\n )\n const propertyValidator = property.getValidator(propertyGetter)\n const fleshedOutInstanceProperties = {\n get: {\n [key]: () => propertyGetter(),\n },\n validators: {\n [key]: propertyValidator,\n },\n }\n const asReferenced = property as ModelReferencePropertyInstance<\n any,\n any\n >\n const referencedProperty = asReferenced.getReferencedId\n ? {\n references: {\n [key]: () =>\n asReferenced.getReferencedId(\n // @ts-ignore\n instanceValues[key] as ModelReferenceType<any>\n ),\n },\n }\n : {}\n\n return merge(\n acc,\n fleshedOutInstanceProperties,\n referencedProperty\n ) as Readonly<{\n get: PropertyGetters<T>\n validators: PropertyValidators<T>\n references: ModelReferenceFunctions\n }>\n },\n startingInternals as Readonly<{\n get: PropertyGetters<T>\n validators: PropertyValidators<T>\n references: ModelReferenceFunctions\n }>\n )\n\n const getModel = () => model as ModelType<T>\n\n // We are casting this, because the output type is really complicated.\n // and memoizing this is very important.\n // @ts-ignore\n const toObj = memoizeAsync(() => {\n return toJsonAble(loadedInternals.get)()\n }) as ToObjectFunction<T>\n\n const validate = memoizeAsync((options = {}) => {\n return Promise.resolve().then(() => {\n return createModelValidator<T, ModelType<T>>(\n loadedInternals.validators,\n modelDefinition.modelValidators\n )(instance as ModelInstance<T>, options)\n }) as Promise<ModelErrors<T> | undefined>\n })\n\n const getReferences = () => loadedInternals.references\n const getValidators = () => loadedInternals.validators\n\n // @ts-ignore\n instance = {\n get: loadedInternals.get,\n getReferences,\n getValidators,\n getModel,\n toObj,\n getPrimaryKey: () => getPrimaryKey(loadedInternals),\n validate,\n } as ModelInstance<T>\n\n if (theOptions.instanceCreatedCallback) {\n const toCall = Array.isArray(theOptions.instanceCreatedCallback)\n ? theOptions.instanceCreatedCallback\n : [theOptions.instanceCreatedCallback]\n toCall.map(func => func(instance as ModelInstance<T>))\n }\n return instance\n }\n\n const getApiInfo = memoizeSync(() => {\n return populateApiInformation(\n modelDefinition.pluralName,\n modelDefinition.namespace,\n modelDefinition.api\n )\n })\n\n // This sets the model that is used by the instances later.\n model = {\n /**\n * Creates a model instance.\n */\n create,\n getName: () =>\n getModelName(modelDefinition.namespace, modelDefinition.pluralName),\n getModelDefinition: memoizeSync(() => modelDefinition),\n getPrimaryKey,\n getApiInfo,\n }\n return model as ModelType<T>\n}\n\n/**\n * A useful function for determining if a RestInfo found in an ApiInfo is \"null\" or not.\n * That is, whether it should be used and considered.\n * @param restInfo\n */\nconst isNullRestInfo = (restInfo: RestInfo): boolean => {\n return restInfo.method === NULL_METHOD && restInfo.endpoint === NULL_ENDPOINT\n}\n\n/**\n * A ModelInstanceFetcher that does not do anything. It always returns undefined.\n */\nconst noFetch: ModelInstanceFetcher = () => {\n return Promise.resolve(undefined)\n}\n\nexport { Model, isNullRestInfo, noFetch }\n", "import merge from 'lodash/merge.js'\nimport {\n PropertyGetters,\n JsonAble,\n ToObjectFunction,\n DataDescription,\n JsonifiedData,\n ModelInstance,\n ToObjectResult,\n} from './types.js'\n\nconst isModelInstance = (obj: any): obj is ModelInstance<any> => {\n return Boolean(obj.toObj)\n}\n\nconst _getValue = async (value: any): Promise<JsonAble | null> => {\n if (value === undefined) {\n return undefined\n }\n if (value === null) {\n return null\n }\n const type = typeof value\n const asFunction = value as (...args: any[]) => any\n if (type === 'function') {\n return _getValue(await asFunction())\n }\n // Nested Object\n if (isModelInstance(value)) {\n return _getValue(await value.toObj())\n }\n // Dates\n const asDate = value as Date\n if (type === 'object' && asDate.toISOString) {\n return _getValue(asDate.toISOString())\n }\n return value\n}\n\nconst toJsonAble =\n <T extends DataDescription>(\n keyToFunc: PropertyGetters<T>\n ): ToObjectFunction<T> =>\n <R extends T | JsonifiedData<T> = JsonifiedData<T>>(): Promise<\n ToObjectResult<R>\n > => {\n return Object.entries(keyToFunc).reduce(async (acc, [key, value]) => {\n const realAcc = await acc\n const trueValue = await _getValue(await value)\n if (trueValue === undefined) {\n return realAcc\n }\n return merge(realAcc, { [key]: trueValue })\n }, Promise.resolve({})) as Promise<ToObjectResult<R>>\n }\n\nexport { toJsonAble }\n", "import isEmpty from 'lodash/isEmpty.js'\nimport merge from 'lodash/merge.js'\nimport flatMap from 'lodash/flatMap.js'\nimport get from 'lodash/get.js'\nimport {\n DataDescription,\n ModelInstance,\n ModelType,\n ModelValidatorComponent,\n PropertyValidatorComponent,\n PropertyValidatorComponentSync,\n PropertyValidator,\n PropertyConfig,\n PropertyValidators,\n ValueGetter,\n Arrayable,\n DataValue,\n ModelErrors,\n ValidatorContext,\n ValuePropertyValidatorComponent,\n ValidationErrors,\n MaybeFunction,\n PropertyValidatorComponentTypeAdvanced,\n PrimitiveValueType,\n ToObjectResult,\n} from './types.js'\nimport { flowFindFirst } from './utils.js'\n\nconst multiValidator = <T extends Arrayable<DataValue>>(\n validators: ValuePropertyValidatorComponent<T>[]\n): ValuePropertyValidatorComponent<T> => {\n const flow = flowFindFirst<T, string>(\n validators as ((t: T) => undefined | string)[]\n )\n return flow as ValuePropertyValidatorComponent<T>\n}\n\nconst filterEmpty = <T>(\n array: readonly (T | undefined | null)[]\n): readonly T[] => {\n return array.filter(x => x) as readonly T[]\n}\n\nconst _trueOrError =\n <T extends Arrayable<DataValue>>(\n method: (t: T) => boolean,\n error: string\n ): ValuePropertyValidatorComponent<T> =>\n (value: T) => {\n if (method(value) === false) {\n return error\n }\n return undefined\n }\n\nconst _typeOrError =\n <T extends Arrayable<DataValue>>(\n type: string,\n errorMessage: string\n ): ValuePropertyValidatorComponent<T> =>\n (value: T) => {\n if (typeof value !== type) {\n return errorMessage\n }\n return undefined\n }\n\nconst isType =\n <T extends Arrayable<DataValue>>(\n type: string\n ): ValuePropertyValidatorComponent<T> =>\n (value: T) => {\n // @ts-ignore\n return _typeOrError(type, `Must be a ${type}`)(value)\n }\nconst isNumber = isType<number>('number')\nconst isInteger = _trueOrError<number>(Number.isInteger, 'Must be an integer')\n\nconst isObject = multiValidator<object>([\n isType<object>('object'),\n x => (Array.isArray(x) ? 'Must be an object, but got an array' : undefined),\n])\nconst isBoolean = isType<boolean>('boolean')\nconst isString = isType<string>('string')\nconst isArray = _trueOrError<readonly DataValue[]>(\n (v: any) => Array.isArray(v),\n 'Value is not an array'\n)\n\nconst PRIMITIVE_TO_SPECIAL_TYPE_VALIDATOR: Record<\n PrimitiveValueType,\n ValuePropertyValidatorComponent<any>\n> = {\n [PrimitiveValueType.boolean]: isBoolean,\n [PrimitiveValueType.string]: isString,\n [PrimitiveValueType.integer]: isInteger,\n [PrimitiveValueType.number]: isNumber,\n [PrimitiveValueType.object]: isObject,\n}\n\nconst arrayType =\n <TValue extends DataValue>(\n type: PrimitiveValueType\n ): ValuePropertyValidatorComponent<readonly TValue[]> =>\n (value: readonly TValue[]) => {\n const arrayError = isArray(value)\n if (arrayError) {\n return arrayError\n }\n const validator = PRIMITIVE_TO_SPECIAL_TYPE_VALIDATOR[type] || isType(type)\n return (value as readonly []).reduce(\n (acc: string | undefined, v: DataValue) => {\n if (acc) {\n return acc\n }\n\n return validator(v)\n },\n undefined\n )\n }\n\nconst meetsRegex =\n <TValue extends DataValue>(\n regex: string | RegExp,\n flags?: string,\n errorMessage = 'Format was invalid'\n ): ValuePropertyValidatorComponent<TValue> =>\n (value: TValue) => {\n const reg = new RegExp(regex, flags)\n // @ts-ignore\n return _trueOrError((v: string) => reg.test(v), errorMessage)(value)\n }\n\nconst choices =\n <T extends DataValue>(\n choiceArray: readonly T[]\n ): ValuePropertyValidatorComponent<T> =>\n (value: T | readonly T[]) => {\n if (Array.isArray(value)) {\n const bad = value.find(v => !choiceArray.includes(v))\n if (bad) {\n return `${bad} is not a valid choice`\n }\n } else {\n if (!choiceArray.includes(value as T)) {\n return `${value} is not a valid choice`\n }\n }\n return undefined\n }\n\nconst isDate: ValuePropertyValidatorComponent<Date> = (value: Date) => {\n if (!value) {\n return 'Date value is empty'\n }\n if (!value.toISOString) {\n return 'Value is not a date'\n }\n return undefined\n}\n\nconst isRequired: ValuePropertyValidatorComponent<any> = (value?: any) => {\n if (value === true || value === false) {\n return undefined\n }\n // @ts-ignore\n if (isNumber(value) === undefined) {\n return undefined\n }\n const empty = isEmpty(value)\n if (empty) {\n // @ts-ignore\n if (isDate(value)) {\n return 'A value is required'\n }\n }\n return undefined\n}\n\nconst maxNumber =\n (max: number): ValuePropertyValidatorComponent<number> =>\n (value: number) => {\n // @ts-ignore\n const numberError = isNumber(value)\n if (numberError) {\n return numberError\n }\n if (value && value > max) {\n return `The maximum is ${max}`\n }\n return undefined\n }\n\nconst minNumber =\n (min: number): ValuePropertyValidatorComponent<number> =>\n (value: number) => {\n // @ts-ignore\n const numberError = isNumber(value)\n if (numberError) {\n return numberError\n }\n if (value && value < min) {\n return `The minimum is ${min}`\n }\n return undefined\n }\n\nconst maxTextLength =\n (max: number): ValuePropertyValidatorComponent<string> =>\n (value: string) => {\n // @ts-ignore\n const stringError = isString(value)\n if (stringError) {\n return stringError\n }\n if (value && value.length > max) {\n return `The maximum length is ${max}`\n }\n return undefined\n }\n\nconst minTextLength =\n (min: number): ValuePropertyValidatorComponent<string> =>\n (value: string) => {\n // @ts-ignore\n const stringError = isString(value)\n if (stringError) {\n return stringError\n }\n if (value && value.length < min) {\n return `The minimum length is ${min}`\n }\n return undefined\n }\n\nconst aggregateValidator = <T extends DataDescription>(\n value: any,\n methodOrMethods:\n | PropertyValidatorComponent<T>\n | readonly PropertyValidatorComponent<T>[]\n): PropertyValidator<T> => {\n const toDo = Array.isArray(methodOrMethods)\n ? methodOrMethods\n : [methodOrMethods]\n\n const _aggregativeValidator: PropertyValidator<T> = async (\n model: ModelType<T>,\n instanceData: ToObjectResult<T>,\n propertyConfiguration: ValidatorContext\n ) => {\n const values = await Promise.all(\n toDo.map(method => {\n return method(value, model, instanceData, propertyConfiguration)\n })\n )\n return filterEmpty(values)\n }\n return _aggregativeValidator\n}\n\nconst emptyValidator = () => undefined\n\nconst _boolChoice =\n <T extends DataDescription>(\n method: (configValue: any) => PropertyValidatorComponentSync<T>\n ) =>\n (configValue: any) => {\n const func = method(configValue)\n const validatorWrapper: PropertyValidatorComponentSync<T> = func\n return validatorWrapper\n }\n\ntype MethodConfigDict<T extends DataDescription> = Readonly<{\n [s: string]: (config: any) => PropertyValidatorComponentSync<T>\n}>\n\nconst simpleFuncWrap =\n <T extends DataDescription>(validator: PropertyValidatorComponentSync<T>) =>\n () => {\n return validator\n }\n\nconst includeOrDont =\n <T extends DataDescription>(\n method: () => PropertyValidatorComponentSync<T>\n ) =>\n (configValue: any) => {\n if (configValue === false) {\n return emptyValidator\n }\n const func = method()\n const validatorWrapper: PropertyValidatorComponentSync<T> = func\n return validatorWrapper\n }\n\nconst CONFIG_TO_VALIDATE_METHOD = <\n T extends DataDescription,\n>(): MethodConfigDict<T> => ({\n required: includeOrDont(simpleFuncWrap(isRequired)),\n isInteger: _boolChoice<T>(simpleFuncWrap(isInteger)),\n isNumber: _boolChoice<T>(simpleFuncWrap(isNumber)),\n isString: _boolChoice<T>(simpleFuncWrap(isString)),\n isArray: _boolChoice<T>(simpleFuncWrap(isArray)),\n isBoolean: _boolChoice<T>(simpleFuncWrap(isBoolean)),\n choices: _boolChoice<T>(choices),\n})\n\nconst createPropertyValidator = <\n TValue extends Arrayable<DataValue>,\n T extends DataDescription = DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n>(\n valueGetter: ValueGetter<\n TValue,\n T,\n TModelExtensions,\n TModelInstanceExtensions\n >,\n config: PropertyConfig<TValue>\n): PropertyValidator<T> => {\n const _propertyValidator = async (\n model: ModelType<T>,\n instanceData: ToObjectResult<T>,\n propertyConfiguration: ValidatorContext\n ): Promise<ValidationErrors> => {\n return Promise.resolve().then(async () => {\n const configToValidateMethod = CONFIG_TO_VALIDATE_METHOD<T>()\n if (!config) {\n config = {}\n }\n const validators: readonly PropertyValidatorComponent<T>[] = [\n ...Object.entries(config).map(([key, value]) => {\n const method = configToValidateMethod[key]\n if (method) {\n return method(value)\n }\n return emptyValidator\n }),\n ...(config.validators ? config.validators : []),\n ].filter(x => x) as PropertyValidatorComponent<T>[]\n const value = await valueGetter()\n const isRequiredValue = config.required\n ? true\n : validators.includes(isRequired)\n if (!value && !isRequiredValue) {\n return []\n }\n const validator = aggregateValidator(value, validators)\n const errors = await validator(model, instanceData, propertyConfiguration)\n return [...new Set(flatMap(errors))]\n })\n }\n return _propertyValidator\n}\n\nconst createModelValidator = <\n T extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n>(\n validators: PropertyValidators<T>,\n modelValidators?: readonly ModelValidatorComponent<\n T,\n TModelExtensions,\n TModelInstanceExtensions\n >[]\n) => {\n const _modelValidator = async (\n instance: ModelInstance<T, TModelExtensions, TModelInstanceExtensions>,\n propertyConfiguration: ValidatorContext\n ): Promise<ModelErrors<T> | undefined> => {\n return Promise.resolve().then(async () => {\n if (!instance) {\n throw new Error(`Instance cannot be empty`)\n }\n const model = instance.getModel()\n const keysAndFunctions = Object.entries(validators)\n const instanceData = await instance.toObj<T>()\n const propertyValidationErrors = await Promise.all(\n keysAndFunctions.map(async ([key, validator]) => {\n return [\n key,\n await validator(model, instanceData, propertyConfiguration),\n ]\n })\n )\n const modelValidationErrors = (\n await Promise.all(\n modelValidators\n ? modelValidators.map(validator => {\n return validator(model, instanceData, propertyConfiguration)\n })\n : []\n )\n ).filter(x => x) as readonly string[]\n const propertyErrors = propertyValidationErrors\n .filter(([, errors]) => Boolean(errors) && errors.length > 0)\n .reduce((acc, [key, errors]) => {\n return merge(acc, { [String(key)]: errors })\n }, {} as ModelErrors<T>)\n const final =\n modelValidationErrors.length > 0\n ? merge(propertyErrors, { overall: modelValidationErrors })\n : propertyErrors\n if (isEmpty(final)) {\n return undefined\n }\n return final\n })\n }\n return _modelValidator\n}\n\nconst isValid = <T extends DataDescription>(errors: ModelErrors<T>) => {\n return Object.keys(errors).length < 1\n}\n\nconst referenceTypeMatch = (\n referencedModel: MaybeFunction<ModelType<any>>\n): PropertyValidatorComponentTypeAdvanced<\n ModelInstance<any, any, any>,\n any\n> => {\n return (value?: ModelInstance<any, any, any>) => {\n const theType = typeof value\n switch (theType) {\n case 'string':\n case 'number':\n case 'undefined':\n return undefined\n default:\n break\n }\n if (value === null) {\n return undefined\n }\n // This needs to stay here, as it delays the creation long enough for\n // self referencing types.\n const model =\n typeof referencedModel === 'function'\n ? referencedModel()\n : referencedModel\n // Assumption: By the time this is received, value === a model instance.\n const eModel = model.getName()\n const aModel = value.getModel().getName()\n if (eModel !== aModel) {\n return `Model should be ${eModel} instead, received ${aModel}`\n }\n return undefined\n }\n}\n\n/**\n * A validator that can validate an entire object.\n *\n * @param required - If this object is required.\n * @param keyToValidators - An object that has a dotted path key to the property to validate, and one or more validators for it.\n */\nconst objectValidator = <T extends object>({\n required,\n keyToValidators,\n}: {\n required?: boolean\n keyToValidators: Record<\n string,\n | ValuePropertyValidatorComponent<any>\n | ValuePropertyValidatorComponent<any>[]\n >\n}): ValuePropertyValidatorComponent<T> => {\n return (obj: T) => {\n if (!obj) {\n if (required) {\n return 'Must include a value'\n }\n return undefined\n }\n const isNotObj = isObject(obj)\n if (isNotObj) {\n return isNotObj\n }\n return (\n Object.entries(keyToValidators)\n .reduce((acc, [key, validator]) => {\n const theValidator = Array.isArray(validator)\n ? multiValidator(validator)\n : (validator as ValuePropertyValidatorComponent<any>)\n const value = get(obj, key)\n const error = theValidator(value)\n if (error) {\n return acc.concat(`${key}: ${error}`)\n }\n return acc\n }, [] as string[])\n .join(', ') || undefined\n )\n }\n}\n\nconst optionalValidator = <T extends Arrayable<DataValue>>(\n validator: ValuePropertyValidatorComponent<T>\n): ValuePropertyValidatorComponent<T> => {\n return (v: T | undefined): string | undefined => {\n if (v === undefined || v === null) {\n return undefined\n }\n return validator(v)\n }\n}\n\nconst UUID_VALIDATOR =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/iu\n\nconst isValidUuid: ValuePropertyValidatorComponent<string> = (uuid: string) => {\n const stringError = isString(uuid)\n if (stringError) {\n return stringError\n }\n return meetsRegex<string>(UUID_VALIDATOR, 'g', 'Invalid UUID format')(uuid)\n}\n\nexport {\n isNumber,\n isBoolean,\n isString,\n isInteger,\n isType,\n isDate,\n isArray,\n isRequired,\n maxNumber,\n minNumber,\n choices,\n maxTextLength,\n minTextLength,\n meetsRegex,\n aggregateValidator,\n emptyValidator,\n createPropertyValidator,\n createModelValidator,\n arrayType,\n isValid,\n referenceTypeMatch,\n multiValidator,\n isObject,\n objectValidator,\n optionalValidator,\n isValidUuid,\n}\n", "import * as openapi from 'openapi-types'\nimport { ZodObject, ZodType } from 'zod'\n\nexport type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }\n\nexport type XOR<T, U> = T | U extends object\n ? (Without<T, U> & U) | (Without<U, T> & T)\n : T | U\n\n/**\n * A function that returns the value, or just the value\n */\ntype MaybeFunction<T> = T | (() => T)\n\n/**\n * The data or a promise that returns the data\n */\ntype MaybePromise<T> = T | Promise<T>\n\n/**\n * The value or null\n */\ntype Nullable<T> = T | null\n\n/**\n * The value, or undefined\n */\ntype Maybe<T> = T | undefined\n\n/**\n * The value or an array of the types of value\n */\ntype Arrayable<T> = T | readonly T[]\n\n/**\n * A JSON compliant object.\n */\ntype JsonObj = Readonly<{\n [s: string]: JsonAble | null | undefined\n}>\n\n/**\n * A description of valid json values.\n */\ntype JsonAble =\n | Arrayable<JsonObj>\n | readonly (number | string | boolean)[]\n | readonly JsonAble[]\n | number\n | string\n | boolean\n | null\n | undefined\n\n/**\n * This is a fully Json compliant version of a DataDescription\n */\ntype JsonifiedData<T extends DataDescription> = {\n readonly [P in keyof T]: JsonAble\n}\n\n/**\n * Removes promises from every property of an object.\n */\ntype RemovePromises<T extends object> = {\n // @ts-ignore\n [K in keyof T as T[K] extends Promise<any> ? K : never]: Awaited<T[K]>\n} & {\n [K in keyof T as T[K] extends Promise<any> ? never : K]: T[K]\n}\n\n/**\n * The types that are allowed in a choice.\n */\ntype ChoiceTypes = null | string | number | boolean\n\n/**\n * A Model Reference that is only string|number|undefined|null\n */\ntype FlattenModelReferences<TData extends DataDescription> = {\n [K in keyof TData as TData[K] extends ModelInstance<any>\n ? never\n : K]: TData[K]\n} & {\n [K in keyof TData as TData[K] extends ModelInstance<TData>\n ? K\n : never]: PrimaryKeyType\n}\n\n/**\n * The result of a \"toObj()\" call. See {@link ModelInstance.toObj}\n * This is guaranteed to be JSON compliant.\n */\ntype ToObjectResult<TData extends DataDescription> = RemovePromises<\n FlattenModelReferences<TData>\n>\n\n/**\n * A function that will provide a JSON compliant representation of the data.\n * Useful for saving in a database, or sending out over a network.\n */\ntype ToObjectFunction<TData extends DataDescription> = <\n R extends TData | JsonifiedData<TData> = JsonifiedData<TData>,\n>() => Promise<ToObjectResult<R>>\n\n/**\n * Getter functions that provide access to the value of a property of an instance.\n */\ntype PropertyGetters<TData extends DataDescription> = {\n readonly [PropertyKey in keyof Required<TData>]: () => TData[PropertyKey]\n}\n\n/**\n * The most basic description of data supported by this framework.\n * This includes all of JSON and additional functionality for referenced models.\n */\ntype DataDescription = Readonly<{\n [s: string]:\n | Promise<PrimaryKeyType>\n | Arrayable<number>\n | Arrayable<string>\n | Arrayable<boolean>\n | Arrayable<null>\n | Arrayable<DataDescription>\n | Arrayable<Date>\n | Arrayable<undefined>\n | ModelReferenceType<any>\n | Arrayable<JsonAble>\n}>\n\nexport type CanBeNullableType<T extends DataValue> = XOR<\n T | undefined | null,\n T\n>\n\n/**\n * These are the allowable types for setting a property of data to.\n */\ntype DataValue = MaybePromise<\n | Arrayable<JsonAble>\n | (() => DataValue) // A lazy function that provides a value.\n | Arrayable<null>\n | Arrayable<undefined>\n | Arrayable<Date>\n | Arrayable<DataDescription>\n>\n\n/**\n * Additional context to a validation. Sometimes there are other validation information needed than what can be provided within a model itself.\n */\ntype ValidatorContext = Readonly<Record<string, any>>\n\n/**\n * A collection of errors for a property or model.\n */\ntype ValidationErrors = readonly string[]\n\n/**\n * The response to a validation attempt of a model at the lowest level. Something is bad (a string), or its good (undefined)\n */\ntype ComponentValidationErrorResponse = string | undefined\n\n/**\n * The errors across an entire model. Contains both overall errors, as well as individualized property errors.\n */\ntype ModelErrors<TData extends DataDescription> = {\n readonly [Property in keyof Partial<TData>]: ValidationErrors\n} & Readonly<{ overall?: ValidationErrors }>\n\n/**\n * The most flexible representation of a Property Validator.\n * @param value - The raw value being evaluated\n * @param model - The model (e.g. for datastore lookups). Use model.create(data) if you need an instance.\n * @param instanceData - An already JSONified version of the model. This is a convenience so toObj() does not need to be called so frequently.\n * @param context - Additional outside context to help with validation. (Most cases this is unused)\n */\ntype PropertyValidatorComponentTypeAdvanced<\n TValue,\n TData extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> = (\n value: TValue,\n model: ModelType<TData, TModelExtensions, TModelInstanceExtensions>,\n instanceData: ToObjectResult<TData>,\n context: ValidatorContext\n) => ComponentValidationErrorResponse\n\n/**\n * A Property Validator that does not use Promises\n */\ntype PropertyValidatorComponentSync<\n TData extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> = PropertyValidatorComponentTypeAdvanced<\n any,\n TData,\n TModelExtensions,\n TModelInstanceExtensions\n>\n\n/**\n * A simple property validator that just looks at the value.\n * @param value - A single value to validate\n */\ntype ValuePropertyValidatorComponent<TValue extends Arrayable<DataValue>> = (\n value: TValue\n) => ComponentValidationErrorResponse\n\n/**\n * A property validator that returns a promise.\n * @param value - The value to validate\n * @param model - The model (e.g. for datastore lookups). Use model.create(data) if you need an instance.\n * @param instanceData - The jsonified version of the data\n * @param context - Additional context to validate against.\n */\ntype PropertyValidatorComponentAsync<\n TData extends DataDescription,\n TModelExtensions extends object,\n TModelInstanceExtensions extends object,\n> = (\n value: Arrayable<DataValue>,\n model: ModelType<TData, TModelExtensions, TModelInstanceExtensions>,\n instanceData: ToObjectResult<TData>,\n context: ValidatorContext\n) => Promise<ComponentValidationErrorResponse>\n\n/**\n * A property validator that is either Sync or Async.\n */\ntype PropertyValidatorComponent<\n TData extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> =\n | PropertyValidatorComponentSync<\n TData,\n TModelExtensions,\n TModelInstanceExtensions\n >\n | PropertyValidatorComponentAsync<\n TData,\n TModelExtensions,\n TModelInstanceExtensions\n >\n\n/**\n * The validator for an entire property. This is composed of multiple underlying validators that all get executed and then assembled together.\n * @param model - The model (the instance's model). Use model.create(data) if you need an instance.\n * @param instanceData - The instance data to compare\n * @param context - Additional context for validating.\n */\ntype PropertyValidator<TData extends DataDescription> = (\n model: ModelType<TData>,\n instanceData: ToObjectResult<TData>,\n context: ValidatorContext\n) => Promise<ValidationErrors>\n\n/**\n * The component of a Model Validator. These are combined to create a single model validator.\n * @param model - The model. Use model.create(data) if you need an instance.\n * @param instanceData - The JSONified version of the model.\n * @param context - Additional context to assist with validating.\n */\ntype ModelValidatorComponent<\n TData extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> = (\n model: ModelType<TData, TModelExtensions, TModelInstanceExtensions>,\n instanceData: ToObjectResult<TData>,\n context: ValidatorContext\n) => Promise<ComponentValidationErrorResponse>\n\n/**\n * A function that will get the value of a property.\n * Depending on what the property is, it'll either be a primitive value\n * or it'll be a referenced model.\n */\ntype ValueGetter<\n /**\n * The type of value\n */\n TValue extends Arrayable<DataValue>,\n /**\n * The value existing within a specific type of data.\n */\n TData extends DataDescription = DataDescription,\n /**\n * Any additional model extensions.\n */\n TModelExtensions extends object = object,\n /**\n * Any additional model instance extensions.\n */\n TModelInstanceExtensions extends object = object,\n> = () => MaybePromise<\n TValue | ModelInstance<TData, TModelExtensions, TModelInstanceExtensions>\n>\n\n/**\n * An instance of a property. This is used to describe a property in depth as well as provide functionality like validating values.\n * @interface\n */\ntype PropertyInstance<\n /**\n * The type of value that the property represents.\n */\n TValue extends Arrayable<DataValue>,\n /**\n * The data that the property sits within.\n */\n TData extends DataDescription = DataDescription,\n /**\n * Any additional model extensions.\n */\n TModelExtensions extends object = object,\n /**\n * Any additional model instance extensions.\n */\n TModelInstanceExtensions extends object = object,\n> = Readonly<{\n /**\n * Gets the configuration passed into the property constructor.\n */\n getConfig: () => object\n /**\n * Gets available choices for limiting the value of this property.\n */\n getChoices: () => readonly ChoiceTypes[]\n /**\n * If there is a default value\n */\n getDefaultValue: () => TValue | undefined\n /**\n * If there is a constant value that never changes. (This is used above all else).\n */\n getConstantValue: () => TValue | undefined\n /**\n * Gets the ValueType of the property. Unless custom properties are used, the value is a {@link PropertyType}.\n * Otherwise the value could be string for custom types.\n */\n getPropertyType: () => PropertyType | string\n /**\n * Creates a value getter.\n * @param value - The type of value\n * @param modelData - The type of data.\n * @param modelInstance - An instance of the model that has the data.\n */\n createGetter: (\n value: TValue,\n modelData: TData,\n modelInstance: ModelInstance<\n TData,\n TModelExtensions,\n TModelInstanceExtensions\n >\n ) => ValueGetter<TValue, TData, TModelExtensions, TModelInstanceExtensions>\n /**\n * Function that exposes a zod schema for this property.\n */\n getZod: () => ZodType<TValue>\n /**\n * Gets a validator for the property. This is not normally used.\n * Instead for validation look at {@link ModelInstance.validate}\n * @param valueGetter - The getter for the value.\n */\n getValidator: (\n valueGetter: ValueGetter<\n TValue,\n TData,\n TModelExtensions,\n TModelInstanceExtensions\n >\n ) => PropertyValidator<TData>\n}>\n\n/**\n * A list of properties that make up a model.\n */\ntype PropertiesList<TData extends DataDescription> = {\n readonly [P in keyof TData as TData[P] extends Arrayable<DataValue>\n ? P\n : never]: PropertyInstance<any>\n}\n\n/**\n * An extends a Property to add additional functions helpful for dealing with\n * referenced models.\n */\ninterface ModelReferencePropertyInstance<\n TData extends DataDescription,\n TProperty extends Arrayable<DataValue>,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> extends PropertyInstance<TProperty> {\n /**\n * Gets the id (foreign key) of the referenced model.\n * @param instanceValues - The ModelReference. (key, data, or instance)\n */\n readonly getReferencedId: (\n instanceValues: ModelReferenceType<\n TData,\n TModelExtensions,\n TModelInstanceExtensions\n >\n ) => Maybe<PrimaryKeyType>\n\n /**\n * Gets reference's model\n */\n readonly getReferencedModel: () => ModelType<\n TData,\n TModelExtensions,\n TModelInstanceExtensions\n >\n}\n\n/**\n * A property of a model that references another model instance.\n * This is a basic implementation of a \"foreign key\".\n * The value of this property can be either a key type (string|number), or a model instance, or the model data itself. It depends on the ModelInstanceFetcher.\n */\ntype ModelReferenceType<\n TData extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> = MaybePromise<\n | TData\n | ModelInstance<TData, TModelExtensions, TModelInstanceExtensions>\n | ToObjectResult<TData>\n | PrimaryKeyType\n>\n\n/**\n * Common property validator choices.\n * @interface\n */\ntype CommonValidators = Readonly<{\n /**\n * Is this property required?\n */\n required?: boolean\n /**\n * Can the property only be an integer?\n */\n isInteger?: boolean\n /**\n * Can the property only be a number?\n */\n isNumber?: boolean\n /**\n * Can the property only be a string?\n */\n isString?: boolean\n /**\n * Is the property an array of values?\n */\n isArray?: boolean\n /**\n * Is the property only true or false?\n */\n isBoolean?: boolean\n}>\n\n/**\n * Standard configuration options for properties.\n * @interface\n */\ntype PropertyConfigOptions<TValue extends Arrayable<DataValue>> = Readonly<\n Partial<{\n /**\n * A type override to override the property type of a property.\n */\n typeOverride: PropertyType | string\n /**\n * A default value if one is never given.\n */\n defaultValue: TValue\n /**\n * Determines if this value needs to go through denormalization.\n */\n isDenormalized: boolean\n /**\n * The value of the property (if provided)\n */\n value: TValue\n /**\n * Possible limiting choices of what the property can be.\n */\n choices: readonly ChoiceTypes[]\n /**\n * A lazy loading method, which will only run when the value is actually retrieved.\n * IMPORTANT: Do not include promises as part of this because they are not thread safe.\n * @param value - The current value\n * @param modelData - The models current data\n */\n lazyLoadMethod: <TData extends DataDescription>(\n value: TValue,\n modelData: CreateParams<TData>\n ) => TValue\n /**\n * A thread safe (Atomic) version of lazyLoadMethod. Use this for all lazy loadings that requires Promises.\n * @param value - The current value\n * @param modelData - The models current data.\n */\n lazyLoadMethodAtomic: <TData extends DataDescription>(\n value: TValue,\n modelData: CreateParams<TData>\n ) => Promise<TValue>\n /**\n * An optional function that can select a \"part\" of the value to return.\n * @param instanceValue\n */\n valueSelector: (instanceValue: MaybePromise<TValue>) => TValue\n /**\n * Additional validators for the property.\n */\n validators: readonly PropertyValidatorComponent<any>[]\n /**\n * An optional zod schema for this property. If provided, it will be used as an\n * override for the generated schema.\n */\n zod?: ZodType<any>\n /**\n * A short human readable description of the property for documentation.\n */\n description?: string\n /**\n * The maximum length of the value. (Drives validation)\n */\n maxLength: number\n /**\n * The minimum length of the value. (Drives validation)\n */\n minLength: number\n /**\n * The maximum size of the value. (Drives validation)\n */\n maxValue: number\n /**\n * The minimum size of the value. (Drives validation)\n */\n minValue: number\n /**\n * If the value should be created automatically. Used in date creation.\n */\n autoNow: boolean\n /**\n * If you are using ModelReferences, this is required.\n * A fetcher used for getting model references.\n * This configuration item is used within the {@link AdvancedModelReferenceProperty} and any other property\n * that is lazy loading (atomically) models.\n */\n fetcher: ModelInstanceFetcher\n }>\n>\n\n/**\n * A function that has the ability to fetch an instance of a model.\n * This is the backbone that provides the \"ModelReference\" functionality.\n * This is useful downstream for building ORMs and other systems that require\n * hydrating \"foreign key\" models.\n * @param model - The model type that is being fetched.\n * @param primaryKey - The primary key of the desired data.\n */\ntype ModelInstanceFetcher<\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> = <TData extends DataDescription>(\n model: ModelType<TData, TModelExtensions, TModelInstanceExtensions>,\n primaryKey: PrimaryKeyType\n) =>\n | Promise<\n | TData\n | ModelInstance<TData, TModelExtensions, TModelInstanceExtensions>\n | ToObjectResult<TData>\n >\n | Promise<null>\n | Promise<undefined>\n\n/**\n * The configurations for a property.\n */\ntype PropertyConfig<TValue extends Arrayable<DataValue>> =\n | (PropertyConfigOptions<TValue> & CommonValidators)\n | undefined\n\n/**\n * Depending on your system a primary key is either a string or a number.\n */\ntype PrimaryKeyType = string | number\n\n/**\n * A function that has the ability to build models. (The models themselves, not instances of models)\n * This is actually a \"factory of model factories\" but we're just calling it a ModelFactory.\n *\n * IMPORTANT:\n * If you want to override and create extended Models/ModelInstances this is the place to do it.\n * Create your own ModelFactory that adds additional functionality.\n * For expanding a Model, you can just add it to the overall object. that {@link ModelFactory} produces.\n *\n * For expanding a ModelInstance, you will want to wrap the \"create()\" function of {@link ModelType}\n *\n * @param modelDefinition - The minimal model definitions needed.\n * @param options - Additional model options.\n */\ntype ModelFactory<\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n TModelFactoryOptionsExtensions extends object = object,\n> = <TData extends DataDescription>(\n modelDefinition: MinimalModelDefinition<TData>,\n options?: ModelFactoryOptions<TData, TModelFactoryOptionsExtensions>\n) => ModelType<TData, TModelExtensions, TModelInstanceExtensions>\n\n/**\n * Input parameters to a model's create function.\n */\ntype CreateParams<\n TData extends DataDescription,\n IgnoreProperties extends string = '',\n> = Omit<TData | RemovePromises<TData>, IgnoreProperties>\n\n/**\n * Higher Level Methods associated with a model based API. CRUDS\n */\nenum ApiMethod {\n create = 'create',\n retrieve = 'retrieve',\n update = 'update',\n delete = 'delete',\n search = 'search',\n}\n\n/**\n * Basic REST information for a model.\n * @interface\n */\ntype RestInfo = {\n /**\n * The endpoint (not including the base domain). This format can include \":id\" to describe a specific instance id.\n * Example: /api/v2/whatever-i-want/model/:id\n * The following are the defaults by API method:\n * create: '/namespace/app',\n * retrieve: '/namespace/app/id',\n * update: '/namespace/app/id',\n * delete: '/namespace/app/id',\n * search: '/namespace/app/search',\n */\n endpoint: string\n /**\n * Security descriptions\n */\n security: openapi.OpenAPIV3_1.SecurityRequirementObject\n /**\n * The HTTP Method. The following are the defaults used:\n * create: post,\n * retrieve: get,\n * update: put,\n * delete: delete,\n * search: post,\n */\n method: openapi.OpenAPIV3_1.HttpMethods\n}\n\n/**\n * A minimum input for a RestInfo.\n */\ntype RestInfoMinimum = {\n security?: openapi.OpenAPIV3_1.SecurityRequirementObject\n} & Omit<RestInfo, 'security'>\n\n/**\n * Functional API documentation for a given model. This allows the automatic creation of tools and documentation such as OpenApi specs.\n * This uses the standard \"CRUDS\" api methods that you might see on any API involving a model.\n * Create, Retrieve, Update, Delete, Search\n * @interface\n */\ntype ApiInfo = {\n /**\n * If true, no api information should be published. This means, that no code-generation tool should produce\n * any api code/documentation as it relates to this model. If you want partial publishing, look at \"onlyPublish\"\n */\n noPublish: boolean\n /**\n * Similar to noPublish, but granular. This will only publish the methods shown. If noPublish is provided,\n * this will be empty. If onlyPublish is empty, and noPublish is false, then all methods will be published.\n */\n onlyPublish: readonly ApiMethod[]\n /**\n * A description of each Api method to its rest info.\n * If this is not manually overrided then defaults are used for each.\n */\n rest: Record<ApiMethod, RestInfo>\n /**\n * Create normally can support bulk inserts (more than one). If this property is true, create will only handle \"one\" model at a time.\n */\n createOnlyOne: boolean\n}\n\n/**\n * An {@link ApiInfo} that has only part of RestInfo completed. (useful for overriding defaults)\n * @interface\n */\ntype ApiInfoPartialRest = Readonly<{\n rest: Partial<Record<ApiMethod, RestInfoMinimum>>\n}> &\n Omit<ApiInfo, 'rest'>\n\n/**\n * Expressively defines metadata for a given model.\n * @interface\n */\ntype ModelDefinition<TData extends DataDescription> = Readonly<{\n /**\n * The primary name for the model and instances of the model. This should be a name for multiple of the model instances.\n */\n pluralName: string\n /**\n * The name that this model exists within, such as an app. This is used to combine with the pluralName to create\n * a unique name across a system that it is used in.\n *\n * Recommended:\n * If you are creating reusable libraries/packages for people, we recommend using the name of the package itself.\n * Example: \"@my-scoped-package/name\"\n *\n * If you are creating this model to be used locally, just use the \"app\" name that the model corresponds to.\n * Example: \"auth\"\n *\n * The namespace is also used in the auto-generation of {@link RestInfo.endpoint}. If you want to design the endpoint so that it looks/reads/flows better then consider overriding the endpoint yourself.\n */\n namespace: string\n /**\n * The properties that make up the model.\n */\n properties: PropertiesList<Required<TData>>\n /**\n * The name of the property that has the unique id for the model. Used to uniquely identify instances of this model vs other ones.\n */\n primaryKeyName: string\n /**\n * Validators of the overall model (rather than properties)\n */\n modelValidators: readonly ModelValidatorComponent<TData>[]\n /**\n * The name for a model/instance where there is one of them.\n */\n singularName: string\n /**\n * A text used for displaying the name of the model in a UI.\n */\n displayName: string\n /**\n * A helpful human-readable description that explains what the model is and what it is used for.\n */\n description: string\n /**\n * The raw api information provided in. When looking for a fleshed out version of this data\n * look at {@link ModelType.getApiInfo}\n */\n api?: Partial<ApiInfoPartialRest>\n /**\n * A zod schema for the model.\n */\n schema: ZodObject<DataDescription>\n}>\n\n/**\n * The most minimum information needed to create a model.\n * @interface\n */\ntype MinimalModelDefinition<TData extends DataDescription> = Partial<\n ModelDefinition<TData>\n> & {\n namespace: string\n pluralName: string\n properties: PropertiesList<Required<TData>>\n}\n\n/**\n * Represents a Model. A Model creates instances (ModelInstance) as well as describes generally about the data. (ModelDefinition).\n * @typeParam TData - The type of data\n * @typeParam TModelExtensions - Extensions on the model.\n * @typeParam TModelInstanceExtensions - Extensions on the instances produced by this model.\n * @interface\n */\ntype ModelType<\n TData extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> = Readonly<{\n /**\n * This is a unique name combining namespace + pluralName. This can be used as a key to uniquely identify\n * this model across an entire system.\n * Example:\n * pluralName=MyModels\n * namespace=@my-package/namespace\n *\n * Return: '@my-package/namespace/MyModels'\n */\n getName: () => string\n /**\n * Gets the metadata that describes the model.\n */\n getModelDefinition: () => ModelDefinition<TData>\n /**\n * Gets the primary key of instance data. This helpful method shortcuts having to figure out the primaryKey's name\n * and then reaching inside the instance data to get the primary key.\n * @param instanceData The underlying instance data that has the primary key.\n */\n getPrimaryKey: (instanceData: TData | ToObjectResult<TData>) => PrimaryKeyType\n /**\n * Gets the Api Information on the model.\n *\n * This will take what is manually provided via the ModelDefinition and autopopulate everything that is possible\n * with default values, or values that make sense based on the ApiInformation provided.\n */\n getApiInfo: () => Required<ApiInfo>\n /**\n * Creates an instance of this model with the data that is provided.\n *\n * @typeParam IgnorePrimaryKey - One or more properties to ignore type restrictions on. This is extremely useful for primaryKeys that have not been created yet, or other generated properties (that are required instead of optional).\n * @param data - The data that makes up an instance of the model.\n * NOTE: A tradeoff was made between supporting the DataDescription vs a ToObjectReturn<DataDescription>. One or the other could be supported, but not both.\n * In order to support executing create() while passing in data that comes from \".toObj()\" we recommend using that case feature of toObj().\n */\n create: <IgnoreProperties extends string = ''>(\n data: CreateParams<TData, IgnoreProperties>\n ) => ModelInstance<TData, TModelExtensions, TModelInstanceExtensions>\n}> &\n TModelExtensions\n\n/**\n * A function that can provide a model reference.\n */\ntype ModelReferenceFunctions = Record<string, () => Maybe<PrimaryKeyType>>\n\n/**\n * Records of Property name to Validator.\n */\ntype PropertyValidators<TData extends DataDescription> = Readonly<\n Record<string, PropertyValidator<TData>>\n>\n\n/**\n * An instance of a Model. This \"wrapper\" fully embodies the power of the framework, and provides the most enrichment of a single piece of a data possible.\n * @typeParam TData - The type of data\n * @typeParam TModelExtensions - Extensions on the overall model.\n * @typeParam TModelInstanceExtensions - Extensions on all instances of a model.\n * @interface\n */\ntype ModelInstance<\n TData extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> = Readonly<{\n /**\n * Gets the value of individual properties on the instance.\n * These are memoized.\n */\n get: PropertyGetters<TData>\n /**\n * Gets all model references that this instance may have as record of property name to function getter.\n *\n */\n getReferences: () => ModelReferenceFunctions\n /**\n * Gets a basic representation of the data.\n * This function is memoized.\n */\n toObj: ToObjectFunction<TData>\n /**\n * Gets the primary key of the instance (without having to know the primary key name).\n */\n getPrimaryKey: () => PrimaryKeyType\n /**\n * Gets the validators for this model instance.\n */\n getValidators: () => PropertyValidators<TData>\n /**\n * Runs validation against this instance.\n * This function is memoized.\n * @param options\n */\n validate: (options?: object) => Promise<ModelErrors<TData> | undefined>\n /**\n * Gets the model that backs this instance.\n */\n getModel: () => ModelType<TData, TModelExtensions, TModelInstanceExtensions>\n}> &\n TModelInstanceExtensions\n\n/**\n * A callback function for receiving when a new model has been created.\n * @param instance - A newly created model instance.\n */\ntype ModelCreatedCallback<\n TData extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> = (\n instance: ModelInstance<TData, TModelExtensions, TModelInstanceExtensions>\n) => void\n\n/**\n * Options to pass into model generation.\n * @interface\n */\ntype ModelFactoryOptions<\n TData extends DataDescription,\n TModelFactoryOptionsExtensions extends object = object,\n> = Record<string, any> &\n Readonly<{\n /**\n * 1 or more (array) of callback functions for when models get created.\n */\n instanceCreatedCallback?: Arrayable<ModelCreatedCallback<TData>>\n }> &\n TModelFactoryOptionsExtensions\n\n/**\n * A function that can calculate a denormalized value. This is very useful for property values that have very complicated and often expensive calculations (but should be calculated once).\n * NOTE: The data that comes in (to be normalized) via the modelData, is the raw data passed into create(). If other functions must fire to create values, they will not be present. Example: Foreign keys.\n * @param modelData - The model's data as it was passed into the create() function.\n * @param modelInstance - The instance that the model corresponds with\n */\ntype CalculateDenormalization<\n TValue extends CanBeNullableType<DataValue>,\n TData extends DataDescription,\n TModelExtensions extends object = object,\n TModelInstanceExtensions extends object = object,\n> = (\n modelData: CreateParams<TData>,\n modelInstance: ModelInstance<\n TData,\n TModelExtensions,\n TModelInstanceExtensions\n >\n) => MaybePromise<TValue | undefined>\n\n/**\n * Higher level value types that describe what the value of a property is.\n * These values can be used to generate expressive APIs as well as GUI elements.\n */\nenum PropertyType {\n UniqueId = 'UniqueId',\n Date = 'Date',\n Datetime = 'Datetime',\n Array = 'Array',\n ModelReference = 'ModelReference',\n Integer = 'Integer',\n Text = 'Text',\n BigText = 'BigText',\n Number = 'Number',\n Object = 'Object',\n Email = 'Email',\n Boolean = 'Boolean',\n}\n\n/**\n * The most primitive data types that can be used.\n */\nenum PrimitiveValueType {\n boolean = 'boolean',\n string = 'string',\n object = 'object',\n number = 'number',\n integer = 'integer',\n}\n\n/**\n * Dates can either be a Date or a string\n */\ntype DateValueType = Date | string\n\n/**\n * A useful type for setting the props object of a Model constructor.\n */\ntype ModelConstructorProps = Readonly<{\n Model: ModelFactory\n}>\n\n/**\n * A useful type for setting the props object of a Model constructor that has model references that need a fetcher\n */\ntype ModelWithReferencesConstructorProps = ModelConstructorProps &\n Readonly<{\n fetcher: ModelInstanceFetcher\n }>\n\nexport {\n PrimitiveValueType,\n PropertyType,\n MaybeFunction,\n Maybe,\n MaybePromise,\n Nullable,\n Arrayable,\n JsonAble,\n ToObjectFunction,\n ToObjectResult,\n ModelInstance,\n ModelType,\n PropertyValidatorComponent,\n PropertyValidatorComponentSync,\n PropertyValidatorComponentAsync,\n PropertyValidator,\n ModelValidatorComponent,\n PropertyInstance,\n PropertyConfig,\n DataValue,\n ValueGetter,\n ModelReferenceType,\n ModelDefinition,\n ModelFactoryOptions,\n ModelReferencePropertyInstance,\n PropertyGetters,\n PropertyValidators,\n PropertyValidatorComponentTypeAdvanced,\n DataDescription,\n ModelReferenceFunctions,\n ModelErrors,\n PrimaryKeyType,\n ModelFactory,\n ModelInstanceFetcher,\n CreateParams,\n ValidatorContext,\n ValuePropertyValidatorComponent,\n ValidationErrors,\n ComponentValidationErrorResponse,\n JsonifiedData,\n JsonObj,\n CalculateDenormalization,\n PropertiesList,\n MinimalModelDefinition,\n ChoiceTypes,\n PropertyConfigOptions,\n CommonValidators,\n DateValueType,\n ApiInfo,\n RestInfo,\n ApiMethod,\n RemovePromises,\n FlattenModelReferences,\n ApiInfoPartialRest,\n RestInfoMinimum,\n ModelConstructorProps,\n ModelWithReferencesConstructorProps,\n}\n", "import AsyncLock from 'async-lock'\nimport { v4 as uuidv4 } from 'uuid'\n// @ts-ignore\nimport getRandomValuesFunc from 'get-random-values'\n\nconst getRandomValues = (): Uint8Array => {\n const array = new Uint8Array(1)\n if (typeof window !== 'undefined') {\n if (window.crypto) {\n return window.crypto.getRandomValues(array)\n }\n // @ts-ignore\n if (window.msCrypto) {\n // @ts-ignore\n return window.msCrypto.getRandomValues(array)\n }\n }\n\n return getRandomValuesFunc(array)\n}\n\nconst toTitleCase = (string: string) => {\n return `${string.slice(0, 1).toUpperCase()}${string.slice(1)}`\n}\n\nconst loweredTitleCase = (string: string) => {\n return `${string.slice(0, 1).toLowerCase()}${string.slice(1)}`\n}\n\nconst isPromise = <T>(something: any): something is Promise<T> => {\n if (something?.then) {\n return true\n }\n return false\n}\n\nenum PluralEndings {\n ves = 'fe',\n ies = 'y',\n i = 'us',\n zes = 'ze',\n ses = 's',\n es = 'e',\n s = '',\n}\nconst _singularizingRe = new RegExp(\n `(${Object.keys(PluralEndings).join('|')})$`,\n 'u'\n)\n\nconst singularize = (word: string) => {\n // @ts-ignore\n return word.replace(_singularizingRe, r => PluralEndings[r])\n}\n\nconst createHeadAndTail = (values: readonly string[], joiner: string) => {\n const head = values[0]\n const tail = values.slice(1).join(joiner)\n return [head, tail]\n}\n\nconst flowFindFirst =\n <T, TResult>(funcs: ((t: T) => undefined | TResult)[]) =>\n (input: T) => {\n return funcs.reduce((acc: undefined | TResult, func) => {\n if (acc) {\n return acc\n }\n return func(input)\n }, undefined) as string | TResult\n }\n\nconst memoizeSync = <T, A extends Array<any>>(method: (...args: A) => T) => {\n /* eslint-disable functional/no-let */\n let value: any = undefined\n let called = false\n return (...args: A): T => {\n if (!called) {\n called = true\n value = method(...args)\n }\n\n return value\n }\n /* eslint-enable functional/no-let */\n}\n\nconst memoizeAsync = <T, A extends Array<any>>(method: (...args: A) => T) => {\n const key = uuidv4()\n const lock = new AsyncLock()\n /* eslint-disable functional/no-let */\n let value: any = undefined\n let called = false\n return async (...args: A): Promise<T> => {\n return lock.acquire(key, async () => {\n if (!called) {\n called = true\n value = await method(...args)\n }\n\n return value\n })\n }\n /* eslint-enable functional/no-let */\n}\n\nconst createUuid = uuidv4\n\nexport {\n getRandomValues,\n loweredTitleCase,\n toTitleCase,\n isPromise,\n createHeadAndTail,\n singularize,\n flowFindFirst,\n memoizeSync,\n memoizeAsync,\n createUuid,\n}\n", "import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n", "const rnds8 = new Uint8Array(16);\nexport default function rng() {\n return crypto.getRandomValues(rnds8);\n}\n", "import rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (!buf && !options && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n return _v4(options, buf, offset);\n}\nfunction _v4(options, buf, offset) {\n options = options || {};\n const rnds = options.random ?? options.rng?.() ?? rng();\n if (rnds.length < 16) {\n throw new Error('Random bytes length must be >= 16');\n }\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n }\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n", "import { OpenAPIV3 } from 'openapi-types'\nimport kebabCase from 'lodash/kebabCase.js'\nimport flow from 'lodash/flow.js'\nimport merge from 'lodash/merge.js'\nimport get from 'lodash/get.js'\nimport { z, ZodType } from 'zod'\nimport {\n ApiInfo,\n ApiInfoPartialRest,\n ApiMethod,\n Arrayable,\n DataDescription,\n DataValue,\n ModelInstance,\n PrimaryKeyType,\n PropertyConfig,\n CanBeNullableType,\n PropertyValidatorComponent,\n PropertyValidatorComponentTypeAdvanced,\n RestInfo,\n RestInfoMinimum,\n} from './types.js'\nimport { createHeadAndTail } from './utils.js'\nimport {\n emptyValidator,\n maxNumber,\n maxTextLength,\n minNumber,\n minTextLength,\n} from './validation.js'\nimport HttpMethods = OpenAPIV3.HttpMethods\n\nconst NULL_ENDPOINT = 'NULL'\nconst NULL_METHOD = HttpMethods.HEAD\nconst ID_KEY = ':id'\n\nconst getValueForReferencedModel = async (\n modelInstance: ModelInstance<any>,\n path: string\n): Promise<PrimaryKeyType | any> => {\n const [head, tail] = createHeadAndTail(path.split('.'), '.')\n // If there are no nested keys, just return the reference id.\n if (!tail) {\n return modelInstance.getReferences()[head]()\n }\n const modelReference = await modelInstance.get[head]()\n if (modelReference.toObj) {\n const [nestedHead, nestedTail] = createHeadAndTail(tail.split('.'), '.')\n const value = await modelReference.get[nestedHead]()\n if (nestedTail) {\n return get(value, nestedTail)\n }\n return value\n }\n return get(modelReference, tail)\n}\n\nconst getValueForModelInstance = async (\n modelInstance: ModelInstance<any>,\n path: string\n): Promise<PrimaryKeyType | any> => {\n const [head, tail] = createHeadAndTail(path.split('.'), '.')\n const value = await modelInstance.get[head]()\n return tail ? get(value, tail) : value\n}\n\nconst isReferencedProperty = (\n modelInstance: ModelInstance<any>,\n key: string\n) => {\n return modelInstance.getReferences()[key]\n}\n\nconst getCommonTextValidators = <T extends CanBeNullableType<string> = string>(\n config: PropertyConfig<T>\n): readonly PropertyValidatorComponent<any>[] => {\n return [\n getValidatorFromConfigElseEmpty(config?.maxLength, maxTextLength),\n getValidatorFromConfigElseEmpty(config?.minLength, minTextLength),\n ]\n}\n\nconst getValidatorFromConfigElseEmpty = <\n T extends DataDescription,\n TValue extends DataValue,\n>(\n input: TValue | undefined,\n\n validatorGetter: (t: TValue) => PropertyValidatorComponent<T>\n): PropertyValidatorComponent<T> => {\n if (input !== undefined) {\n const validator = validatorGetter(input)\n return validator\n }\n return emptyValidator\n}\n\nconst getCommonNumberValidators = <\n T extends CanBeNullableType<number> = number,\n>(\n config: PropertyConfig<T>\n): readonly PropertyValidatorComponent<any>[] => {\n return [\n getValidatorFromConfigElseEmpty(config?.minValue, minNumber),\n getValidatorFromConfigElseEmpty(config?.maxValue, maxNumber),\n ]\n}\n\nconst mergeValidators = <\n TValue extends Arrayable<CanBeNullableType<DataValue>> = Arrayable<DataValue>,\n>(\n config: PropertyConfig<TValue> | undefined,\n ...validators: readonly (\n | PropertyValidatorComponent<any>\n | PropertyValidatorComponentTypeAdvanced<any, any>\n )[]\n): PropertyValidatorComponent<any>[] => {\n return [...validators, ...(config?.validators ? config.validators : [])]\n}\n\nconst isModelInstance = (obj: any): obj is ModelInstance<any, any> => {\n // @ts-ignore\n return Boolean(obj && obj.getPrimaryKey)\n}\n\nconst getModelName = (namespace: string, pluralName: string) => {\n return `${namespace}/${pluralName}`\n}\n\nconst parseModelName = (modelName: string) => {\n const parts = modelName.split('/')\n // eslint-disable-next-line functional/immutable-data\n const pluralName = parts.pop()\n const namespace = parts.join('/')\n return { namespace, pluralName }\n}\n\nconst buildValidEndpoint = (...components: readonly string[]) => {\n const suffix = components\n .map(x => {\n if (x === ID_KEY) {\n return x\n }\n return kebabCase(x)\n })\n .map(s => s.toLowerCase())\n .join('/')\n return `/${suffix}`\n}\n\nconst _generateRestInfo =\n (method: HttpMethods, withId: boolean, ...additional: readonly string[]) =>\n (pluralName: string, namespace: string) =>\n (existing?: RestInfoMinimum): RestInfo => {\n if (existing) {\n return {\n // Default add security, then override it.\n security: {},\n ...existing,\n }\n }\n const endpoint = withId\n ? buildValidEndpoint(namespace, pluralName, ID_KEY)\n : buildValidEndpoint(namespace, pluralName, ...additional)\n return {\n method,\n endpoint,\n // We cannot auto create security.\n security: {},\n }\n }\n\nconst _apiMethodToRestInfoGenerator = {\n [ApiMethod.create]: _generateRestInfo(HttpMethods.POST, false),\n [ApiMethod.retrieve]: _generateRestInfo(HttpMethods.GET, true),\n [ApiMethod.update]: _generateRestInfo(HttpMethods.PUT, true),\n [ApiMethod.delete]: _generateRestInfo(HttpMethods.DELETE, true),\n [ApiMethod.search]: _generateRestInfo(HttpMethods.POST, false, 'search'),\n}\n\nconst getNullRestInfo = () => {\n return {\n endpoint: NULL_ENDPOINT,\n method: NULL_METHOD,\n security: {},\n }\n}\n\nconst _fillOutRestInfo = (\n pluralName: string,\n namespace: string,\n partial: Partial<ApiInfoPartialRest> | undefined,\n nullRest: Record<ApiMethod, RestInfo>\n) => {\n const finishedRestInfo: Record<ApiMethod, RestInfo> = Object.entries(\n ApiMethod\n ).reduce(\n (acc, [, method]) => {\n const existing =\n partial && partial.rest && partial.rest[method]\n ? partial.rest[method]\n : undefined\n const restInfo = _apiMethodToRestInfoGenerator[method](\n pluralName,\n namespace\n )(existing)\n return merge(acc, {\n [method]: restInfo,\n })\n },\n nullRest as Record<ApiMethod, RestInfo>\n )\n return {\n noPublish: false,\n onlyPublish: [],\n rest: finishedRestInfo,\n createOnlyOne: partial?.createOnlyOne || false,\n }\n}\n\nconst populateApiInformation = (\n pluralName: string,\n namespace: string,\n partial: Partial<ApiInfoPartialRest> | undefined\n): Readonly<Required<ApiInfo>> => {\n const nullRest = {\n delete: getNullRestInfo(),\n search: getNullRestInfo(),\n update: getNullRestInfo(),\n retrieve: getNullRestInfo(),\n create: getNullRestInfo(),\n }\n\n if (!partial) {\n return _fillOutRestInfo(pluralName, namespace, partial, nullRest)\n }\n // Are we not going to publish at all? All \"nulled\" out.\n if (partial.noPublish) {\n return {\n onlyPublish: [],\n noPublish: true,\n rest: nullRest,\n createOnlyOne: false,\n }\n }\n\n const rest: Partial<Record<ApiMethod, RestInfoMinimum>> = partial.rest || {}\n // Should we only publish some but not all?\n if (partial.onlyPublish && partial.onlyPublish.length > 0) {\n return partial.onlyPublish.reduce(\n (acc, method) => {\n const restInfo = _apiMethodToRestInfoGenerator[method](\n pluralName,\n namespace\n )(rest[method])\n return merge(acc, {\n rest: {\n [method]: restInfo,\n },\n })\n },\n {\n noPublish: false,\n onlyPublish: partial.onlyPublish,\n createOnlyOne: Boolean(partial.createOnlyOne),\n rest: nullRest,\n } as ApiInfo\n )\n }\n return _fillOutRestInfo(pluralName, namespace, partial, nullRest)\n}\n\n/**\n * Create a zod schema generator for a property given its type and config.\n * Returns a function that when called produces the zod schema.\n */\nconst createZodForProperty =\n (propertyType: any, config?: PropertyConfig<any>) => () => {\n const myConfig: PropertyConfig<any> = config || {}\n const provided = myConfig.zod\n if (provided) {\n return provided as ZodType<any>\n }\n\n const _getZodForPropertyType = (pt: any) => {\n if (myConfig.choices) {\n return z.enum(myConfig.choices as any)\n }\n switch (pt) {\n case 'UniqueId':\n return z.string()\n case 'Date':\n case 'Datetime':\n return z.union([z.string(), z.date()])\n case 'Integer':\n return z.number().int()\n case 'Number':\n return z.number()\n case 'Boolean':\n return z.boolean()\n case 'Array':\n return z.array(z.any())\n case 'Object':\n return z.object().loose()\n case 'Email':\n return z.email()\n case 'Text':\n case 'BigText':\n return z.string()\n case 'ModelReference':\n return z.union([z.string(), z.number()])\n default:\n return z.any()\n }\n }\n\n const baseSchema = _getZodForPropertyType(propertyType)\n const choices = (config as any)?.choices\n const schemaFromChoices =\n choices && Array.isArray(choices) && choices.length > 0\n ? z.union(choices.map((c: any) => z.literal(c)) as any)\n : baseSchema\n\n const finalSchema = flow([\n s =>\n typeof myConfig.minValue === 'number' ? s.min(myConfig.minValue) : s,\n s =>\n typeof myConfig.maxValue === 'number' ? s.max(myConfig.maxValue) : s,\n s =>\n typeof myConfig.minLength === 'number' ? s.min(myConfig.minLength) : s,\n s =>\n typeof myConfig.maxLength === 'number' ? s.max(myConfig.maxLength) : s,\n s =>\n myConfig.defaultValue !== undefined\n ? s.default(myConfig.defaultValue)\n : s,\n s => (myConfig.required ? s : s.optional()),\n // Attach description for Zod consumers and OpenAPI generators.\n s => {\n if (myConfig.description) {\n // zod's describe helps Zod introspection; some zod-openapi versions expect metadata via .meta or .openapi\n // Use .describe and also attach .meta with openapi description if available.\n if (typeof s.openapi === 'function') {\n return s.openapi({ description: myConfig.description })\n }\n return s.meta\n ? s.meta({ description: myConfig.description })\n : s.describe(myConfig.description)\n }\n return s\n },\n ])(schemaFromChoices)\n\n return finalSchema as ZodType<any>\n }\n\nexport {\n isReferencedProperty,\n getValueForModelInstance,\n getValueForReferencedModel,\n getCommonTextValidators,\n getValidatorFromConfigElseEmpty,\n getCommonNumberValidators,\n mergeValidators,\n isModelInstance,\n getModelName,\n buildValidEndpoint,\n populateApiInformation,\n NULL_ENDPOINT,\n NULL_METHOD,\n createZodForProperty,\n parseModelName,\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAkB;AAClB,IAAAC,cAAsC;;;ACDtC,mBAAkB;AAWlB,IAAM,kBAAkB,CAAC,QAAwC;AAC/D,SAAO,QAAQ,IAAI,KAAK;AAC1B;AAEA,IAAM,YAAY,OAAO,UAAyC;AAChE,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT;AACA,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AACA,QAAM,OAAO,OAAO;AACpB,QAAM,aAAa;AACnB,MAAI,SAAS,YAAY;AACvB,WAAO,UAAU,MAAM,WAAW,CAAC;AAAA,EACrC;AAEA,MAAI,gBAAgB,KAAK,GAAG;AAC1B,WAAO,UAAU,MAAM,MAAM,MAAM,CAAC;AAAA,EACtC;AAEA,QAAM,SAAS;AACf,MAAI,SAAS,YAAY,OAAO,aAAa;AAC3C,WAAO,UAAU,OAAO,YAAY,CAAC;AAAA,EACvC;AACA,SAAO;AACT;AAEA,IAAM,aACJ,CACE,cAEF,MAEK;AACH,SAAO,OAAO,QAAQ,SAAS,EAAE,OAAO,OAAO,KAAK,CAAC,KAAK,KAAK,MAAM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import_merge", "import_zod", "merge", "import_merge", "ApiMethod", "PluralEndings", "AsyncLock", "flow", "merge", "isEmpty", "import_merge", "import_get", "kebabCase", "merge", "merge", "z", "options"]
|
|
7
|
+
}
|