prismic-ts-codegen 0.1.12 → 0.1.14
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/_node_modules/@prismicio/client/dist/buildQueryURL.cjs +59 -0
- package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.js +59 -0
- package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs +5 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.js +5 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/createClient.cjs +1138 -0
- package/dist/_node_modules/@prismicio/client/dist/createClient.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/createClient.js +1138 -0
- package/dist/_node_modules/@prismicio/client/dist/createClient.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ForbiddenError.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ForbiddenError.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ForbiddenError.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ForbiddenError.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/NotFoundError.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/NotFoundError.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/NotFoundError.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/NotFoundError.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ParsingError.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ParsingError.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ParsingError.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ParsingError.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +19 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +19 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/filter.cjs +247 -0
- package/dist/_node_modules/@prismicio/client/dist/filter.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/filter.js +247 -0
- package/dist/_node_modules/@prismicio/client/dist/filter.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryEndpoint.cjs +13 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryEndpoint.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryEndpoint.js +13 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryEndpoint.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.cjs +12 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.js +12 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +47 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +47 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +26 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +26 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryEndpoint.cjs +12 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryEndpoint.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryEndpoint.js +12 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryEndpoint.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/appendFilters.cjs +11 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/appendFilters.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/appendFilters.js +11 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/appendFilters.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castArray.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castArray.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castArray.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castArray.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castThunk.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castThunk.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castThunk.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castThunk.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/devMsg.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/devMsg.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/devMsg.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/devMsg.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/everyTagFilter.cjs +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/everyTagFilter.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/everyTagFilter.js +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/everyTagFilter.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findMasterRef.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findMasterRef.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findMasterRef.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findMasterRef.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRef.cjs +12 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRef.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRef.js +12 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRef.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByID.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByID.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByID.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByID.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByLabel.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByLabel.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByLabel.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByLabel.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/getPreviewCookie.cjs +21 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/getPreviewCookie.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/getPreviewCookie.js +21 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/getPreviewCookie.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/minifyGraphQLQuery.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/minifyGraphQLQuery.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/minifyGraphQLQuery.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/someTagsFilter.cjs +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/someTagsFilter.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/someTagsFilter.js +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/someTagsFilter.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/typeFilter.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/typeFilter.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/typeFilter.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/typeFilter.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/package.json.cjs +5 -0
- package/dist/_node_modules/@prismicio/client/dist/package.json.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/package.json.js +5 -0
- package/dist/_node_modules/@prismicio/client/dist/package.json.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +10 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +10 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +1 -0
- package/dist/_node_modules/quick-lru/index.cjs +234 -0
- package/dist/_node_modules/quick-lru/index.cjs.map +1 -0
- package/dist/_node_modules/quick-lru/index.js +235 -0
- package/dist/_node_modules/quick-lru/index.js.map +1 -0
- package/dist/cli/loadLocaleIDs.cjs +2 -19
- package/dist/cli/loadLocaleIDs.cjs.map +1 -1
- package/dist/cli/loadLocaleIDs.js +2 -2
- package/dist/cli/loadLocaleIDs.js.map +1 -1
- package/dist/generateTypes.cjs +2 -2
- package/dist/generateTypes.cjs.map +1 -1
- package/dist/generateTypes.js +1 -1
- package/dist/lib/buildCustomTypeDataType.cjs.map +1 -1
- package/dist/lib/buildCustomTypeDataType.d.ts +1 -1
- package/dist/lib/buildCustomTypeDataType.js.map +1 -1
- package/dist/lib/buildCustomTypeType.cjs.map +1 -1
- package/dist/lib/buildCustomTypeType.d.ts +1 -1
- package/dist/lib/buildCustomTypeType.js.map +1 -1
- package/dist/lib/buildFieldDocs.cjs.map +1 -1
- package/dist/lib/buildFieldDocs.d.ts +1 -1
- package/dist/lib/buildFieldDocs.js.map +1 -1
- package/dist/lib/buildFieldProperties.cjs +18 -19
- package/dist/lib/buildFieldProperties.cjs.map +1 -1
- package/dist/lib/buildFieldProperties.d.ts +1 -1
- package/dist/lib/buildFieldProperties.js +18 -19
- package/dist/lib/buildFieldProperties.js.map +1 -1
- package/dist/lib/buildSharedSliceType.cjs.map +1 -1
- package/dist/lib/buildSharedSliceType.d.ts +1 -1
- package/dist/lib/buildSharedSliceType.js.map +1 -1
- package/dist/lib/checkHasUIDFIeld.cjs.map +1 -1
- package/dist/lib/checkHasUIDFIeld.d.ts +1 -1
- package/dist/lib/checkHasUIDFIeld.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/buildCustomTypeDataType.ts +1 -1
- package/src/lib/buildCustomTypeType.ts +1 -1
- package/src/lib/buildFieldDocs.ts +1 -1
- package/src/lib/buildFieldProperties.ts +19 -23
- package/src/lib/buildSharedSliceType.ts +1 -1
- package/src/lib/checkHasUIDFIeld.ts +1 -1
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
class QuickLRU extends Map {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
super();
|
|
5
|
+
if (!(options.maxSize && options.maxSize > 0)) {
|
|
6
|
+
throw new TypeError("`maxSize` must be a number greater than 0");
|
|
7
|
+
}
|
|
8
|
+
if (typeof options.maxAge === "number" && options.maxAge === 0) {
|
|
9
|
+
throw new TypeError("`maxAge` must be a number greater than 0");
|
|
10
|
+
}
|
|
11
|
+
this.maxSize = options.maxSize;
|
|
12
|
+
this.maxAge = options.maxAge || Number.POSITIVE_INFINITY;
|
|
13
|
+
this.onEviction = options.onEviction;
|
|
14
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
15
|
+
this.oldCache = /* @__PURE__ */ new Map();
|
|
16
|
+
this._size = 0;
|
|
17
|
+
}
|
|
18
|
+
// TODO: Use private class methods when targeting Node.js 16.
|
|
19
|
+
_emitEvictions(cache) {
|
|
20
|
+
if (typeof this.onEviction !== "function") {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const [key, item] of cache) {
|
|
24
|
+
this.onEviction(key, item.value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
_deleteIfExpired(key, item) {
|
|
28
|
+
if (typeof item.expiry === "number" && item.expiry <= Date.now()) {
|
|
29
|
+
if (typeof this.onEviction === "function") {
|
|
30
|
+
this.onEviction(key, item.value);
|
|
31
|
+
}
|
|
32
|
+
return this.delete(key);
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
_getOrDeleteIfExpired(key, item) {
|
|
37
|
+
const deleted = this._deleteIfExpired(key, item);
|
|
38
|
+
if (deleted === false) {
|
|
39
|
+
return item.value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
_getItemValue(key, item) {
|
|
43
|
+
return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
|
|
44
|
+
}
|
|
45
|
+
_peek(key, cache) {
|
|
46
|
+
const item = cache.get(key);
|
|
47
|
+
return this._getItemValue(key, item);
|
|
48
|
+
}
|
|
49
|
+
_set(key, value) {
|
|
50
|
+
this.cache.set(key, value);
|
|
51
|
+
this._size++;
|
|
52
|
+
if (this._size >= this.maxSize) {
|
|
53
|
+
this._size = 0;
|
|
54
|
+
this._emitEvictions(this.oldCache);
|
|
55
|
+
this.oldCache = this.cache;
|
|
56
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
_moveToRecent(key, item) {
|
|
60
|
+
this.oldCache.delete(key);
|
|
61
|
+
this._set(key, item);
|
|
62
|
+
}
|
|
63
|
+
*_entriesAscending() {
|
|
64
|
+
for (const item of this.oldCache) {
|
|
65
|
+
const [key, value] = item;
|
|
66
|
+
if (!this.cache.has(key)) {
|
|
67
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
68
|
+
if (deleted === false) {
|
|
69
|
+
yield item;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const item of this.cache) {
|
|
74
|
+
const [key, value] = item;
|
|
75
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
76
|
+
if (deleted === false) {
|
|
77
|
+
yield item;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
get(key) {
|
|
82
|
+
if (this.cache.has(key)) {
|
|
83
|
+
const item = this.cache.get(key);
|
|
84
|
+
return this._getItemValue(key, item);
|
|
85
|
+
}
|
|
86
|
+
if (this.oldCache.has(key)) {
|
|
87
|
+
const item = this.oldCache.get(key);
|
|
88
|
+
if (this._deleteIfExpired(key, item) === false) {
|
|
89
|
+
this._moveToRecent(key, item);
|
|
90
|
+
return item.value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
set(key, value, { maxAge = this.maxAge } = {}) {
|
|
95
|
+
const expiry = typeof maxAge === "number" && maxAge !== Number.POSITIVE_INFINITY ? Date.now() + maxAge : void 0;
|
|
96
|
+
if (this.cache.has(key)) {
|
|
97
|
+
this.cache.set(key, {
|
|
98
|
+
value,
|
|
99
|
+
expiry
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
this._set(key, { value, expiry });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
has(key) {
|
|
106
|
+
if (this.cache.has(key)) {
|
|
107
|
+
return !this._deleteIfExpired(key, this.cache.get(key));
|
|
108
|
+
}
|
|
109
|
+
if (this.oldCache.has(key)) {
|
|
110
|
+
return !this._deleteIfExpired(key, this.oldCache.get(key));
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
peek(key) {
|
|
115
|
+
if (this.cache.has(key)) {
|
|
116
|
+
return this._peek(key, this.cache);
|
|
117
|
+
}
|
|
118
|
+
if (this.oldCache.has(key)) {
|
|
119
|
+
return this._peek(key, this.oldCache);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
delete(key) {
|
|
123
|
+
const deleted = this.cache.delete(key);
|
|
124
|
+
if (deleted) {
|
|
125
|
+
this._size--;
|
|
126
|
+
}
|
|
127
|
+
return this.oldCache.delete(key) || deleted;
|
|
128
|
+
}
|
|
129
|
+
clear() {
|
|
130
|
+
this.cache.clear();
|
|
131
|
+
this.oldCache.clear();
|
|
132
|
+
this._size = 0;
|
|
133
|
+
}
|
|
134
|
+
resize(newSize) {
|
|
135
|
+
if (!(newSize && newSize > 0)) {
|
|
136
|
+
throw new TypeError("`maxSize` must be a number greater than 0");
|
|
137
|
+
}
|
|
138
|
+
const items = [...this._entriesAscending()];
|
|
139
|
+
const removeCount = items.length - newSize;
|
|
140
|
+
if (removeCount < 0) {
|
|
141
|
+
this.cache = new Map(items);
|
|
142
|
+
this.oldCache = /* @__PURE__ */ new Map();
|
|
143
|
+
this._size = items.length;
|
|
144
|
+
} else {
|
|
145
|
+
if (removeCount > 0) {
|
|
146
|
+
this._emitEvictions(items.slice(0, removeCount));
|
|
147
|
+
}
|
|
148
|
+
this.oldCache = new Map(items.slice(removeCount));
|
|
149
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
150
|
+
this._size = 0;
|
|
151
|
+
}
|
|
152
|
+
this.maxSize = newSize;
|
|
153
|
+
}
|
|
154
|
+
*keys() {
|
|
155
|
+
for (const [key] of this) {
|
|
156
|
+
yield key;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
*values() {
|
|
160
|
+
for (const [, value] of this) {
|
|
161
|
+
yield value;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
*[Symbol.iterator]() {
|
|
165
|
+
for (const item of this.cache) {
|
|
166
|
+
const [key, value] = item;
|
|
167
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
168
|
+
if (deleted === false) {
|
|
169
|
+
yield [key, value.value];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
for (const item of this.oldCache) {
|
|
173
|
+
const [key, value] = item;
|
|
174
|
+
if (!this.cache.has(key)) {
|
|
175
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
176
|
+
if (deleted === false) {
|
|
177
|
+
yield [key, value.value];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
*entriesDescending() {
|
|
183
|
+
let items = [...this.cache];
|
|
184
|
+
for (let i = items.length - 1; i >= 0; --i) {
|
|
185
|
+
const item = items[i];
|
|
186
|
+
const [key, value] = item;
|
|
187
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
188
|
+
if (deleted === false) {
|
|
189
|
+
yield [key, value.value];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
items = [...this.oldCache];
|
|
193
|
+
for (let i = items.length - 1; i >= 0; --i) {
|
|
194
|
+
const item = items[i];
|
|
195
|
+
const [key, value] = item;
|
|
196
|
+
if (!this.cache.has(key)) {
|
|
197
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
198
|
+
if (deleted === false) {
|
|
199
|
+
yield [key, value.value];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
*entriesAscending() {
|
|
205
|
+
for (const [key, value] of this._entriesAscending()) {
|
|
206
|
+
yield [key, value.value];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
get size() {
|
|
210
|
+
if (!this._size) {
|
|
211
|
+
return this.oldCache.size;
|
|
212
|
+
}
|
|
213
|
+
let oldCacheSize = 0;
|
|
214
|
+
for (const key of this.oldCache.keys()) {
|
|
215
|
+
if (!this.cache.has(key)) {
|
|
216
|
+
oldCacheSize++;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return Math.min(this._size + oldCacheSize, this.maxSize);
|
|
220
|
+
}
|
|
221
|
+
entries() {
|
|
222
|
+
return this.entriesAscending();
|
|
223
|
+
}
|
|
224
|
+
forEach(callbackFunction, thisArgument = this) {
|
|
225
|
+
for (const [key, value] of this.entriesAscending()) {
|
|
226
|
+
callbackFunction.call(thisArgument, value, key, this);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
get [Symbol.toStringTag]() {
|
|
230
|
+
return JSON.stringify([...this.entriesAscending()]);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
module.exports = QuickLRU;
|
|
234
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../node_modules/quick-lru/index.js"],"sourcesContent":["export default class QuickLRU extends Map {\n\tconstructor(options = {}) {\n\t\tsuper();\n\n\t\tif (!(options.maxSize && options.maxSize > 0)) {\n\t\t\tthrow new TypeError('`maxSize` must be a number greater than 0');\n\t\t}\n\n\t\tif (typeof options.maxAge === 'number' && options.maxAge === 0) {\n\t\t\tthrow new TypeError('`maxAge` must be a number greater than 0');\n\t\t}\n\n\t\t// TODO: Use private class fields when ESLint supports them.\n\t\tthis.maxSize = options.maxSize;\n\t\tthis.maxAge = options.maxAge || Number.POSITIVE_INFINITY;\n\t\tthis.onEviction = options.onEviction;\n\t\tthis.cache = new Map();\n\t\tthis.oldCache = new Map();\n\t\tthis._size = 0;\n\t}\n\n\t// TODO: Use private class methods when targeting Node.js 16.\n\t_emitEvictions(cache) {\n\t\tif (typeof this.onEviction !== 'function') {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const [key, item] of cache) {\n\t\t\tthis.onEviction(key, item.value);\n\t\t}\n\t}\n\n\t_deleteIfExpired(key, item) {\n\t\tif (typeof item.expiry === 'number' && item.expiry <= Date.now()) {\n\t\t\tif (typeof this.onEviction === 'function') {\n\t\t\t\tthis.onEviction(key, item.value);\n\t\t\t}\n\n\t\t\treturn this.delete(key);\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t_getOrDeleteIfExpired(key, item) {\n\t\tconst deleted = this._deleteIfExpired(key, item);\n\t\tif (deleted === false) {\n\t\t\treturn item.value;\n\t\t}\n\t}\n\n\t_getItemValue(key, item) {\n\t\treturn item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;\n\t}\n\n\t_peek(key, cache) {\n\t\tconst item = cache.get(key);\n\n\t\treturn this._getItemValue(key, item);\n\t}\n\n\t_set(key, value) {\n\t\tthis.cache.set(key, value);\n\t\tthis._size++;\n\n\t\tif (this._size >= this.maxSize) {\n\t\t\tthis._size = 0;\n\t\t\tthis._emitEvictions(this.oldCache);\n\t\t\tthis.oldCache = this.cache;\n\t\t\tthis.cache = new Map();\n\t\t}\n\t}\n\n\t_moveToRecent(key, item) {\n\t\tthis.oldCache.delete(key);\n\t\tthis._set(key, item);\n\t}\n\n\t* _entriesAscending() {\n\t\tfor (const item of this.oldCache) {\n\t\t\tconst [key, value] = item;\n\t\t\tif (!this.cache.has(key)) {\n\t\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\t\tif (deleted === false) {\n\t\t\t\t\tyield item;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const item of this.cache) {\n\t\t\tconst [key, value] = item;\n\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\tif (deleted === false) {\n\t\t\t\tyield item;\n\t\t\t}\n\t\t}\n\t}\n\n\tget(key) {\n\t\tif (this.cache.has(key)) {\n\t\t\tconst item = this.cache.get(key);\n\n\t\t\treturn this._getItemValue(key, item);\n\t\t}\n\n\t\tif (this.oldCache.has(key)) {\n\t\t\tconst item = this.oldCache.get(key);\n\t\t\tif (this._deleteIfExpired(key, item) === false) {\n\t\t\t\tthis._moveToRecent(key, item);\n\t\t\t\treturn item.value;\n\t\t\t}\n\t\t}\n\t}\n\n\tset(key, value, {maxAge = this.maxAge} = {}) {\n\t\tconst expiry =\n\t\t\ttypeof maxAge === 'number' && maxAge !== Number.POSITIVE_INFINITY ?\n\t\t\t\tDate.now() + maxAge :\n\t\t\t\tundefined;\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.set(key, {\n\t\t\t\tvalue,\n\t\t\t\texpiry\n\t\t\t});\n\t\t} else {\n\t\t\tthis._set(key, {value, expiry});\n\t\t}\n\t}\n\n\thas(key) {\n\t\tif (this.cache.has(key)) {\n\t\t\treturn !this._deleteIfExpired(key, this.cache.get(key));\n\t\t}\n\n\t\tif (this.oldCache.has(key)) {\n\t\t\treturn !this._deleteIfExpired(key, this.oldCache.get(key));\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tpeek(key) {\n\t\tif (this.cache.has(key)) {\n\t\t\treturn this._peek(key, this.cache);\n\t\t}\n\n\t\tif (this.oldCache.has(key)) {\n\t\t\treturn this._peek(key, this.oldCache);\n\t\t}\n\t}\n\n\tdelete(key) {\n\t\tconst deleted = this.cache.delete(key);\n\t\tif (deleted) {\n\t\t\tthis._size--;\n\t\t}\n\n\t\treturn this.oldCache.delete(key) || deleted;\n\t}\n\n\tclear() {\n\t\tthis.cache.clear();\n\t\tthis.oldCache.clear();\n\t\tthis._size = 0;\n\t}\n\n\tresize(newSize) {\n\t\tif (!(newSize && newSize > 0)) {\n\t\t\tthrow new TypeError('`maxSize` must be a number greater than 0');\n\t\t}\n\n\t\tconst items = [...this._entriesAscending()];\n\t\tconst removeCount = items.length - newSize;\n\t\tif (removeCount < 0) {\n\t\t\tthis.cache = new Map(items);\n\t\t\tthis.oldCache = new Map();\n\t\t\tthis._size = items.length;\n\t\t} else {\n\t\t\tif (removeCount > 0) {\n\t\t\t\tthis._emitEvictions(items.slice(0, removeCount));\n\t\t\t}\n\n\t\t\tthis.oldCache = new Map(items.slice(removeCount));\n\t\t\tthis.cache = new Map();\n\t\t\tthis._size = 0;\n\t\t}\n\n\t\tthis.maxSize = newSize;\n\t}\n\n\t* keys() {\n\t\tfor (const [key] of this) {\n\t\t\tyield key;\n\t\t}\n\t}\n\n\t* values() {\n\t\tfor (const [, value] of this) {\n\t\t\tyield value;\n\t\t}\n\t}\n\n\t* [Symbol.iterator]() {\n\t\tfor (const item of this.cache) {\n\t\t\tconst [key, value] = item;\n\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\tif (deleted === false) {\n\t\t\t\tyield [key, value.value];\n\t\t\t}\n\t\t}\n\n\t\tfor (const item of this.oldCache) {\n\t\t\tconst [key, value] = item;\n\t\t\tif (!this.cache.has(key)) {\n\t\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\t\tif (deleted === false) {\n\t\t\t\t\tyield [key, value.value];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t* entriesDescending() {\n\t\tlet items = [...this.cache];\n\t\tfor (let i = items.length - 1; i >= 0; --i) {\n\t\t\tconst item = items[i];\n\t\t\tconst [key, value] = item;\n\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\tif (deleted === false) {\n\t\t\t\tyield [key, value.value];\n\t\t\t}\n\t\t}\n\n\t\titems = [...this.oldCache];\n\t\tfor (let i = items.length - 1; i >= 0; --i) {\n\t\t\tconst item = items[i];\n\t\t\tconst [key, value] = item;\n\t\t\tif (!this.cache.has(key)) {\n\t\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\t\tif (deleted === false) {\n\t\t\t\t\tyield [key, value.value];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t* entriesAscending() {\n\t\tfor (const [key, value] of this._entriesAscending()) {\n\t\t\tyield [key, value.value];\n\t\t}\n\t}\n\n\tget size() {\n\t\tif (!this._size) {\n\t\t\treturn this.oldCache.size;\n\t\t}\n\n\t\tlet oldCacheSize = 0;\n\t\tfor (const key of this.oldCache.keys()) {\n\t\t\tif (!this.cache.has(key)) {\n\t\t\t\toldCacheSize++;\n\t\t\t}\n\t\t}\n\n\t\treturn Math.min(this._size + oldCacheSize, this.maxSize);\n\t}\n\n\tentries() {\n\t\treturn this.entriesAscending();\n\t}\n\n\tforEach(callbackFunction, thisArgument = this) {\n\t\tfor (const [key, value] of this.entriesAscending()) {\n\t\t\tcallbackFunction.call(thisArgument, value, key, this);\n\t\t}\n\t}\n\n\tget [Symbol.toStringTag]() {\n\t\treturn JSON.stringify([...this.entriesAscending()]);\n\t}\n}\n"],"names":[],"mappings":";AAAe,MAAM,iBAAiB,IAAI;AAAA,EACzC,YAAY,UAAU,IAAI;AACzB;AAEA,QAAI,EAAE,QAAQ,WAAW,QAAQ,UAAU,IAAI;AAC9C,YAAM,IAAI,UAAU,2CAA2C;AAAA,IAC/D;AAED,QAAI,OAAO,QAAQ,WAAW,YAAY,QAAQ,WAAW,GAAG;AAC/D,YAAM,IAAI,UAAU,0CAA0C;AAAA,IAC9D;AAGD,SAAK,UAAU,QAAQ;AACvB,SAAK,SAAS,QAAQ,UAAU,OAAO;AACvC,SAAK,aAAa,QAAQ;AAC1B,SAAK,QAAQ,oBAAI;AACjB,SAAK,WAAW,oBAAI;AACpB,SAAK,QAAQ;AAAA,EACb;AAAA;AAAA,EAGD,eAAe,OAAO;AACrB,QAAI,OAAO,KAAK,eAAe,YAAY;AAC1C;AAAA,IACA;AAED,eAAW,CAAC,KAAK,IAAI,KAAK,OAAO;AAChC,WAAK,WAAW,KAAK,KAAK,KAAK;AAAA,IAC/B;AAAA,EACD;AAAA,EAED,iBAAiB,KAAK,MAAM;AAC3B,QAAI,OAAO,KAAK,WAAW,YAAY,KAAK,UAAU,KAAK,OAAO;AACjE,UAAI,OAAO,KAAK,eAAe,YAAY;AAC1C,aAAK,WAAW,KAAK,KAAK,KAAK;AAAA,MAC/B;AAED,aAAO,KAAK,OAAO,GAAG;AAAA,IACtB;AAED,WAAO;AAAA,EACP;AAAA,EAED,sBAAsB,KAAK,MAAM;AAChC,UAAM,UA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AK;EACZ;AAAA,EAED,QAAQ,kBAAkB,eAAe,MAAM;AAC9C,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK,iBAAgB,GAAI;AACnD,uBAAiB,KAAK,cAAc,OAAO,KAAK,IAAI;AAAA,IACpD;AAAA,EACD;AAAA,EAED,KAAK,OAAO,WAAW,IAAI;AAC1B,WAAO,KAAK,UAAU,CAAC,GAAG,KAAK,iBAAkB,CAAA,CAAC;AAAA,EAClD;AACF;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
class QuickLRU extends Map {
|
|
2
|
+
constructor(options = {}) {
|
|
3
|
+
super();
|
|
4
|
+
if (!(options.maxSize && options.maxSize > 0)) {
|
|
5
|
+
throw new TypeError("`maxSize` must be a number greater than 0");
|
|
6
|
+
}
|
|
7
|
+
if (typeof options.maxAge === "number" && options.maxAge === 0) {
|
|
8
|
+
throw new TypeError("`maxAge` must be a number greater than 0");
|
|
9
|
+
}
|
|
10
|
+
this.maxSize = options.maxSize;
|
|
11
|
+
this.maxAge = options.maxAge || Number.POSITIVE_INFINITY;
|
|
12
|
+
this.onEviction = options.onEviction;
|
|
13
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
14
|
+
this.oldCache = /* @__PURE__ */ new Map();
|
|
15
|
+
this._size = 0;
|
|
16
|
+
}
|
|
17
|
+
// TODO: Use private class methods when targeting Node.js 16.
|
|
18
|
+
_emitEvictions(cache) {
|
|
19
|
+
if (typeof this.onEviction !== "function") {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
for (const [key, item] of cache) {
|
|
23
|
+
this.onEviction(key, item.value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
_deleteIfExpired(key, item) {
|
|
27
|
+
if (typeof item.expiry === "number" && item.expiry <= Date.now()) {
|
|
28
|
+
if (typeof this.onEviction === "function") {
|
|
29
|
+
this.onEviction(key, item.value);
|
|
30
|
+
}
|
|
31
|
+
return this.delete(key);
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
_getOrDeleteIfExpired(key, item) {
|
|
36
|
+
const deleted = this._deleteIfExpired(key, item);
|
|
37
|
+
if (deleted === false) {
|
|
38
|
+
return item.value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
_getItemValue(key, item) {
|
|
42
|
+
return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
|
|
43
|
+
}
|
|
44
|
+
_peek(key, cache) {
|
|
45
|
+
const item = cache.get(key);
|
|
46
|
+
return this._getItemValue(key, item);
|
|
47
|
+
}
|
|
48
|
+
_set(key, value) {
|
|
49
|
+
this.cache.set(key, value);
|
|
50
|
+
this._size++;
|
|
51
|
+
if (this._size >= this.maxSize) {
|
|
52
|
+
this._size = 0;
|
|
53
|
+
this._emitEvictions(this.oldCache);
|
|
54
|
+
this.oldCache = this.cache;
|
|
55
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
_moveToRecent(key, item) {
|
|
59
|
+
this.oldCache.delete(key);
|
|
60
|
+
this._set(key, item);
|
|
61
|
+
}
|
|
62
|
+
*_entriesAscending() {
|
|
63
|
+
for (const item of this.oldCache) {
|
|
64
|
+
const [key, value] = item;
|
|
65
|
+
if (!this.cache.has(key)) {
|
|
66
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
67
|
+
if (deleted === false) {
|
|
68
|
+
yield item;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const item of this.cache) {
|
|
73
|
+
const [key, value] = item;
|
|
74
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
75
|
+
if (deleted === false) {
|
|
76
|
+
yield item;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
get(key) {
|
|
81
|
+
if (this.cache.has(key)) {
|
|
82
|
+
const item = this.cache.get(key);
|
|
83
|
+
return this._getItemValue(key, item);
|
|
84
|
+
}
|
|
85
|
+
if (this.oldCache.has(key)) {
|
|
86
|
+
const item = this.oldCache.get(key);
|
|
87
|
+
if (this._deleteIfExpired(key, item) === false) {
|
|
88
|
+
this._moveToRecent(key, item);
|
|
89
|
+
return item.value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
set(key, value, { maxAge = this.maxAge } = {}) {
|
|
94
|
+
const expiry = typeof maxAge === "number" && maxAge !== Number.POSITIVE_INFINITY ? Date.now() + maxAge : void 0;
|
|
95
|
+
if (this.cache.has(key)) {
|
|
96
|
+
this.cache.set(key, {
|
|
97
|
+
value,
|
|
98
|
+
expiry
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
this._set(key, { value, expiry });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
has(key) {
|
|
105
|
+
if (this.cache.has(key)) {
|
|
106
|
+
return !this._deleteIfExpired(key, this.cache.get(key));
|
|
107
|
+
}
|
|
108
|
+
if (this.oldCache.has(key)) {
|
|
109
|
+
return !this._deleteIfExpired(key, this.oldCache.get(key));
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
peek(key) {
|
|
114
|
+
if (this.cache.has(key)) {
|
|
115
|
+
return this._peek(key, this.cache);
|
|
116
|
+
}
|
|
117
|
+
if (this.oldCache.has(key)) {
|
|
118
|
+
return this._peek(key, this.oldCache);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
delete(key) {
|
|
122
|
+
const deleted = this.cache.delete(key);
|
|
123
|
+
if (deleted) {
|
|
124
|
+
this._size--;
|
|
125
|
+
}
|
|
126
|
+
return this.oldCache.delete(key) || deleted;
|
|
127
|
+
}
|
|
128
|
+
clear() {
|
|
129
|
+
this.cache.clear();
|
|
130
|
+
this.oldCache.clear();
|
|
131
|
+
this._size = 0;
|
|
132
|
+
}
|
|
133
|
+
resize(newSize) {
|
|
134
|
+
if (!(newSize && newSize > 0)) {
|
|
135
|
+
throw new TypeError("`maxSize` must be a number greater than 0");
|
|
136
|
+
}
|
|
137
|
+
const items = [...this._entriesAscending()];
|
|
138
|
+
const removeCount = items.length - newSize;
|
|
139
|
+
if (removeCount < 0) {
|
|
140
|
+
this.cache = new Map(items);
|
|
141
|
+
this.oldCache = /* @__PURE__ */ new Map();
|
|
142
|
+
this._size = items.length;
|
|
143
|
+
} else {
|
|
144
|
+
if (removeCount > 0) {
|
|
145
|
+
this._emitEvictions(items.slice(0, removeCount));
|
|
146
|
+
}
|
|
147
|
+
this.oldCache = new Map(items.slice(removeCount));
|
|
148
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
149
|
+
this._size = 0;
|
|
150
|
+
}
|
|
151
|
+
this.maxSize = newSize;
|
|
152
|
+
}
|
|
153
|
+
*keys() {
|
|
154
|
+
for (const [key] of this) {
|
|
155
|
+
yield key;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
*values() {
|
|
159
|
+
for (const [, value] of this) {
|
|
160
|
+
yield value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
*[Symbol.iterator]() {
|
|
164
|
+
for (const item of this.cache) {
|
|
165
|
+
const [key, value] = item;
|
|
166
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
167
|
+
if (deleted === false) {
|
|
168
|
+
yield [key, value.value];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const item of this.oldCache) {
|
|
172
|
+
const [key, value] = item;
|
|
173
|
+
if (!this.cache.has(key)) {
|
|
174
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
175
|
+
if (deleted === false) {
|
|
176
|
+
yield [key, value.value];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
*entriesDescending() {
|
|
182
|
+
let items = [...this.cache];
|
|
183
|
+
for (let i = items.length - 1; i >= 0; --i) {
|
|
184
|
+
const item = items[i];
|
|
185
|
+
const [key, value] = item;
|
|
186
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
187
|
+
if (deleted === false) {
|
|
188
|
+
yield [key, value.value];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
items = [...this.oldCache];
|
|
192
|
+
for (let i = items.length - 1; i >= 0; --i) {
|
|
193
|
+
const item = items[i];
|
|
194
|
+
const [key, value] = item;
|
|
195
|
+
if (!this.cache.has(key)) {
|
|
196
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
197
|
+
if (deleted === false) {
|
|
198
|
+
yield [key, value.value];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
*entriesAscending() {
|
|
204
|
+
for (const [key, value] of this._entriesAscending()) {
|
|
205
|
+
yield [key, value.value];
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
get size() {
|
|
209
|
+
if (!this._size) {
|
|
210
|
+
return this.oldCache.size;
|
|
211
|
+
}
|
|
212
|
+
let oldCacheSize = 0;
|
|
213
|
+
for (const key of this.oldCache.keys()) {
|
|
214
|
+
if (!this.cache.has(key)) {
|
|
215
|
+
oldCacheSize++;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return Math.min(this._size + oldCacheSize, this.maxSize);
|
|
219
|
+
}
|
|
220
|
+
entries() {
|
|
221
|
+
return this.entriesAscending();
|
|
222
|
+
}
|
|
223
|
+
forEach(callbackFunction, thisArgument = this) {
|
|
224
|
+
for (const [key, value] of this.entriesAscending()) {
|
|
225
|
+
callbackFunction.call(thisArgument, value, key, this);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
get [Symbol.toStringTag]() {
|
|
229
|
+
return JSON.stringify([...this.entriesAscending()]);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export {
|
|
233
|
+
QuickLRU as default
|
|
234
|
+
};
|
|
235
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../node_modules/quick-lru/index.js"],"sourcesContent":["export default class QuickLRU extends Map {\n\tconstructor(options = {}) {\n\t\tsuper();\n\n\t\tif (!(options.maxSize && options.maxSize > 0)) {\n\t\t\tthrow new TypeError('`maxSize` must be a number greater than 0');\n\t\t}\n\n\t\tif (typeof options.maxAge === 'number' && options.maxAge === 0) {\n\t\t\tthrow new TypeError('`maxAge` must be a number greater than 0');\n\t\t}\n\n\t\t// TODO: Use private class fields when ESLint supports them.\n\t\tthis.maxSize = options.maxSize;\n\t\tthis.maxAge = options.maxAge || Number.POSITIVE_INFINITY;\n\t\tthis.onEviction = options.onEviction;\n\t\tthis.cache = new Map();\n\t\tthis.oldCache = new Map();\n\t\tthis._size = 0;\n\t}\n\n\t// TODO: Use private class methods when targeting Node.js 16.\n\t_emitEvictions(cache) {\n\t\tif (typeof this.onEviction !== 'function') {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const [key, item] of cache) {\n\t\t\tthis.onEviction(key, item.value);\n\t\t}\n\t}\n\n\t_deleteIfExpired(key, item) {\n\t\tif (typeof item.expiry === 'number' && item.expiry <= Date.now()) {\n\t\t\tif (typeof this.onEviction === 'function') {\n\t\t\t\tthis.onEviction(key, item.value);\n\t\t\t}\n\n\t\t\treturn this.delete(key);\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t_getOrDeleteIfExpired(key, item) {\n\t\tconst deleted = this._deleteIfExpired(key, item);\n\t\tif (deleted === false) {\n\t\t\treturn item.value;\n\t\t}\n\t}\n\n\t_getItemValue(key, item) {\n\t\treturn item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;\n\t}\n\n\t_peek(key, cache) {\n\t\tconst item = cache.get(key);\n\n\t\treturn this._getItemValue(key, item);\n\t}\n\n\t_set(key, value) {\n\t\tthis.cache.set(key, value);\n\t\tthis._size++;\n\n\t\tif (this._size >= this.maxSize) {\n\t\t\tthis._size = 0;\n\t\t\tthis._emitEvictions(this.oldCache);\n\t\t\tthis.oldCache = this.cache;\n\t\t\tthis.cache = new Map();\n\t\t}\n\t}\n\n\t_moveToRecent(key, item) {\n\t\tthis.oldCache.delete(key);\n\t\tthis._set(key, item);\n\t}\n\n\t* _entriesAscending() {\n\t\tfor (const item of this.oldCache) {\n\t\t\tconst [key, value] = item;\n\t\t\tif (!this.cache.has(key)) {\n\t\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\t\tif (deleted === false) {\n\t\t\t\t\tyield item;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const item of this.cache) {\n\t\t\tconst [key, value] = item;\n\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\tif (deleted === false) {\n\t\t\t\tyield item;\n\t\t\t}\n\t\t}\n\t}\n\n\tget(key) {\n\t\tif (this.cache.has(key)) {\n\t\t\tconst item = this.cache.get(key);\n\n\t\t\treturn this._getItemValue(key, item);\n\t\t}\n\n\t\tif (this.oldCache.has(key)) {\n\t\t\tconst item = this.oldCache.get(key);\n\t\t\tif (this._deleteIfExpired(key, item) === false) {\n\t\t\t\tthis._moveToRecent(key, item);\n\t\t\t\treturn item.value;\n\t\t\t}\n\t\t}\n\t}\n\n\tset(key, value, {maxAge = this.maxAge} = {}) {\n\t\tconst expiry =\n\t\t\ttypeof maxAge === 'number' && maxAge !== Number.POSITIVE_INFINITY ?\n\t\t\t\tDate.now() + maxAge :\n\t\t\t\tundefined;\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.set(key, {\n\t\t\t\tvalue,\n\t\t\t\texpiry\n\t\t\t});\n\t\t} else {\n\t\t\tthis._set(key, {value, expiry});\n\t\t}\n\t}\n\n\thas(key) {\n\t\tif (this.cache.has(key)) {\n\t\t\treturn !this._deleteIfExpired(key, this.cache.get(key));\n\t\t}\n\n\t\tif (this.oldCache.has(key)) {\n\t\t\treturn !this._deleteIfExpired(key, this.oldCache.get(key));\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tpeek(key) {\n\t\tif (this.cache.has(key)) {\n\t\t\treturn this._peek(key, this.cache);\n\t\t}\n\n\t\tif (this.oldCache.has(key)) {\n\t\t\treturn this._peek(key, this.oldCache);\n\t\t}\n\t}\n\n\tdelete(key) {\n\t\tconst deleted = this.cache.delete(key);\n\t\tif (deleted) {\n\t\t\tthis._size--;\n\t\t}\n\n\t\treturn this.oldCache.delete(key) || deleted;\n\t}\n\n\tclear() {\n\t\tthis.cache.clear();\n\t\tthis.oldCache.clear();\n\t\tthis._size = 0;\n\t}\n\n\tresize(newSize) {\n\t\tif (!(newSize && newSize > 0)) {\n\t\t\tthrow new TypeError('`maxSize` must be a number greater than 0');\n\t\t}\n\n\t\tconst items = [...this._entriesAscending()];\n\t\tconst removeCount = items.length - newSize;\n\t\tif (removeCount < 0) {\n\t\t\tthis.cache = new Map(items);\n\t\t\tthis.oldCache = new Map();\n\t\t\tthis._size = items.length;\n\t\t} else {\n\t\t\tif (removeCount > 0) {\n\t\t\t\tthis._emitEvictions(items.slice(0, removeCount));\n\t\t\t}\n\n\t\t\tthis.oldCache = new Map(items.slice(removeCount));\n\t\t\tthis.cache = new Map();\n\t\t\tthis._size = 0;\n\t\t}\n\n\t\tthis.maxSize = newSize;\n\t}\n\n\t* keys() {\n\t\tfor (const [key] of this) {\n\t\t\tyield key;\n\t\t}\n\t}\n\n\t* values() {\n\t\tfor (const [, value] of this) {\n\t\t\tyield value;\n\t\t}\n\t}\n\n\t* [Symbol.iterator]() {\n\t\tfor (const item of this.cache) {\n\t\t\tconst [key, value] = item;\n\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\tif (deleted === false) {\n\t\t\t\tyield [key, value.value];\n\t\t\t}\n\t\t}\n\n\t\tfor (const item of this.oldCache) {\n\t\t\tconst [key, value] = item;\n\t\t\tif (!this.cache.has(key)) {\n\t\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\t\tif (deleted === false) {\n\t\t\t\t\tyield [key, value.value];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t* entriesDescending() {\n\t\tlet items = [...this.cache];\n\t\tfor (let i = items.length - 1; i >= 0; --i) {\n\t\t\tconst item = items[i];\n\t\t\tconst [key, value] = item;\n\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\tif (deleted === false) {\n\t\t\t\tyield [key, value.value];\n\t\t\t}\n\t\t}\n\n\t\titems = [...this.oldCache];\n\t\tfor (let i = items.length - 1; i >= 0; --i) {\n\t\t\tconst item = items[i];\n\t\t\tconst [key, value] = item;\n\t\t\tif (!this.cache.has(key)) {\n\t\t\t\tconst deleted = this._deleteIfExpired(key, value);\n\t\t\t\tif (deleted === false) {\n\t\t\t\t\tyield [key, value.value];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t* entriesAscending() {\n\t\tfor (const [key, value] of this._entriesAscending()) {\n\t\t\tyield [key, value.value];\n\t\t}\n\t}\n\n\tget size() {\n\t\tif (!this._size) {\n\t\t\treturn this.oldCache.size;\n\t\t}\n\n\t\tlet oldCacheSize = 0;\n\t\tfor (const key of this.oldCache.keys()) {\n\t\t\tif (!this.cache.has(key)) {\n\t\t\t\toldCacheSize++;\n\t\t\t}\n\t\t}\n\n\t\treturn Math.min(this._size + oldCacheSize, this.maxSize);\n\t}\n\n\tentries() {\n\t\treturn this.entriesAscending();\n\t}\n\n\tforEach(callbackFunction, thisArgument = this) {\n\t\tfor (const [key, value] of this.entriesAscending()) {\n\t\t\tcallbackFunction.call(thisArgument, value, key, this);\n\t\t}\n\t}\n\n\tget [Symbol.toStringTag]() {\n\t\treturn JSON.stringify([...this.entriesAscending()]);\n\t}\n}\n"],"names":[],"mappings":"AAAe,MAAM,iBAAiB,IAAI;AAAA,EACzC,YAAY,UAAU,IAAI;AACzB;AAEA,QAAI,EAAE,QAAQ,WAAW,QAAQ,UAAU,IAAI;AAC9C,YAAM,IAAI,UAAU,2CAA2C;AAAA,IAC/D;AAED,QAAI,OAAO,QAAQ,WAAW,YAAY,QAAQ,WAAW,GAAG;AAC/D,YAAM,IAAI,UAAU,0CAA0C;AAAA,IAC9D;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AC,KAAK,MAAM,IAAI,GAAG,GAAG;AACzB,cAAM,UAAU,KAAK,iBAAiB,KAAK,KAAK;AAChD,YAAI,YAAY,OAAO;AACtB,gBAAM,CAAC,KAAK,MAAM,KAAK;AAAA,QACvB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAED,CAAE,mBAAmB;AACpB,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK,kBAAiB,GAAI;AACpD,YAAM,CAAC,KAAK,MAAM,KAAK;AAAA,IACvB;AAAA,EACD;AAAA,EAED,IAAI,OAAO;AACV,QAAI,CAAC,KAAK,OAAO;AAChB,aAAO,KAAK,SAAS;AAAA,IACrB;AAED,QAAI,eAAe;AACnB,eAAW,OAAO,KAAK,SAAS,KAAI,GAAI;AACvC,UAAI,CAAC,KAAK,MAAM,IAAI,GAAG,GAAG;AACzB;AAAA,MACA;AAAA,IACD;AAED,WAAO,KAAK,IAAI,KAAK,QAAQ,cAAc,KAAK,OAAO;AAAA,EACvD;AAAA,EAED,UAAU;AACT,WAAO,KAAK;EACZ;AAAA,EAED,QAAQ,kBAAkB,eAAe,MAAM;AAC9C,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK,iBAAgB,GAAI;AACnD,uBAAiB,KAAK,cAAc,OAAO,KAAK,IAAI;AAAA,IACpD;AAAA,EACD;AAAA,EAED,KAAK,OAAO,WAAW,IAAI;AAC1B,WAAO,KAAK,UAAU,CAAC,GAAG,KAAK,iBAAkB,CAAA,CAAC;AAAA,EAClD;AACF;","x_google_ignoreList":[0]}
|
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const prismic = require("@prismicio/client");
|
|
4
3
|
const fetch = require("node-fetch");
|
|
5
|
-
|
|
6
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
-
if (e) {
|
|
8
|
-
for (const k in e) {
|
|
9
|
-
if (k !== "default") {
|
|
10
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: () => e[k]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
n.default = e;
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
const prismic__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismic);
|
|
4
|
+
const createClient = require('./../_node_modules/@prismicio/client/dist/createClient.cjs');
|
|
22
5
|
const loadLocaleIDs = async (config) => {
|
|
23
6
|
const localeIDs = new Set(config.localeIDs || []);
|
|
24
7
|
if ("repositoryName" in config && config.fetchFromRepository) {
|
|
25
|
-
const client =
|
|
8
|
+
const client = createClient.createClient(config.repositoryName, {
|
|
26
9
|
accessToken: config.accessToken,
|
|
27
10
|
fetch
|
|
28
11
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadLocaleIDs.cjs","sources":["../../../src/cli/loadLocaleIDs.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport fetch from \"node-fetch\";\n\ntype LoadLocalesConfig =\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t }\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t\t\trepositoryName: string;\n\t\t\taccessToken: string;\n\t\t\tfetchFromRepository?: boolean;\n\t };\n\nexport const loadLocaleIDs = async (\n\tconfig: LoadLocalesConfig,\n): Promise<string[]> => {\n\tconst localeIDs = new Set<string>(config.localeIDs || []);\n\n\tif (\"repositoryName\" in config && config.fetchFromRepository) {\n\t\tconst client = prismic.createClient(config.repositoryName, {\n\t\t\taccessToken: config.accessToken,\n\t\t\tfetch,\n\t\t});\n\n\t\tconst repository = await client.getRepository();\n\n\t\tfor (const language of repository.languages) {\n\t\t\tlocaleIDs.add(language.id);\n\t\t}\n\t}\n\n\treturn [...localeIDs];\n};\n"],"names":["prismic"],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadLocaleIDs.cjs","sources":["../../../src/cli/loadLocaleIDs.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport fetch from \"node-fetch\";\n\ntype LoadLocalesConfig =\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t }\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t\t\trepositoryName: string;\n\t\t\taccessToken: string;\n\t\t\tfetchFromRepository?: boolean;\n\t };\n\nexport const loadLocaleIDs = async (\n\tconfig: LoadLocalesConfig,\n): Promise<string[]> => {\n\tconst localeIDs = new Set<string>(config.localeIDs || []);\n\n\tif (\"repositoryName\" in config && config.fetchFromRepository) {\n\t\tconst client = prismic.createClient(config.repositoryName, {\n\t\t\taccessToken: config.accessToken,\n\t\t\tfetch,\n\t\t});\n\n\t\tconst repository = await client.getRepository();\n\n\t\tfor (const language of repository.languages) {\n\t\t\tlocaleIDs.add(language.id);\n\t\t}\n\t}\n\n\treturn [...localeIDs];\n};\n"],"names":["prismic.createClient"],"mappings":";;;;AAca,MAAA,gBAAgB,OAC5B,WACsB;AACtB,QAAM,YAAY,IAAI,IAAY,OAAO,aAAa,CAAE,CAAA;AAEpD,MAAA,oBAAoB,UAAU,OAAO,qBAAqB;AAC7D,UAAM,SAASA,aAAAA,aAAqB,OAAO,gBAAgB;AAAA,MAC1D,aAAa,OAAO;AAAA,MACpB;AAAA,IAAA,CACA;AAEK,UAAA,aAAa,MAAM,OAAO;AAErB,eAAA,YAAY,WAAW,WAAW;AAClC,gBAAA,IAAI,SAAS,EAAE;AAAA,IACzB;AAAA,EACD;AAEM,SAAA,CAAC,GAAG,SAAS;AACrB;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as prismic from "@prismicio/client";
|
|
2
1
|
import fetch from "node-fetch";
|
|
2
|
+
import { createClient } from './../_node_modules/@prismicio/client/dist/createClient.js';
|
|
3
3
|
const loadLocaleIDs = async (config) => {
|
|
4
4
|
const localeIDs = new Set(config.localeIDs || []);
|
|
5
5
|
if ("repositoryName" in config && config.fetchFromRepository) {
|
|
6
|
-
const client =
|
|
6
|
+
const client = createClient(config.repositoryName, {
|
|
7
7
|
accessToken: config.accessToken,
|
|
8
8
|
fetch
|
|
9
9
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadLocaleIDs.js","sources":["../../../src/cli/loadLocaleIDs.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport fetch from \"node-fetch\";\n\ntype LoadLocalesConfig =\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t }\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t\t\trepositoryName: string;\n\t\t\taccessToken: string;\n\t\t\tfetchFromRepository?: boolean;\n\t };\n\nexport const loadLocaleIDs = async (\n\tconfig: LoadLocalesConfig,\n): Promise<string[]> => {\n\tconst localeIDs = new Set<string>(config.localeIDs || []);\n\n\tif (\"repositoryName\" in config && config.fetchFromRepository) {\n\t\tconst client = prismic.createClient(config.repositoryName, {\n\t\t\taccessToken: config.accessToken,\n\t\t\tfetch,\n\t\t});\n\n\t\tconst repository = await client.getRepository();\n\n\t\tfor (const language of repository.languages) {\n\t\t\tlocaleIDs.add(language.id);\n\t\t}\n\t}\n\n\treturn [...localeIDs];\n};\n"],"names":[],"mappings":";;AAca,MAAA,gBAAgB,OAC5B,WACsB;AACtB,QAAM,YAAY,IAAI,IAAY,OAAO,aAAa,CAAE,CAAA;AAEpD,MAAA,oBAAoB,UAAU,OAAO,qBAAqB;AAC7D,UAAM,
|
|
1
|
+
{"version":3,"file":"loadLocaleIDs.js","sources":["../../../src/cli/loadLocaleIDs.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport fetch from \"node-fetch\";\n\ntype LoadLocalesConfig =\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t }\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t\t\trepositoryName: string;\n\t\t\taccessToken: string;\n\t\t\tfetchFromRepository?: boolean;\n\t };\n\nexport const loadLocaleIDs = async (\n\tconfig: LoadLocalesConfig,\n): Promise<string[]> => {\n\tconst localeIDs = new Set<string>(config.localeIDs || []);\n\n\tif (\"repositoryName\" in config && config.fetchFromRepository) {\n\t\tconst client = prismic.createClient(config.repositoryName, {\n\t\t\taccessToken: config.accessToken,\n\t\t\tfetch,\n\t\t});\n\n\t\tconst repository = await client.getRepository();\n\n\t\tfor (const language of repository.languages) {\n\t\t\tlocaleIDs.add(language.id);\n\t\t}\n\t}\n\n\treturn [...localeIDs];\n};\n"],"names":["prismic.createClient"],"mappings":";;AAca,MAAA,gBAAgB,OAC5B,WACsB;AACtB,QAAM,YAAY,IAAI,IAAY,OAAO,aAAa,CAAE,CAAA;AAEpD,MAAA,oBAAoB,UAAU,OAAO,qBAAqB;AAC7D,UAAM,SAASA,aAAqB,OAAO,gBAAgB;AAAA,MAC1D,aAAa,OAAO;AAAA,MACpB;AAAA,IAAA,CACA;AAEK,UAAA,aAAa,MAAM,OAAO;AAErB,eAAA,YAAY,WAAW,WAAW;AAClC,gBAAA,IAAI,SAAS,EAAE;AAAA,IACzB;AAAA,EACD;AAEM,SAAA,CAAC,GAAG,SAAS;AACrB;"}
|
package/dist/generateTypes.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const commonTags = require("common-tags");
|
|
4
|
-
const
|
|
4
|
+
const index = require('./_node_modules/quick-lru/index.cjs');
|
|
5
5
|
const addLine = require("./lib/addLine.cjs");
|
|
6
6
|
const addSection = require("./lib/addSection.cjs");
|
|
7
7
|
const buildCustomTypeType = require("./lib/buildCustomTypeType.cjs");
|
|
8
8
|
const buildSharedSliceType = require("./lib/buildSharedSliceType.cjs");
|
|
9
9
|
const buildUnion = require("./lib/buildUnion.cjs");
|
|
10
|
-
const cache = new
|
|
10
|
+
const cache = new index({ maxSize: 1e3 });
|
|
11
11
|
function generateTypes(config = {}) {
|
|
12
12
|
var _a, _b, _c, _d, _e;
|
|
13
13
|
const fieldConfigs = config.fieldConfigs || {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.cjs","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { addLine } from \"./lib/addLine\";\nimport { addSection } from \"./lib/addSection\";\nimport { buildCustomTypeType } from \"./lib/buildCustomTypeType\";\nimport { buildSharedSliceType } from \"./lib/buildSharedSliceType\";\nimport { buildUnion } from \"./lib/buildUnion\";\n\nimport { FieldConfigs } from \"./types\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nconst cache = new QuickLRU<string, unknown>({ maxSize: 1000 });\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n\tcache?: boolean;\n};\n\nexport function generateTypes(config: GenerateTypesConfig = {}): string {\n\tconst fieldConfigs = config.fieldConfigs || {};\n\tconst shouldUseCache = config.cache ?? true;\n\n\tlet code = \"\";\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\tlet clientImportName = \"prismic\";\n\n\tcode = addLine(`import type * as prismic from \"${typesProvider}\";`, code);\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tcode = addLine(\n\t\t\t\t`import type * as ${clientImportName} from \"@prismicio/client\";`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\t}\n\n\tcode = addSection(\n\t\t`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`,\n\t\tcode,\n\t);\n\n\tconst contentTypeNames: string[] = [];\n\n\tif (config.customTypeModels) {\n\t\tconst allDocumentTypesTypeNames: string[] = [];\n\n\t\tfor (const model of config.customTypeModels) {\n\t\t\tconst customTypeType = buildCustomTypeType({\n\t\t\t\tmodel,\n\t\t\t\tlocaleIDs: config.localeIDs,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tfor (const auxiliaryType of customTypeType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\n\t\t\t}\n\n\t\t\tcode = addSection(customTypeType.code, code);\n\n\t\t\tallDocumentTypesTypeNames.push(customTypeType.name);\n\n\t\t\tcontentTypeNames.push(customTypeType.name);\n\t\t\tcontentTypeNames.push(customTypeType.dataName);\n\t\t}\n\n\t\tif (config.customTypeModels.length > 0) {\n\t\t\tconst allDocumentTypesUnionName = \"AllDocumentTypes\";\n\t\t\tconst allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);\n\n\t\t\tcode = addSection(\n\t\t\t\t`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`,\n\t\t\t\tcode,\n\t\t\t);\n\n\t\t\tcontentTypeNames.push(allDocumentTypesUnionName);\n\t\t}\n\t}\n\n\tif (config.sharedSliceModels) {\n\t\tfor (const model of config.sharedSliceModels) {\n\t\t\tconst sharedSliceType = buildSharedSliceType({\n\t\t\t\tmodel,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tcode = addSection(sharedSliceType.code, code);\n\n\t\t\tcontentTypeNames.push(sharedSliceType.name);\n\t\t\tcontentTypeNames.push(sharedSliceType.variationUnionName);\n\t\t\tcontentTypeNames.push(...sharedSliceType.variationNames);\n\t\t}\n\t}\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tlet clientModuleCode = \"\";\n\n\t\tif (config.clientIntegration.includeCreateClientInterface) {\n\t\t\tif ((config.customTypeModels?.length || 0) > 0) {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (config.clientIntegration.includeContentNamespace) {\n\t\t\tclientModuleCode = addSection(\n\t\t\t\tsource`\n\t\t\t\t\tnamespace Content {\n\t\t\t\t\t\texport type {\n\t\t\t\t\t\t\t${contentTypeNames.join(\",\\n\")}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t`,\n\t\t\t\tclientModuleCode,\n\t\t\t);\n\t\t}\n\n\t\tcode = addSection(\n\t\t\tsource`\n\t\t\t\tdeclare module \"@prismicio/client\" {\n\t\t\t\t\t${clientModuleCode}\n\t\t\t\t}\n\t\t\t`,\n\t\t\tcode,\n\t\t);\n\t}\n\n\treturn code;\n}\n"],"names":["addLine","addSection","buildCustomTypeType","buildUnion","buildSharedSliceType","source"],"mappings":";;;;;;;;;AAcA,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"generateTypes.cjs","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { addLine } from \"./lib/addLine\";\nimport { addSection } from \"./lib/addSection\";\nimport { buildCustomTypeType } from \"./lib/buildCustomTypeType\";\nimport { buildSharedSliceType } from \"./lib/buildSharedSliceType\";\nimport { buildUnion } from \"./lib/buildUnion\";\n\nimport { FieldConfigs } from \"./types\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nconst cache = new QuickLRU<string, unknown>({ maxSize: 1000 });\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n\tcache?: boolean;\n};\n\nexport function generateTypes(config: GenerateTypesConfig = {}): string {\n\tconst fieldConfigs = config.fieldConfigs || {};\n\tconst shouldUseCache = config.cache ?? true;\n\n\tlet code = \"\";\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\tlet clientImportName = \"prismic\";\n\n\tcode = addLine(`import type * as prismic from \"${typesProvider}\";`, code);\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tcode = addLine(\n\t\t\t\t`import type * as ${clientImportName} from \"@prismicio/client\";`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\t}\n\n\tcode = addSection(\n\t\t`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`,\n\t\tcode,\n\t);\n\n\tconst contentTypeNames: string[] = [];\n\n\tif (config.customTypeModels) {\n\t\tconst allDocumentTypesTypeNames: string[] = [];\n\n\t\tfor (const model of config.customTypeModels) {\n\t\t\tconst customTypeType = buildCustomTypeType({\n\t\t\t\tmodel,\n\t\t\t\tlocaleIDs: config.localeIDs,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tfor (const auxiliaryType of customTypeType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\n\t\t\t}\n\n\t\t\tcode = addSection(customTypeType.code, code);\n\n\t\t\tallDocumentTypesTypeNames.push(customTypeType.name);\n\n\t\t\tcontentTypeNames.push(customTypeType.name);\n\t\t\tcontentTypeNames.push(customTypeType.dataName);\n\t\t}\n\n\t\tif (config.customTypeModels.length > 0) {\n\t\t\tconst allDocumentTypesUnionName = \"AllDocumentTypes\";\n\t\t\tconst allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);\n\n\t\t\tcode = addSection(\n\t\t\t\t`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`,\n\t\t\t\tcode,\n\t\t\t);\n\n\t\t\tcontentTypeNames.push(allDocumentTypesUnionName);\n\t\t}\n\t}\n\n\tif (config.sharedSliceModels) {\n\t\tfor (const model of config.sharedSliceModels) {\n\t\t\tconst sharedSliceType = buildSharedSliceType({\n\t\t\t\tmodel,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tcode = addSection(sharedSliceType.code, code);\n\n\t\t\tcontentTypeNames.push(sharedSliceType.name);\n\t\t\tcontentTypeNames.push(sharedSliceType.variationUnionName);\n\t\t\tcontentTypeNames.push(...sharedSliceType.variationNames);\n\t\t}\n\t}\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tlet clientModuleCode = \"\";\n\n\t\tif (config.clientIntegration.includeCreateClientInterface) {\n\t\t\tif ((config.customTypeModels?.length || 0) > 0) {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (config.clientIntegration.includeContentNamespace) {\n\t\t\tclientModuleCode = addSection(\n\t\t\t\tsource`\n\t\t\t\t\tnamespace Content {\n\t\t\t\t\t\texport type {\n\t\t\t\t\t\t\t${contentTypeNames.join(\",\\n\")}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t`,\n\t\t\t\tclientModuleCode,\n\t\t\t);\n\t\t}\n\n\t\tcode = addSection(\n\t\t\tsource`\n\t\t\t\tdeclare module \"@prismicio/client\" {\n\t\t\t\t\t${clientModuleCode}\n\t\t\t\t}\n\t\t\t`,\n\t\t\tcode,\n\t\t);\n\t}\n\n\treturn code;\n}\n"],"names":["QuickLRU","addLine","addSection","buildCustomTypeType","buildUnion","buildSharedSliceType","source"],"mappings":";;;;;;;;;AAcA,MAAM,QAAQ,IAAIA,MAA0B,EAAE,SAAS,IAAM,CAAA;AAe7C,SAAA,cAAc,SAA8B,IAAE;;AACvD,QAAA,eAAe,OAAO,gBAAgB;AACtC,QAAA,iBAAiB,OAAO,SAAS;AAEvC,MAAI,OAAO;AAEL,QAAA,gBAAgB,OAAO,iBAAiB;AAC9C,MAAI,mBAAmB;AAEhB,SAAAC,QAAA,QAAQ,kCAAkC,mBAAmB,IAAI;AAExE,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,kBAAkB,qBAAqB;AACvB,yBAAA;AAIZ,aAAAA,QAAA,QACN,oB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B,QAAA,OAAO,kBAAkB,8BAA8B;AAC1D,aAAK,YAAO,qBAAP,mBAAyB,WAAU,KAAK,GAAG;AAC/C,2BAAmBA,WAClB,WAAA;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAAA,OAEX;AACN,2BAAmBA,WAClB,WAAA;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAEjB;AAAA,IACD;AAEG,QAAA,OAAO,kBAAkB,yBAAyB;AACrD,yBAAmBA,WAClB,WAAAI;;;SAGK,iBAAiB,KAAK,KAAK;AAAA;AAAA;AAAA,OAIhC,gBAAgB;AAAA,IAEjB;AAED,WAAOJ,WACN,WAAAI;;OAEI;AAAA;AAAA,MAGJ,IAAI;AAAA,EAEL;AAEM,SAAA;AACR;;"}
|
package/dist/generateTypes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { source } from "common-tags";
|
|
2
|
-
import QuickLRU from
|
|
2
|
+
import QuickLRU from './_node_modules/quick-lru/index.js';
|
|
3
3
|
import { addLine } from "./lib/addLine.js";
|
|
4
4
|
import { addSection } from "./lib/addSection.js";
|
|
5
5
|
import { buildCustomTypeType } from "./lib/buildCustomTypeType.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeDataType.cjs","sources":["../../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n}\n"],"names":["buildTypeName","getHumanReadableModelName","buildFieldProperties","source"],"mappings":";;;;;;AAqBM,SAAU,wBACf,MAAiC;AAEjC,MAAI,OAAO;AACX,QAAM,iBAAkC,CAAA;AAExC,QAAM,OAAOA,cAAAA,cAAc,KAAK,MAAM,IAAI,YAAY,MAAM;AAC5D,QAAM,oBAAoBC,0BAAAA,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,MAAI,kBAAkB;AAEX,aAAA,WAAW,KAAK,MAAM,MAAM;AAChC,UAAA,EAAE,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,KAAK,OAAO;AAExD,UAAM,qBAAqBC,qBAAAA,qBAAqB;AAAA,MAC/C;AAAA,MACA,cAAc,KAAK;AAAA,MACnB,MAAM;AAAA,QACL;AAAA,UACC,MAAM,KAAK,MAAM;AAAA,UACjB,OAAO,KAAK;AAAA,QACZ;AAAA,MACD;AAAA,MACD;AAAA,IAAA,CACA;AAED,uBAAmB,mBAAmB;AAEvB,mBAAA,KAAK,GAAG,mBAAmB,cAAc;AAAA,EACxD;AAED,MAAI,iBAAiB;AACb,WAAAC,WAAAA;AAAAA;AAAAA,oBAEW;AAAA;AAAA,eAEL;AAAA,MACT;AAAA;AAAA;AAAA,EAAA,OAGE;AACN,WAAO,aAAa;AAAA,EACpB;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;;"}
|
|
1
|
+
{"version":3,"file":"buildCustomTypeDataType.cjs","sources":["../../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n}\n"],"names":["buildTypeName","getHumanReadableModelName","buildFieldProperties","source"],"mappings":";;;;;;AAqBM,SAAU,wBACf,MAAiC;AAEjC,MAAI,OAAO;AACX,QAAM,iBAAkC,CAAA;AAExC,QAAM,OAAOA,cAAAA,cAAc,KAAK,MAAM,IAAI,YAAY,MAAM;AAC5D,QAAM,oBAAoBC,0BAAAA,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,MAAI,kBAAkB;AAEX,aAAA,WAAW,KAAK,MAAM,MAAM;AAChC,UAAA,EAAE,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,KAAK,OAAO;AAExD,UAAM,qBAAqBC,qBAAAA,qBAAqB;AAAA,MAC/C;AAAA,MACA,cAAc,KAAK;AAAA,MACnB,MAAM;AAAA,QACL;AAAA,UACC,MAAM,KAAK,MAAM;AAAA,UACjB,OAAO,KAAK;AAAA,QACZ;AAAA,MACD;AAAA,MACD;AAAA,IAAA,CACA;AAED,uBAAmB,mBAAmB;AAEvB,mBAAA,KAAK,GAAG,mBAAmB,cAAc;AAAA,EACxD;AAED,MAAI,iBAAiB;AACb,WAAAC,WAAAA;AAAAA;AAAAA,oBAEW;AAAA;AAAA,eAEL;AAAA,MACT;AAAA;AAAA;AAAA,EAAA,OAGE;AACN,WAAO,aAAa;AAAA,EACpB;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;;"}
|