Skip to content

Commit 2dd9f60

Browse files
authored
Use JSON types from @croct/json (#122)
This commit also removes support for passing undefined properties in operations to keep it consistent with other places accepting JSON values.
1 parent 13ca858 commit 2dd9f60

File tree

10 files changed

+9467
-2535
lines changed

10 files changed

+9467
-2535
lines changed

package-lock.json

+9,444-2,505
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"build": "tsc"
2929
},
3030
"dependencies": {
31+
"@croct/json": "^1.0",
3132
"tslib": "^2.3.1"
3233
},
3334
"devDependencies": {

renovate.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"github>croct-tech/renovate-public-presets:js"
4+
]
5+
}

src/activeRecord.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import {JsonStructure, JsonValue} from '@croct/json';
12
import {Operation, Patch} from './patch';
2-
import {JsonArray, JsonObject, JsonValue} from './json';
33
import {TrackingEvent} from './trackingEvents';
44
import {
55
addOperation,
@@ -64,16 +64,16 @@ export abstract class ActiveRecord<T extends TrackingEvent> {
6464
});
6565
}
6666

67-
public merge(value: JsonObject | JsonArray): this;
67+
public merge(value: JsonStructure): this;
6868

69-
public merge(property: string, value: JsonObject | JsonArray): this;
69+
public merge(property: string, value: JsonStructure): this;
7070

71-
public merge(propertyOrValue: string | JsonObject | JsonArray, value?: JsonObject | JsonArray): this {
71+
public merge(propertyOrValue: string | JsonStructure, value?: JsonStructure): this {
7272
if (typeof propertyOrValue === 'string') {
7373
return this.pushOperation({
7474
type: 'merge',
7575
path: propertyOrValue,
76-
value: value as JsonObject | JsonArray,
76+
value: value as JsonStructure,
7777
});
7878
}
7979

src/evaluator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {JsonObject, JsonValue} from './json';
1+
import {JsonObject, JsonValue} from '@croct/json';
22
import {TokenProvider} from './token';
33
import {EVALUATION_ENDPOINT_URL, MAX_EXPRESSION_LENGTH} from './constants';
44
import {formatMessage} from './error';

src/facade/evaluatorFacade.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import {JsonObject, JsonValue} from '@croct/json';
12
import {Evaluator, Campaign, EvaluationContext, Page} from '../evaluator';
2-
import {JsonObject, JsonValue} from '../json';
33
import {Tab} from '../tab';
44
import {optionsSchema} from '../schema';
55
import {formatCause} from '../error';

src/json.ts

-13
This file was deleted.

src/patch.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {LenientJsonArray, LenientJsonObject, LenientJsonValue} from './json';
1+
import {JsonStructure, JsonValue} from '@croct/json';
22

33
interface AbstractOperation {
44
type: string;
@@ -15,37 +15,37 @@ interface ClearOperation extends AbstractOperation {
1515

1616
interface SetOperation extends AbstractOperation {
1717
type: 'set';
18-
value: LenientJsonValue;
18+
value: JsonValue;
1919
}
2020

2121
interface AddOperation extends AbstractOperation {
2222
type: 'add';
23-
value: LenientJsonValue;
23+
value: JsonValue;
2424
}
2525

2626
interface CombineOperation extends AbstractOperation {
2727
type: 'combine';
28-
value: LenientJsonValue;
28+
value: JsonValue;
2929
}
3030

3131
interface MergeOperation extends AbstractOperation {
3232
type: 'merge';
33-
value: LenientJsonArray | LenientJsonObject;
33+
value: JsonStructure;
3434
}
3535

3636
interface IncrementOperation extends AbstractOperation {
3737
type: 'increment';
38-
value: LenientJsonValue;
38+
value: JsonValue;
3939
}
4040

4141
interface DecrementOperation extends AbstractOperation {
4242
type: 'decrement';
43-
value: LenientJsonValue;
43+
value: JsonValue;
4444
}
4545

4646
interface removeOperation extends AbstractOperation {
4747
type: 'remove';
48-
value: LenientJsonValue;
48+
value: JsonValue;
4949
}
5050

5151
export type Operation =

src/validation/jsonType.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import {JsonArray, JsonObject, JsonPrimitive, JsonValue} from '@croct/json';
12
import {Schema, TypeSchema, Violation} from './schema';
2-
import {JsonArray, JsonObject, JsonPrimitive, JsonValue} from '../json';
33
import {describe, formatPath} from './violation';
44

55
function isJsonPrimitive(value: unknown): value is JsonPrimitive {

test/facade/evaluatorFacade.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import {JsonObject} from '@croct/json';
12
import {EvaluatorFacade, MinimalContextFactory, TabContextFactory} from '../../src/facade';
23
import {Evaluator, Campaign, EvaluationOptions, Page} from '../../src/evaluator';
34
import {Tab} from '../../src/tab';
4-
import {JsonObject} from '../../src/json';
55

66
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
77

0 commit comments

Comments
 (0)