@flopflip/cache 0.0.0-canary-20240411092321 → 14.0.0

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.
@@ -0,0 +1,10 @@
1
+ import { type TAdapter, type TAdapterIdentifiers, type TCacheIdentifiers, type TFlags } from '@flopflip/types';
2
+ declare function getCachePrefix(adapterIdentifiers: TAdapterIdentifiers): string;
3
+ declare function getCache(cacheIdentifier: TCacheIdentifiers, adapterIdentifiers: TAdapterIdentifiers, cacheKey?: string): Promise<{
4
+ set(flags: TFlags): any;
5
+ get(): any;
6
+ unset(): any;
7
+ }>;
8
+ declare function getCachedFlags(cacheIdentifier: TCacheIdentifiers, adapterIdentifiers: TAdapterIdentifiers): TFlags;
9
+ declare function getAllCachedFlags(adapter: TAdapter, cacheIdentifier?: TCacheIdentifiers): TFlags;
10
+ export { getAllCachedFlags, getCache, getCachedFlags, getCachePrefix };
@@ -0,0 +1,3 @@
1
+ declare const version = "__@FLOPFLIP/VERSION_OF_RELEASE__";
2
+ export { version };
3
+ export { getAllCachedFlags, getCache, getCachedFlags } from "./cache.js";
@@ -0,0 +1,3 @@
1
+ declare const version = "__@FLOPFLIP/VERSION_OF_RELEASE__";
2
+ export { getAllCachedFlags, getCache, getCachedFlags } from "./cache/index.js";
3
+ export { version };
@@ -1,2 +1,2 @@
1
- export * from "../src/index";
2
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmxvcGZsaXAtY2FjaGUuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
1
+ export * from "./declarations/src/index";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmxvcGZsaXAtY2FjaGUuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
@@ -0,0 +1,160 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var types = require('@flopflip/types');
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ function toPrimitive(t, r) {
26
+ if ("object" != typeof t || !t) return t;
27
+ var e = t[Symbol.toPrimitive];
28
+ if (void 0 !== e) {
29
+ var i = e.call(t, r || "default");
30
+ if ("object" != typeof i) return i;
31
+ throw new TypeError("@@toPrimitive must return a primitive value.");
32
+ }
33
+ return ("string" === r ? String : Number)(t);
34
+ }
35
+
36
+ function toPropertyKey(t) {
37
+ var i = toPrimitive(t, "string");
38
+ return "symbol" == typeof i ? i : i + "";
39
+ }
40
+
41
+ function _defineProperty(obj, key, value) {
42
+ key = toPropertyKey(key);
43
+ if (key in obj) {
44
+ Object.defineProperty(obj, key, {
45
+ value: value,
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true
49
+ });
50
+ } else {
51
+ obj[key] = value;
52
+ }
53
+ return obj;
54
+ }
55
+
56
+ function ownKeys(e, r) {
57
+ var t = Object.keys(e);
58
+ if (Object.getOwnPropertySymbols) {
59
+ var o = Object.getOwnPropertySymbols(e);
60
+ r && (o = o.filter(function (r) {
61
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
62
+ })), t.push.apply(t, o);
63
+ }
64
+ return t;
65
+ }
66
+ function _objectSpread2(e) {
67
+ for (var r = 1; r < arguments.length; r++) {
68
+ var t = null != arguments[r] ? arguments[r] : {};
69
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
70
+ _defineProperty(e, r, t[r]);
71
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
72
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
73
+ });
74
+ }
75
+ return e;
76
+ }
77
+
78
+ const FLAGS_CACHE_KEY = 'flags';
79
+ const FLAGS_REFERENCE_CACHE_KEY = 'flags-reference';
80
+ function getCachePrefix(adapterIdentifiers) {
81
+ return "@flopflip/".concat(adapterIdentifiers, "-adapter");
82
+ }
83
+ async function importCache(cacheIdentifier) {
84
+ let cacheModule;
85
+ switch (cacheIdentifier) {
86
+ case types.cacheIdentifiers.local:
87
+ {
88
+ cacheModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/localstorage-cache')); });
89
+ break;
90
+ }
91
+ case types.cacheIdentifiers.session:
92
+ {
93
+ cacheModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/sessionstorage-cache')); });
94
+ break;
95
+ }
96
+ }
97
+ return cacheModule;
98
+ }
99
+ async function getCache(cacheIdentifier, adapterIdentifiers, cacheKey) {
100
+ const cacheModule = await importCache(cacheIdentifier);
101
+ const CACHE_PREFIX = getCachePrefix(adapterIdentifiers);
102
+ const createCache = cacheModule.default;
103
+ const flagsCachePrefix = [CACHE_PREFIX, cacheKey].filter(Boolean).join('/');
104
+ const flagsCache = createCache({
105
+ prefix: flagsCachePrefix
106
+ });
107
+ const referenceCache = createCache({
108
+ prefix: CACHE_PREFIX
109
+ });
110
+ return {
111
+ set(flags) {
112
+ const haveFlagsBeenWritten = flagsCache.set(FLAGS_CACHE_KEY, flags);
113
+ if (haveFlagsBeenWritten) {
114
+ referenceCache.set(FLAGS_REFERENCE_CACHE_KEY, [flagsCachePrefix, FLAGS_CACHE_KEY].join('/'));
115
+ }
116
+ return haveFlagsBeenWritten;
117
+ },
118
+ get() {
119
+ return flagsCache.get(FLAGS_CACHE_KEY);
120
+ },
121
+ unset() {
122
+ referenceCache.unset(FLAGS_REFERENCE_CACHE_KEY);
123
+ return flagsCache.unset(FLAGS_CACHE_KEY);
124
+ }
125
+ };
126
+ }
127
+ function getCachedFlags(cacheIdentifier, adapterIdentifiers) {
128
+ const CACHE_PREFIX = getCachePrefix(adapterIdentifiers);
129
+ const cacheModule = cacheIdentifier === types.cacheIdentifiers.local ? localStorage : sessionStorage;
130
+ const flagReferenceKey = [CACHE_PREFIX, FLAGS_REFERENCE_CACHE_KEY].join('/');
131
+ const referenceToCachedFlags = cacheModule.getItem(flagReferenceKey);
132
+ if (referenceToCachedFlags) {
133
+ try {
134
+ const cacheKey = JSON.parse(referenceToCachedFlags);
135
+ const cachedFlags = cacheModule.getItem(cacheKey);
136
+ if (cacheKey && cachedFlags) {
137
+ return JSON.parse(cachedFlags);
138
+ }
139
+ } catch (error) {
140
+ console.warn("@flopflip/cache: Failed to parse cached flags from ".concat(cacheIdentifier, "."));
141
+ }
142
+ }
143
+ return {};
144
+ }
145
+ function getAllCachedFlags(adapter, cacheIdentifier) {
146
+ if (!cacheIdentifier) {
147
+ return {};
148
+ }
149
+ if (adapter.effectIds) {
150
+ return adapter.effectIds.reduce((defaultFlags, effectId) => _objectSpread2(_objectSpread2({}, defaultFlags), getCachedFlags(cacheIdentifier, effectId)), {});
151
+ }
152
+ return getCachedFlags(cacheIdentifier, adapter.id);
153
+ }
154
+
155
+ const version = "14.0.0";
156
+
157
+ exports.getAllCachedFlags = getAllCachedFlags;
158
+ exports.getCache = getCache;
159
+ exports.getCachedFlags = getCachedFlags;
160
+ exports.version = version;
@@ -1,16 +1,7 @@
1
- "use strict";
2
- // this file might look strange and you might be wondering what it's for
3
- // it's lets you import your source files by importing this entrypoint
4
- // as you would import it if it was built with preconstruct build
5
- // this file is slightly different to some others though
6
- // it has a require hook which compiles your code with Babel
7
- // this means that you don't have to set up @babel/register or anything like that
8
- // but you can still require this module and it'll be compiled
1
+ 'use strict';
9
2
 
10
- // this bit of code imports the require hook and registers it
11
- let unregister = require("../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../..", "..");
12
-
13
- // this re-exports the source file
14
- module.exports = require("../src/index.ts");
15
-
16
- unregister();
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./flopflip-cache.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./flopflip-cache.cjs.dev.js");
7
+ }
@@ -0,0 +1,160 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var types = require('@flopflip/types');
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ function toPrimitive(t, r) {
26
+ if ("object" != typeof t || !t) return t;
27
+ var e = t[Symbol.toPrimitive];
28
+ if (void 0 !== e) {
29
+ var i = e.call(t, r || "default");
30
+ if ("object" != typeof i) return i;
31
+ throw new TypeError("@@toPrimitive must return a primitive value.");
32
+ }
33
+ return ("string" === r ? String : Number)(t);
34
+ }
35
+
36
+ function toPropertyKey(t) {
37
+ var i = toPrimitive(t, "string");
38
+ return "symbol" == typeof i ? i : i + "";
39
+ }
40
+
41
+ function _defineProperty(obj, key, value) {
42
+ key = toPropertyKey(key);
43
+ if (key in obj) {
44
+ Object.defineProperty(obj, key, {
45
+ value: value,
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true
49
+ });
50
+ } else {
51
+ obj[key] = value;
52
+ }
53
+ return obj;
54
+ }
55
+
56
+ function ownKeys(e, r) {
57
+ var t = Object.keys(e);
58
+ if (Object.getOwnPropertySymbols) {
59
+ var o = Object.getOwnPropertySymbols(e);
60
+ r && (o = o.filter(function (r) {
61
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
62
+ })), t.push.apply(t, o);
63
+ }
64
+ return t;
65
+ }
66
+ function _objectSpread2(e) {
67
+ for (var r = 1; r < arguments.length; r++) {
68
+ var t = null != arguments[r] ? arguments[r] : {};
69
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
70
+ _defineProperty(e, r, t[r]);
71
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
72
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
73
+ });
74
+ }
75
+ return e;
76
+ }
77
+
78
+ const FLAGS_CACHE_KEY = 'flags';
79
+ const FLAGS_REFERENCE_CACHE_KEY = 'flags-reference';
80
+ function getCachePrefix(adapterIdentifiers) {
81
+ return "@flopflip/".concat(adapterIdentifiers, "-adapter");
82
+ }
83
+ async function importCache(cacheIdentifier) {
84
+ let cacheModule;
85
+ switch (cacheIdentifier) {
86
+ case types.cacheIdentifiers.local:
87
+ {
88
+ cacheModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/localstorage-cache')); });
89
+ break;
90
+ }
91
+ case types.cacheIdentifiers.session:
92
+ {
93
+ cacheModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/sessionstorage-cache')); });
94
+ break;
95
+ }
96
+ }
97
+ return cacheModule;
98
+ }
99
+ async function getCache(cacheIdentifier, adapterIdentifiers, cacheKey) {
100
+ const cacheModule = await importCache(cacheIdentifier);
101
+ const CACHE_PREFIX = getCachePrefix(adapterIdentifiers);
102
+ const createCache = cacheModule.default;
103
+ const flagsCachePrefix = [CACHE_PREFIX, cacheKey].filter(Boolean).join('/');
104
+ const flagsCache = createCache({
105
+ prefix: flagsCachePrefix
106
+ });
107
+ const referenceCache = createCache({
108
+ prefix: CACHE_PREFIX
109
+ });
110
+ return {
111
+ set(flags) {
112
+ const haveFlagsBeenWritten = flagsCache.set(FLAGS_CACHE_KEY, flags);
113
+ if (haveFlagsBeenWritten) {
114
+ referenceCache.set(FLAGS_REFERENCE_CACHE_KEY, [flagsCachePrefix, FLAGS_CACHE_KEY].join('/'));
115
+ }
116
+ return haveFlagsBeenWritten;
117
+ },
118
+ get() {
119
+ return flagsCache.get(FLAGS_CACHE_KEY);
120
+ },
121
+ unset() {
122
+ referenceCache.unset(FLAGS_REFERENCE_CACHE_KEY);
123
+ return flagsCache.unset(FLAGS_CACHE_KEY);
124
+ }
125
+ };
126
+ }
127
+ function getCachedFlags(cacheIdentifier, adapterIdentifiers) {
128
+ const CACHE_PREFIX = getCachePrefix(adapterIdentifiers);
129
+ const cacheModule = cacheIdentifier === types.cacheIdentifiers.local ? localStorage : sessionStorage;
130
+ const flagReferenceKey = [CACHE_PREFIX, FLAGS_REFERENCE_CACHE_KEY].join('/');
131
+ const referenceToCachedFlags = cacheModule.getItem(flagReferenceKey);
132
+ if (referenceToCachedFlags) {
133
+ try {
134
+ const cacheKey = JSON.parse(referenceToCachedFlags);
135
+ const cachedFlags = cacheModule.getItem(cacheKey);
136
+ if (cacheKey && cachedFlags) {
137
+ return JSON.parse(cachedFlags);
138
+ }
139
+ } catch (error) {
140
+ console.warn("@flopflip/cache: Failed to parse cached flags from ".concat(cacheIdentifier, "."));
141
+ }
142
+ }
143
+ return {};
144
+ }
145
+ function getAllCachedFlags(adapter, cacheIdentifier) {
146
+ if (!cacheIdentifier) {
147
+ return {};
148
+ }
149
+ if (adapter.effectIds) {
150
+ return adapter.effectIds.reduce((defaultFlags, effectId) => _objectSpread2(_objectSpread2({}, defaultFlags), getCachedFlags(cacheIdentifier, effectId)), {});
151
+ }
152
+ return getCachedFlags(cacheIdentifier, adapter.id);
153
+ }
154
+
155
+ const version = "14.0.0";
156
+
157
+ exports.getAllCachedFlags = getAllCachedFlags;
158
+ exports.getCache = getCache;
159
+ exports.getCachedFlags = getCachedFlags;
160
+ exports.version = version;
@@ -0,0 +1,135 @@
1
+ import { cacheIdentifiers } from '@flopflip/types';
2
+
3
+ function toPrimitive(t, r) {
4
+ if ("object" != typeof t || !t) return t;
5
+ var e = t[Symbol.toPrimitive];
6
+ if (void 0 !== e) {
7
+ var i = e.call(t, r || "default");
8
+ if ("object" != typeof i) return i;
9
+ throw new TypeError("@@toPrimitive must return a primitive value.");
10
+ }
11
+ return ("string" === r ? String : Number)(t);
12
+ }
13
+
14
+ function toPropertyKey(t) {
15
+ var i = toPrimitive(t, "string");
16
+ return "symbol" == typeof i ? i : i + "";
17
+ }
18
+
19
+ function _defineProperty(obj, key, value) {
20
+ key = toPropertyKey(key);
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+
34
+ function ownKeys(e, r) {
35
+ var t = Object.keys(e);
36
+ if (Object.getOwnPropertySymbols) {
37
+ var o = Object.getOwnPropertySymbols(e);
38
+ r && (o = o.filter(function (r) {
39
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
40
+ })), t.push.apply(t, o);
41
+ }
42
+ return t;
43
+ }
44
+ function _objectSpread2(e) {
45
+ for (var r = 1; r < arguments.length; r++) {
46
+ var t = null != arguments[r] ? arguments[r] : {};
47
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
48
+ _defineProperty(e, r, t[r]);
49
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
50
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
51
+ });
52
+ }
53
+ return e;
54
+ }
55
+
56
+ const FLAGS_CACHE_KEY = 'flags';
57
+ const FLAGS_REFERENCE_CACHE_KEY = 'flags-reference';
58
+ function getCachePrefix(adapterIdentifiers) {
59
+ return "@flopflip/".concat(adapterIdentifiers, "-adapter");
60
+ }
61
+ async function importCache(cacheIdentifier) {
62
+ let cacheModule;
63
+ switch (cacheIdentifier) {
64
+ case cacheIdentifiers.local:
65
+ {
66
+ cacheModule = await import('@flopflip/localstorage-cache');
67
+ break;
68
+ }
69
+ case cacheIdentifiers.session:
70
+ {
71
+ cacheModule = await import('@flopflip/sessionstorage-cache');
72
+ break;
73
+ }
74
+ }
75
+ return cacheModule;
76
+ }
77
+ async function getCache(cacheIdentifier, adapterIdentifiers, cacheKey) {
78
+ const cacheModule = await importCache(cacheIdentifier);
79
+ const CACHE_PREFIX = getCachePrefix(adapterIdentifiers);
80
+ const createCache = cacheModule.default;
81
+ const flagsCachePrefix = [CACHE_PREFIX, cacheKey].filter(Boolean).join('/');
82
+ const flagsCache = createCache({
83
+ prefix: flagsCachePrefix
84
+ });
85
+ const referenceCache = createCache({
86
+ prefix: CACHE_PREFIX
87
+ });
88
+ return {
89
+ set(flags) {
90
+ const haveFlagsBeenWritten = flagsCache.set(FLAGS_CACHE_KEY, flags);
91
+ if (haveFlagsBeenWritten) {
92
+ referenceCache.set(FLAGS_REFERENCE_CACHE_KEY, [flagsCachePrefix, FLAGS_CACHE_KEY].join('/'));
93
+ }
94
+ return haveFlagsBeenWritten;
95
+ },
96
+ get() {
97
+ return flagsCache.get(FLAGS_CACHE_KEY);
98
+ },
99
+ unset() {
100
+ referenceCache.unset(FLAGS_REFERENCE_CACHE_KEY);
101
+ return flagsCache.unset(FLAGS_CACHE_KEY);
102
+ }
103
+ };
104
+ }
105
+ function getCachedFlags(cacheIdentifier, adapterIdentifiers) {
106
+ const CACHE_PREFIX = getCachePrefix(adapterIdentifiers);
107
+ const cacheModule = cacheIdentifier === cacheIdentifiers.local ? localStorage : sessionStorage;
108
+ const flagReferenceKey = [CACHE_PREFIX, FLAGS_REFERENCE_CACHE_KEY].join('/');
109
+ const referenceToCachedFlags = cacheModule.getItem(flagReferenceKey);
110
+ if (referenceToCachedFlags) {
111
+ try {
112
+ const cacheKey = JSON.parse(referenceToCachedFlags);
113
+ const cachedFlags = cacheModule.getItem(cacheKey);
114
+ if (cacheKey && cachedFlags) {
115
+ return JSON.parse(cachedFlags);
116
+ }
117
+ } catch (error) {
118
+ console.warn("@flopflip/cache: Failed to parse cached flags from ".concat(cacheIdentifier, "."));
119
+ }
120
+ }
121
+ return {};
122
+ }
123
+ function getAllCachedFlags(adapter, cacheIdentifier) {
124
+ if (!cacheIdentifier) {
125
+ return {};
126
+ }
127
+ if (adapter.effectIds) {
128
+ return adapter.effectIds.reduce((defaultFlags, effectId) => _objectSpread2(_objectSpread2({}, defaultFlags), getCachedFlags(cacheIdentifier, effectId)), {});
129
+ }
130
+ return getCachedFlags(cacheIdentifier, adapter.id);
131
+ }
132
+
133
+ const version = "14.0.0";
134
+
135
+ export { getAllCachedFlags, getCache, getCachedFlags, version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopflip/cache",
3
- "version": "0.0.0-canary-20240411092321",
3
+ "version": "14.0.0",
4
4
  "description": "Caching for flipflop adapters",
5
5
  "main": "dist/flopflip-cache.cjs.js",
6
6
  "module": "dist/flopflip-cache.esm.js",
@@ -29,8 +29,8 @@
29
29
  "client"
30
30
  ],
31
31
  "dependencies": {
32
- "@flopflip/localstorage-cache": "0.0.0-canary-20240411092321",
33
- "@flopflip/sessionstorage-cache": "0.0.0-canary-20240411092321",
34
- "@flopflip/types": "0.0.0-canary-20240411092321"
32
+ "@flopflip/localstorage-cache": "14.0.0",
33
+ "@flopflip/sessionstorage-cache": "14.0.0",
34
+ "@flopflip/types": "14.0.0"
35
35
  }
36
36
  }