@byline/client 0.9.3
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 +373 -0
- package/README.md +20 -0
- package/dist/client.d.ts +60 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +158 -0
- package/dist/client.js.map +1 -0
- package/dist/collection-handle.d.ts +182 -0
- package/dist/collection-handle.d.ts.map +1 -0
- package/dist/collection-handle.js +511 -0
- package/dist/collection-handle.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/response.d.ts +27 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +80 -0
- package/dist/response.js.map +1 -0
- package/dist/types.d.ts +323 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
import type { ChangeStatusResult, CollectionDefinition, CreateDocumentResult, DeleteDocumentResult, UnpublishResult, UpdateDocumentResult } from '@byline/core';
|
|
9
|
+
import type { BylineClient } from './client.js';
|
|
10
|
+
import type { ClientDocument, CreateOptions, FindByIdOptions, FindByPathOptions, FindByVersionOptions, FindOneOptions, FindOptions, FindResult, HistoryOptions, UpdateOptions } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* A handle scoped to a single collection. Provides read (and eventually write)
|
|
13
|
+
* operations against that collection's documents.
|
|
14
|
+
*
|
|
15
|
+
* Created via `client.collection('posts')`.
|
|
16
|
+
*/
|
|
17
|
+
export declare class CollectionHandle {
|
|
18
|
+
private client;
|
|
19
|
+
private definition;
|
|
20
|
+
constructor(client: BylineClient, definition: CollectionDefinition);
|
|
21
|
+
/**
|
|
22
|
+
* Find documents with optional filtering, sorting, pagination, and field
|
|
23
|
+
* selection.
|
|
24
|
+
*
|
|
25
|
+
* All queries are routed through `findDocuments()` which supports
|
|
26
|
+
* document-level conditions (status, text search), field-level filters
|
|
27
|
+
* (EXISTS subqueries against EAV store tables), and field-level sorting
|
|
28
|
+
* (LATERAL JOINs).
|
|
29
|
+
*/
|
|
30
|
+
find<F = Record<string, any>>(options?: FindOptions<F>): Promise<FindResult<F>>;
|
|
31
|
+
/**
|
|
32
|
+
* Find a single document matching the given options. Returns `null` if no
|
|
33
|
+
* document matches.
|
|
34
|
+
*/
|
|
35
|
+
findOne<F = Record<string, any>>(options?: FindOneOptions<F>): Promise<ClientDocument<F> | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Find a document by its logical document ID.
|
|
38
|
+
*/
|
|
39
|
+
findById<F = Record<string, any>>(documentId: string, options?: FindByIdOptions<F>): Promise<ClientDocument<F> | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Find a document by its URL path/slug. Returns `null` when no document
|
|
42
|
+
* exists at the given path (the storage adapter resolves missing paths
|
|
43
|
+
* to `null` rather than throwing).
|
|
44
|
+
*/
|
|
45
|
+
findByPath<F = Record<string, any>>(path: string, options?: FindByPathOptions<F>): Promise<ClientDocument<F> | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new document in this collection.
|
|
48
|
+
*
|
|
49
|
+
* `data` is a plain object matching the collection's field shape. When
|
|
50
|
+
* `options.status` is omitted the collection's default status (from its
|
|
51
|
+
* workflow definition) is used.
|
|
52
|
+
*/
|
|
53
|
+
create(data: Record<string, any>, options?: CreateOptions): Promise<CreateDocumentResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Update an existing document via full replacement (PUT semantics).
|
|
56
|
+
* Creates a new immutable version row. Hooks receive the real previous
|
|
57
|
+
* version as `originalData`.
|
|
58
|
+
*/
|
|
59
|
+
update(documentId: string, data: Record<string, any>, options?: UpdateOptions): Promise<UpdateDocumentResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Change a document's workflow status. The transition is validated
|
|
62
|
+
* against the collection's declared workflow (±1 step or reset-to-first);
|
|
63
|
+
* transitioning to `'published'` auto-archives any other published
|
|
64
|
+
* versions of the same document.
|
|
65
|
+
*/
|
|
66
|
+
changeStatus(documentId: string, nextStatus: string): Promise<ChangeStatusResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Archive the currently-published version(s) of a document.
|
|
69
|
+
*/
|
|
70
|
+
unpublish(documentId: string): Promise<UnpublishResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Soft-delete a document. All versions are flagged `is_deleted = true`
|
|
73
|
+
* and disappear from read paths (the `current_documents` view filters
|
|
74
|
+
* them out). When the collection has any upload-capable image/file
|
|
75
|
+
* field and a storage provider is configured, the original file and
|
|
76
|
+
* every persisted variant on each upload-capable field are removed
|
|
77
|
+
* after the DB soft-delete — failures there are logged but non-fatal.
|
|
78
|
+
*/
|
|
79
|
+
delete(documentId: string): Promise<DeleteDocumentResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Count documents visible to the current actor, optionally filtered by
|
|
82
|
+
* status.
|
|
83
|
+
*
|
|
84
|
+
* Applies the collection's `beforeRead` predicate so the count reflects
|
|
85
|
+
* only the rows the actor can see (multi-tenant scoping, owner-only
|
|
86
|
+
* drafts, soft-delete hide, etc).
|
|
87
|
+
*/
|
|
88
|
+
count(where?: {
|
|
89
|
+
status?: string;
|
|
90
|
+
_bypassBeforeRead?: true;
|
|
91
|
+
}): Promise<number>;
|
|
92
|
+
/**
|
|
93
|
+
* Per-status document counts for this collection. Used by admin status
|
|
94
|
+
* bars / dashboards. Applies `beforeRead` so per-status counts reflect
|
|
95
|
+
* only the actor's visible rows.
|
|
96
|
+
*/
|
|
97
|
+
countByStatus(options?: {
|
|
98
|
+
_bypassBeforeRead?: true;
|
|
99
|
+
}): Promise<Array<{
|
|
100
|
+
status: string;
|
|
101
|
+
count: number;
|
|
102
|
+
}>>;
|
|
103
|
+
/**
|
|
104
|
+
* Fetch the version history for a single document. Applies `beforeRead`
|
|
105
|
+
* as an access gate via `findById` — if the actor can't see the
|
|
106
|
+
* document at all, history returns an empty result rather than
|
|
107
|
+
* leaking version metadata.
|
|
108
|
+
*
|
|
109
|
+
* Each version in the response is a shaped `ClientDocument`. Pagination
|
|
110
|
+
* mirrors the storage adapter's `{ documents, meta }` shape, then is
|
|
111
|
+
* mapped to the same `{ docs, meta }` envelope `find()` returns.
|
|
112
|
+
*/
|
|
113
|
+
history<F = Record<string, any>>(documentId: string, options?: HistoryOptions): Promise<FindResult<F>>;
|
|
114
|
+
/**
|
|
115
|
+
* Fetch a specific version of a document by its `documentVersionId`.
|
|
116
|
+
* Used by admin diff views.
|
|
117
|
+
*
|
|
118
|
+
* Pass-through to `getDocumentByVersion`; access enforcement falls back
|
|
119
|
+
* to the collection-level `read` ability (asserted at the top of every
|
|
120
|
+
* read entry point). Row-level `beforeRead` does **not** apply here —
|
|
121
|
+
* version-by-id is a history-viewing primitive and the caller is
|
|
122
|
+
* expected to have already passed an access check on the parent
|
|
123
|
+
* document. Use `history()` instead if you want the access gate.
|
|
124
|
+
*/
|
|
125
|
+
findByVersion<F = Record<string, any>>(versionId: string, options?: FindByVersionOptions<F>): Promise<ClientDocument<F> | null>;
|
|
126
|
+
/**
|
|
127
|
+
* Build a fresh `DocumentLifecycleContext` for a write call. Pulls the
|
|
128
|
+
* resolved collection id, inherits the client-wide logger and storage
|
|
129
|
+
* provider, and includes the collection definition so hooks can observe it.
|
|
130
|
+
*/
|
|
131
|
+
private buildLifecycleContext;
|
|
132
|
+
/**
|
|
133
|
+
* Resolve the caller's `RequestContext` and enforce the read ability
|
|
134
|
+
* for this collection. Called at the top of every read entry point so
|
|
135
|
+
* reads and writes both fail closed at the service boundary.
|
|
136
|
+
*
|
|
137
|
+
* Returns the resolved context so callers can thread `readMode` and
|
|
138
|
+
* other per-request state into the adapter without re-resolving.
|
|
139
|
+
*/
|
|
140
|
+
private resolveAndAssertRead;
|
|
141
|
+
/**
|
|
142
|
+
* Invoke `populateDocuments` on a freshly-read (raw, storage-shape) set
|
|
143
|
+
* of documents when the caller asked for populate. No-op otherwise.
|
|
144
|
+
*
|
|
145
|
+
* Runs BEFORE `shapeDocument` so the populate service sees the raw
|
|
146
|
+
* `{document_id, fields}` shape it expects. The shape pass
|
|
147
|
+
* (`shapeWithPopulated`) then walks the mutated tree and converts every
|
|
148
|
+
* newly-inserted raw sub-document into a `ClientDocument`.
|
|
149
|
+
*/
|
|
150
|
+
private populateIfRequested;
|
|
151
|
+
/**
|
|
152
|
+
* Apply richtext populate to a freshly-read set of source documents.
|
|
153
|
+
* Mirrors what `populateDocuments` does for materialised targets, but
|
|
154
|
+
* runs unconditionally for sources because `richTextPopulate` is a
|
|
155
|
+
* framework-managed phase rather than a user-opted DSL like
|
|
156
|
+
* `populate`/`depth`. Each leaf is gated by its own
|
|
157
|
+
* `populateRelationsOnRead` inside the service. No-ops when no adapter
|
|
158
|
+
* is registered.
|
|
159
|
+
*/
|
|
160
|
+
private richTextPopulateSources;
|
|
161
|
+
/**
|
|
162
|
+
* Resolve and cache the `beforeRead` hook predicate for this collection
|
|
163
|
+
* inside the current `ReadContext`. Honours `_bypassBeforeRead` (admin
|
|
164
|
+
* tooling, seeds, migrations).
|
|
165
|
+
*/
|
|
166
|
+
private resolveBeforeReadPredicate;
|
|
167
|
+
/**
|
|
168
|
+
* Like `resolveBeforeReadPredicate`, but parses the predicate to the
|
|
169
|
+
* adapter-facing `DocumentFilter[]` shape used by `getDocumentById` /
|
|
170
|
+
* `getDocumentByPath`. Returns `undefined` (not `[]`) when there is no
|
|
171
|
+
* scoping, so the adapter can skip the loop entirely.
|
|
172
|
+
*/
|
|
173
|
+
private resolveBeforeReadFilters;
|
|
174
|
+
/**
|
|
175
|
+
* Shape a raw doc to `ClientDocument<F>`, then recursively shape any
|
|
176
|
+
* populated raw sub-documents inside its `fields`. Stubs
|
|
177
|
+
* (`_resolved: false` / `_cycle: true`) and plain field values are
|
|
178
|
+
* preserved by reference.
|
|
179
|
+
*/
|
|
180
|
+
private shapeWithPopulated;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=collection-handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-handle.d.ts","sourceRoot":"","sources":["../src/collection-handle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EAMpB,eAAe,EACf,oBAAoB,EACrB,MAAM,cAAc,CAAA;AAmBrB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,UAAU,EACV,cAAc,EACd,aAAa,EACd,MAAM,YAAY,CAAA;AAEnB;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,UAAU,CAAsB;gBAE5B,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,oBAAoB;IAKlE;;;;;;;;OAQG;IACG,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAE,WAAW,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAuEzF;;;OAGG;IACG,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,OAAO,GAAE,cAAc,CAAC,CAAC,CAAM,GAC9B,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAgBpC;;OAEG;IACG,QAAQ,CAAC,CA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