@collective-intelligence/external-apps-server-sdk 0.2.4 → 0.2.6

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.
@@ -1 +1 @@
1
- import*as Effect2 from"effect/Effect";import*as Layer from"effect/Layer";import*as NextCache from"next/cache.js";import*as Context from"effect/Context";import*as Effect from"effect/Effect";import*as Option from"effect/Option";import{realtimeTopicKey}from"@collective-intelligence/external-apps-client-sdk";import*as Brand from"effect/Brand";import{createHash}from"node:crypto";var brand=Brand.nominal();var hashed=(kind,key)=>brand(`ci:${kind}:${createHash("sha256").update(key).digest("base64url")}`);var schema=(fqn)=>hashed("s",fqn);var ciTag={all:brand("ci:all"),entity:(fqn,id)=>hashed("e",JSON.stringify([fqn,id])),schema,topic:(topic)=>topic.filter===undefined?schema(topic.schema):hashed("t",realtimeTopicKey(topic))};var noInvalidation={invalidate:()=>Effect.void};var CacheInvalidation=Context.Reference("@collective-intelligence/external-apps-server-sdk/CacheInvalidation",{defaultValue:()=>noInvalidation});var invalidateRecord=Effect.fnUntraced(function*invalidateRecord(record){const invalidation=yield*CacheInvalidation;if(invalidation===noInvalidation){return}const fqn=yield*record.fqn;if(Option.isSome(fqn)){const tags=[ciTag.entity(fqn.value,record.id),ciTag.schema(fqn.value)];yield*invalidation.invalidate(tags).pipe(Effect.catchDefect((defect)=>Effect.logWarning("The cache invalidation failed; the write keeps the record that CI confirmed",defect).pipe(Effect.annotateLogs({tags:tags.join(" ")}))))}});var nextInvalidate=(tags)=>{for(const tag of tags){NextCache.revalidateTag(tag,{expire:0})}};var layerNext=Layer.succeed(CacheInvalidation,{invalidate:(tags)=>Effect2.sync(()=>{nextInvalidate(tags)})});var CacheInvalidation2={layerNext};export{CacheInvalidation2 as CacheInvalidation};
1
+ import*as Effect2 from"effect/Effect";import*as Layer from"effect/Layer";import*as NextCache from"next/cache.js";import*as Context from"effect/Context";import*as Effect from"effect/Effect";import*as Option from"effect/Option";import{realtimeTopicKey}from"@collective-intelligence/external-apps-client-sdk";import*as Brand from"effect/Brand";import{createHash}from"node:crypto";var brand=Brand.nominal();var hashed=(kind,key)=>brand(`ci:${kind}:${createHash("sha256").update(key).digest("base64url")}`);var schema=(fqn)=>hashed("s",fqn);var list=(fqn)=>hashed("l",fqn);var ciTag={all:brand("ci:all"),entity:(fqn,id)=>hashed("e",JSON.stringify([fqn,id])),list,schema,topic:(topic)=>topic.filter===undefined?list(topic.schema):hashed("t",realtimeTopicKey(topic))};var noInvalidation={invalidate:()=>Effect.void};var CacheInvalidation=Context.Reference("@collective-intelligence/external-apps-server-sdk/CacheInvalidation",{defaultValue:()=>noInvalidation});var invalidateRecord=Effect.fnUntraced(function*invalidateRecord(record){const invalidation=yield*CacheInvalidation;if(invalidation===noInvalidation){return}const fqn=yield*record.fqn;if(Option.isSome(fqn)){const tags=[ciTag.entity(fqn.value,record.id),ciTag.list(fqn.value)];yield*invalidation.invalidate(tags).pipe(Effect.catchDefect((defect)=>Effect.logWarning("The cache invalidation failed; the write keeps the record that CI confirmed",defect).pipe(Effect.annotateLogs({tags:tags.join(" ")}))))}});var nextInvalidate=(tags)=>{for(const tag of tags){NextCache.revalidateTag(tag,{expire:0})}};var layerNext=Layer.succeed(CacheInvalidation,{invalidate:(tags)=>Effect2.sync(()=>{nextInvalidate(tags)})});var CacheInvalidation2={layerNext};export{CacheInvalidation2 as CacheInvalidation};