@dalgo/dalgo2postgrest 0.0.0-bootstrap.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -2
- package/README.md +404 -4
- package/dist/capabilities.d.ts +129 -0
- package/dist/capabilities.js +78 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/cursor.d.ts +60 -0
- package/dist/cursor.js +261 -0
- package/dist/cursor.js.map +1 -0
- package/dist/database.d.ts +95 -0
- package/dist/database.js +730 -0
- package/dist/database.js.map +1 -0
- package/dist/discovery.d.ts +111 -0
- package/dist/discovery.js +235 -0
- package/dist/discovery.js.map +1 -0
- package/dist/fields.d.ts +20 -0
- package/dist/fields.js +32 -0
- package/dist/fields.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +25 -0
- package/dist/json.js +114 -0
- package/dist/json.js.map +1 -0
- package/package.json +50 -7
package/dist/json.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON parsing that refuses numbers JavaScript cannot carry losslessly.
|
|
3
|
+
*
|
|
4
|
+
* `JSON.parse` silently rounds before any reviver sees a value: an integer such
|
|
5
|
+
* as `9007199254740993` becomes `9007199254740992`, and a decimal such as
|
|
6
|
+
* `0.10000000000000001` becomes `0.1`. For a DALgo key, a keyset order value or
|
|
7
|
+
* record data that changes the identity or the value of a row, and for a cursor
|
|
8
|
+
* boundary it can repeat or skip an actual row. The raw text is therefore
|
|
9
|
+
* checked before parsing instead of trying to detect the loss afterwards.
|
|
10
|
+
*
|
|
11
|
+
* The policy is exact: a number token is accepted only when the decimal value
|
|
12
|
+
* it denotes is the same decimal value the adapter would serialize back
|
|
13
|
+
* (`String(Number(token))`), and when it neither underflows to zero, overflows
|
|
14
|
+
* to a non-finite value, becomes -0, nor denotes an integer outside the safe
|
|
15
|
+
* range. Textual spellings of one decimal value are equivalent, so `1`, `1.0`
|
|
16
|
+
* and `1e0` are all accepted, while `0.10000000000000001` and `1e-400` are
|
|
17
|
+
* refused. The thrown error deliberately carries no number or row value.
|
|
18
|
+
*/
|
|
19
|
+
export class PostgrestJsonNumberError extends TypeError {
|
|
20
|
+
constructor() {
|
|
21
|
+
super("PostgREST JSON contains a number that JavaScript cannot round-trip without losing precision");
|
|
22
|
+
this.name = "PostgrestJsonNumberError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const NUMBER = /^(-?)(0|[1-9]\d*)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/u;
|
|
26
|
+
function decimalValue(token) {
|
|
27
|
+
const match = NUMBER.exec(token);
|
|
28
|
+
if (match === null)
|
|
29
|
+
throw new PostgrestJsonNumberError();
|
|
30
|
+
const [, sign = "", integer = "", fraction = "", exponent = "0"] = match;
|
|
31
|
+
const all = `${integer}${fraction}`;
|
|
32
|
+
const significant = all.replace(/^0+/u, "");
|
|
33
|
+
if (significant.length === 0) {
|
|
34
|
+
// Every digit is zero, so the written exponent cannot change the value.
|
|
35
|
+
return { negative: sign === "-", digits: "", exponent: 0 };
|
|
36
|
+
}
|
|
37
|
+
const digits = significant.replace(/0+$/u, "");
|
|
38
|
+
return {
|
|
39
|
+
negative: sign === "-",
|
|
40
|
+
digits,
|
|
41
|
+
exponent: Number(exponent) - fraction.length + (significant.length - digits.length),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function sameDecimal(left, right) {
|
|
45
|
+
return left.negative === right.negative
|
|
46
|
+
&& left.digits === right.digits
|
|
47
|
+
&& left.exponent === right.exponent;
|
|
48
|
+
}
|
|
49
|
+
function checkNumber(token) {
|
|
50
|
+
const value = Number(token);
|
|
51
|
+
// Non-finite values, underflow to zero, and a negative zero sign all change
|
|
52
|
+
// the literal that would be sent back.
|
|
53
|
+
if (!Number.isFinite(value) || Object.is(value, -0))
|
|
54
|
+
throw new PostgrestJsonNumberError();
|
|
55
|
+
// A decimal or exponent token can still denote an integer, e.g. 9007199254740993.0
|
|
56
|
+
// or 1e21; the adapter only carries integers in the safe range.
|
|
57
|
+
if (Number.isInteger(value) && !Number.isSafeInteger(value))
|
|
58
|
+
throw new PostgrestJsonNumberError();
|
|
59
|
+
if (!sameDecimal(decimalValue(token), decimalValue(String(value)))) {
|
|
60
|
+
throw new PostgrestJsonNumberError();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function assertLosslessNumbers(text) {
|
|
64
|
+
let index = 0;
|
|
65
|
+
while (index < text.length) {
|
|
66
|
+
const code = text.charCodeAt(index);
|
|
67
|
+
if (code === 0x22) {
|
|
68
|
+
// Skip a JSON string, including escaped quotes and backslashes, so digits
|
|
69
|
+
// inside a string value are never mistaken for number literals.
|
|
70
|
+
index += 1;
|
|
71
|
+
while (index < text.length) {
|
|
72
|
+
const character = text.charCodeAt(index);
|
|
73
|
+
if (character === 0x5c) {
|
|
74
|
+
index += 2;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
index += 1;
|
|
78
|
+
if (character === 0x22)
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (code === 0x2d || (code >= 0x30 && code <= 0x39)) {
|
|
84
|
+
const start = index;
|
|
85
|
+
index += 1;
|
|
86
|
+
while (index < text.length) {
|
|
87
|
+
const character = text.charCodeAt(index);
|
|
88
|
+
if ((character >= 0x30 && character <= 0x39)
|
|
89
|
+
|| character === 0x2b // +
|
|
90
|
+
|| character === 0x2d // -
|
|
91
|
+
|| character === 0x2e // .
|
|
92
|
+
|| character === 0x45 // E
|
|
93
|
+
|| character === 0x65) { // e
|
|
94
|
+
index += 1;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
checkNumber(text.slice(start, index));
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
index += 1;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Parses JSON after proving every number literal survives the round trip exactly. */
|
|
106
|
+
export function parseLosslessJson(text) {
|
|
107
|
+
assertLosslessNumbers(text);
|
|
108
|
+
return JSON.parse(text);
|
|
109
|
+
}
|
|
110
|
+
/** True for a native number the adapter must not emit without losing precision. */
|
|
111
|
+
export function isUnsafeNativeNumber(value) {
|
|
112
|
+
return Number.isInteger(value) && !Number.isSafeInteger(value);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=json.js.map
|
package/dist/json.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,wBAAyB,SAAQ,SAAS;IACrD;QACE,KAAK,CAAC,6FAA6F,CAAC,CAAC;QACrG,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAWD,MAAM,MAAM,GAAG,oDAAoD,CAAC;AAEpE,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,IAAI,wBAAwB,EAAE,CAAC;IACzD,MAAM,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,QAAQ,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC;IACzE,MAAM,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,EAAE,CAAC;IACpC,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5C,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,wEAAwE;QACxE,OAAO,EAAE,QAAQ,EAAE,IAAI,KAAK,GAAG,EAAE,MAAM,EAAE,EAAE,EAA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KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;YACtC,SAAS;QACX,CAAC;QACD,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;AACrC,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalgo/dalgo2postgrest",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "PostgREST HTTP adapter for DALgo TypeScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"packageManager": "pnpm@11.20.0",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.build.json",
|
|
21
|
+
"build:deps": "pnpm --filter \"@dalgo/dalgo2postgrest...\" run build",
|
|
22
|
+
"check": "eslint . && vitest run && tsc -p tsconfig.build.json && tsc -p tsconfig.examples.json",
|
|
23
|
+
"lint": "eslint .",
|
|
24
|
+
"prepack": "npm --prefix ../adapter-runtime run build && npm run build",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:browser": "pnpm run build:deps && node scripts/real-postgrest-browser.mjs",
|
|
27
|
+
"test:real": "node scripts/real-postgrest.mjs"
|
|
28
|
+
},
|
|
6
29
|
"repository": {
|
|
7
30
|
"type": "git",
|
|
8
31
|
"url": "git+https://github.com/dal-go/dalgo-http-adapters.git",
|
|
9
32
|
"directory": "packages/postgrest"
|
|
10
33
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/dal-go/dalgo-http-adapters/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/dal-go/dalgo-http-adapters/tree/main/packages/postgrest#readme",
|
|
38
|
+
"license": "MIT",
|
|
15
39
|
"publishConfig": {
|
|
16
40
|
"access": "public",
|
|
17
41
|
"registry": "https://registry.npmjs.org"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=24"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@dalgo/adapter-runtime": ">=0.1.0 <1.0.0",
|
|
48
|
+
"@dalgo/core": ">=0.7.4 <0.9.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@dalgo/adapter-runtime": "workspace:^",
|
|
52
|
+
"@dalgo/core": "^0.7.4",
|
|
53
|
+
"@eslint/js": "10.0.1",
|
|
54
|
+
"@playwright/test": "1.64.1",
|
|
55
|
+
"@types/node": "26.6.5",
|
|
56
|
+
"esbuild": "0.28.2",
|
|
57
|
+
"eslint": "10.11.0",
|
|
58
|
+
"typescript": "6.0.3",
|
|
59
|
+
"typescript-eslint": "8.70.0",
|
|
60
|
+
"vitest": "5.0.1"
|
|
18
61
|
}
|
|
19
62
|
}
|