turbine-orm 0.81.0 → 0.90.0
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/README.md +26 -25
- package/dist/checkout.d.ts +27 -2
- package/dist/checkout.js +75 -4
- package/dist/cjs/checkout.d.ts +27 -2
- package/dist/cjs/checkout.js +76 -3
- package/dist/cjs/cli/code-first-tags.d.ts +62 -0
- package/dist/cjs/cli/code-first-tags.js +124 -0
- package/dist/cjs/cli/compile-query.js +9 -0
- package/dist/cjs/cli/config.d.ts +35 -6
- package/dist/cjs/cli/config.js +17 -1
- package/dist/cjs/cli/destructive.d.ts +7 -4
- package/dist/cjs/cli/destructive.js +224 -20
- package/dist/cjs/cli/error-catalog.js +36 -0
- package/dist/cjs/cli/error-text.d.ts +15 -0
- package/dist/cjs/cli/error-text.js +40 -0
- package/dist/cjs/cli/index.d.ts +62 -4
- package/dist/cjs/cli/index.js +568 -108
- package/dist/cjs/cli/local-server-guard.d.ts +53 -0
- package/dist/cjs/cli/local-server-guard.js +119 -0
- package/dist/cjs/cli/local-server-output.d.ts +41 -0
- package/dist/cjs/cli/local-server-output.js +103 -0
- package/dist/cjs/cli/mcp.d.ts +8 -0
- package/dist/cjs/cli/mcp.js +121 -32
- package/dist/cjs/cli/migrate.d.ts +113 -5
- package/dist/cjs/cli/migrate.js +270 -21
- package/dist/cjs/cli/observe.d.ts +6 -1
- package/dist/cjs/cli/observe.js +85 -55
- package/dist/cjs/cli/pii-predicate-guard.d.ts +43 -23
- package/dist/cjs/cli/pii-predicate-guard.js +98 -37
- package/dist/cjs/cli/prisma-resolve.js +17 -13
- package/dist/cjs/cli/prisma-schema.js +12 -4
- package/dist/cjs/cli/studio-ui.generated.js +1 -1
- package/dist/cjs/cli/studio.d.ts +14 -2
- package/dist/cjs/cli/studio.js +244 -69
- package/dist/cjs/cli/ui.d.ts +1 -1
- package/dist/cjs/client.d.ts +558 -85
- package/dist/cjs/client.js +1270 -395
- package/dist/cjs/connection-guard.d.ts +13 -0
- package/dist/cjs/connection-guard.js +28 -0
- package/dist/cjs/connection-url.d.ts +51 -16
- package/dist/cjs/connection-url.js +67 -34
- package/dist/cjs/diagnostics.d.ts +81 -0
- package/dist/cjs/diagnostics.js +147 -0
- package/dist/cjs/dialect.d.ts +449 -20
- package/dist/cjs/dialect.js +117 -76
- package/dist/cjs/engine-config.d.ts +7 -6
- package/dist/cjs/errors.d.ts +126 -6
- package/dist/cjs/errors.js +256 -13
- package/dist/cjs/generate.d.ts +57 -7
- package/dist/cjs/generate.js +635 -279
- package/dist/cjs/global-filters-config.d.ts +59 -0
- package/dist/cjs/global-filters-config.js +367 -0
- package/dist/cjs/index.d.ts +9 -4
- package/dist/cjs/index.js +10 -2
- package/dist/cjs/introspect.d.ts +31 -6
- package/dist/cjs/introspect.js +108 -50
- package/dist/cjs/log-codes.d.ts +12 -0
- package/dist/cjs/log-codes.js +77 -0
- package/dist/cjs/logger.d.ts +87 -0
- package/dist/cjs/logger.js +98 -0
- package/dist/cjs/mssql.d.ts +8 -5
- package/dist/cjs/mssql.js +352 -65
- package/dist/cjs/mysql.d.ts +3 -5
- package/dist/cjs/mysql.js +420 -70
- package/dist/cjs/nested-write.d.ts +3 -0
- package/dist/cjs/nested-write.js +179 -114
- package/dist/cjs/pipeline-submittable.d.ts +12 -0
- package/dist/cjs/pipeline-submittable.js +118 -44
- package/dist/cjs/pipeline.js +21 -26
- package/dist/cjs/powdb-introspect.d.ts +5 -2
- package/dist/cjs/powdb-introspect.js +20 -15
- package/dist/cjs/powdb-shared.d.ts +36 -5
- package/dist/cjs/powdb-shared.js +67 -8
- package/dist/cjs/powdb.d.ts +4 -0
- package/dist/cjs/powdb.js +183 -51
- package/dist/cjs/powql.d.ts +394 -51
- package/dist/cjs/powql.js +1829 -284
- package/dist/cjs/prisma-compat.d.ts +23 -15
- package/dist/cjs/prisma-compat.js +507 -372
- package/dist/cjs/query/aggregates.d.ts +17 -1
- package/dist/cjs/query/aggregates.js +261 -29
- package/dist/cjs/query/batched-loader.d.ts +25 -6
- package/dist/cjs/query/batched-loader.js +103 -20
- package/dist/cjs/query/builder.d.ts +325 -184
- package/dist/cjs/query/builder.js +1452 -490
- package/dist/cjs/query/column-ref.d.ts +61 -0
- package/dist/cjs/query/column-ref.js +73 -0
- package/dist/cjs/query/compound-unique.d.ts +21 -0
- package/dist/cjs/query/compound-unique.js +98 -18
- package/dist/cjs/query/deferred.d.ts +53 -16
- package/dist/cjs/query/expr.d.ts +217 -0
- package/dist/cjs/query/expr.js +859 -0
- package/dist/cjs/query/filters.d.ts +155 -53
- package/dist/cjs/query/filters.js +613 -76
- package/dist/cjs/query/index.d.ts +2 -0
- package/dist/cjs/query/index.js +7 -1
- package/dist/cjs/query/json-value.d.ts +43 -0
- package/dist/cjs/query/json-value.js +59 -0
- package/dist/cjs/query/normalize-args.d.ts +87 -0
- package/dist/cjs/query/normalize-args.js +527 -0
- package/dist/cjs/query/option-surface.d.ts +16 -4
- package/dist/cjs/query/option-surface.js +57 -14
- package/dist/cjs/query/relation-names.d.ts +14 -0
- package/dist/cjs/query/relation-names.js +77 -18
- package/dist/cjs/query/relations.d.ts +30 -3
- package/dist/cjs/query/relations.js +219 -63
- package/dist/cjs/query/row-lock.d.ts +49 -0
- package/dist/cjs/query/row-lock.js +138 -0
- package/dist/cjs/query/sql-comment.d.ts +161 -0
- package/dist/cjs/query/sql-comment.js +381 -0
- package/dist/cjs/query/stream-idle.d.ts +132 -0
- package/dist/cjs/query/stream-idle.js +212 -0
- package/dist/cjs/query/table-client.d.ts +101 -0
- package/dist/cjs/query/table-client.js +74 -0
- package/dist/cjs/query/types.d.ts +677 -298
- package/dist/cjs/query/utils.d.ts +105 -6
- package/dist/cjs/query/utils.js +426 -19
- package/dist/cjs/query/warn-registry.d.ts +18 -0
- package/dist/cjs/query/warn-registry.js +18 -0
- package/dist/cjs/query/where-compile.d.ts +138 -14
- package/dist/cjs/query/where-compile.js +513 -29
- package/dist/cjs/query/where.d.ts +159 -59
- package/dist/cjs/query/where.js +716 -246
- package/dist/cjs/query/writes.d.ts +112 -50
- package/dist/cjs/query/writes.js +1498 -200
- package/dist/cjs/query-events.d.ts +4 -2
- package/dist/cjs/query-events.js +3 -1
- package/dist/cjs/realtime.d.ts +7 -3
- package/dist/cjs/realtime.js +13 -2
- package/dist/cjs/schema-builder.d.ts +55 -4
- package/dist/cjs/schema-builder.js +382 -18
- package/dist/cjs/schema-metadata.d.ts +21 -1
- package/dist/cjs/schema-metadata.js +29 -7
- package/dist/cjs/schema-sql.d.ts +75 -5
- package/dist/cjs/schema-sql.js +497 -45
- package/dist/cjs/schema.d.ts +26 -5
- package/dist/cjs/schema.js +110 -13
- package/dist/cjs/sql-placeholders.d.ts +56 -0
- package/dist/cjs/sql-placeholders.js +204 -0
- package/dist/cjs/sqlite.d.ts +75 -20
- package/dist/cjs/sqlite.js +593 -95
- package/dist/cjs/supplied-pool-types.d.ts +48 -0
- package/dist/cjs/supplied-pool-types.js +256 -0
- package/dist/cjs/transaction-control.d.ts +51 -0
- package/dist/cjs/transaction-control.js +316 -0
- package/dist/cjs/transaction-state.d.ts +342 -0
- package/dist/cjs/transaction-state.js +707 -0
- package/dist/cjs/typed-sql.d.ts +37 -3
- package/dist/cjs/typed-sql.js +102 -8
- package/dist/cli/code-first-tags.d.ts +62 -0
- package/dist/cli/code-first-tags.js +120 -0
- package/dist/cli/compile-query.js +9 -0
- package/dist/cli/config.d.ts +35 -6
- package/dist/cli/config.js +16 -1
- package/dist/cli/destructive.d.ts +7 -4
- package/dist/cli/destructive.js +224 -20
- package/dist/cli/error-catalog.js +36 -0
- package/dist/cli/error-text.d.ts +15 -0
- package/dist/cli/error-text.js +37 -0
- package/dist/cli/index.d.ts +62 -4
- package/dist/cli/index.js +569 -112
- package/dist/cli/local-server-guard.d.ts +53 -0
- package/dist/cli/local-server-guard.js +113 -0
- package/dist/cli/local-server-output.d.ts +41 -0
- package/dist/cli/local-server-output.js +98 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +121 -34
- package/dist/cli/migrate.d.ts +113 -5
- package/dist/cli/migrate.js +261 -21
- package/dist/cli/observe.d.ts +6 -1
- package/dist/cli/observe.js +84 -54
- package/dist/cli/pii-predicate-guard.d.ts +43 -23
- package/dist/cli/pii-predicate-guard.js +100 -35
- package/dist/cli/prisma-resolve.js +15 -11
- package/dist/cli/prisma-schema.js +12 -4
- package/dist/cli/studio-ui.generated.js +1 -1
- package/dist/cli/studio.d.ts +14 -2
- package/dist/cli/studio.js +246 -71
- package/dist/cli/ui.d.ts +1 -1
- package/dist/client.d.ts +558 -85
- package/dist/client.js +1275 -400
- package/dist/connection-guard.d.ts +13 -0
- package/dist/connection-guard.js +27 -0
- package/dist/connection-url.d.ts +51 -16
- package/dist/connection-url.js +63 -34
- package/dist/diagnostics.d.ts +81 -0
- package/dist/diagnostics.js +144 -0
- package/dist/dialect.d.ts +449 -20
- package/dist/dialect.js +115 -43
- package/dist/engine-config.d.ts +7 -6
- package/dist/errors.d.ts +126 -6
- package/dist/errors.js +252 -12
- package/dist/generate.d.ts +57 -7
- package/dist/generate.js +635 -281
- package/dist/global-filters-config.d.ts +59 -0
- package/dist/global-filters-config.js +361 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +4 -2
- package/dist/introspect.d.ts +31 -6
- package/dist/introspect.js +106 -50
- package/dist/log-codes.d.ts +12 -0
- package/dist/log-codes.js +74 -0
- package/dist/logger.d.ts +87 -0
- package/dist/logger.js +93 -0
- package/dist/mssql.d.ts +8 -5
- package/dist/mssql.js +354 -67
- package/dist/mysql.d.ts +3 -5
- package/dist/mysql.js +423 -73
- package/dist/nested-write.d.ts +3 -0
- package/dist/nested-write.js +177 -112
- package/dist/pipeline-submittable.d.ts +12 -0
- package/dist/pipeline-submittable.js +117 -44
- package/dist/pipeline.js +21 -26
- package/dist/powdb-introspect.d.ts +5 -2
- package/dist/powdb-introspect.js +21 -16
- package/dist/powdb-shared.d.ts +36 -5
- package/dist/powdb-shared.js +65 -8
- package/dist/powdb.d.ts +4 -0
- package/dist/powdb.js +183 -51
- package/dist/powql.d.ts +394 -51
- package/dist/powql.js +1836 -291
- package/dist/prisma-compat.d.ts +23 -15
- package/dist/prisma-compat.js +508 -373
- package/dist/query/aggregates.d.ts +17 -1
- package/dist/query/aggregates.js +263 -32
- package/dist/query/batched-loader.d.ts +25 -6
- package/dist/query/batched-loader.js +101 -21
- package/dist/query/builder.d.ts +325 -184
- package/dist/query/builder.js +1458 -495
- package/dist/query/column-ref.d.ts +61 -0
- package/dist/query/column-ref.js +66 -0
- package/dist/query/compound-unique.d.ts +21 -0
- package/dist/query/compound-unique.js +97 -19
- package/dist/query/deferred.d.ts +53 -16
- package/dist/query/expr.d.ts +217 -0
- package/dist/query/expr.js +848 -0
- package/dist/query/filters.d.ts +155 -53
- package/dist/query/filters.js +597 -72
- package/dist/query/index.d.ts +2 -0
- package/dist/query/index.js +4 -0
- package/dist/query/json-value.d.ts +43 -0
- package/dist/query/json-value.js +54 -0
- package/dist/query/normalize-args.d.ts +87 -0
- package/dist/query/normalize-args.js +517 -0
- package/dist/query/option-surface.d.ts +16 -4
- package/dist/query/option-surface.js +56 -13
- package/dist/query/relation-names.d.ts +14 -0
- package/dist/query/relation-names.js +77 -19
- package/dist/query/relations.d.ts +30 -3
- package/dist/query/relations.js +220 -67
- package/dist/query/row-lock.d.ts +49 -0
- package/dist/query/row-lock.js +131 -0
- package/dist/query/sql-comment.d.ts +161 -0
- package/dist/query/sql-comment.js +374 -0
- package/dist/query/stream-idle.d.ts +132 -0
- package/dist/query/stream-idle.js +203 -0
- package/dist/query/table-client.d.ts +101 -0
- package/dist/query/table-client.js +70 -0
- package/dist/query/types.d.ts +677 -298
- package/dist/query/utils.d.ts +105 -6
- package/dist/query/utils.js +414 -18
- package/dist/query/warn-registry.d.ts +18 -0
- package/dist/query/warn-registry.js +18 -0
- package/dist/query/where-compile.d.ts +138 -14
- package/dist/query/where-compile.js +508 -31
- package/dist/query/where.d.ts +159 -59
- package/dist/query/where.js +711 -248
- package/dist/query/writes.d.ts +112 -50
- package/dist/query/writes.js +1496 -202
- package/dist/query-events.d.ts +4 -2
- package/dist/query-events.js +3 -1
- package/dist/realtime.d.ts +7 -3
- package/dist/realtime.js +13 -2
- package/dist/schema-builder.d.ts +55 -4
- package/dist/schema-builder.js +381 -18
- package/dist/schema-metadata.d.ts +21 -1
- package/dist/schema-metadata.js +28 -7
- package/dist/schema-sql.d.ts +75 -5
- package/dist/schema-sql.js +494 -44
- package/dist/schema.d.ts +26 -5
- package/dist/schema.js +109 -13
- package/dist/sql-placeholders.d.ts +56 -0
- package/dist/sql-placeholders.js +200 -0
- package/dist/sqlite.d.ts +75 -20
- package/dist/sqlite.js +597 -99
- package/dist/supplied-pool-types.d.ts +48 -0
- package/dist/supplied-pool-types.js +247 -0
- package/dist/transaction-control.d.ts +51 -0
- package/dist/transaction-control.js +311 -0
- package/dist/transaction-state.d.ts +342 -0
- package/dist/transaction-state.js +696 -0
- package/dist/typed-sql.d.ts +37 -3
- package/dist/typed-sql.js +100 -8
- package/package.json +7 -4
- package/skills/turbine-orm/SKILL.md +56 -6
package/dist/query/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
export type { AggregateArgs, AggregateResult, ArrayFilter, ColumnRef, ConnectOrCreateOp, CountArgs, CreateArgs, CreateDataInput, CreateManyArgs, DeleteArgs, DeleteManyArgs, FieldResult, FindManyArgs, FindManyStreamArgs, FindUniqueArgs, GlobalFilters, GroupByAggregateSpec, GroupByArgs, GroupByDistinctOn, GroupByResult, HavingClause, JsonEncoding, JsonFilter, JsonPathAggregateTarget, JsonPathGroupKey, JsonPathOrderBy, NestedCreateOp, NestedUpdateOp, NestedUpdateOpItem, NestedUpsertOpItem, OmitResult, OrderByClause, OrderByObject, OrderBySpec, OrderDirection, QueryResult, RelationDescriptor, RelationFilter, RelationLoadStrategy, RelationOrderBy, RelationOrderByChain, RelationPickBy, RelationPickOrderBy, ResolvedSkipGlobalFilters, SelectResult, SkipGlobalFilters, TextSearchFilter, TypedWithClause, UpdateArgs, UpdateDataInput, UpdateInput, UpdateManyArgs, UpdateOperatorInput, UpsertArgs, VectorDistanceFilter, VectorFilter, VectorMetric, VectorOrderBy, VectorOrderByDistance, WhereClause, WhereOperator, WhereValue, WithClause, WithOptions, WithOrderByObject, WithResult, } from './types.js';
|
|
9
9
|
export type { BuiltStatement, BulkInsertStatementInput, ColumnDefinitionInput, ColumnTypeInput, CreateIndexStatementInput, CreateTableStatementInput, Dialect, InsertStatementInput, UpsertStatementInput, } from '../dialect.js';
|
|
10
10
|
export { postgresDialect } from '../dialect.js';
|
|
11
|
+
export { col } from './column-ref.js';
|
|
12
|
+
export { type JsonValue, jsonValue } from './json-value.js';
|
|
11
13
|
export type { OptionKind, OptionTable } from './option-surface.js';
|
|
12
14
|
export { AGGREGATE_OPTIONS, ALL_OPTION_TABLES, applyNativeOptions, COUNT_OPTIONS, CREATE_MANY_OPTIONS, CREATE_OPTIONS, DELETE_MANY_OPTIONS, DELETE_OPTIONS, FIND_MANY_OPTIONS, FIND_MANY_STREAM_OPTIONS, FIND_UNIQUE_OPTIONS, GROUP_BY_OPTIONS, optionKeysOfKind, UPDATE_MANY_OPTIONS, UPDATE_OPTIONS, UPSERT_OPTIONS, } from './option-surface.js';
|
|
13
15
|
export type { PrivilegeOption, Unsafe } from './types.js';
|
package/dist/query/index.js
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* former monolithic `import { … } from './query.js'`.
|
|
7
7
|
*/
|
|
8
8
|
export { postgresDialect } from '../dialect.js';
|
|
9
|
+
// Column references: `col('field')` builds the branded operand that compares
|
|
10
|
+
// two columns of one row. `jsonValue(v)` marks a value to store as JSON.
|
|
11
|
+
export { col } from './column-ref.js';
|
|
12
|
+
export { jsonValue } from './json-value.js';
|
|
9
13
|
export { AGGREGATE_OPTIONS, ALL_OPTION_TABLES, applyNativeOptions, COUNT_OPTIONS, CREATE_MANY_OPTIONS, CREATE_OPTIONS, DELETE_MANY_OPTIONS, DELETE_OPTIONS, FIND_MANY_OPTIONS, FIND_MANY_STREAM_OPTIONS, FIND_UNIQUE_OPTIONS, GROUP_BY_OPTIONS, optionKeysOfKind, UPDATE_MANY_OPTIONS, UPDATE_OPTIONS, UPSERT_OPTIONS, } from './option-surface.js';
|
|
10
14
|
// The privilege sentinel: a runtime value, not a type (see types.ts).
|
|
11
15
|
export { assertOrderDirection, resolveSkipGlobalFilters, resolveUnsafeFlag, UNSAFE } from './types.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* turbine-orm: explicit JSON values for json / jsonb writes.
|
|
3
|
+
*
|
|
4
|
+
* A JS string written to a json/jsonb column is RAW JSON TEXT: `'{"a":1}'`
|
|
5
|
+
* stores the object `{ a: 1 }`, which is how `JSON.stringify(value)` callers
|
|
6
|
+
* have always written documents. That rule leaves no way to store a JSON
|
|
7
|
+
* STRING (`"hello"`) or a JSON `null` (as opposed to SQL NULL).
|
|
8
|
+
* `jsonValue(v)` is that way: the wrapped value is serialized with
|
|
9
|
+
* `JSON.stringify` on every engine and every write path, so
|
|
10
|
+
*
|
|
11
|
+
* jsonValue('hello') stores the JSON string "hello"
|
|
12
|
+
* jsonValue(null) stores the JSON value null (the column is NOT SQL NULL)
|
|
13
|
+
* jsonValue([1, 2]) stores the JSON array [1, 2]
|
|
14
|
+
*
|
|
15
|
+
* The brand is a `Symbol.for` key so a copy of the package loaded twice (ESM
|
|
16
|
+
* and CJS) still recognizes the other copy's values, and so `JSON.parse` can
|
|
17
|
+
* never produce one from request data.
|
|
18
|
+
*/
|
|
19
|
+
declare const JSON_VALUE_BRAND: unique symbol;
|
|
20
|
+
/** A value marked for `JSON.stringify` serialization. Create with {@link jsonValue}. */
|
|
21
|
+
export interface JsonValue<T = unknown> {
|
|
22
|
+
readonly [JSON_VALUE_BRAND]: true;
|
|
23
|
+
/** The wrapped value, exactly as passed to {@link jsonValue}. */
|
|
24
|
+
readonly value: T;
|
|
25
|
+
/** `JSON.stringify(wrapper)` serializes the wrapped value, never the wrapper. */
|
|
26
|
+
toJSON(): T;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Mark `value` to be written as JSON. See the module comment for why a plain
|
|
30
|
+
* string cannot mean this. Throws (E003 at write time) only when the value is
|
|
31
|
+
* not JSON-serializable, e.g. a `bigint` or `undefined`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function jsonValue<T>(value: T): JsonValue<T>;
|
|
34
|
+
/** Whether `value` was produced by {@link jsonValue} (any loaded copy of the package). */
|
|
35
|
+
export declare function isJsonValue(value: unknown): value is JsonValue;
|
|
36
|
+
/**
|
|
37
|
+
* The JSON text a json/jsonb column receives for `value`. `undefined` (and a
|
|
38
|
+
* function or symbol) has no JSON form and `JSON.stringify` returns
|
|
39
|
+
* `undefined` for it; a `bigint` makes it throw. Both surface as `undefined`
|
|
40
|
+
* here so the caller can raise its own E003 naming the column.
|
|
41
|
+
*/
|
|
42
|
+
export declare function serializeJsonValue(value: unknown): string | undefined;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* turbine-orm: explicit JSON values for json / jsonb writes.
|
|
3
|
+
*
|
|
4
|
+
* A JS string written to a json/jsonb column is RAW JSON TEXT: `'{"a":1}'`
|
|
5
|
+
* stores the object `{ a: 1 }`, which is how `JSON.stringify(value)` callers
|
|
6
|
+
* have always written documents. That rule leaves no way to store a JSON
|
|
7
|
+
* STRING (`"hello"`) or a JSON `null` (as opposed to SQL NULL).
|
|
8
|
+
* `jsonValue(v)` is that way: the wrapped value is serialized with
|
|
9
|
+
* `JSON.stringify` on every engine and every write path, so
|
|
10
|
+
*
|
|
11
|
+
* jsonValue('hello') stores the JSON string "hello"
|
|
12
|
+
* jsonValue(null) stores the JSON value null (the column is NOT SQL NULL)
|
|
13
|
+
* jsonValue([1, 2]) stores the JSON array [1, 2]
|
|
14
|
+
*
|
|
15
|
+
* The brand is a `Symbol.for` key so a copy of the package loaded twice (ESM
|
|
16
|
+
* and CJS) still recognizes the other copy's values, and so `JSON.parse` can
|
|
17
|
+
* never produce one from request data.
|
|
18
|
+
*/
|
|
19
|
+
const JSON_VALUE_BRAND = Symbol.for('turbine-orm.jsonValue');
|
|
20
|
+
/**
|
|
21
|
+
* Mark `value` to be written as JSON. See the module comment for why a plain
|
|
22
|
+
* string cannot mean this. Throws (E003 at write time) only when the value is
|
|
23
|
+
* not JSON-serializable, e.g. a `bigint` or `undefined`.
|
|
24
|
+
*/
|
|
25
|
+
export function jsonValue(value) {
|
|
26
|
+
const wrapper = {
|
|
27
|
+
[JSON_VALUE_BRAND]: true,
|
|
28
|
+
value,
|
|
29
|
+
toJSON: () => value,
|
|
30
|
+
// node-postgres calls `toPostgres` for an object param before its own
|
|
31
|
+
// JSON fallback; a wrapper that reaches the driver unresolved still binds
|
|
32
|
+
// the serialized text rather than `{"value":...}`.
|
|
33
|
+
toPostgres: () => serializeJsonValue(value),
|
|
34
|
+
};
|
|
35
|
+
return Object.freeze(wrapper);
|
|
36
|
+
}
|
|
37
|
+
/** Whether `value` was produced by {@link jsonValue} (any loaded copy of the package). */
|
|
38
|
+
export function isJsonValue(value) {
|
|
39
|
+
return typeof value === 'object' && value !== null && value[JSON_VALUE_BRAND] === true;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The JSON text a json/jsonb column receives for `value`. `undefined` (and a
|
|
43
|
+
* function or symbol) has no JSON form and `JSON.stringify` returns
|
|
44
|
+
* `undefined` for it; a `bigint` makes it throw. Both surface as `undefined`
|
|
45
|
+
* here so the caller can raise its own E003 naming the column.
|
|
46
|
+
*/
|
|
47
|
+
export function serializeJsonValue(value) {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.stringify(value);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `undefined` means absent, decided ONCE at the args seam.
|
|
3
|
+
*
|
|
4
|
+
* Every public operation (and its `build*` twin) runs its args through
|
|
5
|
+
* {@link pruneUndefinedArgs} before anything else reads them: the empty-`where`
|
|
6
|
+
* guards, the SQL-cache fingerprint, the SQL build and the param collect. A key
|
|
7
|
+
* whose value is `undefined` is removed, and so is an object (or combinator
|
|
8
|
+
* array) that BECOMES empty because of it, recursively, so
|
|
9
|
+
* `{ user: { email: undefined } }` is exactly `{}`. One pass up front, because
|
|
10
|
+
* consumers that each decide what `undefined` means end up disagreeing: a cache
|
|
11
|
+
* key that counted `{ gte: undefined }` while the builder skipped it served a
|
|
12
|
+
* `<=` template to a `>=` call.
|
|
13
|
+
*
|
|
14
|
+
* Pruned positions: `where` (combinators, relation filters, column operator
|
|
15
|
+
* objects including a nested `not`), `having`, `cursor`, `orderBy`, and every
|
|
16
|
+
* `with` relation's `where` / `orderBy`. Never `data` / `create` / `update`
|
|
17
|
+
* (a json column may legitimately receive `{}`), never an operand value (an
|
|
18
|
+
* `in` list, a JSON document, a vector), and never an object written empty
|
|
19
|
+
* (`{}`, `{ OR: [] }`), which keeps its own meaning. A column operator object
|
|
20
|
+
* left holding only modifiers (`mode`, `path`, `config`) is removed too:
|
|
21
|
+
* `{ contains: q, mode: 'insensitive' }` with `q` undefined is no filter.
|
|
22
|
+
*
|
|
23
|
+
* PowDB runs the same function from `PowqlInterface.normalizeArgs`, so the
|
|
24
|
+
* two engines cannot disagree about what `undefined` means.
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
import type { SchemaMetadata } from '../schema.js';
|
|
29
|
+
/**
|
|
30
|
+
* Remove every `undefined` from the pruned positions of one operation's args
|
|
31
|
+
* (see the module comment). Returns `args` by reference when nothing changed.
|
|
32
|
+
*
|
|
33
|
+
* `table` is the operation's table; relation filters and `with` levels are
|
|
34
|
+
* resolved against `schema` so each sub-where is pruned against its own target.
|
|
35
|
+
*/
|
|
36
|
+
export declare function pruneUndefinedArgs<A>(schema: SchemaMetadata, table: string, args: A): A;
|
|
37
|
+
/**
|
|
38
|
+
* Whether pruning turned a `where` that HAD keys into one with none: every key
|
|
39
|
+
* the caller wrote was `undefined`. A `where: {}` written as `{}` is not
|
|
40
|
+
* emptied; it was empty already.
|
|
41
|
+
*/
|
|
42
|
+
export declare function whereEmptiedByPruning(original: unknown, pruned: unknown): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Refuse a single-row read whose `where` was emptied by pruning. `findFirst`
|
|
45
|
+
* with every filter value `undefined` would otherwise return an arbitrary row,
|
|
46
|
+
* which on a lookup by a secret (a reset token, an invite code) is another
|
|
47
|
+
* user's row. `findMany` and `count` keep "undefined means absent".
|
|
48
|
+
*/
|
|
49
|
+
export declare function assertWhereNotEmptiedByPruning(table: string, operation: string, original: unknown, pruned: unknown): void;
|
|
50
|
+
/**
|
|
51
|
+
* THE "has a cursor" test: a plain object holding at least one defined value.
|
|
52
|
+
* The page-order completion and the cursor planner both ask it (on PowDB too),
|
|
53
|
+
* so a page cannot be a cursor page to one and not to the other. A `cursor`
|
|
54
|
+
* written in a shape that names no row never reaches it as "no cursor": see
|
|
55
|
+
* {@link assertCursorWritten} and {@link assertCursorNotEmptied}.
|
|
56
|
+
*/
|
|
57
|
+
export declare function hasCursor(cursor: unknown): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Refuse a `cursor` that is written but names no row: `null`, a value that is
|
|
60
|
+
* not an object, or `{}`. Read as "no cursor", such a page skipped both the
|
|
61
|
+
* cursor and the page tiebreaker, so a pager written as
|
|
62
|
+
* `cursor: last ? { id: last.id } : {}` cut its first page from a different
|
|
63
|
+
* order than every later page and skipped rows.
|
|
64
|
+
*/
|
|
65
|
+
export declare function assertCursorWritten(table: string, operation: string, cursor: unknown): void;
|
|
66
|
+
/**
|
|
67
|
+
* Refuse a `cursor` whose every field was `undefined`. Read as absent it would
|
|
68
|
+
* restart the walk at the first page, so a pager whose last-row value went
|
|
69
|
+
* missing would re-read page one forever. Same rule and message on every engine.
|
|
70
|
+
* `operation` names the call in the message when the caller knows it; without
|
|
71
|
+
* it the message names no operation rather than a wrong one.
|
|
72
|
+
*/
|
|
73
|
+
export declare function assertCursorNotEmptied(table: string, original: unknown, pruned: unknown, operation?: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* Internal findMany flag: the page STARTS AT the cursor row instead of after
|
|
76
|
+
* it. Prisma's cursor is inclusive (its `skip: 1` idiom drops the cursor row),
|
|
77
|
+
* so `turbine-orm/prisma-compat` sets this; core's own `cursor` stays
|
|
78
|
+
* exclusive. A symbol key, so a request body spread into findMany args cannot
|
|
79
|
+
* set it (JSON.parse never produces a symbol) and the unknown-option check,
|
|
80
|
+
* which reads `Object.keys`, never sees it. `Symbol.for` so ESM and CJS copies
|
|
81
|
+
* of the package agree on it.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
export declare const CURSOR_INCLUSIVE: unique symbol;
|
|
86
|
+
/** Whether `args` carries {@link CURSOR_INCLUSIVE}. @internal */
|
|
87
|
+
export declare function isCursorInclusive(args: unknown): boolean;
|