[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/stop-iteration-iterator
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']
+31
View File
@@ -0,0 +1,31 @@
# 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.1.0](https://github.com/ljharb/stop-iteration-iterator/compare/v1.0.0...v1.1.0) - 2024-12-13
### Commits
- [New] add types [`f0ee985`](https://github.com/ljharb/stop-iteration-iterator/commit/f0ee985afeccf2950e693757266c77baeaab50f5)
- [actions] split out node 10-20, and 20+ [`b49d910`](https://github.com/ljharb/stop-iteration-iterator/commit/b49d9101ff21b27e30ce6b2c52e121b36efaa7e8)
- [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `npmignore`, `tape` [`2bdaff7`](https://github.com/ljharb/stop-iteration-iterator/commit/2bdaff787a45d4034c079bd308c4a9ba2b09950e)
- [types] clean up tsconfig [`c275b15`](https://github.com/ljharb/stop-iteration-iterator/commit/c275b15940ed12955e77bf2fd764ff507788637d)
- [meta] clean up changelog [`a3eeb9a`](https://github.com/ljharb/stop-iteration-iterator/commit/a3eeb9a763063e27a560f09d25b865f40e373154)
- [Robustness] use `es-errors` [`ca51cb8`](https://github.com/ljharb/stop-iteration-iterator/commit/ca51cb8d7ef259e4aa8e4a9289f0c187fc08d560)
- [Tests] replace `aud` with `npm audit` [`d4b8df0`](https://github.com/ljharb/stop-iteration-iterator/commit/d4b8df04328f133b65bec028c5f78715cd061357)
- [Deps] update `internal-slot` [`61ca626`](https://github.com/ljharb/stop-iteration-iterator/commit/61ca626be1bd5e9bb6051f70b32e3d49b8abcd6a)
- [Deps] update `internal-slot` [`cdabf84`](https://github.com/ljharb/stop-iteration-iterator/commit/cdabf8419d448faaacd1b5d87c839acb7a6eb899)
- [meta] add `sideEffects` flag [`a5f6cb6`](https://github.com/ljharb/stop-iteration-iterator/commit/a5f6cb6e9fa8859115e452c22d4ef90366dc4d0f)
- [Dev Deps] add missing peer dep [`6f6496e`](https://github.com/ljharb/stop-iteration-iterator/commit/6f6496ec5c47499f5e30b80268e2ce545a5469ba)
## v1.0.0 - 2023-01-12
### Commits
- Initial implementation, tests, readme [`43e8109`](https://github.com/ljharb/stop-iteration-iterator/commit/43e81099d2f2b63ff3a8a253ad13dd8279c9e2dc)
- Initial commit [`23929ce`](https://github.com/ljharb/stop-iteration-iterator/commit/23929ce525165bfe54f053284fd066dce8598486)
- npm init [`a9847ab`](https://github.com/ljharb/stop-iteration-iterator/commit/a9847ab637a7c223fb7478d47caf04e89ba283ff)
- Only apps should have lockfiles [`4e41f3f`](https://github.com/ljharb/stop-iteration-iterator/commit/4e41f3fbbaf8a1d32b12514d7296961e5df73e4b)
+42
View File
@@ -0,0 +1,42 @@
# stop-iteration-iterator <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]
Firefox 17-26 iterators throw a StopIteration object to indicate "done". This normalizes it.
# Usage
```js
var stopIterationIterator = require('stop-iteration-iterator');
var s = new Set([1, 2]);
var iterator = stopIterationIterator(s.keys());
iterator.next(); // { done: false, value: 1 }
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/stop-iteration-iterator
[npm-version-svg]: https://versionbadg.es/ljharb/stop-iteration-iterator.svg
[deps-svg]: https://david-dm.org/ljharb/stop-iteration-iterator.svg
[deps-url]: https://david-dm.org/ljharb/stop-iteration-iterator
[dev-deps-svg]: https://david-dm.org/ljharb/stop-iteration-iterator/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/stop-iteration-iterator#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/stop-iteration-iterator.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/stop-iteration-iterator.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/stop-iteration-iterator.svg
[downloads-url]: https://npm-stat.com/charts.html?package=stop-iteration-iterator
[codecov-image]: https://codecov.io/gh/ljharb/stop-iteration-iterator/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/ljharb/stop-iteration-iterator/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/stop-iteration-iterator
[actions-url]: https://github.com/ljharb/stop-iteration-iterator/actions
+7
View File
@@ -0,0 +1,7 @@
declare global {
const StopIteration: (object & { readonly __brand__?: unique symbol }) | undefined;
}
declare function getStopIterationIterator<T>(origIterator: { next(): IteratorResult<T> }): Iterator<T, unknown, T>;
export = getStopIterationIterator;
+77
View File
@@ -0,0 +1,77 @@
{
"name": "stop-iteration-iterator",
"version": "1.1.0",
"description": "Firefox 17-26 iterators throw a StopIteration object to indicate \"done\". This normalizes it.",
"main": "index.js",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"sideEffects": false,
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc && attw -P",
"pretest": "npm run lint",
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",
"posttest": "npx npm@'>= 10.2' audit --production",
"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/stop-iteration-iterator.git"
},
"keywords": [
"stopiteration",
"iterator",
"firefox"
],
"author": "Jordan Harband <ljharb@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ljharb/stop-iteration-iterator/issues"
},
"homepage": "https://github.com/ljharb/stop-iteration-iterator#readme",
"dependencies": {
"es-errors": "^1.3.0",
"internal-slot": "^1.1.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.2",
"@types/tape": "^5.6.5",
"auto-changelog": "^2.5.0",
"encoding": "^0.1.13",
"eslint": "=8.8.0",
"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"
},
"testling": {
"files": "test/index.js"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
+51
View File
@@ -0,0 +1,51 @@
'use strict';
var test = require('tape');
var stopIterationIterator = require('../');
test('stopIterationIterator', function (t) {
t.equal(typeof stopIterationIterator, 'function', 'stopIterationIterator is a function');
t.test('no StopIteration support', { skip: typeof StopIteration === 'object' }, function (st) {
st['throws'](
// @ts-expect-error
function () { stopIterationIterator(); },
SyntaxError,
'throws a SyntaxError when StopIteration is not supported'
);
st.end();
});
t.test('StopIteration support', { skip: typeof StopIteration !== 'object' }, function (st) {
// eslint-disable-next-line no-extra-parens
var s = /** @type {Set<number> & { iterator(): SetIterator<number>}} */ (new Set([1, 2]));
var i = s.iterator();
st.equal(i.next(), 1, 'first item is 1');
st.equal(i.next(), 2, 'second item is 2');
try {
i.next();
st.fail();
} catch (e) {
st.equal(e, StopIteration, 'StopIteration thrown');
}
// eslint-disable-next-line no-extra-parens
var m = /** @type {Map<number, string> & { iterator(): MapIterator<[string, number]>}} */ (new Map([[1, 'a'], [2, 'b']]));
var mi = m.iterator();
st.deepEqual(mi.next(), [1, 'a'], 'first item is 1 and a');
st.deepEqual(mi.next(), [2, 'b'], 'second item is 2 and b');
try {
mi.next();
st.fail();
} catch (e) {
st.equal(e, StopIteration, 'StopIteration thrown');
}
st.end();
});
t.end();
});
+6
View File
@@ -0,0 +1,6 @@
{
"extends": "@ljharb/tsconfig",
"exclude": [
"coverage",
],
}