@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,511 @@
|
|
|
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 { applyAfterRead, applyBeforeRead, assertActorCanPerform, changeDocumentStatus, createDocument, createReadContext, deleteDocument, mergePredicates, parseSort, parseWhere, populateDocuments, populateRichTextFields, unpublishDocument, updateDocument, } from '@byline/core';
|
|
9
|
+
import { shapeDocument, shapePopulatedInPlace } from './response.js';
|
|
10
|
+
/**
|
|
11
|
+
* A handle scoped to a single collection. Provides read (and eventually write)
|
|
12
|
+
* operations against that collection's documents.
|
|
13
|
+
*
|
|
14
|
+
* Created via `client.collection('posts')`.
|
|
15
|
+
*/
|
|
16
|
+
export class CollectionHandle {
|
|
17
|
+
client;
|
|
18
|
+
definition;
|
|
19
|
+
constructor(client, definition) {
|
|
20
|
+
this.client = client;
|
|
21
|
+
this.definition = definition;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Find documents with optional filtering, sorting, pagination, and field
|
|
25
|
+
* selection.
|
|
26
|
+
*
|
|
27
|
+
* All queries are routed through `findDocuments()` which supports
|
|
28
|
+
* document-level conditions (status, text search), field-level filters
|
|
29
|
+
* (EXISTS subqueries against EAV store tables), and field-level sorting
|
|
30
|
+
* (LATERAL JOINs).
|
|
31
|
+
*/
|
|
32
|
+
async find(options = {}) {
|
|
33
|
+
const requestContext = await this.resolveAndAssertRead();
|
|
34
|
+
const collectionId = await this.client.resolveCollectionId(this.definition.path);
|
|
35
|
+
const { where, select, sort, locale = 'en', page = 1, pageSize = 20 } = options;
|
|
36
|
+
const readMode = resolveReadMode(options.status);
|
|
37
|
+
const readCtx = options._readContext ?? createReadContext();
|
|
38
|
+
const hookPredicate = await this.resolveBeforeReadPredicate(requestContext, readCtx, options._bypassBeforeRead);
|
|
39
|
+
const merged = mergePredicates(hookPredicate, where);
|
|
40
|
+
const parsedWhere = await parseWhere(merged, this.definition, {
|
|
41
|
+
collections: this.client.collections,
|
|
42
|
+
resolveCollectionId: (path) => this.client.resolveCollectionId(path),
|
|
43
|
+
logger: this.client.logger,
|
|
44
|
+
});
|
|
45
|
+
const parsedSort = parseSort(sort, this.definition);
|
|
46
|
+
const result = await this.client.db.queries.documents.findDocuments({
|
|
47
|
+
collection_id: collectionId,
|
|
48
|
+
filters: parsedWhere.filters,
|
|
49
|
+
status: parsedWhere.status,
|
|
50
|
+
pathFilter: parsedWhere.pathFilter,
|
|
51
|
+
query: parsedWhere.query,
|
|
52
|
+
sort: parsedSort.fieldSort,
|
|
53
|
+
orderBy: parsedSort.orderBy,
|
|
54
|
+
orderDirection: parsedSort.orderDirection,
|
|
55
|
+
locale,
|
|
56
|
+
page,
|
|
57
|
+
pageSize,
|
|
58
|
+
fields: select,
|
|
59
|
+
readMode,
|
|
60
|
+
});
|
|
61
|
+
await this.populateIfRequested(collectionId, result.documents, locale, readMode, requestContext, {
|
|
62
|
+
...options,
|
|
63
|
+
_readContext: readCtx,
|
|
64
|
+
});
|
|
65
|
+
// Richtext populate runs *after* relation populate (so populated relation
|
|
66
|
+
// targets are already attached) and *before* afterRead (so user-land
|
|
67
|
+
// hooks observe the refreshed rich-text content).
|
|
68
|
+
await this.richTextPopulateSources(result.documents, readCtx);
|
|
69
|
+
// Fire afterRead for each source document AFTER populate so the hook
|
|
70
|
+
// sees the fully populated tree. Targets were already fired inside
|
|
71
|
+
// populate. applyAfterRead deduplicates via readCtx.afterReadFired.
|
|
72
|
+
for (const d of result.documents) {
|
|
73
|
+
await applyAfterRead({ doc: d, definition: this.definition, readContext: readCtx });
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
docs: result.documents.map((d) => this.shapeWithPopulated(d)),
|
|
77
|
+
meta: {
|
|
78
|
+
total: result.total,
|
|
79
|
+
page,
|
|
80
|
+
pageSize,
|
|
81
|
+
totalPages: Math.ceil(result.total / pageSize),
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Find a single document matching the given options. Returns `null` if no
|
|
87
|
+
* document matches.
|
|
88
|
+
*/
|
|
89
|
+
async findOne(options = {}) {
|
|
90
|
+
const result = await this.find({
|
|
91
|
+
where: options.where,
|
|
92
|
+
select: options.select,
|
|
93
|
+
locale: options.locale,
|
|
94
|
+
page: 1,
|
|
95
|
+
pageSize: 1,
|
|
96
|
+
populate: options.populate,
|
|
97
|
+
depth: options.depth,
|
|
98
|
+
status: options.status,
|
|
99
|
+
_readContext: options._readContext,
|
|
100
|
+
_bypassBeforeRead: options._bypassBeforeRead,
|
|
101
|
+
});
|
|
102
|
+
return result.docs[0] ?? null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Find a document by its logical document ID.
|
|
106
|
+
*/
|
|
107
|
+
async findById(documentId, options = {}) {
|
|
108
|
+
const requestContext = await this.resolveAndAssertRead();
|
|
109
|
+
const collectionId = await this.client.resolveCollectionId(this.definition.path);
|
|
110
|
+
const { locale = 'en' } = options;
|
|
111
|
+
const readMode = resolveReadMode(options.status);
|
|
112
|
+
const readCtx = options._readContext ?? createReadContext();
|
|
113
|
+
const filters = await this.resolveBeforeReadFilters(requestContext, readCtx, options._bypassBeforeRead);
|
|
114
|
+
const raw = await this.client.db.queries.documents.getDocumentById({
|
|
115
|
+
collection_id: collectionId,
|
|
116
|
+
document_id: documentId,
|
|
117
|
+
locale,
|
|
118
|
+
reconstruct: true,
|
|
119
|
+
readMode,
|
|
120
|
+
filters,
|
|
121
|
+
});
|
|
122
|
+
if (raw == null)
|
|
123
|
+
return null;
|
|
124
|
+
// Trim to selected fields BEFORE populate so populate doesn't waste work
|
|
125
|
+
// on relations the caller filtered out. Mutates `raw.fields` in place.
|
|
126
|
+
if (options.select?.length) {
|
|
127
|
+
trimFields(raw, options.select);
|
|
128
|
+
}
|
|
129
|
+
await this.populateIfRequested(collectionId, [raw], locale, readMode, requestContext, {
|
|
130
|
+
...options,
|
|
131
|
+
_readContext: readCtx,
|
|
132
|
+
});
|
|
133
|
+
await this.richTextPopulateSources([raw], readCtx);
|
|
134
|
+
await applyAfterRead({
|
|
135
|
+
doc: raw,
|
|
136
|
+
definition: this.definition,
|
|
137
|
+
readContext: readCtx,
|
|
138
|
+
});
|
|
139
|
+
return this.shapeWithPopulated(raw);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Find a document by its URL path/slug. Returns `null` when no document
|
|
143
|
+
* exists at the given path (the storage adapter resolves missing paths
|
|
144
|
+
* to `null` rather than throwing).
|
|
145
|
+
*/
|
|
146
|
+
async findByPath(path, options = {}) {
|
|
147
|
+
const requestContext = await this.resolveAndAssertRead();
|
|
148
|
+
const collectionId = await this.client.resolveCollectionId(this.definition.path);
|
|
149
|
+
const { locale = 'en' } = options;
|
|
150
|
+
const readMode = resolveReadMode(options.status);
|
|
151
|
+
const readCtx = options._readContext ?? createReadContext();
|
|
152
|
+
const filters = await this.resolveBeforeReadFilters(requestContext, readCtx, options._bypassBeforeRead);
|
|
153
|
+
const raw = await this.client.db.queries.documents.getDocumentByPath({
|
|
154
|
+
collection_id: collectionId,
|
|
155
|
+
path,
|
|
156
|
+
locale,
|
|
157
|
+
reconstruct: true,
|
|
158
|
+
readMode,
|
|
159
|
+
filters,
|
|
160
|
+
});
|
|
161
|
+
if (raw == null)
|
|
162
|
+
return null;
|
|
163
|
+
if (options.select?.length) {
|
|
164
|
+
trimFields(raw, options.select);
|
|
165
|
+
}
|
|
166
|
+
await this.populateIfRequested(collectionId, [raw], locale, readMode, requestContext, {
|
|
167
|
+
...options,
|
|
168
|
+
_readContext: readCtx,
|
|
169
|
+
});
|
|
170
|
+
await this.richTextPopulateSources([raw], readCtx);
|
|
171
|
+
await applyAfterRead({
|
|
172
|
+
doc: raw,
|
|
173
|
+
definition: this.definition,
|
|
174
|
+
readContext: readCtx,
|
|
175
|
+
});
|
|
176
|
+
return this.shapeWithPopulated(raw);
|
|
177
|
+
}
|
|
178
|
+
// -------------------------------------------------------------------------
|
|
179
|
+
// Write path
|
|
180
|
+
//
|
|
181
|
+
// Each method resolves the collection id, builds a DocumentLifecycleContext,
|
|
182
|
+
// and delegates to the corresponding `document-lifecycle` service. Hooks
|
|
183
|
+
// declared on the collection definition (beforeCreate, afterCreate, …) run
|
|
184
|
+
// inside those services — no separate wiring is needed here.
|
|
185
|
+
//
|
|
186
|
+
// Patches stay admin-internal: the client API does whole-document writes
|
|
187
|
+
// only. UI-level intent (array reordering, block insertion) belongs to the
|
|
188
|
+
// admin route layer, not to a framework-agnostic SDK.
|
|
189
|
+
// -------------------------------------------------------------------------
|
|
190
|
+
/**
|
|
191
|
+
* Create a new document in this collection.
|
|
192
|
+
*
|
|
193
|
+
* `data` is a plain object matching the collection's field shape. When
|
|
194
|
+
* `options.status` is omitted the collection's default status (from its
|
|
195
|
+
* workflow definition) is used.
|
|
196
|
+
*/
|
|
197
|
+
async create(data, options = {}) {
|
|
198
|
+
const ctx = await this.buildLifecycleContext();
|
|
199
|
+
return createDocument(ctx, {
|
|
200
|
+
data,
|
|
201
|
+
locale: options.locale,
|
|
202
|
+
status: options.status,
|
|
203
|
+
path: options.path,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Update an existing document via full replacement (PUT semantics).
|
|
208
|
+
* Creates a new immutable version row. Hooks receive the real previous
|
|
209
|
+
* version as `originalData`.
|
|
210
|
+
*/
|
|
211
|
+
async update(documentId, data, options = {}) {
|
|
212
|
+
const ctx = await this.buildLifecycleContext();
|
|
213
|
+
return updateDocument(ctx, {
|
|
214
|
+
documentId,
|
|
215
|
+
data,
|
|
216
|
+
locale: options.locale,
|
|
217
|
+
path: options.path,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Change a document's workflow status. The transition is validated
|
|
222
|
+
* against the collection's declared workflow (±1 step or reset-to-first);
|
|
223
|
+
* transitioning to `'published'` auto-archives any other published
|
|
224
|
+
* versions of the same document.
|
|
225
|
+
*/
|
|
226
|
+
async changeStatus(documentId, nextStatus) {
|
|
227
|
+
const ctx = await this.buildLifecycleContext();
|
|
228
|
+
return changeDocumentStatus(ctx, { documentId, nextStatus });
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Archive the currently-published version(s) of a document.
|
|
232
|
+
*/
|
|
233
|
+
async unpublish(documentId) {
|
|
234
|
+
const ctx = await this.buildLifecycleContext();
|
|
235
|
+
return unpublishDocument(ctx, { documentId });
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Soft-delete a document. All versions are flagged `is_deleted = true`
|
|
239
|
+
* and disappear from read paths (the `current_documents` view filters
|
|
240
|
+
* them out). When the collection has any upload-capable image/file
|
|
241
|
+
* field and a storage provider is configured, the original file and
|
|
242
|
+
* every persisted variant on each upload-capable field are removed
|
|
243
|
+
* after the DB soft-delete — failures there are logged but non-fatal.
|
|
244
|
+
*/
|
|
245
|
+
async delete(documentId) {
|
|
246
|
+
const ctx = await this.buildLifecycleContext();
|
|
247
|
+
return deleteDocument(ctx, { documentId });
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Count documents visible to the current actor, optionally filtered by
|
|
251
|
+
* status.
|
|
252
|
+
*
|
|
253
|
+
* Applies the collection's `beforeRead` predicate so the count reflects
|
|
254
|
+
* only the rows the actor can see (multi-tenant scoping, owner-only
|
|
255
|
+
* drafts, soft-delete hide, etc).
|
|
256
|
+
*/
|
|
257
|
+
async count(where) {
|
|
258
|
+
const counts = await this.countByStatus({
|
|
259
|
+
_bypassBeforeRead: where?._bypassBeforeRead,
|
|
260
|
+
});
|
|
261
|
+
if (where?.status) {
|
|
262
|
+
const match = counts.find((c) => c.status === where.status);
|
|
263
|
+
return match?.count ?? 0;
|
|
264
|
+
}
|
|
265
|
+
return counts.reduce((sum, c) => sum + c.count, 0);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Per-status document counts for this collection. Used by admin status
|
|
269
|
+
* bars / dashboards. Applies `beforeRead` so per-status counts reflect
|
|
270
|
+
* only the actor's visible rows.
|
|
271
|
+
*/
|
|
272
|
+
async countByStatus(options = {}) {
|
|
273
|
+
const requestContext = await this.resolveAndAssertRead();
|
|
274
|
+
const collectionId = await this.client.resolveCollectionId(this.definition.path);
|
|
275
|
+
const filters = await this.resolveBeforeReadFilters(requestContext, createReadContext(), options._bypassBeforeRead);
|
|
276
|
+
return this.client.db.queries.documents.getDocumentCountsByStatus({
|
|
277
|
+
collection_id: collectionId,
|
|
278
|
+
filters,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Fetch the version history for a single document. Applies `beforeRead`
|
|
283
|
+
* as an access gate via `findById` — if the actor can't see the
|
|
284
|
+
* document at all, history returns an empty result rather than
|
|
285
|
+
* leaking version metadata.
|
|
286
|
+
*
|
|
287
|
+
* Each version in the response is a shaped `ClientDocument`. Pagination
|
|
288
|
+
* mirrors the storage adapter's `{ documents, meta }` shape, then is
|
|
289
|
+
* mapped to the same `{ docs, meta }` envelope `find()` returns.
|
|
290
|
+
*/
|
|
291
|
+
async history(documentId, options = {}) {
|
|
292
|
+
const _requestContext = await this.resolveAndAssertRead();
|
|
293
|
+
const collectionId = await this.client.resolveCollectionId(this.definition.path);
|
|
294
|
+
const readCtx = options._readContext ?? createReadContext();
|
|
295
|
+
const locale = options.locale ?? 'en';
|
|
296
|
+
const page = options.page ?? 1;
|
|
297
|
+
const pageSize = options.pageSize ?? 20;
|
|
298
|
+
// Access gate. `findById` runs `beforeRead`; a `null` here means either
|
|
299
|
+
// the document does not exist or the actor's predicate excludes it. In
|
|
300
|
+
// both cases an empty history is the correct response.
|
|
301
|
+
//
|
|
302
|
+
// `status: 'any'` so the gate asks "can the actor see *any* version of
|
|
303
|
+
// this document?" rather than the client's default "is there a
|
|
304
|
+
// published version they can see?". A draft-only document with the
|
|
305
|
+
// owning actor should still surface history; using the published-only
|
|
306
|
+
// default would gate them out incorrectly.
|
|
307
|
+
if (!options._bypassBeforeRead) {
|
|
308
|
+
const accessible = await this.findById(documentId, {
|
|
309
|
+
locale,
|
|
310
|
+
status: 'any',
|
|
311
|
+
_readContext: readCtx,
|
|
312
|
+
});
|
|
313
|
+
if (accessible == null) {
|
|
314
|
+
return {
|
|
315
|
+
docs: [],
|
|
316
|
+
meta: { total: 0, page, pageSize, totalPages: 0 },
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const result = await this.client.db.queries.documents.getDocumentHistory({
|
|
321
|
+
collection_id: collectionId,
|
|
322
|
+
document_id: documentId,
|
|
323
|
+
locale,
|
|
324
|
+
page,
|
|
325
|
+
page_size: pageSize,
|
|
326
|
+
order: options.order,
|
|
327
|
+
desc: options.desc,
|
|
328
|
+
});
|
|
329
|
+
return {
|
|
330
|
+
docs: result.documents.map((d) => this.shapeWithPopulated(d)),
|
|
331
|
+
meta: {
|
|
332
|
+
total: result.meta.total,
|
|
333
|
+
page: result.meta.page,
|
|
334
|
+
pageSize: result.meta.page_size,
|
|
335
|
+
totalPages: result.meta.total_pages,
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Fetch a specific version of a document by its `documentVersionId`.
|
|
341
|
+
* Used by admin diff views.
|
|
342
|
+
*
|
|
343
|
+
* Pass-through to `getDocumentByVersion`; access enforcement falls back
|
|
344
|
+
* to the collection-level `read` ability (asserted at the top of every
|
|
345
|
+
* read entry point). Row-level `beforeRead` does **not** apply here —
|
|
346
|
+
* version-by-id is a history-viewing primitive and the caller is
|
|
347
|
+
* expected to have already passed an access check on the parent
|
|
348
|
+
* document. Use `history()` instead if you want the access gate.
|
|
349
|
+
*/
|
|
350
|
+
async findByVersion(versionId, options = {}) {
|
|
351
|
+
await this.resolveAndAssertRead();
|
|
352
|
+
const locale = options.locale ?? 'en';
|
|
353
|
+
const raw = await this.client.db.queries.documents.getDocumentByVersion({
|
|
354
|
+
document_version_id: versionId,
|
|
355
|
+
locale,
|
|
356
|
+
});
|
|
357
|
+
if (raw == null)
|
|
358
|
+
return null;
|
|
359
|
+
return this.shapeWithPopulated(raw);
|
|
360
|
+
}
|
|
361
|
+
// -------------------------------------------------------------------------
|
|
362
|
+
// Internals
|
|
363
|
+
// -------------------------------------------------------------------------
|
|
364
|
+
/**
|
|
365
|
+
* Build a fresh `DocumentLifecycleContext` for a write call. Pulls the
|
|
366
|
+
* resolved collection id, inherits the client-wide logger and storage
|
|
367
|
+
* provider, and includes the collection definition so hooks can observe it.
|
|
368
|
+
*/
|
|
369
|
+
async buildLifecycleContext() {
|
|
370
|
+
const { id: collectionId, version: collectionVersion } = await this.client.resolveCollectionRecord(this.definition.path);
|
|
371
|
+
return {
|
|
372
|
+
db: this.client.db,
|
|
373
|
+
definition: this.definition,
|
|
374
|
+
collectionId,
|
|
375
|
+
collectionVersion,
|
|
376
|
+
collectionPath: this.definition.path,
|
|
377
|
+
storage: this.client.storage,
|
|
378
|
+
logger: this.client.logger,
|
|
379
|
+
defaultLocale: this.client.defaultLocale,
|
|
380
|
+
slugifier: this.client.slugifier,
|
|
381
|
+
requestContext: await this.client.resolveRequestContext(),
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Resolve the caller's `RequestContext` and enforce the read ability
|
|
386
|
+
* for this collection. Called at the top of every read entry point so
|
|
387
|
+
* reads and writes both fail closed at the service boundary.
|
|
388
|
+
*
|
|
389
|
+
* Returns the resolved context so callers can thread `readMode` and
|
|
390
|
+
* other per-request state into the adapter without re-resolving.
|
|
391
|
+
*/
|
|
392
|
+
async resolveAndAssertRead() {
|
|
393
|
+
const requestContext = await this.client.resolveRequestContext();
|
|
394
|
+
assertActorCanPerform(requestContext, this.definition.path, 'read');
|
|
395
|
+
return requestContext;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Invoke `populateDocuments` on a freshly-read (raw, storage-shape) set
|
|
399
|
+
* of documents when the caller asked for populate. No-op otherwise.
|
|
400
|
+
*
|
|
401
|
+
* Runs BEFORE `shapeDocument` so the populate service sees the raw
|
|
402
|
+
* `{document_id, fields}` shape it expects. The shape pass
|
|
403
|
+
* (`shapeWithPopulated`) then walks the mutated tree and converts every
|
|
404
|
+
* newly-inserted raw sub-document into a `ClientDocument`.
|
|
405
|
+
*/
|
|
406
|
+
async populateIfRequested(collectionId, rawDocs, locale, readMode, requestContext, options) {
|
|
407
|
+
if (options.populate === undefined)
|
|
408
|
+
return;
|
|
409
|
+
await populateDocuments({
|
|
410
|
+
db: this.client.db,
|
|
411
|
+
collections: this.client.collections,
|
|
412
|
+
collectionId,
|
|
413
|
+
documents: rawDocs,
|
|
414
|
+
populate: options.populate,
|
|
415
|
+
depth: options.depth,
|
|
416
|
+
locale,
|
|
417
|
+
readMode,
|
|
418
|
+
readContext: options._readContext,
|
|
419
|
+
requestContext,
|
|
420
|
+
bypassBeforeRead: options._bypassBeforeRead,
|
|
421
|
+
richTextPopulate: this.client.richTextPopulate,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Apply richtext populate to a freshly-read set of source documents.
|
|
426
|
+
* Mirrors what `populateDocuments` does for materialised targets, but
|
|
427
|
+
* runs unconditionally for sources because `richTextPopulate` is a
|
|
428
|
+
* framework-managed phase rather than a user-opted DSL like
|
|
429
|
+
* `populate`/`depth`. Each leaf is gated by its own
|
|
430
|
+
* `populateRelationsOnRead` inside the service. No-ops when no adapter
|
|
431
|
+
* is registered.
|
|
432
|
+
*/
|
|
433
|
+
async richTextPopulateSources(rawDocs, readContext) {
|
|
434
|
+
const populate = this.client.richTextPopulate;
|
|
435
|
+
if (!populate || rawDocs.length === 0)
|
|
436
|
+
return;
|
|
437
|
+
await populateRichTextFields({
|
|
438
|
+
fields: this.definition.fields,
|
|
439
|
+
collectionPath: this.definition.path,
|
|
440
|
+
documents: rawDocs,
|
|
441
|
+
populate,
|
|
442
|
+
readContext,
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Resolve and cache the `beforeRead` hook predicate for this collection
|
|
447
|
+
* inside the current `ReadContext`. Honours `_bypassBeforeRead` (admin
|
|
448
|
+
* tooling, seeds, migrations).
|
|
449
|
+
*/
|
|
450
|
+
async resolveBeforeReadPredicate(requestContext, readContext, bypass) {
|
|
451
|
+
if (bypass)
|
|
452
|
+
return null;
|
|
453
|
+
return applyBeforeRead({
|
|
454
|
+
definition: this.definition,
|
|
455
|
+
requestContext,
|
|
456
|
+
readContext,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Like `resolveBeforeReadPredicate`, but parses the predicate to the
|
|
461
|
+
* adapter-facing `DocumentFilter[]` shape used by `getDocumentById` /
|
|
462
|
+
* `getDocumentByPath`. Returns `undefined` (not `[]`) when there is no
|
|
463
|
+
* scoping, so the adapter can skip the loop entirely.
|
|
464
|
+
*/
|
|
465
|
+
async resolveBeforeReadFilters(requestContext, readContext, bypass) {
|
|
466
|
+
const predicate = await this.resolveBeforeReadPredicate(requestContext, readContext, bypass);
|
|
467
|
+
if (predicate == null)
|
|
468
|
+
return undefined;
|
|
469
|
+
const parsed = await parseWhere(predicate, this.definition, {
|
|
470
|
+
collections: this.client.collections,
|
|
471
|
+
resolveCollectionId: (path) => this.client.resolveCollectionId(path),
|
|
472
|
+
logger: this.client.logger,
|
|
473
|
+
});
|
|
474
|
+
return parsed.filters.length > 0 ? parsed.filters : undefined;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Shape a raw doc to `ClientDocument<F>`, then recursively shape any
|
|
478
|
+
* populated raw sub-documents inside its `fields`. Stubs
|
|
479
|
+
* (`_resolved: false` / `_cycle: true`) and plain field values are
|
|
480
|
+
* preserved by reference.
|
|
481
|
+
*/
|
|
482
|
+
shapeWithPopulated(raw) {
|
|
483
|
+
const shaped = shapeDocument(raw);
|
|
484
|
+
shaped.fields = shapePopulatedInPlace(shaped.fields);
|
|
485
|
+
return shaped;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Resolve the client-facing `status` option to an adapter `readMode`.
|
|
490
|
+
*
|
|
491
|
+
* Public @byline/client consumers default to `'published'` — safer for
|
|
492
|
+
* non-admin use because a newer draft won't leak through populate or
|
|
493
|
+
* over-write the previously-published content a reader expects to see.
|
|
494
|
+
* Callers (typically admin server fns) pass `'any'` explicitly when
|
|
495
|
+
* they want the current version regardless of status.
|
|
496
|
+
*/
|
|
497
|
+
function resolveReadMode(status) {
|
|
498
|
+
return status ?? 'published';
|
|
499
|
+
}
|
|
500
|
+
/** Mutate `raw.fields` to retain only the entries matching `select`. */
|
|
501
|
+
function trimFields(raw, select) {
|
|
502
|
+
const fields = raw.fields;
|
|
503
|
+
if (fields == null || typeof fields !== 'object')
|
|
504
|
+
return;
|
|
505
|
+
const allowed = new Set(select);
|
|
506
|
+
for (const k of Object.keys(fields)) {
|
|
507
|
+
if (!allowed.has(k))
|
|
508
|
+
delete fields[k];
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
//# sourceMappingURL=collection-handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-handle.js","sourceRoot":"","sources":["../src/collection-handle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgBH,OAAO,EACL,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,GACf,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAepE;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAc;IACpB,UAAU,CAAsB;IAExC,YAAY,MAAoB,EAAE,UAAgC;QAChE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,CAA0B,UAA0B,EAAE;QAC9D,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAA;QACxD,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QAChF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,GAAG,CAAC,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,OAAO,CAAA;QAC/E,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAChD,MAAM,OAAO,GA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AAC,CAAC,CAAC,CAAA;IACvC,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export { type ChangeStatusResult, type CreateDocumentResult, type CycleRelationValue, createReadContext, type DeleteDocumentResult, ERR_CONFLICT, ERR_INVALID_TRANSITION, ERR_NOT_FOUND, ERR_READ_BUDGET_EXCEEDED, ERR_VALIDATION, type PopulatedRelationValue, type PopulateFieldOptions, type PopulateFieldSpec, type PopulateMap, type PopulateSpec, type ReadContext, type ReadMode, type UnpublishResult, type UnresolvedRelationValue, type UpdateDocumentResult, } from '@byline/core';
|
|
9
|
+
export { BylineClient, createBylineClient } from './client.js';
|
|
10
|
+
export { CollectionHandle } from './collection-handle.js';
|
|
11
|
+
export type { BylineClientConfig, ClientDocument, CreateOptions, FilterOperators, FindByIdOptions, FindByPathOptions, FindOneOptions, FindOptions, FindResult, PopulatedRelation, SortDirection, SortSpec, UpdateOptions, WhereClause, WhereValue, WithPopulated, } from './types.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,iBAAiB,EACjB,KAAK,oBAAoB,EACzB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,wBAAwB,EACxB,cAAc,EACd,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,GAC1B,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,aAAa,EACb,WAAW,EACX,UAAU,EACV,aAAa,GACd,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export { createReadContext, ERR_CONFLICT, ERR_INVALID_TRANSITION, ERR_NOT_FOUND, ERR_READ_BUDGET_EXCEEDED, ERR_VALIDATION, } from '@byline/core';
|
|
9
|
+
export { BylineClient, createBylineClient } from './client.js';
|
|
10
|
+
export { CollectionHandle } from './collection-handle.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAIL,iBAAiB,EAEjB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,wBAAwB,EACxB,cAAc,GAWf,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { ClientDocument } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Shape an internal document (snake_case, storage layer format) into the
|
|
11
|
+
* public ClientDocument format (camelCase). The generic `F` types the
|
|
12
|
+
* `fields` property for callers that know their collection's shape.
|
|
13
|
+
*/
|
|
14
|
+
export declare function shapeDocument<F = Record<string, any>>(raw: Record<string, any>): ClientDocument<F>;
|
|
15
|
+
/**
|
|
16
|
+
* After `populateDocuments` replaces relation leaves with raw
|
|
17
|
+
* storage-shape documents, walk the tree and convert each one to a
|
|
18
|
+
* `ClientDocument` in place. Preserves reference equality for
|
|
19
|
+
* non-document values so stubs (`_resolved: false`, `_cycle: true`) and
|
|
20
|
+
* rich-text blobs are not rewritten.
|
|
21
|
+
*
|
|
22
|
+
* Call on `shaped.fields` after the top-level doc has already been
|
|
23
|
+
* shaped. The function mutates arrays in place (replacing populated
|
|
24
|
+
* entries) and returns the possibly-rewritten value for scalar inputs.
|
|
25
|
+
*/
|
|
26
|
+
export declare function shapePopulatedInPlace(value: unknown): unknown;
|
|
27
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAahD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACvB,cAAc,CAAC,CAAC,CAAC,CAUnB;AAaD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAqB7D"}
|