[backend] fix: 修复异常处理和类型转换问题

This commit is contained in:
xsl
2026-01-26 11:53:40 +08:00
parent 7ccc2a6ac6
commit 83e05bf85f
28639 changed files with 2506458 additions and 93 deletions
+12
View File
@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/set-proto
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+15
View File
@@ -0,0 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v1.0.0 - 2024-12-30
### Commits
- Initial implementation, tests, readme, types [`7036fc9`](https://github.com/ljharb/set-proto/commit/7036fc9128568b1ff0b75d1955f7f364a4394079)
- Initial commit [`dd9bedd`](https://github.com/ljharb/set-proto/commit/dd9bedd41db6ff3efa00c84fcac8ae34558bf6ee)
- npm init [`63915de`](https://github.com/ljharb/set-proto/commit/63915dee39422698275fabe9876eb141e04390dd)
- Only apps should have lockfiles [`deffdae`](https://github.com/ljharb/set-proto/commit/deffdae5b989a9305247a4db314222ecc0a99280)
+8
View File
@@ -0,0 +1,8 @@
declare function setProto<O extends object, P extends object | null>(
object: O,
proto: P,
): O;
declare const x: typeof setProto | null;
export = x;
+6
View File
@@ -0,0 +1,6 @@
'use strict';
var $Object = require('es-object-atoms');
/** @type {import('./Object.setPrototypeOf')} */
module.exports = $Object.setPrototypeOf || null;
+52
View File
@@ -0,0 +1,52 @@
# set-proto <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
Robustly set the [[Prototype]] of an object. Uses the best available method.
## Getting started
```sh
npm install --save set-proto
```
## Usage/Examples
```js
const assert = require('assert');
const setProto = require('set-proto');
const a = { a: 1, b: 2, [Symbol.toStringTag]: 'foo' };
const b = { c: 3 };
assert.ok(!('c' in a));
setProto(a, b);
assert.ok('c' in a);
```
## Tests
Clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/set-proto
[npm-version-svg]: https://versionbadg.es/ljharb/set-proto.svg
[deps-svg]: https://david-dm.org/ljharb/set-proto.svg
[deps-url]: https://david-dm.org/ljharb/set-proto
[dev-deps-svg]: https://david-dm.org/ljharb/set-proto/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/set-proto#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/set-proto.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/set-proto.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/set-proto.svg
[downloads-url]: https://npm-stat.com/charts.html?package=set-proto
[codecov-image]: https://codecov.io/gh/ljharb/set-proto/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/ljharb/set-proto/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/set-proto
[actions-url]: https://github.com/ljharb/set-proto/actions
+3
View File
@@ -0,0 +1,3 @@
declare const x: typeof Reflect.setPrototypeOf | null;
export = x;
+4
View File
@@ -0,0 +1,4 @@
'use strict';
/** @type {import('./Reflect.setPrototypeOf')} */
module.exports = (typeof Reflect !== 'undefined' && Reflect.setPrototypeOf) || null;
+8
View File
@@ -0,0 +1,8 @@
declare function setProto<O extends object, P extends object | null>(
object: O,
proto: P,
): O;
declare const x: typeof setProto | null;
export = x;
+82
View File
@@ -0,0 +1,82 @@
{
"name": "set-proto",
"version": "1.0.0",
"description": "Robustly set the [[Prototype]] of an object",
"main": "index.js",
"exports": {
".": "./index.js",
"./Reflect.setPrototypeOf": "./Reflect.setPrototypeOf.js",
"./Object.setPrototypeOf": "./Object.setPrototypeOf.js",
"./package.json": "./package.json"
},
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"pretest": "npm run --silent lint",
"test": "npm run tests-only",
"posttest": "npx npm@\">=10.2\" audit --production",
"tests-only": "nyc tape 'test/**/*.js'",
"prelint": "evalmd README.md",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc && attw -P",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/ljharb/set-proto.git"
},
"keywords": [
"set",
"proto",
"prototype",
"setPrototypeOf",
"[[Prototype]]"
],
"author": "Jordan Harband <ljharb@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ljharb/set-proto/issues"
},
"homepage": "https://github.com/ljharb/set-proto#readme",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.0.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.2",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.3",
"@types/tape": "^5.8.0",
"auto-changelog": "^2.5.0",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0",
"typescript": "next"
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
},
"testling": {
"files": "test/index.js"
}
}
+40
View File
@@ -0,0 +1,40 @@
'use strict';
var test = require('tape');
var setProto = require('../');
var isPrototypeOf = Object.prototype.isPrototypeOf;
test('setProto', function (t) {
t.equal(typeof setProto, 'function', 'is a function');
t.test('can set', { skip: !setProto }, function (st) {
var obj = { a: 1 };
var proto = { b: 2 };
st.ok(isPrototypeOf.call(Object.prototype, obj), 'Object.prototype is isPrototypeOf obj');
st.notOk(isPrototypeOf.call(proto, obj), 'proto is not isPrototypeOf obj');
st.ok('a' in obj, 'a is in obj');
st.notOk('b' in obj, 'b is not in obj');
// eslint-disable-next-line no-extra-parens
st.equal(/** @type {NonNullable<typeof setProto>} */ (setProto)(obj, proto), obj, 'returns the object');
st.ok(isPrototypeOf.call(Object.prototype, obj), 'Object.prototype is isPrototypeOf obj');
st.ok(isPrototypeOf.call(proto, obj), 'proto is isPrototypeOf obj');
st.ok('a' in obj, 'a is in obj');
st.ok('b' in obj, 'b is in obj');
st.equal(Object.getPrototypeOf(obj), proto, 'sets the prototype');
st.end();
});
t.test('can not set', { skip: !!setProto }, function (st) {
st.equal(setProto, null);
st.end();
});
t.end();
});
+9
View File
@@ -0,0 +1,9 @@
{
"extends": "@ljharb/tsconfig",
"compilerOptions": {
//"target": "es2021",
},
"exclude": [
"coverage",
],
}