graphddb 0.2.0 → 0.2.2
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 +68 -3
- package/dist/{chunk-UNRQ5YJT.js → chunk-27XBTYVK.js} +1 -1
- package/dist/{chunk-347U24SB.js → chunk-3MI43FHU.js} +519 -48
- package/dist/{chunk-F27INYI2.js → chunk-CXIAECRS.js} +272 -97
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +5 -19
- package/dist/index.js +113 -7
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +2 -2
- package/dist/{types-D6qLpw2M.d.ts → types-SKxZQbQO.d.ts} +230 -122
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,64 @@ A partition key is a graph entry point, a relation an explicit traversal path, a
|
|
|
37
37
|
selection set. GraphDDB does not invent a query language — it executes well-designed access
|
|
38
38
|
patterns directly and makes ambiguity visible through plans, limits, and relation resolution.
|
|
39
39
|
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install graphddb
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The AWS SDK v3 is a peer dependency — install the clients you use:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`tsx` is an optional peer dependency, needed only to run the code-generation CLI
|
|
53
|
+
(`graphddb generate …`) directly against TypeScript definition files. Library
|
|
54
|
+
consumers don't need it (so it never pulls esbuild into your runtime bundle):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install -D tsx
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Requires Node.js ≥ 22.
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { DDBModel, model, string, key, k } from 'graphddb';
|
|
66
|
+
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
67
|
+
|
|
68
|
+
@model({ table: 'AppTable', prefix: 'USER' })
|
|
69
|
+
class UserModel extends DDBModel {
|
|
70
|
+
static readonly keys = key<{ userId: string }>((c) => ({
|
|
71
|
+
pk: k`USER#${c.userId}`,
|
|
72
|
+
sk: k`PROFILE`,
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
@string userId!: string;
|
|
76
|
+
@string name!: string;
|
|
77
|
+
}
|
|
78
|
+
const User = UserModel.asModel();
|
|
79
|
+
|
|
80
|
+
// Wire up the DynamoDB client once (configure retries/region on the client itself).
|
|
81
|
+
DDBModel.setClient(new DynamoDBClient({}));
|
|
82
|
+
|
|
83
|
+
// Read — only the selected fields appear in the result type.
|
|
84
|
+
const user = await User.query({ userId: 'alice' }, { name: true });
|
|
85
|
+
|
|
86
|
+
// Single-item write — raw base op, named after the DynamoDB API.
|
|
87
|
+
await User.putItem({ userId: 'alice', name: 'Alice' });
|
|
88
|
+
|
|
89
|
+
// Multi-item atomic write — the unified envelope (default `mode: 'transaction'`).
|
|
90
|
+
await DDBModel.mutate({
|
|
91
|
+
user: { update: User, key: { userId: 'alice' }, input: { name: 'Alice B.' } },
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
For cross-service contracts, the Python bridge, multi-fragment atomic mutations,
|
|
96
|
+
and more, see the sections below and [`docs/spec.md`](./docs/spec.md).
|
|
97
|
+
|
|
40
98
|
## User Permissions Example
|
|
41
99
|
|
|
42
100
|
The [user-permissions](./examples/user-permissions/) example models users, groups, memberships, and permissions in a single DynamoDB table.
|
|
@@ -272,6 +330,10 @@ are aliased (`ExpressionAttributeNames`) — there is no literal interpolation,
|
|
|
272
330
|
the compiled expression is injection-free, and it is attached independently of
|
|
273
331
|
the `KeyConditionExpression` / `ProjectionExpression`.
|
|
274
332
|
|
|
333
|
+
The same `cond` fragment is also accepted as a write `condition` (on
|
|
334
|
+
`putItem` / `updateItem` / `deleteItem`, transaction items, and public commands),
|
|
335
|
+
not just as a read filter.
|
|
336
|
+
|
|
275
337
|
> **RCU note:** A `FilterExpression` does **not** reduce read capacity —
|
|
276
338
|
> DynamoDB reads matching keys first, then filters. `limit` is applied
|
|
277
339
|
> **before** the filter, so a single page may return **fewer** than `limit`
|
|
@@ -339,7 +401,11 @@ const res = await DDBModel.mutate({
|
|
|
339
401
|
- **`key`** is a single object or an **array of objects** (key-array bulk). A
|
|
340
402
|
transaction compiles to `TransactWriteItems`; parallel mode compiles to
|
|
341
403
|
`BatchWriteItem` (chunked, with `UnprocessedItems` retry).
|
|
342
|
-
- **`condition`** is
|
|
404
|
+
- **`condition`** is a `WriteCondition` write gate — the same declarative
|
|
405
|
+
operator subset as read filters (`eq`/`ne`/comparisons/`between`/`in`/string
|
|
406
|
+
ops/`size`/`attributeType` + `and`/`or`/`not`), the legacy existence primitives
|
|
407
|
+
(`notExists` / `attributeExists` / `attributeNotExists`), or a raw `cond`
|
|
408
|
+
fragment.
|
|
343
409
|
- **`result: { select, options? }`** reads the written item back; omit it and the
|
|
344
410
|
route returns void.
|
|
345
411
|
- **`mode: 'transaction'`** (DEFAULT) is one atomic `TransactWriteItems`:
|
|
@@ -515,7 +581,6 @@ Layer 5: Hydrator
|
|
|
515
581
|
| Structured keys | Keys are built from `k` segment templates; partial keys compile to `begins_with` at a segment boundary. |
|
|
516
582
|
| Typed consistentRead | `consistentRead` is only available for PK queries. GSI queries are rejected at compile time. |
|
|
517
583
|
| Server-side filter | `filter` is a declarative DynamoDB `FilterExpression` (AppSync `ModelFilterInput`-compatible), typed against the full entity and able to reference unprojected attributes. It does not reduce RCU, and `limit` is applied before it. |
|
|
518
|
-
| Post-load filtering | No built-in post-load predicate; use `result.items.filter(...)` on the typed projection. Efficient narrowing belongs in key design. |
|
|
519
584
|
|
|
520
585
|
## Architectural Boundaries
|
|
521
586
|
|
|
@@ -583,7 +648,7 @@ The query / relation / write API above is the core layer. GraphDDB also ships:
|
|
|
583
648
|
- Entity metadata / decorators
|
|
584
649
|
- DDBModel base class / connection management
|
|
585
650
|
- Type system (SelectableOf, QueryResult, QueryKeyOf)
|
|
586
|
-
- CRUD (put, update, delete, conditional writes)
|
|
651
|
+
- CRUD (put, update, delete, conditional writes — `WriteCondition` shares the full declarative filter operator set plus the `cond` raw escape hatch)
|
|
587
652
|
- Query / List (planner, executor, hydrator, cursor pagination)
|
|
588
653
|
- Type-safe filtering: declarative server-side `filter` (FilterExpression / AppSync `ModelFilterInput`-compatible), plus `Model.col` column refs and the `cond` raw escape hatch
|
|
589
654
|
- Structured segment keys (`k` tag): partial keys compile to `begins_with` at a segment boundary
|