@flaghoist/adapter-memory 0.1.2 → 0.2.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.
- package/README.md +2 -1
- package/dist/index.cjs +65 -0
- package/dist/index.js +68 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,7 +24,8 @@ memoryAdapter([{ key: 'new-checkout', enabled: true, rollout: { percentage: 100
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
Everything disappears when the process exits. That is the point, but it does mean this is not the
|
|
27
|
-
one to reach for in production.
|
|
27
|
+
one to reach for in production. Webhook endpoints and audit entries are kept in memory too, with the
|
|
28
|
+
same lifetime as the flags.
|
|
28
29
|
|
|
29
30
|
It is validated by the same conformance suite as the other adapters, so it behaves like the real
|
|
30
31
|
thing rather than like a stub that drifts.
|
package/dist/index.cjs
CHANGED
|
@@ -23,9 +23,23 @@ __export(index_exports, {
|
|
|
23
23
|
memoryAdapter: () => memoryAdapter
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_core = require("@flaghoist/core");
|
|
27
|
+
var toJson = (value) => JSON.stringify(value);
|
|
28
|
+
var fromJson = (raw) => JSON.parse(raw);
|
|
26
29
|
function memoryAdapter(seed = []) {
|
|
27
30
|
const store = /* @__PURE__ */ new Map();
|
|
28
31
|
for (const flag of seed) store.set(flag.key, structuredClone(flag));
|
|
32
|
+
const auditBuf = [];
|
|
33
|
+
const webhooks = /* @__PURE__ */ new Map();
|
|
34
|
+
const records = /* @__PURE__ */ new Map();
|
|
35
|
+
const collection = (name) => {
|
|
36
|
+
let c = records.get(name);
|
|
37
|
+
if (!c) {
|
|
38
|
+
c = /* @__PURE__ */ new Map();
|
|
39
|
+
records.set(name, c);
|
|
40
|
+
}
|
|
41
|
+
return c;
|
|
42
|
+
};
|
|
29
43
|
return {
|
|
30
44
|
async get(key) {
|
|
31
45
|
const flag = store.get(key);
|
|
@@ -39,6 +53,57 @@ function memoryAdapter(seed = []) {
|
|
|
39
53
|
},
|
|
40
54
|
async list() {
|
|
41
55
|
return [...store.values()].map((flag) => structuredClone(flag));
|
|
56
|
+
},
|
|
57
|
+
async appendAudit(entry) {
|
|
58
|
+
auditBuf.push(structuredClone(entry));
|
|
59
|
+
},
|
|
60
|
+
async listAudit(options) {
|
|
61
|
+
let entries = auditBuf.slice().reverse();
|
|
62
|
+
if (options?.category) {
|
|
63
|
+
entries = entries.filter((e) => (0, import_core.auditCategory)(e.action) === options.category);
|
|
64
|
+
}
|
|
65
|
+
if (options?.flagKey) entries = entries.filter((e) => e.flagKey === options.flagKey);
|
|
66
|
+
if (options?.action) entries = entries.filter((e) => e.action === options.action);
|
|
67
|
+
if (options?.environment !== void 0) {
|
|
68
|
+
entries = entries.filter((e) => e.environment === options.environment);
|
|
69
|
+
}
|
|
70
|
+
const total = entries.length;
|
|
71
|
+
const offset = options?.offset ?? 0;
|
|
72
|
+
const limit = options?.limit ?? 50;
|
|
73
|
+
return { entries: entries.slice(offset, offset + limit), total };
|
|
74
|
+
},
|
|
75
|
+
async putWebhook(id, webhook) {
|
|
76
|
+
webhooks.set(id, structuredClone(webhook));
|
|
77
|
+
},
|
|
78
|
+
async getWebhook(id) {
|
|
79
|
+
const w = webhooks.get(id);
|
|
80
|
+
return w ? structuredClone(w) : null;
|
|
81
|
+
},
|
|
82
|
+
async deleteWebhook(id) {
|
|
83
|
+
webhooks.delete(id);
|
|
84
|
+
},
|
|
85
|
+
async listWebhooks() {
|
|
86
|
+
return [...webhooks.values()].map((w) => structuredClone(w));
|
|
87
|
+
},
|
|
88
|
+
async getRecord(name, id) {
|
|
89
|
+
(0, import_core.assertRecordAddress)(name, id);
|
|
90
|
+
const raw = records.get(name)?.get(id);
|
|
91
|
+
return raw === void 0 ? null : fromJson(raw);
|
|
92
|
+
},
|
|
93
|
+
async putRecord(name, id, value) {
|
|
94
|
+
(0, import_core.assertRecordAddress)(name, id);
|
|
95
|
+
collection(name).set(id, toJson(value));
|
|
96
|
+
},
|
|
97
|
+
async deleteRecord(name, id) {
|
|
98
|
+
(0, import_core.assertRecordAddress)(name, id);
|
|
99
|
+
records.get(name)?.delete(id);
|
|
100
|
+
},
|
|
101
|
+
async listRecords(name) {
|
|
102
|
+
(0, import_core.assertRecordAddress)(name);
|
|
103
|
+
return [...records.get(name) ?? /* @__PURE__ */ new Map()].map(([id, raw]) => ({
|
|
104
|
+
id,
|
|
105
|
+
value: fromJson(raw)
|
|
106
|
+
}));
|
|
42
107
|
}
|
|
43
108
|
};
|
|
44
109
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
assertRecordAddress,
|
|
4
|
+
auditCategory
|
|
5
|
+
} from "@flaghoist/core";
|
|
6
|
+
var toJson = (value) => JSON.stringify(value);
|
|
7
|
+
var fromJson = (raw) => JSON.parse(raw);
|
|
2
8
|
function memoryAdapter(seed = []) {
|
|
3
9
|
const store = /* @__PURE__ */ new Map();
|
|
4
10
|
for (const flag of seed) store.set(flag.key, structuredClone(flag));
|
|
11
|
+
const auditBuf = [];
|
|
12
|
+
const webhooks = /* @__PURE__ */ new Map();
|
|
13
|
+
const records = /* @__PURE__ */ new Map();
|
|
14
|
+
const collection = (name) => {
|
|
15
|
+
let c = records.get(name);
|
|
16
|
+
if (!c) {
|
|
17
|
+
c = /* @__PURE__ */ new Map();
|
|
18
|
+
records.set(name, c);
|
|
19
|
+
}
|
|
20
|
+
return c;
|
|
21
|
+
};
|
|
5
22
|
return {
|
|
6
23
|
async get(key) {
|
|
7
24
|
const flag = store.get(key);
|
|
@@ -15,6 +32,57 @@ function memoryAdapter(seed = []) {
|
|
|
15
32
|
},
|
|
16
33
|
async list() {
|
|
17
34
|
return [...store.values()].map((flag) => structuredClone(flag));
|
|
35
|
+
},
|
|
36
|
+
async appendAudit(entry) {
|
|
37
|
+
auditBuf.push(structuredClone(entry));
|
|
38
|
+
},
|
|
39
|
+
async listAudit(options) {
|
|
40
|
+
let entries = auditBuf.slice().reverse();
|
|
41
|
+
if (options?.category) {
|
|
42
|
+
entries = entries.filter((e) => auditCategory(e.action) === options.category);
|
|
43
|
+
}
|
|
44
|
+
if (options?.flagKey) entries = entries.filter((e) => e.flagKey === options.flagKey);
|
|
45
|
+
if (options?.action) entries = entries.filter((e) => e.action === options.action);
|
|
46
|
+
if (options?.environment !== void 0) {
|
|
47
|
+
entries = entries.filter((e) => e.environment === options.environment);
|
|
48
|
+
}
|
|
49
|
+
const total = entries.length;
|
|
50
|
+
const offset = options?.offset ?? 0;
|
|
51
|
+
const limit = options?.limit ?? 50;
|
|
52
|
+
return { entries: entries.slice(offset, offset + limit), total };
|
|
53
|
+
},
|
|
54
|
+
async putWebhook(id, webhook) {
|
|
55
|
+
webhooks.set(id, structuredClone(webhook));
|
|
56
|
+
},
|
|
57
|
+
async getWebhook(id) {
|
|
58
|
+
const w = webhooks.get(id);
|
|
59
|
+
return w ? structuredClone(w) : null;
|
|
60
|
+
},
|
|
61
|
+
async deleteWebhook(id) {
|
|
62
|
+
webhooks.delete(id);
|
|
63
|
+
},
|
|
64
|
+
async listWebhooks() {
|
|
65
|
+
return [...webhooks.values()].map((w) => structuredClone(w));
|
|
66
|
+
},
|
|
67
|
+
async getRecord(name, id) {
|
|
68
|
+
assertRecordAddress(name, id);
|
|
69
|
+
const raw = records.get(name)?.get(id);
|
|
70
|
+
return raw === void 0 ? null : fromJson(raw);
|
|
71
|
+
},
|
|
72
|
+
async putRecord(name, id, value) {
|
|
73
|
+
assertRecordAddress(name, id);
|
|
74
|
+
collection(name).set(id, toJson(value));
|
|
75
|
+
},
|
|
76
|
+
async deleteRecord(name, id) {
|
|
77
|
+
assertRecordAddress(name, id);
|
|
78
|
+
records.get(name)?.delete(id);
|
|
79
|
+
},
|
|
80
|
+
async listRecords(name) {
|
|
81
|
+
assertRecordAddress(name);
|
|
82
|
+
return [...records.get(name) ?? /* @__PURE__ */ new Map()].map(([id, raw]) => ({
|
|
83
|
+
id,
|
|
84
|
+
value: fromJson(raw)
|
|
85
|
+
}));
|
|
18
86
|
}
|
|
19
87
|
};
|
|
20
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flaghoist/adapter-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "In-memory StorageAdapter for Flaghoist — development, tests, and fallback defaults.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"node": ">=20"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@flaghoist/core": "0.
|
|
30
|
+
"@flaghoist/core": "0.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@flaghoist/adapter-conformance": "0.0.0"
|