@loradb/lora-graphql 0.24.1 → 0.25.1

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.
Files changed (54) hide show
  1. package/README.md +201 -50
  2. package/dist/analyze/input-schemas.d.ts +11 -0
  3. package/dist/analyze/plans.d.ts +8 -0
  4. package/dist/analyze/stored.d.ts +29 -0
  5. package/dist/cli.js +263 -244
  6. package/dist/cli.js.map +1 -1
  7. package/dist/compile/cache.d.ts +9 -1
  8. package/dist/compile/context.d.ts +3 -0
  9. package/dist/compile/read/common.d.ts +2 -0
  10. package/dist/compile/read/root.d.ts +7 -0
  11. package/dist/compile/selection.d.ts +5 -0
  12. package/dist/diff-BZZNZs76.js +134 -0
  13. package/dist/diff-BZZNZs76.js.map +1 -0
  14. package/dist/driver.d.ts +36 -1
  15. package/dist/errors.d.ts +21 -1
  16. package/dist/events/outbox.d.ts +14 -0
  17. package/dist/events/worker.d.ts +67 -0
  18. package/dist/execute/changes.d.ts +8 -0
  19. package/dist/execute/cypher-mutation.d.ts +5 -1
  20. package/dist/execute/mutate/checks.d.ts +16 -0
  21. package/dist/execute/mutate/env.d.ts +50 -0
  22. package/dist/execute/mutate/errors.d.ts +6 -0
  23. package/dist/execute/mutate/links.d.ts +38 -0
  24. package/dist/execute/mutate/plan.d.ts +5 -0
  25. package/dist/execute/mutate/reported.d.ts +26 -0
  26. package/dist/execute/mutate/runner.d.ts +107 -25
  27. package/dist/execute/mutate/single-call.d.ts +92 -0
  28. package/dist/execute/mutate/triggers.d.ts +27 -0
  29. package/dist/execute/mutate/unique-together.d.ts +5 -1
  30. package/dist/execute/mutate/validate.d.ts +11 -0
  31. package/dist/execute/transaction.d.ts +13 -2
  32. package/dist/index.d.ts +7 -2
  33. package/dist/index.js +16 -15
  34. package/dist/lora-graphql-RvZQdHNA.js +17411 -0
  35. package/dist/lora-graphql-RvZQdHNA.js.map +1 -0
  36. package/dist/lora-graphql.d.ts +30 -1
  37. package/dist/model/build/authorization.d.ts +11 -1
  38. package/dist/model/build/constraints.d.ts +22 -0
  39. package/dist/model/build/rule-checks.d.ts +6 -1
  40. package/dist/model/build/trigger.d.ts +16 -0
  41. package/dist/model/constraints.d.ts +112 -0
  42. package/dist/model/desugar.d.ts +7 -0
  43. package/dist/model/directives.d.ts +1 -1
  44. package/dist/model/types.d.ts +55 -0
  45. package/dist/options.d.ts +76 -3
  46. package/dist/results.d.ts +12 -1
  47. package/dist/schema/scalars.d.ts +8 -1
  48. package/dist/standard-schema.d.ts +37 -0
  49. package/dist/testing.js +1 -1
  50. package/package.json +2 -2
  51. package/dist/diff-K8-GSeKH.js +0 -100
  52. package/dist/diff-K8-GSeKH.js.map +0 -1
  53. package/dist/driver-CXKPLfkz.js +0 -14447
  54. package/dist/driver-CXKPLfkz.js.map +0 -1
@@ -0,0 +1,92 @@
1
+ import { DriverTransaction, LoraDriver, QueryResult, RunOptions, Statement } from '../../driver.js';
2
+ import { GraphModel } from '../../model/types.js';
3
+ import { WritePlan } from './plan.js';
4
+ /**
5
+ * A transaction that is one `driver.run()` call until `open()` makes it a
6
+ * real one. In its single form the first batch is the whole mutation: it
7
+ * is committed when the call returns, so `commit()` has nothing left to
8
+ * do, and a failure has already rolled everything back.
9
+ *
10
+ * With `single` false it is never one call, only late: the transaction
11
+ * begins with its first statement, so what a mutation works out before
12
+ * that (its plan, its `@populatedBy` callbacks) does not hold the lock.
13
+ */
14
+ export declare class LazyTransaction implements DriverTransaction {
15
+ #private;
16
+ constructor(driver: LoraDriver, options: RunOptions, single?: boolean);
17
+ /**
18
+ * Whether the single call ran and committed: an error after that can
19
+ * no longer undo the write.
20
+ */
21
+ get committed(): boolean;
22
+ /** Whether the mutation is still one call. */
23
+ get single(): boolean;
24
+ /** The mutation needs more than one round trip: begin a transaction. */
25
+ open(): Promise<void>;
26
+ execute(statement: Statement): Promise<QueryResult>;
27
+ executeMany(statements: Statement[]): Promise<QueryResult[]>;
28
+ commit(): Promise<void>;
29
+ rollback(): Promise<void>;
30
+ get isOpen(): boolean;
31
+ }
32
+ /**
33
+ * `err` without the position the binding appends to the error of a
34
+ * failing statement of a batch (`(statement 2 of 3)`): callers see the
35
+ * error a lone statement gives. An error whose message is read-only (the
36
+ * DOMException of an aborted request) is passed on as it is.
37
+ */
38
+ export declare function withoutPosition(err: unknown): unknown;
39
+ /**
40
+ * Whether the database has `assert()`: asked once per driver. Without it
41
+ * every mutation keeps its transaction and decides in JavaScript.
42
+ */
43
+ export declare function supportsAssert(driver: LoraDriver): Promise<boolean>;
44
+ /**
45
+ * Whether reading any node can be refused by a READ validate rule: a
46
+ * payload read would then need a decision after the write, which a single
47
+ * call cannot make.
48
+ */
49
+ export declare function readCanBeRefused(model: GraphModel): boolean;
50
+ /**
51
+ * What the guard of a single-call update that writes relationships stands
52
+ * for: the node is not there (or not the caller's to update), so the call
53
+ * rolled back and the mutation answers null, as a transaction would after
54
+ * finding nothing.
55
+ */
56
+ export declare const NOT_THERE: unique symbol;
57
+ /**
58
+ * Whether `plan`'s links can go out in a single call: when each is
59
+ * known to create its relationship. A transaction asks the database
60
+ * whether the pair was connected already, and applies other rules to a
61
+ * re-connect; here it must be certain beforehand. It is when one end is
62
+ * a node this plan creates (it has no relationships yet) and no two
63
+ * links name the same relationship (one from each side's field). An
64
+ * update's links ask the database instead (`plan.reconnects`). A
65
+ * property the rules refuse depends on what the link found, in
66
+ * JavaScript.
67
+ */
68
+ export declare function linksInOne(plan: WritePlan): boolean;
69
+ /** The message of an `assert()` that stands for a refused rule. */
70
+ export declare function refusal(kind: "forbidden" | "hidden" | "taken", type: string, detail: string): string;
71
+ /**
72
+ * The request error an assertion stood for, or `err` when it is not one
73
+ * of ours.
74
+ */
75
+ export declare function refused(model: GraphModel, err: unknown): unknown;
76
+ /**
77
+ * The assertions of one single call that stand for an error only this
78
+ * mutation can name (the row a check failed on, a target that is not
79
+ * there): each is numbered, and its number is its message.
80
+ */
81
+ export declare class Assertions {
82
+ #private;
83
+ /**
84
+ * The message, a Cypher expression, of an assertion that stands for
85
+ * `error`: {@link Assertions.refusedBy} gives the error back. `detail`
86
+ * is an expression appended to it, for an error that names what the
87
+ * rows held.
88
+ */
89
+ failsAs(error: (detail: string) => unknown, detail?: string): string;
90
+ /** The error an assertion of {@link Assertions.failsAs} stood for, if `err` is one. */
91
+ refusedBy(err: unknown): unknown;
92
+ }
@@ -0,0 +1,27 @@
1
+ import { CompileContext } from '../../compile/context.js';
2
+ import { Statement } from '../../driver.js';
3
+ import { NodeType, Trigger, TriggerOperation } from '../../model/types.js';
4
+ import { MutationEnv } from './env.js';
5
+ import { Runner } from './runner.js';
6
+ /** Whether the mutation may fire a trigger: a statement or a function. */
7
+ export declare function hasTriggers(env: MutationEnv): boolean;
8
+ /** Whether the mutation may call a trigger function. */
9
+ export declare function hasTriggerFunctions(env: MutationEnv): boolean;
10
+ /** The trigger statement for `keys`, with `this` bound to each node. */
11
+ export declare function triggerStatement(ctx: CompileContext, node: NodeType, trigger: Trigger, operation: TriggerOperation, keys: unknown[]): Statement;
12
+ /**
13
+ * The text ahead of a CONNECT or DISCONNECT trigger's statement: one row
14
+ * per pair of `pairs` (a list of `[this key, target key]`), with `this`
15
+ * and `target` bound.
16
+ */
17
+ export declare function relationshipTriggerPrefix(node: NodeType, target: NodeType, pairs: string): string;
18
+ /**
19
+ * Run the CREATE and UPDATE triggers for what the mutation wrote so far.
20
+ * A node the mutation created and then updated fires CREATE only.
21
+ */
22
+ export declare function runWriteTriggers(runner: Runner): Promise<void>;
23
+ /** Run the DELETE triggers of `doomed`, while the nodes still exist. */
24
+ export declare function runDeleteTriggers(runner: Runner, doomed: ReadonlyArray<{
25
+ node: NodeType;
26
+ keys: unknown[];
27
+ }>): Promise<void>;
@@ -14,5 +14,9 @@ export declare function checkUniqueTogetherOf(env: MutationEnv, tx: DriverTransa
14
14
  * compares it with the nodes that share its first relationship end (or,
15
15
  * with scalars only, its first scalar's value) — never a scan of the type.
16
16
  * Without `keys`, every node of the type is compared (a scan).
17
+ *
18
+ * With `failing`, the statement fails instead of returning that node:
19
+ * `failing` gives the assertion's message, from an expression for the
20
+ * node's place in `keys`.
17
21
  */
18
- export declare function uniqueTogetherStatement(ctx: CompileContext, model: GraphModel, node: NodeType, u: UniqueTogether, keys: unknown[] | undefined): string;
22
+ export declare function uniqueTogetherStatement(ctx: CompileContext, model: GraphModel, node: NodeType, u: UniqueTogether, keys: unknown[] | undefined, failing?: (index: string) => string): string;
@@ -0,0 +1,11 @@
1
+ import { GraphModel, NodeType } from '../../model/types.js';
2
+ import { MutationKind } from '../../schema/mutations.js';
3
+ import { TypeValidator } from '../../standard-schema.js';
4
+ export type Validators = Readonly<Record<string, TypeValidator>>;
5
+ /**
6
+ * Refuse a mutation whose input breaks a field's rule or its type's
7
+ * validator, with every violation in one `BAD_USER_INPUT`. Values
8
+ * computed during the write (an `adjust`, a `@populatedBy` callback) are
9
+ * checked where they appear.
10
+ */
11
+ export declare function validateInput(model: GraphModel, validators: Validators, op: MutationKind, node: NodeType, args: Record<string, unknown>): Promise<void>;
@@ -2,8 +2,19 @@ import { DriverTransaction, QueryResult } from '../driver.js';
2
2
  import { WriteChange } from './changes.js';
3
3
  export declare class LoraTransaction {
4
4
  #private;
5
- /** @internal Created by `LoraGraphQL.begin()`. */
6
- constructor(tx: DriverTransaction, emit: (change: WriteChange) => void);
5
+ /**
6
+ * @internal Created by `LoraGraphQL.begin()`, and for a JavaScript
7
+ * trigger over the transaction of the mutation that fired it
8
+ * (`inTrigger`), which that mutation commits.
9
+ */
10
+ constructor(tx: DriverTransaction, emit: (change: WriteChange) => void, inTrigger?: boolean);
11
+ /**
12
+ * @internal Whether a trigger owns this handle: mutations run in it
13
+ * fire no trigger themselves.
14
+ */
15
+ get inTrigger(): boolean;
16
+ /** @internal The write-sets recorded so far, handed over. */
17
+ drain(): WriteChange[];
7
18
  /** @internal The driver transaction statements run in. */
8
19
  get driverTransaction(): DriverTransaction;
9
20
  /** False once committed, rolled back, or failed. */
package/dist/index.d.ts CHANGED
@@ -15,11 +15,16 @@ export type { CypherFinding } from './analyze/cypher-check.js';
15
15
  export { diffSchemas, type ApiChange, type SchemaDiff, } from './analyze/diff.js';
16
16
  export type { CompiledRead, ReadSet, SeekExpectation, } from './compile/read/types.js';
17
17
  export type { EntityRef, RelationshipRef, WriteChange, } from './execute/changes.js';
18
- export type { MutationInfo, PopulatedByCallback, } from './execute/mutate/env.js';
18
+ export type { MutationInfo, PopulatedByCallback, TriggerEvent, TriggerFunction, TriggerFunctions, } from './execute/mutate/env.js';
19
19
  export type { MutationKind } from './schema/mutations.js';
20
20
  export type { ChangeEvent } from './schema/hooks.js';
21
21
  export { LoraTransaction } from './execute/transaction.js';
22
- export { ModelError, formatProblem, isLoraGraphQLError, LORA_GRAPHQL_ERROR_CODES, type LoraGraphQLErrorCode, type ModelProblem, } from './errors.js';
22
+ export type { Worker, WorkerOptions } from './events/worker.js';
23
+ export { ModelError, formatProblem, isLoraGraphQLError, LORA_GRAPHQL_ERROR_CODES, type LoraGraphQLErrorCode, type ModelProblem, type Violation, } from './errors.js';
24
+ export type { FieldConstraints } from './model/constraints.js';
25
+ export { inputSchemas, type JsonSchema } from './analyze/input-schemas.js';
26
+ export type { StoredReport, StoredViolation } from './analyze/stored.js';
27
+ export type { StandardIssue, StandardResult, StandardSchemaV1, TypeValidator, } from './standard-schema.js';
23
28
  export { toGlobalId, fromGlobalId } from './schema/global-id.js';
24
29
  export type { Attributes, MetricsLike, ObservabilityOptions, SpanLike, StatementEndEvent, TracerLike, } from './observe.js';
25
30
  export { schemaHash, type ManifestOperation, type OperationManifest, } from './codegen.js';
package/dist/index.js CHANGED
@@ -1,26 +1,27 @@
1
- import { D as r, L as e, a as o, b as l, M as i, c as d, d as n, e as t, f as p, g as f, h as m, i as L, j as c, l as R, p as h, r as D, s as E, k as G, t as b, v as u } from "./driver-CXKPLfkz.js";
2
- import { d as A } from "./diff-K8-GSeKH.js";
1
+ import { D as r, L as e, a as o, b as i, M as l, c as n, d, e as t, f as m, g as p, h as c, i as f, j as L, k as h, l as R, p as D, r as u, s as E, m as G, t as b, v } from "./lora-graphql-RvZQdHNA.js";
2
+ import { d as O } from "./diff-BZZNZs76.js";
3
3
  export {
4
4
  r as DEFAULT_GUARDS,
5
5
  e as LORA_GRAPHQL_ERROR_CODES,
6
6
  o as LoraGraphQL,
7
- l as LoraTransaction,
8
- i as ModelError,
9
- d as buildModel,
10
- n as checkPlans,
11
- A as diffSchemas,
7
+ i as LoraTransaction,
8
+ l as ModelError,
9
+ n as buildModel,
10
+ d as checkPlans,
11
+ O as diffSchemas,
12
12
  t as directiveTypeDefs,
13
- p as envelopPlugin,
14
- f as formatProblem,
15
- m as fromGlobalId,
16
- L as inferRequirements,
17
- c as isLoraGraphQLError,
13
+ m as envelopPlugin,
14
+ p as formatProblem,
15
+ c as fromGlobalId,
16
+ f as inferRequirements,
17
+ L as inputSchemas,
18
+ h as isLoraGraphQLError,
18
19
  R as loraDriver,
19
- h as parseOptions,
20
- D as requirementDdl,
20
+ D as parseOptions,
21
+ u as requirementDdl,
21
22
  E as scanExpands,
22
23
  G as schemaHash,
23
24
  b as toGlobalId,
24
- u as validationRules
25
+ v as validationRules
25
26
  };
26
27
  //# sourceMappingURL=index.js.map