@obelism/content 0.4.0 → 0.5.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/README.md +9 -0
- package/dist/index.d.mts +5 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/index.mjs +23 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,15 @@ await content.getEntry('entry_…') // Entry | null
|
|
|
26
26
|
await content.getEntries({ contentType: 'post', limit: 20, skip: 0 }) // { items, total, limit, skip }
|
|
27
27
|
for await (const post of content.getAllEntries({ contentType: 'post' })) {
|
|
28
28
|
}
|
|
29
|
+
await content.getFirstEntry({
|
|
30
|
+
contentType: 'navigation',
|
|
31
|
+
fields: { key: 'main' },
|
|
32
|
+
}) // Entry | null
|
|
33
|
+
await content.getEntries({
|
|
34
|
+
contentType: 'post',
|
|
35
|
+
fields: { category: 'news', 'date[gte]': '2026-01-01', tags: ['a', 'b'] }, // a list: one of them
|
|
36
|
+
order: '-fields.date',
|
|
37
|
+
})
|
|
29
38
|
await content.getContentModel() // the model file
|
|
30
39
|
```
|
|
31
40
|
|
package/dist/index.d.mts
CHANGED
|
@@ -17,9 +17,12 @@ type RequestOptions = {
|
|
|
17
17
|
richText?: RichTextFormat | undefined;
|
|
18
18
|
init?: RequestInit | undefined;
|
|
19
19
|
};
|
|
20
|
+
type FieldFilterValue = string | number | boolean;
|
|
20
21
|
type EntriesQuery = RequestOptions & {
|
|
21
22
|
contentType?: string | undefined;
|
|
22
23
|
parentPath?: string | undefined;
|
|
24
|
+
fields?: Record<string, FieldFilterValue | readonly FieldFilterValue[]> | undefined;
|
|
25
|
+
order?: string | undefined;
|
|
23
26
|
limit?: number | undefined;
|
|
24
27
|
skip?: number | undefined;
|
|
25
28
|
};
|
|
@@ -29,7 +32,8 @@ declare class ContentClient {
|
|
|
29
32
|
constructor({ token, url, locale, depth, richText, timeout, init, fetch: fetchImpl, }: ContentClientOptions);
|
|
30
33
|
getPage: <TEntry extends Entry = Entry>(path: string, options?: RequestOptions) => Promise<TEntry | null>;
|
|
31
34
|
getEntry: <TEntry extends Entry = Entry>(id: string, options?: RequestOptions) => Promise<TEntry | null>;
|
|
32
|
-
getEntries: <TEntry extends Entry = Entry>({ contentType, parentPath, limit, skip, ...options }?: EntriesQuery) => Promise<EntryList<TEntry>>;
|
|
35
|
+
getEntries: <TEntry extends Entry = Entry>({ contentType, parentPath, fields, order, limit, skip, ...options }?: EntriesQuery) => Promise<EntryList<TEntry>>;
|
|
36
|
+
getFirstEntry: <TEntry extends Entry = Entry>(query?: Omit<EntriesQuery, "limit" | "skip">) => Promise<TEntry | null>;
|
|
33
37
|
getAllEntries<TEntry extends Entry = Entry>(query?: Omit<EntriesQuery, 'skip'>): AsyncGenerator<TEntry, void, undefined>;
|
|
34
38
|
getContentModel: (options?: Pick<RequestOptions, "init">) => Promise<ModelFile>;
|
|
35
39
|
}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sources":["../src/client.ts","../src/config.ts","../src/editable.ts","../src/errors.ts","../src/images.ts","../src/improve.ts","../src/preview.ts","../src/richText.ts"],"mappings":";;;AACA,KAAK,oBAAoB;AACzB;AACA;AACA;AACA;AACA,eAAe,cAAc;AAC7B;AACA,WAAW,WAAW;AACtB,mBAAmB,KAAK;AACxB;AACA,KAAK,cAAc;AACnB;AACA;AACA,eAAe,cAAc;AAC7B,WAAW,WAAW;AACtB;AACA,KAAK,YAAY,GAAG,cAAc;AAClC;AACA;AACA;AACA;AACA;AACA,cAAc,aAAa;AAC3B;AACA;AACA,2FAA2F,oBAAoB;AAC/G,6BAA6B,KAAK,GAAG,KAAK,0BAA0B,cAAc,KAAK,OAAO;AAC9F,8BAA8B,KAAK,GAAG,KAAK,wBAAwB,cAAc,KAAK,OAAO;AAC7F,gCAAgC,KAAK,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sources":["../src/client.ts","../src/config.ts","../src/editable.ts","../src/errors.ts","../src/images.ts","../src/improve.ts","../src/preview.ts","../src/richText.ts"],"mappings":";;;AACA,KAAK,oBAAoB;AACzB;AACA;AACA;AACA;AACA,eAAe,cAAc;AAC7B;AACA,WAAW,WAAW;AACtB,mBAAmB,KAAK;AACxB;AACA,KAAK,cAAc;AACnB;AACA;AACA,eAAe,cAAc;AAC7B,WAAW,WAAW;AACtB;AACA,KAAK,gBAAgB;AACrB,KAAK,YAAY,GAAG,cAAc;AAClC;AACA;AACA,aAAa,MAAM,SAAS,gBAAgB,YAAY,gBAAgB;AACxE;AACA;AACA;AACA;AACA,cAAc,aAAa;AAC3B;AACA;AACA,2FAA2F,oBAAoB;AAC/G,6BAA6B,KAAK,GAAG,KAAK,0BAA0B,cAAc,KAAK,OAAO;AAC9F,8BAA8B,KAAK,GAAG,KAAK,wBAAwB,cAAc,KAAK,OAAO;AAC7F,gCAAgC,KAAK,GAAG,KAAK,wEAAwE,YAAY,KAAK,OAAO,CAAC,SAAS;AACvJ,mCAAmC,KAAK,GAAG,KAAK,UAAU,IAAI,CAAC,YAAY,wBAAwB,OAAO;AAC1G,iCAAiC,KAAK,GAAG,KAAK,UAAU,IAAI,CAAC,YAAY,YAAY,cAAc;AACnG,gCAAgC,IAAI,CAAC,cAAc,cAAc,OAAO,CAAC,SAAS;AAClF;;ACpCA,cAAc,WAAW;;ACAzB,cAAc,aAAa;AAC3B,cAAc,eAAe;AAC7B,KAAK,QAAQ;AACb;AACA;AACA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA,yBAAyB,QAAQ;;ACXjC,cAAc,eAAe,SAAS,KAAK;AAC3C;AACA;AACA;AACA;AACA;;ACJA,KAAK,cAAc;AACnB;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,QAAQ,UAAU,IAAI,CAAC,KAAK,+BAA+B,cAAc;AACvF,cAAc,WAAW,UAAU,IAAI,CAAC,KAAK,iDAAiD,IAAI,CAAC,cAAc;;ACRjH,cAAc,aAAa;AAC3B,cAAc,cAAc,UAAU,KAAK,cAAc,YAAY;AACrE,cAAc,kBAAkB,kBAAkB,KAAK,SAAS,YAAY;;ACH5E,cAAc,cAAc;AAC5B;AACA;AACA;AACA;AACA;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,KAAK,iBAAiB,GAAG,GAAG,GAAG,eAAe,YAAY,MAAM;AAChE,cAAc,iBAAiB,UAAU,iBAAiB,KAAK,aAAa;;ACX5E,cAAc,SAAS,EAAE,MAAM;AAC/B,cAAc,UAAU;AACxB,KAAK,mBAAmB;AACxB,0BAA0B,KAAK,GAAG,SAAS,QAAQ,YAAY;AAC/D,0BAA0B,KAAK,QAAQ,YAAY;AACnD;AACA,cAAc,cAAc,QAAQ,YAAY,oDAAoD,mBAAmB;AACvH,cAAc,YAAY,SAAS,YAAY;AAC/C,cAAc,mBAAmB,QAAQ,YAAY;;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,9 +17,12 @@ type RequestOptions = {
|
|
|
17
17
|
richText?: RichTextFormat | undefined;
|
|
18
18
|
init?: RequestInit | undefined;
|
|
19
19
|
};
|
|
20
|
+
type FieldFilterValue = string | number | boolean;
|
|
20
21
|
type EntriesQuery = RequestOptions & {
|
|
21
22
|
contentType?: string | undefined;
|
|
22
23
|
parentPath?: string | undefined;
|
|
24
|
+
fields?: Record<string, FieldFilterValue | readonly FieldFilterValue[]> | undefined;
|
|
25
|
+
order?: string | undefined;
|
|
23
26
|
limit?: number | undefined;
|
|
24
27
|
skip?: number | undefined;
|
|
25
28
|
};
|
|
@@ -29,7 +32,8 @@ declare class ContentClient {
|
|
|
29
32
|
constructor({ token, url, locale, depth, richText, timeout, init, fetch: fetchImpl, }: ContentClientOptions);
|
|
30
33
|
getPage: <TEntry extends Entry = Entry>(path: string, options?: RequestOptions) => Promise<TEntry | null>;
|
|
31
34
|
getEntry: <TEntry extends Entry = Entry>(id: string, options?: RequestOptions) => Promise<TEntry | null>;
|
|
32
|
-
getEntries: <TEntry extends Entry = Entry>({ contentType, parentPath, limit, skip, ...options }?: EntriesQuery) => Promise<EntryList<TEntry>>;
|
|
35
|
+
getEntries: <TEntry extends Entry = Entry>({ contentType, parentPath, fields, order, limit, skip, ...options }?: EntriesQuery) => Promise<EntryList<TEntry>>;
|
|
36
|
+
getFirstEntry: <TEntry extends Entry = Entry>(query?: Omit<EntriesQuery, "limit" | "skip">) => Promise<TEntry | null>;
|
|
33
37
|
getAllEntries<TEntry extends Entry = Entry>(query?: Omit<EntriesQuery, 'skip'>): AsyncGenerator<TEntry, void, undefined>;
|
|
34
38
|
getContentModel: (options?: Pick<RequestOptions, "init">) => Promise<ModelFile>;
|
|
35
39
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sources":["../src/client.ts","../src/config.ts","../src/editable.ts","../src/errors.ts","../src/images.ts","../src/improve.ts","../src/preview.ts","../src/richText.ts"],"mappings":";;;AACA,KAAK,oBAAoB;AACzB;AACA;AACA;AACA;AACA,eAAe,cAAc;AAC7B;AACA,WAAW,WAAW;AACtB,mBAAmB,KAAK;AACxB;AACA,KAAK,cAAc;AACnB;AACA;AACA,eAAe,cAAc;AAC7B,WAAW,WAAW;AACtB;AACA,KAAK,YAAY,GAAG,cAAc;AAClC;AACA;AACA;AACA;AACA;AACA,cAAc,aAAa;AAC3B;AACA;AACA,2FAA2F,oBAAoB;AAC/G,6BAA6B,KAAK,GAAG,KAAK,0BAA0B,cAAc,KAAK,OAAO;AAC9F,8BAA8B,KAAK,GAAG,KAAK,wBAAwB,cAAc,KAAK,OAAO;AAC7F,gCAAgC,KAAK,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../src/client.ts","../src/config.ts","../src/editable.ts","../src/errors.ts","../src/images.ts","../src/improve.ts","../src/preview.ts","../src/richText.ts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B,kBAAkB,KAAK,SAAS,YAAY;;ACH5E,cAAc,cAAc;AAC5B;AACA;AACA;AACA;AACA;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,KAAK,iBAAiB,GAAG,GAAG,GAAG,eAAe,YAAY,MAAM;AAChE,cAAc,iBAAiB,UAAU,iBAAiB,KAAK,aAAa;;ACX5E,cAAc,SAAS,EAAE,MAAM;AAC/B,cAAc,UAAU;AACxB,KAAK,mBAAmB;AACxB,0BAA0B,KAAK,GAAG,SAAS,QAAQ,YAAY;AAC/D,0BAA0B,KAAK,QAAQ,YAAY;AACnD;AACA,cAAc,cAAc,QAAQ,YAAY,oDAAoD,mBAAmB;AACvH,cAAc,YAAY,SAAS,YAAY;AAC/C,cAAc,mBAAmB,QAAQ,YAAY;;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,18 @@ class ContentApiError extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
// `fields` as the API's `fields.<apiId>[op]` parameters.
|
|
20
|
+
const fieldParams = (fields)=>Object.fromEntries(Object.entries(fields ?? {}).map(([key, value])=>{
|
|
21
|
+
if (!Array.isArray(value)) return [
|
|
22
|
+
`fields.${key}`,
|
|
23
|
+
String(value)
|
|
24
|
+
];
|
|
25
|
+
const name = key.includes('[') ? key : `${key}[in]`;
|
|
26
|
+
return [
|
|
27
|
+
`fields.${name}`,
|
|
28
|
+
value.join(',')
|
|
29
|
+
];
|
|
30
|
+
}));
|
|
19
31
|
const trimSlashes = (path)=>path.replace(/^\/+|\/+$/g, '');
|
|
20
32
|
// Reads one space environment's content through the delivery API. The token
|
|
21
33
|
// decides the space, the environment and whether drafts are visible.
|
|
@@ -50,12 +62,22 @@ class ContentClient {
|
|
|
50
62
|
return result?.entry ?? null;
|
|
51
63
|
};
|
|
52
64
|
// One page of entries, ordered as in the space's tree.
|
|
53
|
-
this.getEntries = ({ contentType, parentPath, limit, skip, ...options } = {})=>this.#request('/entries', {
|
|
65
|
+
this.getEntries = ({ contentType, parentPath, fields, order, limit, skip, ...options } = {})=>this.#request('/entries', {
|
|
54
66
|
contentType,
|
|
55
67
|
parentPath: parentPath === undefined ? undefined : trimSlashes(parentPath),
|
|
68
|
+
...fieldParams(fields),
|
|
69
|
+
order,
|
|
56
70
|
limit,
|
|
57
71
|
skip
|
|
58
72
|
}, options);
|
|
73
|
+
// The first entry matching the query, or null: a settings entry, or a
|
|
74
|
+
// navigation by its key, without its id.
|
|
75
|
+
//
|
|
76
|
+
// await content.getFirstEntry({ contentType: 'navigation', fields: { key: 'main' } })
|
|
77
|
+
this.getFirstEntry = async (query = {})=>(await this.getEntries({
|
|
78
|
+
...query,
|
|
79
|
+
limit: 1
|
|
80
|
+
})).items[0] ?? null;
|
|
59
81
|
// The environment's content model, e.g. to generate types in a build.
|
|
60
82
|
this.getContentModel = (options = {})=>this.#request('/content-model', {}, options, {
|
|
61
83
|
defaults: false
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,18 @@ class ContentApiError extends Error {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// `fields` as the API's `fields.<apiId>[op]` parameters.
|
|
18
|
+
const fieldParams = (fields)=>Object.fromEntries(Object.entries(fields ?? {}).map(([key, value])=>{
|
|
19
|
+
if (!Array.isArray(value)) return [
|
|
20
|
+
`fields.${key}`,
|
|
21
|
+
String(value)
|
|
22
|
+
];
|
|
23
|
+
const name = key.includes('[') ? key : `${key}[in]`;
|
|
24
|
+
return [
|
|
25
|
+
`fields.${name}`,
|
|
26
|
+
value.join(',')
|
|
27
|
+
];
|
|
28
|
+
}));
|
|
17
29
|
const trimSlashes = (path)=>path.replace(/^\/+|\/+$/g, '');
|
|
18
30
|
// Reads one space environment's content through the delivery API. The token
|
|
19
31
|
// decides the space, the environment and whether drafts are visible.
|
|
@@ -48,12 +60,22 @@ class ContentClient {
|
|
|
48
60
|
return result?.entry ?? null;
|
|
49
61
|
};
|
|
50
62
|
// One page of entries, ordered as in the space's tree.
|
|
51
|
-
this.getEntries = ({ contentType, parentPath, limit, skip, ...options } = {})=>this.#request('/entries', {
|
|
63
|
+
this.getEntries = ({ contentType, parentPath, fields, order, limit, skip, ...options } = {})=>this.#request('/entries', {
|
|
52
64
|
contentType,
|
|
53
65
|
parentPath: parentPath === undefined ? undefined : trimSlashes(parentPath),
|
|
66
|
+
...fieldParams(fields),
|
|
67
|
+
order,
|
|
54
68
|
limit,
|
|
55
69
|
skip
|
|
56
70
|
}, options);
|
|
71
|
+
// The first entry matching the query, or null: a settings entry, or a
|
|
72
|
+
// navigation by its key, without its id.
|
|
73
|
+
//
|
|
74
|
+
// await content.getFirstEntry({ contentType: 'navigation', fields: { key: 'main' } })
|
|
75
|
+
this.getFirstEntry = async (query = {})=>(await this.getEntries({
|
|
76
|
+
...query,
|
|
77
|
+
limit: 1
|
|
78
|
+
})).items[0] ?? null;
|
|
57
79
|
// The environment's content model, e.g. to generate types in a build.
|
|
58
80
|
this.getContentModel = (options = {})=>this.#request('/content-model', {}, options, {
|
|
59
81
|
defaults: false
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@obelism/content",
|
|
3
3
|
"description": "Obelism Content SDK: the delivery API client, the visual editor bridge with prompt editing, editing on your own site, and the content model CLI",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
7
7
|
"headless-cms",
|