@cms0/cms0 0.1.1 → 0.2.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/cjs/custom-types/registry.cjs +4 -19
- package/dist/cjs/index.cjs +69 -47
- package/dist/esm/custom-types/registry.js +4 -19
- package/dist/esm/index.js +69 -47
- package/dist/types/custom-types/index.d.ts +6 -11
- package/dist/types/custom-types/index.d.ts.map +1 -1
- package/dist/types/custom-types/registry.d.ts +9 -13
- package/dist/types/custom-types/registry.d.ts.map +1 -1
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -44,28 +44,13 @@ const richTextDescriptor = {
|
|
|
44
44
|
customType: "RichText",
|
|
45
45
|
};
|
|
46
46
|
const localizedStringDescriptor = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
type: "object",
|
|
50
|
-
properties: {
|
|
51
|
-
locale: primitive("string"),
|
|
52
|
-
isDefault: primitive("boolean"),
|
|
53
|
-
value: primitive("string"),
|
|
54
|
-
},
|
|
55
|
-
},
|
|
47
|
+
kind: "primitive",
|
|
48
|
+
type: "json",
|
|
56
49
|
customType: "LocalizedString",
|
|
57
50
|
};
|
|
58
51
|
const localizedRichTextDescriptor = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
type: "object",
|
|
62
|
-
properties: {
|
|
63
|
-
locale: primitive("string"),
|
|
64
|
-
isDefault: primitive("boolean"),
|
|
65
|
-
value: primitive("json"),
|
|
66
|
-
html: primitive("string"),
|
|
67
|
-
},
|
|
68
|
-
},
|
|
52
|
+
kind: "primitive",
|
|
53
|
+
type: "json",
|
|
69
54
|
customType: "LocalizedRichText",
|
|
70
55
|
};
|
|
71
56
|
exports.customModelDescriptors = {
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -100,56 +100,59 @@ function coerceRichTextValue(value) {
|
|
|
100
100
|
html,
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
function normalizeLocaleTag(value) {
|
|
104
|
+
return typeof value === "string" ? value.trim() : "";
|
|
105
|
+
}
|
|
106
|
+
function normalizeLocalizedMap(source, normalizeValue) {
|
|
107
|
+
const record = source && typeof source === "object" ? source : {};
|
|
108
|
+
const localesSource = record.locales && typeof record.locales === "object" && !Array.isArray(record.locales)
|
|
109
|
+
? record.locales
|
|
110
|
+
: {};
|
|
111
|
+
const locales = {};
|
|
112
|
+
for (const [locale, raw] of Object.entries(localesSource)) {
|
|
113
|
+
const localeKey = normalizeLocaleTag(locale);
|
|
114
|
+
if (!localeKey)
|
|
115
|
+
continue;
|
|
116
|
+
locales[localeKey] = normalizeValue(raw);
|
|
117
|
+
}
|
|
118
|
+
const explicitDefault = normalizeLocaleTag(record.defaultLocale);
|
|
119
|
+
const firstLocale = Object.keys(locales)[0] ?? "";
|
|
120
|
+
const defaultLocale = explicitDefault || firstLocale;
|
|
121
|
+
return { defaultLocale, locales };
|
|
122
|
+
}
|
|
123
|
+
function projectLocalizedByLocale(localized, locale) {
|
|
124
|
+
if (!locale || locale === "all")
|
|
125
|
+
return localized;
|
|
126
|
+
const requested = normalizeLocaleTag(locale);
|
|
127
|
+
if (!requested)
|
|
128
|
+
return localized;
|
|
129
|
+
const requestedValue = localized.locales[requested];
|
|
130
|
+
if (requestedValue === undefined) {
|
|
131
|
+
return {
|
|
132
|
+
defaultLocale: requested,
|
|
133
|
+
locales: {},
|
|
134
|
+
};
|
|
112
135
|
}
|
|
113
|
-
return
|
|
136
|
+
return {
|
|
137
|
+
defaultLocale: requested,
|
|
138
|
+
locales: {
|
|
139
|
+
[requested]: requestedValue,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
114
142
|
}
|
|
115
143
|
function coerceLocalizedStringValue(value, locale, defaultLocale) {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
...source,
|
|
122
|
-
locale: typeof source.locale === "string" ? source.locale : "",
|
|
123
|
-
isDefault: source.isDefault === true,
|
|
124
|
-
value: toPlainText(source.value),
|
|
125
|
-
};
|
|
126
|
-
})
|
|
127
|
-
.filter((row) => shouldKeepLocalizedEntry(row, locale, defaultLocale));
|
|
144
|
+
const normalized = normalizeLocalizedMap(value, (entry) => toPlainText(entry));
|
|
145
|
+
if (!normalized.defaultLocale && defaultLocale) {
|
|
146
|
+
normalized.defaultLocale = defaultLocale;
|
|
147
|
+
}
|
|
148
|
+
return projectLocalizedByLocale(normalized, locale);
|
|
128
149
|
}
|
|
129
150
|
function coerceLocalizedRichTextValue(value, locale, defaultLocale) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const nested = rawValue && typeof rawValue === "object" ? rawValue : null;
|
|
136
|
-
const normalizedValue = nested && "value" in nested && nested.value !== undefined
|
|
137
|
-
? nested.value
|
|
138
|
-
: rawValue ?? {};
|
|
139
|
-
const html = typeof source.html === "string"
|
|
140
|
-
? source.html
|
|
141
|
-
: typeof nested?.html === "string"
|
|
142
|
-
? nested.html
|
|
143
|
-
: "";
|
|
144
|
-
return {
|
|
145
|
-
...source,
|
|
146
|
-
locale: typeof source.locale === "string" ? source.locale : "",
|
|
147
|
-
isDefault: source.isDefault === true,
|
|
148
|
-
value: normalizedValue ?? {},
|
|
149
|
-
html,
|
|
150
|
-
};
|
|
151
|
-
})
|
|
152
|
-
.filter((row) => shouldKeepLocalizedEntry(row, locale, defaultLocale));
|
|
151
|
+
const normalized = normalizeLocalizedMap(value, (entry) => coerceRichTextValue(entry));
|
|
152
|
+
if (!normalized.defaultLocale && defaultLocale) {
|
|
153
|
+
normalized.defaultLocale = defaultLocale;
|
|
154
|
+
}
|
|
155
|
+
return projectLocalizedByLocale(normalized, locale);
|
|
153
156
|
}
|
|
154
157
|
function coerceCustomTypeValue(descriptor, value, options) {
|
|
155
158
|
const customType = descriptor.customType;
|
|
@@ -385,6 +388,13 @@ async function normalizeModelRef(modelName, id, context, trail, isCollectionItem
|
|
|
385
388
|
context.modelCache.set(nodeKey, promise);
|
|
386
389
|
return promise;
|
|
387
390
|
}
|
|
391
|
+
function missingModelRefValue(descriptor) {
|
|
392
|
+
if (descriptor.nullable)
|
|
393
|
+
return null;
|
|
394
|
+
if (descriptor.optional)
|
|
395
|
+
return undefined;
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
388
398
|
async function normalizeObjectField(descriptor, path, raw, context, trail, isCollectionItem) {
|
|
389
399
|
const source = raw && typeof raw === "object" ? raw : {};
|
|
390
400
|
const output = {};
|
|
@@ -402,6 +412,13 @@ async function normalizeObjectField(descriptor, path, raw, context, trail, isCol
|
|
|
402
412
|
propertyName,
|
|
403
413
|
allowObjectIdFallback: false,
|
|
404
414
|
});
|
|
415
|
+
if (!refId) {
|
|
416
|
+
const missing = missingModelRefValue(propertyDescriptor);
|
|
417
|
+
if (missing !== undefined) {
|
|
418
|
+
output[propertyName] = missing;
|
|
419
|
+
}
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
405
422
|
output[propertyName] = await normalizeModelRef(propertyDescriptor.model, refId, context, trail, false);
|
|
406
423
|
continue;
|
|
407
424
|
}
|
|
@@ -497,6 +514,9 @@ async function normalizeField(descriptor, path, raw, context, trail, isCollectio
|
|
|
497
514
|
}
|
|
498
515
|
if (isModelRefDescriptor(descriptor)) {
|
|
499
516
|
const refId = extractModelRefId(raw, descriptor.model);
|
|
517
|
+
if (!refId) {
|
|
518
|
+
return missingModelRefValue(descriptor);
|
|
519
|
+
}
|
|
500
520
|
return normalizeModelRef(descriptor.model, refId, context, trail, isCollectionItem);
|
|
501
521
|
}
|
|
502
522
|
if (isArrayDescriptor(descriptor)) {
|
|
@@ -604,10 +624,12 @@ async function runResource(resource, descriptor, baseUrl, apiKey, defaultLocale,
|
|
|
604
624
|
const responseMode = options?.response ?? "normalized";
|
|
605
625
|
const includeIdMode = resolveIncludeIdMode(options?.includeId);
|
|
606
626
|
const resolveModelRefs = options?.resolveModelRefs !== false;
|
|
607
|
-
const
|
|
627
|
+
const requestedLocale = options?.locale ??
|
|
608
628
|
(typeof options?.query?.locale === "string"
|
|
609
629
|
? options.query.locale
|
|
610
|
-
:
|
|
630
|
+
: undefined);
|
|
631
|
+
const locale = requestedLocale ??
|
|
632
|
+
(responseMode === "normalized" ? "all" : undefined);
|
|
611
633
|
const query = {
|
|
612
634
|
...(options?.query ?? {}),
|
|
613
635
|
};
|
|
@@ -40,28 +40,13 @@ const richTextDescriptor = {
|
|
|
40
40
|
customType: "RichText",
|
|
41
41
|
};
|
|
42
42
|
const localizedStringDescriptor = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
type: "object",
|
|
46
|
-
properties: {
|
|
47
|
-
locale: primitive("string"),
|
|
48
|
-
isDefault: primitive("boolean"),
|
|
49
|
-
value: primitive("string"),
|
|
50
|
-
},
|
|
51
|
-
},
|
|
43
|
+
kind: "primitive",
|
|
44
|
+
type: "json",
|
|
52
45
|
customType: "LocalizedString",
|
|
53
46
|
};
|
|
54
47
|
const localizedRichTextDescriptor = {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
type: "object",
|
|
58
|
-
properties: {
|
|
59
|
-
locale: primitive("string"),
|
|
60
|
-
isDefault: primitive("boolean"),
|
|
61
|
-
value: primitive("json"),
|
|
62
|
-
html: primitive("string"),
|
|
63
|
-
},
|
|
64
|
-
},
|
|
48
|
+
kind: "primitive",
|
|
49
|
+
type: "json",
|
|
65
50
|
customType: "LocalizedRichText",
|
|
66
51
|
};
|
|
67
52
|
export const customModelDescriptors = {
|
package/dist/esm/index.js
CHANGED
|
@@ -96,56 +96,59 @@ function coerceRichTextValue(value) {
|
|
|
96
96
|
html,
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
function normalizeLocaleTag(value) {
|
|
100
|
+
return typeof value === "string" ? value.trim() : "";
|
|
101
|
+
}
|
|
102
|
+
function normalizeLocalizedMap(source, normalizeValue) {
|
|
103
|
+
const record = source && typeof source === "object" ? source : {};
|
|
104
|
+
const localesSource = record.locales && typeof record.locales === "object" && !Array.isArray(record.locales)
|
|
105
|
+
? record.locales
|
|
106
|
+
: {};
|
|
107
|
+
const locales = {};
|
|
108
|
+
for (const [locale, raw] of Object.entries(localesSource)) {
|
|
109
|
+
const localeKey = normalizeLocaleTag(locale);
|
|
110
|
+
if (!localeKey)
|
|
111
|
+
continue;
|
|
112
|
+
locales[localeKey] = normalizeValue(raw);
|
|
113
|
+
}
|
|
114
|
+
const explicitDefault = normalizeLocaleTag(record.defaultLocale);
|
|
115
|
+
const firstLocale = Object.keys(locales)[0] ?? "";
|
|
116
|
+
const defaultLocale = explicitDefault || firstLocale;
|
|
117
|
+
return { defaultLocale, locales };
|
|
118
|
+
}
|
|
119
|
+
function projectLocalizedByLocale(localized, locale) {
|
|
120
|
+
if (!locale || locale === "all")
|
|
121
|
+
return localized;
|
|
122
|
+
const requested = normalizeLocaleTag(locale);
|
|
123
|
+
if (!requested)
|
|
124
|
+
return localized;
|
|
125
|
+
const requestedValue = localized.locales[requested];
|
|
126
|
+
if (requestedValue === undefined) {
|
|
127
|
+
return {
|
|
128
|
+
defaultLocale: requested,
|
|
129
|
+
locales: {},
|
|
130
|
+
};
|
|
108
131
|
}
|
|
109
|
-
return
|
|
132
|
+
return {
|
|
133
|
+
defaultLocale: requested,
|
|
134
|
+
locales: {
|
|
135
|
+
[requested]: requestedValue,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
110
138
|
}
|
|
111
139
|
function coerceLocalizedStringValue(value, locale, defaultLocale) {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
...source,
|
|
118
|
-
locale: typeof source.locale === "string" ? source.locale : "",
|
|
119
|
-
isDefault: source.isDefault === true,
|
|
120
|
-
value: toPlainText(source.value),
|
|
121
|
-
};
|
|
122
|
-
})
|
|
123
|
-
.filter((row) => shouldKeepLocalizedEntry(row, locale, defaultLocale));
|
|
140
|
+
const normalized = normalizeLocalizedMap(value, (entry) => toPlainText(entry));
|
|
141
|
+
if (!normalized.defaultLocale && defaultLocale) {
|
|
142
|
+
normalized.defaultLocale = defaultLocale;
|
|
143
|
+
}
|
|
144
|
+
return projectLocalizedByLocale(normalized, locale);
|
|
124
145
|
}
|
|
125
146
|
function coerceLocalizedRichTextValue(value, locale, defaultLocale) {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const nested = rawValue && typeof rawValue === "object" ? rawValue : null;
|
|
132
|
-
const normalizedValue = nested && "value" in nested && nested.value !== undefined
|
|
133
|
-
? nested.value
|
|
134
|
-
: rawValue ?? {};
|
|
135
|
-
const html = typeof source.html === "string"
|
|
136
|
-
? source.html
|
|
137
|
-
: typeof nested?.html === "string"
|
|
138
|
-
? nested.html
|
|
139
|
-
: "";
|
|
140
|
-
return {
|
|
141
|
-
...source,
|
|
142
|
-
locale: typeof source.locale === "string" ? source.locale : "",
|
|
143
|
-
isDefault: source.isDefault === true,
|
|
144
|
-
value: normalizedValue ?? {},
|
|
145
|
-
html,
|
|
146
|
-
};
|
|
147
|
-
})
|
|
148
|
-
.filter((row) => shouldKeepLocalizedEntry(row, locale, defaultLocale));
|
|
147
|
+
const normalized = normalizeLocalizedMap(value, (entry) => coerceRichTextValue(entry));
|
|
148
|
+
if (!normalized.defaultLocale && defaultLocale) {
|
|
149
|
+
normalized.defaultLocale = defaultLocale;
|
|
150
|
+
}
|
|
151
|
+
return projectLocalizedByLocale(normalized, locale);
|
|
149
152
|
}
|
|
150
153
|
function coerceCustomTypeValue(descriptor, value, options) {
|
|
151
154
|
const customType = descriptor.customType;
|
|
@@ -381,6 +384,13 @@ async function normalizeModelRef(modelName, id, context, trail, isCollectionItem
|
|
|
381
384
|
context.modelCache.set(nodeKey, promise);
|
|
382
385
|
return promise;
|
|
383
386
|
}
|
|
387
|
+
function missingModelRefValue(descriptor) {
|
|
388
|
+
if (descriptor.nullable)
|
|
389
|
+
return null;
|
|
390
|
+
if (descriptor.optional)
|
|
391
|
+
return undefined;
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
384
394
|
async function normalizeObjectField(descriptor, path, raw, context, trail, isCollectionItem) {
|
|
385
395
|
const source = raw && typeof raw === "object" ? raw : {};
|
|
386
396
|
const output = {};
|
|
@@ -398,6 +408,13 @@ async function normalizeObjectField(descriptor, path, raw, context, trail, isCol
|
|
|
398
408
|
propertyName,
|
|
399
409
|
allowObjectIdFallback: false,
|
|
400
410
|
});
|
|
411
|
+
if (!refId) {
|
|
412
|
+
const missing = missingModelRefValue(propertyDescriptor);
|
|
413
|
+
if (missing !== undefined) {
|
|
414
|
+
output[propertyName] = missing;
|
|
415
|
+
}
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
401
418
|
output[propertyName] = await normalizeModelRef(propertyDescriptor.model, refId, context, trail, false);
|
|
402
419
|
continue;
|
|
403
420
|
}
|
|
@@ -493,6 +510,9 @@ async function normalizeField(descriptor, path, raw, context, trail, isCollectio
|
|
|
493
510
|
}
|
|
494
511
|
if (isModelRefDescriptor(descriptor)) {
|
|
495
512
|
const refId = extractModelRefId(raw, descriptor.model);
|
|
513
|
+
if (!refId) {
|
|
514
|
+
return missingModelRefValue(descriptor);
|
|
515
|
+
}
|
|
496
516
|
return normalizeModelRef(descriptor.model, refId, context, trail, isCollectionItem);
|
|
497
517
|
}
|
|
498
518
|
if (isArrayDescriptor(descriptor)) {
|
|
@@ -600,10 +620,12 @@ async function runResource(resource, descriptor, baseUrl, apiKey, defaultLocale,
|
|
|
600
620
|
const responseMode = options?.response ?? "normalized";
|
|
601
621
|
const includeIdMode = resolveIncludeIdMode(options?.includeId);
|
|
602
622
|
const resolveModelRefs = options?.resolveModelRefs !== false;
|
|
603
|
-
const
|
|
623
|
+
const requestedLocale = options?.locale ??
|
|
604
624
|
(typeof options?.query?.locale === "string"
|
|
605
625
|
? options.query.locale
|
|
606
|
-
:
|
|
626
|
+
: undefined);
|
|
627
|
+
const locale = requestedLocale ??
|
|
628
|
+
(responseMode === "normalized" ? "all" : undefined);
|
|
607
629
|
const query = {
|
|
608
630
|
...(options?.query ?? {}),
|
|
609
631
|
};
|
|
@@ -22,15 +22,10 @@ export type RichText = {
|
|
|
22
22
|
value: Record<string, any>;
|
|
23
23
|
html: string;
|
|
24
24
|
};
|
|
25
|
-
export type
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export type LocalizedRichText =
|
|
31
|
-
locale: string;
|
|
32
|
-
isDefault: boolean;
|
|
33
|
-
value: Record<string, any>;
|
|
34
|
-
html: string;
|
|
35
|
-
}>;
|
|
25
|
+
export type Localized<T> = {
|
|
26
|
+
defaultLocale: string;
|
|
27
|
+
locales: Record<string, T>;
|
|
28
|
+
};
|
|
29
|
+
export type LocalizedString = Localized<string>;
|
|
30
|
+
export type LocalizedRichText = Localized<RichText>;
|
|
36
31
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/custom-types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC;AAE5B,MAAM,MAAM,KAAK,GAAG,QAAQ,G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M,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ModelDescriptor, PrimitiveType } from "@cms0/shared";
|
|
2
2
|
export declare const customModelDescriptors: {
|
|
3
3
|
readonly File: ModelDescriptor;
|
|
4
4
|
readonly Image: ModelDescriptor;
|
|
@@ -13,17 +13,15 @@ export declare const customInlineDescriptors: {
|
|
|
13
13
|
customType?: string;
|
|
14
14
|
};
|
|
15
15
|
readonly LocalizedString: {
|
|
16
|
-
kind?: "
|
|
17
|
-
type:
|
|
18
|
-
items: FieldDescriptor;
|
|
16
|
+
kind?: "primitive";
|
|
17
|
+
type: PrimitiveType;
|
|
19
18
|
optional?: boolean;
|
|
20
19
|
nullable?: boolean;
|
|
21
20
|
customType?: string;
|
|
22
21
|
};
|
|
23
22
|
readonly LocalizedRichText: {
|
|
24
|
-
kind?: "
|
|
25
|
-
type:
|
|
26
|
-
items: FieldDescriptor;
|
|
23
|
+
kind?: "primitive";
|
|
24
|
+
type: PrimitiveType;
|
|
27
25
|
optional?: boolean;
|
|
28
26
|
nullable?: boolean;
|
|
29
27
|
customType?: string;
|
|
@@ -38,17 +36,15 @@ export declare const customTypeDescriptors: {
|
|
|
38
36
|
customType?: string;
|
|
39
37
|
};
|
|
40
38
|
readonly LocalizedString: {
|
|
41
|
-
kind?: "
|
|
42
|
-
type:
|
|
43
|
-
items: FieldDescriptor;
|
|
39
|
+
kind?: "primitive";
|
|
40
|
+
type: PrimitiveType;
|
|
44
41
|
optional?: boolean;
|
|
45
42
|
nullable?: boolean;
|
|
46
43
|
customType?: string;
|
|
47
44
|
};
|
|
48
45
|
readonly LocalizedRichText: {
|
|
49
|
-
kind?: "
|
|
50
|
-
type:
|
|
51
|
-
items: FieldDescriptor;
|
|
46
|
+
kind?: "primitive";
|
|
47
|
+
type: PrimitiveType;
|
|
52
48
|
optional?: boolean;
|
|
53
49
|
nullable?: boolean;
|
|
54
50
|
customType?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/custom-types/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/custom-types/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA6DpF,eAAO,MAAM,sBAAsB;;;;CAIzB,CAAC;AAEX,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;CAI1B,CAAC;AAEX,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;CAGxB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,qBAAqB,CAAC;AAEhE,eAAO,MAAM,eAAe,aAAsD,CAAC;AACnF,eAAO,MAAM,oBAAoB,aAEhC,CAAC;AACF,eAAO,MAAM,qBAAqB,aAEjC,CAAC;AAEF,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAwBlF"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Cms0APIConfig } from "@cms0/cms0/config";
|
|
2
2
|
import { schemaDescriptor } from "@cms0/cms0/schema-descriptors";
|
|
3
3
|
import { FullDescriptor } from "@cms0/shared";
|
|
4
|
+
import type { LocalizedRichText as CmsLocalizedRichText, LocalizedString as CmsLocalizedString, RichText as CmsRichText } from "./custom-types/index.js";
|
|
4
5
|
type QueryValue = string | number | boolean | null | undefined;
|
|
5
6
|
type QueryParam = QueryValue | QueryValue[];
|
|
6
7
|
export type CmsQuery = Record<string, QueryParam>;
|
|
@@ -71,6 +72,7 @@ export interface Cms0Options {
|
|
|
71
72
|
assets?: CmsAssetOptions;
|
|
72
73
|
}
|
|
73
74
|
type PrimitiveValueFromDescriptor<TypeName extends string> = TypeName extends "string" ? string : TypeName extends "number" ? number : TypeName extends "boolean" ? boolean : any;
|
|
75
|
+
type CustomTypeValueFromDescriptor<TypeName extends string> = TypeName extends "RichText" ? CmsRichText : TypeName extends "LocalizedString" ? CmsLocalizedString : TypeName extends "LocalizedRichText" ? CmsLocalizedRichText : never;
|
|
74
76
|
type ApplyDescriptorFlags<Descriptor, Value> = Descriptor extends {
|
|
75
77
|
optional: true;
|
|
76
78
|
nullable: true;
|
|
@@ -83,6 +85,22 @@ type InferDescriptorObject<Properties extends Record<string, any>, ModelMap exte
|
|
|
83
85
|
[Key in keyof Properties]: InferDescriptorField<Properties[Key], ModelMap>;
|
|
84
86
|
};
|
|
85
87
|
type InferDescriptorField<Descriptor, ModelMap extends Record<string, any>> = ApplyDescriptorFlags<Descriptor, Descriptor extends {
|
|
88
|
+
customType: infer CustomType extends string;
|
|
89
|
+
} ? CustomTypeValueFromDescriptor<CustomType> extends never ? Descriptor extends {
|
|
90
|
+
kind: "modelRef";
|
|
91
|
+
model: infer ModelName extends string;
|
|
92
|
+
} ? ModelName extends keyof ModelMap ? ModelMap[ModelName] : string : Descriptor extends {
|
|
93
|
+
kind: "primitive";
|
|
94
|
+
type: infer Primitive extends string;
|
|
95
|
+
} ? PrimitiveValueFromDescriptor<Primitive> : Descriptor extends {
|
|
96
|
+
type: "array";
|
|
97
|
+
items: infer Items;
|
|
98
|
+
} ? Array<InferDescriptorField<Items, ModelMap>> : Descriptor extends {
|
|
99
|
+
type: "object";
|
|
100
|
+
properties: infer Properties extends Record<string, any>;
|
|
101
|
+
} ? InferDescriptorObject<Properties, ModelMap> : Descriptor extends {
|
|
102
|
+
type: infer Primitive extends string;
|
|
103
|
+
} ? PrimitiveValueFromDescriptor<Primitive> : any : CustomTypeValueFromDescriptor<CustomType> : Descriptor extends {
|
|
86
104
|
kind: "modelRef";
|
|
87
105
|
model: infer ModelName extends string;
|
|
88
106
|
} ? ModelName extends keyof ModelMap ? ModelMap[ModelName] : string : Descriptor extends {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAGL,cAAc,EACf,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAGL,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,iBAAiB,IAAI,oBAAoB,EACzC,eAAe,IAAI,kBAAkB,EACrC,QAAQ,IAAI,WAAW,EACxB,MAAM,yBAAyB,CAAC;AAEjC,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAC/D,KAAK,UAAU,GAAG,UAAU,GAAG,UAAU,EAAE,CAAC;AAC5C,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAElD,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,UAAU,GAAG,KAAK,CAAC;AAEhE,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EA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