@powersync/service-jsonbig 0.17.10
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 +67 -0
- package/README.md +19 -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 +5 -0
- package/dist/json.js +37 -0
- package/dist/json.js.map +1 -0
- package/dist/json_container.d.ts +18 -0
- package/dist/json_container.js +27 -0
- package/dist/json_container.js.map +1 -0
- package/dist/json_stringify.d.ts +36 -0
- package/dist/json_stringify.js +167 -0
- package/dist/json_stringify.js.map +1 -0
- package/package.json +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2023-2024 Journey Mobile, Inc.
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
|
|
20
|
+
|
|
21
|
+
### License Grant
|
|
22
|
+
|
|
23
|
+
Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below.
|
|
24
|
+
|
|
25
|
+
### Permitted Purpose
|
|
26
|
+
|
|
27
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that:
|
|
28
|
+
|
|
29
|
+
1. substitutes for the Software;
|
|
30
|
+
2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or
|
|
31
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
32
|
+
|
|
33
|
+
Permitted Purposes specifically include using the Software:
|
|
34
|
+
|
|
35
|
+
1. for your internal use and access;
|
|
36
|
+
2. for non-commercial education;
|
|
37
|
+
3. for non-commercial research; and
|
|
38
|
+
4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions.
|
|
39
|
+
|
|
40
|
+
### Patents
|
|
41
|
+
|
|
42
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately.
|
|
43
|
+
|
|
44
|
+
### Redistribution
|
|
45
|
+
|
|
46
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of the Software.
|
|
47
|
+
If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software.
|
|
48
|
+
|
|
49
|
+
### Disclaimer
|
|
50
|
+
|
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
52
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
53
|
+
|
|
54
|
+
### Trademarks
|
|
55
|
+
|
|
56
|
+
Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names.
|
|
57
|
+
|
|
58
|
+
## Grant of Future License
|
|
59
|
+
|
|
60
|
+
We hereby irrevocably grant you an additional license to use the Software under the Apache License, Version 2.0 that is effective on the second anniversary of the date we make the Software available. On or after that date, you may use the Software under the Apache License, Version 2.0, in which case the following will apply:
|
|
61
|
+
|
|
62
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
|
63
|
+
You may obtain a copy of the License at
|
|
64
|
+
|
|
65
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
66
|
+
|
|
67
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# powersync-jsonbig
|
|
2
|
+
|
|
3
|
+
JSON is used everywhere, including:
|
|
4
|
+
1. PostgreSQL (json/jsonb types)
|
|
5
|
+
2. Sync rules input (values are normalized to JSON text).
|
|
6
|
+
3. Sync rule transformations (extracting values, constructing objects in the future)
|
|
7
|
+
4. Persisting data in the database.
|
|
8
|
+
5. Sending to the client.
|
|
9
|
+
|
|
10
|
+
Where we can, JSON data is kept as strings and not parsed.
|
|
11
|
+
This is so that:
|
|
12
|
+
1. We don't add parsing / serializing overhead.
|
|
13
|
+
2. We don't change the data.
|
|
14
|
+
|
|
15
|
+
Specifically:
|
|
16
|
+
1. The SQLite type system makes a distinction between INTEGER and REAL values. We try to preserve this.
|
|
17
|
+
2. Integers in SQLite can be up to 64-bit.
|
|
18
|
+
|
|
19
|
+
For this, we use a custom parser, and use BigInt for all integers, and number for floats.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/json.d.ts
ADDED
package/dist/json.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as json from 'lossless-json';
|
|
2
|
+
import { isInteger } from 'lossless-json';
|
|
3
|
+
import { JsonContainer } from './json_container.js';
|
|
4
|
+
import { stringify } from './json_stringify.js';
|
|
5
|
+
const numberParser = (value) => {
|
|
6
|
+
return isInteger(value) ? BigInt(value) : parseFloat(value);
|
|
7
|
+
};
|
|
8
|
+
const numberStringifier = {
|
|
9
|
+
test: (value) => typeof value == 'number',
|
|
10
|
+
stringify: (value) => {
|
|
11
|
+
const text = value.toString();
|
|
12
|
+
if (isInteger(text)) {
|
|
13
|
+
// Used to preserve the "type".
|
|
14
|
+
return text + '.0';
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return text;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
// Avoid a parse + serialize round-trip for JSON data.
|
|
22
|
+
const jsonContainerStringifier = {
|
|
23
|
+
test: (value) => value instanceof JsonContainer,
|
|
24
|
+
stringify: (value) => {
|
|
25
|
+
return value.toString();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const stringifiers = [numberStringifier, jsonContainerStringifier];
|
|
29
|
+
export const JSONBig = {
|
|
30
|
+
parse(text, reviver) {
|
|
31
|
+
return json.parse(text, reviver, numberParser);
|
|
32
|
+
},
|
|
33
|
+
stringify(value, replacer, space) {
|
|
34
|
+
return stringify(value, replacer, space, stringifiers);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
//# 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,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,SAAS,EAAoD,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store a JSON text value. Used to mark the value as JSON-sourced, but only parse if really needed.
|
|
3
|
+
*/
|
|
4
|
+
export declare class JsonContainer {
|
|
5
|
+
readonly data: string;
|
|
6
|
+
constructor(data: string);
|
|
7
|
+
parsed(): unknown;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @returns The JSON representation
|
|
11
|
+
*/
|
|
12
|
+
toString(): string;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @returns The parsed representation
|
|
16
|
+
*/
|
|
17
|
+
toJSON(): unknown;
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { JSONBig } from './json.js';
|
|
2
|
+
/**
|
|
3
|
+
* Store a JSON text value. Used to mark the value as JSON-sourced, but only parse if really needed.
|
|
4
|
+
*/
|
|
5
|
+
export class JsonContainer {
|
|
6
|
+
constructor(data) {
|
|
7
|
+
this.data = data;
|
|
8
|
+
}
|
|
9
|
+
parsed() {
|
|
10
|
+
return JSONBig.parse(this.data);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @returns The JSON representation
|
|
15
|
+
*/
|
|
16
|
+
toString() {
|
|
17
|
+
return this.data;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @returns The parsed representation
|
|
22
|
+
*/
|
|
23
|
+
toJSON() {
|
|
24
|
+
return this.parsed();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=json_container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json_container.js","sourceRoot":"","sources":["../src/json_container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,aAAa;IAGxB,YAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,MAAM;QACJ,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Replacer, NumberStringifier, JavaScriptValue } from 'lossless-json';
|
|
2
|
+
/**
|
|
3
|
+
* The LosslessJSON.stringify() method converts a JavaScript value to a JSON string,
|
|
4
|
+
* optionally replacing values if a replacer function is specified, or
|
|
5
|
+
* optionally including only the specified properties if a replacer array is specified.
|
|
6
|
+
*
|
|
7
|
+
* @param value
|
|
8
|
+
* The value to convert to a JSON string.
|
|
9
|
+
*
|
|
10
|
+
* @param [replacer]
|
|
11
|
+
* A function that alters the behavior of the stringification process,
|
|
12
|
+
* or an array of String and Number objects that serve as a whitelist for
|
|
13
|
+
* selecting the properties of the value object to be included in the JSON string.
|
|
14
|
+
* If this value is null or not provided, all properties of the object are
|
|
15
|
+
* included in the resulting JSON string.
|
|
16
|
+
*
|
|
17
|
+
* @param [space]
|
|
18
|
+
* A String or Number object that's used to insert white space into the output
|
|
19
|
+
* JSON string for readability purposes. If this is a Number, it indicates the
|
|
20
|
+
* number of space characters to use as white space; this number is capped at 10
|
|
21
|
+
* if it's larger than that. Values less than 1 indicate that no space should be
|
|
22
|
+
* used. If this is a String, the string (or the first 10 characters of the string,
|
|
23
|
+
* if it's longer than that) is used as white space. If this parameter is not
|
|
24
|
+
* provided (or is null), no white space is used.
|
|
25
|
+
*
|
|
26
|
+
* @param [numberStringifiers]
|
|
27
|
+
* An optional list with additional number stringifiers, for example to serialize
|
|
28
|
+
* a BigNumber. The output of the function must be valid stringified JSON.
|
|
29
|
+
* When `undefined` is returned, the property will be deleted from the object.
|
|
30
|
+
* The difference with using a `replacer` is that the output of a `replacer`
|
|
31
|
+
* must be JSON and will be stringified afterwards, whereas the output of the
|
|
32
|
+
* `numberStringifiers` is already stringified JSON.
|
|
33
|
+
*
|
|
34
|
+
* @returns Returns the string representation of the JSON object.
|
|
35
|
+
*/
|
|
36
|
+
export declare function stringify(value: JavaScriptValue, replacer?: Replacer, space?: number | string, numberStringifiers?: NumberStringifier[]): string | undefined;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Adapted from https://github.com/josdejong/lossless-json/blob/dfb8a1a787ae167fffec068c3b6623179d3bfb95/src/stringify.ts
|
|
2
|
+
import { isNumber } from 'lossless-json';
|
|
3
|
+
/**
|
|
4
|
+
* The LosslessJSON.stringify() method converts a JavaScript value to a JSON string,
|
|
5
|
+
* optionally replacing values if a replacer function is specified, or
|
|
6
|
+
* optionally including only the specified properties if a replacer array is specified.
|
|
7
|
+
*
|
|
8
|
+
* @param value
|
|
9
|
+
* The value to convert to a JSON string.
|
|
10
|
+
*
|
|
11
|
+
* @param [replacer]
|
|
12
|
+
* A function that alters the behavior of the stringification process,
|
|
13
|
+
* or an array of String and Number objects that serve as a whitelist for
|
|
14
|
+
* selecting the properties of the value object to be included in the JSON string.
|
|
15
|
+
* If this value is null or not provided, all properties of the object are
|
|
16
|
+
* included in the resulting JSON string.
|
|
17
|
+
*
|
|
18
|
+
* @param [space]
|
|
19
|
+
* A String or Number object that's used to insert white space into the output
|
|
20
|
+
* JSON string for readability purposes. If this is a Number, it indicates the
|
|
21
|
+
* number of space characters to use as white space; this number is capped at 10
|
|
22
|
+
* if it's larger than that. Values less than 1 indicate that no space should be
|
|
23
|
+
* used. If this is a String, the string (or the first 10 characters of the string,
|
|
24
|
+
* if it's longer than that) is used as white space. If this parameter is not
|
|
25
|
+
* provided (or is null), no white space is used.
|
|
26
|
+
*
|
|
27
|
+
* @param [numberStringifiers]
|
|
28
|
+
* An optional list with additional number stringifiers, for example to serialize
|
|
29
|
+
* a BigNumber. The output of the function must be valid stringified JSON.
|
|
30
|
+
* When `undefined` is returned, the property will be deleted from the object.
|
|
31
|
+
* The difference with using a `replacer` is that the output of a `replacer`
|
|
32
|
+
* must be JSON and will be stringified afterwards, whereas the output of the
|
|
33
|
+
* `numberStringifiers` is already stringified JSON.
|
|
34
|
+
*
|
|
35
|
+
* @returns Returns the string representation of the JSON object.
|
|
36
|
+
*/
|
|
37
|
+
export function stringify(value, replacer, space, numberStringifiers) {
|
|
38
|
+
const resolvedSpace = resolveSpace(space);
|
|
39
|
+
const replacedValue = typeof replacer === 'function' ? replacer.call({ '': value }, '', value) : value;
|
|
40
|
+
return stringifyValue(replacedValue, '');
|
|
41
|
+
/**
|
|
42
|
+
* Stringify a value
|
|
43
|
+
*/
|
|
44
|
+
function stringifyValue(value, indent) {
|
|
45
|
+
if (Array.isArray(numberStringifiers)) {
|
|
46
|
+
const stringifier = numberStringifiers.find((item) => item.test(value));
|
|
47
|
+
if (stringifier) {
|
|
48
|
+
const str = stringifier.stringify(value);
|
|
49
|
+
if (typeof str !== 'string' || (!isNumber(str) && false)) {
|
|
50
|
+
// Changed: The number check is disabled, so that we can use this for other types.
|
|
51
|
+
throw new Error('Invalid JSON number: ' +
|
|
52
|
+
'output of a number stringifier must be a string containing a JSON number ' +
|
|
53
|
+
`(output: ${str})`);
|
|
54
|
+
}
|
|
55
|
+
return str;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// boolean, null, number, string, or date
|
|
59
|
+
if (typeof value === 'boolean' ||
|
|
60
|
+
typeof value === 'number' ||
|
|
61
|
+
typeof value === 'string' ||
|
|
62
|
+
value === null ||
|
|
63
|
+
value instanceof Date ||
|
|
64
|
+
value instanceof Boolean ||
|
|
65
|
+
value instanceof Number ||
|
|
66
|
+
value instanceof String) {
|
|
67
|
+
return JSON.stringify(value);
|
|
68
|
+
}
|
|
69
|
+
// lossless number, the secret ingredient :)
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
if (value && value.isLosslessNumber) {
|
|
73
|
+
return value.toString();
|
|
74
|
+
}
|
|
75
|
+
// BigInt
|
|
76
|
+
if (typeof value === 'bigint') {
|
|
77
|
+
return value.toString();
|
|
78
|
+
}
|
|
79
|
+
// Array
|
|
80
|
+
if (Array.isArray(value)) {
|
|
81
|
+
return stringifyArray(value, indent);
|
|
82
|
+
}
|
|
83
|
+
// Object (test lastly!)
|
|
84
|
+
if (value && typeof value === 'object') {
|
|
85
|
+
return stringifyObject(value, indent);
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Stringify an array
|
|
91
|
+
*/
|
|
92
|
+
function stringifyArray(array, indent) {
|
|
93
|
+
if (array.length === 0) {
|
|
94
|
+
return '[]';
|
|
95
|
+
}
|
|
96
|
+
const childIndent = resolvedSpace ? indent + resolvedSpace : undefined;
|
|
97
|
+
let str = resolvedSpace ? '[\n' : '[';
|
|
98
|
+
for (let i = 0; i < array.length; i++) {
|
|
99
|
+
const item = typeof replacer === 'function' ? replacer.call(array, String(i), array[i]) : array[i];
|
|
100
|
+
if (resolvedSpace) {
|
|
101
|
+
str += childIndent;
|
|
102
|
+
}
|
|
103
|
+
if (typeof item !== 'undefined' && typeof item !== 'function') {
|
|
104
|
+
str += stringifyValue(item, childIndent);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
str += 'null';
|
|
108
|
+
}
|
|
109
|
+
if (i < array.length - 1) {
|
|
110
|
+
str += resolvedSpace ? ',\n' : ',';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
str += resolvedSpace ? '\n' + indent + ']' : ']';
|
|
114
|
+
return str;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Stringify an object
|
|
118
|
+
*/
|
|
119
|
+
function stringifyObject(object, indent) {
|
|
120
|
+
if (typeof object.toJSON === 'function') {
|
|
121
|
+
return stringify(object.toJSON(), replacer, space, numberStringifiers);
|
|
122
|
+
}
|
|
123
|
+
const keys = Array.isArray(replacer) ? replacer.map(String) : Object.keys(object);
|
|
124
|
+
if (keys.length === 0) {
|
|
125
|
+
return '{}';
|
|
126
|
+
}
|
|
127
|
+
const childIndent = resolvedSpace ? indent + resolvedSpace : undefined;
|
|
128
|
+
let first = true;
|
|
129
|
+
let str = resolvedSpace ? '{\n' : '{';
|
|
130
|
+
keys.forEach((key) => {
|
|
131
|
+
const value = typeof replacer === 'function' ? replacer.call(object, key, object[key]) : object[key];
|
|
132
|
+
if (includeProperty(key, value)) {
|
|
133
|
+
if (first) {
|
|
134
|
+
first = false;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
str += resolvedSpace ? ',\n' : ',';
|
|
138
|
+
}
|
|
139
|
+
const keyStr = JSON.stringify(key);
|
|
140
|
+
str += resolvedSpace ? childIndent + keyStr + ': ' : keyStr + ':';
|
|
141
|
+
str += stringifyValue(value, childIndent);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
str += resolvedSpace ? '\n' + indent + '}' : '}';
|
|
145
|
+
return str;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Test whether to include a property in a stringified object or not.
|
|
149
|
+
*/
|
|
150
|
+
function includeProperty(key, value) {
|
|
151
|
+
return typeof value !== 'undefined' && typeof value !== 'function' && typeof value !== 'symbol';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Resolve a JSON stringify space:
|
|
156
|
+
* replace a number with a string containing that number of spaces
|
|
157
|
+
*/
|
|
158
|
+
function resolveSpace(space) {
|
|
159
|
+
if (typeof space === 'number') {
|
|
160
|
+
return ' '.repeat(space);
|
|
161
|
+
}
|
|
162
|
+
if (typeof space === 'string' && space !== '') {
|
|
163
|
+
return space;
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=json_stringify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KAC1B;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,EAAE;QAC7C,OAAO,KAAK,CAAC;KACd;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@powersync/service-jsonbig",
|
|
3
|
+
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
|
+
"version": "0.17.10",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**/*"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"lossless-json": "^2.0.8"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rm -r ./dist && tsc -b --clean",
|
|
21
|
+
"build": "tsc -b"
|
|
22
|
+
}
|
|
23
|
+
}
|