@contello/store 1.0.1 → 1.0.2
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/index.cjs +0 -30
- package/dist/index.d.cts +1 -24
- package/dist/index.d.ts +1 -24
- package/dist/index.js +0 -28
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -30,8 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
ComponentMapper: () => ComponentMapper,
|
|
34
|
-
NO_MATCH: () => NO_MATCH,
|
|
35
33
|
Store: () => Store,
|
|
36
34
|
createStore: () => createStore
|
|
37
35
|
});
|
|
@@ -1265,36 +1263,8 @@ var Store = class {
|
|
|
1265
1263
|
function createStore(options) {
|
|
1266
1264
|
return new Store(options);
|
|
1267
1265
|
}
|
|
1268
|
-
|
|
1269
|
-
// src/component-mapper.ts
|
|
1270
|
-
var NO_MATCH = /* @__PURE__ */ Symbol("@contello/store/no-match");
|
|
1271
|
-
var ComponentMapper = class {
|
|
1272
|
-
constructor(visitors) {
|
|
1273
|
-
this.visitors = visitors;
|
|
1274
|
-
}
|
|
1275
|
-
map(flat, refs) {
|
|
1276
|
-
const flatMap = new Map((flat ?? []).map((c) => [c._flatId, c]));
|
|
1277
|
-
return this.resolveRefs(flatMap, refs);
|
|
1278
|
-
}
|
|
1279
|
-
resolveRefs(flatMap, refs) {
|
|
1280
|
-
return (refs ?? []).flatMap((ref) => {
|
|
1281
|
-
if (!ref._flatId) return [];
|
|
1282
|
-
const component = flatMap.get(ref._flatId);
|
|
1283
|
-
if (!component) return [];
|
|
1284
|
-
const visitor = this.visitors[component.__typename];
|
|
1285
|
-
if (!visitor) {
|
|
1286
|
-
this.visitors[NO_MATCH]?.(component);
|
|
1287
|
-
return [];
|
|
1288
|
-
}
|
|
1289
|
-
const result = visitor(component, (nestedRefs) => this.resolveRefs(flatMap, nestedRefs));
|
|
1290
|
-
return result ? [result] : [];
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
1266
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1295
1267
|
0 && (module.exports = {
|
|
1296
|
-
ComponentMapper,
|
|
1297
|
-
NO_MATCH,
|
|
1298
1268
|
Store,
|
|
1299
1269
|
createStore
|
|
1300
1270
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -327,27 +327,4 @@ declare class Store<TOps extends OperationMap | undefined = undefined, TModels e
|
|
|
327
327
|
}
|
|
328
328
|
declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string>(options: CreateStoreOptions<TOps, TModels>): Store<TOps, TModels>;
|
|
329
329
|
|
|
330
|
-
|
|
331
|
-
type FlatRef = {
|
|
332
|
-
_flatId?: string | undefined;
|
|
333
|
-
};
|
|
334
|
-
type MapFn<TResult> = (refs: readonly FlatRef[] | undefined) => TResult[];
|
|
335
|
-
type Visitors<TFlat extends {
|
|
336
|
-
__typename: string;
|
|
337
|
-
} & FlatRef, TResult> = {
|
|
338
|
-
[K in TFlat['__typename']]?: (component: Extract<TFlat, {
|
|
339
|
-
__typename: K;
|
|
340
|
-
}>, map: MapFn<TResult>) => TResult | undefined | false | 0 | '';
|
|
341
|
-
} & {
|
|
342
|
-
[NO_MATCH]?: (component: TFlat) => void;
|
|
343
|
-
};
|
|
344
|
-
declare class ComponentMapper<TFlat extends {
|
|
345
|
-
__typename: string;
|
|
346
|
-
} & FlatRef, TResult> {
|
|
347
|
-
private readonly visitors;
|
|
348
|
-
constructor(visitors: Visitors<TFlat, TResult>);
|
|
349
|
-
map(flat: readonly TFlat[] | undefined, refs: readonly FlatRef[] | undefined): TResult[];
|
|
350
|
-
private resolveRefs;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
export { type AssetCollectionOptions, type Assets, type CacheOptions, type Collection, type CollectionDef, type CollectionSync, type CollectionSyncDef, ComponentMapper, type CreateStoreOptions, type Fetchable, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyCacheOptions, type LazyCollection, type LazyCollectionDef, type MapperContext, NO_MATCH, type RouteCollectionOptions, type Routes, type Singleton, type SingletonDef, type SingletonSync, type SingletonSyncDef, Store, type StoreAsset, type StoreFile, type StoreFileMetadata, type StoreRoute, type StoreRouteCustomHeader, type SyncCacheOptions, type UpdateBatch, type UpdateEvent, type UpdateEventFor, type UpdateMutationType, createStore };
|
|
330
|
+
export { type AssetCollectionOptions, type Assets, type CacheOptions, type Collection, type CollectionDef, type CollectionSync, type CollectionSyncDef, type CreateStoreOptions, type Fetchable, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyCacheOptions, type LazyCollection, type LazyCollectionDef, type MapperContext, type RouteCollectionOptions, type Routes, type Singleton, type SingletonDef, type SingletonSync, type SingletonSyncDef, Store, type StoreAsset, type StoreFile, type StoreFileMetadata, type StoreRoute, type StoreRouteCustomHeader, type SyncCacheOptions, type UpdateBatch, type UpdateEvent, type UpdateEventFor, type UpdateMutationType, createStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -327,27 +327,4 @@ declare class Store<TOps extends OperationMap | undefined = undefined, TModels e
|
|
|
327
327
|
}
|
|
328
328
|
declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string>(options: CreateStoreOptions<TOps, TModels>): Store<TOps, TModels>;
|
|
329
329
|
|
|
330
|
-
|
|
331
|
-
type FlatRef = {
|
|
332
|
-
_flatId?: string | undefined;
|
|
333
|
-
};
|
|
334
|
-
type MapFn<TResult> = (refs: readonly FlatRef[] | undefined) => TResult[];
|
|
335
|
-
type Visitors<TFlat extends {
|
|
336
|
-
__typename: string;
|
|
337
|
-
} & FlatRef, TResult> = {
|
|
338
|
-
[K in TFlat['__typename']]?: (component: Extract<TFlat, {
|
|
339
|
-
__typename: K;
|
|
340
|
-
}>, map: MapFn<TResult>) => TResult | undefined | false | 0 | '';
|
|
341
|
-
} & {
|
|
342
|
-
[NO_MATCH]?: (component: TFlat) => void;
|
|
343
|
-
};
|
|
344
|
-
declare class ComponentMapper<TFlat extends {
|
|
345
|
-
__typename: string;
|
|
346
|
-
} & FlatRef, TResult> {
|
|
347
|
-
private readonly visitors;
|
|
348
|
-
constructor(visitors: Visitors<TFlat, TResult>);
|
|
349
|
-
map(flat: readonly TFlat[] | undefined, refs: readonly FlatRef[] | undefined): TResult[];
|
|
350
|
-
private resolveRefs;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
export { type AssetCollectionOptions, type Assets, type CacheOptions, type Collection, type CollectionDef, type CollectionSync, type CollectionSyncDef, ComponentMapper, type CreateStoreOptions, type Fetchable, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyCacheOptions, type LazyCollection, type LazyCollectionDef, type MapperContext, NO_MATCH, type RouteCollectionOptions, type Routes, type Singleton, type SingletonDef, type SingletonSync, type SingletonSyncDef, Store, type StoreAsset, type StoreFile, type StoreFileMetadata, type StoreRoute, type StoreRouteCustomHeader, type SyncCacheOptions, type UpdateBatch, type UpdateEvent, type UpdateEventFor, type UpdateMutationType, createStore };
|
|
330
|
+
export { type AssetCollectionOptions, type Assets, type CacheOptions, type Collection, type CollectionDef, type CollectionSync, type CollectionSyncDef, type CreateStoreOptions, type Fetchable, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyCacheOptions, type LazyCollection, type LazyCollectionDef, type MapperContext, type RouteCollectionOptions, type Routes, type Singleton, type SingletonDef, type SingletonSync, type SingletonSyncDef, Store, type StoreAsset, type StoreFile, type StoreFileMetadata, type StoreRoute, type StoreRouteCustomHeader, type SyncCacheOptions, type UpdateBatch, type UpdateEvent, type UpdateEventFor, type UpdateMutationType, createStore };
|
package/dist/index.js
CHANGED
|
@@ -1226,35 +1226,7 @@ var Store = class {
|
|
|
1226
1226
|
function createStore(options) {
|
|
1227
1227
|
return new Store(options);
|
|
1228
1228
|
}
|
|
1229
|
-
|
|
1230
|
-
// src/component-mapper.ts
|
|
1231
|
-
var NO_MATCH = /* @__PURE__ */ Symbol("@contello/store/no-match");
|
|
1232
|
-
var ComponentMapper = class {
|
|
1233
|
-
constructor(visitors) {
|
|
1234
|
-
this.visitors = visitors;
|
|
1235
|
-
}
|
|
1236
|
-
map(flat, refs) {
|
|
1237
|
-
const flatMap = new Map((flat ?? []).map((c) => [c._flatId, c]));
|
|
1238
|
-
return this.resolveRefs(flatMap, refs);
|
|
1239
|
-
}
|
|
1240
|
-
resolveRefs(flatMap, refs) {
|
|
1241
|
-
return (refs ?? []).flatMap((ref) => {
|
|
1242
|
-
if (!ref._flatId) return [];
|
|
1243
|
-
const component = flatMap.get(ref._flatId);
|
|
1244
|
-
if (!component) return [];
|
|
1245
|
-
const visitor = this.visitors[component.__typename];
|
|
1246
|
-
if (!visitor) {
|
|
1247
|
-
this.visitors[NO_MATCH]?.(component);
|
|
1248
|
-
return [];
|
|
1249
|
-
}
|
|
1250
|
-
const result = visitor(component, (nestedRefs) => this.resolveRefs(flatMap, nestedRefs));
|
|
1251
|
-
return result ? [result] : [];
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
};
|
|
1255
1229
|
export {
|
|
1256
|
-
ComponentMapper,
|
|
1257
|
-
NO_MATCH,
|
|
1258
1230
|
Store,
|
|
1259
1231
|
createStore
|
|
1260
1232
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contello/store",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Framework-agnostic store for Contello CMS with reactive collections and automatic dependency tracking",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"rxjs": "^7.0.0"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@contello/client": "workspace
|
|
25
|
+
"@contello/client": "workspace:^",
|
|
26
26
|
"backoff-rxjs": "^7.0.0",
|
|
27
27
|
"lru-cache": "^11.2.7"
|
|
28
28
|
},
|