Reflect.getMetadata is not a function

这段代码展示了如何在Node.js中导入'class-transformer'库,将接收到的JSON请求体转换为GwStatusLogDto类型的对象,以便进行数据处理。通过调用'plainToClass'函数,将JSON对象转换为类实例。
import { plainToClass } from 'class-transformer'

let bodyParams: GwStatusLogDto;
const jsonBody: any = JSON.parse(req.body);

bodyParams = plainToClass(GwStatusLogDto, jsonBody);

添加引用

import 'reflect-metadata'

将下面reflect-metadata源码改成好理解的代码,并且在文件上方屏蔽eslint校验:let Reflect; (function (Reflect) { // Metadata Proposal // https://rbuckton.github.io/reflect-metadata/ (function (factory) { let root = typeof globalThis === 'object' ? globalThis : typeof global === 'object' ? global : typeof self === 'object' ? self : typeof this === 'object' ? this : sloppyModeThis(); let exporter = makeExporter(Reflect); if (typeof root.Reflect !== 'undefined') { exporter = makeExporter(root.Reflect, exporter); } factory(exporter, root); if (typeof root.Reflect === 'undefined') { root.Reflect = Reflect; } function makeExporter(target, previous) { return function (key, value) { Object.defineProperty(target, key, { configurable: true, writable: true, value }); if (previous) { previous(key, value); } }; } function functionThis() { try { return Function('return this;')(); } catch (_) { } } function indirectEvalThis() { try { return (void 0, eval)('(function() { return this; })()'); } catch (_) { } } function sloppyModeThis() { return functionThis() || indirectEvalThis(); } })((exporter, root) => { let hasOwn = Object.prototype.hasOwnProperty; // feature test for Symbol support let supportsSymbol = typeof Symbol === 'function'; let toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== 'undefined' ? Symbol.toPrimitive : '@@toPrimitive'; let iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== 'undefined' ? Symbol.iterator : '@@iterator'; let supportsCreate = typeof Object.create === 'function'; // feature test for Object.create support let supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support let downLevel = !supportsCreate && !supportsProto; let HashMap = { // create an object in dictionary mode (a.k.a. "slow" mode in v8) create: supportsCreate ? function () { return MakeDictionary(Object.create(null)); } : supportsProto ? function () { return MakeDictionary({ __proto__: null }); } : function () { return MakeDictionary({}); }, has: downLevel ? function (map, key) { return hasOwn.call(map, key); } : function (map, key) { return key in map; }, get: downLevel ? function (map, key) { return hasOwn.call(map, key) ? map[key] : undefined; } : function (map, key) { return map[key]; }, }; // Load global or shim versions of Map, Set, and WeakMap let functionPrototype = Object.getPrototypeOf(Function); let _Map = typeof Map === 'function' && typeof Map.prototype.entries === 'function' ? Map : CreateMapPolyfill(); let _Set = typeof Set === 'function' && typeof Set.prototype.entries === 'function' ? Set : CreateSetPolyfill(); let _WeakMap = typeof WeakMap === 'function' ? WeakMap : CreateWeakMapPolyfill(); let registrySymbol = supportsSymbol ? Symbol.for('@reflect-metadata:registry') : undefined; let metadataRegistry = GetOrCreateMetadataRegistry(); let metadataProvider = CreateMetadataProvider(metadataRegistry); /** * Applies a set of decorators to a property of a target object. * @param decorators An array of decorators. * @param target The target object. * @param propertyKey (Optional) The property key to decorate. * @param attributes (Optional) The property descriptor for the target key. * @remarks Decorators are applied in reverse order. * @example * * class Example { * // property declarations are not part of ES6, though they are valid in TypeScript: * // static staticProperty; * // property; * * constructor(p) { } * static staticMethod(p) { } * method(p) { } * } * * // constructor * Example = Reflect.decorate(decoratorsArray, Example); * * // property (on constructor) * Reflect.decorate(decoratorsArray, Example, "staticProperty"); * * // property (on prototype) * Reflect.decorate(decoratorsArray, Example.prototype, "property"); * * // method (on constructor) * Object.defineProperty(Example, "staticMethod", * Reflect.decorate(decoratorsArray, Example, "staticMethod", * Object.getOwnPropertyDescriptor(Example, "staticMethod"))); * * // method (on prototype) * Object.defineProperty(Example.prototype, "method", * Reflect.decorate(decoratorsArray, Example.prototype, "method", * Object.getOwnPropertyDescriptor(Example.prototype, "method"))); * */ function decorate(decorators, target, propertyKey, attributes) { if (!IsUndefined(propertyKey)) { if (!IsArray(decorators)) { throw new TypeError(); } if (!IsObject(target)) { throw new TypeError(); } if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes)) { throw new TypeError(); } if (IsNull(attributes)) { attributes = undefined; } propertyKey = ToPropertyKey(propertyKey); return DecorateProperty(decorators, target, propertyKey, attributes); } else { if (!IsArray(decorators)) { throw new TypeError(); } if (!IsConstructor(target)) { throw new TypeError(); } return DecorateConstructor(decorators, target); } } exporter('decorate', decorate); // 4.1.2 Reflect.metadata(metadataKey, metadataValue) // https://rbuckton.github.io/reflect-metadata/#reflect.metadata /** * A default metadata decorator factory that can be used on a class, class member, or parameter. * @param metadataKey The key for the metadata entry. * @param metadataValue The value for the metadata entry. * @returns A decorator function. * @remarks * If `metadataKey` is already defined for the target and target key, the * metadataValue for that key will be overwritten. * @example * * // constructor * @Reflect.metadata(key, value) * class Example { * } * * // property (on constructor, TypeScript only) * class Example { * @Reflect.metadata(key, value) * static staticProperty; * } * * // property (on prototype, TypeScript only) * class Example { * @Reflect.metadata(key, value) * property; * } * * // method (on constructor) * class Example { * @Reflect.metadata(key, value) * static staticMethod() { } * } * * // method (on prototype) * class Example { * @Reflect.metadata(key, value) * method() { } * } * */ function metadata(metadataKey, metadataValue) { function decorator(target, propertyKey) { if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey)) { throw new TypeError(); } OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey); } return decorator; } exporter('metadata', metadata); /** * Define a unique metadata entry on the target. * @param metadataKey A key used to store and retrieve metadata. * @param metadataValue A value that contains attached metadata. * @param target The target object on which to define metadata. * @param propertyKey (Optional) The property key for the target. * @example * * class Example { * // property declarations are not part of ES6, though they are valid in TypeScript: * // static staticProperty; * // property; * * constructor(p) { } * static staticMethod(p) { } * method(p) { } * } * * // constructor * Reflect.defineMetadata("custom:annotation", options, Example); * * // property (on constructor) * Reflect.defineMetadata("custom:annotation", options, Example, "staticProperty"); * * // property (on prototype) * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "property"); * * // method (on constructor) * Reflect.defineMetadata("custom:annotation", options, Example, "staticMethod"); * * // method (on prototype) * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "method"); * * // decorator factory as metadata-producing annotation. * function MyAnnotation(options): Decorator { * return (target, key?) => Reflect.defineMetadata("custom:annotation", options, target, key); * } * */ function defineMetadata(metadataKey, metadataValue, target, propertyKey) { if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey)) { propertyKey = ToPropertyKey(propertyKey); } return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey); } exporter('defineMetadata', defineMetadata); /** * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. * @param propertyKey (Optional) The property key for the target. * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. * @example * * class Example { * // property declarations are not part of ES6, though they are valid in TypeScript: * // static staticProperty; * // property; * * constructor(p) { } * static staticMethod(p) { } * method(p) { } * } * * // constructor * result = Reflect.hasMetadata("custom:annotation", Example); * * // property (on constructor) * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty"); * * // property (on prototype) * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property"); * * // method (on constructor) * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod"); * * // method (on prototype) * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method"); * */ function hasMetadata(metadataKey, target, propertyKey) { if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey)) { propertyKey = ToPropertyKey(propertyKey); } return OrdinaryHasMetadata(metadataKey, target, propertyKey); } exporter('hasMetadata', hasMetadata); /** * Gets a value indicating whether the target object has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. * @param propertyKey (Optional) The property key for the target. * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. * @example * * class Example { * // property declarations are not part of ES6, though they are valid in TypeScript: * // static staticProperty; * // property; * * constructor(p) { } * static staticMethod(p) { } * method(p) { } * } * * // constructor * result = Reflect.hasOwnMetadata("custom:annotation", Example); * * // property (on constructor) * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty"); * * // property (on prototype) * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property"); * * // method (on constructor) * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod"); * * // method (on prototype) * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method"); * */ function hasOwnMetadata(metadataKey, target, propertyKey) { if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey)) { propertyKey = ToPropertyKey(propertyKey); } return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey); } exporter('hasOwnMetadata', hasOwnMetadata); /** * Gets the metadata value for the provided metadata key on the target object or its prototype chain. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. * @param propertyKey (Optional) The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * * class Example { * // property declarations are not part of ES6, though they are valid in TypeScript: * // static staticProperty; * // property; * * constructor(p) { } * static staticMethod(p) { } * method(p) { } * } * * // constructor * result = Reflect.getMetadata("custom:annotation", Example); * * // property (on constructor) * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty"); * * // property (on prototype) * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property"); * * // method (on constructor) * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod"); * * // method (on prototype) * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method"); * */ function getMetadata(metadataKey, target, propertyKey) { if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey)) { propertyKey = ToPropertyKey(propertyKey); } return OrdinaryGetMetadata(metadataKey, target, propertyKey); } exporter('getMetadata', getMetadata); /** * Gets the metadata value for the provided metadata key on the target object. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. * @param propertyKey (Optional) The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * * class Example { * // property declarations are not part of ES6, though they are valid in TypeScript: * // static staticProperty; * // property; * * constructor(p) { } * static staticMethod(p) { } * method(p) { } * } * * // constructor * result = Reflect.getOwnMetadata("custom:annotation", Example); * * // property (on constructor) * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty"); * * // property (on prototype) * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property"); * * // method (on constructor) * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod"); * * // method (on prototype) * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method"); * */ function getOwnMetadata(metadataKey, target, propertyKey) { if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey)) { propertyKey = ToPropertyKey(propertyKey); } return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey); } exporter('getOwnMetadata', getOwnMetadata); /** * Gets the metadata keys defined on the target object or its prototype chain. * @param target The target object on which the metadata is defined. * @param propertyKey (Optional) The property key for the target. * @returns An array of unique metadata keys. * @example * * class Example { * // property declarations are not part of ES6, though they are valid in TypeScript: * // static staticProperty; * // property; * * constructor(p) { } * static staticMethod(p) { } * method(p) { } * } * * // constructor * result = Reflect.getMetadataKeys(Example); * * // property (on constructor) * result = Reflect.getMetadataKeys(Example, "staticProperty"); * * // property (on prototype) * result = Reflect.getMetadataKeys(Example.prototype, "property"); * * // method (on constructor) * result = Reflect.getMetadataKeys(Example, "staticMethod"); * * // method (on prototype) * result = Reflect.getMetadataKeys(Example.prototype, "method"); * */ function getMetadataKeys(target, propertyKey) { if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey)) { propertyKey = ToPropertyKey(propertyKey); } return OrdinaryMetadataKeys(target, propertyKey); } exporter('getMetadataKeys', getMetadataKeys); /** * Gets the unique metadata keys defined on the target object. * @param target The target object on which the metadata is defined. * @param propertyKey (Optional) The property key for the target. * @returns An array of unique metadata keys. * @example * * class Example { * // property declarations are not part of ES6, though they are valid in TypeScript: * // static staticProperty; * // property; * * constructor(p) { } * static staticMethod(p) { } * method(p) { } * } * * // constructor * result = Reflect.getOwnMetadataKeys(Example); * * // property (on constructor) * result = Reflect.getOwnMetadataKeys(Example, "staticProperty"); * * // property (on prototype) * result = Reflect.getOwnMetadataKeys(Example.prototype, "property"); * * // method (on constructor) * result = Reflect.getOwnMetadataKeys(Example, "staticMethod"); * * // method (on prototype) * result = Reflect.getOwnMetadataKeys(Example.prototype, "method"); * */ function getOwnMetadataKeys(target, propertyKey) { if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey)) { propertyKey = ToPropertyKey(propertyKey); } return OrdinaryOwnMetadataKeys(target, propertyKey); } exporter('getOwnMetadataKeys', getOwnMetadataKeys); /** * Deletes the metadata entry from the target object with the provided key. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. * @param propertyKey (Optional) The property key for the target. * @returns `true` if the metadata entry was found and deleted; otherwise, false. * @example * * class Example { * // property declarations are not part of ES6, though they are valid in TypeScript: * // static staticProperty; * // property; * * constructor(p) { } * static staticMethod(p) { } * method(p) { } * } * * // constructor * result = Reflect.deleteMetadata("custom:annotation", Example); * * // property (on constructor) * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty"); * * // property (on prototype) * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property"); * * // method (on constructor) * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod"); * * // method (on prototype) * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method"); * */ function deleteMetadata(metadataKey, target, propertyKey) { if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey)) { propertyKey = ToPropertyKey(propertyKey); } if (!IsObject(target)) { throw new TypeError(); } if (!IsUndefined(propertyKey)) { propertyKey = ToPropertyKey(propertyKey); } let provider = GetMetadataProvider(target, propertyKey, /* Create*/ false); if (IsUndefined(provider)) { return false; } return provider.OrdinaryDeleteMetadata(metadataKey, target, propertyKey); } exporter('deleteMetadata', deleteMetadata); function DecorateConstructor(decorators, target) { for (let i = decorators.length - 1; i >= 0; --i) { let decorator = decorators[i]; let decorated = decorator(target); if (!IsUndefined(decorated) && !IsNull(decorated)) { if (!IsConstructor(decorated)) { throw new TypeError(); } target = decorated; } } return target; } function DecorateProperty(decorators, target, propertyKey, descriptor) { for (let i = decorators.length - 1; i >= 0; --i) { let decorator = decorators[i]; let decorated = decorator(target, propertyKey, descriptor); if (!IsUndefined(decorated) && !IsNull(decorated)) { if (!IsObject(decorated)) { throw new TypeError(); } descriptor = decorated; } } return descriptor; } // 3.1.1.1 OrdinaryHasMetadata(MetadataKey, O, P) // https://rbuckton.github.io/reflect-metadata/#ordinaryhasmetadata function OrdinaryHasMetadata(MetadataKey, O, P) { let hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P); if (hasOwn) { return true; } let parent = OrdinaryGetPrototypeOf(O); if (!IsNull(parent)) { return OrdinaryHasMetadata(MetadataKey, parent, P); } return false; } // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P) // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata function OrdinaryHasOwnMetadata(MetadataKey, O, P) { let provider = GetMetadataProvider(O, P, /* Create*/ false); if (IsUndefined(provider)) { return false; } return ToBoolean(provider.OrdinaryHasOwnMetadata(MetadataKey, O, P)); } // 3.1.3.1 OrdinaryGetMetadata(MetadataKey, O, P) // https://rbuckton.github.io/reflect-metadata/#ordinarygetmetadata function OrdinaryGetMetadata(MetadataKey, O, P) { let hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P); if (hasOwn) { return OrdinaryGetOwnMetadata(MetadataKey, O, P); } let parent = OrdinaryGetPrototypeOf(O); if (!IsNull(parent)) { return OrdinaryGetMetadata(MetadataKey, parent, P); } return undefined; } // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P) // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata function OrdinaryGetOwnMetadata(MetadataKey, O, P) { let provider = GetMetadataProvider(O, P, /* Create*/ false); if (IsUndefined(provider)) { return; } return provider.OrdinaryGetOwnMetadata(MetadataKey, O, P); } // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) { let provider = GetMetadataProvider(O, P, /* Create*/ true); provider.OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P); } // 3.1.6.1 OrdinaryMetadataKeys(O, P) // https://rbuckton.github.io/reflect-metadata/#ordinarymetadatakeys function OrdinaryMetadataKeys(O, P) { let ownKeys = OrdinaryOwnMetadataKeys(O, P); let parent = OrdinaryGetPrototypeOf(O); if (parent === null) { return ownKeys; } let parentKeys = OrdinaryMetadataKeys(parent, P); if (parentKeys.length <= 0) { return ownKeys; } if (ownKeys.length <= 0) { return parentKeys; } let set = new _Set(); let keys = []; for (let _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) { var key = ownKeys_1[_i]; var hasKey = set.has(key); if (!hasKey) { set.add(key); keys.push(key); } } for (let _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) { var key = parentKeys_1[_a]; var hasKey = set.has(key); if (!hasKey) { set.add(key); keys.push(key); } } return keys; } // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P) // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys function OrdinaryOwnMetadataKeys(O, P) { let provider = GetMetadataProvider(O, P, /* create*/ false); if (!provider) { return []; } return provider.OrdinaryOwnMetadataKeys(O, P); } // 6 ECMAScript Data Types and Values // https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values function Type(x) { if (x === null) { return 1 /* Null */; } switch (typeof x) { case 'undefined': return 0 /* Undefined */; case 'boolean': return 2 /* Boolean */; case 'string': return 3 /* String */; case 'symbol': return 4 /* Symbol */; case 'number': return 5 /* Number */; case 'object': return x === null ? 1 /* Null */ : 6 /* Object */; default: return 6 /* Object */; } } // 6.1.1 The Undefined Type // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-undefined-type function IsUndefined(x) { return x === undefined; } // 6.1.2 The Null Type // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-null-type function IsNull(x) { return x === null; } // 6.1.5 The Symbol Type // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-symbol-type function IsSymbol(x) { return typeof x === 'symbol'; } // 6.1.7 The Object Type // https://tc39.github.io/ecma262/#sec-object-type function IsObject(x) { return typeof x === 'object' ? x !== null : typeof x === 'function'; } // 7.1 Type Conversion // https://tc39.github.io/ecma262/#sec-type-conversion // 7.1.1 ToPrimitive(input [, PreferredType]) // https://tc39.github.io/ecma262/#sec-toprimitive function ToPrimitive(input, PreferredType) { switch (Type(input)) { case 0 /* Undefined */: return input; case 1 /* Null */: return input; case 2 /* Boolean */: return input; case 3 /* String */: return input; case 4 /* Symbol */: return input; case 5 /* Number */: return input; } let hint = PreferredType === 3 /* String */ ? 'string' : PreferredType === 5 /* Number */ ? 'number' : 'default'; let exoticToPrim = GetMethod(input, toPrimitiveSymbol); if (exoticToPrim !== undefined) { let result = exoticToPrim.call(input, hint); if (IsObject(result)) { throw new TypeError(); } return result; } return OrdinaryToPrimitive(input, hint === 'default' ? 'number' : hint); } // 7.1.1.1 OrdinaryToPrimitive(O, hint) // https://tc39.github.io/ecma262/#sec-ordinarytoprimitive function OrdinaryToPrimitive(O, hint) { if (hint === 'string') { let toString_1 = O.toString; if (IsCallable(toString_1)) { var result = toString_1.call(O); if (!IsObject(result)) { return result; } } var { valueOf } = O; if (IsCallable(valueOf)) { var result = valueOf.call(O); if (!IsObject(result)) { return result; } } } else { var { valueOf } = O; if (IsCallable(valueOf)) { var result = valueOf.call(O); if (!IsObject(result)) { return result; } } let toString_2 = O.toString; if (IsCallable(toString_2)) { var result = toString_2.call(O); if (!IsObject(result)) { return result; } } } throw new TypeError(); } // 7.1.2 ToBoolean(argument) // https://tc39.github.io/ecma262/2016/#sec-toboolean function ToBoolean(argument) { return Boolean(argument); } // 7.1.12 ToString(argument) // https://tc39.github.io/ecma262/#sec-tostring function ToString(argument) { return `${argument}`; } // 7.1.14 ToPropertyKey(argument) // https://tc39.github.io/ecma262/#sec-topropertykey function ToPropertyKey(argument) { let key = ToPrimitive(argument, 3 /* String */); if (IsSymbol(key)) { return key; } return ToString(key); } // 7.2 Testing and Comparison Operations // https://tc39.github.io/ecma262/#sec-testing-and-comparison-operations // 7.2.2 IsArray(argument) // https://tc39.github.io/ecma262/#sec-isarray function IsArray(argument) { return Array.isArray ? Array.isArray(argument) : argument instanceof Object ? argument instanceof Array : Object.prototype.toString.call(argument) === '[object Array]'; } // 7.2.3 IsCallable(argument) // https://tc39.github.io/ecma262/#sec-iscallable function IsCallable(argument) { // NOTE: This is an approximation as we cannot check for [[Call]] internal method. return typeof argument === 'function'; } // 7.2.4 IsConstructor(argument) // https://tc39.github.io/ecma262/#sec-isconstructor function IsConstructor(argument) { // NOTE: This is an approximation as we cannot check for [[Construct]] internal method. return typeof argument === 'function'; } // 7.2.7 IsPropertyKey(argument) // https://tc39.github.io/ecma262/#sec-ispropertykey function IsPropertyKey(argument) { switch (Type(argument)) { case 3 /* String */: return true; case 4 /* Symbol */: return true; default: return false; } } function SameValueZero(x, y) { return x === y || x !== x && y !== y; } // 7.3 Operations on Objects // https://tc39.github.io/ecma262/#sec-operations-on-objects // 7.3.9 GetMethod(V, P) // https://tc39.github.io/ecma262/#sec-getmethod function GetMethod(V, P) { let func = V[P]; if (func === undefined || func === null) { return undefined; } if (!IsCallable(func)) { throw new TypeError(); } return func; } // 7.4 Operations on Iterator Objects // https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects function GetIterator(obj) { let method = GetMethod(obj, iteratorSymbol); if (!IsCallable(method)) { throw new TypeError(); } // from Call let iterator = method.call(obj); if (!IsObject(iterator)) { throw new TypeError(); } return iterator; } // 7.4.4 IteratorValue(iterResult) // https://tc39.github.io/ecma262/2016/#sec-iteratorvalue function IteratorValue(iterResult) { return iterResult.value; } // 7.4.5 IteratorStep(iterator) // https://tc39.github.io/ecma262/#sec-iteratorstep function IteratorStep(iterator) { let result = iterator.next(); return result.done ? false : result; } // 7.4.6 IteratorClose(iterator, completion) // https://tc39.github.io/ecma262/#sec-iteratorclose function IteratorClose(iterator) { let f = iterator.return; if (f) { f.call(iterator); } } // 9.1 Ordinary Object Internal Methods and Internal Slots // https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots // 9.1.1.1 OrdinaryGetPrototypeOf(O) // https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof function OrdinaryGetPrototypeOf(O) { let proto = Object.getPrototypeOf(O); if (typeof O !== 'function' || O === functionPrototype) { return proto; } // TypeScript doesn't set __proto__ in ES5, as it's non-standard. // Try to determine the superclass constructor. Compatible implementations // must either set __proto__ on a subclass constructor to the superclass constructor, // or ensure each class has a valid `constructor` property on its prototype that // points back to the constructor. // If this is not the same as Function.[[Prototype]], then this is definately inherited. // This is the case when in ES6 or when using __proto__ in a compatible browser. if (proto !== functionPrototype) { return proto; } // If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage. let { prototype } = O; let prototypeProto = prototype && Object.getPrototypeOf(prototype); if (prototypeProto == null || prototypeProto === Object.prototype) { return proto; } // If the constructor was not a function, then we cannot determine the heritage. let { constructor } = prototypeProto; if (typeof constructor !== 'function') { return proto; } // If we have some kind of self-reference, then we cannot determine the heritage. if (constructor === O) { return proto; } // we have a pretty good guess at the heritage. return constructor; } // Global metadata registry // - Allows `import "reflect-metadata"` and `import "reflect-metadata/no-conflict"` to interoperate. // - Uses isolated metadata if `Reflect` is frozen before the registry can be installed. /** * Creates a registry used to allow multiple `reflect-metadata` providers. */ function CreateMetadataRegistry() { let fallback; if (!IsUndefined(registrySymbol) && typeof root.Reflect !== 'undefined' && !(registrySymbol in root.Reflect) && typeof root.Reflect.defineMetadata === 'function') { // interoperate with older version of `reflect-metadata` that did not support a registry. fallback = CreateFallbackProvider(root.Reflect); } let first; let second; let rest; let targetProviderMap = new _WeakMap(); let registry = { registerProvider, getProvider, setProvider, }; return registry; function registerProvider(provider) { if (!Object.isExtensible(registry)) { throw new Error('Cannot add provider to a frozen registry.'); } switch (true) { case fallback === provider: break; case IsUndefined(first): first = provider; break; case first === provider: break; case IsUndefined(second): second = provider; break; case second === provider: break; default: if (rest === undefined) { rest = new _Set(); } rest.add(provider); break; } } function getProviderNoCache(O, P) { if (!IsUndefined(first)) { if (first.isProviderFor(O, P)) { return first; } if (!IsUndefined(second)) { if (second.isProviderFor(O, P)) { return first; } if (!IsUndefined(rest)) { let iterator = GetIterator(rest); while (true) { let next = IteratorStep(iterator); if (!next) { return undefined; } let provider = IteratorValue(next); if (provider.isProviderFor(O, P)) { IteratorClose(iterator); return provider; } } } } } if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) { return fallback; } return undefined; } function getProvider(O, P) { let providerMap = targetProviderMap.get(O); let provider; if (!IsUndefined(providerMap)) { provider = providerMap.get(P); } if (!IsUndefined(provider)) { return provider; } provider = getProviderNoCache(O, P); if (!IsUndefined(provider)) { if (IsUndefined(providerMap)) { providerMap = new _Map(); targetProviderMap.set(O, providerMap); } providerMap.set(P, provider); } return provider; } function hasProvider(provider) { if (IsUndefined(provider)) { throw new TypeError(); } return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider); } function setProvider(O, P, provider) { if (!hasProvider(provider)) { throw new Error('Metadata provider not registered.'); } let existingProvider = getProvider(O, P); if (existingProvider !== provider) { if (!IsUndefined(existingProvider)) { return false; } let providerMap = targetProviderMap.get(O); if (IsUndefined(providerMap)) { providerMap = new _Map(); targetProviderMap.set(O, providerMap); } providerMap.set(P, provider); } return true; } } /** * Gets or creates the shared registry of metadata providers. */ function GetOrCreateMetadataRegistry() { let metadataRegistry; if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) { metadataRegistry = root.Reflect[registrySymbol]; } if (IsUndefined(metadataRegistry)) { metadataRegistry = CreateMetadataRegistry(); } if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) { Object.defineProperty(root.Reflect, registrySymbol, { enumerable: false, configurable: false, writable: false, value: metadataRegistry, }); } return metadataRegistry; } function CreateMetadataProvider(registry) { // [[Metadata]] internal slot // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots let metadata = new _WeakMap(); let provider = { isProviderFor (O, P) { let targetMetadata = metadata.get(O); if (IsUndefined(targetMetadata)) { return false; } return targetMetadata.has(P); }, OrdinaryDefineOwnMetadata, OrdinaryHasOwnMetadata, OrdinaryGetOwnMetadata, OrdinaryOwnMetadataKeys, OrdinaryDeleteMetadata, }; metadataRegistry.registerProvider(provider); return provider; function GetOrCreateMetadataMap(O, P, Create) { let targetMetadata = metadata.get(O); let createdTargetMetadata = false; if (IsUndefined(targetMetadata)) { if (!Create) { return undefined; } targetMetadata = new _Map(); metadata.set(O, targetMetadata); createdTargetMetadata = true; } let metadataMap = targetMetadata.get(P); if (IsUndefined(metadataMap)) { if (!Create) { return undefined; } metadataMap = new _Map(); targetMetadata.set(P, metadataMap); if (!registry.setProvider(O, P, provider)) { targetMetadata.delete(P); if (createdTargetMetadata) { metadata.delete(O); } throw new Error('Wrong provider for target.'); } } return metadataMap; } // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P) // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata function OrdinaryHasOwnMetadata(MetadataKey, O, P) { let metadataMap = GetOrCreateMetadataMap(O, P, /* Create*/ false); if (IsUndefined(metadataMap)) { return false; } return ToBoolean(metadataMap.has(MetadataKey)); } // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P) // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata function OrdinaryGetOwnMetadata(MetadataKey, O, P) { let metadataMap = GetOrCreateMetadataMap(O, P, /* Create*/ false); if (IsUndefined(metadataMap)) { return undefined; } return metadataMap.get(MetadataKey); } // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) { let metadataMap = GetOrCreateMetadataMap(O, P, /* Create*/ true); metadataMap.set(MetadataKey, MetadataValue); } // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P) // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys function OrdinaryOwnMetadataKeys(O, P) { let keys = []; let metadataMap = GetOrCreateMetadataMap(O, P, /* Create*/ false); if (IsUndefined(metadataMap)) { return keys; } let keysObj = metadataMap.keys(); let iterator = GetIterator(keysObj); let k = 0; while (true) { let next = IteratorStep(iterator); if (!next) { keys.length = k; return keys; } let nextValue = IteratorValue(next); try { keys[k] = nextValue; } catch (e) { try { IteratorClose(iterator); } finally { throw e; } } k++; } } function OrdinaryDeleteMetadata(MetadataKey, O, P) { let metadataMap = GetOrCreateMetadataMap(O, P, /* Create*/ false); if (IsUndefined(metadataMap)) { return false; } if (!metadataMap.delete(MetadataKey)) { return false; } if (metadataMap.size === 0) { let targetMetadata = metadata.get(O); if (!IsUndefined(targetMetadata)) { targetMetadata.delete(P); if (targetMetadata.size === 0) { metadata.delete(targetMetadata); } } } return true; } } function CreateFallbackProvider(reflect) { let { defineMetadata } = reflect, { hasOwnMetadata } = reflect, { getOwnMetadata } = reflect, { getOwnMetadataKeys } = reflect, { deleteMetadata } = reflect; let metadataOwner = new _WeakMap(); let provider = { isProviderFor (O, P) { let metadataPropertySet = metadataOwner.get(O); if (!IsUndefined(metadataPropertySet) && metadataPropertySet.has(P)) { return true; } if (getOwnMetadataKeys(O, P).length) { if (IsUndefined(metadataPropertySet)) { metadataPropertySet = new _Set(); metadataOwner.set(O, metadataPropertySet); } metadataPropertySet.add(P); return true; } return false; }, OrdinaryDefineOwnMetadata: defineMetadata, OrdinaryHasOwnMetadata: hasOwnMetadata, OrdinaryGetOwnMetadata: getOwnMetadata, OrdinaryOwnMetadataKeys: getOwnMetadataKeys, OrdinaryDeleteMetadata: deleteMetadata, }; return provider; } /** * Gets the metadata provider for an object. If the object has no metadata provider and this is for a create operation, * then this module's metadata provider is assigned to the object. */ function GetMetadataProvider(O, P, Create) { let registeredProvider = metadataRegistry.getProvider(O, P); if (!IsUndefined(registeredProvider)) { return registeredProvider; } if (Create) { if (metadataRegistry.setProvider(O, P, metadataProvider)) { return metadataProvider; } throw new Error('Illegal state.'); } return undefined; } // naive Map shim function CreateMapPolyfill() { let cacheSentinel = {}; let arraySentinel = []; let MapIterator = /** @class */ (function () { function MapIterator(keys, values, selector) { this._index = 0; this._keys = keys; this._values = values; this._selector = selector; } MapIterator.prototype['@@iterator'] = function () { return this; }; MapIterator.prototype[iteratorSymbol] = function () { return this; }; MapIterator.prototype.next = function () { let index = this._index; if (index >= 0 && index < this._keys.length) { let result = this._selector(this._keys[index], this._values[index]); if (index + 1 >= this._keys.length) { this._index = -1; this._keys = arraySentinel; this._values = arraySentinel; } else { this._index++; } return { value: result, done: false }; } return { value: undefined, done: true }; }; MapIterator.prototype.throw = function (error) { if (this._index >= 0) { this._index = -1; this._keys = arraySentinel; this._values = arraySentinel; } throw error; }; MapIterator.prototype.return = function (value) { if (this._index >= 0) { this._index = -1; this._keys = arraySentinel; this._values = arraySentinel; } return { value, done: true }; }; return MapIterator; }()); let Map = /** @class */ (function () { function Map() { this._keys = []; this._values = []; this._cacheKey = cacheSentinel; this._cacheIndex = -2; } Object.defineProperty(Map.prototype, 'size', { get () { return this._keys.length; }, enumerable: true, configurable: true, }); Map.prototype.has = function (key) { return this._find(key, /* insert*/ false) >= 0; }; Map.prototype.get = function (key) { let index = this._find(key, /* insert*/ false); return index >= 0 ? this._values[index] : undefined; }; Map.prototype.set = function (key, value) { let index = this._find(key, /* insert*/ true); this._values[index] = value; return this; }; Map.prototype.delete = function (key) { let index = this._find(key, /* insert*/ false); if (index >= 0) { let size = this._keys.length; for (let i = index + 1; i < size; i++) { this._keys[i - 1] = this._keys[i]; this._values[i - 1] = this._values[i]; } this._keys.length--; this._values.length--; if (SameValueZero(key, this._cacheKey)) { this._cacheKey = cacheSentinel; this._cacheIndex = -2; } return true; } return false; }; Map.prototype.clear = function () { this._keys.length = 0; this._values.length = 0; this._cacheKey = cacheSentinel; this._cacheIndex = -2; }; Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); }; Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); }; Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); }; Map.prototype['@@iterator'] = function () { return this.entries(); }; Map.prototype[iteratorSymbol] = function () { return this.entries(); }; Map.prototype._find = function (key, insert) { if (!SameValueZero(this._cacheKey, key)) { this._cacheIndex = -1; for (let i = 0; i < this._keys.length; i++) { if (SameValueZero(this._keys[i], key)) { this._cacheIndex = i; break; } } } if (this._cacheIndex < 0 && insert) { this._cacheIndex = this._keys.length; this._keys.push(key); this._values.push(undefined); } return this._cacheIndex; }; return Map; }()); return Map; function getKey(key, _) { return key; } function getValue(_, value) { return value; } function getEntry(key, value) { return [key, value]; } } // naive Set shim function CreateSetPolyfill() { let Set = /** @class */ (function () { function Set() { this._map = new _Map(); } Object.defineProperty(Set.prototype, 'size', { get () { return this._map.size; }, enumerable: true, configurable: true, }); Set.prototype.has = function (value) { return this._map.has(value); }; Set.prototype.add = function (value) { return this._map.set(value, value), this; }; Set.prototype.delete = function (value) { return this._map.delete(value); }; Set.prototype.clear = function () { this._map.clear(); }; Set.prototype.keys = function () { return this._map.keys(); }; Set.prototype.values = function () { return this._map.keys(); }; Set.prototype.entries = function () { return this._map.entries(); }; Set.prototype['@@iterator'] = function () { return this.keys(); }; Set.prototype[iteratorSymbol] = function () { return this.keys(); }; return Set; }()); return Set; } // naive WeakMap shim function CreateWeakMapPolyfill() { let UUID_SIZE = 16; let keys = HashMap.create(); let rootKey = CreateUniqueKey(); return /** @class */ (function () { function WeakMap() { this._key = CreateUniqueKey(); } WeakMap.prototype.has = function (target) { let table = GetOrCreateWeakMapTable(target, /* create*/ false); return table !== undefined ? HashMap.has(table, this._key) : false; }; WeakMap.prototype.get = function (target) { let table = GetOrCreateWeakMapTable(target, /* create*/ false); return table !== undefined ? HashMap.get(table, this._key) : undefined; }; WeakMap.prototype.set = function (target, value) { let table = GetOrCreateWeakMapTable(target, /* create*/ true); table[this._key] = value; return this; }; WeakMap.prototype.delete = function (target) { let table = GetOrCreateWeakMapTable(target, /* create*/ false); return table !== undefined ? delete table[this._key] : false; }; WeakMap.prototype.clear = function () { // NOTE: not a real clear, just makes the previous data unreachable this._key = CreateUniqueKey(); }; return WeakMap; }()); function CreateUniqueKey() { let key; do { key = `@@WeakMap@@${CreateUUID()}`; } while (HashMap.has(keys, key)); keys[key] = true; return key; } function GetOrCreateWeakMapTable(target, create) { if (!hasOwn.call(target, rootKey)) { if (!create) { return undefined; } Object.defineProperty(target, rootKey, { value: HashMap.create() }); } return target[rootKey]; } function FillRandomBytes(buffer, size) { for (let i = 0; i < size; ++i) { buffer[i] = Math.random() * 0xff | 0; } return buffer; } function GenRandomBytes(size) { if (typeof Uint8Array === 'function') { let array = new Uint8Array(size); if (typeof crypto !== 'undefined') { crypto.getRandomValues(array); } else if (typeof msCrypto !== 'undefined') { msCrypto.getRandomValues(array); } else { FillRandomBytes(array, size); } return array; } return FillRandomBytes(new Array(size), size); } function CreateUUID() { let data = GenRandomBytes(UUID_SIZE); // mark as random - RFC 4122 § 4.4 data[6] = data[6] & 0x4f | 0x40; data[8] = data[8] & 0xbf | 0x80; let result = ''; for (let offset = 0; offset < UUID_SIZE; ++offset) { let byte = data[offset]; if (offset === 4 || offset === 6 || offset === 8) { result += '-'; } if (byte < 16) { result += '0'; } result += byte.toString(16).toLowerCase(); } return result; } } // uses a heuristic used by v8 and chakra to force an object into dictionary mode. function MakeDictionary(obj) { obj.__ = undefined; delete obj.__; return obj; } }); })(Reflect || (Reflect = {}));
09-29
.nbcio.modules.flowable.flow.FlowableConfig:49 - ╔══════════════════════════════════════════╗ 2025-09-03 15:09:14.749 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:50 - ║ 正在配置Flowable引擎 (v6.7.2) 2025-09-03 15:09:14.749 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:51 - ║ Spring Boot版本: 2.4.x 2025-09-03 15:09:14.749 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:52 - ╚══════════════════════════════════════════╝ 2025-09-03 15:09:14.750 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:59 - ✅ 数据源和事务管理器已正确注入 2025-09-03 15:09:14.769 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:68 - 🔗 数据源信息: jdbc:mysql://192.168.8.3:3306/yaxt-micro?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai 2025-09-03 15:09:14.769 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:75 - 🔀 事务管理器: JpaTransactionManager 2025-09-03 15:09:14.769 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:79 - 🔄 数据库Schema更新策略: true (自动更新) 2025-09-03 15:09:14.769 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:81 - 💾 数据库类型: mysql 2025-09-03 15:09:14.769 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:86 - 🚫 已禁用IDM引擎和事件注册表 2025-09-03 15:09:15.013 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:100 - ✅ Flowable引擎初始化成功! 2025-09-03 15:09:15.013 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:101 - 🔧 Flowable版本: 6.7.2.0 2025-09-03 15:09:15.014 [main] INFO com.nbcio.modules.flowable.flow.FlowableConfig:102 - ⏱️ 启动耗时: 15657 ms 2025-09-03 15:09:15.741 [main] INFO o.f.c.engine.impl.async.DefaultAsyncTaskExecutor:154 - Creating thread pool queue of size 2048 2025-09-03 15:09:15.742 [main] INFO o.f.c.engine.impl.async.DefaultAsyncTaskExecutor:159 - Creating thread factory with naming pattern flowable-async-job-executor-thread-%d 2025-09-03 15:09:15.744 [main] INFO o.f.c.engine.impl.async.DefaultAsyncTaskExecutor:164 - Creating executor service with corePoolSize 8, maxPoolSize 8 and keepAliveTime 5000 2025-09-03 15:09:15.982 [main] ERROR o.f.common.engine.impl.interceptor.CommandContext:125 - Error while closing command context java.lang.NullPointerException: null at org.flowable.engine.impl.db.ProcessDbSchemaManager.schemaUpdate(ProcessDbSchemaManager.java:232) at org.flowable.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:54) at org.flowable.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:28) at org.flowable.engine.impl.interceptor.CommandInvoker$1.run(CommandInvoker.java:67) at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:140) at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:114) at org.flowable.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:72) at org.flowable.engine.impl.interceptor.BpmnOverrideContextInterceptor.execute(BpmnOverrideContextInterceptor.java:26) at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53) at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:105) at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:57) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:57) at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56) at org.flowable.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:83) at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:917) at org.flowable.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java:76) at org.flowable.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:59) at org.flowable.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:32) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1828) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1265) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:538) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207) at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:247) at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:204) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:134) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:410) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:898) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) at org.springframework.cloud.context.named.NamedContextFactory.createContext(NamedContextFactory.java:136) at org.springframework.cloud.context.named.NamedContextFactory.getContext(NamedContextFactory.java:101) at org.springframework.cloud.context.named.NamedContextFactory.getInstance(NamedContextFactory.java:145) at org.springframework.cloud.openfeign.FeignClientFactoryBean.get(FeignClientFactoryBean.java:264) at org.springframework.cloud.openfeign.FeignClientFactoryBean.feign(FeignClientFactoryBean.java:97) at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:320) at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:310) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1828) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1265) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1532) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1489) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1270) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) at org.jeecg.JeecgSystemCloudApplication.main(JeecgSystemCloudApplication.java:66) 2025-09-03 15:09:15.995 [main] WARN o.s.c.a.AnnotationConfigApplicationContext:559 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'flowableGlobalListenerConfig' defined in file [D:\work\javacode\yaxt-micro\jeecg-cloud-module\nbcio-boot-module-flowable\target\classes\com\nbcio\modules\flowable\config\FlowableGlobalListenerConfig.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'taskCreateListener' defined in file [D:\work\javacode\yaxt-micro\jeecg-cloud-module\nbcio-boot-module-flowable\target\classes\com\nbcio\modules\flowable\listener\TaskCreateListener.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'taskServiceBean' defined in class path resource [org/flowable/spring/boot/ProcessEngineServicesAutoConfiguration.class]: Unsatisfied dependency expressed through method 'taskServiceBean' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException 2025-09-03 15:09:15.997 [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext:559 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jeecgTestFeignController': Unsatisfied dependency expressed through field 'jeecgTestClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.jeecg.modules.cloud.feign.feign.JeecgTestClient': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'flowableGlobalListenerConfig' defined in file [D:\work\javacode\yaxt-micro\jeecg-cloud-module\nbcio-boot-module-flowable\target\classes\com\nbcio\modules\flowable\config\FlowableGlobalListenerConfig.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'taskCreateListener' defined in file [D:\work\javacode\yaxt-micro\jeecg-cloud-module\nbcio-boot-module-flowable\target\classes\com\nbcio\modules\flowable\listener\TaskCreateListener.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'taskServiceBean' defined in class path resource [org/flowable/spring/boot/ProcessEngineServicesAutoConfiguration.class]: Unsatisfied dependency expressed through method 'taskServiceBean' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException 2025-09-03 15:09:15.998 [main] INFO o.s.a.r.listener.SimpleMessageListenerContainer:1260 - Shutdown ignored - container is not active already 2025-09-03 15:09:16.004 [main] INFO o.s.orm.jpa.LocalContainerEntityManagerFactoryBean:598 - Closing JPA EntityManagerFactory for persistence unit 'default' 2025-09-03 15:09:16.009 [main] INFO c.b.dynamic.datasource.DynamicRoutingDataSource:217 - dynamic-datasource start closing .... 2025-09-03 15:09:16.011 [main] INFO com.alibaba.druid.pool.DruidDataSource:2029 - {dataSource-1} closing ... 2025-09-03 15:09:16.013 [main] INFO com.alibaba.druid.pool.DruidDataSource:2101 - {dataSource-1} closed 为什么还是报错
09-04
<think> 我们之前已经讨论过“authStore.login is not a function”的问题,但问题仍然存在,因此需要更深入的排查。 可能的原因包括: 1. Pinia store 没有正确初始化(可能由于循环依赖或模块加载顺序问题) 2. 在调用`useAuthStore()`时,Pinia插件尚未安装(例如在Vue应用安装之前就调用了store) 3. store定义文件(auth.ts)没有默认导出,或者导出方式不正确 4. 在组件外部调用了store(例如在普通的js文件中) 下面提供一种更健壮的解决方案: 步骤1:确保Pinia安装正确(在Vue应用创建时安装Pinia) 步骤2:在store定义中使用`defineStore`,并确保在组件中通过`useAuthStore`使用 步骤3:检查是否有条件地使用store(例如在某个if语句中调用`useAuthStore`,这可能导致在Pinia安装前调用) 如果上述步骤都正确,但问题仍然存在,我们可以尝试一种更可靠的方式:在组件中延迟调用store方法(例如在mounted生命周期之后调用),或者使用一个包装函数来确保Pinia已安装。 但是,根据Pinia的官方文档,`useAuthStore`必须在`setup()`函数或`<script setup>`的顶层调用,且不能有条件地调用。 下面提供一个完整的示例,包括store定义、main.ts和组件使用。 首先,确保store定义文件(`src/stores/auth.ts`)如下: </think>## 深入解决 "authStore.login is not a function" 错误 这个错误表明 Pinia store 中的 `login` 方法未能正确暴露或访问。以下是更全面的解决方案,包含多种可能性排查: ### 核心原因分析 1. **Store 定义问题**: - `login` 方法未正确定义为 action - Store 使用了错误的定义方式(选项式 vs 组合式) 2. **Store 实例化问题**: - 在组件外部创建 store 实例 - 在生命周期钩子之前访问 store 3. **作用域问题**: - 在异步回调或嵌套函数中访问 store - `this` 绑定丢失(特别是使用箭头函数时) 4. **构建/编译问题**: - 未正确配置构建工具(Vite/Webpack) - TypeScript 类型检查失败 ### 完整解决方案 #### 1. 修复 Store 定义(组合式 API 推荐) ```typescript // src/stores/auth.ts import { defineStore } from 'pinia' import { ref } from 'vue' export const useAuthStore = defineStore('auth', () => { // 状态 const user = ref<User | null>(null) const isAuthenticated = ref(!!localStorage.getItem('token')) // Actions const login = async (credentials: LoginCredentials): Promise<void> => { return new Promise((resolve, reject) => { setTimeout(() => { if (credentials.username === 'admin' && credentials.password === '123456') { user.value = { username: credentials.username } isAuthenticated.value = true localStorage.setItem('token', 'fake-jwt-token') resolve() } else { reject(new Error('用户名或密码错误')) } }, 1000) }) } const logout = () => { user.value = null isAuthenticated.value = false localStorage.removeItem('token') } return { user, isAuthenticated, login, logout } }) ``` #### 2. 修复组件使用方式 ```vue <!-- src/views/LoginView.vue --> <script setup lang="ts"> import { onMounted } from 'vue' import { useRouter } from 'vue-router' import { useAuthStore } from '@/stores/auth' const router = useRouter() const authStore = useAuthStore() const error = ref<string | null>(null) // 确保在 DOM 挂载后访问 store onMounted(() => { console.log('Store available:', authStore) console.log('Login method:', authStore.login) }) const handleLogin = async (credentials: any) => { try { // 使用可选链操作符防止运行时错误 await authStore.login?.(credentials) router.push('/dashboard') } catch (err: any) { error.value = err.message || '登录失败' } } </script> ``` #### 3. 添加 Store 类型安全声明 ```typescript // src/types/pinia.d.ts import { StoreDefinition } from 'pinia' // 声明全局 store 类型 declare module 'pinia' { export interface AuthStore extends StoreDefinition { login: (credentials: { username: string; password: string }) => Promise<void> logout: () => void user: Ref<User | null> isAuthenticated: Ref<boolean> } } ``` #### 4. 验证 Pinia 安装 ```typescript // src/main.ts import { createApp } from 'vue' import { createPinia } from 'pinia' import App from './App.vue' import router from './router' // 创建 Pinia 实例 const pinia = createPinia() // 添加插件验证 pinia.use(({ store }) => { console.log(`Store created: ${store.$id}`) }) const app = createApp(App) // 必须先安装 Pinia app.use(pinia) app.use(router) app.mount('#app') ``` #### 5. 添加 Store 单元测试 ```typescript // tests/unit/authStore.spec.ts import { setActivePinia, createPinia } from 'pinia' import { useAuthStore } from '@/stores/auth' describe('Auth Store', () => { beforeEach(() => { setActivePinia(createPinia()) localStorage.clear() }) it('should have login method', () => { const store = useAuthStore() expect(typeof store.login).toBe('function') }) it('should login successfully', async () => { const store = useAuthStore() await expect(store.login({ username: 'admin', password: '123456' })).resolves.not.toThrow() expect(store.isAuthenticated).toBe(true) }) }) ``` ### 高级调试技巧 #### 1. 添加 Store 生命周期日志 ```typescript // src/stores/auth.ts export const useAuthStore = defineStore('auth', () => { // ...状态和actions... // 添加调试钩子 if (import.meta.env.DEV) { onStoreAction(({ name, store, args }) => { console.log(`Action called: ${name}`, args) }) } return { ... } }) ``` #### 2. 使用 Proxy 包装 Store ```typescript // src/utils/storeDebugger.ts export function debugStore<T extends object>(store: T): T { if (import.meta.env.PROD) return store return new Proxy(store, { get(target, property) { const value = Reflect.get(target, property) if (typeof value === 'function') { return (...args: any[]) => { console.groupCollapsed(`[Store] Calling ${String(property)}`) console.log('Arguments:', args) try { const result = value.apply(target, args) console.log('Result:', result) console.groupEnd() return result } catch (error) { console.error('Error:', error) console.groupEnd() throw error } } } return value } }) } ``` ```vue <script setup> import { debugStore } from '@/utils/storeDebugger' const authStore = debugStore(useAuthStore()) </script> ``` ### 备选方案:使用 StoreToRefs 访问 ```vue <script setup lang="ts"> import { storeToRefs } from 'pinia' import { useAuthStore } from '@/stores/auth' const authStore = useAuthStore() const { login, logout } = storeToRefs(authStore) const handleLogin = async () => { // 通过 .value 访问方法 await login.value({ username: 'test', password: 'test' }) } </script> ``` ### 完整错误处理流程 1. **验证 Store 定义**: - 确认 `login` 定义在 `actions`(选项式)或直接暴露(组合式) - 确保没有使用箭头函数 2. **检查 Pinia 安装顺序**: ```typescript // 错误:在 app.use(router) 之后安装 app.use(router) app.use(pinia) // ❌ 顺序错误 // 正确:先安装 Pinia app.use(pinia) // ✅ app.use(router) ``` 3. **验证组件初始化**: ```typescript // 错误:在 setup 外部使用 const authStore = useAuthStore() // ❌ 在顶层作用域 export default { setup() { // 正确:在 setup 函数内 const authStore = useAuthStore() // ✅ } } ``` 4. **检查打包配置**: ```javascript // vite.config.js export default { build: { rollupOptions: { external: ['pinia'] // 确保没有排除 pinia } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值