@nohead/sdk 0.3.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/CHANGELOG.md CHANGED
@@ -5,6 +5,42 @@ Changes to `@nohead/sdk` that you can notice. Versions follow
5
5
  releases; a change that could break your code is a major one. Each release's
6
6
  section is its GitHub release's notes.
7
7
 
8
+ ## 0.5.0
9
+
10
+ - **Breaking:** field migrations are created under their collection:
11
+ `migrations.create(collection, { field_id, ...changes, dry_run? })`
12
+ (`POST /v1/collections/{collection_id}/migrations`) replaces
13
+ `fields.migrate(field, ...)`. It returns a preview for a dry run and the
14
+ `FieldMigration` otherwise, as before. `FieldMigrateParams` is
15
+ `MigrationCreateParams`, with `field_id`.
16
+ - **Breaking:** `drafts.list` no longer takes `record_id`; a record's drafts
17
+ are `records.drafts(record)`.
18
+ - **Breaking:** `assets.list`'s `content_type` is one MIME type or `type/*`
19
+ wildcard as a string, or several as a list (sent as
20
+ `filter[content_type][in]`). A comma-separated string no longer lists
21
+ several types: pass a list.
22
+ - **Breaking:** `auditEvents.list` sorts by `created_at` or `-created_at`
23
+ (the default), not `id`, and records no longer sort by `id`.
24
+ - Webhook events always carry `actor` and `via` (now required in
25
+ `WebhookEventPayload`), and `Via` no longer has `import` or `migration`,
26
+ which were never sent.
27
+
28
+ ## 0.4.0
29
+
30
+ - **Breaking:** a field's `api_key` is its `key` (in fields, their aliases,
31
+ `fields.create` and `fields.update`), as the editor's "Field key" says.
32
+ API keys keep their name.
33
+ - **Breaking:** `collections.schemaChanges.get(schemaChange)` takes the
34
+ schema change's ID alone (`GET /v1/schema-changes/{id}`).
35
+ - **Breaking:** `fields.update` no longer takes `type` or `multiple`; they
36
+ rewrite record values, so they are `fields.migrate`. The API refuses a
37
+ body key an operation doesn't take with `400` (`unknown_parameter`, naming
38
+ it), so a misspelt key no longer passes unnoticed.
39
+ - `Field` and `FieldCreate` are typed per field type: narrowing on
40
+ `field.type` types its `configuration` (`if (field.type === "enum")
41
+ field.configuration.options`), and `EnumFieldConfiguration`,
42
+ `RelationFieldConfiguration`... are exported.
43
+
8
44
  ## 0.3.0
9
45
 
10
46
  - **Breaking:** 0.1.0 and 0.2.0 no longer work with the API: its paths and
package/README.md CHANGED
@@ -118,7 +118,7 @@ await nohead.drafts.merge(draft.id) // or drafts.schedule(draft.id, { merge_at }
118
118
 
119
119
  - A record has at most one draft; starting a second is a `ConflictError` (detail code `draft_exists`, with its `draft_id`).
120
120
  - A merge changes content only: a live record stays live, an unpublished one unpublished. Publishing a live record with a pending draft is a `ConflictError` (`draft_pending`).
121
- - `records.drafts(id)` lists a record's draft, and `drafts.list(collection, { record_id })` a collection's (`record_id` takes up to 100 IDs).
121
+ - `records.drafts(id)` lists a record's draft, and `drafts.list(collection)` a collection's.
122
122
  - `drafts.discard` deletes one for good.
123
123
  - Drafts take the type of their data as records do: `drafts.get<Post>(id)` is a `Nohead.Draft<Post>` (also exported as `NoheadDraft`).
124
124
 
@@ -306,20 +306,24 @@ Search needs `search_enabled` collections and the `search:read` scope. It pages
306
306
  const posts = await nohead.collections.create({
307
307
  name: "Posts",
308
308
  slug: "posts",
309
- fields: [{ name: "Title", api_key: "title", type: "text", required: true }],
309
+ fields: [{ name: "Title", key: "title", type: "text", required: true }],
310
310
  })
311
311
  await nohead.fields.create("posts", {
312
312
  name: "Summary",
313
- api_key: "summary",
313
+ key: "summary",
314
314
  type: "long_text",
315
315
  })
316
316
 
317
317
  // Changes that rewrite records go through a migration; preview first
318
- const preview = await nohead.fields.migrate("fld_…", {
318
+ const preview = await nohead.migrations.create("posts", {
319
+ field_id: "fld_…",
319
320
  type: "long_text",
320
321
  dry_run: true,
321
322
  })
322
- const migration = await nohead.fields.migrate("fld_…", { type: "long_text" })
323
+ const migration = await nohead.migrations.create("posts", {
324
+ field_id: "fld_…",
325
+ type: "long_text",
326
+ })
323
327
  await nohead.migrations.get(migration.id)
324
328
  ```
325
329
 
@@ -370,8 +374,8 @@ response.headers.get("RateLimit-Remaining")
370
374
  | `collections` | `list`, `get`, `create`, `update`, `delete`, `restore`, `schema` |
371
375
  | `collections.schemaChanges` | `list`, `get` |
372
376
  | `collections.searchIndex` | `get`, `rebuild` |
373
- | `fields` | `list`, `get`, `create`, `update`, `delete`, `restore`, `order`, `reorder`, `removeAlias`, `migrate` |
374
- | `migrations` | `list`, `get`, `cancel` |
377
+ | `fields` | `list`, `get`, `create`, `update`, `delete`, `restore`, `order`, `reorder`, `removeAlias` |
378
+ | `migrations` | `create`, `list`, `get`, `cancel` |
375
379
  | `assets` | `upload`, `createUpload`, `complete`, `list`, `get`, `delete`, `restore`, `purge`, `usage`, `imageUrl`, `downloadUrl` |
376
380
  | `webhooks` | `list`, `get`, `create`, `update`, `delete`, `restore`, `rotateSecret`, `test`, `unwrap` |
377
381
  | `webhooks.secrets` | `list`, `retire` |
package/dist/core.js CHANGED
@@ -178,6 +178,11 @@ export class Core {
178
178
  }
179
179
  async #path(template, values = {}) {
180
180
  let path = template;
181
+ const names = [...template.matchAll(/\{(\w+)\}/g)].map(([, name]) => name);
182
+ // A value the template doesn't take is a method out of step with its operation.
183
+ for (const name of Object.keys(values))
184
+ if (!names.includes(name))
185
+ throw new TypeError(`${name} is not a path parameter of ${template}`);
181
186
  for (const [, name] of template.matchAll(/\{(\w+)\}/g)) {
182
187
  let value = values[name];
183
188
  if (value === undefined && name === "project_id") {
@@ -132,10 +132,6 @@ export declare const OPERATIONS: {
132
132
  readonly method: "GET";
133
133
  readonly path: "/v1/collections/{collection_id}/fields";
134
134
  };
135
- readonly fields_migrate: {
136
- readonly method: "POST";
137
- readonly path: "/v1/fields/{field_id}/migrations";
138
- };
139
135
  readonly fields_remove_alias: {
140
136
  readonly method: "DELETE";
141
137
  readonly path: "/v1/fields/{field_id}/aliases/{alias}";
@@ -164,6 +160,10 @@ export declare const OPERATIONS: {
164
160
  readonly method: "POST";
165
161
  readonly path: "/v1/migrations/{migration_id}/cancel";
166
162
  };
163
+ readonly migrations_create: {
164
+ readonly method: "POST";
165
+ readonly path: "/v1/collections/{collection_id}/migrations";
166
+ };
167
167
  readonly migrations_get: {
168
168
  readonly method: "GET";
169
169
  readonly path: "/v1/migrations/{migration_id}";
@@ -258,7 +258,7 @@ export declare const OPERATIONS: {
258
258
  };
259
259
  readonly schema_changes_get: {
260
260
  readonly method: "GET";
261
- readonly path: "/v1/collections/{collection_id}/schema-changes/{schema_change_id}";
261
+ readonly path: "/v1/schema-changes/{schema_change_id}";
262
262
  };
263
263
  readonly schema_changes_list: {
264
264
  readonly method: "GET";
@@ -459,10 +459,6 @@ export interface Operations {
459
459
  data: T.FieldsListData;
460
460
  response: T.FieldsListResponse;
461
461
  };
462
- fields_migrate: {
463
- data: T.FieldsMigrateData;
464
- response: T.FieldsMigrateResponse;
465
- };
466
462
  fields_remove_alias: {
467
463
  data: T.FieldsRemoveAliasData;
468
464
  response: T.FieldsRemoveAliasResponse;
@@ -491,6 +487,10 @@ export interface Operations {
491
487
  data: T.MigrationsCancelData;
492
488
  response: T.MigrationsCancelResponse;
493
489
  };
490
+ migrations_create: {
491
+ data: T.MigrationsCreateData;
492
+ response: T.MigrationsCreateResponse;
493
+ };
494
494
  migrations_get: {
495
495
  data: T.MigrationsGetData;
496
496
  response: T.MigrationsGetResponse;
@@ -32,7 +32,6 @@ export const OPERATIONS = {
32
32
  fields_get: { method: "GET", path: "/v1/fields/{field_id}" },
33
33
  fields_get_order: { method: "GET", path: "/v1/collections/{collection_id}/field-order" },
34
34
  fields_list: { method: "GET", path: "/v1/collections/{collection_id}/fields" },
35
- fields_migrate: { method: "POST", path: "/v1/fields/{field_id}/migrations" },
36
35
  fields_remove_alias: { method: "DELETE", path: "/v1/fields/{field_id}/aliases/{alias}" },
37
36
  fields_reorder: { method: "PUT", path: "/v1/collections/{collection_id}/field-order" },
38
37
  fields_restore: { method: "POST", path: "/v1/fields/{field_id}/restore" },
@@ -40,6 +39,7 @@ export const OPERATIONS = {
40
39
  health_check: { method: "GET", path: "/v1/health" },
41
40
  me_get: { method: "GET", path: "/v1/me" },
42
41
  migrations_cancel: { method: "POST", path: "/v1/migrations/{migration_id}/cancel" },
42
+ migrations_create: { method: "POST", path: "/v1/collections/{collection_id}/migrations" },
43
43
  migrations_get: { method: "GET", path: "/v1/migrations/{migration_id}" },
44
44
  migrations_list: { method: "GET", path: "/v1/collections/{collection_id}/migrations" },
45
45
  projects_search: { method: "GET", path: "/v1/projects/{project_id}/search" },
@@ -63,7 +63,7 @@ export const OPERATIONS = {
63
63
  records_unschedule: { method: "DELETE", path: "/v1/records/{record_id}/schedule" },
64
64
  records_update: { method: "PATCH", path: "/v1/records/{record_id}" },
65
65
  scheduled_changes_list: { method: "GET", path: "/v1/collections/{collection_id}/scheduled-changes" },
66
- schema_changes_get: { method: "GET", path: "/v1/collections/{collection_id}/schema-changes/{schema_change_id}" },
66
+ schema_changes_get: { method: "GET", path: "/v1/schema-changes/{schema_change_id}" },
67
67
  schema_changes_list: { method: "GET", path: "/v1/collections/{collection_id}/schema-changes" },
68
68
  search_index_get: { method: "GET", path: "/v1/collections/{collection_id}/search-index" },
69
69
  search_index_rebuild: { method: "POST", path: "/v1/collections/{collection_id}/search-index/rebuild" },
@@ -1 +1 @@
1
- export type { Actor, ApiKeyScope, Asset, AssetEventData, AssetList, AssetProperties, AssetUploadCreate, AssetUploadTarget, AssetUsage, AssetWithUpload, AuditEvent, AuditEventList, Change, Collection, CollectionCreate, CollectionList, CollectionUpdate, DownloadUrl, Draft, DraftCreate, DraftEventData, DraftList, DraftSchedule, DraftScheduleUpdate, Error, ErrorDetail, ErrorType, FeatureFlags, Field, FieldAliasEventData, FieldCreate, FieldDefinition, FieldList, FieldMigration, FieldMigrationCounts, FieldMigrationList, FieldMigrationPreview, FieldMigrationRequest, FieldOrder, FieldType, FieldUpdate, Health, ImageUrl, ListMeta, MergedDraft, NullableTimestamp, Principal, PublishedOnly, RecordBatch, RecordBatchRequest, RecordCount, RecordData, RecordDiff, RecordEventData, RecordFilterValue, RecordList, RecordPublication, RecordRevision, RecordRevisionDetail, RecordRevisionList, RecordRevisionOperation, RecordRevisionProperties, RecordSchedule, RecordScheduleUpdate, RecordWrite, RequestId, RevertPreview, ScheduledChange, ScheduledChangeList, Schema, SchemaChange, SchemaChangeDetail, SchemaChangeList, SchemaChangeProperties, SchemaDefinition, SchemaEventData, SearchIndex, SearchResults, TimeFilter, Timestamp, Via, Webhook, WebhookCreate, WebhookDelivery, WebhookDeliveryDetail, WebhookDeliveryList, WebhookDeliveryProperties, WebhookEventPayload, WebhookEventType, WebhookList, WebhookProperties, WebhookSecret, WebhookSecretList, WebhookSecretProperties, WebhookSecretWithValue, WebhookSubscription, WebhookTestEventData, WebhookUpdate, WebhookWithSecret, } from "./types.gen.ts";
1
+ export type { Actor, ApiKeyScope, Asset, AssetEventData, AssetField, AssetFieldConfiguration, AssetFieldCreate, AssetList, AssetProperties, AssetUploadCreate, AssetUploadTarget, AssetUsage, AssetWithUpload, AuditEvent, AuditEventList, BooleanField, BooleanFieldConfiguration, BooleanFieldCreate, Change, Collection, CollectionCreate, CollectionList, CollectionUpdate, DateField, DateFieldConfiguration, DateFieldCreate, DecimalField, DecimalFieldConfiguration, DecimalFieldCreate, DownloadUrl, Draft, DraftCreate, DraftEventData, DraftList, DraftSchedule, DraftScheduleUpdate, EnumField, EnumFieldConfiguration, EnumFieldCreate, Error, ErrorDetail, ErrorType, FeatureFlags, Field, FieldAliasEventData, FieldConfiguration, FieldCreate, FieldCreateProperties, FieldDefinition, FieldList, FieldMigration, FieldMigrationCounts, FieldMigrationList, FieldMigrationPreview, FieldMigrationRequest, FieldOrder, FieldProperties, FieldType, FieldUpdate, Health, ImageUrl, IntegerField, IntegerFieldConfiguration, IntegerFieldCreate, JsonField, JsonFieldConfiguration, JsonFieldCreate, ListMeta, LongTextField, LongTextFieldConfiguration, LongTextFieldCreate, MergedDraft, NullableTimestamp, Principal, PublishedOnly, RecordBatch, RecordBatchRequest, RecordCount, RecordData, RecordDiff, RecordEventData, RecordFilterValue, RecordList, RecordPublication, RecordRevision, RecordRevisionDetail, RecordRevisionList, RecordRevisionOperation, RecordRevisionProperties, RecordSchedule, RecordScheduleUpdate, RecordWrite, RelationField, RelationFieldConfiguration, RelationFieldCreate, RequestId, RevertPreview, RichTextField, RichTextFieldConfiguration, RichTextFieldCreate, ScheduledChange, ScheduledChangeList, Schema, SchemaChange, SchemaChangeDetail, SchemaChangeList, SchemaChangeProperties, SchemaDefinition, SchemaEventData, SearchIndex, SearchResults, TextField, TextFieldConfiguration, TextFieldCreate, TimeFilter, Timestamp, Via, Webhook, WebhookCreate, WebhookDelivery, WebhookDeliveryDetail, WebhookDeliveryList, WebhookDeliveryProperties, WebhookEventPayload, WebhookEventType, WebhookList, WebhookProperties, WebhookSecret, WebhookSecretList, WebhookSecretProperties, WebhookSecretWithValue, WebhookSubscription, WebhookTestEventData, WebhookUpdate, WebhookWithSecret, } from "./types.gen.ts";