@webiny/website-builder-sdk 0.0.0-unstable.9f53ea597d → 0.0.0-unstable.a4f3e4ea8b
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/BindingsResolver.d.ts +4 -1
- package/BindingsResolver.js.map +1 -1
- package/ComponentResolver.d.ts +3 -2
- package/ComponentResolver.js +6 -3
- package/ComponentResolver.js.map +1 -1
- package/ContentSdk.d.ts +0 -11
- package/ContentSdk.js +0 -20
- package/ContentSdk.js.map +1 -1
- package/contentEntry/ContentEntryBindingsResolver.d.ts +30 -0
- package/contentEntry/ContentEntryBindingsResolver.js +45 -0
- package/contentEntry/ContentEntryBindingsResolver.js.map +1 -0
- package/contentEntry/ContentEntryCache.d.ts +46 -0
- package/contentEntry/ContentEntryCache.js +50 -0
- package/contentEntry/ContentEntryCache.js.map +1 -0
- package/contentEntry/resolveContentEntry.d.ts +74 -0
- package/contentEntry/resolveContentEntry.js +53 -0
- package/contentEntry/resolveContentEntry.js.map +1 -0
- package/contentEntry/resolveContentEntry.test.js +213 -0
- package/contentEntry/resolveContentEntry.test.js.map +1 -0
- package/createComponent.d.ts +5 -0
- package/createComponent.js +32 -0
- package/createComponent.js.map +1 -0
- package/createInput.d.ts +10 -2
- package/createInput.js +8 -1
- package/createInput.js.map +1 -1
- package/dataProviders/ApiClient.js.map +1 -1
- package/dataProviders/DefaultDataProvider.d.ts +0 -4
- package/dataProviders/DefaultDataProvider.js +0 -35
- package/dataProviders/DefaultDataProvider.js.map +1 -1
- package/dataProviders/NullDataProvider.d.ts +0 -4
- package/dataProviders/NullDataProvider.js +0 -9
- package/dataProviders/NullDataProvider.js.map +1 -1
- package/index.d.ts +4 -1
- package/index.js +4 -1
- package/package.json +3 -3
- package/types.d.ts +69 -5
- package/dataProviders/GET_EXPERIMENT_PAUSED.d.ts +0 -1
- package/dataProviders/GET_EXPERIMENT_PAUSED.js +0 -17
- package/dataProviders/GET_EXPERIMENT_PAUSED.js.map +0 -1
- package/dataProviders/GET_PAGE_EXPERIMENT.d.ts +0 -1
- package/dataProviders/GET_PAGE_EXPERIMENT.js +0 -32
- package/dataProviders/GET_PAGE_EXPERIMENT.js.map +0 -1
- package/dataProviders/GET_VARIANT_CONTENT.d.ts +0 -1
- package/dataProviders/GET_VARIANT_CONTENT.js +0 -24
- package/dataProviders/GET_VARIANT_CONTENT.js.map +0 -1
- package/experiments/PostHogAnalyticsProvider.d.ts +0 -31
- package/experiments/PostHogAnalyticsProvider.js +0 -28
- package/experiments/PostHogAnalyticsProvider.js.map +0 -1
- package/experiments/analyticsProvider.d.ts +0 -4
- package/experiments/analyticsProvider.js +0 -11
- package/experiments/analyticsProvider.js.map +0 -1
- package/experiments/bucketing.d.ts +0 -27
- package/experiments/bucketing.js +0 -91
- package/experiments/bucketing.js.map +0 -1
- package/experiments/bucketing.test.js +0 -183
- package/experiments/bucketing.test.js.map +0 -1
- package/experiments/index.d.ts +0 -5
- package/experiments/index.js +0 -5
- package/experiments/render.d.ts +0 -79
- package/experiments/render.js +0 -149
- package/experiments/render.js.map +0 -1
- package/experiments/types.d.ts +0 -108
- package/experiments/types.js +0 -4
- package/experiments/types.js.map +0 -1
- /package/{experiments/bucketing.test.d.ts → contentEntry/resolveContentEntry.test.d.ts} +0 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { isAlreadyResolved, isQueryValue, resolveContentEntryValue } from "./resolveContentEntry.js";
|
|
3
|
+
const entry = (id)=>({
|
|
4
|
+
id,
|
|
5
|
+
entryId: id,
|
|
6
|
+
values: {
|
|
7
|
+
title: `T${id}`
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
function makeLoader(over = {}) {
|
|
11
|
+
return {
|
|
12
|
+
getEntry: vi.fn(async ({ entryId })=>entry(entryId)),
|
|
13
|
+
listEntries: vi.fn(async ()=>({
|
|
14
|
+
data: [
|
|
15
|
+
entry("1"),
|
|
16
|
+
entry("2")
|
|
17
|
+
],
|
|
18
|
+
meta: {
|
|
19
|
+
cursor: "c1",
|
|
20
|
+
hasMoreItems: true,
|
|
21
|
+
totalCount: 5
|
|
22
|
+
}
|
|
23
|
+
})),
|
|
24
|
+
...over
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
describe("resolveContentEntryValue — manual mode", ()=>{
|
|
28
|
+
it("resolves a single reference", async ()=>{
|
|
29
|
+
const loader = makeLoader();
|
|
30
|
+
const result = await resolveContentEntryValue({
|
|
31
|
+
id: "42",
|
|
32
|
+
modelId: "blog"
|
|
33
|
+
}, false, loader);
|
|
34
|
+
expect(loader.getEntry).toHaveBeenCalledWith({
|
|
35
|
+
modelId: "blog",
|
|
36
|
+
entryId: "42"
|
|
37
|
+
});
|
|
38
|
+
expect(result).toEqual(entry("42"));
|
|
39
|
+
});
|
|
40
|
+
it("returns null for a null single value", async ()=>{
|
|
41
|
+
const loader = makeLoader();
|
|
42
|
+
const result = await resolveContentEntryValue(null, false, loader);
|
|
43
|
+
expect(result).toBeNull();
|
|
44
|
+
expect(loader.getEntry).not.toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
it("resolves a list of references, preserving order", async ()=>{
|
|
47
|
+
const loader = makeLoader();
|
|
48
|
+
const result = await resolveContentEntryValue([
|
|
49
|
+
{
|
|
50
|
+
id: "1",
|
|
51
|
+
modelId: "blog"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "2",
|
|
55
|
+
modelId: "blog"
|
|
56
|
+
}
|
|
57
|
+
], true, loader);
|
|
58
|
+
expect(loader.getEntry).toHaveBeenCalledTimes(2);
|
|
59
|
+
expect(result).toEqual([
|
|
60
|
+
entry("1"),
|
|
61
|
+
entry("2")
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
it("filters out unresolved (deleted) references in a list", async ()=>{
|
|
65
|
+
const loader = makeLoader({
|
|
66
|
+
getEntry: vi.fn(async ({ entryId })=>"2" === entryId ? null : entry(entryId))
|
|
67
|
+
});
|
|
68
|
+
const result = await resolveContentEntryValue([
|
|
69
|
+
{
|
|
70
|
+
id: "1",
|
|
71
|
+
modelId: "blog"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "2",
|
|
75
|
+
modelId: "blog"
|
|
76
|
+
}
|
|
77
|
+
], true, loader);
|
|
78
|
+
expect(result).toEqual([
|
|
79
|
+
entry("1")
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
it("returns an empty array for a null list value", async ()=>{
|
|
83
|
+
const loader = makeLoader();
|
|
84
|
+
const result = await resolveContentEntryValue(null, true, loader);
|
|
85
|
+
expect(result).toEqual([]);
|
|
86
|
+
expect(loader.getEntry).not.toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe("resolveContentEntryValue — query mode", ()=>{
|
|
90
|
+
it("runs the query and returns items + pageInfo", async ()=>{
|
|
91
|
+
const loader = makeLoader();
|
|
92
|
+
const result = await resolveContentEntryValue({
|
|
93
|
+
modelId: "blog",
|
|
94
|
+
sort: {
|
|
95
|
+
field: "values_title",
|
|
96
|
+
order: "asc"
|
|
97
|
+
},
|
|
98
|
+
limit: 5,
|
|
99
|
+
search: "cat"
|
|
100
|
+
}, false, loader);
|
|
101
|
+
expect(loader.listEntries).toHaveBeenCalledWith({
|
|
102
|
+
modelId: "blog",
|
|
103
|
+
sort: {
|
|
104
|
+
values_title: "asc"
|
|
105
|
+
},
|
|
106
|
+
limit: 5,
|
|
107
|
+
search: "cat"
|
|
108
|
+
});
|
|
109
|
+
expect(result).toMatchObject({
|
|
110
|
+
items: [
|
|
111
|
+
entry("1"),
|
|
112
|
+
entry("2")
|
|
113
|
+
],
|
|
114
|
+
pageInfo: {
|
|
115
|
+
cursor: "c1",
|
|
116
|
+
hasMore: true,
|
|
117
|
+
totalCount: 5
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
it("always embeds the continuation query", async ()=>{
|
|
122
|
+
const loader = makeLoader();
|
|
123
|
+
const result = await resolveContentEntryValue({
|
|
124
|
+
modelId: "blog",
|
|
125
|
+
limit: 4
|
|
126
|
+
}, false, loader);
|
|
127
|
+
expect(result.query).toEqual({
|
|
128
|
+
modelId: "blog",
|
|
129
|
+
sort: void 0,
|
|
130
|
+
limit: 4,
|
|
131
|
+
search: void 0
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
it("runs a minimal query (modelId only)", async ()=>{
|
|
135
|
+
const loader = makeLoader();
|
|
136
|
+
await resolveContentEntryValue({
|
|
137
|
+
modelId: "blog"
|
|
138
|
+
}, false, loader);
|
|
139
|
+
expect(loader.listEntries).toHaveBeenCalledWith({
|
|
140
|
+
modelId: "blog",
|
|
141
|
+
sort: void 0,
|
|
142
|
+
limit: void 0,
|
|
143
|
+
search: void 0
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
describe("isQueryValue", ()=>{
|
|
148
|
+
it("returns true for { modelId } without id", ()=>{
|
|
149
|
+
expect(isQueryValue({
|
|
150
|
+
modelId: "blog"
|
|
151
|
+
})).toBe(true);
|
|
152
|
+
expect(isQueryValue({
|
|
153
|
+
modelId: "blog",
|
|
154
|
+
sort: {
|
|
155
|
+
field: "a",
|
|
156
|
+
order: "asc"
|
|
157
|
+
}
|
|
158
|
+
})).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
it("returns false for a manual reference { id, modelId }", ()=>{
|
|
161
|
+
expect(isQueryValue({
|
|
162
|
+
id: "42",
|
|
163
|
+
modelId: "blog"
|
|
164
|
+
})).toBe(false);
|
|
165
|
+
});
|
|
166
|
+
it("returns false for arrays and non-objects", ()=>{
|
|
167
|
+
expect(isQueryValue([
|
|
168
|
+
{
|
|
169
|
+
modelId: "blog"
|
|
170
|
+
}
|
|
171
|
+
])).toBe(false);
|
|
172
|
+
expect(isQueryValue(null)).toBe(false);
|
|
173
|
+
expect(isQueryValue("string")).toBe(false);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
describe("isAlreadyResolved", ()=>{
|
|
177
|
+
it("returns true for a query result with items", ()=>{
|
|
178
|
+
expect(isAlreadyResolved({
|
|
179
|
+
items: [],
|
|
180
|
+
pageInfo: {}
|
|
181
|
+
}, false)).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
it("returns true for a list of resolved entries", ()=>{
|
|
184
|
+
expect(isAlreadyResolved([
|
|
185
|
+
{
|
|
186
|
+
values: {
|
|
187
|
+
title: "x"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
], true)).toBe(true);
|
|
191
|
+
});
|
|
192
|
+
it("returns false for a list of bare references", ()=>{
|
|
193
|
+
expect(isAlreadyResolved([
|
|
194
|
+
{
|
|
195
|
+
id: "1",
|
|
196
|
+
modelId: "blog"
|
|
197
|
+
}
|
|
198
|
+
], true)).toBe(false);
|
|
199
|
+
});
|
|
200
|
+
it("returns true for a single resolved entry", ()=>{
|
|
201
|
+
expect(isAlreadyResolved({
|
|
202
|
+
values: {
|
|
203
|
+
title: "x"
|
|
204
|
+
}
|
|
205
|
+
}, false)).toBe(true);
|
|
206
|
+
});
|
|
207
|
+
it("returns false for null", ()=>{
|
|
208
|
+
expect(isAlreadyResolved(null, false)).toBe(false);
|
|
209
|
+
expect(isAlreadyResolved(null, true)).toBe(false);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
//# sourceMappingURL=resolveContentEntry.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentEntry/resolveContentEntry.test.js","sources":["../../src/contentEntry/resolveContentEntry.test.ts"],"sourcesContent":["import { describe, it, expect, vi } from \"vitest\";\nimport {\n resolveContentEntryValue,\n isQueryValue,\n isAlreadyResolved,\n type ContentEntryLoader\n} from \"./resolveContentEntry.js\";\n\nconst entry = (id: string) => ({ id, entryId: id, values: { title: `T${id}` } });\n\nfunction makeLoader(over: Partial<ContentEntryLoader> = {}): ContentEntryLoader {\n return {\n getEntry: vi.fn(async ({ entryId }: { entryId: string }) => entry(entryId)),\n listEntries: vi.fn(async () => ({\n data: [entry(\"1\"), entry(\"2\")],\n meta: { cursor: \"c1\", hasMoreItems: true, totalCount: 5 }\n })),\n ...over\n };\n}\n\ndescribe(\"resolveContentEntryValue — manual mode\", () => {\n it(\"resolves a single reference\", async () => {\n const loader = makeLoader();\n const result = await resolveContentEntryValue({ id: \"42\", modelId: \"blog\" }, false, loader);\n expect(loader.getEntry).toHaveBeenCalledWith({ modelId: \"blog\", entryId: \"42\" });\n expect(result).toEqual(entry(\"42\"));\n });\n\n it(\"returns null for a null single value\", async () => {\n const loader = makeLoader();\n const result = await resolveContentEntryValue(null, false, loader);\n expect(result).toBeNull();\n expect(loader.getEntry).not.toHaveBeenCalled();\n });\n\n it(\"resolves a list of references, preserving order\", async () => {\n const loader = makeLoader();\n const result = await resolveContentEntryValue(\n [\n { id: \"1\", modelId: \"blog\" },\n { id: \"2\", modelId: \"blog\" }\n ],\n true,\n loader\n );\n expect(loader.getEntry).toHaveBeenCalledTimes(2);\n expect(result).toEqual([entry(\"1\"), entry(\"2\")]);\n });\n\n it(\"filters out unresolved (deleted) references in a list\", async () => {\n const loader = makeLoader({\n getEntry: vi.fn(async ({ entryId }: { entryId: string }) =>\n entryId === \"2\" ? null : entry(entryId)\n )\n });\n const result = await resolveContentEntryValue(\n [\n { id: \"1\", modelId: \"blog\" },\n { id: \"2\", modelId: \"blog\" }\n ],\n true,\n loader\n );\n expect(result).toEqual([entry(\"1\")]);\n });\n\n it(\"returns an empty array for a null list value\", async () => {\n const loader = makeLoader();\n const result = await resolveContentEntryValue(null, true, loader);\n expect(result).toEqual([]);\n expect(loader.getEntry).not.toHaveBeenCalled();\n });\n});\n\ndescribe(\"resolveContentEntryValue — query mode\", () => {\n it(\"runs the query and returns items + pageInfo\", async () => {\n const loader = makeLoader();\n const result = await resolveContentEntryValue(\n {\n modelId: \"blog\",\n sort: { field: \"values_title\", order: \"asc\" },\n limit: 5,\n search: \"cat\"\n },\n false,\n loader\n );\n expect(loader.listEntries).toHaveBeenCalledWith({\n modelId: \"blog\",\n sort: { values_title: \"asc\" },\n limit: 5,\n search: \"cat\"\n });\n expect(result).toMatchObject({\n items: [entry(\"1\"), entry(\"2\")],\n pageInfo: { cursor: \"c1\", hasMore: true, totalCount: 5 }\n });\n });\n\n it(\"always embeds the continuation query\", async () => {\n const loader = makeLoader();\n const result = (await resolveContentEntryValue(\n { modelId: \"blog\", limit: 4 },\n false,\n loader\n )) as Record<string, unknown>;\n expect(result.query).toEqual({\n modelId: \"blog\",\n sort: undefined,\n limit: 4,\n search: undefined\n });\n });\n\n it(\"runs a minimal query (modelId only)\", async () => {\n const loader = makeLoader();\n await resolveContentEntryValue({ modelId: \"blog\" }, false, loader);\n expect(loader.listEntries).toHaveBeenCalledWith({\n modelId: \"blog\",\n sort: undefined,\n limit: undefined,\n search: undefined\n });\n });\n});\n\ndescribe(\"isQueryValue\", () => {\n it(\"returns true for { modelId } without id\", () => {\n expect(isQueryValue({ modelId: \"blog\" })).toBe(true);\n expect(isQueryValue({ modelId: \"blog\", sort: { field: \"a\", order: \"asc\" } })).toBe(true);\n });\n\n it(\"returns false for a manual reference { id, modelId }\", () => {\n expect(isQueryValue({ id: \"42\", modelId: \"blog\" })).toBe(false);\n });\n\n it(\"returns false for arrays and non-objects\", () => {\n expect(isQueryValue([{ modelId: \"blog\" }])).toBe(false);\n expect(isQueryValue(null)).toBe(false);\n expect(isQueryValue(\"string\")).toBe(false);\n });\n});\n\ndescribe(\"isAlreadyResolved\", () => {\n it(\"returns true for a query result with items\", () => {\n expect(isAlreadyResolved({ items: [], pageInfo: {} }, false)).toBe(true);\n });\n\n it(\"returns true for a list of resolved entries\", () => {\n expect(isAlreadyResolved([{ values: { title: \"x\" } }], true)).toBe(true);\n });\n\n it(\"returns false for a list of bare references\", () => {\n expect(isAlreadyResolved([{ id: \"1\", modelId: \"blog\" }], true)).toBe(false);\n });\n\n it(\"returns true for a single resolved entry\", () => {\n expect(isAlreadyResolved({ values: { title: \"x\" } }, false)).toBe(true);\n });\n\n it(\"returns false for null\", () => {\n expect(isAlreadyResolved(null, false)).toBe(false);\n expect(isAlreadyResolved(null, true)).toBe(false);\n });\n});\n"],"names":["entry","id","makeLoader","over","vi","entryId","describe","it","loader","result","resolveContentEntryValue","expect","undefined","isQueryValue","isAlreadyResolved"],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Component, ComponentManifestInput } from "./types.js";
|
|
2
|
+
export type ExtractInputs<T> = T extends {
|
|
3
|
+
inputs: infer I;
|
|
4
|
+
} ? I : never;
|
|
5
|
+
export declare function createComponent<TComponent extends (props: any) => any, TInputs extends ExtractInputs<Parameters<TComponent>[0]>>(component: TComponent, manifest: ComponentManifestInput<TInputs>): Component;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createSlotInput } from "./createInput.js";
|
|
2
|
+
function createComponent(component, manifest) {
|
|
3
|
+
const inputs = [];
|
|
4
|
+
if (Array.isArray(manifest.inputs)) inputs.push(...manifest.inputs);
|
|
5
|
+
else {
|
|
6
|
+
const inputsObject = manifest.inputs ?? {};
|
|
7
|
+
Object.keys(inputsObject).forEach((name)=>{
|
|
8
|
+
inputs.push({
|
|
9
|
+
...inputsObject[name],
|
|
10
|
+
name
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const acceptsChildren = manifest.acceptsChildren;
|
|
15
|
+
if (acceptsChildren) {
|
|
16
|
+
const hasChildren = inputs.some((input)=>"children" === input.name);
|
|
17
|
+
if (!hasChildren) inputs.push(createSlotInput({
|
|
18
|
+
name: "children"
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
component,
|
|
23
|
+
manifest: {
|
|
24
|
+
...manifest,
|
|
25
|
+
tags: manifest.tags ?? [],
|
|
26
|
+
inputs
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { createComponent };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=createComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createComponent.js","sources":["../src/createComponent.ts"],"sourcesContent":["import type {\n Component,\n ComponentInput,\n ComponentManifest,\n ComponentManifestInput\n} from \"./types.js\";\nimport type { InputFactory } from \"./createInput.js\";\nimport { createSlotInput } from \"./createInput.js\";\n\nexport type ExtractInputs<T> = T extends { inputs: infer I } ? I : never;\n\nexport function createComponent<\n TComponent extends (props: any) => any,\n TInputs extends ExtractInputs<Parameters<TComponent>[0]>\n>(component: TComponent, manifest: ComponentManifestInput<TInputs>): Component {\n const inputs: ComponentInput[] = [];\n\n if (Array.isArray(manifest.inputs)) {\n inputs.push(...manifest.inputs);\n } else {\n const inputsObject: Record<string, InputFactory<any>> = manifest.inputs ?? {};\n Object.keys(inputsObject).forEach((name: string) => {\n inputs.push({ ...inputsObject[name], name });\n });\n }\n\n const acceptsChildren = manifest.acceptsChildren;\n\n if (acceptsChildren) {\n const hasChildren = inputs.some(input => input.name === \"children\");\n if (!hasChildren) {\n inputs.push(createSlotInput({ name: \"children\" }));\n }\n }\n\n return {\n component,\n manifest: { ...manifest, tags: manifest.tags ?? [], inputs } as ComponentManifest\n };\n}\n"],"names":["createComponent","component","manifest","inputs","Array","inputsObject","Object","name","acceptsChildren","hasChildren","input","createSlotInput"],"mappings":";AAWO,SAASA,gBAGdC,SAAqB,EAAEC,QAAyC;IAC9D,MAAMC,SAA2B,EAAE;IAEnC,IAAIC,MAAM,OAAO,CAACF,SAAS,MAAM,GAC7BC,OAAO,IAAI,IAAID,SAAS,MAAM;SAC3B;QACH,MAAMG,eAAkDH,SAAS,MAAM,IAAI,CAAC;QAC5EI,OAAO,IAAI,CAACD,cAAc,OAAO,CAAC,CAACE;YAC/BJ,OAAO,IAAI,CAAC;gBAAE,GAAGE,YAAY,CAACE,KAAK;gBAAEA;YAAK;QAC9C;IACJ;IAEA,MAAMC,kBAAkBN,SAAS,eAAe;IAEhD,IAAIM,iBAAiB;QACjB,MAAMC,cAAcN,OAAO,IAAI,CAACO,CAAAA,QAASA,AAAe,eAAfA,MAAM,IAAI;QACnD,IAAI,CAACD,aACDN,OAAO,IAAI,CAACQ,gBAAgB;YAAE,MAAM;QAAW;IAEvD;IAEA,OAAO;QACHV;QACA,UAAU;YAAE,GAAGC,QAAQ;YAAE,MAAMA,SAAS,IAAI,IAAI,EAAE;YAAEC;QAAO;IAC/D;AACJ"}
|
package/createInput.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TextInput, LongTextInput, NumberInput, BooleanInput, ColorInput, FileInput, LexicalInput, SelectInput, RadioInput, ObjectInput, DateTimeInput, ComponentInput, TagsInput, SlotInput } from "./types.js";
|
|
2
|
-
export type InputFactory<Name extends string> = ReturnType<typeof createTextInput<Name>> | ReturnType<typeof createLongTextInput<Name>> | ReturnType<typeof createNumberInput<Name>> | ReturnType<typeof createBooleanInput<Name>> | ReturnType<typeof createColorInput<Name>> | ReturnType<typeof createFileInput<Name>> | ReturnType<typeof createDateInput<Name>> | ReturnType<typeof createLexicalInput<Name>> | ReturnType<typeof createSelectInput<Name>> | ReturnType<typeof createRadioInput<Name>> | ReturnType<typeof createObjectInput<Name>> | ReturnType<typeof createTagsInput<Name>> | ReturnType<typeof createSlotInput<Name>>;
|
|
1
|
+
import type { TextInput, LongTextInput, NumberInput, BooleanInput, ColorInput, FileInput, LexicalInput, SelectInput, RadioInput, ObjectInput, DateTimeInput, ComponentInput, TagsInput, SlotInput, ContentEntryInput } from "./types.js";
|
|
2
|
+
export type InputFactory<Name extends string> = ReturnType<typeof createTextInput<Name>> | ReturnType<typeof createLongTextInput<Name>> | ReturnType<typeof createNumberInput<Name>> | ReturnType<typeof createBooleanInput<Name>> | ReturnType<typeof createColorInput<Name>> | ReturnType<typeof createFileInput<Name>> | ReturnType<typeof createDateInput<Name>> | ReturnType<typeof createLexicalInput<Name>> | ReturnType<typeof createSelectInput<Name>> | ReturnType<typeof createRadioInput<Name>> | ReturnType<typeof createObjectInput<Name>> | ReturnType<typeof createTagsInput<Name>> | ReturnType<typeof createSlotInput<Name>> | ReturnType<typeof createContentEntryInput<Name>>;
|
|
3
3
|
/**
|
|
4
4
|
* TypeScript Overload Resolution and Input Factory Design
|
|
5
5
|
*
|
|
@@ -122,4 +122,12 @@ export declare function createSlotInput<TName extends string>(input: {
|
|
|
122
122
|
export declare function createSlotInput<TName extends string>(input: Omit<SlotInput, "type" | "name">): SlotInput & {
|
|
123
123
|
name: TName;
|
|
124
124
|
};
|
|
125
|
+
export declare function createContentEntryInput<TName extends string>(input: {
|
|
126
|
+
name: TName;
|
|
127
|
+
} & Omit<ContentEntryInput, "type" | "name">): ContentEntryInput & {
|
|
128
|
+
name: TName;
|
|
129
|
+
};
|
|
130
|
+
export declare function createContentEntryInput<TName extends string>(input: Omit<ContentEntryInput, "type" | "name">): ContentEntryInput & {
|
|
131
|
+
name: TName;
|
|
132
|
+
};
|
|
125
133
|
export declare function createInput(input: ComponentInput): ComponentInput;
|
package/createInput.js
CHANGED
|
@@ -93,10 +93,17 @@ function createSlotInput(input) {
|
|
|
93
93
|
...input
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
+
function createContentEntryInput(input) {
|
|
97
|
+
return createInput({
|
|
98
|
+
type: "contentEntry",
|
|
99
|
+
renderer: "Webiny/ContentEntry",
|
|
100
|
+
...input
|
|
101
|
+
});
|
|
102
|
+
}
|
|
96
103
|
function createInput(input) {
|
|
97
104
|
if (input.onChange) input.onChange = functionConverter.serialize(input.onChange);
|
|
98
105
|
return input;
|
|
99
106
|
}
|
|
100
|
-
export { createBooleanInput, createColorInput, createDateInput, createFileInput, createInput, createLexicalInput, createLongTextInput, createNumberInput, createObjectInput, createRadioInput, createSelectInput, createSlotInput, createTagsInput, createTextInput };
|
|
107
|
+
export { createBooleanInput, createColorInput, createContentEntryInput, createDateInput, createFileInput, createInput, createLexicalInput, createLongTextInput, createNumberInput, createObjectInput, createRadioInput, createSelectInput, createSlotInput, createTagsInput, createTextInput };
|
|
101
108
|
|
|
102
109
|
//# sourceMappingURL=createInput.js.map
|
package/createInput.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInput.js","sources":["../src/createInput.ts"],"sourcesContent":["import type {\n TextInput,\n LongTextInput,\n NumberInput,\n BooleanInput,\n ColorInput,\n FileInput,\n LexicalInput,\n SelectInput,\n RadioInput,\n ObjectInput,\n DateTimeInput,\n ComponentInput,\n TagsInput,\n SlotInput\n} from \"./types.js\";\nimport { functionConverter } from \"~/FunctionConverter.js\";\n\nexport type InputFactory<Name extends string> =\n | ReturnType<typeof createTextInput<Name>>\n | ReturnType<typeof createLongTextInput<Name>>\n | ReturnType<typeof createNumberInput<Name>>\n | ReturnType<typeof createBooleanInput<Name>>\n | ReturnType<typeof createColorInput<Name>>\n | ReturnType<typeof createFileInput<Name>>\n | ReturnType<typeof createDateInput<Name>>\n | ReturnType<typeof createLexicalInput<Name>>\n | ReturnType<typeof createSelectInput<Name>>\n | ReturnType<typeof createRadioInput<Name>>\n | ReturnType<typeof createObjectInput<Name>>\n | ReturnType<typeof createTagsInput<Name>>\n | ReturnType<typeof createSlotInput<Name>>;\n\n/**\n * TypeScript Overload Resolution and Input Factory Design\n *\n * Each input factory (e.g., createTextInput) is defined with two TypeScript overload signatures:\n * 1. One overload requires a `name` property in the input (used for array-based APIs, where inference is needed).\n * 2. The other overload omits the `name` property (used for object-based APIs, where the key provides the name).\n *\n * TypeScript resolves overloads by scanning from top to bottom and picking the first matching signature.\n * The implementation signature uses `any` for the argument, and the return type is unified to match all overloads.\n *\n * In array mode, the `name` must be explicitly provided in the input object, so inference for `TName` works.\n * In object mode, the input does not require a `name` property; instead, the key in the object (e.g., `{ foo: createTextInput({ ... }) }`)\n * provides the name via contextual typing from the consuming function (such as `createComponent`). TypeScript uses this context\n * to resolve the correct type for `TName` even when `name` is omitted from the input.\n *\n * This pattern ensures that all returned input objects are typed as `{ name: TName }`, whether `name` is provided explicitly or inferred,\n * so consumers of these factories do not need to worry about the presence of the `name` property in the result.\n */\n// Text\nexport function createTextInput<TName extends string>(\n input: { name: TName } & Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(\n input: Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(input: any): TextInput & { name: TName } {\n return createInput({\n type: \"text\",\n renderer: \"Webiny/Input\",\n ...input\n }) as TextInput & { name: TName };\n}\n\n// Long Text\nexport function createLongTextInput<TName extends string>(\n input: { name: TName } & Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: any\n): LongTextInput & { name: TName } {\n return createInput({\n type: \"longText\",\n renderer: \"Webiny/Textarea\",\n ...input\n }) as LongTextInput & { name: TName };\n}\n\n// Number\nexport function createNumberInput<TName extends string>(\n input: { name: TName } & Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(\n input: Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(input: any): NumberInput & { name: TName } {\n return createInput({\n type: \"number\",\n renderer: \"Webiny/Number\",\n ...input\n }) as NumberInput & { name: TName };\n}\n\n// Boolean\nexport function createBooleanInput<TName extends string>(\n input: { name: TName } & Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: any\n): BooleanInput & { name: TName } {\n return createInput({\n type: \"boolean\",\n renderer: \"Webiny/Switch\",\n ...input\n }) as BooleanInput & { name: TName };\n}\n\n// Color\nexport function createColorInput<TName extends string>(\n input: { name: TName } & Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(\n input: Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(input: any): ColorInput & { name: TName } {\n return createInput({\n type: \"color\",\n renderer: \"Webiny/ColorPicker\",\n ...input\n }) as ColorInput & { name: TName };\n}\n\n// File\nexport function createFileInput<TName extends string>(\n input: { name: TName } & Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(\n input: Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(input: any): FileInput & { name: TName } {\n return createInput({\n type: \"file\",\n renderer: \"Webiny/FileManager\",\n ...input\n }) as FileInput & { name: TName };\n}\n\n// Date\nexport function createDateInput<TName extends string>(\n input: { name: TName } & Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(\n input: Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(input: any): DateTimeInput & { name: TName } {\n return createInput({\n type: \"datetime\",\n renderer: \"Webiny/DateTime\",\n ...input\n }) as DateTimeInput & { name: TName };\n}\n\n// Rich Text\nexport function createLexicalInput<TName extends string>(\n input: { name: TName } & Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: any\n): LexicalInput & { name: TName } {\n return createInput({\n type: \"lexical\",\n renderer: \"Webiny/Lexical\",\n ...input\n }) as LexicalInput & { name: TName };\n}\n\n// Select\nexport function createSelectInput<TName extends string>(\n input: { name: TName } & Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(\n input: Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(input: any): SelectInput & { name: TName } {\n return createInput({\n type: \"select\",\n renderer: \"Webiny/Select\",\n ...input\n }) as SelectInput & { name: TName };\n}\n\n// Radio\nexport function createRadioInput<TName extends string>(\n input: { name: TName } & Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(\n input: Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(input: any): RadioInput & { name: TName } {\n return createInput({\n type: \"radio\",\n renderer: \"Webiny/RadioGroup\",\n ...input\n }) as RadioInput & { name: TName };\n}\n\n// Object\nexport function createObjectInput<TName extends string>(\n input: { name: TName } & Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(\n input: Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(input: any): ObjectInput & { name: TName } {\n return createInput({\n type: \"object\",\n renderer: \"Webiny/Object\",\n ...input\n }) as ObjectInput & { name: TName };\n}\n\n// Tags\nexport function createTagsInput<TName extends string>(\n input: { name: TName } & Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(\n input: Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(input: any): TagsInput & { name: TName } {\n return createInput({\n type: \"text\",\n list: true,\n renderer: \"Webiny/Tags\",\n ...input\n }) as TagsInput & { name: TName };\n}\n\nexport function createSlotInput<TName extends string>(\n input: { name: TName } & Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(\n input: Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(input: any): SlotInput & { name: TName } {\n return createInput({\n type: \"slot\",\n list: true,\n renderer: \"Webiny/Slot\",\n defaultValue: [],\n ...input\n }) as SlotInput & { name: TName };\n}\n\n// Implementation\nexport function createInput(input: ComponentInput): ComponentInput {\n if (input.onChange) {\n // @ts-expect-error We don't use this function on the frontend, so this is ok.\n input.onChange = functionConverter.serialize(input.onChange!);\n }\n return input;\n}\n"],"names":["createTextInput","input","createInput","createLongTextInput","createNumberInput","createBooleanInput","createColorInput","createFileInput","createDateInput","createLexicalInput","createSelectInput","createRadioInput","createObjectInput","createTagsInput","createSlotInput","functionConverter"],"mappings":";AA0DO,SAASA,gBAAsCC,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASE,oBACZF,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASG,kBAAwCH,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASI,mBACZJ,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASK,iBAAuCL,KAAU;IAC7D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASM,gBAAsCN,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASO,gBAAsCP,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASQ,mBACZR,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASS,kBAAwCT,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASU,iBAAuCV,KAAU;IAC7D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASW,kBAAwCX,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASY,gBAAsCZ,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AAQO,SAASa,gBAAsCb,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,MAAM;QACN,UAAU;QACV,cAAc,EAAE;QAChB,GAAGD,KAAK;IACZ;AACJ;AAGO,SAASC,YAAYD,KAAqB;IAC7C,IAAIA,MAAM,QAAQ,EAEdA,MAAM,QAAQ,GAAGc,kBAAkB,SAAS,CAACd,MAAM,QAAQ;IAE/D,OAAOA;AACX"}
|
|
1
|
+
{"version":3,"file":"createInput.js","sources":["../src/createInput.ts"],"sourcesContent":["import type {\n TextInput,\n LongTextInput,\n NumberInput,\n BooleanInput,\n ColorInput,\n FileInput,\n LexicalInput,\n SelectInput,\n RadioInput,\n ObjectInput,\n DateTimeInput,\n ComponentInput,\n TagsInput,\n SlotInput,\n ContentEntryInput\n} from \"./types.js\";\nimport { functionConverter } from \"~/FunctionConverter.js\";\n\nexport type InputFactory<Name extends string> =\n | ReturnType<typeof createTextInput<Name>>\n | ReturnType<typeof createLongTextInput<Name>>\n | ReturnType<typeof createNumberInput<Name>>\n | ReturnType<typeof createBooleanInput<Name>>\n | ReturnType<typeof createColorInput<Name>>\n | ReturnType<typeof createFileInput<Name>>\n | ReturnType<typeof createDateInput<Name>>\n | ReturnType<typeof createLexicalInput<Name>>\n | ReturnType<typeof createSelectInput<Name>>\n | ReturnType<typeof createRadioInput<Name>>\n | ReturnType<typeof createObjectInput<Name>>\n | ReturnType<typeof createTagsInput<Name>>\n | ReturnType<typeof createSlotInput<Name>>\n | ReturnType<typeof createContentEntryInput<Name>>;\n\n/**\n * TypeScript Overload Resolution and Input Factory Design\n *\n * Each input factory (e.g., createTextInput) is defined with two TypeScript overload signatures:\n * 1. One overload requires a `name` property in the input (used for array-based APIs, where inference is needed).\n * 2. The other overload omits the `name` property (used for object-based APIs, where the key provides the name).\n *\n * TypeScript resolves overloads by scanning from top to bottom and picking the first matching signature.\n * The implementation signature uses `any` for the argument, and the return type is unified to match all overloads.\n *\n * In array mode, the `name` must be explicitly provided in the input object, so inference for `TName` works.\n * In object mode, the input does not require a `name` property; instead, the key in the object (e.g., `{ foo: createTextInput({ ... }) }`)\n * provides the name via contextual typing from the consuming function (such as `createComponent`). TypeScript uses this context\n * to resolve the correct type for `TName` even when `name` is omitted from the input.\n *\n * This pattern ensures that all returned input objects are typed as `{ name: TName }`, whether `name` is provided explicitly or inferred,\n * so consumers of these factories do not need to worry about the presence of the `name` property in the result.\n */\n// Text\nexport function createTextInput<TName extends string>(\n input: { name: TName } & Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(\n input: Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(input: any): TextInput & { name: TName } {\n return createInput({\n type: \"text\",\n renderer: \"Webiny/Input\",\n ...input\n }) as TextInput & { name: TName };\n}\n\n// Long Text\nexport function createLongTextInput<TName extends string>(\n input: { name: TName } & Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: any\n): LongTextInput & { name: TName } {\n return createInput({\n type: \"longText\",\n renderer: \"Webiny/Textarea\",\n ...input\n }) as LongTextInput & { name: TName };\n}\n\n// Number\nexport function createNumberInput<TName extends string>(\n input: { name: TName } & Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(\n input: Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(input: any): NumberInput & { name: TName } {\n return createInput({\n type: \"number\",\n renderer: \"Webiny/Number\",\n ...input\n }) as NumberInput & { name: TName };\n}\n\n// Boolean\nexport function createBooleanInput<TName extends string>(\n input: { name: TName } & Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: any\n): BooleanInput & { name: TName } {\n return createInput({\n type: \"boolean\",\n renderer: \"Webiny/Switch\",\n ...input\n }) as BooleanInput & { name: TName };\n}\n\n// Color\nexport function createColorInput<TName extends string>(\n input: { name: TName } & Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(\n input: Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(input: any): ColorInput & { name: TName } {\n return createInput({\n type: \"color\",\n renderer: \"Webiny/ColorPicker\",\n ...input\n }) as ColorInput & { name: TName };\n}\n\n// File\nexport function createFileInput<TName extends string>(\n input: { name: TName } & Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(\n input: Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(input: any): FileInput & { name: TName } {\n return createInput({\n type: \"file\",\n renderer: \"Webiny/FileManager\",\n ...input\n }) as FileInput & { name: TName };\n}\n\n// Date\nexport function createDateInput<TName extends string>(\n input: { name: TName } & Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(\n input: Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(input: any): DateTimeInput & { name: TName } {\n return createInput({\n type: \"datetime\",\n renderer: \"Webiny/DateTime\",\n ...input\n }) as DateTimeInput & { name: TName };\n}\n\n// Rich Text\nexport function createLexicalInput<TName extends string>(\n input: { name: TName } & Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: any\n): LexicalInput & { name: TName } {\n return createInput({\n type: \"lexical\",\n renderer: \"Webiny/Lexical\",\n ...input\n }) as LexicalInput & { name: TName };\n}\n\n// Select\nexport function createSelectInput<TName extends string>(\n input: { name: TName } & Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(\n input: Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(input: any): SelectInput & { name: TName } {\n return createInput({\n type: \"select\",\n renderer: \"Webiny/Select\",\n ...input\n }) as SelectInput & { name: TName };\n}\n\n// Radio\nexport function createRadioInput<TName extends string>(\n input: { name: TName } & Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(\n input: Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(input: any): RadioInput & { name: TName } {\n return createInput({\n type: \"radio\",\n renderer: \"Webiny/RadioGroup\",\n ...input\n }) as RadioInput & { name: TName };\n}\n\n// Object\nexport function createObjectInput<TName extends string>(\n input: { name: TName } & Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(\n input: Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(input: any): ObjectInput & { name: TName } {\n return createInput({\n type: \"object\",\n renderer: \"Webiny/Object\",\n ...input\n }) as ObjectInput & { name: TName };\n}\n\n// Tags\nexport function createTagsInput<TName extends string>(\n input: { name: TName } & Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(\n input: Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(input: any): TagsInput & { name: TName } {\n return createInput({\n type: \"text\",\n list: true,\n renderer: \"Webiny/Tags\",\n ...input\n }) as TagsInput & { name: TName };\n}\n\nexport function createSlotInput<TName extends string>(\n input: { name: TName } & Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(\n input: Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(input: any): SlotInput & { name: TName } {\n return createInput({\n type: \"slot\",\n list: true,\n renderer: \"Webiny/Slot\",\n defaultValue: [],\n ...input\n }) as SlotInput & { name: TName };\n}\n\n// Content Entry\nexport function createContentEntryInput<TName extends string>(\n input: { name: TName } & Omit<ContentEntryInput, \"type\" | \"name\">\n): ContentEntryInput & { name: TName };\nexport function createContentEntryInput<TName extends string>(\n input: Omit<ContentEntryInput, \"type\" | \"name\">\n): ContentEntryInput & { name: TName };\nexport function createContentEntryInput<TName extends string>(\n input: any\n): ContentEntryInput & { name: TName } {\n return createInput({\n type: \"contentEntry\",\n renderer: \"Webiny/ContentEntry\",\n ...input\n }) as ContentEntryInput & { name: TName };\n}\n\n// Implementation\nexport function createInput(input: ComponentInput): ComponentInput {\n if (input.onChange) {\n // @ts-expect-error We don't use this function on the frontend, so this is ok.\n input.onChange = functionConverter.serialize(input.onChange!);\n }\n return input;\n}\n"],"names":["createTextInput","input","createInput","createLongTextInput","createNumberInput","createBooleanInput","createColorInput","createFileInput","createDateInput","createLexicalInput","createSelectInput","createRadioInput","createObjectInput","createTagsInput","createSlotInput","createContentEntryInput","functionConverter"],"mappings":";AA4DO,SAASA,gBAAsCC,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASE,oBACZF,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASG,kBAAwCH,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASI,mBACZJ,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASK,iBAAuCL,KAAU;IAC7D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASM,gBAAsCN,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASO,gBAAsCP,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASQ,mBACZR,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASS,kBAAwCT,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASU,iBAAuCV,KAAU;IAC7D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASW,kBAAwCX,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASY,gBAAsCZ,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AAQO,SAASa,gBAAsCb,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,MAAM;QACN,UAAU;QACV,cAAc,EAAE;QAChB,GAAGD,KAAK;IACZ;AACJ;AASO,SAASc,wBACZd,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AAGO,SAASC,YAAYD,KAAqB;IAC7C,IAAIA,MAAM,QAAQ,EAEdA,MAAM,QAAQ,GAAGe,kBAAkB,SAAS,CAACf,MAAM,QAAQ;IAE/D,OAAOA;AACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataProviders/ApiClient.js","sources":["../../src/dataProviders/ApiClient.ts"],"sourcesContent":["interface QueryParams {\n query: string;\n variables: Record<string, any>;\n}\n\nexport interface ApiClientConfig {\n apiHost: string;\n apiKey: string;\n apiTenant: string;\n preview?: boolean;\n}\n\ntype WithPath<T> = T & {\n path?: string;\n next?: Record<string, any>;\n};\n\nexport class ApiClient {\n private readonly config: ApiClientConfig;\n\n constructor(config: ApiClientConfig) {\n this.config = config;\n }\n\n async fetch({ headers, path, ...params }: WithPath<RequestInit>): Promise<any> {\n return fetch(`${this.config.apiHost}${path}`, {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Tenant\": this.config.apiTenant,\n Authorization: \"Bearer \" + this.config.apiKey,\n ...headers\n },\n ...params\n }).then(res => res.json());\n }\n\n async query({ query, variables }: QueryParams, options?: { noStore?: boolean }) {\n
|
|
1
|
+
{"version":3,"file":"dataProviders/ApiClient.js","sources":["../../src/dataProviders/ApiClient.ts"],"sourcesContent":["interface QueryParams {\n query: string;\n variables: Record<string, any>;\n}\n\nexport interface ApiClientConfig {\n apiHost: string;\n apiKey: string;\n apiTenant: string;\n preview?: boolean;\n}\n\ntype WithPath<T> = T & {\n path?: string;\n next?: Record<string, any>;\n};\n\nexport class ApiClient {\n private readonly config: ApiClientConfig;\n\n constructor(config: ApiClientConfig) {\n this.config = config;\n }\n\n async fetch({ headers, path, ...params }: WithPath<RequestInit>): Promise<any> {\n return fetch(`${this.config.apiHost}${path}`, {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Tenant\": this.config.apiTenant,\n Authorization: \"Bearer \" + this.config.apiKey,\n ...headers\n },\n ...params\n }).then(res => res.json());\n }\n\n async query({ query, variables }: QueryParams, options?: { noStore?: boolean }) {\n const fetchOptions: Pick<WithPath<RequestInit>, \"cache\" | \"next\"> = options?.noStore\n ? { cache: \"no-store\" }\n : { next: { revalidate: this.config.preview ? 0 : 60 } };\n\n const request: WithPath<RequestInit> = {\n ...fetchOptions,\n path: \"/graphql\",\n method: \"POST\",\n body: JSON.stringify({\n query,\n variables\n })\n };\n\n const json = await this.fetch(request);\n\n if (json.message) {\n throw new Error(json.message);\n }\n\n if (json.errors) {\n console.error(json.errors);\n throw new Error(\"Failed to fetch API\");\n }\n\n return json.data;\n }\n}\n"],"names":["ApiClient","config","headers","path","params","fetch","res","query","variables","options","fetchOptions","request","JSON","json","Error","console"],"mappings":"AAiBO,MAAMA;IAGT,YAAYC,MAAuB,CAAE;QACjC,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEA,MAAM,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGC,QAA+B,EAAgB;QAC3E,OAAOC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,GAAGF,MAAM,EAAE;YAC1C,QAAQ;YACR,SAAS;gBACL,gBAAgB;gBAChB,YAAY,IAAI,CAAC,MAAM,CAAC,SAAS;gBACjC,eAAe,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC7C,GAAGD,OAAO;YACd;YACA,GAAGE,MAAM;QACb,GAAG,IAAI,CAACE,CAAAA,MAAOA,IAAI,IAAI;IAC3B;IAEA,MAAM,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAe,EAAEC,OAA+B,EAAE;QAC5E,MAAMC,eAA8DD,SAAS,UACvE;YAAE,OAAO;QAAW,IACpB;YAAE,MAAM;gBAAE,YAAY,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI;YAAG;QAAE;QAE3D,MAAME,UAAiC;YACnC,GAAGD,YAAY;YACf,MAAM;YACN,QAAQ;YACR,MAAME,KAAK,SAAS,CAAC;gBACjBL;gBACAC;YACJ;QACJ;QAEA,MAAMK,OAAO,MAAM,IAAI,CAAC,KAAK,CAACF;QAE9B,IAAIE,KAAK,OAAO,EACZ,MAAM,IAAIC,MAAMD,KAAK,OAAO;QAGhC,IAAIA,KAAK,MAAM,EAAE;YACbE,QAAQ,KAAK,CAACF,KAAK,MAAM;YACzB,MAAM,IAAIC,MAAM;QACpB;QAEA,OAAOD,KAAK,IAAI;IACpB;AACJ"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { IDataProvider, ListPagesOptions, ListPagesResult, PublicPage } from "../types.js";
|
|
2
|
-
import type { ActiveExperiment, VariantContent } from "../experiments/types.js";
|
|
3
2
|
import type { ApiClient } from "../dataProviders/ApiClient.js";
|
|
4
3
|
interface DefaultDataProviderConfig {
|
|
5
4
|
apiClient: ApiClient;
|
|
@@ -10,9 +9,6 @@ export declare class DefaultDataProvider implements IDataProvider {
|
|
|
10
9
|
getPageByPath(path: string): Promise<PublicPage | null>;
|
|
11
10
|
getPageById(id: string): Promise<PublicPage | null>;
|
|
12
11
|
listPages(options?: ListPagesOptions): Promise<ListPagesResult>;
|
|
13
|
-
getPageExperiment(path: string): Promise<ActiveExperiment | null>;
|
|
14
|
-
getVariantContent(variantId: string): Promise<VariantContent | null>;
|
|
15
|
-
getExperimentPaused(experimentId: string): Promise<boolean>;
|
|
16
12
|
private checkForErrors;
|
|
17
13
|
}
|
|
18
14
|
export {};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { GET_PAGE_BY_PATH } from "./GET_PAGE_BY_PATH.js";
|
|
2
2
|
import { GET_PAGE_BY_ID } from "./GET_PAGE_BY_ID.js";
|
|
3
3
|
import { LIST_PUBLISHED_PAGES } from "./LIST_PUBLISHED_PAGES.js";
|
|
4
|
-
import { GET_PAGE_EXPERIMENT } from "./GET_PAGE_EXPERIMENT.js";
|
|
5
|
-
import { GET_VARIANT_CONTENT } from "./GET_VARIANT_CONTENT.js";
|
|
6
|
-
import { GET_EXPERIMENT_PAUSED } from "./GET_EXPERIMENT_PAUSED.js";
|
|
7
4
|
const ignoreActions = [
|
|
8
5
|
".well-known",
|
|
9
6
|
"_next"
|
|
@@ -54,38 +51,6 @@ class DefaultDataProvider {
|
|
|
54
51
|
}
|
|
55
52
|
};
|
|
56
53
|
}
|
|
57
|
-
async getPageExperiment(path) {
|
|
58
|
-
const result = await this.config.apiClient.query({
|
|
59
|
-
query: GET_PAGE_EXPERIMENT,
|
|
60
|
-
variables: {
|
|
61
|
-
path
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
this.checkForErrors(`getPageExperiment:${path}`, result.websiteBuilder.getPageExperiment);
|
|
65
|
-
return result.websiteBuilder.getPageExperiment.data ?? null;
|
|
66
|
-
}
|
|
67
|
-
async getVariantContent(variantId) {
|
|
68
|
-
const result = await this.config.apiClient.query({
|
|
69
|
-
query: GET_VARIANT_CONTENT,
|
|
70
|
-
variables: {
|
|
71
|
-
id: variantId
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
this.checkForErrors(`getVariantContent:${variantId}`, result.websiteBuilder.getVariantContent);
|
|
75
|
-
return result.websiteBuilder.getVariantContent.data ?? null;
|
|
76
|
-
}
|
|
77
|
-
async getExperimentPaused(experimentId) {
|
|
78
|
-
const result = await this.config.apiClient.query({
|
|
79
|
-
query: GET_EXPERIMENT_PAUSED,
|
|
80
|
-
variables: {
|
|
81
|
-
experimentId
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
noStore: true
|
|
85
|
-
});
|
|
86
|
-
this.checkForErrors(`getExperimentPaused:${experimentId}`, result.websiteBuilder.getExperimentPaused);
|
|
87
|
-
return true === result.websiteBuilder.getExperimentPaused.data;
|
|
88
|
-
}
|
|
89
54
|
checkForErrors(action, data) {
|
|
90
55
|
if (data.error) {
|
|
91
56
|
if (ignoreActions.some((item)=>action.includes(item))) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataProviders/DefaultDataProvider.js","sources":["../../src/dataProviders/DefaultDataProvider.ts"],"sourcesContent":["import type { IDataProvider, ListPagesOptions, ListPagesResult, PublicPage } from \"~/types.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"dataProviders/DefaultDataProvider.js","sources":["../../src/dataProviders/DefaultDataProvider.ts"],"sourcesContent":["import type { IDataProvider, ListPagesOptions, ListPagesResult, PublicPage } from \"~/types.js\";\nimport type { ApiClient } from \"~/dataProviders/ApiClient.js\";\nimport { GET_PAGE_BY_PATH } from \"./GET_PAGE_BY_PATH.js\";\nimport { GET_PAGE_BY_ID } from \"./GET_PAGE_BY_ID.js\";\nimport { LIST_PUBLISHED_PAGES } from \"./LIST_PUBLISHED_PAGES.js\";\n\ninterface DefaultDataProviderConfig {\n apiClient: ApiClient;\n}\n\nconst ignoreActions = [\".well-known\", \"_next\"];\n\nexport class DefaultDataProvider implements IDataProvider {\n private config: DefaultDataProviderConfig;\n\n constructor(config: DefaultDataProviderConfig) {\n this.config = config;\n }\n\n public async getPageByPath(path: string): Promise<PublicPage | null> {\n const result = await this.config.apiClient.query({\n query: GET_PAGE_BY_PATH,\n variables: {\n path\n }\n });\n\n this.checkForErrors(`getPageByPath:${path}`, result.websiteBuilder.getPageByPath);\n\n return result.websiteBuilder.getPageByPath.data;\n }\n\n public async getPageById(id: string): Promise<PublicPage | null> {\n const result = await this.config.apiClient.query({\n query: GET_PAGE_BY_ID,\n variables: {\n id\n }\n });\n\n this.checkForErrors(\"getPageById\", result.websiteBuilder.getPageById);\n\n return result.websiteBuilder.getPageById.data;\n }\n\n public async listPages(options?: ListPagesOptions): Promise<ListPagesResult> {\n const { where, ...rest } = options ?? {};\n\n const result = await this.config.apiClient.query({\n query: LIST_PUBLISHED_PAGES,\n variables: {\n where: {\n ...where,\n published: true\n },\n ...rest\n }\n });\n\n this.checkForErrors(\"listPages\", result.websiteBuilder.listPages);\n\n return {\n data: result.websiteBuilder.listPages.data ?? [],\n meta: result.websiteBuilder.listPages.meta ?? {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null\n }\n };\n }\n\n private checkForErrors(action: string, data: any) {\n if (data.error) {\n // TODO: investigate how these ignored actions make their way to the SDK.\n if (ignoreActions.some(item => action.includes(item))) {\n return;\n }\n console.error(`Could not execute \"${action}\". Reason: ${data.error.message}`);\n }\n }\n}\n"],"names":["ignoreActions","DefaultDataProvider","config","path","result","GET_PAGE_BY_PATH","id","GET_PAGE_BY_ID","options","where","rest","LIST_PUBLISHED_PAGES","action","data","item","console"],"mappings":";;;AAUA,MAAMA,gBAAgB;IAAC;IAAe;CAAQ;AAEvC,MAAMC;IAGT,YAAYC,MAAiC,CAAE;QAC3C,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEA,MAAa,cAAcC,IAAY,EAA8B;QACjE,MAAMC,SAAS,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAC7C,OAAOC;YACP,WAAW;gBACPF;YACJ;QACJ;QAEA,IAAI,CAAC,cAAc,CAAC,CAAC,cAAc,EAAEA,MAAM,EAAEC,OAAO,cAAc,CAAC,aAAa;QAEhF,OAAOA,OAAO,cAAc,CAAC,aAAa,CAAC,IAAI;IACnD;IAEA,MAAa,YAAYE,EAAU,EAA8B;QAC7D,MAAMF,SAAS,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAC7C,OAAOG;YACP,WAAW;gBACPD;YACJ;QACJ;QAEA,IAAI,CAAC,cAAc,CAAC,eAAeF,OAAO,cAAc,CAAC,WAAW;QAEpE,OAAOA,OAAO,cAAc,CAAC,WAAW,CAAC,IAAI;IACjD;IAEA,MAAa,UAAUI,OAA0B,EAA4B;QACzE,MAAM,EAAEC,KAAK,EAAE,GAAGC,MAAM,GAAGF,WAAW,CAAC;QAEvC,MAAMJ,SAAS,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAC7C,OAAOO;YACP,WAAW;gBACP,OAAO;oBACH,GAAGF,KAAK;oBACR,WAAW;gBACf;gBACA,GAAGC,IAAI;YACX;QACJ;QAEA,IAAI,CAAC,cAAc,CAAC,aAAaN,OAAO,cAAc,CAAC,SAAS;QAEhE,OAAO;YACH,MAAMA,OAAO,cAAc,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE;YAChD,MAAMA,OAAO,cAAc,CAAC,SAAS,CAAC,IAAI,IAAI;gBAC1C,cAAc;gBACd,YAAY;gBACZ,QAAQ;YACZ;QACJ;IACJ;IAEQ,eAAeQ,MAAc,EAAEC,IAAS,EAAE;QAC9C,IAAIA,KAAK,KAAK,EAAE;YAEZ,IAAIb,cAAc,IAAI,CAACc,CAAAA,OAAQF,OAAO,QAAQ,CAACE,QAC3C;YAEJC,QAAQ,KAAK,CAAC,CAAC,mBAAmB,EAAEH,OAAO,WAAW,EAAEC,KAAK,KAAK,CAAC,OAAO,EAAE;QAChF;IACJ;AACJ"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { IDataProvider, PublicRedirect } from "../types.js";
|
|
2
2
|
import type { PublicPage } from "../types.js";
|
|
3
|
-
import type { ActiveExperiment, VariantContent } from "../experiments/types.js";
|
|
4
3
|
export declare class NullDataProvider implements IDataProvider {
|
|
5
4
|
getPageById(): Promise<PublicPage | null>;
|
|
6
5
|
getPageByPath(): Promise<PublicPage | null>;
|
|
7
|
-
getPageExperiment(): Promise<ActiveExperiment | null>;
|
|
8
|
-
getVariantContent(): Promise<VariantContent | null>;
|
|
9
|
-
getExperimentPaused(): Promise<boolean>;
|
|
10
6
|
listPages(): Promise<{
|
|
11
7
|
data: never[];
|
|
12
8
|
meta: {
|
|
@@ -5,15 +5,6 @@ class NullDataProvider {
|
|
|
5
5
|
getPageByPath() {
|
|
6
6
|
return Promise.resolve(null);
|
|
7
7
|
}
|
|
8
|
-
getPageExperiment() {
|
|
9
|
-
return Promise.resolve(null);
|
|
10
|
-
}
|
|
11
|
-
getVariantContent() {
|
|
12
|
-
return Promise.resolve(null);
|
|
13
|
-
}
|
|
14
|
-
getExperimentPaused() {
|
|
15
|
-
return Promise.resolve(false);
|
|
16
|
-
}
|
|
17
8
|
async listPages() {
|
|
18
9
|
return {
|
|
19
10
|
data: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataProviders/NullDataProvider.js","sources":["../../src/dataProviders/NullDataProvider.ts"],"sourcesContent":["import type { IDataProvider, PublicRedirect } from \"~/types.js\";\nimport type { PublicPage } from \"~/types.js\";\
|
|
1
|
+
{"version":3,"file":"dataProviders/NullDataProvider.js","sources":["../../src/dataProviders/NullDataProvider.ts"],"sourcesContent":["import type { IDataProvider, PublicRedirect } from \"~/types.js\";\nimport type { PublicPage } from \"~/types.js\";\n\nexport class NullDataProvider implements IDataProvider {\n getPageById(): Promise<PublicPage | null> {\n return Promise.resolve(null);\n }\n\n getPageByPath(): Promise<PublicPage | null> {\n return Promise.resolve(null);\n }\n\n public async listPages() {\n return { data: [], meta: { hasMoreItems: false, totalCount: 0, cursor: null } };\n }\n\n listRedirects(): Promise<PublicRedirect[]> {\n return Promise.resolve([]);\n }\n}\n"],"names":["NullDataProvider","Promise"],"mappings":"AAGO,MAAMA;IACT,cAA0C;QACtC,OAAOC,QAAQ,OAAO,CAAC;IAC3B;IAEA,gBAA4C;QACxC,OAAOA,QAAQ,OAAO,CAAC;IAC3B;IAEA,MAAa,YAAY;QACrB,OAAO;YAAE,MAAM,EAAE;YAAE,MAAM;gBAAE,cAAc;gBAAO,YAAY;gBAAG,QAAQ;YAAK;QAAE;IAClF;IAEA,gBAA2C;QACvC,OAAOA,QAAQ,OAAO,CAAC,EAAE;IAC7B;AACJ"}
|
package/index.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export * from "./DocumentStore.js";
|
|
|
8
8
|
export * from "./Logger.js";
|
|
9
9
|
export * from "./FunctionConverter.js";
|
|
10
10
|
export * from "./createInput.js";
|
|
11
|
+
export * from "./contentEntry/resolveContentEntry.js";
|
|
12
|
+
export * from "./contentEntry/ContentEntryCache.js";
|
|
13
|
+
export * from "./contentEntry/ContentEntryBindingsResolver.js";
|
|
14
|
+
export * from "./createComponent.js";
|
|
11
15
|
export * from "./image/index.js";
|
|
12
16
|
export * from "./asset/index.js";
|
|
13
17
|
export * from "./MouseTracker.js";
|
|
@@ -23,7 +27,6 @@ export * from "./createElement.js";
|
|
|
23
27
|
export * from "./registerComponentGroup.js";
|
|
24
28
|
export * from "./jsonPatch.js";
|
|
25
29
|
export * from "./headersProvider.js";
|
|
26
|
-
export * from "./experiments/index.js";
|
|
27
30
|
export * from "./ComponentManifestToAstConverter.js";
|
|
28
31
|
export * from "./findMatchingAstNode.js";
|
|
29
32
|
export * from "./InheritanceProcessor.js";
|
package/index.js
CHANGED
|
@@ -8,6 +8,10 @@ export * from "./DocumentStore.js";
|
|
|
8
8
|
export * from "./Logger.js";
|
|
9
9
|
export * from "./FunctionConverter.js";
|
|
10
10
|
export * from "./createInput.js";
|
|
11
|
+
export * from "./contentEntry/resolveContentEntry.js";
|
|
12
|
+
export * from "./contentEntry/ContentEntryCache.js";
|
|
13
|
+
export * from "./contentEntry/ContentEntryBindingsResolver.js";
|
|
14
|
+
export * from "./createComponent.js";
|
|
11
15
|
export * from "./image/index.js";
|
|
12
16
|
export * from "./asset/index.js";
|
|
13
17
|
export * from "./MouseTracker.js";
|
|
@@ -22,7 +26,6 @@ export * from "./createElement.js";
|
|
|
22
26
|
export * from "./registerComponentGroup.js";
|
|
23
27
|
export * from "./jsonPatch.js";
|
|
24
28
|
export * from "./headersProvider.js";
|
|
25
|
-
export * from "./experiments/index.js";
|
|
26
29
|
export * from "./ComponentManifestToAstConverter.js";
|
|
27
30
|
export * from "./findMatchingAstNode.js";
|
|
28
31
|
export * from "./InheritanceProcessor.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/website-builder-sdk",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.a4f3e4ea8b",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"author": "Pavel Denisjuk",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@webiny/sdk": "0.0.0-unstable.
|
|
15
|
+
"@webiny/sdk": "0.0.0-unstable.a4f3e4ea8b",
|
|
16
16
|
"csstype": "3.2.3",
|
|
17
17
|
"deep-equal": "2.2.3",
|
|
18
18
|
"deepmerge": "4.3.1",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/deep-equal": "1.0.4",
|
|
32
32
|
"@types/is-hotkey": "0.1.10",
|
|
33
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
33
|
+
"@webiny/build-tools": "0.0.0-unstable.a4f3e4ea8b",
|
|
34
34
|
"typescript": "7.0.2",
|
|
35
35
|
"vitest": "4.1.10"
|
|
36
36
|
},
|