@cyphra/runtime 0.1.0 → 0.2.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/LICENSE +21 -0
- package/dist/index.d.ts +327 -1
- package/dist/index.js +960 -0
- package/dist/index.js.map +1 -1
- package/package.json +19 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cyphra contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Config, Driver, Session, ManagedTransaction, Result, QueryResult } from 'neo4j-driver';
|
|
2
2
|
export { Config, Driver, ManagedTransaction, Session } from 'neo4j-driver';
|
|
3
3
|
import { CompiledCypher, SelectQuery } from '@cyphra/query';
|
|
4
|
+
import { SchemaModel } from '@cyphra/schema';
|
|
5
|
+
export { SchemaModel } from '@cyphra/schema';
|
|
4
6
|
|
|
5
7
|
type CyphraClientOptions = {
|
|
6
8
|
/** Bolt / Neo4j URI, e.g. `neo4j+s://xxx.databases.neo4j.io`. */
|
|
@@ -126,4 +128,328 @@ declare function toPlainRecords(result: Result | QueryResult): Promise<Record<st
|
|
|
126
128
|
*/
|
|
127
129
|
declare function toPlainRecord(result: Result | QueryResult): Promise<Record<string, unknown> | undefined>;
|
|
128
130
|
|
|
129
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Type-level API of the Cyphra ORM client.
|
|
133
|
+
*
|
|
134
|
+
* `cyphra generate` emits a {@link TypeMap} describing every node model; all argument and result
|
|
135
|
+
* types below are computed from it, so the client is fully typed without per-model generated code.
|
|
136
|
+
*
|
|
137
|
+
* @packageDocumentation
|
|
138
|
+
*/
|
|
139
|
+
/** Type-level description of one relation field on a node model. */
|
|
140
|
+
type RelationTypeDef = {
|
|
141
|
+
readonly target: string;
|
|
142
|
+
readonly many: boolean;
|
|
143
|
+
readonly optional: boolean;
|
|
144
|
+
/** Edge properties (from a `relationship { … }` model), or `null` when the edge is untyped. */
|
|
145
|
+
readonly edge: Record<string, unknown> | null;
|
|
146
|
+
};
|
|
147
|
+
/** Type-level description of one node model. */
|
|
148
|
+
type ModelTypeDef = {
|
|
149
|
+
/** Scalar properties as returned by queries (optional fields are `T | null`, lists are `T[]`). */
|
|
150
|
+
readonly scalars: Record<string, unknown>;
|
|
151
|
+
/** Scalar keys that must be provided on `create` (non-optional, no default, not a list). */
|
|
152
|
+
readonly createRequired: string;
|
|
153
|
+
/** `@id` / `@unique` keys usable in `findUnique`, `connect`, … */
|
|
154
|
+
readonly unique: string;
|
|
155
|
+
readonly relations: Record<string, RelationTypeDef>;
|
|
156
|
+
};
|
|
157
|
+
type TypeMap = Record<string, ModelTypeDef>;
|
|
158
|
+
type Scalars<TM extends TypeMap, M extends keyof TM> = TM[M]["scalars"];
|
|
159
|
+
type Relations<TM extends TypeMap, M extends keyof TM> = TM[M]["relations"];
|
|
160
|
+
type Rel<TM extends TypeMap, M extends keyof TM, R extends keyof Relations<TM, M>> = Relations<TM, M>[R];
|
|
161
|
+
type Target<TM extends TypeMap, M extends keyof TM, R extends keyof Relations<TM, M>> = Rel<TM, M, R>["target"] & keyof TM;
|
|
162
|
+
type Simplify<T> = {
|
|
163
|
+
[K in keyof T]: T[K];
|
|
164
|
+
} & {};
|
|
165
|
+
type Comparable = number | Date;
|
|
166
|
+
/** Filter on one scalar field. A bare value means `equals`; `null` means "property absent". */
|
|
167
|
+
type ScalarFilter<T> = [NonNullable<T>] extends [readonly (infer E)[]] ? {
|
|
168
|
+
/** List contains this element. */
|
|
169
|
+
has?: E;
|
|
170
|
+
/** List contains every element. */
|
|
171
|
+
hasEvery?: readonly E[];
|
|
172
|
+
/** List contains at least one element. */
|
|
173
|
+
hasSome?: readonly E[];
|
|
174
|
+
isEmpty?: boolean;
|
|
175
|
+
equals?: readonly E[];
|
|
176
|
+
} : T | ({
|
|
177
|
+
equals?: T;
|
|
178
|
+
not?: T | ScalarFilter<T>;
|
|
179
|
+
in?: readonly NonNullable<T>[];
|
|
180
|
+
notIn?: readonly NonNullable<T>[];
|
|
181
|
+
} & (NonNullable<T> extends Comparable ? {
|
|
182
|
+
lt?: NonNullable<T>;
|
|
183
|
+
lte?: NonNullable<T>;
|
|
184
|
+
gt?: NonNullable<T>;
|
|
185
|
+
gte?: NonNullable<T>;
|
|
186
|
+
} : unknown) & (NonNullable<T> extends string ? {
|
|
187
|
+
contains?: string;
|
|
188
|
+
startsWith?: string;
|
|
189
|
+
endsWith?: string;
|
|
190
|
+
} : unknown));
|
|
191
|
+
type RelationFilter<TM extends TypeMap, D extends RelationTypeDef> = D["many"] extends true ? {
|
|
192
|
+
/** At least one related node matches. */
|
|
193
|
+
some?: WhereInput<TM, D["target"] & keyof TM>;
|
|
194
|
+
/** No related node matches. */
|
|
195
|
+
none?: WhereInput<TM, D["target"] & keyof TM>;
|
|
196
|
+
/** Every related node matches (vacuously true when there are none). */
|
|
197
|
+
every?: WhereInput<TM, D["target"] & keyof TM>;
|
|
198
|
+
} : null | {
|
|
199
|
+
/** The related node exists and matches (`null`: no related node). */
|
|
200
|
+
is?: WhereInput<TM, D["target"] & keyof TM> | null;
|
|
201
|
+
/** No related node matching this (`null`: a related node exists). */
|
|
202
|
+
isNot?: WhereInput<TM, D["target"] & keyof TM> | null;
|
|
203
|
+
};
|
|
204
|
+
type WhereInput<TM extends TypeMap, M extends keyof TM> = {
|
|
205
|
+
[K in keyof Scalars<TM, M>]?: ScalarFilter<Scalars<TM, M>[K]>;
|
|
206
|
+
} & {
|
|
207
|
+
[R in keyof Relations<TM, M>]?: RelationFilter<TM, Rel<TM, M, R>>;
|
|
208
|
+
} & {
|
|
209
|
+
AND?: WhereInput<TM, M> | readonly WhereInput<TM, M>[];
|
|
210
|
+
OR?: readonly WhereInput<TM, M>[];
|
|
211
|
+
NOT?: WhereInput<TM, M> | readonly WhereInput<TM, M>[];
|
|
212
|
+
};
|
|
213
|
+
type RequireAtLeastOne<T> = {
|
|
214
|
+
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Omit<T, K>>;
|
|
215
|
+
}[keyof T];
|
|
216
|
+
/** Identifies a single node: at least one `@id`/`@unique` field, plus optional extra filters. */
|
|
217
|
+
type WhereUniqueInput<TM extends TypeMap, M extends keyof TM> = RequireAtLeastOne<{
|
|
218
|
+
[K in TM[M]["unique"] & keyof Scalars<TM, M>]: NonNullable<Scalars<TM, M>[K]>;
|
|
219
|
+
}> & WhereInput<TM, M>;
|
|
220
|
+
type SortOrder = "asc" | "desc";
|
|
221
|
+
type OrderByInput<TM extends TypeMap, M extends keyof TM> = {
|
|
222
|
+
[K in keyof Scalars<TM, M>]?: SortOrder;
|
|
223
|
+
} | readonly {
|
|
224
|
+
[K in keyof Scalars<TM, M>]?: SortOrder;
|
|
225
|
+
}[];
|
|
226
|
+
/** Options for loading a relation inside `select` / `include`. */
|
|
227
|
+
type RelationLoadArgs<TM extends TypeMap, T extends keyof TM> = {
|
|
228
|
+
where?: WhereInput<TM, T>;
|
|
229
|
+
orderBy?: OrderByInput<TM, T>;
|
|
230
|
+
skip?: number;
|
|
231
|
+
take?: number;
|
|
232
|
+
select?: SelectInput<TM, T>;
|
|
233
|
+
include?: IncludeInput<TM, T>;
|
|
234
|
+
};
|
|
235
|
+
type SelectInput<TM extends TypeMap, M extends keyof TM> = {
|
|
236
|
+
[K in keyof Scalars<TM, M>]?: boolean;
|
|
237
|
+
} & {
|
|
238
|
+
[R in keyof Relations<TM, M>]?: boolean | RelationLoadArgs<TM, Target<TM, M, R>>;
|
|
239
|
+
};
|
|
240
|
+
type IncludeInput<TM extends TypeMap, M extends keyof TM> = {
|
|
241
|
+
[R in keyof Relations<TM, M>]?: boolean | RelationLoadArgs<TM, Target<TM, M, R>>;
|
|
242
|
+
};
|
|
243
|
+
type EdgePart<D extends RelationTypeDef> = D["edge"] extends Record<string, unknown> ? {
|
|
244
|
+
$edge: D["edge"];
|
|
245
|
+
} : unknown;
|
|
246
|
+
type RelationPayload<TM extends TypeMap, D extends RelationTypeDef, A> = D["many"] extends true ? Simplify<Payload<TM, D["target"] & keyof TM, A> & EdgePart<D>>[] : D["optional"] extends true ? Simplify<Payload<TM, D["target"] & keyof TM, A> & EdgePart<D>> | null : Simplify<Payload<TM, D["target"] & keyof TM, A> & EdgePart<D>>;
|
|
247
|
+
type TrueKeys<T> = {
|
|
248
|
+
[K in keyof T]: T[K] extends false | undefined ? never : K;
|
|
249
|
+
}[keyof T];
|
|
250
|
+
type SelectPayload<TM extends TypeMap, M extends keyof TM, S> = {
|
|
251
|
+
[K in TrueKeys<S> & keyof Scalars<TM, M>]: Scalars<TM, M>[K];
|
|
252
|
+
} & {
|
|
253
|
+
[R in TrueKeys<S> & keyof Relations<TM, M>]: RelationPayload<TM, Rel<TM, M, R>, S[R & keyof S] extends object ? S[R & keyof S] : object>;
|
|
254
|
+
};
|
|
255
|
+
type IncludePayload<TM extends TypeMap, M extends keyof TM, I> = Scalars<TM, M> & {
|
|
256
|
+
[R in TrueKeys<I> & keyof Relations<TM, M>]: RelationPayload<TM, Rel<TM, M, R>, I[R & keyof I] extends object ? I[R & keyof I] : object>;
|
|
257
|
+
};
|
|
258
|
+
/** Result type of a query on model `M` with args `A` (honours `select` / `include`). */
|
|
259
|
+
type Payload<TM extends TypeMap, M extends keyof TM, A> = Simplify<IsObject<ArgOf<A, "select">> extends true ? SelectPayload<TM, M, ArgOf<A, "select">> : IsObject<ArgOf<A, "include">> extends true ? IncludePayload<TM, M, ArgOf<A, "include">> : Scalars<TM, M>>;
|
|
260
|
+
type IsObject<X> = [X] extends [never] ? false : [X] extends [object] ? true : false;
|
|
261
|
+
type ArgOf<A, K extends string> = A extends {
|
|
262
|
+
[P in K]?: infer V;
|
|
263
|
+
} ? Exclude<V, undefined> : never;
|
|
264
|
+
type EdgeInput<D extends RelationTypeDef> = D["edge"] extends Record<string, unknown> ? {
|
|
265
|
+
$edge?: Partial<D["edge"]>;
|
|
266
|
+
} : unknown;
|
|
267
|
+
type OneOrMany<D extends RelationTypeDef, T> = D["many"] extends true ? T | readonly T[] : T;
|
|
268
|
+
type ScalarCreate<TM extends TypeMap, M extends keyof TM> = {
|
|
269
|
+
[K in TM[M]["createRequired"] & keyof Scalars<TM, M>]: Scalars<TM, M>[K];
|
|
270
|
+
} & {
|
|
271
|
+
[K in Exclude<keyof Scalars<TM, M>, TM[M]["createRequired"]>]?: Scalars<TM, M>[K];
|
|
272
|
+
};
|
|
273
|
+
type RelationCreate<TM extends TypeMap, D extends RelationTypeDef> = {
|
|
274
|
+
/** Create related node(s) and link them. */
|
|
275
|
+
create?: OneOrMany<D, CreateInput<TM, D["target"] & keyof TM> & EdgeInput<D>>;
|
|
276
|
+
/** Link existing node(s); throws if a target does not exist. */
|
|
277
|
+
connect?: OneOrMany<D, WhereUniqueInput<TM, D["target"] & keyof TM> & EdgeInput<D>>;
|
|
278
|
+
};
|
|
279
|
+
type CreateInput<TM extends TypeMap, M extends keyof TM> = ScalarCreate<TM, M> & {
|
|
280
|
+
[R in keyof Relations<TM, M>]?: RelationCreate<TM, Rel<TM, M, R>>;
|
|
281
|
+
};
|
|
282
|
+
type NumberUpdate = {
|
|
283
|
+
increment?: number;
|
|
284
|
+
decrement?: number;
|
|
285
|
+
multiply?: number;
|
|
286
|
+
};
|
|
287
|
+
type ScalarUpdate<TM extends TypeMap, M extends keyof TM> = {
|
|
288
|
+
[K in keyof Scalars<TM, M>]?: Scalars<TM, M>[K] extends number | null ? Scalars<TM, M>[K] | NumberUpdate : Scalars<TM, M>[K];
|
|
289
|
+
};
|
|
290
|
+
type RelationUpdate<TM extends TypeMap, D extends RelationTypeDef> = RelationCreate<TM, D> & (D["many"] extends true ? {
|
|
291
|
+
/** Remove the edge(s) to these nodes (the nodes are kept). */
|
|
292
|
+
disconnect?: OneOrMany<D, WhereUniqueInput<TM, D["target"] & keyof TM>>;
|
|
293
|
+
/** Replace all edges of this relation with edges to these nodes. */
|
|
294
|
+
set?: readonly (WhereUniqueInput<TM, D["target"] & keyof TM> & EdgeInput<D>)[];
|
|
295
|
+
} : {
|
|
296
|
+
/** Remove the edge (the related node is kept). */
|
|
297
|
+
disconnect?: boolean;
|
|
298
|
+
});
|
|
299
|
+
type UpdateInput<TM extends TypeMap, M extends keyof TM> = ScalarUpdate<TM, M> & {
|
|
300
|
+
[R in keyof Relations<TM, M>]?: RelationUpdate<TM, Rel<TM, M, R>>;
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* `select` and `include` are the only arguments that change the result type, so they are the only
|
|
304
|
+
* ones captured as type parameters. Everything else is typed directly, which keeps TypeScript's
|
|
305
|
+
* excess-property checks working (an unknown field in `data` or `where` is a compile error).
|
|
306
|
+
*/
|
|
307
|
+
type Projection<S, I> = {
|
|
308
|
+
select?: S;
|
|
309
|
+
include?: I;
|
|
310
|
+
};
|
|
311
|
+
type FindManyArgs<TM extends TypeMap, M extends keyof TM> = {
|
|
312
|
+
where?: WhereInput<TM, M>;
|
|
313
|
+
orderBy?: OrderByInput<TM, M>;
|
|
314
|
+
skip?: number;
|
|
315
|
+
take?: number;
|
|
316
|
+
};
|
|
317
|
+
type FindUniqueArgs<TM extends TypeMap, M extends keyof TM> = {
|
|
318
|
+
where: WhereUniqueInput<TM, M>;
|
|
319
|
+
};
|
|
320
|
+
type CreateArgs<TM extends TypeMap, M extends keyof TM> = {
|
|
321
|
+
data: CreateInput<TM, M>;
|
|
322
|
+
};
|
|
323
|
+
type CreateManyArgs<TM extends TypeMap, M extends keyof TM> = {
|
|
324
|
+
data: readonly ScalarCreate<TM, M>[];
|
|
325
|
+
};
|
|
326
|
+
type UpdateArgs<TM extends TypeMap, M extends keyof TM> = {
|
|
327
|
+
where: WhereUniqueInput<TM, M>;
|
|
328
|
+
data: UpdateInput<TM, M>;
|
|
329
|
+
};
|
|
330
|
+
type UpdateManyArgs<TM extends TypeMap, M extends keyof TM> = {
|
|
331
|
+
where?: WhereInput<TM, M>;
|
|
332
|
+
data: ScalarUpdate<TM, M>;
|
|
333
|
+
};
|
|
334
|
+
type UpsertArgs<TM extends TypeMap, M extends keyof TM> = {
|
|
335
|
+
where: WhereUniqueInput<TM, M>;
|
|
336
|
+
create: CreateInput<TM, M>;
|
|
337
|
+
update: UpdateInput<TM, M>;
|
|
338
|
+
};
|
|
339
|
+
type DeleteArgs<TM extends TypeMap, M extends keyof TM> = {
|
|
340
|
+
where: WhereUniqueInput<TM, M>;
|
|
341
|
+
};
|
|
342
|
+
type CountArgs<TM extends TypeMap, M extends keyof TM> = {
|
|
343
|
+
where?: WhereInput<TM, M>;
|
|
344
|
+
};
|
|
345
|
+
type BatchResult = {
|
|
346
|
+
count: number;
|
|
347
|
+
};
|
|
348
|
+
type Sel<TM extends TypeMap, M extends keyof TM> = SelectInput<TM, M> | undefined;
|
|
349
|
+
type Inc<TM extends TypeMap, M extends keyof TM> = IncludeInput<TM, M> | undefined;
|
|
350
|
+
type Out<TM extends TypeMap, M extends keyof TM, S, I> = Payload<TM, M, {
|
|
351
|
+
select: S;
|
|
352
|
+
include: I;
|
|
353
|
+
}>;
|
|
354
|
+
/** Operations available on `db.<model>`. */
|
|
355
|
+
type ModelDelegate<TM extends TypeMap, M extends keyof TM> = {
|
|
356
|
+
findMany<S extends Sel<TM, M> = undefined, I extends Inc<TM, M> = undefined>(args?: FindManyArgs<TM, M> & Projection<S, I>): Promise<Out<TM, M, S, I>[]>;
|
|
357
|
+
findFirst<S extends Sel<TM, M> = undefined, I extends Inc<TM, M> = undefined>(args?: FindManyArgs<TM, M> & Projection<S, I>): Promise<Out<TM, M, S, I> | null>;
|
|
358
|
+
/** `null` when no node matches. */
|
|
359
|
+
findUnique<S extends Sel<TM, M> = undefined, I extends Inc<TM, M> = undefined>(args: FindUniqueArgs<TM, M> & Projection<S, I>): Promise<Out<TM, M, S, I> | null>;
|
|
360
|
+
/** Throws {@link import("./errors.js").NotFoundError} when no node matches. */
|
|
361
|
+
findUniqueOrThrow<S extends Sel<TM, M> = undefined, I extends Inc<TM, M> = undefined>(args: FindUniqueArgs<TM, M> & Projection<S, I>): Promise<Out<TM, M, S, I>>;
|
|
362
|
+
count(args?: CountArgs<TM, M>): Promise<number>;
|
|
363
|
+
create<S extends Sel<TM, M> = undefined, I extends Inc<TM, M> = undefined>(args: CreateArgs<TM, M> & Projection<S, I>): Promise<Out<TM, M, S, I>>;
|
|
364
|
+
/** Create many nodes in one statement (scalars only, no nested writes). */
|
|
365
|
+
createMany(args: CreateManyArgs<TM, M>): Promise<BatchResult>;
|
|
366
|
+
update<S extends Sel<TM, M> = undefined, I extends Inc<TM, M> = undefined>(args: UpdateArgs<TM, M> & Projection<S, I>): Promise<Out<TM, M, S, I>>;
|
|
367
|
+
updateMany(args: UpdateManyArgs<TM, M>): Promise<BatchResult>;
|
|
368
|
+
upsert<S extends Sel<TM, M> = undefined, I extends Inc<TM, M> = undefined>(args: UpsertArgs<TM, M> & Projection<S, I>): Promise<Out<TM, M, S, I>>;
|
|
369
|
+
/** Detach-deletes the node and returns it as it was. */
|
|
370
|
+
delete<S extends Sel<TM, M> = undefined, I extends Inc<TM, M> = undefined>(args: DeleteArgs<TM, M> & Projection<S, I>): Promise<Out<TM, M, S, I>>;
|
|
371
|
+
deleteMany(args?: CountArgs<TM, M>): Promise<BatchResult>;
|
|
372
|
+
};
|
|
373
|
+
/** Lower-cases the first character: `BlogPost` → `blogPost`. */
|
|
374
|
+
type DelegateKey<M extends string> = Uncapitalize<M>;
|
|
375
|
+
type ModelDelegates<TM extends TypeMap> = {
|
|
376
|
+
[M in keyof TM & string as DelegateKey<M>]: ModelDelegate<TM, M>;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/** Options for {@link createOrm}: connection options, or an existing {@link CyphraClient}. */
|
|
380
|
+
type OrmOptions = CyphraClientOptions | {
|
|
381
|
+
client: CyphraClient;
|
|
382
|
+
debug?: boolean;
|
|
383
|
+
};
|
|
384
|
+
type Raw = {
|
|
385
|
+
/**
|
|
386
|
+
* Run a raw parameterized Cypher query (tagged template) and return rows as plain JS
|
|
387
|
+
* (integers → number, temporals → Date, nodes → properties).
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* const rows = await db.$cypher`MATCH (u:User) WHERE u.email = ${email} RETURN u.name AS name`;
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
$cypher<T = Record<string, unknown>>(strings: TemplateStringsArray, ...values: unknown[]): Promise<T[]>;
|
|
395
|
+
};
|
|
396
|
+
/** Client handed to {@link OrmClient.$transaction} callbacks. */
|
|
397
|
+
type OrmTransactionClient<TM extends TypeMap> = ModelDelegates<TM> & Raw;
|
|
398
|
+
type OrmClient<TM extends TypeMap> = ModelDelegates<TM> & Raw & {
|
|
399
|
+
/**
|
|
400
|
+
* Run `fn` in a single write transaction: every operation commits together or not at all.
|
|
401
|
+
* The driver may retry `fn` on transient errors, so keep it free of outside side effects.
|
|
402
|
+
*/
|
|
403
|
+
$transaction<T>(fn: (tx: OrmTransactionClient<TM>) => Promise<T>): Promise<T>;
|
|
404
|
+
/** Underlying low-level client (sessions, driver). */
|
|
405
|
+
readonly $client: CyphraClient;
|
|
406
|
+
/** The resolved schema the client was built from. */
|
|
407
|
+
readonly $schema: SchemaModel;
|
|
408
|
+
/** Close the driver (only when the client owns it, i.e. it was created from connection options). */
|
|
409
|
+
$disconnect(): Promise<void>;
|
|
410
|
+
};
|
|
411
|
+
/**
|
|
412
|
+
* Create a typed ORM client from a resolved schema model. Normally called by the generated
|
|
413
|
+
* `createClient()` in `cyphra.gen.ts`, which supplies both the model and its {@link TypeMap}.
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```ts
|
|
417
|
+
* import { createClient } from "./cyphra.gen.js";
|
|
418
|
+
* const db = createClient({ uri, user, password });
|
|
419
|
+
* const alice = await db.user.create({ data: { email: "alice@example.com", name: "Alice" } });
|
|
420
|
+
* const posts = await db.post.findMany({ where: { author: { is: { id: alice.id } } }, include: { author: true } });
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
declare function createOrm<TM extends TypeMap>(schema: SchemaModel, options: OrmOptions): OrmClient<TM>;
|
|
424
|
+
|
|
425
|
+
/** Base class for errors raised by the Cyphra ORM client. */
|
|
426
|
+
declare class CyphraError extends Error {
|
|
427
|
+
constructor(message: string);
|
|
428
|
+
}
|
|
429
|
+
/** Invalid arguments: unknown field, wrong value type, missing unique key, … */
|
|
430
|
+
declare class CyphraValidationError extends CyphraError {
|
|
431
|
+
}
|
|
432
|
+
/** A node required by the operation does not exist (`update`, `delete`, `connect`, `…OrThrow`). */
|
|
433
|
+
declare class NotFoundError extends CyphraError {
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Executes ORM operations for one node model against a {@link Runner}.
|
|
438
|
+
*
|
|
439
|
+
* Reads are single statements. Writes with nested relation operations run as a sequence of
|
|
440
|
+
* statements inside one write transaction, so a failing step (e.g. a missing `connect` target)
|
|
441
|
+
* rolls the whole operation back.
|
|
442
|
+
*
|
|
443
|
+
* @packageDocumentation
|
|
444
|
+
*/
|
|
445
|
+
|
|
446
|
+
/** Collision-resistant, URL-safe id (cuid2-style: a letter followed by 23 base-36 chars). */
|
|
447
|
+
declare function createCuid(): string;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Best-effort conversion of arbitrary driver values to plain JS: integers → number,
|
|
451
|
+
* temporal values → `Date`, nodes/relationships → their properties. Used for raw queries.
|
|
452
|
+
*/
|
|
453
|
+
declare function toNative(value: unknown): unknown;
|
|
454
|
+
|
|
455
|
+
export { type BatchResult, type CountArgs, type CreateArgs, type CreateInput, type CreateManyArgs, CyphraClient, type CyphraClientOptions, CyphraError, CyphraValidationError, type DelegateKey, type DeleteArgs, type FindManyArgs, type FindUniqueArgs, type IncludeInput, type ModelDelegate, type ModelDelegates, type ModelTypeDef, NotFoundError, type OrderByInput, type OrmClient, type OrmOptions, type OrmTransactionClient, type Payload, type RelationLoadArgs, type RelationTypeDef, type ScalarFilter, type SelectInput, type SortOrder, type TypeMap, type UpdateArgs, type UpdateInput, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, createCuid, createOrm, toNative, toPlainRecord, toPlainRecords };
|