@nohead/sdk 0.4.0 → 0.6.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/CHANGELOG.md +56 -0
- package/README.md +63 -21
- package/dist/client.d.ts +2 -1
- package/dist/client.js +3 -1
- package/dist/core.d.ts +4 -1
- package/dist/generated/operations.gen.d.ts +24 -16
- package/dist/generated/operations.gen.js +3 -2
- package/dist/generated/schemas.gen.d.ts +1 -1
- package/dist/generated/types.gen.d.ts +188 -81
- package/dist/images.d.ts +75 -0
- package/dist/images.js +113 -0
- package/dist/resources/assets.d.ts +11 -6
- package/dist/resources/assets.js +19 -7
- package/dist/resources/drafts.d.ts +3 -4
- package/dist/resources/drafts.js +4 -15
- package/dist/resources/records.d.ts +14 -3
- package/dist/resources/records.js +15 -2
- package/dist/resources/schema.d.ts +10 -9
- package/dist/resources/schema.js +4 -4
- package/dist/types.d.ts +12 -8
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -1
package/dist/images.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image renditions without a request (`@nohead/sdk/images`). Image URLs are
|
|
3
|
+
* open: an image asset's `image_url` serves the whole image, and any of
|
|
4
|
+
* imgproxy's processing options written into it transform it
|
|
5
|
+
* (https://docs.imgproxy.net/usage/processing). No dependencies, so it suits
|
|
6
|
+
* browser bundles and frameworks' image components.
|
|
7
|
+
*
|
|
8
|
+
* imageUrl(asset, { width: 800, height: 600, fit: "cover", format: "webp" })
|
|
9
|
+
*/
|
|
10
|
+
const FITS = { contain: "fit", cover: "fill", fill: "force" };
|
|
11
|
+
/** A rendition of an image: its `image_url` with these options. */
|
|
12
|
+
export function imageUrl(image, options = {}) {
|
|
13
|
+
const base = typeof image === "string" ? image : image.image_url;
|
|
14
|
+
if (!base)
|
|
15
|
+
throw new TypeError("Not a ready image: it has no image_url");
|
|
16
|
+
const at = base.indexOf("/plain/");
|
|
17
|
+
if (at < 0)
|
|
18
|
+
throw new TypeError(`Not a Nohead image URL: ${base}`);
|
|
19
|
+
const { width, height, fit = "contain", format, quality, dpr, gravity, } = options;
|
|
20
|
+
for (const option of [gravity, ...(options.options ?? [])])
|
|
21
|
+
if (option && /[/@?#]/.test(option))
|
|
22
|
+
throw new TypeError(`Not an imgproxy option: ${option}`);
|
|
23
|
+
const segments = [];
|
|
24
|
+
if (width || height)
|
|
25
|
+
segments.push(`rs:${FITS[fit]}:${width ?? 0}:${height ?? 0}`);
|
|
26
|
+
if (gravity)
|
|
27
|
+
segments.push(`g:${gravity}`);
|
|
28
|
+
if (dpr)
|
|
29
|
+
segments.push(`dpr:${dpr}`);
|
|
30
|
+
if (quality)
|
|
31
|
+
segments.push(`q:${quality}`);
|
|
32
|
+
segments.push(...(options.options ?? []));
|
|
33
|
+
// The source comes last; a format replaces any the URL already names.
|
|
34
|
+
let source = base.slice(at);
|
|
35
|
+
if (format)
|
|
36
|
+
source = `${source.replace(/@[a-z]+$/, "")}@${format}`;
|
|
37
|
+
return `${base.slice(0, at)}${segments.map((s) => `/${s}`).join("")}${source}`;
|
|
38
|
+
}
|
|
39
|
+
/** Whether a URL is a Nohead image's: the loaders leave any other alone. */
|
|
40
|
+
export function isImageUrl(src) {
|
|
41
|
+
return (typeof src === "string" && /^https?:\/\/[^/]+\/(.*\/)?plain\//.test(src));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A Next.js image loader. In a file named by `images.loaderFile` in
|
|
45
|
+
* next.config: `export { nextImageLoader as default } from "@nohead/sdk/images"`,
|
|
46
|
+
* then `<Image src={asset.image_url} width={…} height={…} alt={asset.alt} />`.
|
|
47
|
+
* Other images (the site's own) are left as they are.
|
|
48
|
+
*/
|
|
49
|
+
export function nextImageLoader({ src, width, quality, }) {
|
|
50
|
+
return isImageUrl(src) ? imageUrl(src, { width, quality }) : src;
|
|
51
|
+
}
|
|
52
|
+
const FORMATS = new Set(["webp", "avif", "jpeg", "png"]);
|
|
53
|
+
// Astro's and Nuxt Image's fits, as imgproxy has them.
|
|
54
|
+
const FRAMEWORK_FITS = {
|
|
55
|
+
cover: "cover",
|
|
56
|
+
contain: "contain",
|
|
57
|
+
fill: "fill",
|
|
58
|
+
inside: "contain",
|
|
59
|
+
outside: "cover",
|
|
60
|
+
};
|
|
61
|
+
const fitOf = (fit) => typeof fit === "string" ? FRAMEWORK_FITS[fit] : undefined;
|
|
62
|
+
const formatOf = (format) => typeof format === "string" && FORMATS.has(format)
|
|
63
|
+
? format
|
|
64
|
+
: undefined;
|
|
65
|
+
/**
|
|
66
|
+
* An Astro image service (an external one: Astro never fetches the image).
|
|
67
|
+
* In a module named by `image.service.entrypoint` in astro.config:
|
|
68
|
+
* `export { astroImageService as default } from "@nohead/sdk/images"`.
|
|
69
|
+
* Other images (the site's own, imported or remote) are served as they are.
|
|
70
|
+
*/
|
|
71
|
+
export const astroImageService = {
|
|
72
|
+
getURL(options) {
|
|
73
|
+
const { src } = options;
|
|
74
|
+
if (!isImageUrl(src)) {
|
|
75
|
+
const own = typeof src === "string" ? src : src?.src;
|
|
76
|
+
return typeof own === "string" ? own : "";
|
|
77
|
+
}
|
|
78
|
+
return imageUrl(src, {
|
|
79
|
+
width: options.width,
|
|
80
|
+
height: options.height,
|
|
81
|
+
fit: fitOf(options.fit),
|
|
82
|
+
format: formatOf(options.format),
|
|
83
|
+
quality: typeof options.quality === "number" ? options.quality : undefined,
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Nuxt Image's custom provider (`getImage`). In a file named as a provider
|
|
89
|
+
* in nuxt.config's `image.providers`: on Nuxt Image 2,
|
|
90
|
+
* `export { nuxtImageProvider as default } from "@nohead/sdk/images"`; on
|
|
91
|
+
* Nuxt Image 1, `export { getImage } from "@nohead/sdk/images"`. Other
|
|
92
|
+
* images are left as they are.
|
|
93
|
+
*/
|
|
94
|
+
export function getImage(src, { modifiers = {} } = {}) {
|
|
95
|
+
const number = (value) => typeof value === "number"
|
|
96
|
+
? value
|
|
97
|
+
: typeof value === "string" && value
|
|
98
|
+
? Number(value)
|
|
99
|
+
: undefined;
|
|
100
|
+
if (!isImageUrl(src))
|
|
101
|
+
return { url: src };
|
|
102
|
+
return {
|
|
103
|
+
url: imageUrl(src, {
|
|
104
|
+
width: number(modifiers.width),
|
|
105
|
+
height: number(modifiers.height),
|
|
106
|
+
fit: fitOf(modifiers.fit),
|
|
107
|
+
format: formatOf(modifiers.format),
|
|
108
|
+
quality: number(modifiers.quality),
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** Nuxt Image 2's provider: what its `defineProvider({ getImage })` returns. */
|
|
113
|
+
export const nuxtImageProvider = () => ({ getImage });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { APIPromise, PagePromise } from "../api-promise.ts";
|
|
2
2
|
import type { RequestOptions } from "../core.ts";
|
|
3
|
-
import type { Asset, AssetUploadCreate, AssetWithUpload, AssetUsage, DownloadUrl
|
|
4
|
-
import type { AssetListParams
|
|
3
|
+
import type { Asset, AssetUpdate, AssetUploadCreate, AssetWithUpload, AssetUsage, DownloadUrl } from "../generated/types.gen.ts";
|
|
4
|
+
import type { AssetListParams } from "../types.ts";
|
|
5
5
|
import { Resource } from "./resource.ts";
|
|
6
6
|
/** What `assets.upload` accepts. A stream needs `byte_size`. */
|
|
7
7
|
export type Uploadable = Blob | ArrayBuffer | Uint8Array | ReadableStream;
|
|
@@ -38,8 +38,15 @@ export declare class Assets extends Resource {
|
|
|
38
38
|
createUpload(params: AssetUploadCreate, options?: RequestOptions): APIPromise<AssetWithUpload>;
|
|
39
39
|
/** Checks an uploaded file and marks the asset `ready`. */
|
|
40
40
|
complete(asset: string, options?: RequestOptions): APIPromise<Asset>;
|
|
41
|
-
list(params?: AssetListParams, options?: RequestOptions): PagePromise<Asset>;
|
|
41
|
+
list({ content_type, ...params }?: AssetListParams, options?: RequestOptions): PagePromise<Asset>;
|
|
42
42
|
get(asset: string, options?: RequestOptions): APIPromise<Asset>;
|
|
43
|
+
/**
|
|
44
|
+
* Renames the asset (`filename`) or sets its `alt` text (`null` or `""`
|
|
45
|
+
* clears it). The file itself can't change: upload a new asset for that.
|
|
46
|
+
* `alt` is the default wherever the asset is used. A deleted asset is a
|
|
47
|
+
* `ConflictError`: restore it first.
|
|
48
|
+
*/
|
|
49
|
+
update(asset: string, params: AssetUpdate, options?: RequestOptions): APIPromise<Asset>;
|
|
43
50
|
/**
|
|
44
51
|
* Soft-deletes the asset: `restore` brings it back until its
|
|
45
52
|
* `purge_after`, when the file is purged (or now, with `purge`).
|
|
@@ -60,8 +67,6 @@ export declare class Assets extends Resource {
|
|
|
60
67
|
* updated with the fields that use it (`uses`). Needs `records:read` too.
|
|
61
68
|
*/
|
|
62
69
|
usage(asset: string, options?: RequestOptions): APIPromise<AssetUsage>;
|
|
63
|
-
/** A
|
|
64
|
-
imageUrl(asset: string, params?: ImageUrlParams, options?: RequestOptions): APIPromise<ImageUrl>;
|
|
65
|
-
/** A 15-minute link to download the original file (`url`). */
|
|
70
|
+
/** A link to download the original file (`url`), valid for 2 minutes. */
|
|
66
71
|
downloadUrl(asset: string, options?: RequestOptions): APIPromise<DownloadUrl>;
|
|
67
72
|
}
|
package/dist/resources/assets.js
CHANGED
|
@@ -74,12 +74,28 @@ export class Assets extends Resource {
|
|
|
74
74
|
complete(asset, options) {
|
|
75
75
|
return this.core.request("assets_complete", { path: { asset_id: asset } }, options);
|
|
76
76
|
}
|
|
77
|
-
list(params = {}, options) {
|
|
78
|
-
return this.core.paginate("assets_list", {
|
|
77
|
+
list({ content_type, ...params } = {}, options) {
|
|
78
|
+
return this.core.paginate("assets_list", {
|
|
79
|
+
query: listQuery({
|
|
80
|
+
...params,
|
|
81
|
+
content_type: Array.isArray(content_type)
|
|
82
|
+
? { in: content_type }
|
|
83
|
+
: content_type,
|
|
84
|
+
}, ["deleted", "content_type"]),
|
|
85
|
+
}, options);
|
|
79
86
|
}
|
|
80
87
|
get(asset, options) {
|
|
81
88
|
return this.core.request("assets_get", { path: { asset_id: asset } }, options);
|
|
82
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Renames the asset (`filename`) or sets its `alt` text (`null` or `""`
|
|
92
|
+
* clears it). The file itself can't change: upload a new asset for that.
|
|
93
|
+
* `alt` is the default wherever the asset is used. A deleted asset is a
|
|
94
|
+
* `ConflictError`: restore it first.
|
|
95
|
+
*/
|
|
96
|
+
update(asset, params, options) {
|
|
97
|
+
return this.core.request("assets_update", { path: { asset_id: asset }, body: params }, options);
|
|
98
|
+
}
|
|
83
99
|
/**
|
|
84
100
|
* Soft-deletes the asset: `restore` brings it back until its
|
|
85
101
|
* `purge_after`, when the file is purged (or now, with `purge`).
|
|
@@ -108,11 +124,7 @@ export class Assets extends Resource {
|
|
|
108
124
|
usage(asset, options) {
|
|
109
125
|
return this.core.request("assets_usage", { path: { asset_id: asset } }, options);
|
|
110
126
|
}
|
|
111
|
-
/** A
|
|
112
|
-
imageUrl(asset, params = {}, options) {
|
|
113
|
-
return this.core.request("assets_image_url", { path: { asset_id: asset }, query: params }, options);
|
|
114
|
-
}
|
|
115
|
-
/** A 15-minute link to download the original file (`url`). */
|
|
127
|
+
/** A link to download the original file (`url`), valid for 2 minutes. */
|
|
116
128
|
downloadUrl(asset, options) {
|
|
117
129
|
return this.core.request("assets_download_url", { path: { asset_id: asset } }, options);
|
|
118
130
|
}
|
|
@@ -19,11 +19,10 @@ export declare class Drafts extends Resource {
|
|
|
19
19
|
*/
|
|
20
20
|
create<D = RecordData>(record: string, params?: DraftCreateParams<D>, options?: RequestOptions): APIPromise<NoheadDraft<D>>;
|
|
21
21
|
/**
|
|
22
|
-
* A collection's drafts, most recently changed first.
|
|
23
|
-
*
|
|
24
|
-
* `TypeError`, since it would match no record).
|
|
22
|
+
* A collection's drafts, most recently changed first. One record's draft
|
|
23
|
+
* is `records.drafts(record)`.
|
|
25
24
|
*/
|
|
26
|
-
list<D = RecordData>(collection: string,
|
|
25
|
+
list<D = RecordData>(collection: string, params?: DraftListParams, options?: RequestOptions): PagePromise<NoheadDraft<D>>;
|
|
27
26
|
/** With `data` as the record reads after the merge, for previews. */
|
|
28
27
|
get<D = RecordData>(draft: string, params?: DraftGetParams, options?: RequestOptions): APIPromise<NoheadDraft<D>>;
|
|
29
28
|
/** Sets the given fields (`null` clears one), as a record update does. */
|
package/dist/resources/drafts.js
CHANGED
|
@@ -17,22 +17,11 @@ export class Drafts extends Resource {
|
|
|
17
17
|
return this.core.request("drafts_create", { path: { record_id: record }, body: params }, options);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* A collection's drafts, most recently changed first.
|
|
21
|
-
*
|
|
22
|
-
* `TypeError`, since it would match no record).
|
|
20
|
+
* A collection's drafts, most recently changed first. One record's draft
|
|
21
|
+
* is `records.drafts(record)`.
|
|
23
22
|
*/
|
|
24
|
-
list(collection,
|
|
25
|
-
|
|
26
|
-
throw new TypeError("record_id needs at least one record ID");
|
|
27
|
-
const filter = record_id === undefined
|
|
28
|
-
? undefined
|
|
29
|
-
: {
|
|
30
|
-
record_id: Array.isArray(record_id) ? { in: record_id } : record_id,
|
|
31
|
-
};
|
|
32
|
-
return this.core.paginate("drafts_list", {
|
|
33
|
-
path: { collection_id: collection },
|
|
34
|
-
query: { ...params, ...(filter && { filter }) },
|
|
35
|
-
}, options);
|
|
23
|
+
list(collection, params = {}, options) {
|
|
24
|
+
return this.core.paginate("drafts_list", { path: { collection_id: collection }, query: params }, options);
|
|
36
25
|
}
|
|
37
26
|
/** With `data` as the record reads after the merge, for previews. */
|
|
38
27
|
get(draft, params = {}, options) {
|
|
@@ -12,8 +12,12 @@ export declare class Records extends Resource {
|
|
|
12
12
|
/** A collection's records, newest first by default. */
|
|
13
13
|
list<D = RecordData>(collection: string, params?: RecordListParams, options?: RequestOptions): PagePromise<NoheadRecord<D>>;
|
|
14
14
|
get<D = RecordData>(record: string, params?: RecordGetParams, options?: RequestOptions): APIPromise<NoheadRecord<D>>;
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Creates an unpublished record. With `upsert_on`, updates the record
|
|
17
|
+
* holding that unique value instead, if one exists, so a sync can run
|
|
18
|
+
* again without duplicates; `ifMatch` then applies to that update.
|
|
19
|
+
*/
|
|
20
|
+
create<D = RecordData>(collection: string, params: RecordCreateParams<D>, options?: ConditionalWriteOptions): APIPromise<NoheadRecord<D>>;
|
|
17
21
|
/** Sets the given fields (`null` clears one); others keep their values. */
|
|
18
22
|
update<D = RecordData>(record: string, params: RecordUpdateParams<D>, options?: ConditionalWriteOptions): APIPromise<NoheadRecord<D>>;
|
|
19
23
|
/**
|
|
@@ -63,7 +67,7 @@ export declare class Records extends Resource {
|
|
|
63
67
|
/** The changes between two revisions. */
|
|
64
68
|
diff(record: string, params: RecordDiffParams, options?: RequestOptions): APIPromise<RecordDiff>;
|
|
65
69
|
/**
|
|
66
|
-
* Full-text search in one collection
|
|
70
|
+
* Full-text search in one collection, matching its `searchable` fields.
|
|
67
71
|
* Pages through the first 1,000 hits, most relevant first.
|
|
68
72
|
*/
|
|
69
73
|
search<D = RecordData>(collection: string, query: string, params?: RecordSearchParams, options?: RequestOptions): PagePromise<NoheadRecord<D>, SearchMeta>;
|
|
@@ -79,3 +83,10 @@ export declare class Revisions extends Resource {
|
|
|
79
83
|
}, options?: ConditionalWriteOptions): APIPromise<RevertPreview>;
|
|
80
84
|
revert<D = RecordData>(record: string, revision: number, params?: DryRunParams, options?: ConditionalWriteOptions): APIPromise<NoheadRecord<D>>;
|
|
81
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* A revision by its own ID (`rev_…`), as webhooks and the activity log name
|
|
88
|
+
* it. Readable while its record is deleted.
|
|
89
|
+
*/
|
|
90
|
+
export declare class RevisionsById extends Resource {
|
|
91
|
+
get(revision: string, options?: RequestOptions): APIPromise<RecordRevisionDetail>;
|
|
92
|
+
}
|
|
@@ -12,7 +12,11 @@ export class Records extends Resource {
|
|
|
12
12
|
get(record, params = {}, options) {
|
|
13
13
|
return this.core.request("records_get", { path: { record_id: record }, query: params }, options);
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Creates an unpublished record. With `upsert_on`, updates the record
|
|
17
|
+
* holding that unique value instead, if one exists, so a sync can run
|
|
18
|
+
* again without duplicates; `ifMatch` then applies to that update.
|
|
19
|
+
*/
|
|
16
20
|
create(collection, params, options) {
|
|
17
21
|
return this.core.request("records_create", { path: { collection_id: collection }, body: params }, options);
|
|
18
22
|
}
|
|
@@ -93,7 +97,7 @@ export class Records extends Resource {
|
|
|
93
97
|
return this.core.request("records_diff", { path: { record_id: record }, query: params }, options);
|
|
94
98
|
}
|
|
95
99
|
/**
|
|
96
|
-
* Full-text search in one collection
|
|
100
|
+
* Full-text search in one collection, matching its `searchable` fields.
|
|
97
101
|
* Pages through the first 1,000 hits, most relevant first.
|
|
98
102
|
*/
|
|
99
103
|
search(collection, query, params = {}, options) {
|
|
@@ -113,3 +117,12 @@ export class Revisions extends Resource {
|
|
|
113
117
|
return this.core.request("record_revisions_revert", { path: { record_id: record, revision }, query: params }, options);
|
|
114
118
|
}
|
|
115
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* A revision by its own ID (`rev_…`), as webhooks and the activity log name
|
|
122
|
+
* it. Readable while its record is deleted.
|
|
123
|
+
*/
|
|
124
|
+
export class RevisionsById extends Resource {
|
|
125
|
+
get(revision, options) {
|
|
126
|
+
return this.core.request("revisions_get", { path: { revision_id: revision } }, options);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { APIPromise, PagePromise } from "../api-promise.ts";
|
|
2
2
|
import type { RequestOptions, WriteOptions } from "../core.ts";
|
|
3
3
|
import type { Collection, FieldOrder, CollectionCreate, CollectionUpdate, Field, FieldCreate, FieldMigration, FieldMigrationPreview, FieldUpdate, Schema, SchemaChange, SchemaChangeDetail, SearchIndex } from "../generated/types.gen.ts";
|
|
4
|
-
import type { DeletedListParams, DryRunParams,
|
|
4
|
+
import type { DeletedListParams, DryRunParams, FieldReorderParams, ListParams, MigrationCreateParams, SchemaParams } from "../types.ts";
|
|
5
5
|
import { Resource } from "./resource.ts";
|
|
6
6
|
/** Collections of the key's project. `collection` is an ID or slug. */
|
|
7
7
|
export declare class Collections extends Resource {
|
|
@@ -39,7 +39,7 @@ export declare class Fields extends Resource {
|
|
|
39
39
|
get(field: string, options?: RequestOptions): APIPromise<Field>;
|
|
40
40
|
/**
|
|
41
41
|
* Renames, describes or loosens a field. Changes that rewrite record
|
|
42
|
-
* values (type, `multiple`, tighter rules) are `
|
|
42
|
+
* values (type, `multiple`, tighter rules) are `migrations.create`.
|
|
43
43
|
*/
|
|
44
44
|
update(field: string, params: FieldUpdate, options?: WriteOptions): APIPromise<Field>;
|
|
45
45
|
/**
|
|
@@ -54,17 +54,18 @@ export declare class Fields extends Resource {
|
|
|
54
54
|
reorder(collection: string, params: FieldReorderParams, options?: WriteOptions): APIPromise<FieldOrder>;
|
|
55
55
|
/** Stops accepting a renamed field's old API key before its 6 months end. */
|
|
56
56
|
removeAlias(field: string, alias: string, options?: RequestOptions): APIPromise<Field>;
|
|
57
|
+
}
|
|
58
|
+
/** Field migrations. While one runs, its collection is read-only. */
|
|
59
|
+
export declare class Migrations extends Resource {
|
|
57
60
|
/**
|
|
58
|
-
* Starts a
|
|
59
|
-
*
|
|
61
|
+
* Starts a migration of one of the collection's fields (`field_id`): a
|
|
62
|
+
* type, `multiple`, tighter configuration or a backfill, which rewrites
|
|
63
|
+
* every record. With `dry_run`, previews it.
|
|
60
64
|
*/
|
|
61
|
-
|
|
65
|
+
create(collection: string, params: MigrationCreateParams & {
|
|
62
66
|
dry_run: true;
|
|
63
67
|
}, options?: WriteOptions): APIPromise<FieldMigrationPreview>;
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
/** Field migrations. While one runs, its collection is read-only. */
|
|
67
|
-
export declare class Migrations extends Resource {
|
|
68
|
+
create(collection: string, params: MigrationCreateParams & DryRunParams, options?: WriteOptions): APIPromise<FieldMigration>;
|
|
68
69
|
list(collection: string, params?: ListParams, options?: RequestOptions): PagePromise<FieldMigration>;
|
|
69
70
|
get(migration: string, options?: RequestOptions): APIPromise<FieldMigration>;
|
|
70
71
|
cancel(migration: string, options?: RequestOptions): APIPromise<FieldMigration>;
|
package/dist/resources/schema.js
CHANGED
|
@@ -66,7 +66,7 @@ export class Fields extends Resource {
|
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Renames, describes or loosens a field. Changes that rewrite record
|
|
69
|
-
* values (type, `multiple`, tighter rules) are `
|
|
69
|
+
* values (type, `multiple`, tighter rules) are `migrations.create`.
|
|
70
70
|
*/
|
|
71
71
|
update(field, params, options) {
|
|
72
72
|
return this.core.request("fields_update", { path: { field_id: field }, body: params }, options);
|
|
@@ -93,12 +93,12 @@ export class Fields extends Resource {
|
|
|
93
93
|
removeAlias(field, alias, options) {
|
|
94
94
|
return this.core.request("fields_remove_alias", { path: { field_id: field, alias } }, options);
|
|
95
95
|
}
|
|
96
|
-
migrate(field, { dry_run, ...body }, options) {
|
|
97
|
-
return this.core.request("fields_migrate", { path: { field_id: field }, query: { dry_run }, body }, options);
|
|
98
|
-
}
|
|
99
96
|
}
|
|
100
97
|
/** Field migrations. While one runs, its collection is read-only. */
|
|
101
98
|
export class Migrations extends Resource {
|
|
99
|
+
create(collection, { dry_run, ...body }, options) {
|
|
100
|
+
return this.core.request("migrations_create", { path: { collection_id: collection }, query: { dry_run }, body }, options);
|
|
101
|
+
}
|
|
102
102
|
list(collection, params = {}, options) {
|
|
103
103
|
return this.core.paginate("migrations_list", { path: { collection_id: collection }, query: params }, options);
|
|
104
104
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -71,6 +71,11 @@ export interface RecordGetParams {
|
|
|
71
71
|
}
|
|
72
72
|
export interface RecordCreateParams<D = G.RecordData> {
|
|
73
73
|
data: D;
|
|
74
|
+
/**
|
|
75
|
+
* The key of a `unique` field whose value `data` includes: the active
|
|
76
|
+
* record holding that value is updated instead, if there is one.
|
|
77
|
+
*/
|
|
78
|
+
upsert_on?: string;
|
|
74
79
|
}
|
|
75
80
|
export interface RecordUpdateParams<D = G.RecordData> {
|
|
76
81
|
data: RecordDataUpdate<D>;
|
|
@@ -88,8 +93,6 @@ export interface DraftGetParams {
|
|
|
88
93
|
expand?: string[];
|
|
89
94
|
}
|
|
90
95
|
export interface DraftListParams extends ListParams {
|
|
91
|
-
/** One record's draft, or several records' (up to 100). */
|
|
92
|
-
record_id?: string | string[];
|
|
93
96
|
sort?: "updated_at" | "-updated_at";
|
|
94
97
|
}
|
|
95
98
|
export interface DraftScheduleParams {
|
|
@@ -155,9 +158,9 @@ export interface DeletedListParams extends ListParams {
|
|
|
155
158
|
}
|
|
156
159
|
export interface AssetListParams extends DeletedListParams {
|
|
157
160
|
/**
|
|
158
|
-
* Only assets of
|
|
159
|
-
* `["image/*", "application/pdf"]`, such as an asset
|
|
160
|
-
* `accepted_types`.
|
|
161
|
+
* Only assets of a MIME type or `type/*` wildcard (`"image/*"`), or of any
|
|
162
|
+
* of several: `["image/*", "application/pdf"]`, such as an asset
|
|
163
|
+
* field's `accepted_types`.
|
|
161
164
|
*/
|
|
162
165
|
content_type?: string | string[];
|
|
163
166
|
}
|
|
@@ -165,12 +168,12 @@ export interface SchemaParams {
|
|
|
165
168
|
/** A past schema version; the current one otherwise. */
|
|
166
169
|
version?: number;
|
|
167
170
|
}
|
|
168
|
-
|
|
171
|
+
/** `field_id`, one of the collection's fields, and the parts of its definition to change. */
|
|
172
|
+
export type MigrationCreateParams = G.FieldMigrationRequest;
|
|
169
173
|
export interface FieldReorderParams {
|
|
170
174
|
/** Every active field of the collection, once each, in the new order. */
|
|
171
175
|
field_ids: string[];
|
|
172
176
|
}
|
|
173
|
-
export type ImageUrlParams = NonNullable<G.AssetsImageUrlData["query"]>;
|
|
174
177
|
export interface DeliveryListParams extends ListParams {
|
|
175
178
|
status?: "pending" | "succeeded" | "failed";
|
|
176
179
|
}
|
|
@@ -188,7 +191,8 @@ export interface AuditEventFilter {
|
|
|
188
191
|
}
|
|
189
192
|
export interface AuditEventListParams extends ListParams {
|
|
190
193
|
filter?: AuditEventFilter;
|
|
191
|
-
|
|
194
|
+
/** Newest first by default (`-created_at`). */
|
|
195
|
+
sort?: "created_at" | "-created_at";
|
|
192
196
|
}
|
|
193
197
|
/** The metadata of a search page: also an estimate of the total hits. */
|
|
194
198
|
export type SearchMeta = G.SearchResults["meta"];
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.6.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.6.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nohead/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Official TypeScript SDK for the Nohead API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://nohead.io",
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
"types": "./dist/webhooks.d.ts",
|
|
28
28
|
"default": "./dist/webhooks.js"
|
|
29
29
|
},
|
|
30
|
+
"./images": {
|
|
31
|
+
"types": "./dist/images.d.ts",
|
|
32
|
+
"default": "./dist/images.js"
|
|
33
|
+
},
|
|
30
34
|
"./package.json": "./package.json"
|
|
31
35
|
},
|
|
32
36
|
"files": [
|