@nascentdigital/funnel-core 4.5.7 → 4.6.1
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/dist/schema/Collection.d.ts +41 -10
- package/dist/schema/Collection.js +13 -0
- package/dist/schema/CollectionModel.d.ts +3 -3
- package/dist/schema/CollectionSnapshot.d.ts +1 -1
- package/dist/schema/LinkedCollectionModel.d.ts +1 -1
- package/dist/schema/LinkedData.d.ts +33 -14
- package/dist/schema/LinkedData.js +130 -76
- package/dist/schema/LinkedPage.d.ts +37 -0
- package/dist/schema/LinkedPage.js +103 -0
- package/dist/schema/Page.d.ts +55 -17
- package/dist/schema/Page.js +9 -0
- package/dist/schema/PageModel.d.ts +1 -1
- package/dist/schema/PageModel.js +1 -1
- package/dist/schema/PageSnapshot.d.ts +1 -1
- package/dist/schema/field/base/CollectionField.d.ts +1 -1
- package/dist/schema/field/base/DynamicPagesField.d.ts +7 -5
- package/dist/schema/field/base/DynamicPagesField.js +18 -2
- package/dist/schema/field/base/PageField.d.ts +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/types/TrackedValue.d.ts +8 -0
- package/dist/types/TrackedValue.js +18 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/ui/Placement.d.ts +5 -2
- package/dist/ui/Placement.js +103 -91
- package/dist/utils/ObjectUtils.js +0 -1
- package/package.json +2 -2
- package/dist/schema/LinkedPageModel.d.ts +0 -11
- package/dist/schema/LinkedPageModel.js +0 -26
|
@@ -36,10 +36,10 @@ export declare namespace Collection {
|
|
|
36
36
|
namespace Update {
|
|
37
37
|
type Collection = Collection.Name | Collection.Tags | Collection.Errors;
|
|
38
38
|
namespace Collection {
|
|
39
|
-
type Factory<TProp extends keyof
|
|
39
|
+
type Factory<TProp extends keyof LegacyData> = {
|
|
40
40
|
type: 'collection';
|
|
41
41
|
property: TProp;
|
|
42
|
-
value: UndefinedToNull<
|
|
42
|
+
value: UndefinedToNull<LegacyData[TProp]>;
|
|
43
43
|
};
|
|
44
44
|
export type Name = Factory<'name'>;
|
|
45
45
|
export type Tags = Factory<'tags'>;
|
|
@@ -75,6 +75,27 @@ export declare namespace Collection {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
type Data<T extends Collection = Collection> = {
|
|
78
|
+
__root: 'collection';
|
|
79
|
+
id: Id;
|
|
80
|
+
groupId: GroupId;
|
|
81
|
+
type: T['type'];
|
|
82
|
+
tags: TagGroup.Data;
|
|
83
|
+
brand?: string;
|
|
84
|
+
language: Language;
|
|
85
|
+
version: number;
|
|
86
|
+
name: string;
|
|
87
|
+
fields: Data.ForFields<T['fields']>;
|
|
88
|
+
pageIds?: Page.Id[];
|
|
89
|
+
state: State;
|
|
90
|
+
errors: boolean;
|
|
91
|
+
changeSetId?: ChangeSet.Id;
|
|
92
|
+
snapshotId?: CollectionSnapshot.Id;
|
|
93
|
+
snapshot?: CollectionSnapshot;
|
|
94
|
+
createdOn: number;
|
|
95
|
+
updatedOn: number;
|
|
96
|
+
publishedOn?: number;
|
|
97
|
+
};
|
|
98
|
+
type LegacyData<T extends Collection = Collection> = {
|
|
78
99
|
__root: 'collection';
|
|
79
100
|
id: Id;
|
|
80
101
|
groupId: GroupId;
|
|
@@ -109,20 +130,20 @@ export declare namespace Collection {
|
|
|
109
130
|
const audit: ReadonlyArray<Audit>;
|
|
110
131
|
type Backup = Extract<All, 'snapshot'>;
|
|
111
132
|
const backup: ReadonlyArray<Backup>;
|
|
112
|
-
type All = keyof
|
|
133
|
+
type All = keyof LegacyData;
|
|
113
134
|
const all: ReadonlyArray<All>;
|
|
114
135
|
}
|
|
115
|
-
type AsDraft = Pick<
|
|
136
|
+
type AsDraft = Pick<LegacyData, AsDraft.Prop>;
|
|
116
137
|
namespace AsDraft {
|
|
117
138
|
type Prop = Exclude<Props.Id, 'id'> | Extract<Props.Audit, 'changeSetId'>;
|
|
118
139
|
const props: ReadonlyArray<Prop>;
|
|
119
140
|
}
|
|
120
|
-
type AsNew = Pick<
|
|
141
|
+
type AsNew = Pick<LegacyData, AsNew.Prop>;
|
|
121
142
|
namespace AsNew {
|
|
122
143
|
type Prop = Exclude<Props.Id, 'id' | 'groupId'> | Extract<Props.Audit, 'changeSetId'>;
|
|
123
144
|
const props: ReadonlyArray<Prop>;
|
|
124
145
|
}
|
|
125
|
-
type AsNewLanguage = Pick<
|
|
146
|
+
type AsNewLanguage = Pick<LegacyData, AsNewLanguage.Prop>;
|
|
126
147
|
namespace AsNewLanguage {
|
|
127
148
|
type Prop = Extract<Props.Id, 'type' | 'brand' | 'groupId' | 'version' | 'language'> | Extract<Props.Audit, 'changeSetId'>;
|
|
128
149
|
const props: ReadonlyArray<Prop>;
|
|
@@ -138,7 +159,7 @@ export declare namespace Collection {
|
|
|
138
159
|
type Prop = Props.Id | Props.Content | Extract<Props.Links, 'pageIds'> | Props.Audit;
|
|
139
160
|
const props: ReadonlyArray<Prop>;
|
|
140
161
|
}
|
|
141
|
-
type AsContent = Pick<
|
|
162
|
+
type AsContent = Pick<LegacyData, AsContent.Prop>;
|
|
142
163
|
namespace AsContent {
|
|
143
164
|
type Prop = Props.Id | Props.Content | Props.Links | Props.Audit;
|
|
144
165
|
const props: ReadonlyArray<Prop>;
|
|
@@ -151,7 +172,7 @@ export declare namespace Collection {
|
|
|
151
172
|
name: string;
|
|
152
173
|
instances: AsGroup.Instance[];
|
|
153
174
|
};
|
|
154
|
-
collection?:
|
|
175
|
+
collection?: FlattenedData;
|
|
155
176
|
};
|
|
156
177
|
namespace AsGroup {
|
|
157
178
|
type Instance = Pick<Data, Instance.Prop>;
|
|
@@ -172,12 +193,22 @@ export declare namespace Collection {
|
|
|
172
193
|
[key in keyof T as T[key] extends Optional<Field.Type> ? key : never]?: Field.Data.ForOptionalType<T[key]>;
|
|
173
194
|
};
|
|
174
195
|
}
|
|
196
|
+
type References = {
|
|
197
|
+
files: Record<Asset.Id, Asset.Linked>;
|
|
198
|
+
collections: Record<Collection.Id, Collection.Data.AsLink>;
|
|
199
|
+
};
|
|
200
|
+
type FlattenedData<T extends Collection = Collection> = References & {
|
|
201
|
+
data: Data<T>;
|
|
202
|
+
};
|
|
203
|
+
namespace FlattenedData {
|
|
204
|
+
function filter(value: any): value is FlattenedData;
|
|
205
|
+
}
|
|
175
206
|
type LinkedData<T extends Collection = Collection> = LinkedData.FromRef<T> | LinkedData.FromInline<T>;
|
|
176
207
|
namespace LinkedData {
|
|
177
|
-
type FromRef<T extends Collection = Collection> = Omit<
|
|
208
|
+
type FromRef<T extends Collection = Collection> = Omit<LegacyData<T>, 'fields'> & {
|
|
178
209
|
fields: ForFields<T['fields']>;
|
|
179
210
|
};
|
|
180
|
-
type FromInline<T extends Collection = Collection> = Pick<
|
|
211
|
+
type FromInline<T extends Collection = Collection> = Pick<LegacyData<T>, Exclude<Data.AsInline.Prop, 'fields'>> & {
|
|
181
212
|
fields: ForFields<T['fields']>;
|
|
182
213
|
};
|
|
183
214
|
type ForFields<T extends Fields = Fields> = {
|
|
@@ -162,4 +162,17 @@ exports.Collection = Collection;
|
|
|
162
162
|
}
|
|
163
163
|
Data.filter = filter;
|
|
164
164
|
})(Data = Collection.Data || (Collection.Data = {}));
|
|
165
|
+
let FlattenedData;
|
|
166
|
+
(function (FlattenedData) {
|
|
167
|
+
function filter(value) {
|
|
168
|
+
return utils_1.Value.typeOf(value) === 'object'
|
|
169
|
+
&& 'data' in value
|
|
170
|
+
&& Data.filter(value.data)
|
|
171
|
+
&& 'files' in value
|
|
172
|
+
&& utils_1.Value.typeOf(value.files) === 'object'
|
|
173
|
+
&& 'collections' in value
|
|
174
|
+
&& utils_1.Value.typeOf(value.collections) === 'object';
|
|
175
|
+
}
|
|
176
|
+
FlattenedData.filter = filter;
|
|
177
|
+
})(FlattenedData = Collection.FlattenedData || (Collection.FlattenedData = {}));
|
|
165
178
|
})(Collection || (exports.Collection = Collection = {}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Collection } from './Collection';
|
|
2
2
|
export declare class CollectionModel {
|
|
3
|
-
readonly data: Collection.
|
|
4
|
-
constructor(data: Collection.
|
|
3
|
+
readonly data: Collection.LegacyData;
|
|
4
|
+
constructor(data: Collection.LegacyData);
|
|
5
5
|
/**
|
|
6
6
|
* Synchronizes computed properties with the latest `CollectionModel` data (e.g. updating `name`)
|
|
7
7
|
*/
|
|
@@ -21,7 +21,7 @@ export declare class CollectionModel {
|
|
|
21
21
|
private setValue;
|
|
22
22
|
private find;
|
|
23
23
|
private findInValue;
|
|
24
|
-
static from(data: Collection.
|
|
24
|
+
static from(data: Collection.LegacyData): CollectionModel;
|
|
25
25
|
static fromDraft(data: Collection.Data.AsDraft): CollectionModel;
|
|
26
26
|
}
|
|
27
27
|
export declare namespace CollectionModel {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Tagged } from 'type-fest';
|
|
2
2
|
import { RequiredBy } from '../types';
|
|
3
3
|
import type { Collection } from './Collection';
|
|
4
|
-
export type CollectionSnapshot = RequiredBy<Pick<Collection.
|
|
4
|
+
export type CollectionSnapshot = RequiredBy<Pick<Collection.LegacyData, Exclude<Collection.Data.Props.Id, 'id'> | Collection.Data.Props.Content | 'createdOn' | 'updatedOn' | 'changeSetId'>, 'changeSetId'> & {
|
|
5
5
|
id: CollectionSnapshot.Id;
|
|
6
6
|
};
|
|
7
7
|
export declare namespace CollectionSnapshot {
|
|
@@ -5,5 +5,5 @@ import { Collection } from './Collection';
|
|
|
5
5
|
export declare class LinkedCollectionModel<TCollection extends Collection> {
|
|
6
6
|
readonly data: Collection.LinkedData<TCollection>;
|
|
7
7
|
constructor(data: Collection.LinkedData<TCollection>);
|
|
8
|
-
static fromCollectionData<TCollection extends Collection>(unlinkedData: Collection.
|
|
8
|
+
static fromCollectionData<TCollection extends Collection>(unlinkedData: Collection.LegacyData<TCollection>): LinkedCollectionModel<TCollection>;
|
|
9
9
|
}
|
|
@@ -6,39 +6,58 @@ import { DynamicPagesField, Field } from './field';
|
|
|
6
6
|
import { Page } from './Page';
|
|
7
7
|
export declare namespace LinkedData {
|
|
8
8
|
/**
|
|
9
|
-
* Link data, only resolving static
|
|
9
|
+
* Link data, only resolving static references
|
|
10
10
|
*/
|
|
11
|
-
function resolveStatic<TLinked>(args: Omit<
|
|
11
|
+
export function resolveStatic<TLinked>(args: Omit<LinkedDataArgs, 'resolvers'>): TLinked;
|
|
12
12
|
/**
|
|
13
|
-
* Link data, resolving static and dynamic
|
|
13
|
+
* Link data, resolving static and dynamic references
|
|
14
14
|
*/
|
|
15
|
-
function resolve<TLinked>(args:
|
|
16
|
-
|
|
15
|
+
export function resolve<TLinked>(args: LinkedDataArgs): Promise<TLinked>;
|
|
16
|
+
/**
|
|
17
|
+
* Find all dynamic references in data
|
|
18
|
+
*/
|
|
19
|
+
export function findDynamicRefs(unlinkedData: UnlinkedData): DynamicRefs;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve dynamic references using resolvers
|
|
22
|
+
*/
|
|
23
|
+
export function resolveDynamicRefs({ dynamicRefs, resolvers: { page: pageResolver } }: ResolveDynamicPagesArgs): Promise<DynamicEntities>;
|
|
24
|
+
export type LinkedDataArgs = {
|
|
17
25
|
unlinkedData: UnlinkedData;
|
|
18
26
|
resolvers: DynamicResolvers;
|
|
19
27
|
persona?: string;
|
|
20
28
|
stores?: TransformFromStores;
|
|
29
|
+
skipEntitiesScan?: boolean;
|
|
30
|
+
};
|
|
31
|
+
type ResolveDynamicPagesArgs = {
|
|
32
|
+
dynamicRefs: DynamicRefs;
|
|
33
|
+
resolvers: DynamicResolvers;
|
|
21
34
|
};
|
|
22
|
-
type UnlinkedData = ReadonlyObjectDeep<any>;
|
|
23
|
-
type
|
|
24
|
-
type
|
|
35
|
+
export type UnlinkedData = ReadonlyObjectDeep<any>;
|
|
36
|
+
export type DynamicRefs = Map<DynamicPagesField.Hash, Field.Data.DynamicPages[]>;
|
|
37
|
+
export type DynamicEntities = Map<DynamicPagesField.Hash, Page.LinkedData.AsPreview[]>;
|
|
38
|
+
export type StaticallyLinkedData = Tagged<UnlinkedData, 'linked.statically'>;
|
|
39
|
+
export type TransformFromStores = {
|
|
40
|
+
pages?: ReadonlyArray<Page.Data>;
|
|
25
41
|
assets?: ReadonlyArray<Asset.Linked>;
|
|
26
42
|
collections?: ReadonlyArray<Collection.Data.AsLink>;
|
|
43
|
+
dynamic?: DynamicEntities;
|
|
27
44
|
};
|
|
28
|
-
type
|
|
45
|
+
export type Entities = {
|
|
29
46
|
pages: Map<Page.Id, Page.Data>;
|
|
30
47
|
collections: Map<Collection.Id, Collection.Data.AsLink>;
|
|
31
48
|
assets: Map<Asset.Id, Asset.Linked>;
|
|
49
|
+
dynamic: DynamicEntities;
|
|
32
50
|
};
|
|
33
|
-
type
|
|
51
|
+
export type References = {
|
|
34
52
|
pageRefs: Map<Page.Id, Field.Data.Page[]>;
|
|
35
53
|
collectionRefs: Map<Collection.Id, Field.Data.Collection.Ref[]>;
|
|
36
54
|
assetRefs: Map<Asset.Id, Asset[]>;
|
|
37
|
-
|
|
55
|
+
dynamicRefs: DynamicRefs;
|
|
38
56
|
};
|
|
39
|
-
type PageQuery = DynamicPagesField.Query;
|
|
40
|
-
type PageResolver = (value: PageQuery) => Promise<Page.Data.AsPreview[]>;
|
|
41
|
-
type DynamicResolvers = {
|
|
57
|
+
export type PageQuery = DynamicPagesField.Query;
|
|
58
|
+
export type PageResolver = (value: PageQuery) => Promise<Page.Data.AsPreview[]>;
|
|
59
|
+
export type DynamicResolvers = {
|
|
42
60
|
page: PageResolver;
|
|
43
61
|
};
|
|
62
|
+
export {};
|
|
44
63
|
}
|
|
@@ -11,66 +11,87 @@ const Page_1 = require("./Page");
|
|
|
11
11
|
var LinkedData;
|
|
12
12
|
(function (LinkedData) {
|
|
13
13
|
/**
|
|
14
|
-
* Link data, only resolving static
|
|
14
|
+
* Link data, only resolving static references
|
|
15
15
|
*/
|
|
16
16
|
function resolveStatic(args) {
|
|
17
|
-
// base
|
|
18
|
-
const { data } =
|
|
17
|
+
// base setup
|
|
18
|
+
const { data, references, entities } = setup(args);
|
|
19
|
+
// dereference data (mutates data)
|
|
20
|
+
link({ references, entities });
|
|
19
21
|
// return statically linked data
|
|
20
22
|
return data;
|
|
21
23
|
}
|
|
22
24
|
LinkedData.resolveStatic = resolveStatic;
|
|
23
25
|
/**
|
|
24
|
-
* Link data, resolving static and dynamic
|
|
26
|
+
* Link data, resolving static and dynamic references
|
|
25
27
|
*/
|
|
26
28
|
async function resolve(args) {
|
|
27
|
-
// base
|
|
28
|
-
const { data,
|
|
29
|
-
// resolve dynamic
|
|
30
|
-
await
|
|
29
|
+
// base setup
|
|
30
|
+
const { data, references, entities } = setup(args);
|
|
31
|
+
// resolve dynamic references
|
|
32
|
+
entities.dynamic = await resolveDynamicRefs({
|
|
33
|
+
dynamicRefs: references.dynamicRefs,
|
|
34
|
+
resolvers: args.resolvers
|
|
35
|
+
});
|
|
36
|
+
// dereference data (mutates data)
|
|
37
|
+
link({ references, entities });
|
|
31
38
|
// return linked data
|
|
32
39
|
return data;
|
|
33
40
|
}
|
|
34
41
|
LinkedData.resolve = resolve;
|
|
35
42
|
// base transform
|
|
36
|
-
function
|
|
37
|
-
// clone unlinked data (
|
|
43
|
+
function setup(args) {
|
|
44
|
+
// clone unlinked data (prevent data passed in from being mutated)
|
|
38
45
|
const unlinkedData = utils_1.ObjectUtils.clone(args.unlinkedData);
|
|
39
46
|
// resolve persona values (mutates data)
|
|
40
47
|
resolvePersonas({ data: unlinkedData, persona: args.persona });
|
|
41
|
-
// find all
|
|
42
|
-
const
|
|
43
|
-
|
|
48
|
+
// find all entities in data
|
|
49
|
+
const entities = args.skipEntitiesScan
|
|
50
|
+
? createEmptyEntities()
|
|
51
|
+
: findEntities(unlinkedData);
|
|
52
|
+
// load entities from store
|
|
44
53
|
if (args.stores) {
|
|
45
|
-
|
|
54
|
+
loadFromStores({ stores: args.stores, entities });
|
|
46
55
|
}
|
|
47
56
|
// find all unlinked references
|
|
48
|
-
const
|
|
49
|
-
// resolve static links (mutates data)
|
|
50
|
-
resolveStaticLinks({ references, unlinkedReferences });
|
|
57
|
+
const references = findReferences(unlinkedData);
|
|
51
58
|
// return
|
|
52
59
|
return {
|
|
53
|
-
|
|
60
|
+
entities, references, data: unlinkedData
|
|
54
61
|
};
|
|
55
62
|
}
|
|
56
63
|
// load stores
|
|
57
|
-
function
|
|
58
|
-
const { assets = [], collections = [] } = stores;
|
|
64
|
+
function loadFromStores({ stores, entities }) {
|
|
65
|
+
const { pages = [], assets = [], collections = [], dynamic } = stores;
|
|
66
|
+
// load pages
|
|
67
|
+
pages.forEach(page => {
|
|
68
|
+
entities.pages.set(page.id, page);
|
|
69
|
+
});
|
|
59
70
|
// load assets
|
|
60
71
|
assets.forEach(asset => {
|
|
61
|
-
|
|
72
|
+
entities.assets.set(asset.value.id, asset);
|
|
62
73
|
});
|
|
63
74
|
// load collections
|
|
64
75
|
collections.forEach(collection => {
|
|
65
|
-
|
|
76
|
+
entities.collections.set(collection.id, collection);
|
|
77
|
+
});
|
|
78
|
+
// load dynamic entities
|
|
79
|
+
dynamic === null || dynamic === void 0 ? void 0 : dynamic.forEach((value, key) => {
|
|
80
|
+
entities.dynamic.set(key, value);
|
|
66
81
|
});
|
|
67
82
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// create empty references
|
|
83
|
+
function createEmptyEntities() {
|
|
84
|
+
// create empty entities
|
|
71
85
|
const pages = new Map();
|
|
72
86
|
const collections = new Map();
|
|
73
87
|
const assets = new Map();
|
|
88
|
+
const dynamic = new Map();
|
|
89
|
+
// return entities
|
|
90
|
+
return { pages, collections, assets, dynamic };
|
|
91
|
+
}
|
|
92
|
+
function findEntities(unlinkedData) {
|
|
93
|
+
// create empty entities
|
|
94
|
+
const { pages, collections, assets, dynamic } = createEmptyEntities();
|
|
74
95
|
// walk unlinked data
|
|
75
96
|
utils_1.ObjectUtils.walk(unlinkedData, ({ value }) => {
|
|
76
97
|
// page data
|
|
@@ -112,16 +133,49 @@ var LinkedData;
|
|
|
112
133
|
// otherwise just keep walking
|
|
113
134
|
return true;
|
|
114
135
|
});
|
|
115
|
-
// return
|
|
116
|
-
return { pages, collections, assets };
|
|
136
|
+
// return entities
|
|
137
|
+
return { pages, collections, assets, dynamic };
|
|
117
138
|
}
|
|
118
|
-
|
|
119
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Find all dynamic references in data
|
|
141
|
+
*/
|
|
142
|
+
function findDynamicRefs(unlinkedData) {
|
|
143
|
+
// create empty unlinked references
|
|
144
|
+
const dynamicPageRefs = new Map();
|
|
145
|
+
// helper
|
|
146
|
+
const upsertRef = (id, value, map) => {
|
|
147
|
+
const refs = map.get(id);
|
|
148
|
+
if (refs) {
|
|
149
|
+
refs.push(value);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
map.set(id, [value]);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
// walk unlinked data
|
|
156
|
+
utils_1.ObjectUtils.walk(unlinkedData, ({ value }) => {
|
|
157
|
+
// dynamic ref
|
|
158
|
+
if (field_1.Field.Data.DynamicPages.filter(value)) {
|
|
159
|
+
const dynamicId = field_1.DynamicPagesField.Value.hash(value);
|
|
160
|
+
upsertRef(dynamicId, value, dynamicPageRefs);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
// otherwise just keep walking
|
|
164
|
+
return true;
|
|
165
|
+
});
|
|
166
|
+
// return unlinked references
|
|
167
|
+
return dynamicPageRefs;
|
|
168
|
+
}
|
|
169
|
+
LinkedData.findDynamicRefs = findDynamicRefs;
|
|
170
|
+
/**
|
|
171
|
+
* Find all references in data
|
|
172
|
+
*/
|
|
173
|
+
function findReferences(unlinkedData) {
|
|
120
174
|
// create empty unlinked references
|
|
121
175
|
const pageRefs = new Map();
|
|
122
176
|
const collectionRefs = new Map();
|
|
123
177
|
const assetRefs = new Map();
|
|
124
|
-
const
|
|
178
|
+
const dynamicRefs = new Map();
|
|
125
179
|
// helper
|
|
126
180
|
const upsertRef = (id, value, map) => {
|
|
127
181
|
const refs = map.get(id);
|
|
@@ -154,20 +208,23 @@ var LinkedData;
|
|
|
154
208
|
}
|
|
155
209
|
// dynamic ref
|
|
156
210
|
else if (field_1.Field.Data.DynamicPages.filter(value)) {
|
|
157
|
-
|
|
211
|
+
const dynamicId = field_1.DynamicPagesField.Value.hash(value);
|
|
212
|
+
upsertRef(dynamicId, value, dynamicRefs);
|
|
158
213
|
return true;
|
|
159
214
|
}
|
|
160
215
|
// otherwise just keep walking
|
|
161
216
|
return true;
|
|
162
217
|
});
|
|
163
218
|
// return unlinked references
|
|
164
|
-
return { pageRefs, collectionRefs, assetRefs,
|
|
219
|
+
return { pageRefs, collectionRefs, assetRefs, dynamicRefs };
|
|
165
220
|
}
|
|
166
|
-
|
|
167
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Link entities to references
|
|
223
|
+
*/
|
|
224
|
+
function link({ entities, references }) {
|
|
168
225
|
// setup
|
|
169
|
-
const { pages, collections, assets } =
|
|
170
|
-
const { pageRefs, collectionRefs, assetRefs } =
|
|
226
|
+
const { pages, collections, assets, dynamic } = entities;
|
|
227
|
+
const { pageRefs, collectionRefs, assetRefs, dynamicRefs } = references;
|
|
171
228
|
// resolve page refs
|
|
172
229
|
pageRefs.forEach((refs, id) => {
|
|
173
230
|
const pageData = pages.get(id);
|
|
@@ -202,6 +259,24 @@ var LinkedData;
|
|
|
202
259
|
delete ref.__ref;
|
|
203
260
|
});
|
|
204
261
|
});
|
|
262
|
+
// dynamic page refs
|
|
263
|
+
dynamicRefs.forEach((refs, hash) => {
|
|
264
|
+
const pagePreviews = dynamic.get(hash);
|
|
265
|
+
// for each reference change to new shape
|
|
266
|
+
refs.forEach(ref => {
|
|
267
|
+
var _a;
|
|
268
|
+
const staticPagesData = (_a = ref.value.staticPages) !== null && _a !== void 0 ? _a : [];
|
|
269
|
+
ref.value = pagePreviews
|
|
270
|
+
? {
|
|
271
|
+
// @ts-expect-error changing type
|
|
272
|
+
pages: [
|
|
273
|
+
...staticPagesData.map(item => item.value),
|
|
274
|
+
...pagePreviews
|
|
275
|
+
]
|
|
276
|
+
}
|
|
277
|
+
: ref.value;
|
|
278
|
+
});
|
|
279
|
+
});
|
|
205
280
|
}
|
|
206
281
|
function resolvePersonas({ data, persona }) {
|
|
207
282
|
var _a;
|
|
@@ -234,55 +309,34 @@ var LinkedData;
|
|
|
234
309
|
delete field.personas;
|
|
235
310
|
}
|
|
236
311
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
//
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
// TODO: remove hardcoded schema in value
|
|
249
|
-
if (staticPages.length >= TEMP_LIMIT) {
|
|
250
|
-
dynamicPages.value = {
|
|
251
|
-
// @ts-expect-error changing type on purpose
|
|
252
|
-
__schema: {
|
|
253
|
-
types: ['case-study'],
|
|
254
|
-
size: TEMP_LIMIT
|
|
255
|
-
},
|
|
256
|
-
pages: staticPages
|
|
257
|
-
};
|
|
312
|
+
/**
|
|
313
|
+
* Resolve dynamic references using resolvers
|
|
314
|
+
*/
|
|
315
|
+
async function resolveDynamicRefs({ dynamicRefs, resolvers: { page: pageResolver } }) {
|
|
316
|
+
// create unique requests for dynamic references
|
|
317
|
+
const requests = Array.from(dynamicRefs).map(async ([hash, data]) => {
|
|
318
|
+
// only grab the first dynamic reference (should all be the same)
|
|
319
|
+
const { types, sort, staticPages = [], schema } = data[0].value;
|
|
320
|
+
// we have enough already (don't need to resolve)
|
|
321
|
+
if (staticPages.length >= schema.size) {
|
|
322
|
+
return [hash, []];
|
|
258
323
|
}
|
|
259
|
-
// otherwise we need to
|
|
324
|
+
// otherwise we need to resolve reference
|
|
260
325
|
else {
|
|
261
326
|
// get ids to exclude
|
|
262
|
-
const excludeIds = staticPages.map(page => page.id);
|
|
327
|
+
const excludeIds = staticPages.map(page => page.value.id);
|
|
263
328
|
// fetch only needed amount
|
|
264
|
-
const limit =
|
|
329
|
+
const limit = schema.size - staticPages.length;
|
|
265
330
|
// fetch dynamic items
|
|
266
331
|
const resolvedPages = await pageResolver({ types, excludeIds, sort, limit });
|
|
267
332
|
const linkedResolvedPages = resolveStatic({
|
|
268
333
|
unlinkedData: resolvedPages
|
|
269
334
|
});
|
|
270
|
-
|
|
271
|
-
// stitch static and dynamic items
|
|
272
|
-
// TODO: remove hardcoded schema in value
|
|
273
|
-
dynamicPages.value = {
|
|
274
|
-
// @ts-expect-error changing type on purpose
|
|
275
|
-
__schema: {
|
|
276
|
-
types: ['case-study'],
|
|
277
|
-
size: TEMP_LIMIT
|
|
278
|
-
},
|
|
279
|
-
pages: [
|
|
280
|
-
...staticPages,
|
|
281
|
-
...linkedResolvedPages
|
|
282
|
-
]
|
|
283
|
-
};
|
|
284
|
-
console.debug('[LinkData] final value', dynamicPages.value);
|
|
335
|
+
return [hash, linkedResolvedPages];
|
|
285
336
|
}
|
|
286
|
-
})
|
|
337
|
+
});
|
|
338
|
+
// go through each ref and resolve
|
|
339
|
+
return new Map(await Promise.all(requests));
|
|
287
340
|
}
|
|
341
|
+
LinkedData.resolveDynamicRefs = resolveDynamicRefs;
|
|
288
342
|
})(LinkedData || (exports.LinkedData = LinkedData = {}));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LinkedData } from './LinkedData';
|
|
2
|
+
import { Page } from './Page';
|
|
3
|
+
export declare class LinkedPage<TPage extends Page> {
|
|
4
|
+
private readonly _data;
|
|
5
|
+
private readonly _linkedStore;
|
|
6
|
+
private readonly _nav;
|
|
7
|
+
private readonly _content;
|
|
8
|
+
private constructor();
|
|
9
|
+
get url(): string;
|
|
10
|
+
get seo(): import("./Seo").Seo.Data;
|
|
11
|
+
get header(): {
|
|
12
|
+
fields: any;
|
|
13
|
+
config: {
|
|
14
|
+
theme: any;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
get footer(): {
|
|
18
|
+
fields: any;
|
|
19
|
+
config: {
|
|
20
|
+
theme: any;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
get data(): Page.Data<TPage, string>;
|
|
24
|
+
get content(): Page.LinkedData.Content<TPage>;
|
|
25
|
+
private get;
|
|
26
|
+
static create<TPage extends Page>(args: LinkedPage.CreateArgs<TPage>): Promise<LinkedPage<TPage>>;
|
|
27
|
+
}
|
|
28
|
+
export declare namespace LinkedPage {
|
|
29
|
+
type CreateArgs<TPage extends Page> = {
|
|
30
|
+
data: Page.FlattenedData<TPage>;
|
|
31
|
+
resolvers: LinkedData.DynamicResolvers;
|
|
32
|
+
};
|
|
33
|
+
type ConstructorArgs<TPage extends Page> = {
|
|
34
|
+
data: Page.Data<TPage>;
|
|
35
|
+
linkedStore: LinkedData.TransformFromStores;
|
|
36
|
+
};
|
|
37
|
+
}
|