alchemy 0.16.0 → 0.16.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.
Files changed (55) hide show
  1. package/lib/alchemy.d.ts.map +1 -1
  2. package/lib/alchemy.js +6 -5
  3. package/lib/alchemy.js.map +1 -1
  4. package/lib/apply.d.ts.map +1 -1
  5. package/lib/apply.js +31 -31
  6. package/lib/apply.js.map +1 -1
  7. package/lib/cloudflare/queue.d.ts.map +1 -1
  8. package/lib/cloudflare/queue.js +3 -2
  9. package/lib/cloudflare/queue.js.map +1 -1
  10. package/lib/cloudflare/r2-rest-state-store.d.ts +1 -1
  11. package/lib/cloudflare/r2-rest-state-store.d.ts.map +1 -1
  12. package/lib/cloudflare/r2-rest-state-store.js +5 -4
  13. package/lib/cloudflare/r2-rest-state-store.js.map +1 -1
  14. package/lib/cloudflare/worker.js +1 -1
  15. package/lib/cloudflare/worker.js.map +1 -1
  16. package/lib/context.d.ts +1 -1
  17. package/lib/context.d.ts.map +1 -1
  18. package/lib/context.js +6 -5
  19. package/lib/context.js.map +1 -1
  20. package/lib/destroy.d.ts.map +1 -1
  21. package/lib/destroy.js +20 -20
  22. package/lib/destroy.js.map +1 -1
  23. package/lib/fs/file-system-state-store.d.ts +1 -1
  24. package/lib/fs/file-system-state-store.d.ts.map +1 -1
  25. package/lib/fs/file-system-state-store.js +5 -3
  26. package/lib/fs/file-system-state-store.js.map +1 -1
  27. package/lib/os/exec.d.ts +46 -1
  28. package/lib/os/exec.d.ts.map +1 -1
  29. package/lib/os/exec.js +47 -1
  30. package/lib/os/exec.js.map +1 -1
  31. package/lib/resource.d.ts +15 -11
  32. package/lib/resource.d.ts.map +1 -1
  33. package/lib/resource.js +12 -7
  34. package/lib/resource.js.map +1 -1
  35. package/lib/scope.d.ts +1 -1
  36. package/lib/scope.d.ts.map +1 -1
  37. package/lib/scope.js +2 -1
  38. package/lib/scope.js.map +1 -1
  39. package/lib/state.d.ts +3 -2
  40. package/lib/state.d.ts.map +1 -1
  41. package/lib/state.js +29 -0
  42. package/lib/state.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/alchemy.ts +13 -6
  45. package/src/apply.ts +37 -30
  46. package/src/cloudflare/queue.ts +6 -3
  47. package/src/cloudflare/r2-rest-state-store.ts +5 -5
  48. package/src/cloudflare/worker.ts +1 -1
  49. package/src/context.ts +21 -13
  50. package/src/destroy.ts +34 -20
  51. package/src/fs/file-system-state-store.ts +5 -7
  52. package/src/os/exec.ts +87 -2
  53. package/src/resource.ts +22 -18
  54. package/src/scope.ts +2 -2
  55. package/src/state.ts +42 -2
package/src/state.ts CHANGED
@@ -1,5 +1,14 @@
1
- import type { Resource, ResourceProps } from "./resource.js";
2
- import type { Scope } from "./scope.js";
1
+ import {
2
+ ResourceFQN,
3
+ ResourceID,
4
+ ResourceKind,
5
+ ResourceScope,
6
+ ResourceSeq,
7
+ type Resource,
8
+ type ResourceProps,
9
+ } from "./resource.js";
10
+ import { Scope } from "./scope.js";
11
+ import { deserialize } from "./serde.js";
3
12
 
4
13
  export type State<
5
14
  Kind extends string = string,
@@ -41,3 +50,34 @@ export interface StateStore {
41
50
  set(key: string, value: State): Promise<void>;
42
51
  delete(key: string): Promise<void>;
43
52
  }
53
+
54
+ export async function deserializeState(
55
+ scope: Scope,
56
+ content: string,
57
+ ): Promise<State> {
58
+ const state = (await deserialize(scope, JSON.parse(content))) as State;
59
+
60
+ if (ResourceID in state.output) {
61
+ // this is a new state
62
+ return state;
63
+ }
64
+ const output: any = state.output;
65
+ delete output.Kind;
66
+ delete output.ID;
67
+ delete output.FQN;
68
+ delete output.Scope;
69
+ delete output.Seq;
70
+ // fix this bug
71
+ if (state.kind === "scope") {
72
+ state.kind = Scope.KIND;
73
+ }
74
+ output[ResourceKind] = state.kind;
75
+ output[ResourceID] = state.id;
76
+ output[ResourceFQN] = state.fqn;
77
+ output[ResourceScope] = scope;
78
+ output[ResourceSeq] = state.seq;
79
+ state.output = output;
80
+ // re-write the state with the migrated format
81
+ await scope.state.set(state.id, state);
82
+ return state;
83
+ }