@nascentdigital/funnel-core 4.4.17 → 4.4.19

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.
@@ -1,5 +1,6 @@
1
1
  import { Tagged } from 'type-fest';
2
2
  import { Language } from '../regionalization';
3
+ import { UndefinedToNull } from '../types';
3
4
  import { Asset } from './Asset';
4
5
  import type { ChangeSet } from './ChangeSet';
5
6
  import type { CollectionSnapshot } from './CollectionSnapshot';
@@ -31,16 +32,20 @@ export declare namespace Collection {
31
32
  type GroupId = Tagged<string, 'funnel.Collection.GroupId'>;
32
33
  type Type = Tagged<string, 'funnel.Collection.Type'>;
33
34
  type State = 'draft' | 'published' | 'unpublished';
34
- type Update = Update.Name | Update.Tag | Update.ObjectInsert | Update.ArrayInsert | Update.ArrayDelete | Update.ArrayReorder | Update.Value;
35
+ type Update = Update.Collection | Update.ObjectInsert | Update.ArrayInsert | Update.ArrayDelete | Update.ArrayReorder | Update.Value;
35
36
  namespace Update {
36
- type Name = {
37
- type: 'name';
38
- name: string;
39
- };
40
- type Tag = {
41
- type: 'tags';
42
- tags: TagGroup.Data;
43
- };
37
+ type Collection = Collection.Name | Collection.Tags | Collection.Errors;
38
+ namespace Collection {
39
+ type Factory<TProp extends keyof Data> = {
40
+ type: 'collection';
41
+ property: TProp;
42
+ value: UndefinedToNull<Data[TProp]>;
43
+ };
44
+ export type Name = Factory<'name'>;
45
+ export type Tags = Factory<'tags'>;
46
+ export type Errors = Factory<'errors'>;
47
+ export {};
48
+ }
44
49
  type Value = {
45
50
  type: 'value';
46
51
  path: string[];
@@ -12,8 +12,7 @@ export declare class CollectionModel {
12
12
  * @param updates - a collection of updates to be applied to this collection.
13
13
  */
14
14
  update(updates: ReadonlyArray<Collection.Update>): void;
15
- private updateName;
16
- private updateTags;
15
+ private updateCollection;
17
16
  private updateObjectInsert;
18
17
  private updateArrayInsert;
19
18
  private updateArrayDelete;
@@ -34,11 +34,8 @@ class CollectionModel {
34
34
  // apply updates
35
35
  updates.forEach(update => {
36
36
  switch (update.type) {
37
- case 'name':
38
- this.updateName(update);
39
- break;
40
- case 'tags':
41
- this.updateTags(update);
37
+ case 'collection':
38
+ this.updateCollection(update);
42
39
  break;
43
40
  case 'object.insert':
44
41
  this.updateObjectInsert(update);
@@ -57,18 +54,15 @@ class CollectionModel {
57
54
  break;
58
55
  }
59
56
  });
60
- // finally, sync the model
61
- this.sync();
62
- }
63
- updateName(update) {
64
- // replace name
65
- const { data: collection } = this;
66
- collection.name = update.name;
67
57
  }
68
- updateTags(update) {
69
- // replace tags
70
- const { data: collection } = this;
71
- collection.tags = update.tags;
58
+ updateCollection(update) {
59
+ // clear value if updated value is null
60
+ const collection = this.data;
61
+ // if (update.value === null) {
62
+ // delete collection[update.property]
63
+ // }
64
+ // update value
65
+ collection[update.property] = update.value;
72
66
  }
73
67
  updateObjectInsert(_a) {
74
68
  var { value } = _a, update = __rest(_a, ["value"]);
@@ -1,6 +1,6 @@
1
1
  import { StringKeyOf, Tagged } from 'type-fest';
2
2
  import { Language, Localized } from '../regionalization';
3
- import { PartialBy } from '../types';
3
+ import { PartialBy, UndefinedToNull } from '../types';
4
4
  import { Asset } from './Asset';
5
5
  import { Block } from './Block';
6
6
  import type { ChangeSet } from './ChangeSet';
@@ -50,7 +50,6 @@ export declare namespace Page {
50
50
  namespace Update {
51
51
  type Page = Page.Name | Page.Tags | Page.Slug | Page.Url | Page.Preview | Page.Errors | Page.Publication;
52
52
  namespace Page {
53
- type UndefinedToNull<T> = T extends undefined ? null : T;
54
53
  type Factory<TProp extends keyof Data> = {
55
54
  type: 'page';
56
55
  property: TProp;
@@ -98,12 +98,12 @@ class PageModel {
98
98
  });
99
99
  }
100
100
  updatePage(update) {
101
- // clear value
101
+ // clear value if updated value is null
102
102
  const page = this.data;
103
103
  if (update.value === null) {
104
104
  delete page[update.property];
105
105
  }
106
- // update value
106
+ // otherwise update value
107
107
  else {
108
108
  page[update.property] = update.value;
109
109
  }
@@ -0,0 +1 @@
1
+ export type UndefinedToNull<T> = T extends undefined ? null : T;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -12,3 +12,4 @@ export * from './RequiredBy';
12
12
  export * from './Result';
13
13
  export * from './Timestamp';
14
14
  export * from './Transform';
15
+ export * from './UndefinedToNull';
@@ -28,3 +28,4 @@ __exportStar(require("./RequiredBy"), exports);
28
28
  __exportStar(require("./Result"), exports);
29
29
  __exportStar(require("./Timestamp"), exports);
30
30
  __exportStar(require("./Transform"), exports);
31
+ __exportStar(require("./UndefinedToNull"), exports);
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@nascentdigital/funnel-core",
3
- "version": "4.4.17",
3
+ "version": "4.4.19",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/nascentdigital/funnel.git",
6
6
  "directory": "libs/core"
7
7
  },
8
8
  "publishConfig": {
9
- "registry": "https://registry.npmjs.org/"
9
+ "registry": "https://registry.npmjs.org/",
10
+ "access": "public"
10
11
  },
11
12
  "main": "dist/index.js",
12
13
  "types": "dist/index.d.ts",
@@ -64,5 +65,5 @@
64
65
  "jest-tsd": "^0.2.2",
65
66
  "ts-jest": "^29.3.2"
66
67
  },
67
- "gitHead": "f343d2af0dff3dd7e8ae12a9ab83bceb93381ec2"
68
+ "gitHead": "d4ab7346c7b2e39897e5eb6be0a64e2f0278d51b"
68
69
  }