@orion-js/typed-model 4.3.1 → 4.4.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/LICENSE +21 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/prop.d.ts +9 -0
- package/dist/decorators/typedSchema.d.ts +14 -0
- package/dist/errors/CannotDetermineType.d.ts +3 -0
- package/dist/factories/cloneSchemaClass.d.ts +15 -0
- package/dist/factories/getModelForClass.d.ts +5 -0
- package/dist/factories/getSchemaForClass.d.ts +2 -0
- package/dist/factories/index.d.ts +3 -0
- package/dist/factories/processTypeForProp.d.ts +2 -0
- package/dist/index.cjs +10 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -48
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/storage/metadataStorage.d.ts +6 -0
- package/dist/utils/interfaces.d.ts +3 -0
- package/package.json +15 -16
- package/dist/index.d.cts +0 -48
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Orionjs Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Constructor, SchemaFieldType, SchemaNode } from '@orion-js/schema';
|
|
2
|
+
import { Model } from '@orion-js/models';
|
|
3
|
+
export interface PropOptions extends Omit<SchemaNode, 'type'> {
|
|
4
|
+
type: SchemaFieldType | Constructor<any> | Model | Model[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use schema with InferSchemaType<schema as const> instead
|
|
8
|
+
*/
|
|
9
|
+
export declare function Prop(options: PropOptions): (_target: any, context: ClassFieldDecoratorContext) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TypedSchemaOptions } from '../storage/metadataStorage';
|
|
2
|
+
import { Model } from '@orion-js/models';
|
|
3
|
+
import { PropOptions } from './prop';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use schema with InferSchemaType<schema as const> instead
|
|
6
|
+
*/
|
|
7
|
+
export declare function TypedSchema(options?: TypedSchemaOptions): (_target: any, context: ClassDecoratorContext<any>) => void;
|
|
8
|
+
export type SchemaFromTypedSchemaMetadata = {
|
|
9
|
+
_isTypedSchema: true;
|
|
10
|
+
_modelName: string;
|
|
11
|
+
_modelOptions: TypedSchemaOptions;
|
|
12
|
+
_getModel: () => Model;
|
|
13
|
+
[key: `_prop:${string}`]: PropOptions;
|
|
14
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CloneOptions } from '@orion-js/models';
|
|
2
|
+
import { Constructor } from '../utils/interfaces';
|
|
3
|
+
import { Schema } from '@orion-js/schema';
|
|
4
|
+
export interface CloneSchemaClassOptions<TClass, TFields extends (keyof TClass)[] | undefined = undefined> {
|
|
5
|
+
name: string;
|
|
6
|
+
pickFields?: TFields;
|
|
7
|
+
mapFields?: CloneOptions['mapFields'];
|
|
8
|
+
extendSchema?: CloneOptions['extendSchema'];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `cloneSchema` instead
|
|
12
|
+
*/
|
|
13
|
+
export declare function cloneSchemaClass<TClass, TFields extends (keyof TClass)[] | undefined = undefined>(inputType: Constructor<TClass>, options: CloneSchemaClassOptions<TClass, TFields>): Schema & {
|
|
14
|
+
__tsFieldType: TFields extends undefined ? TClass : Pick<TClass, TFields[number]>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Model } from '@orion-js/models';
|
|
2
|
+
import { SchemaFromTypedSchemaMetadata } from '..';
|
|
3
|
+
import { Schema } from '@orion-js/schema';
|
|
4
|
+
export declare function getModelForClass(target: any): Model;
|
|
5
|
+
export declare function internal_getModelForClassFromMetadata(metadata: SchemaFromTypedSchemaMetadata): Model<Schema>;
|
package/dist/index.cjs
CHANGED
|
@@ -101,24 +101,25 @@ function getParamTypeForProp(type2) {
|
|
|
101
101
|
if ((_a = type2 == null ? void 0 : type2[Symbol.metadata]) == null ? void 0 : _a._getModel) {
|
|
102
102
|
return type2[Symbol.metadata]._getModel(type2);
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const objectType = type2;
|
|
105
|
+
if (objectType == null ? void 0 : objectType.getSchema) {
|
|
106
|
+
return getParamTypeForProp(objectType.getSchema());
|
|
106
107
|
}
|
|
107
108
|
if (isType("Object", type2)) {
|
|
108
|
-
if (
|
|
109
|
+
if (objectType.__isFieldType) {
|
|
109
110
|
return type2;
|
|
110
111
|
}
|
|
111
112
|
const subschema = {};
|
|
112
|
-
Object.keys(
|
|
113
|
+
for (const key of Object.keys(objectType)) {
|
|
113
114
|
if (key.startsWith("__")) {
|
|
114
|
-
subschema[key] =
|
|
115
|
-
|
|
115
|
+
subschema[key] = objectType[key];
|
|
116
|
+
continue;
|
|
116
117
|
}
|
|
117
118
|
subschema[key] = {
|
|
118
|
-
...
|
|
119
|
-
type: getParamTypeForProp(
|
|
119
|
+
...objectType[key],
|
|
120
|
+
type: getParamTypeForProp(objectType[key].type)
|
|
120
121
|
};
|
|
121
|
-
}
|
|
122
|
+
}
|
|
122
123
|
return subschema;
|
|
123
124
|
}
|
|
124
125
|
return type2;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/type.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/isType.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/omit.js","../src/factories/getModelForClass.ts","../src/factories/processTypeForProp.ts","../src/factories/getSchemaForClass.ts","../src/factories/cloneSchemaClass.ts","../src/decorators/typedSchema.ts","../src/errors/CannotDetermineType.ts","../src/decorators/prop.ts"],"sourcesContent":["export * from './decorators'\nexport * from './factories'\n","export function type(input){\n if (input === null){\n return 'Null'\n } else if (input === undefined){\n return 'Undefined'\n } else if (Number.isNaN(input)){\n return 'NaN'\n }\n const typeResult = Object.prototype.toString.call(input).slice(8, -1)\n\n return typeResult === 'AsyncFunction' ? 'Promise' : typeResult\n}\n","function _isInteger(n){\n return n << 0 === n\n}\n\nexport const isInteger = Number.isInteger || _isInteger\n\n/**\n * Check if `index` is integer even if it is a string.\n */\nexport const isIndexInteger = index => Number.isInteger(Number(index))\n","import { isInteger } from './isInteger.js'\n\nexport function createPath(path, delimiter = '.'){\n return typeof path === 'string' ?\n path.split(delimiter).map(x => isInteger(x) ? Number(x) : x) :\n path\n}\n","import { type } from './type.js'\n\nexport function isType(xType, x){\n if (arguments.length === 1){\n return xHolder => isType(xType, xHolder)\n }\n\n return type(x) === xType\n}\n","export function compare(a, b){\n return String(a) === String(b)\n}\n","import { compare } from './compare.js'\n\nexport function includes(a, list){\n let index = -1\n const { length } = list\n\n while (++index < length)\n if (compare(list[ index ], a))\n return true\n\n return false\n}\n","import { createPath } from './_internals/createPath.js'\nimport { includes } from './_internals/includes.js'\n\nexport function omit(propsToOmit, obj){\n if (arguments.length === 1) return _obj => omit(propsToOmit, _obj)\n\n if (obj === null || obj === undefined)\n return undefined\n\n const propsToOmitValue = createPath(propsToOmit, ',')\n const willReturn = {}\n\n for (const key in obj)\n if (!includes(key, propsToOmitValue))\n willReturn[ key ] = obj[ key ]\n\n return willReturn\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {createModel, Model} from '@orion-js/models'\nimport {SchemaFromTypedSchemaMetadata} from '..'\nimport {getParamTypeForProp} from './processTypeForProp'\nimport {Schema} from '@orion-js/schema'\n\n// @ts-ignore polyfill for Symbol.metadata // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#decorator-metadata\nSymbol.metadata ??= Symbol('Symbol.metadata')\n\nexport function getModelForClass(target: any): Model {\n const targetAsModel = target as any as Model\n if (targetAsModel.__isModel) {\n return targetAsModel\n }\n\n const metadata = target[Symbol.metadata] as SchemaFromTypedSchemaMetadata\n\n if (!metadata) {\n return targetAsModel\n }\n\n return internal_getModelForClassFromMetadata(metadata)\n}\n\nexport function internal_getModelForClassFromMetadata(metadata: SchemaFromTypedSchemaMetadata) {\n const modelName = metadata._modelName\n\n const schema: Schema = {}\n const keys = Object.keys(metadata ?? {})\n const injectionKeys = keys.filter(key => key.startsWith('_prop:'))\n\n for (const key of injectionKeys) {\n const prop = metadata[key] as Schema\n const schemaProp = key.replace('_prop:', '')\n\n schema[schemaProp] = {\n ...prop,\n type: getParamTypeForProp(prop.type as any),\n }\n }\n\n const model = createModel({\n ...metadata._modelOptions,\n name: modelName,\n schema,\n })\n\n return model\n}\n","import {isType} from 'rambdax'\nimport {PropOptions} from '../decorators/prop'\n\nexport function getParamTypeForProp(type: PropOptions['type']) {\n if (Array.isArray(type)) {\n const itemType = type[0]\n return [getParamTypeForProp(itemType)]\n }\n\n if (type?.[Symbol.metadata]?._getModel) {\n return type[Symbol.metadata]._getModel(type)\n }\n\n if (type?.getSchema) {\n return getParamTypeForProp(type.getSchema())\n }\n\n if (isType('Object', type)) {\n if (type.__isFieldType) {\n return type\n }\n\n const subschema = {}\n Object.keys(type).forEach(key => {\n if (key.startsWith('__')) {\n subschema[key] = type[key]\n return\n }\n\n subschema[key] = {\n ...type[key],\n type: getParamTypeForProp(type[key].type),\n }\n })\n\n return subschema\n }\n\n return type\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {Schema} from '@orion-js/schema'\nimport {getModelForClass} from './getModelForClass'\n\nexport function getSchemaForClass(target: any): Schema {\n return getModelForClass(target).getSchema()\n}\n","import {CloneOptions} from '@orion-js/models'\nimport {Constructor} from '../utils/interfaces'\nimport {cloneSchema, getSchemaFromAnyOrionForm, Schema} from '@orion-js/schema'\n\nexport interface CloneSchemaClassOptions<\n TClass,\n TFields extends (keyof TClass)[] | undefined = undefined,\n> {\n name: string\n pickFields?: TFields\n mapFields?: CloneOptions['mapFields']\n extendSchema?: CloneOptions['extendSchema']\n}\n\n/**\n * @deprecated Use `cloneSchema` instead\n */\nexport function cloneSchemaClass<TClass, TFields extends (keyof TClass)[] | undefined = undefined>(\n inputType: Constructor<TClass>,\n options: CloneSchemaClassOptions<TClass, TFields>,\n): Schema & {\n __tsFieldType: TFields extends undefined ? TClass : Pick<TClass, TFields[number]>\n} {\n const schema = getSchemaFromAnyOrionForm(inputType) as Schema\n\n const newSchema = cloneSchema({\n schema,\n name: options.name,\n pickFields: options.pickFields as any as string[],\n mapFields: options.mapFields,\n extendSchema: options.extendSchema,\n })\n\n return newSchema as any\n}\n","import {omit} from 'rambdax'\nimport {internal_getModelForClassFromMetadata} from '../factories'\nimport {TypedSchemaOptions} from '../storage/metadataStorage'\nimport {Model} from '@orion-js/models'\nimport {PropOptions} from './prop'\n\n/**\n * @deprecated use schema with InferSchemaType<schema as const> instead\n */\nexport function TypedSchema(options: TypedSchemaOptions = {}) {\n return (_target: any, context: ClassDecoratorContext<any>) => {\n context.metadata._isTypedSchema = true\n context.metadata._modelName = options.name || context.name\n context.metadata._modelOptions = omit('name', options)\n context.metadata._getModel = () => {\n return internal_getModelForClassFromMetadata(\n context.metadata as SchemaFromTypedSchemaMetadata,\n )\n }\n }\n}\n\nexport type SchemaFromTypedSchemaMetadata = {\n _isTypedSchema: true\n _modelName: string\n _modelOptions: TypedSchemaOptions\n _getModel: () => Model\n [key: `_prop:${string}`]: PropOptions\n}\n","export class CannotDetermineTypeError extends Error {\n constructor(propertyKey: string) {\n super(\n `Cannot determine type at @Prop() \"${propertyKey}\". type: is required for all props since Orion v4`,\n )\n }\n}\n","import {Constructor, SchemaFieldType, SchemaNode} from '@orion-js/schema'\nimport {Model} from '@orion-js/models'\nimport {CannotDetermineTypeError} from '../errors/CannotDetermineType'\n\nexport interface PropOptions extends Omit<SchemaNode, 'type'> {\n type: SchemaFieldType | Constructor<any> | Model | Model[]\n}\n\n/**\n * @deprecated use schema with InferSchemaType<schema as const> instead\n */\nexport function Prop(options: PropOptions) {\n return (_target: any, context: ClassFieldDecoratorContext) => {\n const propertyKey = String(context.name)\n\n if (!options?.type) {\n throw new CannotDetermineTypeError(propertyKey)\n }\n\n context.metadata[`_prop:${propertyKey}`] = options\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,KAAK,OAAM;AACzB,MAAI,U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AAM,IAAI,yBAAyB,WAAW;AAAA,IAChD;AAEA,YAAQ,SAAS,SAAS,WAAW,EAAE,IAAI;AAAA,EAC7C;AACF;","names":["type"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/type.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/isType.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/omit.js","../src/factories/getModelForClass.ts","../src/factories/processTypeForProp.ts","../src/factories/getSchemaForClass.ts","../src/factories/cloneSchemaClass.ts","../src/decorators/typedSchema.ts","../src/errors/CannotDetermineType.ts","../src/decorators/prop.ts"],"sourcesContent":["export * from './decorators'\nexport * from './factories'\n","export function type(input){\n if (input === null){\n return 'Null'\n } else if (input === undefined){\n return 'Undefined'\n } else if (Number.isNaN(input)){\n return 'NaN'\n }\n const typeResult = Object.prototype.toString.call(input).slice(8, -1)\n\n return typeResult === 'AsyncFunction' ? 'Promise' : typeResult\n}\n","function _isInteger(n){\n return n << 0 === n\n}\n\nexport const isInteger = Number.isInteger || _isInteger\n\n/**\n * Check if `index` is integer even if it is a string.\n */\nexport const isIndexInteger = index => Number.isInteger(Number(index))\n","import { isInteger } from './isInteger.js'\n\nexport function createPath(path, delimiter = '.'){\n return typeof path === 'string' ?\n path.split(delimiter).map(x => isInteger(x) ? Number(x) : x) :\n path\n}\n","import { type } from './type.js'\n\nexport function isType(xType, x){\n if (arguments.length === 1){\n return xHolder => isType(xType, xHolder)\n }\n\n return type(x) === xType\n}\n","export function compare(a, b){\n return String(a) === String(b)\n}\n","import { compare } from './compare.js'\n\nexport function includes(a, list){\n let index = -1\n const { length } = list\n\n while (++index < length)\n if (compare(list[ index ], a))\n return true\n\n return false\n}\n","import { createPath } from './_internals/createPath.js'\nimport { includes } from './_internals/includes.js'\n\nexport function omit(propsToOmit, obj){\n if (arguments.length === 1) return _obj => omit(propsToOmit, _obj)\n\n if (obj === null || obj === undefined)\n return undefined\n\n const propsToOmitValue = createPath(propsToOmit, ',')\n const willReturn = {}\n\n for (const key in obj)\n if (!includes(key, propsToOmitValue))\n willReturn[ key ] = obj[ key ]\n\n return willReturn\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {createModel, Model} from '@orion-js/models'\nimport {SchemaFromTypedSchemaMetadata} from '..'\nimport {getParamTypeForProp} from './processTypeForProp'\nimport {Schema} from '@orion-js/schema'\n\n// @ts-ignore polyfill for Symbol.metadata // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#decorator-metadata\nSymbol.metadata ??= Symbol('Symbol.metadata')\n\nexport function getModelForClass(target: any): Model {\n const targetAsModel = target as any as Model\n if (targetAsModel.__isModel) {\n return targetAsModel\n }\n\n const metadata = target[Symbol.metadata] as SchemaFromTypedSchemaMetadata\n\n if (!metadata) {\n return targetAsModel\n }\n\n return internal_getModelForClassFromMetadata(metadata)\n}\n\nexport function internal_getModelForClassFromMetadata(metadata: SchemaFromTypedSchemaMetadata) {\n const modelName = metadata._modelName\n\n const schema: Schema = {}\n const keys = Object.keys(metadata ?? {})\n const injectionKeys = keys.filter(key => key.startsWith('_prop:'))\n\n for (const key of injectionKeys) {\n const prop = metadata[key] as Schema\n const schemaProp = key.replace('_prop:', '')\n\n schema[schemaProp] = {\n ...prop,\n type: getParamTypeForProp(prop.type as any),\n }\n }\n\n const model = createModel({\n ...metadata._modelOptions,\n name: modelName,\n schema,\n })\n\n return model\n}\n","import {isType} from 'rambdax'\nimport {PropOptions} from '../decorators/prop'\n\nexport function getParamTypeForProp(type: PropOptions['type']) {\n if (Array.isArray(type)) {\n const itemType = type[0]\n return [getParamTypeForProp(itemType)]\n }\n\n if (type?.[Symbol.metadata]?._getModel) {\n return type[Symbol.metadata]._getModel(type)\n }\n\n const objectType = type as Record<PropertyKey, any>\n\n if (objectType?.getSchema) {\n return getParamTypeForProp(objectType.getSchema())\n }\n\n if (isType('Object', type)) {\n if (objectType.__isFieldType) {\n return type\n }\n\n const subschema = {}\n for (const key of Object.keys(objectType)) {\n if (key.startsWith('__')) {\n subschema[key] = objectType[key]\n continue\n }\n\n subschema[key] = {\n ...objectType[key],\n type: getParamTypeForProp(objectType[key].type),\n }\n }\n\n return subschema\n }\n\n return type\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {Schema} from '@orion-js/schema'\nimport {getModelForClass} from './getModelForClass'\n\nexport function getSchemaForClass(target: any): Schema {\n return getModelForClass(target).getSchema()\n}\n","import {CloneOptions} from '@orion-js/models'\nimport {Constructor} from '../utils/interfaces'\nimport {cloneSchema, getSchemaFromAnyOrionForm, Schema} from '@orion-js/schema'\n\nexport interface CloneSchemaClassOptions<\n TClass,\n TFields extends (keyof TClass)[] | undefined = undefined,\n> {\n name: string\n pickFields?: TFields\n mapFields?: CloneOptions['mapFields']\n extendSchema?: CloneOptions['extendSchema']\n}\n\n/**\n * @deprecated Use `cloneSchema` instead\n */\nexport function cloneSchemaClass<TClass, TFields extends (keyof TClass)[] | undefined = undefined>(\n inputType: Constructor<TClass>,\n options: CloneSchemaClassOptions<TClass, TFields>,\n): Schema & {\n __tsFieldType: TFields extends undefined ? TClass : Pick<TClass, TFields[number]>\n} {\n const schema = getSchemaFromAnyOrionForm(inputType) as Schema\n\n const newSchema = cloneSchema({\n schema,\n name: options.name,\n pickFields: options.pickFields as any as string[],\n mapFields: options.mapFields,\n extendSchema: options.extendSchema,\n })\n\n return newSchema as any\n}\n","import {omit} from 'rambdax'\nimport {internal_getModelForClassFromMetadata} from '../factories'\nimport {TypedSchemaOptions} from '../storage/metadataStorage'\nimport {Model} from '@orion-js/models'\nimport {PropOptions} from './prop'\n\n/**\n * @deprecated use schema with InferSchemaType<schema as const> instead\n */\nexport function TypedSchema(options: TypedSchemaOptions = {}) {\n return (_target: any, context: ClassDecoratorContext<any>) => {\n context.metadata._isTypedSchema = true\n context.metadata._modelName = options.name || context.name\n context.metadata._modelOptions = omit('name', options)\n context.metadata._getModel = () => {\n return internal_getModelForClassFromMetadata(\n context.metadata as SchemaFromTypedSchemaMetadata,\n )\n }\n }\n}\n\nexport type SchemaFromTypedSchemaMetadata = {\n _isTypedSchema: true\n _modelName: string\n _modelOptions: TypedSchemaOptions\n _getModel: () => Model\n [key: `_prop:${string}`]: PropOptions\n}\n","export class CannotDetermineTypeError extends Error {\n constructor(propertyKey: string) {\n super(\n `Cannot determine type at @Prop() \"${propertyKey}\". type: is required for all props since Orion v4`,\n )\n }\n}\n","import {Constructor, SchemaFieldType, SchemaNode} from '@orion-js/schema'\nimport {Model} from '@orion-js/models'\nimport {CannotDetermineTypeError} from '../errors/CannotDetermineType'\n\nexport interface PropOptions extends Omit<SchemaNode, 'type'> {\n type: SchemaFieldType | Constructor<any> | Model | Model[]\n}\n\n/**\n * @deprecated use schema with InferSchemaType<schema as const> instead\n */\nexport function Prop(options: PropOptions) {\n return (_target: any, context: ClassFieldDecoratorContext) => {\n const propertyKey = String(context.name)\n\n if (!options?.type) {\n throw new CannotDetermineTypeError(propertyKey)\n }\n\n context.metadata[`_prop:${propertyKey}`] = options\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,KAAK,OAAM;AACzB,MAAI,UAAU,MAAK;AACjB,WAAO;AAAA,EACT,WAAW,UAAU,QAAU;AAC7B,WAAO;AAAA,EACT,WAAW,OAAO,MAAM,KAAK,GAAE;AAC7B,WAAO;AAAA,EACT;AACA,QAAM,aAAa,OAAO,UAAU,SAAS,KAAK,KAAK,EAAE,MAAM,GAAG,EAAE;AAEpE,SAAO,eAAe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omit<CreateModelOptions, 'schema'>>;
|
|
5
|
-
|
|
6
|
-
interface PropOptions extends Omit<SchemaNode, 'type'> {
|
|
7
|
-
type: SchemaFieldType | Constructor$1<any> | Model | Model[];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated use schema with InferSchemaType<schema as const> instead
|
|
11
|
-
*/
|
|
12
|
-
declare function Prop(options: PropOptions): (_target: any, context: ClassFieldDecoratorContext) => void;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated use schema with InferSchemaType<schema as const> instead
|
|
16
|
-
*/
|
|
17
|
-
declare function TypedSchema(options?: TypedSchemaOptions): (_target: any, context: ClassDecoratorContext<any>) => void;
|
|
18
|
-
type SchemaFromTypedSchemaMetadata = {
|
|
19
|
-
_isTypedSchema: true;
|
|
20
|
-
_modelName: string;
|
|
21
|
-
_modelOptions: TypedSchemaOptions;
|
|
22
|
-
_getModel: () => Model;
|
|
23
|
-
[key: `_prop:${string}`]: PropOptions;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
declare function getSchemaForClass(target: any): Schema;
|
|
27
|
-
|
|
28
|
-
declare function getModelForClass(target: any): Model;
|
|
29
|
-
declare function internal_getModelForClassFromMetadata(metadata: SchemaFromTypedSchemaMetadata): Model<Schema>;
|
|
30
|
-
|
|
31
|
-
interface Constructor<T> extends Function {
|
|
32
|
-
new (...args: unknown[]): T;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface CloneSchemaClassOptions<TClass, TFields extends (keyof TClass)[] | undefined = undefined> {
|
|
36
|
-
name: string;
|
|
37
|
-
pickFields?: TFields;
|
|
38
|
-
mapFields?: CloneOptions['mapFields'];
|
|
39
|
-
extendSchema?: CloneOptions['extendSchema'];
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @deprecated Use `cloneSchema` instead
|
|
43
|
-
*/
|
|
44
|
-
declare function cloneSchemaClass<TClass, TFields extends (keyof TClass)[] | undefined = undefined>(inputType: Constructor<TClass>, options: CloneSchemaClassOptions<TClass, TFields>): Schema & {
|
|
45
|
-
__tsFieldType: TFields extends undefined ? TClass : Pick<TClass, TFields[number]>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export { type CloneSchemaClassOptions, Prop, type PropOptions, type SchemaFromTypedSchemaMetadata, TypedSchema, cloneSchemaClass, getModelForClass, getSchemaForClass, internal_getModelForClassFromMetadata };
|
|
1
|
+
export * from './decorators';
|
|
2
|
+
export * from './factories';
|
package/dist/index.js
CHANGED
|
@@ -71,24 +71,25 @@ function getParamTypeForProp(type2) {
|
|
|
71
71
|
if ((_a = type2 == null ? void 0 : type2[Symbol.metadata]) == null ? void 0 : _a._getModel) {
|
|
72
72
|
return type2[Symbol.metadata]._getModel(type2);
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const objectType = type2;
|
|
75
|
+
if (objectType == null ? void 0 : objectType.getSchema) {
|
|
76
|
+
return getParamTypeForProp(objectType.getSchema());
|
|
76
77
|
}
|
|
77
78
|
if (isType("Object", type2)) {
|
|
78
|
-
if (
|
|
79
|
+
if (objectType.__isFieldType) {
|
|
79
80
|
return type2;
|
|
80
81
|
}
|
|
81
82
|
const subschema = {};
|
|
82
|
-
Object.keys(
|
|
83
|
+
for (const key of Object.keys(objectType)) {
|
|
83
84
|
if (key.startsWith("__")) {
|
|
84
|
-
subschema[key] =
|
|
85
|
-
|
|
85
|
+
subschema[key] = objectType[key];
|
|
86
|
+
continue;
|
|
86
87
|
}
|
|
87
88
|
subschema[key] = {
|
|
88
|
-
...
|
|
89
|
-
type: getParamTypeForProp(
|
|
89
|
+
...objectType[key],
|
|
90
|
+
type: getParamTypeForProp(objectType[key].type)
|
|
90
91
|
};
|
|
91
|
-
}
|
|
92
|
+
}
|
|
92
93
|
return subschema;
|
|
93
94
|
}
|
|
94
95
|
return type2;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/type.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/isType.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/omit.js","../src/factories/getModelForClass.ts","../src/factories/processTypeForProp.ts","../src/factories/getSchemaForClass.ts","../src/factories/cloneSchemaClass.ts","../src/decorators/typedSchema.ts","../src/errors/CannotDetermineType.ts","../src/decorators/prop.ts"],"sourcesContent":["export function type(input){\n if (input === null){\n return 'Null'\n } else if (input === undefined){\n return 'Undefined'\n } else if (Number.isNaN(input)){\n return 'NaN'\n }\n const typeResult = Object.prototype.toString.call(input).slice(8, -1)\n\n return typeResult === 'AsyncFunction' ? 'Promise' : typeResult\n}\n","function _isInteger(n){\n return n << 0 === n\n}\n\nexport const isInteger = Number.isInteger || _isInteger\n\n/**\n * Check if `index` is integer even if it is a string.\n */\nexport const isIndexInteger = index => Number.isInteger(Number(index))\n","import { isInteger } from './isInteger.js'\n\nexport function createPath(path, delimiter = '.'){\n return typeof path === 'string' ?\n path.split(delimiter).map(x => isInteger(x) ? Number(x) : x) :\n path\n}\n","import { type } from './type.js'\n\nexport function isType(xType, x){\n if (arguments.length === 1){\n return xHolder => isType(xType, xHolder)\n }\n\n return type(x) === xType\n}\n","export function compare(a, b){\n return String(a) === String(b)\n}\n","import { compare } from './compare.js'\n\nexport function includes(a, list){\n let index = -1\n const { length } = list\n\n while (++index < length)\n if (compare(list[ index ], a))\n return true\n\n return false\n}\n","import { createPath } from './_internals/createPath.js'\nimport { includes } from './_internals/includes.js'\n\nexport function omit(propsToOmit, obj){\n if (arguments.length === 1) return _obj => omit(propsToOmit, _obj)\n\n if (obj === null || obj === undefined)\n return undefined\n\n const propsToOmitValue = createPath(propsToOmit, ',')\n const willReturn = {}\n\n for (const key in obj)\n if (!includes(key, propsToOmitValue))\n willReturn[ key ] = obj[ key ]\n\n return willReturn\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {createModel, Model} from '@orion-js/models'\nimport {SchemaFromTypedSchemaMetadata} from '..'\nimport {getParamTypeForProp} from './processTypeForProp'\nimport {Schema} from '@orion-js/schema'\n\n// @ts-ignore polyfill for Symbol.metadata // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#decorator-metadata\nSymbol.metadata ??= Symbol('Symbol.metadata')\n\nexport function getModelForClass(target: any): Model {\n const targetAsModel = target as any as Model\n if (targetAsModel.__isModel) {\n return targetAsModel\n }\n\n const metadata = target[Symbol.metadata] as SchemaFromTypedSchemaMetadata\n\n if (!metadata) {\n return targetAsModel\n }\n\n return internal_getModelForClassFromMetadata(metadata)\n}\n\nexport function internal_getModelForClassFromMetadata(metadata: SchemaFromTypedSchemaMetadata) {\n const modelName = metadata._modelName\n\n const schema: Schema = {}\n const keys = Object.keys(metadata ?? {})\n const injectionKeys = keys.filter(key => key.startsWith('_prop:'))\n\n for (const key of injectionKeys) {\n const prop = metadata[key] as Schema\n const schemaProp = key.replace('_prop:', '')\n\n schema[schemaProp] = {\n ...prop,\n type: getParamTypeForProp(prop.type as any),\n }\n }\n\n const model = createModel({\n ...metadata._modelOptions,\n name: modelName,\n schema,\n })\n\n return model\n}\n","import {isType} from 'rambdax'\nimport {PropOptions} from '../decorators/prop'\n\nexport function getParamTypeForProp(type: PropOptions['type']) {\n if (Array.isArray(type)) {\n const itemType = type[0]\n return [getParamTypeForProp(itemType)]\n }\n\n if (type?.[Symbol.metadata]?._getModel) {\n return type[Symbol.metadata]._getModel(type)\n }\n\n if (type?.getSchema) {\n return getParamTypeForProp(type.getSchema())\n }\n\n if (isType('Object', type)) {\n if (type.__isFieldType) {\n return type\n }\n\n const subschema = {}\n Object.keys(type).forEach(key => {\n if (key.startsWith('__')) {\n subschema[key] = type[key]\n return\n }\n\n subschema[key] = {\n ...type[key],\n type: getParamTypeForProp(type[key].type),\n }\n })\n\n return subschema\n }\n\n return type\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {Schema} from '@orion-js/schema'\nimport {getModelForClass} from './getModelForClass'\n\nexport function getSchemaForClass(target: any): Schema {\n return getModelForClass(target).getSchema()\n}\n","import {CloneOptions} from '@orion-js/models'\nimport {Constructor} from '../utils/interfaces'\nimport {cloneSchema, getSchemaFromAnyOrionForm, Schema} from '@orion-js/schema'\n\nexport interface CloneSchemaClassOptions<\n TClass,\n TFields extends (keyof TClass)[] | undefined = undefined,\n> {\n name: string\n pickFields?: TFields\n mapFields?: CloneOptions['mapFields']\n extendSchema?: CloneOptions['extendSchema']\n}\n\n/**\n * @deprecated Use `cloneSchema` instead\n */\nexport function cloneSchemaClass<TClass, TFields extends (keyof TClass)[] | undefined = undefined>(\n inputType: Constructor<TClass>,\n options: CloneSchemaClassOptions<TClass, TFields>,\n): Schema & {\n __tsFieldType: TFields extends undefined ? TClass : Pick<TClass, TFields[number]>\n} {\n const schema = getSchemaFromAnyOrionForm(inputType) as Schema\n\n const newSchema = cloneSchema({\n schema,\n name: options.name,\n pickFields: options.pickFields as any as string[],\n mapFields: options.mapFields,\n extendSchema: options.extendSchema,\n })\n\n return newSchema as any\n}\n","import {omit} from 'rambdax'\nimport {internal_getModelForClassFromMetadata} from '../factories'\nimport {TypedSchemaOptions} from '../storage/metadataStorage'\nimport {Model} from '@orion-js/models'\nimport {PropOptions} from './prop'\n\n/**\n * @deprecated use schema with InferSchemaType<schema as const> instead\n */\nexport function TypedSchema(options: TypedSchemaOptions = {}) {\n return (_target: any, context: ClassDecoratorContext<any>) => {\n context.metadata._isTypedSchema = true\n context.metadata._modelName = options.name || context.name\n context.metadata._modelOptions = omit('name', options)\n context.metadata._getModel = () => {\n return internal_getModelForClassFromMetadata(\n context.metadata as SchemaFromTypedSchemaMetadata,\n )\n }\n }\n}\n\nexport type SchemaFromTypedSchemaMetadata = {\n _isTypedSchema: true\n _modelName: string\n _modelOptions: TypedSchemaOptions\n _getModel: () => Model\n [key: `_prop:${string}`]: PropOptions\n}\n","export class CannotDetermineTypeError extends Error {\n constructor(propertyKey: string) {\n super(\n `Cannot determine type at @Prop() \"${propertyKey}\". type: is required for all props since Orion v4`,\n )\n }\n}\n","import {Constructor, SchemaFieldType, SchemaNode} from '@orion-js/schema'\nimport {Model} from '@orion-js/models'\nimport {CannotDetermineTypeError} from '../errors/CannotDetermineType'\n\nexport interface PropOptions extends Omit<SchemaNode, 'type'> {\n type: SchemaFieldType | Constructor<any> | Model | Model[]\n}\n\n/**\n * @deprecated use schema with InferSchemaType<schema as const> instead\n */\nexport function Prop(options: PropOptions) {\n return (_target: any, context: ClassFieldDecoratorContext) => {\n const propertyKey = String(context.name)\n\n if (!options?.type) {\n throw new CannotDetermineTypeError(propertyKey)\n }\n\n context.metadata[`_prop:${propertyKey}`] = options\n }\n}\n"],"mappings":";AAAO,SAAS,KAAK,OAAM;AACzB,MAAI,UAAU,MAAK;AACjB,WAAO;AAAA,EACT,WAAW,UAAU,QAAU;AAC7B,WAAO;AAAA,EACT,WAAW,OAAO,MAAM,KAAK,GAAE;AAC7B,WAAO;AAAA,EACT;AACA,QAAM,aAAa,OAAO,UAAU,SAAS,KAAK,KAAK,EAAE,MAAM,GAAG,EAAE;AAEpE,SAAO,eAAe,kBAAkB,YAAY;AACtD;;;ACXA,SAAS,WAAW,GAAE;AACpB,SAAO,KAAK,MAAM;AACpB;AAEO,IAAM,YAAY,OAAO,aAAa;;;ACFtC,SAAS,WAAW,MAAM,YAAY,KAAI;AAC/C,SAAO,OAAO,SAAS,WACrB,KAAK,MAAM,SAAS,EAAE,IAAI,OAAK,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAC3D;AACJ;;;ACJO,SAAS,OAAO,OAAO,GAAE;AA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;AAElD,QAAM,YAAY,YAAY;AAAA,IAC5B;AAAA,IACA,MAAM,QAAQ;AAAA,IACd,YAAY,QAAQ;AAAA,IACpB,WAAW,QAAQ;AAAA,IACnB,cAAc,QAAQ;AAAA,EACxB,CAAC;AAED,SAAO;AACT;;;ACzBO,SAAS,YAAY,UAA8B,CAAC,GAAG;AAC5D,SAAO,CAAC,SAAc,YAAwC;AAC5D,YAAQ,SAAS,iBAAiB;AAClC,YAAQ,SAAS,aAAa,QAAQ,QAAQ,QAAQ;AACtD,YAAQ,SAAS,gBAAgB,KAAK,QAAQ,OAAO;AACrD,YAAQ,SAAS,YAAY,MAAM;AACjC,aAAO;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;;;ACpBO,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAClD,YAAY,aAAqB;AAC/B;AAAA,MACE,qCAAqC,WAAW;AAAA,IAClD;AAAA,EACF;AACF;;;ACKO,SAAS,KAAK,SAAsB;AACzC,SAAO,CAAC,SAAc,YAAwC;AAC5D,UAAM,cAAc,OAAO,QAAQ,IAAI;AAEvC,QAAI,EAAC,mCAAS,OAAM;AAClB,YAAM,IAAI,yBAAyB,WAAW;AAAA,IAChD;AAEA,YAAQ,SAAS,SAAS,WAAW,EAAE,IAAI;AAAA,EAC7C;AACF;","names":["type"]}
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/type.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/isType.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js","../../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/omit.js","../src/factories/getModelForClass.ts","../src/factories/processTypeForProp.ts","../src/factories/getSchemaForClass.ts","../src/factories/cloneSchemaClass.ts","../src/decorators/typedSchema.ts","../src/errors/CannotDetermineType.ts","../src/decorators/prop.ts"],"sourcesContent":["export function type(input){\n if (input === null){\n return 'Null'\n } else if (input === undefined){\n return 'Undefined'\n } else if (Number.isNaN(input)){\n return 'NaN'\n }\n const typeResult = Object.prototype.toString.call(input).slice(8, -1)\n\n return typeResult === 'AsyncFunction' ? 'Promise' : typeResult\n}\n","function _isInteger(n){\n return n << 0 === n\n}\n\nexport const isInteger = Number.isInteger || _isInteger\n\n/**\n * Check if `index` is integer even if it is a string.\n */\nexport const isIndexInteger = index => Number.isInteger(Number(index))\n","import { isInteger } from './isInteger.js'\n\nexport function createPath(path, delimiter = '.'){\n return typeof path === 'string' ?\n path.split(delimiter).map(x => isInteger(x) ? Number(x) : x) :\n path\n}\n","import { type } from './type.js'\n\nexport function isType(xType, x){\n if (arguments.length === 1){\n return xHolder => isType(xType, xHolder)\n }\n\n return type(x) === xType\n}\n","export function compare(a, b){\n return String(a) === String(b)\n}\n","import { compare } from './compare.js'\n\nexport function includes(a, list){\n let index = -1\n const { length } = list\n\n while (++index < length)\n if (compare(list[ index ], a))\n return true\n\n return false\n}\n","import { createPath } from './_internals/createPath.js'\nimport { includes } from './_internals/includes.js'\n\nexport function omit(propsToOmit, obj){\n if (arguments.length === 1) return _obj => omit(propsToOmit, _obj)\n\n if (obj === null || obj === undefined)\n return undefined\n\n const propsToOmitValue = createPath(propsToOmit, ',')\n const willReturn = {}\n\n for (const key in obj)\n if (!includes(key, propsToOmitValue))\n willReturn[ key ] = obj[ key ]\n\n return willReturn\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {createModel, Model} from '@orion-js/models'\nimport {SchemaFromTypedSchemaMetadata} from '..'\nimport {getParamTypeForProp} from './processTypeForProp'\nimport {Schema} from '@orion-js/schema'\n\n// @ts-ignore polyfill for Symbol.metadata // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#decorator-metadata\nSymbol.metadata ??= Symbol('Symbol.metadata')\n\nexport function getModelForClass(target: any): Model {\n const targetAsModel = target as any as Model\n if (targetAsModel.__isModel) {\n return targetAsModel\n }\n\n const metadata = target[Symbol.metadata] as SchemaFromTypedSchemaMetadata\n\n if (!metadata) {\n return targetAsModel\n }\n\n return internal_getModelForClassFromMetadata(metadata)\n}\n\nexport function internal_getModelForClassFromMetadata(metadata: SchemaFromTypedSchemaMetadata) {\n const modelName = metadata._modelName\n\n const schema: Schema = {}\n const keys = Object.keys(metadata ?? {})\n const injectionKeys = keys.filter(key => key.startsWith('_prop:'))\n\n for (const key of injectionKeys) {\n const prop = metadata[key] as Schema\n const schemaProp = key.replace('_prop:', '')\n\n schema[schemaProp] = {\n ...prop,\n type: getParamTypeForProp(prop.type as any),\n }\n }\n\n const model = createModel({\n ...metadata._modelOptions,\n name: modelName,\n schema,\n })\n\n return model\n}\n","import {isType} from 'rambdax'\nimport {PropOptions} from '../decorators/prop'\n\nexport function getParamTypeForProp(type: PropOptions['type']) {\n if (Array.isArray(type)) {\n const itemType = type[0]\n return [getParamTypeForProp(itemType)]\n }\n\n if (type?.[Symbol.metadata]?._getModel) {\n return type[Symbol.metadata]._getModel(type)\n }\n\n const objectType = type as Record<PropertyKey, any>\n\n if (objectType?.getSchema) {\n return getParamTypeForProp(objectType.getSchema())\n }\n\n if (isType('Object', type)) {\n if (objectType.__isFieldType) {\n return type\n }\n\n const subschema = {}\n for (const key of Object.keys(objectType)) {\n if (key.startsWith('__')) {\n subschema[key] = objectType[key]\n continue\n }\n\n subschema[key] = {\n ...objectType[key],\n type: getParamTypeForProp(objectType[key].type),\n }\n }\n\n return subschema\n }\n\n return type\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {Schema} from '@orion-js/schema'\nimport {getModelForClass} from './getModelForClass'\n\nexport function getSchemaForClass(target: any): Schema {\n return getModelForClass(target).getSchema()\n}\n","import {CloneOptions} from '@orion-js/models'\nimport {Constructor} from '../utils/interfaces'\nimport {cloneSchema, getSchemaFromAnyOrionForm, Schema} from '@orion-js/schema'\n\nexport interface CloneSchemaClassOptions<\n TClass,\n TFields extends (keyof TClass)[] | undefined = undefined,\n> {\n name: string\n pickFields?: TFields\n mapFields?: CloneOptions['mapFields']\n extendSchema?: CloneOptions['extendSchema']\n}\n\n/**\n * @deprecated Use `cloneSchema` instead\n */\nexport function cloneSchemaClass<TClass, TFields extends (keyof TClass)[] | undefined = undefined>(\n inputType: Constructor<TClass>,\n options: CloneSchemaClassOptions<TClass, TFields>,\n): Schema & {\n __tsFieldType: TFields extends undefined ? TClass : Pick<TClass, TFields[number]>\n} {\n const schema = getSchemaFromAnyOrionForm(inputType) as Schema\n\n const newSchema = cloneSchema({\n schema,\n name: options.name,\n pickFields: options.pickFields as any as string[],\n mapFields: options.mapFields,\n extendSchema: options.extendSchema,\n })\n\n return newSchema as any\n}\n","import {omit} from 'rambdax'\nimport {internal_getModelForClassFromMetadata} from '../factories'\nimport {TypedSchemaOptions} from '../storage/metadataStorage'\nimport {Model} from '@orion-js/models'\nimport {PropOptions} from './prop'\n\n/**\n * @deprecated use schema with InferSchemaType<schema as const> instead\n */\nexport function TypedSchema(options: TypedSchemaOptions = {}) {\n return (_target: any, context: ClassDecoratorContext<any>) => {\n context.metadata._isTypedSchema = true\n context.metadata._modelName = options.name || context.name\n context.metadata._modelOptions = omit('name', options)\n context.metadata._getModel = () => {\n return internal_getModelForClassFromMetadata(\n context.metadata as SchemaFromTypedSchemaMetadata,\n )\n }\n }\n}\n\nexport type SchemaFromTypedSchemaMetadata = {\n _isTypedSchema: true\n _modelName: string\n _modelOptions: TypedSchemaOptions\n _getModel: () => Model\n [key: `_prop:${string}`]: PropOptions\n}\n","export class CannotDetermineTypeError extends Error {\n constructor(propertyKey: string) {\n super(\n `Cannot determine type at @Prop() \"${propertyKey}\". type: is required for all props since Orion v4`,\n )\n }\n}\n","import {Constructor, SchemaFieldType, SchemaNode} from '@orion-js/schema'\nimport {Model} from '@orion-js/models'\nimport {CannotDetermineTypeError} from '../errors/CannotDetermineType'\n\nexport interface PropOptions extends Omit<SchemaNode, 'type'> {\n type: SchemaFieldType | Constructor<any> | Model | Model[]\n}\n\n/**\n * @deprecated use schema with InferSchemaType<schema as const> instead\n */\nexport function Prop(options: PropOptions) {\n return (_target: any, context: ClassFieldDecoratorContext) => {\n const propertyKey = String(context.name)\n\n if (!options?.type) {\n throw new CannotDetermineTypeError(propertyKey)\n }\n\n context.metadata[`_prop:${propertyKey}`] = options\n }\n}\n"],"mappings":";AAAO,SAAS,KAAK,OAAM;AACzB,MAAI,UAAU,MAAK;AACjB,WAAO;AAAA,EACT,WAAW,UAAU,QAAU;AAC7B,WAAO;AAAA,EACT,WAAW,OAAO,MAAM,KAAK,GAAE;AAC7B,WAAO;AAAA,EACT;AACA,QAAM,aAAa,OAAO,UAAU,SAAS,KAAK,KAAK,EAAE,MAAM,GAAG,EAAE;AAEpE,SAAO,eAAe,kBAAkB,YAAY;AACtD;;;ACXA,SAAS,WAAW,GAAE;AACpB,SAAO,KAAK,MAAM;AACpB;AAEO,IAAM,YAAY,OAAO,aAAa;;;ACFtC,SAAS,WAAW,MAAM,YAAY,KAAI;AAC/C,SAAO,OAAO,SAAS,WACrB,KAAK,MAAM,SAAS,EAAE,IAAI,OAAK,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAC3D;AACJ;;;ACJO,SAAS,OAAO,OAAO,GAAE;AAC9B,MAAI,UAAU,WAAW,GAAE;AACzB,WAAO,aAAW,OAAO,OAAO,OAAO;AAAA,EACzC;AAEA,SAAO,KAAK,CAAC,MAAM;AACrB;;;ACRO,SAAS,QAAQ,GAAG,GAAE;AAC3B,SAAO,OAAO,CAAC,MAAM,OAAO,CAAC;AAC/B;;;ACAO,SAAS,SAAS,GAAG,MAAK;AAC/B,MAAI,QAAQ;AACZ,QAAM,EAAE,OAAO,IAAI;AAEnB,SAAO,EAAE,QAAQ;AACf,QAAI,QAA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AQ,SAAS,gBAAgB,KAAK,QAAQ,OAAO;AACrD,YAAQ,SAAS,YAAY,MAAM;AACjC,aAAO;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;;;ACpBO,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAClD,YAAY,aAAqB;AAC/B;AAAA,MACE,qCAAqC,WAAW;AAAA,IAClD;AAAA,EACF;AACF;;;ACKO,SAAS,KAAK,SAAsB;AACzC,SAAO,CAAC,SAAc,YAAwC;AAC5D,UAAM,cAAc,OAAO,QAAQ,IAAI;AAEvC,QAAI,EAAC,mCAAS,OAAM;AAClB,YAAM,IAAI,yBAAyB,WAAW;AAAA,IAChD;AAEA,YAAQ,SAAS,SAAS,WAAW,EAAE,IAAI;AAAA,EAC7C;AACF;","names":["type"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/typed-model",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -15,29 +15,28 @@
|
|
|
15
15
|
],
|
|
16
16
|
"author": "dmerrill6",
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"scripts": {
|
|
19
|
-
"test": "bun test",
|
|
20
|
-
"prepare": "bun run build",
|
|
21
|
-
"clean": "rm -rf ./dist",
|
|
22
|
-
"build": "tsup",
|
|
23
|
-
"dev": "tsup --watch"
|
|
24
|
-
},
|
|
25
18
|
"dependencies": {
|
|
26
|
-
"@orion-js/models": "4.
|
|
27
|
-
"@orion-js/resolvers": "4.
|
|
28
|
-
"@orion-js/schema": "4.
|
|
29
|
-
"@orion-js/services": "4.
|
|
19
|
+
"@orion-js/models": "4.4.0",
|
|
20
|
+
"@orion-js/resolvers": "4.4.0",
|
|
21
|
+
"@orion-js/schema": "4.4.0",
|
|
22
|
+
"@orion-js/services": "4.4.0"
|
|
30
23
|
},
|
|
31
24
|
"peerDependencies": {
|
|
32
|
-
"@orion-js/logger": "4.
|
|
25
|
+
"@orion-js/logger": "4.4.0"
|
|
33
26
|
},
|
|
34
27
|
"devDependencies": {
|
|
35
28
|
"@types/node": "^18.0.0",
|
|
36
|
-
"typescript": "^
|
|
29
|
+
"typescript": "^7.0.2",
|
|
37
30
|
"tsup": "^8.0.1"
|
|
38
31
|
},
|
|
39
32
|
"publishConfig": {
|
|
40
33
|
"access": "public"
|
|
41
34
|
},
|
|
42
|
-
"gitHead": "a485b1fe6a1840ee6cb58fd69d6de62585f1ed10"
|
|
43
|
-
|
|
35
|
+
"gitHead": "a485b1fe6a1840ee6cb58fd69d6de62585f1ed10",
|
|
36
|
+
"scripts": {
|
|
37
|
+
"test": "bun test",
|
|
38
|
+
"clean": "rm -rf ./dist",
|
|
39
|
+
"build": "tsup && bun run ../../scripts/emit-declarations.ts",
|
|
40
|
+
"dev": "tsup --watch"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/index.d.cts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { CreateModelOptions, Model, CloneOptions } from '@orion-js/models';
|
|
2
|
-
import { SchemaNode, SchemaFieldType, Constructor as Constructor$1, Schema } from '@orion-js/schema';
|
|
3
|
-
|
|
4
|
-
type TypedSchemaOptions = Partial<Omit<CreateModelOptions, 'schema'>>;
|
|
5
|
-
|
|
6
|
-
interface PropOptions extends Omit<SchemaNode, 'type'> {
|
|
7
|
-
type: SchemaFieldType | Constructor$1<any> | Model | Model[];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated use schema with InferSchemaType<schema as const> instead
|
|
11
|
-
*/
|
|
12
|
-
declare function Prop(options: PropOptions): (_target: any, context: ClassFieldDecoratorContext) => void;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated use schema with InferSchemaType<schema as const> instead
|
|
16
|
-
*/
|
|
17
|
-
declare function TypedSchema(options?: TypedSchemaOptions): (_target: any, context: ClassDecoratorContext<any>) => void;
|
|
18
|
-
type SchemaFromTypedSchemaMetadata = {
|
|
19
|
-
_isTypedSchema: true;
|
|
20
|
-
_modelName: string;
|
|
21
|
-
_modelOptions: TypedSchemaOptions;
|
|
22
|
-
_getModel: () => Model;
|
|
23
|
-
[key: `_prop:${string}`]: PropOptions;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
declare function getSchemaForClass(target: any): Schema;
|
|
27
|
-
|
|
28
|
-
declare function getModelForClass(target: any): Model;
|
|
29
|
-
declare function internal_getModelForClassFromMetadata(metadata: SchemaFromTypedSchemaMetadata): Model<Schema>;
|
|
30
|
-
|
|
31
|
-
interface Constructor<T> extends Function {
|
|
32
|
-
new (...args: unknown[]): T;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface CloneSchemaClassOptions<TClass, TFields extends (keyof TClass)[] | undefined = undefined> {
|
|
36
|
-
name: string;
|
|
37
|
-
pickFields?: TFields;
|
|
38
|
-
mapFields?: CloneOptions['mapFields'];
|
|
39
|
-
extendSchema?: CloneOptions['extendSchema'];
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @deprecated Use `cloneSchema` instead
|
|
43
|
-
*/
|
|
44
|
-
declare function cloneSchemaClass<TClass, TFields extends (keyof TClass)[] | undefined = undefined>(inputType: Constructor<TClass>, options: CloneSchemaClassOptions<TClass, TFields>): Schema & {
|
|
45
|
-
__tsFieldType: TFields extends undefined ? TClass : Pick<TClass, TFields[number]>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export { type CloneSchemaClassOptions, Prop, type PropOptions, type SchemaFromTypedSchemaMetadata, TypedSchema, cloneSchemaClass, getModelForClass, getSchemaForClass, internal_getModelForClassFromMetadata };
|