This commit is contained in:
21
node_modules/superjson/LICENSE
generated
vendored
Normal file
21
node_modules/superjson/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Simon Knott and superjson contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
348
node_modules/superjson/README.md
generated
vendored
Normal file
348
node_modules/superjson/README.md
generated
vendored
Normal file
@@ -0,0 +1,348 @@
|
||||
<p align="center">
|
||||
<img alt="superjson" src="./docs/superjson-banner.png" width="800" />
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
<a href="#contributors"><img src="https://img.shields.io/badge/all_contributors-31-orange.svg?style=flat-square" alt="All Contributors"/></a>
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
<a href="https://www.npmjs.com/package/superjson">
|
||||
<img alt="npm" src="https://img.shields.io/npm/v/superjson" />
|
||||
</a>
|
||||
<a href="https://lgtm.com/projects/g/blitz-js/superjson/context:javascript">
|
||||
<img
|
||||
alt="Language grade: JavaScript"
|
||||
src="https://img.shields.io/lgtm/grade/javascript/g/blitz-js/superjson.svg?logo=lgtm&logoWidth=18"
|
||||
/>
|
||||
</a>
|
||||
|
||||
<a href="https://github.com/blitz-js/superjson/actions">
|
||||
<img
|
||||
alt="CI"
|
||||
src="https://github.com/blitz-js/superjson/workflows/CI/badge.svg"
|
||||
/>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## Key features
|
||||
|
||||
- 🍱 Reliable serialization and deserialization
|
||||
- 🔐 Type safety with autocompletion
|
||||
- 🐾 Negligible runtime footprint
|
||||
- 💫 Framework agnostic
|
||||
- 🛠 Perfect fix for Next.js's serialisation limitations in `getServerSideProps` and `getInitialProps`
|
||||
|
||||
## Backstory
|
||||
|
||||
At [Blitz](https://github.com/blitz-js/blitz), we have struggled with the limitations of JSON. We often find ourselves working with `Date`, `Map`, `Set` or `BigInt`, but `JSON.stringify` doesn't support any of them without going through the hassle of converting manually!
|
||||
|
||||
Superjson solves these issues by providing a thin wrapper over `JSON.stringify` and `JSON.parse`.
|
||||
|
||||
## Sponsors
|
||||
|
||||
[<img src="https://raw.githubusercontent.com/blitz-js/blitz/main/assets/flightcontrol.png" alt="Flightcontrol Logo" style="width: 400px;"/>](https://www.flightcontrol.dev/?ref=superjson)
|
||||
|
||||
Superjson logo by [NUMI](https://github.com/numi-hq/open-design):
|
||||
|
||||
[<img src="https://raw.githubusercontent.com/numi-hq/open-design/main/assets/numi-lockup.png" alt="NUMI Logo" style="width: 200px;"/>](https://numi.tech/?ref=superjson)
|
||||
|
||||
## Getting started
|
||||
|
||||
Install the library with your package manager of choice, e.g.:
|
||||
|
||||
```
|
||||
yarn add superjson
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
The easiest way to use Superjson is with its `stringify` and `parse` functions. If you know how to use `JSON.stringify`, you already know Superjson!
|
||||
|
||||
Easily stringify any expression you’d like:
|
||||
|
||||
```js
|
||||
import superjson from 'superjson';
|
||||
|
||||
const jsonString = superjson.stringify({ date: new Date(0) });
|
||||
|
||||
// jsonString === '{"json":{"date":"1970-01-01T00:00:00.000Z"},"meta":{"values":{date:"Date"}}}'
|
||||
```
|
||||
|
||||
And parse your JSON like so:
|
||||
|
||||
```js
|
||||
const object = superjson.parse<
|
||||
{ date: Date }
|
||||
>(jsonString);
|
||||
|
||||
// object === { date: new Date(0) }
|
||||
```
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
For cases where you want lower level access to the `json` and `meta` data in the output, you can use the `serialize` and `deserialize` functions.
|
||||
|
||||
One great use case for this is where you have an API that you want to be JSON compatible for all clients, but you still also want to transmit the meta data so clients can use superjson to fully deserialize it.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
const object = {
|
||||
normal: 'string',
|
||||
timestamp: new Date(),
|
||||
test: /superjson/,
|
||||
};
|
||||
|
||||
const { json, meta } = superjson.serialize(object);
|
||||
|
||||
/*
|
||||
json = {
|
||||
normal: 'string',
|
||||
timestamp: "2020-06-20T04:56:50.293Z",
|
||||
test: "/superjson/",
|
||||
};
|
||||
|
||||
// note that `normal` is not included here; `meta` only has special cases
|
||||
meta = {
|
||||
values: {
|
||||
timestamp: ['Date'],
|
||||
test: ['regexp'],
|
||||
}
|
||||
};
|
||||
*/
|
||||
```
|
||||
|
||||
## Using with Next.js
|
||||
|
||||
The `getServerSideProps`, `getInitialProps`, and `getStaticProps` data hooks provided by Next.js do not allow you to transmit Javascript objects like Dates. It will error unless you convert Dates to strings, etc.
|
||||
|
||||
Thankfully, Superjson is a perfect tool to bypass that limitation!
|
||||
|
||||
### Next.js SWC Plugin (experimental, v13 or above)
|
||||
|
||||
Next.js SWC plugins are [experimental](https://nextjs.org/docs/advanced-features/compiler#swc-plugins-experimental), but promise a significant speedup.
|
||||
To use the [SuperJSON SWC plugin](https://github.com/blitz-js/next-superjson-plugin), install it and add it to your `next.config.js`:
|
||||
|
||||
```sh
|
||||
yarn add next-superjson-plugin
|
||||
```
|
||||
|
||||
```js
|
||||
// next.config.js
|
||||
module.exports = {
|
||||
experimental: {
|
||||
swcPlugins: [
|
||||
[
|
||||
'next-superjson-plugin',
|
||||
{
|
||||
excluded: [],
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Next.js (stable Babel transform)
|
||||
|
||||
Install the library with your package manager of choice, e.g.:
|
||||
|
||||
```sh
|
||||
yarn add babel-plugin-superjson-next
|
||||
```
|
||||
|
||||
Add the plugin to your .babelrc. If you don't have one, create it.
|
||||
|
||||
```js
|
||||
{
|
||||
"presets": ["next/babel"],
|
||||
"plugins": [
|
||||
...
|
||||
"superjson-next" // 👈
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Done! Now you can safely use all JS datatypes in your `getServerSideProps` / etc. .
|
||||
|
||||
## API
|
||||
|
||||
### serialize
|
||||
|
||||
Serializes any JavaScript value into a JSON-compatible object.
|
||||
|
||||
#### Examples
|
||||
|
||||
```js
|
||||
const object = {
|
||||
normal: 'string',
|
||||
timestamp: new Date(),
|
||||
test: /superjson/,
|
||||
};
|
||||
|
||||
const { json, meta } = serialize(object);
|
||||
```
|
||||
|
||||
Returns **`json` and `meta`, both JSON-compatible values.**
|
||||
|
||||
## deserialize
|
||||
|
||||
Deserializes the output of Superjson back into your original value.
|
||||
|
||||
#### Examples
|
||||
|
||||
```js
|
||||
const { json, meta } = serialize(object);
|
||||
|
||||
deserialize({ json, meta });
|
||||
```
|
||||
|
||||
Returns **`your original value`**.
|
||||
|
||||
### stringify
|
||||
|
||||
Serializes and then stringifies your JavaScript value.
|
||||
|
||||
#### Examples
|
||||
|
||||
```js
|
||||
const object = {
|
||||
normal: 'string',
|
||||
timestamp: new Date(),
|
||||
test: /superjson/,
|
||||
};
|
||||
|
||||
const jsonString = stringify(object);
|
||||
```
|
||||
|
||||
Returns **`string`**.
|
||||
|
||||
### parse
|
||||
|
||||
Parses and then deserializes the JSON string returned by `stringify`.
|
||||
|
||||
#### Examples
|
||||
|
||||
```js
|
||||
const jsonString = stringify(object);
|
||||
|
||||
parse(jsonString);
|
||||
```
|
||||
|
||||
Returns **`your original value`**.
|
||||
|
||||
---
|
||||
|
||||
Superjson supports many extra types which JSON does not. You can serialize all these:
|
||||
|
||||
| type | supported by standard JSON? | supported by Superjson? |
|
||||
| ----------- | --------------------------- | ----------------------- |
|
||||
| `string` | ✅ | ✅ |
|
||||
| `number` | ✅ | ✅ |
|
||||
| `boolean` | ✅ | ✅ |
|
||||
| `null` | ✅ | ✅ |
|
||||
| `Array` | ✅ | ✅ |
|
||||
| `Object` | ✅ | ✅ |
|
||||
| `undefined` | ❌ | ✅ |
|
||||
| `bigint` | ❌ | ✅ |
|
||||
| `Date` | ❌ | ✅ |
|
||||
| `RegExp` | ❌ | ✅ |
|
||||
| `Set` | ❌ | ✅ |
|
||||
| `Map` | ❌ | ✅ |
|
||||
| `Error` | ❌ | ✅ |
|
||||
| `URL` | ❌ | ✅ |
|
||||
|
||||
## Recipes
|
||||
|
||||
SuperJSON by default only supports built-in data types to keep bundle-size as low as possible.
|
||||
Here are some recipes you can use to extend to non-default data types.
|
||||
|
||||
Place them in some central utility file and make sure they're executed before any other `SuperJSON` calls.
|
||||
In a Next.js project, `_app.ts` would be a good spot for that.
|
||||
|
||||
### `Decimal.js` / `Prisma.Decimal`
|
||||
|
||||
```ts
|
||||
import { Decimal } from 'decimal.js';
|
||||
|
||||
SuperJSON.registerCustom<Decimal, string>(
|
||||
{
|
||||
isApplicable: (v): v is Decimal => Decimal.isDecimal(v),
|
||||
serialize: v => v.toJSON(),
|
||||
deserialize: v => new Decimal(v),
|
||||
},
|
||||
'decimal.js'
|
||||
);
|
||||
```
|
||||
|
||||
## Contributors ✨
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- markdownlint-disable -->
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/merelinguist"><img src="https://avatars3.githubusercontent.com/u/24858006?v=4?s=100" width="100px;" alt="Dylan Brookes"/><br /><sub><b>Dylan Brookes</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=merelinguist" title="Code">💻</a> <a href="https://github.com/blitz-js/superjson/commits?author=merelinguist" title="Documentation">📖</a> <a href="#design-merelinguist" title="Design">🎨</a> <a href="https://github.com/blitz-js/superjson/commits?author=merelinguist" title="Tests">⚠️</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://simonknott.de"><img src="https://avatars1.githubusercontent.com/u/14912729?v=4?s=100" width="100px;" alt="Simon Knott"/><br /><sub><b>Simon Knott</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=Skn0tt" title="Code">💻</a> <a href="#ideas-Skn0tt" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/blitz-js/superjson/commits?author=Skn0tt" title="Tests">⚠️</a> <a href="https://github.com/blitz-js/superjson/commits?author=Skn0tt" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://twitter.com/flybayer"><img src="https://avatars3.githubusercontent.com/u/8813276?v=4?s=100" width="100px;" alt="Brandon Bayer"/><br /><sub><b>Brandon Bayer</b></sub></a><br /><a href="#ideas-flybayer" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://jeremyliberman.com/"><img src="https://avatars3.githubusercontent.com/u/2754163?v=4?s=100" width="100px;" alt="Jeremy Liberman"/><br /><sub><b>Jeremy Liberman</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=mrleebo" title="Tests">⚠️</a> <a href="https://github.com/blitz-js/superjson/commits?author=mrleebo" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jorisre"><img src="https://avatars1.githubusercontent.com/u/7545547?v=4?s=100" width="100px;" alt="Joris"/><br /><sub><b>Joris</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=jorisre" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tomhooijenga"><img src="https://avatars0.githubusercontent.com/u/1853235?v=4?s=100" width="100px;" alt="tomhooijenga"/><br /><sub><b>tomhooijenga</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=tomhooijenga" title="Code">💻</a> <a href="https://github.com/blitz-js/superjson/issues?q=author%3Atomhooijenga" title="Bug reports">🐛</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://twitter.com/ftonato"><img src="https://avatars2.githubusercontent.com/u/5417662?v=4?s=100" width="100px;" alt="Ademílson F. Tonato"/><br /><sub><b>Ademílson F. Tonato</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=ftonato" title="Tests">⚠️</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://haspar.us"><img src="https://avatars0.githubusercontent.com/u/15332326?v=4?s=100" width="100px;" alt="Piotr Monwid-Olechnowicz"/><br /><sub><b>Piotr Monwid-Olechnowicz</b></sub></a><br /><a href="#ideas-hasparus" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://kattcorp.com"><img src="https://avatars1.githubusercontent.com/u/459267?v=4?s=100" width="100px;" alt="Alex Johansson"/><br /><sub><b>Alex Johansson</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=KATT" title="Code">💻</a> <a href="https://github.com/blitz-js/superjson/commits?author=KATT" title="Tests">⚠️</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/simonedelmann"><img src="https://avatars.githubusercontent.com/u/2821076?v=4?s=100" width="100px;" alt="Simon Edelmann"/><br /><sub><b>Simon Edelmann</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Asimonedelmann" title="Bug reports">🐛</a> <a href="https://github.com/blitz-js/superjson/commits?author=simonedelmann" title="Code">💻</a> <a href="#ideas-simonedelmann" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://www.samgarson.com"><img src="https://avatars.githubusercontent.com/u/6242344?v=4?s=100" width="100px;" alt="Sam Garson"/><br /><sub><b>Sam Garson</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Asamtgarson" title="Bug reports">🐛</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://twitter.com/_markeh"><img src="https://avatars.githubusercontent.com/u/1357323?v=4?s=100" width="100px;" alt="Mark Hughes"/><br /><sub><b>Mark Hughes</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Amarkhughes" title="Bug reports">🐛</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://blog.lxxyx.cn/"><img src="https://avatars.githubusercontent.com/u/13161470?v=4?s=100" width="100px;" alt="Lxxyx"/><br /><sub><b>Lxxyx</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=Lxxyx" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://maximomussini.com"><img src="https://avatars.githubusercontent.com/u/1158253?v=4?s=100" width="100px;" alt="Máximo Mussini"/><br /><sub><b>Máximo Mussini</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=ElMassimo" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://goodcode.nz"><img src="https://avatars.githubusercontent.com/u/425971?v=4?s=100" width="100px;" alt="Peter Dekkers"/><br /><sub><b>Peter Dekkers</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3APeterDekkers" title="Bug reports">🐛</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://goleary.com"><img src="https://avatars.githubusercontent.com/u/16123225?v=4?s=100" width="100px;" alt="Gabe O'Leary"/><br /><sub><b>Gabe O'Leary</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=goleary" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/binajmen"><img src="https://avatars.githubusercontent.com/u/15611419?v=4?s=100" width="100px;" alt="Benjamin"/><br /><sub><b>Benjamin</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=binajmen" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/icflorescu"><img src="https://avatars.githubusercontent.com/u/581999?v=4?s=100" width="100px;" alt="Ionut-Cristian Florescu"/><br /><sub><b>Ionut-Cristian Florescu</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Aicflorescu" title="Bug reports">🐛</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chrisj-back2work"><img src="https://avatars.githubusercontent.com/u/68551954?v=4?s=100" width="100px;" alt="Chris Johnson"/><br /><sub><b>Chris Johnson</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=chrisj-back2work" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://nicholaschiang.com"><img src="https://avatars.githubusercontent.com/u/20798889?v=4?s=100" width="100px;" alt="Nicholas Chiang"/><br /><sub><b>Nicholas Chiang</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Anicholaschiang" title="Bug reports">🐛</a> <a href="https://github.com/blitz-js/superjson/commits?author=nicholaschiang" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/datner"><img src="https://avatars.githubusercontent.com/u/22598347?v=4?s=100" width="100px;" alt="Datner"/><br /><sub><b>Datner</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=datner" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ruessej"><img src="https://avatars.githubusercontent.com/u/85690286?v=4?s=100" width="100px;" alt="ruessej"/><br /><sub><b>ruessej</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Aruessej" title="Bug reports">🐛</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://jins.dev"><img src="https://avatars.githubusercontent.com/u/39466936?v=4?s=100" width="100px;" alt="JH.Lee"/><br /><sub><b>JH.Lee</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=orionmiz" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://narumincho.notion.site"><img src="https://avatars.githubusercontent.com/u/16481886?v=4?s=100" width="100px;" alt="narumincho"/><br /><sub><b>narumincho</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=narumincho" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mgreystone"><img src="https://avatars.githubusercontent.com/u/12430681?v=4?s=100" width="100px;" alt="Markus Greystone"/><br /><sub><b>Markus Greystone</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Amgreystone" title="Bug reports">🐛</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://gw2treasures.com/"><img src="https://avatars.githubusercontent.com/u/2511547?v=4?s=100" width="100px;" alt="darthmaim"/><br /><sub><b>darthmaim</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=darthmaim" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://www.maxmalm.se"><img src="https://avatars.githubusercontent.com/u/430872?v=4?s=100" width="100px;" alt="Max Malm"/><br /><sub><b>Max Malm</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=benjick" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tylercollier"><img src="https://avatars.githubusercontent.com/u/366538?v=4?s=100" width="100px;" alt="Tyler Collier"/><br /><sub><b>Tyler Collier</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=tylercollier" title="Documentation">📖</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kidqueb"><img src="https://avatars.githubusercontent.com/u/884128?v=4?s=100" width="100px;" alt="Nick Quebbeman"/><br /><sub><b>Nick Quebbeman</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/commits?author=kidqueb" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://macwright.com/"><img src="https://avatars.githubusercontent.com/u/32314?v=4?s=100" width="100px;" alt="Tom MacWright"/><br /><sub><b>Tom MacWright</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Atmcw" title="Bug reports">🐛</a> <a href="https://github.com/blitz-js/superjson/commits?author=tmcw" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/peterbud"><img src="https://avatars.githubusercontent.com/u/7863452?v=4?s=100" width="100px;" alt="Peter Budai"/><br /><sub><b>Peter Budai</b></sub></a><br /><a href="https://github.com/blitz-js/superjson/issues?q=author%3Apeterbud" title="Bug reports">🐛</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<!-- markdownlint-restore -->
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||
|
||||
## See also
|
||||
|
||||
Other libraries that aim to solve a similar problem:
|
||||
|
||||
- [Serialize JavaScript](https://github.com/yahoo/serialize-javascript) by Eric Ferraiuolo
|
||||
- [devalue](https://github.com/Rich-Harris/devalue) by Rich Harris
|
||||
- [next-json](https://github.com/iccicci/next-json) by Daniele Ricci
|
2
node_modules/superjson/dist/accessDeep.d.ts
generated
vendored
Normal file
2
node_modules/superjson/dist/accessDeep.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare const getDeep: (object: object, path: (string | number)[]) => object;
|
||||
export declare const setDeep: (object: any, path: (string | number)[], mapper: (v: any) => any) => any;
|
123
node_modules/superjson/dist/accessDeep.js
generated
vendored
Normal file
123
node_modules/superjson/dist/accessDeep.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
import { isMap, isArray, isPlainObject, isSet } from './is.js';
|
||||
import { includes } from './util.js';
|
||||
const getNthKey = (value, n) => {
|
||||
if (n > value.size)
|
||||
throw new Error('index out of bounds');
|
||||
const keys = value.keys();
|
||||
while (n > 0) {
|
||||
keys.next();
|
||||
n--;
|
||||
}
|
||||
return keys.next().value;
|
||||
};
|
||||
function validatePath(path) {
|
||||
if (includes(path, '__proto__')) {
|
||||
throw new Error('__proto__ is not allowed as a property');
|
||||
}
|
||||
if (includes(path, 'prototype')) {
|
||||
throw new Error('prototype is not allowed as a property');
|
||||
}
|
||||
if (includes(path, 'constructor')) {
|
||||
throw new Error('constructor is not allowed as a property');
|
||||
}
|
||||
}
|
||||
export const getDeep = (object, path) => {
|
||||
validatePath(path);
|
||||
for (let i = 0; i < path.length; i++) {
|
||||
const key = path[i];
|
||||
if (isSet(object)) {
|
||||
object = getNthKey(object, +key);
|
||||
}
|
||||
else if (isMap(object)) {
|
||||
const row = +key;
|
||||
const type = +path[++i] === 0 ? 'key' : 'value';
|
||||
const keyOfRow = getNthKey(object, row);
|
||||
switch (type) {
|
||||
case 'key':
|
||||
object = keyOfRow;
|
||||
break;
|
||||
case 'value':
|
||||
object = object.get(keyOfRow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
object = object[key];
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};
|
||||
export const setDeep = (object, path, mapper) => {
|
||||
validatePath(path);
|
||||
if (path.length === 0) {
|
||||
return mapper(object);
|
||||
}
|
||||
let parent = object;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
const key = path[i];
|
||||
if (isArray(parent)) {
|
||||
const index = +key;
|
||||
parent = parent[index];
|
||||
}
|
||||
else if (isPlainObject(parent)) {
|
||||
parent = parent[key];
|
||||
}
|
||||
else if (isSet(parent)) {
|
||||
const row = +key;
|
||||
parent = getNthKey(parent, row);
|
||||
}
|
||||
else if (isMap(parent)) {
|
||||
const isEnd = i === path.length - 2;
|
||||
if (isEnd) {
|
||||
break;
|
||||
}
|
||||
const row = +key;
|
||||
const type = +path[++i] === 0 ? 'key' : 'value';
|
||||
const keyOfRow = getNthKey(parent, row);
|
||||
switch (type) {
|
||||
case 'key':
|
||||
parent = keyOfRow;
|
||||
break;
|
||||
case 'value':
|
||||
parent = parent.get(keyOfRow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const lastKey = path[path.length - 1];
|
||||
if (isArray(parent)) {
|
||||
parent[+lastKey] = mapper(parent[+lastKey]);
|
||||
}
|
||||
else if (isPlainObject(parent)) {
|
||||
parent[lastKey] = mapper(parent[lastKey]);
|
||||
}
|
||||
if (isSet(parent)) {
|
||||
const oldValue = getNthKey(parent, +lastKey);
|
||||
const newValue = mapper(oldValue);
|
||||
if (oldValue !== newValue) {
|
||||
parent.delete(oldValue);
|
||||
parent.add(newValue);
|
||||
}
|
||||
}
|
||||
if (isMap(parent)) {
|
||||
const row = +path[path.length - 2];
|
||||
const keyToRow = getNthKey(parent, row);
|
||||
const type = +lastKey === 0 ? 'key' : 'value';
|
||||
switch (type) {
|
||||
case 'key': {
|
||||
const newKey = mapper(keyToRow);
|
||||
parent.set(newKey, parent.get(keyToRow));
|
||||
if (newKey !== keyToRow) {
|
||||
parent.delete(keyToRow);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'value': {
|
||||
parent.set(keyToRow, mapper(parent.get(keyToRow)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};
|
||||
//# sourceMappingURL=accessDeep.js.map
|
1
node_modules/superjson/dist/accessDeep.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/accessDeep.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"accessDeep.js","sourceRoot":"","sources":["../src/accessDeep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,SAAS,GAAG,CAAC,KAA+B,EAAE,CAAS,EAAO,EAAE;IACpE,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC3D,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,OAAO,CAAC,GAAG,CAAC,EAAE;QACZ,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,CAAC,EAAE,CAAC;KACL;IAED,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;AAC3B,CAAC,CAAC;AAEF,SAAS,YAAY,CAAC,IAAyB;IAC7C,IAAI,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IACD,IAAI,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IACD,IAAI,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC7D;AACH,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,IAAyB,EAAU,EAAE;IA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AAC;gBACnD,MAAM;aACP;SACF;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
12
node_modules/superjson/dist/class-registry.d.ts
generated
vendored
Normal file
12
node_modules/superjson/dist/class-registry.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Registry } from './registry.js';
|
||||
import { Class } from './types.js';
|
||||
export interface RegisterOptions {
|
||||
identifier?: string;
|
||||
allowProps?: string[];
|
||||
}
|
||||
export declare class ClassRegistry extends Registry<Class> {
|
||||
constructor();
|
||||
private classToAllowedProps;
|
||||
register(value: Class, options?: string | RegisterOptions): void;
|
||||
getAllowedProps(value: Class): string[] | undefined;
|
||||
}
|
22
node_modules/superjson/dist/class-registry.js
generated
vendored
Normal file
22
node_modules/superjson/dist/class-registry.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Registry } from './registry.js';
|
||||
export class ClassRegistry extends Registry {
|
||||
constructor() {
|
||||
super(c => c.name);
|
||||
this.classToAllowedProps = new Map();
|
||||
}
|
||||
register(value, options) {
|
||||
if (typeof options === 'object') {
|
||||
if (options.allowProps) {
|
||||
this.classToAllowedProps.set(value, options.allowProps);
|
||||
}
|
||||
super.register(value, options.identifier);
|
||||
}
|
||||
else {
|
||||
super.register(value, options);
|
||||
}
|
||||
}
|
||||
getAllowedProps(value) {
|
||||
return this.classToAllowedProps.get(value);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=class-registry.js.map
|
1
node_modules/superjson/dist/class-registry.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/class-registry.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"class-registry.js","sourceRoot":"","sources":["../src/class-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQzC,MAAM,OAAO,aAAc,SAAQ,QAAe;IAChD;QACE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAGb,wBAAmB,GAAG,IAAI,GAAG,EAAmB,CAAC;IAFzD,CAAC;IAID,QAAQ,CAAC,KAAY,EAAE,OAAkC;QACvD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,IAAI,OAAO,CAAC,UAAU,EAAE;gBACtB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;aACzD;YAED,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;SAC3C;aAAM;YACL,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SAChC;IACH,CAAC;IAED,eAAe,CAAC,KAAY;QAC1B,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
13
node_modules/superjson/dist/custom-transformer-registry.d.ts
generated
vendored
Normal file
13
node_modules/superjson/dist/custom-transformer-registry.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { JSONValue } from './types.js';
|
||||
export interface CustomTransfomer<I, O extends JSONValue> {
|
||||
name: string;
|
||||
isApplicable: (v: any) => v is I;
|
||||
serialize: (v: I) => O;
|
||||
deserialize: (v: O) => I;
|
||||
}
|
||||
export declare class CustomTransformerRegistry {
|
||||
private transfomers;
|
||||
register<I, O extends JSONValue>(transformer: CustomTransfomer<I, O>): void;
|
||||
findApplicable<T>(v: T): CustomTransfomer<T, JSONValue> | undefined;
|
||||
findByName(name: string): CustomTransfomer<any, any>;
|
||||
}
|
16
node_modules/superjson/dist/custom-transformer-registry.js
generated
vendored
Normal file
16
node_modules/superjson/dist/custom-transformer-registry.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { find } from './util.js';
|
||||
export class CustomTransformerRegistry {
|
||||
constructor() {
|
||||
this.transfomers = {};
|
||||
}
|
||||
register(transformer) {
|
||||
this.transfomers[transformer.name] = transformer;
|
||||
}
|
||||
findApplicable(v) {
|
||||
return find(this.transfomers, transformer => transformer.isApplicable(v));
|
||||
}
|
||||
findByName(name) {
|
||||
return this.transfomers[name];
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=custom-transformer-registry.js.map
|
1
node_modules/superjson/dist/custom-transformer-registry.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/custom-transformer-registry.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"custom-transformer-registry.js","sourceRoot":"","sources":["../src/custom-transformer-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AASjC,MAAM,OAAO,yBAAyB;IAAtC;QACU,gBAAW,GAA+C,EAAE,CAAC;IAevE,CAAC;IAbC,QAAQ,CAAyB,WAAmC;QAClE,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;IACnD,CAAC;IAED,cAAc,CAAI,CAAI;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,CAC1C,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CACkB,CAAC;IAClD,CAAC;IAED,UAAU,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACF"}
|
8
node_modules/superjson/dist/double-indexed-kv.d.ts
generated
vendored
Normal file
8
node_modules/superjson/dist/double-indexed-kv.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export declare class DoubleIndexedKV<K, V> {
|
||||
keyToValue: Map<K, V>;
|
||||
valueToKey: Map<V, K>;
|
||||
set(key: K, value: V): void;
|
||||
getByKey(key: K): V | undefined;
|
||||
getByValue(value: V): K | undefined;
|
||||
clear(): void;
|
||||
}
|
21
node_modules/superjson/dist/double-indexed-kv.js
generated
vendored
Normal file
21
node_modules/superjson/dist/double-indexed-kv.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
export class DoubleIndexedKV {
|
||||
constructor() {
|
||||
this.keyToValue = new Map();
|
||||
this.valueToKey = new Map();
|
||||
}
|
||||
set(key, value) {
|
||||
this.keyToValue.set(key, value);
|
||||
this.valueToKey.set(value, key);
|
||||
}
|
||||
getByKey(key) {
|
||||
return this.keyToValue.get(key);
|
||||
}
|
||||
getByValue(value) {
|
||||
return this.valueToKey.get(value);
|
||||
}
|
||||
clear() {
|
||||
this.keyToValue.clear();
|
||||
this.valueToKey.clear();
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=double-indexed-kv.js.map
|
1
node_modules/superjson/dist/double-indexed-kv.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/double-indexed-kv.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"double-indexed-kv.js","sourceRoot":"","sources":["../src/double-indexed-kv.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,eAAe;IAA5B;QACE,eAAU,GAAG,IAAI,GAAG,EAAQ,CAAC;QAC7B,eAAU,GAAG,IAAI,GAAG,EAAQ,CAAC;IAmB/B,CAAC;IAjBC,GAAG,CAAC,GAAM,EAAE,KAAQ;QAClB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,QAAQ,CAAC,GAAM;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,UAAU,CAAC,KAAQ;QACjB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
46
node_modules/superjson/dist/index.d.ts
generated
vendored
Normal file
46
node_modules/superjson/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Class, JSONValue, SuperJSONResult, SuperJSONValue } from './types.js';
|
||||
import { ClassRegistry, RegisterOptions } from './class-registry.js';
|
||||
import { Registry } from './registry.js';
|
||||
import { CustomTransfomer, CustomTransformerRegistry } from './custom-transformer-registry.js';
|
||||
export default class SuperJSON {
|
||||
/**
|
||||
* If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
|
||||
*/
|
||||
private readonly dedupe;
|
||||
/**
|
||||
* @param dedupeReferentialEqualities If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
|
||||
*/
|
||||
constructor({ dedupe, }?: {
|
||||
dedupe?: boolean;
|
||||
});
|
||||
serialize(object: SuperJSONValue): SuperJSONResult;
|
||||
deserialize<T = unknown>(payload: SuperJSONResult): T;
|
||||
stringify(object: SuperJSONValue): string;
|
||||
parse<T = unknown>(string: string): T;
|
||||
readonly classRegistry: ClassRegistry;
|
||||
registerClass(v: Class, options?: RegisterOptions | string): void;
|
||||
readonly symbolRegistry: Registry<Symbol>;
|
||||
registerSymbol(v: Symbol, identifier?: string): void;
|
||||
readonly customTransformerRegistry: CustomTransformerRegistry;
|
||||
registerCustom<I, O extends JSONValue>(transformer: Omit<CustomTransfomer<I, O>, 'name'>, name: string): void;
|
||||
readonly allowedErrorProps: string[];
|
||||
allowErrorProps(...props: string[]): void;
|
||||
private static defaultInstance;
|
||||
static serialize: (object: SuperJSONValue) => SuperJSONResult;
|
||||
static deserialize: <T = unknown>(payload: SuperJSONResult) => T;
|
||||
static stringify: (object: SuperJSONValue) => string;
|
||||
static parse: <T = unknown>(string: string) => T;
|
||||
static registerClass: (v: Class, options?: string | RegisterOptions | undefined) => void;
|
||||
static registerSymbol: (v: Symbol, identifier?: string | undefined) => void;
|
||||
static registerCustom: <I, O extends JSONValue>(transformer: Omit<CustomTransfomer<I, O>, "name">, name: string) => void;
|
||||
static allowErrorProps: (...props: string[]) => void;
|
||||
}
|
||||
export { SuperJSON, SuperJSONResult };
|
||||
export declare const serialize: (object: SuperJSONValue) => SuperJSONResult;
|
||||
export declare const deserialize: <T = unknown>(payload: SuperJSONResult) => T;
|
||||
export declare const stringify: (object: SuperJSONValue) => string;
|
||||
export declare const parse: <T = unknown>(string: string) => T;
|
||||
export declare const registerClass: (v: Class, options?: string | RegisterOptions | undefined) => void;
|
||||
export declare const registerCustom: <I, O extends JSONValue>(transformer: Omit<CustomTransfomer<I, O>, "name">, name: string) => void;
|
||||
export declare const registerSymbol: (v: Symbol, identifier?: string | undefined) => void;
|
||||
export declare const allowErrorProps: (...props: string[]) => void;
|
89
node_modules/superjson/dist/index.js
generated
vendored
Normal file
89
node_modules/superjson/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
import { ClassRegistry } from './class-registry.js';
|
||||
import { Registry } from './registry.js';
|
||||
import { CustomTransformerRegistry, } from './custom-transformer-registry.js';
|
||||
import { applyReferentialEqualityAnnotations, applyValueAnnotations, generateReferentialEqualityAnnotations, walker, } from './plainer.js';
|
||||
import { copy } from 'copy-anything';
|
||||
export default class SuperJSON {
|
||||
/**
|
||||
* @param dedupeReferentialEqualities If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
|
||||
*/
|
||||
constructor({ dedupe = false, } = {}) {
|
||||
this.classRegistry = new ClassRegistry();
|
||||
this.symbolRegistry = new Registry(s => s.description ?? '');
|
||||
this.customTransformerRegistry = new CustomTransformerRegistry();
|
||||
this.allowedErrorProps = [];
|
||||
this.dedupe = dedupe;
|
||||
}
|
||||
serialize(object) {
|
||||
const identities = new Map();
|
||||
const output = walker(object, identities, this, this.dedupe);
|
||||
const res = {
|
||||
json: output.transformedValue,
|
||||
};
|
||||
if (output.annotations) {
|
||||
res.meta = {
|
||||
...res.meta,
|
||||
values: output.annotations,
|
||||
};
|
||||
}
|
||||
const equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe);
|
||||
if (equalityAnnotations) {
|
||||
res.meta = {
|
||||
...res.meta,
|
||||
referentialEqualities: equalityAnnotations,
|
||||
};
|
||||
}
|
||||
return res;
|
||||
}
|
||||
deserialize(payload) {
|
||||
const { json, meta } = payload;
|
||||
let result = copy(json);
|
||||
if (meta?.values) {
|
||||
result = applyValueAnnotations(result, meta.values, this);
|
||||
}
|
||||
if (meta?.referentialEqualities) {
|
||||
result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
stringify(object) {
|
||||
return JSON.stringify(this.serialize(object));
|
||||
}
|
||||
parse(string) {
|
||||
return this.deserialize(JSON.parse(string));
|
||||
}
|
||||
registerClass(v, options) {
|
||||
this.classRegistry.register(v, options);
|
||||
}
|
||||
registerSymbol(v, identifier) {
|
||||
this.symbolRegistry.register(v, identifier);
|
||||
}
|
||||
registerCustom(transformer, name) {
|
||||
this.customTransformerRegistry.register({
|
||||
name,
|
||||
...transformer,
|
||||
});
|
||||
}
|
||||
allowErrorProps(...props) {
|
||||
this.allowedErrorProps.push(...props);
|
||||
}
|
||||
}
|
||||
SuperJSON.defaultInstance = new SuperJSON();
|
||||
SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance);
|
||||
SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance);
|
||||
SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance);
|
||||
SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance);
|
||||
SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance);
|
||||
SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance);
|
||||
SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance);
|
||||
SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
|
||||
export { SuperJSON };
|
||||
export const serialize = SuperJSON.serialize;
|
||||
export const deserialize = SuperJSON.deserialize;
|
||||
export const stringify = SuperJSON.stringify;
|
||||
export const parse = SuperJSON.parse;
|
||||
export const registerClass = SuperJSON.registerClass;
|
||||
export const registerCustom = SuperJSON.registerCustom;
|
||||
export const registerSymbol = SuperJSON.registerSymbol;
|
||||
export const allowErrorProps = SuperJSON.allowErrorProps;
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/superjson/dist/index.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAmB,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAEL,yBAAyB,GAC1B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,mCAAmC,EACnC,qBAAqB,EACrB,sCAAsC,EACtC,MAAM,GACP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,SAAS;IAM5B;;OAEG;IACH,YAAY,EACV,MAAM,GAAG,KAAK,MAGZ,EAAE;QA2DG,kBAAa,GAAG,IAAI,aAAa,EAAE,CAAC;QAKpC,mBAAc,GAAG,IAAI,QAAQ,CAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;QAKhE,8BAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;QAW5D,sBAAiB,GAAa,EAAE,CAAC;QA/ExC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,SAAS,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AG,SAAS,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CACnE,SAAS,CAAC,eAAe,CAC1B,CAAC;AACK,yBAAe,GAAG,SAAS,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CACrE,SAAS,CAAC,eAAe,CAC1B,CAAC;AAGJ,OAAO,EAAE,SAAS,EAAmB,CAAC;AAEtC,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC;AAEjD,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;AAC7C,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;AAErC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;AACrD,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC"}
|
25
node_modules/superjson/dist/is.d.ts
generated
vendored
Normal file
25
node_modules/superjson/dist/is.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/// <reference types="node" />
|
||||
export declare const isUndefined: (payload: any) => payload is undefined;
|
||||
export declare const isNull: (payload: any) => payload is null;
|
||||
export declare const isPlainObject: (payload: any) => payload is {
|
||||
[key: string]: any;
|
||||
};
|
||||
export declare const isEmptyObject: (payload: any) => payload is {};
|
||||
export declare const isArray: (payload: any) => payload is any[];
|
||||
export declare const isString: (payload: any) => payload is string;
|
||||
export declare const isNumber: (payload: any) => payload is number;
|
||||
export declare const isBoolean: (payload: any) => payload is boolean;
|
||||
export declare const isRegExp: (payload: any) => payload is RegExp;
|
||||
export declare const isMap: (payload: any) => payload is Map<any, any>;
|
||||
export declare const isSet: (payload: any) => payload is Set<any>;
|
||||
export declare const isSymbol: (payload: any) => payload is symbol;
|
||||
export declare const isDate: (payload: any) => payload is Date;
|
||||
export declare const isError: (payload: any) => payload is Error;
|
||||
export declare const isNaNValue: (payload: any) => payload is number;
|
||||
export declare const isPrimitive: (payload: any) => payload is string | number | boolean | symbol | null | undefined;
|
||||
export declare const isBigint: (payload: any) => payload is bigint;
|
||||
export declare const isInfinite: (payload: any) => payload is number;
|
||||
export declare type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
||||
export declare type TypedArray = InstanceType<TypedArrayConstructor>;
|
||||
export declare const isTypedArray: (payload: any) => payload is TypedArray;
|
||||
export declare const isURL: (payload: any) => payload is URL;
|
35
node_modules/superjson/dist/is.js
generated
vendored
Normal file
35
node_modules/superjson/dist/is.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
const getType = (payload) => Object.prototype.toString.call(payload).slice(8, -1);
|
||||
export const isUndefined = (payload) => typeof payload === 'undefined';
|
||||
export const isNull = (payload) => payload === null;
|
||||
export const isPlainObject = (payload) => {
|
||||
if (typeof payload !== 'object' || payload === null)
|
||||
return false;
|
||||
if (payload === Object.prototype)
|
||||
return false;
|
||||
if (Object.getPrototypeOf(payload) === null)
|
||||
return true;
|
||||
return Object.getPrototypeOf(payload) === Object.prototype;
|
||||
};
|
||||
export const isEmptyObject = (payload) => isPlainObject(payload) && Object.keys(payload).length === 0;
|
||||
export const isArray = (payload) => Array.isArray(payload);
|
||||
export const isString = (payload) => typeof payload === 'string';
|
||||
export const isNumber = (payload) => typeof payload === 'number' && !isNaN(payload);
|
||||
export const isBoolean = (payload) => typeof payload === 'boolean';
|
||||
export const isRegExp = (payload) => payload instanceof RegExp;
|
||||
export const isMap = (payload) => payload instanceof Map;
|
||||
export const isSet = (payload) => payload instanceof Set;
|
||||
export const isSymbol = (payload) => getType(payload) === 'Symbol';
|
||||
export const isDate = (payload) => payload instanceof Date && !isNaN(payload.valueOf());
|
||||
export const isError = (payload) => payload instanceof Error;
|
||||
export const isNaNValue = (payload) => typeof payload === 'number' && isNaN(payload);
|
||||
export const isPrimitive = (payload) => isBoolean(payload) ||
|
||||
isNull(payload) ||
|
||||
isUndefined(payload) ||
|
||||
isNumber(payload) ||
|
||||
isString(payload) ||
|
||||
isSymbol(payload);
|
||||
export const isBigint = (payload) => typeof payload === 'bigint';
|
||||
export const isInfinite = (payload) => payload === Infinity || payload === -Infinity;
|
||||
export const isTypedArray = (payload) => ArrayBuffer.isView(payload) && !(payload instanceof DataView);
|
||||
export const isURL = (payload) => payload instanceof URL;
|
||||
//# sourceMappingURL=is.js.map
|
1
node_modules/superjson/dist/is.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/is.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"is.js","sourceRoot":"","sources":["../src/is.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,CAAC,OAAY,EAAU,EAAE,CACvC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAY,EAAwB,EAAE,CAChE,OAAO,OAAO,KAAK,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAY,EAAmB,EAAE,CAAC,OAAO,KAAK,IAAI,CAAC;AAE1E,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAAY,EACuB,EAAE;IACrC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAClE,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,MA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AmB,EAAE,CACtD,OAAO,YAAY,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAY,EAAoB,EAAE,CACxD,OAAO,YAAY,KAAK,CAAC;AAE3B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAY,EAAyB,EAAE,CAChE,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAEhD,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,OAAY,EACsD,EAAE,CACpE,SAAS,CAAC,OAAO,CAAC;IAClB,MAAM,CAAC,OAAO,CAAC;IACf,WAAW,CAAC,OAAO,CAAC;IACpB,QAAQ,CAAC,OAAO,CAAC;IACjB,QAAQ,CAAC,OAAO,CAAC;IACjB,QAAQ,CAAC,OAAO,CAAC,CAAC;AAEpB,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAY,EAAqB,EAAE,CAC1D,OAAO,OAAO,KAAK,QAAQ,CAAC;AAE9B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAY,EAAqB,EAAE,CAC5D,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,QAAQ,CAAC;AAehD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAY,EAAyB,EAAE,CAClE,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,YAAY,QAAQ,CAAC,CAAC;AAEhE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAAY,EAAkB,EAAE,CAAC,OAAO,YAAY,GAAG,CAAC"}
|
6
node_modules/superjson/dist/pathstringifier.d.ts
generated
vendored
Normal file
6
node_modules/superjson/dist/pathstringifier.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export declare type StringifiedPath = string;
|
||||
declare type Path = string[];
|
||||
export declare const escapeKey: (key: string) => string;
|
||||
export declare const stringifyPath: (path: Path) => StringifiedPath;
|
||||
export declare const parsePath: (string: StringifiedPath) => string[];
|
||||
export {};
|
29
node_modules/superjson/dist/pathstringifier.js
generated
vendored
Normal file
29
node_modules/superjson/dist/pathstringifier.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
export const escapeKey = (key) => key.replace(/\./g, '\\.');
|
||||
export const stringifyPath = (path) => path
|
||||
.map(String)
|
||||
.map(escapeKey)
|
||||
.join('.');
|
||||
export const parsePath = (string) => {
|
||||
const result = [];
|
||||
let segment = '';
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
let char = string.charAt(i);
|
||||
const isEscapedDot = char === '\\' && string.charAt(i + 1) === '.';
|
||||
if (isEscapedDot) {
|
||||
segment += '.';
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
const isEndOfSegment = char === '.';
|
||||
if (isEndOfSegment) {
|
||||
result.push(segment);
|
||||
segment = '';
|
||||
continue;
|
||||
}
|
||||
segment += char;
|
||||
}
|
||||
const lastSegment = segment;
|
||||
result.push(lastSegment);
|
||||
return result;
|
||||
};
|
||||
//# sourceMappingURL=pathstringifier.js.map
|
1
node_modules/superjson/dist/pathstringifier.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/pathstringifier.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"pathstringifier.js","sourceRoot":"","sources":["../src/pathstringifier.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAEpE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAU,EAAmB,EAAE,CAC3D,IAAI;KACD,GAAG,CAAC,MAAM,CAAC;KACX,GAAG,CAAC,SAAS,CAAC;KACd,IAAI,CAAC,GAAG,CAAC,CAAC;AAEf,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAuB,EAAE,EAAE;IACnD,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,IAAI,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAE5B,MAAM,YAAY,GAAG,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;QACnE,IAAI,YAAY,EAAE;YAChB,OAAO,IAAI,GAAG,CAAC;YACf,CAAC,EAAE,CAAC;YACJ,SAAS;SACV;QAED,MAAM,cAAc,GAAG,IAAI,KAAK,GAAG,CAAC;QACpC,IAAI,cAAc,EAAE;YAClB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO,GAAG,EAAE,CAAC;YACb,SAAS;SACV;QAED,OAAO,IAAI,IAAI,CAAC;KACjB;IAED,MAAM,WAAW,GAAG,OAAO,CAAC;IAC5B,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEzB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
16
node_modules/superjson/dist/plainer.d.ts
generated
vendored
Normal file
16
node_modules/superjson/dist/plainer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TypeAnnotation } from './transformer.js';
|
||||
import SuperJSON from './index.js';
|
||||
declare type Tree<T> = InnerNode<T> | Leaf<T>;
|
||||
declare type Leaf<T> = [T];
|
||||
declare type InnerNode<T> = [T, Record<string, Tree<T>>];
|
||||
export declare type MinimisedTree<T> = Tree<T> | Record<string, Tree<T>> | undefined;
|
||||
export declare function applyValueAnnotations(plain: any, annotations: MinimisedTree<TypeAnnotation>, superJson: SuperJSON): any;
|
||||
export declare function applyReferentialEqualityAnnotations(plain: any, annotations: ReferentialEqualityAnnotations): any;
|
||||
interface Result {
|
||||
transformedValue: any;
|
||||
annotations?: MinimisedTree<TypeAnnotation>;
|
||||
}
|
||||
export declare type ReferentialEqualityAnnotations = Record<string, string[]> | [string[]] | [string[], Record<string, string[]>];
|
||||
export declare function generateReferentialEqualityAnnotations(identitites: Map<any, any[][]>, dedupe: boolean): ReferentialEqualityAnnotations | undefined;
|
||||
export declare const walker: (object: any, identities: Map<any, any[][]>, superJson: SuperJSON, dedupe: boolean, path?: any[], objectsInThisPath?: any[], seenObjects?: Map<unknown, Result>) => Result;
|
||||
export {};
|
173
node_modules/superjson/dist/plainer.js
generated
vendored
Normal file
173
node_modules/superjson/dist/plainer.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
import { isArray, isEmptyObject, isMap, isPlainObject, isPrimitive, isSet, } from './is.js';
|
||||
import { escapeKey, stringifyPath } from './pathstringifier.js';
|
||||
import { isInstanceOfRegisteredClass, transformValue, untransformValue, } from './transformer.js';
|
||||
import { includes, forEach } from './util.js';
|
||||
import { parsePath } from './pathstringifier.js';
|
||||
import { getDeep, setDeep } from './accessDeep.js';
|
||||
function traverse(tree, walker, origin = []) {
|
||||
if (!tree) {
|
||||
return;
|
||||
}
|
||||
if (!isArray(tree)) {
|
||||
forEach(tree, (subtree, key) => traverse(subtree, walker, [...origin, ...parsePath(key)]));
|
||||
return;
|
||||
}
|
||||
const [nodeValue, children] = tree;
|
||||
if (children) {
|
||||
forEach(children, (child, key) => {
|
||||
traverse(child, walker, [...origin, ...parsePath(key)]);
|
||||
});
|
||||
}
|
||||
walker(nodeValue, origin);
|
||||
}
|
||||
export function applyValueAnnotations(plain, annotations, superJson) {
|
||||
traverse(annotations, (type, path) => {
|
||||
plain = setDeep(plain, path, v => untransformValue(v, type, superJson));
|
||||
});
|
||||
return plain;
|
||||
}
|
||||
export function applyReferentialEqualityAnnotations(plain, annotations) {
|
||||
function apply(identicalPaths, path) {
|
||||
const object = getDeep(plain, parsePath(path));
|
||||
identicalPaths.map(parsePath).forEach(identicalObjectPath => {
|
||||
plain = setDeep(plain, identicalObjectPath, () => object);
|
||||
});
|
||||
}
|
||||
if (isArray(annotations)) {
|
||||
const [root, other] = annotations;
|
||||
root.forEach(identicalPath => {
|
||||
plain = setDeep(plain, parsePath(identicalPath), () => plain);
|
||||
});
|
||||
if (other) {
|
||||
forEach(other, apply);
|
||||
}
|
||||
}
|
||||
else {
|
||||
forEach(annotations, apply);
|
||||
}
|
||||
return plain;
|
||||
}
|
||||
const isDeep = (object, superJson) => isPlainObject(object) ||
|
||||
isArray(object) ||
|
||||
isMap(object) ||
|
||||
isSet(object) ||
|
||||
isInstanceOfRegisteredClass(object, superJson);
|
||||
function addIdentity(object, path, identities) {
|
||||
const existingSet = identities.get(object);
|
||||
if (existingSet) {
|
||||
existingSet.push(path);
|
||||
}
|
||||
else {
|
||||
identities.set(object, [path]);
|
||||
}
|
||||
}
|
||||
export function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
||||
const result = {};
|
||||
let rootEqualityPaths = undefined;
|
||||
identitites.forEach(paths => {
|
||||
if (paths.length <= 1) {
|
||||
return;
|
||||
}
|
||||
// if we're not deduping, all of these objects continue existing.
|
||||
// putting the shortest path first makes it easier to parse for humans
|
||||
// if we're deduping though, only the first entry will still exist, so we can't do this optimisation.
|
||||
if (!dedupe) {
|
||||
paths = paths
|
||||
.map(path => path.map(String))
|
||||
.sort((a, b) => a.length - b.length);
|
||||
}
|
||||
const [representativePath, ...identicalPaths] = paths;
|
||||
if (representativePath.length === 0) {
|
||||
rootEqualityPaths = identicalPaths.map(stringifyPath);
|
||||
}
|
||||
else {
|
||||
result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath);
|
||||
}
|
||||
});
|
||||
if (rootEqualityPaths) {
|
||||
if (isEmptyObject(result)) {
|
||||
return [rootEqualityPaths];
|
||||
}
|
||||
else {
|
||||
return [rootEqualityPaths, result];
|
||||
}
|
||||
}
|
||||
else {
|
||||
return isEmptyObject(result) ? undefined : result;
|
||||
}
|
||||
}
|
||||
export const walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = new Map()) => {
|
||||
const primitive = isPrimitive(object);
|
||||
if (!primitive) {
|
||||
addIdentity(object, path, identities);
|
||||
const seen = seenObjects.get(object);
|
||||
if (seen) {
|
||||
// short-circuit result if we've seen this object before
|
||||
return dedupe
|
||||
? {
|
||||
transformedValue: null,
|
||||
}
|
||||
: seen;
|
||||
}
|
||||
}
|
||||
if (!isDeep(object, superJson)) {
|
||||
const transformed = transformValue(object, superJson);
|
||||
const result = transformed
|
||||
? {
|
||||
transformedValue: transformed.value,
|
||||
annotations: [transformed.type],
|
||||
}
|
||||
: {
|
||||
transformedValue: object,
|
||||
};
|
||||
if (!primitive) {
|
||||
seenObjects.set(object, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (includes(objectsInThisPath, object)) {
|
||||
// prevent circular references
|
||||
return {
|
||||
transformedValue: null,
|
||||
};
|
||||
}
|
||||
const transformationResult = transformValue(object, superJson);
|
||||
const transformed = transformationResult?.value ?? object;
|
||||
const transformedValue = isArray(transformed) ? [] : {};
|
||||
const innerAnnotations = {};
|
||||
forEach(transformed, (value, index) => {
|
||||
if (index === '__proto__' ||
|
||||
index === 'constructor' ||
|
||||
index === 'prototype') {
|
||||
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
||||
}
|
||||
const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects);
|
||||
transformedValue[index] = recursiveResult.transformedValue;
|
||||
if (isArray(recursiveResult.annotations)) {
|
||||
innerAnnotations[index] = recursiveResult.annotations;
|
||||
}
|
||||
else if (isPlainObject(recursiveResult.annotations)) {
|
||||
forEach(recursiveResult.annotations, (tree, key) => {
|
||||
innerAnnotations[escapeKey(index) + '.' + key] = tree;
|
||||
});
|
||||
}
|
||||
});
|
||||
const result = isEmptyObject(innerAnnotations)
|
||||
? {
|
||||
transformedValue,
|
||||
annotations: !!transformationResult
|
||||
? [transformationResult.type]
|
||||
: undefined,
|
||||
}
|
||||
: {
|
||||
transformedValue,
|
||||
annotations: !!transformationResult
|
||||
? [transformationResult.type, innerAnnotations]
|
||||
: innerAnnotations,
|
||||
};
|
||||
if (!primitive) {
|
||||
seenObjects.set(object, result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
//# sourceMappingURL=plainer.js.map
|
1
node_modules/superjson/dist/plainer.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/plainer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
9
node_modules/superjson/dist/registry.d.ts
generated
vendored
Normal file
9
node_modules/superjson/dist/registry.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export declare class Registry<T> {
|
||||
private readonly generateIdentifier;
|
||||
private kv;
|
||||
constructor(generateIdentifier: (v: T) => string);
|
||||
register(value: T, identifier?: string): void;
|
||||
clear(): void;
|
||||
getIdentifier(value: T): string | undefined;
|
||||
getValue(identifier: string): T | undefined;
|
||||
}
|
26
node_modules/superjson/dist/registry.js
generated
vendored
Normal file
26
node_modules/superjson/dist/registry.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { DoubleIndexedKV } from './double-indexed-kv.js';
|
||||
export class Registry {
|
||||
constructor(generateIdentifier) {
|
||||
this.generateIdentifier = generateIdentifier;
|
||||
this.kv = new DoubleIndexedKV();
|
||||
}
|
||||
register(value, identifier) {
|
||||
if (this.kv.getByValue(value)) {
|
||||
return;
|
||||
}
|
||||
if (!identifier) {
|
||||
identifier = this.generateIdentifier(value);
|
||||
}
|
||||
this.kv.set(identifier, value);
|
||||
}
|
||||
clear() {
|
||||
this.kv.clear();
|
||||
}
|
||||
getIdentifier(value) {
|
||||
return this.kv.getByValue(value);
|
||||
}
|
||||
getValue(identifier) {
|
||||
return this.kv.getByKey(identifier);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=registry.js.map
|
1
node_modules/superjson/dist/registry.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/registry.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,OAAO,QAAQ;IAGnB,YAA6B,kBAAoC;QAApC,uBAAkB,GAAlB,kBAAkB,CAAkB;QAFzD,OAAE,GAAG,IAAI,eAAe,EAAa,CAAC;IAEsB,CAAC;IAErE,QAAQ,CAAC,KAAQ,EAAE,UAAmB;QACpC,IAAI,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC7B,OAAO;SACR;QAED,IAAI,CAAC,UAAU,EAAE;YACf,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;SAC7C;QAED,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,aAAa,CAAC,KAAQ;QACpB,OAAO,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,QAAQ,CAAC,UAAkB;QACzB,OAAO,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;CACF"}
|
17
node_modules/superjson/dist/transformer.d.ts
generated
vendored
Normal file
17
node_modules/superjson/dist/transformer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import SuperJSON from './index.js';
|
||||
export declare type PrimitiveTypeAnnotation = 'number' | 'undefined' | 'bigint';
|
||||
declare type LeafTypeAnnotation = PrimitiveTypeAnnotation | 'regexp' | 'Date' | 'Error' | 'URL';
|
||||
declare type TypedArrayAnnotation = ['typed-array', string];
|
||||
declare type ClassTypeAnnotation = ['class', string];
|
||||
declare type SymbolTypeAnnotation = ['symbol', string];
|
||||
declare type CustomTypeAnnotation = ['custom', string];
|
||||
declare type SimpleTypeAnnotation = LeafTypeAnnotation | 'map' | 'set';
|
||||
declare type CompositeTypeAnnotation = TypedArrayAnnotation | ClassTypeAnnotation | SymbolTypeAnnotation | CustomTypeAnnotation;
|
||||
export declare type TypeAnnotation = SimpleTypeAnnotation | CompositeTypeAnnotation;
|
||||
export declare function isInstanceOfRegisteredClass(potentialClass: any, superJson: SuperJSON): potentialClass is any;
|
||||
export declare const transformValue: (value: any, superJson: SuperJSON) => {
|
||||
value: any;
|
||||
type: TypeAnnotation;
|
||||
} | undefined;
|
||||
export declare const untransformValue: (json: any, type: TypeAnnotation, superJson: SuperJSON) => any;
|
||||
export {};
|
197
node_modules/superjson/dist/transformer.js
generated
vendored
Normal file
197
node_modules/superjson/dist/transformer.js
generated
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
import { isBigint, isDate, isInfinite, isMap, isNaNValue, isRegExp, isSet, isUndefined, isSymbol, isArray, isError, isTypedArray, isURL, } from './is.js';
|
||||
import { findArr } from './util.js';
|
||||
function simpleTransformation(isApplicable, annotation, transform, untransform) {
|
||||
return {
|
||||
isApplicable,
|
||||
annotation,
|
||||
transform,
|
||||
untransform,
|
||||
};
|
||||
}
|
||||
const simpleRules = [
|
||||
simpleTransformation(isUndefined, 'undefined', () => null, () => undefined),
|
||||
simpleTransformation(isBigint, 'bigint', v => v.toString(), v => {
|
||||
if (typeof BigInt !== 'undefined') {
|
||||
return BigInt(v);
|
||||
}
|
||||
console.error('Please add a BigInt polyfill.');
|
||||
return v;
|
||||
}),
|
||||
simpleTransformation(isDate, 'Date', v => v.toISOString(), v => new Date(v)),
|
||||
simpleTransformation(isError, 'Error', (v, superJson) => {
|
||||
const baseError = {
|
||||
name: v.name,
|
||||
message: v.message,
|
||||
};
|
||||
superJson.allowedErrorProps.forEach(prop => {
|
||||
baseError[prop] = v[prop];
|
||||
});
|
||||
return baseError;
|
||||
}, (v, superJson) => {
|
||||
const e = new Error(v.message);
|
||||
e.name = v.name;
|
||||
e.stack = v.stack;
|
||||
superJson.allowedErrorProps.forEach(prop => {
|
||||
e[prop] = v[prop];
|
||||
});
|
||||
return e;
|
||||
}),
|
||||
simpleTransformation(isRegExp, 'regexp', v => '' + v, regex => {
|
||||
const body = regex.slice(1, regex.lastIndexOf('/'));
|
||||
const flags = regex.slice(regex.lastIndexOf('/') + 1);
|
||||
return new RegExp(body, flags);
|
||||
}),
|
||||
simpleTransformation(isSet, 'set',
|
||||
// (sets only exist in es6+)
|
||||
// eslint-disable-next-line es5/no-es6-methods
|
||||
v => [...v.values()], v => new Set(v)),
|
||||
simpleTransformation(isMap, 'map', v => [...v.entries()], v => new Map(v)),
|
||||
simpleTransformation((v) => isNaNValue(v) || isInfinite(v), 'number', v => {
|
||||
if (isNaNValue(v)) {
|
||||
return 'NaN';
|
||||
}
|
||||
if (v > 0) {
|
||||
return 'Infinity';
|
||||
}
|
||||
else {
|
||||
return '-Infinity';
|
||||
}
|
||||
}, Number),
|
||||
simpleTransformation((v) => v === 0 && 1 / v === -Infinity, 'number', () => {
|
||||
return '-0';
|
||||
}, Number),
|
||||
simpleTransformation(isURL, 'URL', v => v.toString(), v => new URL(v)),
|
||||
];
|
||||
function compositeTransformation(isApplicable, annotation, transform, untransform) {
|
||||
return {
|
||||
isApplicable,
|
||||
annotation,
|
||||
transform,
|
||||
untransform,
|
||||
};
|
||||
}
|
||||
const symbolRule = compositeTransformation((s, superJson) => {
|
||||
if (isSymbol(s)) {
|
||||
const isRegistered = !!superJson.symbolRegistry.getIdentifier(s);
|
||||
return isRegistered;
|
||||
}
|
||||
return false;
|
||||
}, (s, superJson) => {
|
||||
const identifier = superJson.symbolRegistry.getIdentifier(s);
|
||||
return ['symbol', identifier];
|
||||
}, v => v.description, (_, a, superJson) => {
|
||||
const value = superJson.symbolRegistry.getValue(a[1]);
|
||||
if (!value) {
|
||||
throw new Error('Trying to deserialize unknown symbol');
|
||||
}
|
||||
return value;
|
||||
});
|
||||
const constructorToName = [
|
||||
Int8Array,
|
||||
Uint8Array,
|
||||
Int16Array,
|
||||
Uint16Array,
|
||||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array,
|
||||
Uint8ClampedArray,
|
||||
].reduce((obj, ctor) => {
|
||||
obj[ctor.name] = ctor;
|
||||
return obj;
|
||||
}, {});
|
||||
const typedArrayRule = compositeTransformation(isTypedArray, v => ['typed-array', v.constructor.name], v => [...v], (v, a) => {
|
||||
const ctor = constructorToName[a[1]];
|
||||
if (!ctor) {
|
||||
throw new Error('Trying to deserialize unknown typed array');
|
||||
}
|
||||
return new ctor(v);
|
||||
});
|
||||
export function isInstanceOfRegisteredClass(potentialClass, superJson) {
|
||||
if (potentialClass?.constructor) {
|
||||
const isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor);
|
||||
return isRegistered;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => {
|
||||
const identifier = superJson.classRegistry.getIdentifier(clazz.constructor);
|
||||
return ['class', identifier];
|
||||
}, (clazz, superJson) => {
|
||||
const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor);
|
||||
if (!allowedProps) {
|
||||
return { ...clazz };
|
||||
}
|
||||
const result = {};
|
||||
allowedProps.forEach(prop => {
|
||||
result[prop] = clazz[prop];
|
||||
});
|
||||
return result;
|
||||
}, (v, a, superJson) => {
|
||||
const clazz = superJson.classRegistry.getValue(a[1]);
|
||||
if (!clazz) {
|
||||
throw new Error(`Trying to deserialize unknown class '${a[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
|
||||
}
|
||||
return Object.assign(Object.create(clazz.prototype), v);
|
||||
});
|
||||
const customRule = compositeTransformation((value, superJson) => {
|
||||
return !!superJson.customTransformerRegistry.findApplicable(value);
|
||||
}, (value, superJson) => {
|
||||
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
||||
return ['custom', transformer.name];
|
||||
}, (value, superJson) => {
|
||||
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
||||
return transformer.serialize(value);
|
||||
}, (v, a, superJson) => {
|
||||
const transformer = superJson.customTransformerRegistry.findByName(a[1]);
|
||||
if (!transformer) {
|
||||
throw new Error('Trying to deserialize unknown custom value');
|
||||
}
|
||||
return transformer.deserialize(v);
|
||||
});
|
||||
const compositeRules = [classRule, symbolRule, customRule, typedArrayRule];
|
||||
export const transformValue = (value, superJson) => {
|
||||
const applicableCompositeRule = findArr(compositeRules, rule => rule.isApplicable(value, superJson));
|
||||
if (applicableCompositeRule) {
|
||||
return {
|
||||
value: applicableCompositeRule.transform(value, superJson),
|
||||
type: applicableCompositeRule.annotation(value, superJson),
|
||||
};
|
||||
}
|
||||
const applicableSimpleRule = findArr(simpleRules, rule => rule.isApplicable(value, superJson));
|
||||
if (applicableSimpleRule) {
|
||||
return {
|
||||
value: applicableSimpleRule.transform(value, superJson),
|
||||
type: applicableSimpleRule.annotation,
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
const simpleRulesByAnnotation = {};
|
||||
simpleRules.forEach(rule => {
|
||||
simpleRulesByAnnotation[rule.annotation] = rule;
|
||||
});
|
||||
export const untransformValue = (json, type, superJson) => {
|
||||
if (isArray(type)) {
|
||||
switch (type[0]) {
|
||||
case 'symbol':
|
||||
return symbolRule.untransform(json, type, superJson);
|
||||
case 'class':
|
||||
return classRule.untransform(json, type, superJson);
|
||||
case 'custom':
|
||||
return customRule.untransform(json, type, superJson);
|
||||
case 'typed-array':
|
||||
return typedArrayRule.untransform(json, type, superJson);
|
||||
default:
|
||||
throw new Error('Unknown transformation: ' + type);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const transformation = simpleRulesByAnnotation[type];
|
||||
if (!transformation) {
|
||||
throw new Error('Unknown transformation: ' + type);
|
||||
}
|
||||
return transformation.untransform(json, superJson);
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=transformer.js.map
|
1
node_modules/superjson/dist/transformer.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/transformer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
28
node_modules/superjson/dist/types.d.ts
generated
vendored
Normal file
28
node_modules/superjson/dist/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { TypeAnnotation } from './transformer.js';
|
||||
import { MinimisedTree, ReferentialEqualityAnnotations } from './plainer.js';
|
||||
export declare type Class = {
|
||||
new (...args: any[]): any;
|
||||
};
|
||||
export declare type PrimitiveJSONValue = string | number | boolean | undefined | null;
|
||||
export declare type JSONValue = PrimitiveJSONValue | JSONArray | JSONObject;
|
||||
export interface JSONArray extends Array<JSONValue> {
|
||||
}
|
||||
export interface JSONObject {
|
||||
[key: string]: JSONValue;
|
||||
}
|
||||
declare type ClassInstance = any;
|
||||
export declare type SerializableJSONValue = Symbol | Set<SuperJSONValue> | Map<SuperJSONValue, SuperJSONValue> | undefined | bigint | Date | ClassInstance | RegExp;
|
||||
export declare type SuperJSONValue = JSONValue | SerializableJSONValue | SuperJSONArray | SuperJSONObject;
|
||||
export interface SuperJSONArray extends Array<SuperJSONValue> {
|
||||
}
|
||||
export interface SuperJSONObject {
|
||||
[key: string]: SuperJSONValue;
|
||||
}
|
||||
export interface SuperJSONResult {
|
||||
json: JSONValue;
|
||||
meta?: {
|
||||
values?: MinimisedTree<TypeAnnotation>;
|
||||
referentialEqualities?: ReferentialEqualityAnnotations;
|
||||
};
|
||||
}
|
||||
export {};
|
2
node_modules/superjson/dist/types.js
generated
vendored
Normal file
2
node_modules/superjson/dist/types.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=types.js.map
|
1
node_modules/superjson/dist/types.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/types.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
4
node_modules/superjson/dist/util.d.ts
generated
vendored
Normal file
4
node_modules/superjson/dist/util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export declare function find<T>(record: Record<string, T>, predicate: (v: T) => boolean): T | undefined;
|
||||
export declare function forEach<T>(record: Record<string, T>, run: (v: T, key: string) => void): void;
|
||||
export declare function includes<T>(arr: T[], value: T): boolean;
|
||||
export declare function findArr<T>(record: T[], predicate: (v: T) => boolean): T | undefined;
|
45
node_modules/superjson/dist/util.js
generated
vendored
Normal file
45
node_modules/superjson/dist/util.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
function valuesOfObj(record) {
|
||||
if ('values' in Object) {
|
||||
// eslint-disable-next-line es5/no-es6-methods
|
||||
return Object.values(record);
|
||||
}
|
||||
const values = [];
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const key in record) {
|
||||
if (record.hasOwnProperty(key)) {
|
||||
values.push(record[key]);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
export function find(record, predicate) {
|
||||
const values = valuesOfObj(record);
|
||||
if ('find' in values) {
|
||||
// eslint-disable-next-line es5/no-es6-methods
|
||||
return values.find(predicate);
|
||||
}
|
||||
const valuesNotNever = values;
|
||||
for (let i = 0; i < valuesNotNever.length; i++) {
|
||||
const value = valuesNotNever[i];
|
||||
if (predicate(value)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
export function forEach(record, run) {
|
||||
Object.entries(record).forEach(([key, value]) => run(value, key));
|
||||
}
|
||||
export function includes(arr, value) {
|
||||
return arr.indexOf(value) !== -1;
|
||||
}
|
||||
export function findArr(record, predicate) {
|
||||
for (let i = 0; i < record.length; i++) {
|
||||
const value = record[i];
|
||||
if (predicate(value)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
//# sourceMappingURL=util.js.map
|
1
node_modules/superjson/dist/util.js.map
generated
vendored
Normal file
1
node_modules/superjson/dist/util.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,SAAS,WAAW,CAAI,MAAyB;IAC/C,IAAI,QAAQ,IAAI,MAAM,EAAE;QACtB,8CAA8C;QAC9C,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KAC9B;IAED,MAAM,MAAM,GAAQ,EAAE,CAAC;IAEvB,gDAAgD;IAChD,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;QACxB,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YAC9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;SAC1B;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,MAAyB,EACzB,SAA4B;IAE5B,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,MAAM,IAAI,MAAM,EAAE;QACpB,8CAA8C;QAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC/B;IAED,MAAM,cAAc,GAAG,MAAa,CAAC;IAErC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC9C,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;YACpB,OAAO,KAAK,CAAC;SACd;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,OAAO,CACrB,MAAyB,EACzB,GAAgC;IAEhC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,QAAQ,CAAI,GAAQ,EAAE,KAAQ;IAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,OAAO,CACrB,MAAW,EACX,SAA4B;IAE5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;YACpB,OAAO,KAAK,CAAC;SACd;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
79
node_modules/superjson/package.json
generated
vendored
Normal file
79
node_modules/superjson/package.json
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"version": "2.2.2",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "./dist/index.js",
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "vitest run",
|
||||
"lint": "tsdx lint",
|
||||
"prepack": "yarn build",
|
||||
"prepare": "husky install",
|
||||
"publish-please": "publish-please",
|
||||
"prepublishOnly": "publish-please guard"
|
||||
},
|
||||
"importSort": {
|
||||
".ts": {
|
||||
"style": "module"
|
||||
}
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 80,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5"
|
||||
},
|
||||
"name": "superjson",
|
||||
"author": {
|
||||
"name": "Simon Knott",
|
||||
"email": "info@simonknott.de",
|
||||
"url": "https://simonknott.de"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Dylan Brookes",
|
||||
"email": "dylan@brookes.net",
|
||||
"url": "https://github.com/merelinguist"
|
||||
},
|
||||
{
|
||||
"name": "Brandon Bayer",
|
||||
"email": "b@bayer.w",
|
||||
"url": "https://twitter.com/flybayer"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/blitz-js/superjson"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/debug": "^4.1.5",
|
||||
"@types/mongodb": "^3.6.12",
|
||||
"@types/node": "^18.7.18",
|
||||
"benchmark": "^2.1.4",
|
||||
"decimal.js": "^10.3.1",
|
||||
"eslint-plugin-es5": "^1.5.0",
|
||||
"husky": "^6.0.0",
|
||||
"mongodb": "^3.6.6",
|
||||
"publish-please": "^5.5.2",
|
||||
"tsdx": "^0.14.1",
|
||||
"typescript": "^4.2.4",
|
||||
"vitest": "^0.34.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"copy-anything": "^3.0.2"
|
||||
},
|
||||
"resolutions": {
|
||||
"**/@typescript-eslint/eslint-plugin": "^4.11.1",
|
||||
"**/@typescript-eslint/parser": "^4.11.1"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user