pepr 0.32.6 → 0.33.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/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright [yyyy] [name of copyright owner]
189
+ Copyright 2024 Defense Unicorns
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/dist/cli.js CHANGED
@@ -288,6 +288,21 @@ function sanitizeResourceName(name2) {
288
288
  }
289
289
 
290
290
  // src/lib/helpers.ts
291
+ var import_ramda = require("ramda");
292
+ function mergePkgJSONEnv(env, pkgJSONEnv) {
293
+ if (!pkgJSONEnv) {
294
+ return env;
295
+ }
296
+ Object.keys(pkgJSONEnv).forEach((key) => {
297
+ if (key === "PEPR_WATCH_MODE") {
298
+ delete pkgJSONEnv[key];
299
+ }
300
+ });
301
+ return (0, import_ramda.mergeDeepRight)(env, pkgJSONEnv);
302
+ }
303
+ function envMapToArray(env) {
304
+ return Object.entries(env).map(([key, value]) => ({ name: key, value }));
305
+ }
291
306
  var ValidationError = class extends Error {
292
307
  };
293
308
  function validateCapabilityNames(capabilities) {
@@ -937,7 +952,7 @@ var peprStoreCRD = {
937
952
  };
938
953
 
939
954
  // src/lib/assets/webhooks.ts
940
- var import_ramda = require("ramda");
955
+ var import_ramda2 = require("ramda");
941
956
  var peprIgnoreLabel = {
942
957
  key: "pepr.dev",
943
958
  operator: "NotIn",
@@ -976,12 +991,12 @@ async function generateWebhookRules(assets, isMutateWebhook) {
976
991
  rules.push(ruleObject);
977
992
  }
978
993
  }
979
- return (0, import_ramda.uniqWith)(import_ramda.equals, rules);
994
+ return (0, import_ramda2.uniqWith)(import_ramda2.equals, rules);
980
995
  }
981
996
  async function webhookConfig(assets, mutateOrValidate, timeoutSeconds = 10) {
982
997
  const ignore = [peprIgnoreLabel];
983
998
  const { name: name2, tls, config, apiToken, host } = assets;
984
- const ignoreNS = (0, import_ramda.concat)(peprIgnoreNamespaces, config.alwaysIgnore.namespaces || []);
999
+ const ignoreNS = (0, import_ramda2.concat)(peprIgnoreNamespaces, config.alwaysIgnore.namespaces || []);
985
1000
  if (ignoreNS) {
986
1001
  ignore.push({
987
1002
  key: "kubernetes.io/metadata.name",
@@ -1170,6 +1185,16 @@ var import_client_node = require("@kubernetes/client-node");
1170
1185
  var import_crypto2 = __toESM(require("crypto"));
1171
1186
  var import_fs4 = require("fs");
1172
1187
  async function overridesFile({ hash, name: name2, image, config, apiToken }, path) {
1188
+ const pkgJSONAdmissionEnv = {
1189
+ PEPR_WATCH_MODE: "false",
1190
+ PEPR_PRETTY_LOG: "false",
1191
+ LOG_LEVEL: "info"
1192
+ };
1193
+ const pkgJSONWatchEnv = {
1194
+ PEPR_WATCH_MODE: "true",
1195
+ PEPR_PRETTY_LOG: "false",
1196
+ LOG_LEVEL: "info"
1197
+ };
1173
1198
  const overrides = {
1174
1199
  secrets: {
1175
1200
  apiToken: Buffer.from(apiToken).toString("base64")
@@ -1186,11 +1211,7 @@ async function overridesFile({ hash, name: name2, image, config, apiToken }, pat
1186
1211
  terminationGracePeriodSeconds: 5,
1187
1212
  failurePolicy: config.onError === "reject" ? "Fail" : "Ignore",
1188
1213
  webhookTimeout: config.webhookTimeout,
1189
- env: [
1190
- { name: "PEPR_WATCH_MODE", value: "false" },
1191
- { name: "PEPR_PRETTY_LOG", value: "false" },
1192
- { name: "LOG_LEVEL", value: "info" }
1193
- ],
1214
+ env: envMapToArray(mergePkgJSONEnv(pkgJSONAdmissionEnv, config.env)),
1194
1215
  image,
1195
1216
  annotations: {
1196
1217
  "pepr.dev/description": `${config.description}` || ""
@@ -1234,11 +1255,7 @@ async function overridesFile({ hash, name: name2, image, config, apiToken }, pat
1234
1255
  },
1235
1256
  watcher: {
1236
1257
  terminationGracePeriodSeconds: 5,
1237
- env: [
1238
- { name: "PEPR_WATCH_MODE", value: "true" },
1239
- { name: "PEPR_PRETTY_LOG", value: "false" },
1240
- { name: "LOG_LEVEL", value: "info" }
1241
- ],
1258
+ env: envMapToArray(mergePkgJSONEnv(pkgJSONWatchEnv, config.env)),
1242
1259
  image,
1243
1260
  annotations: {
1244
1261
  "pepr.dev/description": `${config.description}` || ""
@@ -1281,12 +1298,6 @@ async function overridesFile({ hash, name: name2, image, config, apiToken }, pat
1281
1298
  podAnnotations: {}
1282
1299
  }
1283
1300
  };
1284
- if (process.env.PEPR_MODE === "dev") {
1285
- overrides.admission.env.push({ name: "ZARF_VAR", value: "###ZARF_VAR_THING###" });
1286
- overrides.watcher.env.push({ name: "ZARF_VAR", value: "###ZARF_VAR_THING###" });
1287
- overrides.admission.env.push({ name: "MY_CUSTOM_VAR", value: "example-value" });
1288
- overrides.watcher.env.push({ name: "MY_CUSTOM_VAR", value: "example-value" });
1289
- }
1290
1301
  await import_fs4.promises.writeFile(path, (0, import_client_node.dumpYaml)(overrides, { noRefs: true, forceQuotes: true }));
1291
1302
  }
1292
1303
  function zarfYaml({ name: name2, image, config }, path) {
@@ -1922,7 +1933,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
1922
1933
  var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
1923
1934
  var peprTS = 'import { PeprModule } from "pepr";\n// cfg loads your pepr configuration from package.json\nimport cfg from "./package.json";\n\n// HelloPepr is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\nimport { HelloPepr } from "./capabilities/hello-pepr";\n\n/**\n * This is the main entrypoint for this Pepr module. It is run when the module is started.\n * This is where you register your Pepr configurations and capabilities.\n */\nnew PeprModule(cfg, [\n // "HelloPepr" is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n';
1924
1935
  var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://icanhazdadjoke.com/");\n * const joke = await fetch("https://icanhazdadjoke.com/") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://icanhazdadjoke.com")\n * ```\n */\ninterface TheChuckNorrisJoke {\n id: string;\n joke: string;\n status: number;\n}\n\nWhen(a.ConfigMap)\n .IsCreated()\n .WithLabel("chuck-norris")\n .Mutate(async change => {\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(\n "https://icanhazdadjoke.com/",\n {\n headers: {\n Accept: "application/json",\n },\n },\n );\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n // Add the Chuck Norris joke to the configmap\n change.Raw.data["chuck-says"] = response.data.joke;\n return;\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
1925
- var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.32.6", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", "build:image": "npm run build && docker buildx build --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.30.0", express: "4.19.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.6.3", pino: "9.2.0", "pino-pretty": "11.2.1", "prom-client": "15.1.3", ramda: "0.30.1" }, devDependencies: { "@commitlint/cli": "19.3.0", "@commitlint/config-conventional": "19.2.2", "@fast-check/jest": "^1.8.2", "@jest/globals": "29.7.0", "@types/eslint": "8.56.10", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.11", "@types/prompts": "2.4.9", "fast-check": "^3.19.0", "@types/uuid": "10.0.0", jest: "29.7.0", nock: "13.5.4", "ts-jest": "29.1.5" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.15.0", "@typescript-eslint/parser": "6.15.0", commander: "11.1.0", esbuild: "0.19.10", eslint: "8.56.0", "node-forge": "1.3.1", prettier: "3.1.1", prompts: "2.4.2", typescript: "5.3.3", uuid: "9.0.1" } };
1936
+ var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.33.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", "build:image": "npm run build && docker buildx build --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.30.1", express: "4.19.2", "fast-json-patch": "3.1.1", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "2.6.5", pino: "9.3.1", "pino-pretty": "11.2.1", "prom-client": "15.1.3", ramda: "0.30.1" }, devDependencies: { "@commitlint/cli": "19.3.0", "@commitlint/config-conventional": "19.2.2", "@fast-check/jest": "^1.8.2", "@jest/globals": "29.7.0", "@types/eslint": "9.6.0", "@types/express": "4.17.21", "@types/json-pointer": "^1.0.34", "@types/node": "18.x.x", "@types/node-forge": "1.3.11", "@types/prompts": "2.4.9", "@types/uuid": "10.0.0", "fast-check": "^3.19.0", jest: "29.7.0", "js-yaml": "^4.1.0", nock: "13.5.4", "ts-jest": "29.2.3" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.15.0", "@typescript-eslint/parser": "6.15.0", commander: "11.1.0", esbuild: "0.19.10", eslint: "8.56.0", "node-forge": "1.3.1", prettier: "3.1.1", prompts: "2.4.2", typescript: "5.3.3", uuid: "9.0.1" } };
1926
1937
 
1927
1938
  // src/templates/pepr.code-snippets.json
1928
1939
  var pepr_code_snippets_default = {
@@ -2125,7 +2136,7 @@ async function peprFormat(validateOnly) {
2125
2136
  }
2126
2137
  });
2127
2138
  const formatter = await eslint2.loadFormatter("stylish");
2128
- const resultText = await formatter.format(results);
2139
+ const resultText = await formatter.format(results, {});
2129
2140
  if (resultText) {
2130
2141
  console.log(resultText);
2131
2142
  }
@@ -51,7 +51,7 @@ if (process.env.LOG_LEVEL) {
51
51
  var logger_default = Log;
52
52
 
53
53
  // src/templates/data.json
54
- var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.32.6", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", "build:image": "npm run build && docker buildx build --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.30.0", express: "4.19.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.6.3", pino: "9.2.0", "pino-pretty": "11.2.1", "prom-client": "15.1.3", ramda: "0.30.1" }, devDependencies: { "@commitlint/cli": "19.3.0", "@commitlint/config-conventional": "19.2.2", "@fast-check/jest": "^1.8.2", "@jest/globals": "29.7.0", "@types/eslint": "8.56.10", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.11", "@types/prompts": "2.4.9", "fast-check": "^3.19.0", "@types/uuid": "10.0.0", jest: "29.7.0", nock: "13.5.4", "ts-jest": "29.1.5" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.15.0", "@typescript-eslint/parser": "6.15.0", commander: "11.1.0", esbuild: "0.19.10", eslint: "8.56.0", "node-forge": "1.3.1", prettier: "3.1.1", prompts: "2.4.2", typescript: "5.3.3", uuid: "9.0.1" } };
54
+ var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.33.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", "build:image": "npm run build && docker buildx build --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.30.1", express: "4.19.2", "fast-json-patch": "3.1.1", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "2.6.5", pino: "9.3.1", "pino-pretty": "11.2.1", "prom-client": "15.1.3", ramda: "0.30.1" }, devDependencies: { "@commitlint/cli": "19.3.0", "@commitlint/config-conventional": "19.2.2", "@fast-check/jest": "^1.8.2", "@jest/globals": "29.7.0", "@types/eslint": "9.6.0", "@types/express": "4.17.21", "@types/json-pointer": "^1.0.34", "@types/node": "18.x.x", "@types/node-forge": "1.3.11", "@types/prompts": "2.4.9", "@types/uuid": "10.0.0", "fast-check": "^3.19.0", jest: "29.7.0", "js-yaml": "^4.1.0", nock: "13.5.4", "ts-jest": "29.2.3" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.15.0", "@typescript-eslint/parser": "6.15.0", commander: "11.1.0", esbuild: "0.19.10", eslint: "8.56.0", "node-forge": "1.3.1", prettier: "3.1.1", prompts: "2.4.2", typescript: "5.3.3", uuid: "9.0.1" } };
55
55
 
56
56
  // src/lib/k8s.ts
57
57
  var import_kubernetes_fluent_client = require("kubernetes-fluent-client");
@@ -114,6 +114,7 @@ var import_kubernetes_fluent_client3 = require("kubernetes-fluent-client");
114
114
  var import_kubernetes_fluent_client2 = require("kubernetes-fluent-client");
115
115
 
116
116
  // src/lib/helpers.ts
117
+ var import_ramda = require("ramda");
117
118
  var ValidationError = class extends Error {
118
119
  };
119
120
  function validateHash(expectedHash) {
@@ -1 +1 @@
1
- {"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/yaml.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAO3B,wBAAsB,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAwHhG;AACD,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UA0BrE;AAED,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UA2B1E;AAED,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,mBAwCvF"}
1
+ {"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/yaml.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAQ3B,wBAAsB,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAqHhG;AACD,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UA0BrE;AAED,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UA2B1E;AAED,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,mBAwCvF"}
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,qBAAa,mBAAmB;;gBAMlB,YAAY,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI;CAqM3E"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,qBAAa,mBAAmB;;gBAMlB,YAAY,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI;CA2R3E"}
@@ -1,5 +1,10 @@
1
1
  import { KubernetesObject } from "kubernetes-fluent-client";
2
2
  import { Binding, CapabilityExport } from "./types";
3
+ export declare function mergePkgJSONEnv(env: Record<string, string>, pkgJSONEnv?: Record<string, string>): Record<string, string>;
4
+ export declare function envMapToArray(env: Record<string, string>): {
5
+ name: string;
6
+ value: string;
7
+ }[];
3
8
  export declare class ValidationError extends Error {
4
9
  }
5
10
  export declare function validateCapabilityNames(capabilities: CapabilityExport[] | undefined): void;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAO,gBAAgB,EAAQ,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGpD,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAE7C,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,SAAS,GAAG,IAAI,CAQ1F;AAED,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAOvD;AAED,KAAK,OAAO,GAAG;IACb,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAGF,wBAAgB,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA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OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAK1E"}
@@ -3,6 +3,8 @@ export type DataStore = Record<string, string>;
3
3
  export type DataSender = (op: DataOp, keys: string[], value?: string) => void;
4
4
  export type DataReceiver = (data: DataStore) => void;
5
5
  export type Unsubscribe = () => void;
6
+ export declare function v2StoreKey(key: string): string;
7
+ export declare function stripV2Prefix(key: string): string;
6
8
  export interface PeprStore {
7
9
  /**
8
10
  * Returns the current value associated with the given key, or null if the given key does not exist.
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/lib/storage.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AACtC,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAC9E,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;AACrD,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAGrC,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IACd;;OAEG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1C;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,YAAY,GAAG,WAAW,CAAC;IAE/C;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAEtC;;;OA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AAW,SAAS;IACxB;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IACd;;OAEG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1C;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,YAAY,GAAG,WAAW,CAAC;IAE/C;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAEtC;;;OAGG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1D;;;OAGG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED;;;;GAIG;AAEH,qBAAa,OAAQ,YAAW,SAAS;;IAOvC,cAAc,SAAU,UAAU,UAEhC;IAEF,OAAO,SAAU,SAAS,UAWxB;IAEF,OAAO,QAAS,MAAM,mBAMpB;IAEF,KAAK,aAEH;IAEF,UAAU,QAAS,MAAM,UAEvB;IAEF,OAAO,QAAS,MAAM,SAAS,MAAM,UAEnC;IAEF;;;;;;;OAOG;IACH,cAAc,QAAS,MAAM,SAAS,MAAM,mBAgB1C;IAEF;;;;;;OAMG;IACH,iBAAiB,QAAS,MAAM,mBAgB9B;IAEF,SAAS,eAAgB,YAAY,gBAInC;IAEF,OAAO,aAAc,YAAY,UAE/B;IAEF;;;OAGG;IACH,WAAW,QAAS,MAAM,UAExB;CAqBH"}
package/dist/lib.js CHANGED
@@ -51,7 +51,7 @@ var R = __toESM(require("ramda"));
51
51
 
52
52
  // src/lib/capability.ts
53
53
  var import_kubernetes_fluent_client6 = require("kubernetes-fluent-client");
54
- var import_ramda6 = require("ramda");
54
+ var import_ramda7 = require("ramda");
55
55
 
56
56
  // src/lib/logger.ts
57
57
  var import_pino = require("pino");
@@ -74,7 +74,7 @@ if (process.env.LOG_LEVEL) {
74
74
  var logger_default = Log;
75
75
 
76
76
  // src/lib/module.ts
77
- var import_ramda4 = require("ramda");
77
+ var import_ramda5 = require("ramda");
78
78
 
79
79
  // src/lib/controller/index.ts
80
80
  var import_express = __toESM(require("express"));
@@ -665,7 +665,7 @@ var PeprControllerStore = class {
665
665
  }
666
666
  }
667
667
  setTimeout(
668
- () => (0, import_kubernetes_fluent_client2.K8s)(PeprStore).InNamespace(namespace).Get(this.#name).then(this.#setupWatch).catch(this.#createStoreResource),
668
+ () => (0, import_kubernetes_fluent_client2.K8s)(PeprStore).InNamespace(namespace).Get(this.#name).then(async (store) => await this.#migrateAndSetupWatch(store)).catch(this.#createStoreResource),
669
669
  Math.random() * 3e3
670
670
  );
671
671
  }
@@ -673,6 +673,62 @@ var PeprControllerStore = class {
673
673
  const watcher = (0, import_kubernetes_fluent_client2.K8s)(PeprStore, { name: this.#name, namespace }).Watch(this.#receive);
674
674
  watcher.start().catch((e) => logger_default.error(e, "Error starting Pepr store watch"));
675
675
  };
676
+ #migrateAndSetupWatch = async (store) => {
677
+ logger_default.debug(store, "Pepr Store migration");
678
+ const data = store.data || {};
679
+ const migrateCache = {};
680
+ const flushCache = async () => {
681
+ const indexes = Object.keys(migrateCache);
682
+ const payload = Object.values(migrateCache);
683
+ for (const idx of indexes) {
684
+ delete migrateCache[idx];
685
+ }
686
+ try {
687
+ await (0, import_kubernetes_fluent_client2.K8s)(PeprStore, { namespace, name: this.#name }).Patch(payload);
688
+ } catch (err) {
689
+ logger_default.error(err, "Pepr store update failure");
690
+ if (err.status === 422) {
691
+ Object.keys(migrateCache).forEach((key) => delete migrateCache[key]);
692
+ } else {
693
+ for (const idx of indexes) {
694
+ migrateCache[idx] = payload[Number(idx)];
695
+ }
696
+ }
697
+ }
698
+ };
699
+ const fillCache = (name, op, key, val) => {
700
+ if (op === "add") {
701
+ const path = `/data/${name}-v2-${key}`;
702
+ const value = val || "";
703
+ const cacheIdx = [op, path, value].join(":");
704
+ migrateCache[cacheIdx] = { op, path, value };
705
+ return;
706
+ }
707
+ if (op === "remove") {
708
+ if (key.length < 1) {
709
+ throw new Error(`Key is required for REMOVE operation`);
710
+ }
711
+ for (const k of key) {
712
+ const path = `/data/${name}-${k}`;
713
+ const cacheIdx = [op, path].join(":");
714
+ migrateCache[cacheIdx] = { op, path };
715
+ }
716
+ return;
717
+ }
718
+ throw new Error(`Unsupported operation: ${op}`);
719
+ };
720
+ for (const name of Object.keys(this.#stores)) {
721
+ const offset = `${name}-`.length;
722
+ for (const key of Object.keys(data)) {
723
+ if ((0, import_ramda3.startsWith)(name, key) && !(0, import_ramda3.startsWith)(`${name}-v2`, key)) {
724
+ fillCache(name, "remove", [key.slice(offset)], data[key]);
725
+ fillCache(name, "add", [key.slice(offset)], data[key]);
726
+ }
727
+ }
728
+ }
729
+ await flushCache();
730
+ this.#setupWatch();
731
+ };
676
732
  #receive = (store) => {
677
733
  logger_default.debug(store, "Pepr Store update");
678
734
  const debounced = () => {
@@ -1066,6 +1122,7 @@ function sanitizeResourceName(name) {
1066
1122
  }
1067
1123
 
1068
1124
  // src/lib/helpers.ts
1125
+ var import_ramda4 = require("ramda");
1069
1126
  function checkOverlap(bindingFilters, objectFilters) {
1070
1127
  if (Object.keys(bindingFilters).length === 0) {
1071
1128
  return true;
@@ -1268,7 +1325,7 @@ var PeprModule = class {
1268
1325
  * @param opts Options for the Pepr runtime
1269
1326
  */
1270
1327
  constructor({ description, pepr }, capabilities = [], opts = {}) {
1271
- const config = (0, import_ramda4.clone)(pepr);
1328
+ const config = (0, import_ramda5.clone)(pepr);
1272
1329
  config.description = description;
1273
1330
  ValidateError(config.onError);
1274
1331
  if (isBuildMode()) {
@@ -1315,8 +1372,13 @@ var PeprModule = class {
1315
1372
  };
1316
1373
 
1317
1374
  // src/lib/storage.ts
1318
- var import_ramda5 = require("ramda");
1375
+ var import_ramda6 = require("ramda");
1376
+ var import_json_pointer = __toESM(require("json-pointer"));
1319
1377
  var MAX_WAIT_TIME = 15e3;
1378
+ var STORE_VERSION_PREFIX = "v2";
1379
+ function v2StoreKey(key) {
1380
+ return `${STORE_VERSION_PREFIX}-${import_json_pointer.default.escape(key)}`;
1381
+ }
1320
1382
  var Storage = class {
1321
1383
  #store = {};
1322
1384
  #send;
@@ -1331,20 +1393,24 @@ var Storage = class {
1331
1393
  this.#store = data || {};
1332
1394
  this.#onReady();
1333
1395
  for (const idx in this.#subscribers) {
1334
- this.#subscribers[idx]((0, import_ramda5.clone)(this.#store));
1396
+ this.#subscribers[idx]((0, import_ramda6.clone)(this.#store));
1335
1397
  }
1336
1398
  };
1337
1399
  getItem = (key) => {
1338
- return this.#store[key] || null;
1400
+ const result = this.#store[v2StoreKey(key)] || null;
1401
+ if (result !== null && typeof result !== "function" && typeof result !== "object") {
1402
+ return result;
1403
+ }
1404
+ return null;
1339
1405
  };
1340
1406
  clear = () => {
1341
1407
  this.#dispatchUpdate("remove", Object.keys(this.#store));
1342
1408
  };
1343
1409
  removeItem = (key) => {
1344
- this.#dispatchUpdate("remove", [key]);
1410
+ this.#dispatchUpdate("remove", [v2StoreKey(key)]);
1345
1411
  };
1346
1412
  setItem = (key, value) => {
1347
- this.#dispatchUpdate("add", [key], value);
1413
+ this.#dispatchUpdate("add", [v2StoreKey(key)], value);
1348
1414
  };
1349
1415
  /**
1350
1416
  * Creates a promise and subscribes to the store, the promise resolves when
@@ -1355,10 +1421,10 @@ var Storage = class {
1355
1421
  * @returns
1356
1422
  */
1357
1423
  setItemAndWait = (key, value) => {
1358
- this.#dispatchUpdate("add", [key], value);
1424
+ this.#dispatchUpdate("add", [v2StoreKey(key)], value);
1359
1425
  return new Promise((resolve, reject) => {
1360
1426
  const unsubscribe = this.subscribe((data) => {
1361
- if (data[key] === value) {
1427
+ if (data[`${v2StoreKey(key)}`] === value) {
1362
1428
  unsubscribe();
1363
1429
  resolve();
1364
1430
  }
@@ -1377,10 +1443,10 @@ var Storage = class {
1377
1443
  * @returns
1378
1444
  */
1379
1445
  removeItemAndWait = (key) => {
1380
- this.#dispatchUpdate("remove", [key]);
1446
+ this.#dispatchUpdate("remove", [v2StoreKey(key)]);
1381
1447
  return new Promise((resolve, reject) => {
1382
1448
  const unsubscribe = this.subscribe((data) => {
1383
- if (!Object.hasOwn(data, key)) {
1449
+ if (!Object.hasOwn(data, `${v2StoreKey(key)}`)) {
1384
1450
  unsubscribe();
1385
1451
  resolve();
1386
1452
  }
@@ -1408,7 +1474,7 @@ var Storage = class {
1408
1474
  };
1409
1475
  #onReady = () => {
1410
1476
  for (const handler of this.#readyHandlers) {
1411
- handler((0, import_ramda5.clone)(this.#store));
1477
+ handler((0, import_ramda6.clone)(this.#store));
1412
1478
  }
1413
1479
  this.#onReady = () => {
1414
1480
  };
@@ -1704,7 +1770,7 @@ var Capability = class {
1704
1770
  const commonChain = { WithLabel, WithAnnotation, Mutate, Validate, Watch, Reconcile };
1705
1771
  const isNotEmpty = (value) => Object.keys(value).length > 0;
1706
1772
  const log = (message, cbString) => {
1707
- const filteredObj = (0, import_ramda6.pickBy)(isNotEmpty, binding.filters);
1773
+ const filteredObj = (0, import_ramda7.pickBy)(isNotEmpty, binding.filters);
1708
1774
  logger_default.info(`${message} configured for ${binding.event}`, prefix);
1709
1775
  logger_default.info(filteredObj, prefix);
1710
1776
  logger_default.debug(cbString, prefix);