Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 618a96e

Browse files
authored
chore(orm): export JSON types (#476)
1 parent 96629ed commit 618a96e

10 files changed

Lines changed: 32 additions & 34 deletions

File tree

packages/orm/src/client/crud-types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ExpressionBuilder, OperandExpression, SqlBool } from 'kysely';
2+
import type { DbNull, JsonNull, JsonNullValues, JsonValue } from '../common-types';
23
import type {
34
BuiltinType,
45
FieldDef,
@@ -32,8 +33,6 @@ import type {
3233
} from '../schema';
3334
import type {
3435
AtLeast,
35-
JsonNullValues,
36-
JsonValue,
3736
MapBaseType,
3837
NonEmptyArray,
3938
NullableIf,
@@ -45,7 +44,6 @@ import type {
4544
WrapType,
4645
XOR,
4746
} from '../utils/type-utils';
48-
import type { DbNull, JsonNull } from './null-values';
4947
import type { ClientOptions } from './options';
5048
import type { ToKyselySchema } from './query-builder';
5149

packages/orm/src/client/crud/dialects/base-dialect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { enumerate, invariant, isPlainObject } from '@zenstackhq/common-helpers'
22
import type { Expression, ExpressionBuilder, ExpressionWrapper, SqlBool, ValueNode } from 'kysely';
33
import { expressionBuilder, sql, type SelectQueryBuilder } from 'kysely';
44
import { match, P } from 'ts-pattern';
5+
import { AnyNullClass, DbNullClass, JsonNullClass } from '../../../common-types';
56
import type { BuiltinType, DataSourceProviderType, FieldDef, GetModels, ModelDef, SchemaDef } from '../../../schema';
67
import type { OrArray } from '../../../utils/type-utils';
78
import { AGGREGATE_OPERATORS, DELEGATE_JOINED_FIELD_PREFIX, LOGICAL_COMBINATORS } from '../../constants';
@@ -15,7 +16,6 @@ import type {
1516
StringFilter,
1617
} from '../../crud-types';
1718
import { createConfigError, createInvalidInputError, createNotSupportedError } from '../../errors';
18-
import { AnyNullClass, DbNullClass, JsonNullClass } from '../../null-values';
1919
import type { ClientOptions } from '../../options';
2020
import {
2121
aggregate,

packages/orm/src/client/crud/dialects/postgresql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
} from 'kysely';
1212
import { match } from 'ts-pattern';
1313
import z from 'zod';
14+
import { AnyNullClass, DbNullClass, JsonNullClass } from '../../../common-types';
1415
import type { BuiltinType, FieldDef, GetModels, SchemaDef } from '../../../schema';
1516
import { DELEGATE_JOINED_FIELD_PREFIX } from '../../constants';
1617
import type { FindArgs } from '../../crud-types';
1718
import { createInternalError } from '../../errors';
18-
import { AnyNullClass, DbNullClass, JsonNullClass } from '../../null-values';
1919
import type { ClientOptions } from '../../options';
2020
import {
2121
buildJoinPairs,

packages/orm/src/client/crud/dialects/sqlite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
type SqlBool,
1111
} from 'kysely';
1212
import { match } from 'ts-pattern';
13+
import { AnyNullClass, DbNullClass, JsonNullClass } from '../../../common-types';
1314
import type { BuiltinType, FieldDef, GetModels, SchemaDef } from '../../../schema';
1415
import { DELEGATE_JOINED_FIELD_PREFIX } from '../../constants';
1516
import type { FindArgs } from '../../crud-types';
1617
import { createInternalError } from '../../errors';
17-
import { AnyNullClass, DbNullClass, JsonNullClass } from '../../null-values';
1818
import {
1919
getDelegateDescendantModels,
2020
getManyToManyRelation,

packages/orm/src/client/crud/validator/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Decimal from 'decimal.js';
33
import stableStringify from 'json-stable-stringify';
44
import { match, P } from 'ts-pattern';
55
import { z, ZodType } from 'zod';
6+
import { AnyNullClass, DbNullClass, JsonNullClass } from '../../../common-types';
67
import {
78
type AttributeApplication,
89
type BuiltinType,
@@ -32,7 +33,6 @@ import {
3233
type UpsertArgs,
3334
} from '../../crud-types';
3435
import { createInternalError, createInvalidInputError } from '../../errors';
35-
import { AnyNullClass, DbNullClass, JsonNullClass } from '../../null-values';
3636
import {
3737
fieldHasDefaultValue,
3838
getDiscriminatorField,

packages/orm/src/client/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export type * from './crud-types';
44
export { getCrudDialect } from './crud/dialects';
55
export { BaseCrudDialect } from './crud/dialects/base-dialect';
66
export { ORMError, ORMErrorReason, RejectedByPolicyReason } from './errors';
7-
export { AnyNull, DbNull, JsonNull } from './null-values';
87
export * from './options';
98
export * from './plugin';
109
export type { ZenStackPromise } from './promise';

packages/orm/src/client/null-values.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/orm/src/common-types.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export type JsonValue = string | number | boolean | JsonObject | JsonArray;
2+
export type JsonObject = { [key: string]: JsonValue | null };
3+
export type JsonArray = ReadonlyArray<JsonValue | null>;
4+
export type JsonNullValues = DbNull | JsonNull | AnyNull;
5+
6+
export class DbNullClass {
7+
// @ts-ignore
8+
private __brand = 'DbNull' as const;
9+
}
10+
export const DbNull = new DbNullClass();
11+
export type DbNull = typeof DbNull;
12+
13+
export class JsonNullClass {
14+
// @ts-ignore
15+
private __brand = 'JsonNull' as const;
16+
}
17+
export const JsonNull = new JsonNullClass();
18+
export type JsonNull = typeof JsonNull;
19+
20+
export class AnyNullClass {
21+
// @ts-ignore
22+
private __brand = 'AnyNull' as const;
23+
}
24+
export const AnyNull = new AnyNullClass();
25+
export type AnyNull = typeof AnyNull;

packages/orm/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './client';
2+
export * from './common-types';
23
export * as KyselyUtils from './utils/kysely-utils';
34
export * as SchemaUtils from './utils/schema-utils';
4-
export type { JsonArray, JsonObject, JsonValue } from './utils/type-utils';

packages/orm/src/utils/type-utils.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type Decimal from 'decimal.js';
2-
import type { AnyNull, DbNull, JsonNull } from '../client/null-values';
2+
import type { JsonObject, JsonValue } from '../common-types';
33

44
export type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
55

@@ -45,13 +45,6 @@ type TypeMap = {
4545

4646
export type MapBaseType<T extends string> = T extends keyof TypeMap ? TypeMap[T] : unknown;
4747

48-
export type JsonValue = string | number | boolean | JsonObject | JsonArray;
49-
50-
export type JsonObject = { [key: string]: JsonValue | null };
51-
export type JsonArray = ReadonlyArray<JsonValue | null>;
52-
53-
export type JsonNullValues = DbNull | JsonNull | AnyNull;
54-
5548
export function call(code: string) {
5649
return { code };
5750
}

0 commit comments

Comments
 (0)