Initial commit

This commit is contained in:
Ammaar Reshi
2025-01-04 14:06:53 +00:00
parent 7082408604
commit d6025af146
23760 changed files with 3299690 additions and 0 deletions

21
node_modules/postgres-range/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Abbas Mashayekh
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.

82
node_modules/postgres-range/README.md generated vendored Normal file
View File

@ -0,0 +1,82 @@
# postgres-range [![tests](https://github.com/martianboy/postgres-range/workflows/tests/badge.svg)](https://github.com/martianboy/postgres-range/actions?query=workflow%3Atests)
> Parse postgres range columns
## Install
```
npm install --save postgres-range
```
## Usage
```js
const range = require('postgres-range')
const rng = range.parse('[0,5)', (value) => parseInt(value, 10))
rng.isBounded()
// => true
rng.isLowerBoundClosed()
// => true
rng.isUpperBoundClosed()
// => false
rng.hasLowerBound()
// => true
rng.hasUpperBound()
// => true
rng.containsPoint(4)
// => true
rng.containsRange(range.parse('[1,2]', x => parseInt(x)))
// => true
range.parse('empty').isEmpty()
// => true
range.serialize(new range.Range(0, 5))
// => '(0,5)'
range.serialize(new range.Range(0, 5, range.RANGE_LB_INC | RANGE_UB_INC))
// => '[0,5]'
```
## API
#### `parse(input, [transform])` -> `Range`
##### input
*Required*
Type: `string`
A Postgres range string.
##### transform
Type: `function`
Default: `identity`
A function that transforms non-null bounds of the range.
#### `serialize(range, [format])` -> `string`
##### range
*Required*
Type: `Range`
A `Range` object.
##### format
Type: `function`
Default: `identity`
A function that formats non-null bounds of the range.
## License
MIT © [Abbas Mashayekh](http://github.com/martianboy)

28
node_modules/postgres-range/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,28 @@
export const RANGE_EMPTY = 2
export const RANGE_LB_INC = 4
export const RANGE_UB_INC = 8
export const RANGE_LB_INF = 16
export const RANGE_UB_INF = 32
export class Range<T> {
constructor(lower: T | null, upper: T | null, mask: number);
lower: T | null;
upper: T | null;
hasMask (flag: number): boolean;
isEmpty (): boolean;
isBounded (): boolean;
isLowerBoundClosed (): boolean;
isUpperBoundClosed (): boolean;
hasLowerBound (): boolean;
hasUpperBound (): boolean;
containsPoint (point: T): boolean;
containsRange (range: Range<T>): boolean;
toPostgres (prepareValue: (value: any) => string): string;
}
export function parse(input: string): Range<string>;
export function parse<T>(source: string, transform: (value: string) => T): Range<T>;
export function serialize<T>(range: Range<T>): string;
export function serialize<T>(range: Range<T>, format: (value: T) => string): string;

327
node_modules/postgres-range/index.js generated vendored Normal file
View File

@ -0,0 +1,327 @@
'use strict'
const RANGE_EMPTY = 1 << 1
const RANGE_LB_INC = 1 << 2
const RANGE_UB_INC = 1 << 3
const RANGE_LB_INF = (1 << 4)
const RANGE_UB_INF = (1 << 5)
const EMPTY = 'empty'
const INFINITY = 'infinity'
class RangeError extends Error {}
class Range {
constructor (lower, upper, mask = 0) {
this.lower = lower
this.upper = upper
this.mask = mask
}
/**
* @param {number} flag
*/
hasMask (flag) {
return (this.mask & flag) === flag
}
isEmpty () {
return this.hasMask(RANGE_EMPTY)
}
isBounded () {
return !this.hasMask(RANGE_LB_INF) && !this.hasMask(RANGE_UB_INF)
}
isLowerBoundClosed () {
return this.hasLowerBound() && this.hasMask(RANGE_LB_INC)
}
isUpperBoundClosed () {
return this.hasUpperBound() && this.hasMask(RANGE_UB_INC)
}
hasLowerBound () {
return !this.hasMask(RANGE_LB_INF)
}
hasUpperBound () {
return !this.hasMask(RANGE_UB_INF)
}
containsPoint (point) {
const l = this.hasLowerBound()
const u = this.hasUpperBound()
if (l && u) {
const inLower = this.hasMask(RANGE_LB_INC)
? this.lower <= point
: this.lower < point
const inUpper = this.hasMask(RANGE_UB_INC)
? this.upper >= point
: this.upper > point
return inLower && inUpper
} else if (l) {
return this.hasMask(RANGE_LB_INC)
? this.lower <= point
: this.lower < point
} else if (u) {
return this.hasMask(RANGE_UB_INC)
? this.upper >= point
: this.upper > point
}
// INFINITY
return true
}
/**
* @param {Range} range
*/
containsRange (range) {
return (
(!range.hasLowerBound() || this.containsPoint(range.lower)) &&
(!range.hasUpperBound() || this.containsPoint(range.upper))
)
}
toPostgres (prepareValue) {
return serialize(this, prepareValue);
}
}
/**
* @param {string} input
* @returns {Range}
*/
function parse (input, transform = x => x) {
input = input.trim()
if (input === EMPTY) {
return new Range(null, null, RANGE_EMPTY)
}
let ptr = 0
let mask = 0
if (input[ptr] === '[') {
mask |= RANGE_LB_INC
ptr += 1
} else if (input[ptr] === '(') {
ptr += 1
} else {
throw new RangeError(
`Unexpected character '${input[ptr]}'. Position: ${ptr}`
)
}
const lb = parseBound(input, ptr)
if (lb.infinite) {
mask |= RANGE_LB_INF
}
ptr = lb.ptr
if (input[ptr] === ',') {
ptr += 1
} else {
throw new RangeError(
`Expected comma as the delimiter, got '${input[ptr]}'. Position: ${ptr}`
)
}
const ub = parseBound(input, ptr)
if (ub.infinite) {
mask |= RANGE_UB_INF
}
ptr = ub.ptr
if (input[ptr] === ']') {
mask |= RANGE_UB_INC
ptr += 1
} else if (input[ptr] === ')') {
ptr += 1
} else {
throw new RangeError(
`Unexpected character '${input[ptr]}'. Position: ${ptr}`
)
}
let lower = null
let upper = null
if ((mask & RANGE_LB_INF) !== RANGE_LB_INF) {
lower = transform(lb.value)
}
if ((mask & RANGE_UB_INF) !== RANGE_UB_INF) {
upper = transform(ub.value)
}
return new Range(lower, upper, mask)
}
/**
* @param {string} input
* @param {number} ptr
* @returns {{ value: string | null; infinite: boolean; ptr: number }}
*/
function parseBound (input, ptr) {
if (input[ptr] === ',' || input[ptr] === ')' || input[ptr] === ']') {
return {
infinite: true,
value: null,
ptr
}
} else {
let inQuote = false
let value = ''
let pos = ptr
while (
inQuote ||
!(input[ptr] === ',' || input[ptr] === ')' || input[ptr] === ']')
) {
const ch = input[ptr++]
if (ch === undefined) {
throw new RangeError(`Unexpected end of input. Position: ${ptr}`)
}
if (ch === '\\') {
if (input[ptr] === undefined) {
throw new RangeError(`Unexpected end of input. Position: ${ptr}`)
}
value += input.slice(pos, ptr - 1) + input[ptr]
ptr += 1
pos = ptr
} else if (ch === '"') {
if (!inQuote) {
inQuote = true
pos += 1
} else if (input[ptr] === '"') {
value += input.slice(pos, ptr - 1) + input[ptr]
ptr += 1
pos = ptr
} else {
inQuote = false
value += input.slice(pos, ptr - 1)
pos = ptr + 1
}
}
}
if (ptr > pos) {
value += input.slice(pos, ptr)
}
if (value.endsWith(INFINITY)) {
return {
infinite: true,
value: null,
ptr
}
}
return {
infinite: false,
value,
ptr
}
}
}
/**
* @param {Range} range
*/
function serialize (range, format = x => x) {
if (range.hasMask(RANGE_EMPTY)) {
return EMPTY
}
let s = ''
s += range.isLowerBoundClosed() ? '[' : '('
s += range.hasLowerBound() ? serializeBound(format(range.lower)) : ''
s += ','
s += range.hasUpperBound() ? serializeBound(format(range.upper)) : ''
s += range.isUpperBoundClosed() ? ']' : ')'
return s
}
/**
* @param {any} bnd
*/
function serializeBound (bnd) {
let needsQuotes = false
let pos = 0
let value = ''
if (typeof bnd !== 'string') {
if (typeof bnd === 'number' || typeof bnd === 'bigint') return bnd.toString()
bnd = String(bnd)
}
if (bnd === null || bnd.length === 0) {
return '""'
}
bnd = bnd.trim()
for (let i = 0; i < bnd.length; i++) {
const ch = bnd[i]
if (
ch === '"' ||
ch === '\\' ||
ch === '(' ||
ch === ')' ||
ch === '[' ||
ch === ']' ||
ch === ',' ||
ch === ' '
) {
needsQuotes = true
break
}
}
if (needsQuotes) {
value += '"'
}
let ptr = 0
for (; ptr < bnd.length; ptr++) {
const ch = bnd[ptr]
if (ch === '"' || ch === '\\') {
value += bnd.slice(pos, ptr + 1) + ch
pos = ptr + 1
}
}
if (ptr > pos) {
value += bnd.slice(pos, ptr)
}
if (needsQuotes) {
value += '"'
}
return value
}
module.exports = {
Range,
RangeError,
RANGE_EMPTY,
RANGE_LB_INC,
RANGE_UB_INC,
RANGE_LB_INF,
RANGE_UB_INF,
parse,
serialize
}

19
node_modules/postgres-range/package.json generated vendored Normal file
View File

@ -0,0 +1,19 @@
{
"name": "postgres-range",
"version": "1.1.4",
"description": "Range data type parser and serializer for PostgreSQL",
"main": "index.js",
"repository": "https://github.com/martianboy/postgres-range",
"author": "Abbas Mashayekh <martianboy2005@gmail.com>",
"license": "MIT",
"scripts": {
"test": "standard && tape test.js | tap-spec"
},
"devDependencies": {
"@types/tape": "^4.13.2",
"standard": "^17.0.0",
"tap-spec": "^5.0.0",
"tape": "^5.5.3",
"typescript": "^4.7.3"
}
}