@pipelab/shared 2.0.1-beta.20

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 (54) hide show
  1. package/.turbo/turbo-build.log +41 -0
  2. package/.turbo/turbo-lint.log +136 -0
  3. package/CHANGELOG.md +167 -0
  4. package/LICENSE +110 -0
  5. package/LICENSE.md +110 -0
  6. package/README.md +3 -0
  7. package/dist/index.d.mts +3603 -0
  8. package/dist/index.d.mts.map +1 -0
  9. package/dist/index.mjs +43763 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/package.json +53 -0
  12. package/src/apis.ts +191 -0
  13. package/src/build-history.ts +127 -0
  14. package/src/config/migrators.ts +308 -0
  15. package/src/config/projects-definition.ts +25 -0
  16. package/src/config/projects-types.ts +25 -0
  17. package/src/config/projects.ts +1 -0
  18. package/src/config/settings-definition.ts +21 -0
  19. package/src/config/settings.ts +21 -0
  20. package/src/config.schema.ts +149 -0
  21. package/src/database.types.ts +95 -0
  22. package/src/errors.ts +11 -0
  23. package/src/evaluator.ts +58 -0
  24. package/src/fmt.ts +5 -0
  25. package/src/graph.ts +207 -0
  26. package/src/i18n/de_DE.json +86 -0
  27. package/src/i18n/en_US.json +147 -0
  28. package/src/i18n/es_ES.json +86 -0
  29. package/src/i18n/fr_FR.json +89 -0
  30. package/src/i18n/pt_BR.json +86 -0
  31. package/src/i18n/zh_CN.json +86 -0
  32. package/src/i18n-utils.ts +10 -0
  33. package/src/index.ts +51 -0
  34. package/src/ipc.types.ts +73 -0
  35. package/src/logger.ts +20 -0
  36. package/src/migrations/model.ts +1 -0
  37. package/src/migrations/projects.ts +1 -0
  38. package/src/migrations/settings.ts +1 -0
  39. package/src/model.test.ts +214 -0
  40. package/src/model.ts +233 -0
  41. package/src/plugins/definitions.ts +472 -0
  42. package/src/plugins.ts +20 -0
  43. package/src/quickjs.ts +98 -0
  44. package/src/save-location.ts +42 -0
  45. package/src/subscription-errors.ts +87 -0
  46. package/src/supabase.ts +28 -0
  47. package/src/tests/helpers.ts +5 -0
  48. package/src/types.ts +3 -0
  49. package/src/utils.ts +3 -0
  50. package/src/validation.ts +16 -0
  51. package/src/variables.ts +27 -0
  52. package/src/wasm.d.ts +9 -0
  53. package/src/websocket.types.ts +186 -0
  54. package/tsconfig.json +13 -0
@@ -0,0 +1,214 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { savedFileMigrator, SavedFileV1, SavedFileV2, SavedFileV3 } from "./model";
3
+
4
+ describe("model", () => {
5
+ it("should migrate 1.0.0 to 2.0.0", async () => {
6
+ const v1: SavedFileV1 = {
7
+ version: "1.0.0",
8
+ canvas: {
9
+ blocks: [
10
+ {
11
+ origin: {
12
+ nodeId: "aaa",
13
+ pluginId: "aaa",
14
+ },
15
+ params: {
16
+ aaa: {
17
+ foo: "bar",
18
+ },
19
+ nodata: undefined,
20
+ },
21
+ type: "action",
22
+ uid: "aaa",
23
+ disabled: false,
24
+ },
25
+ {
26
+ origin: {
27
+ nodeId: "aaa",
28
+ pluginId: "aaa",
29
+ },
30
+ params: {
31
+ aaa: {
32
+ foo: "bar",
33
+ },
34
+ },
35
+ type: "event",
36
+ uid: "aaa",
37
+ },
38
+ ],
39
+ },
40
+ description: "aaa",
41
+ name: "aaa",
42
+ variables: [
43
+ {
44
+ description: "aaa",
45
+ id: "aaa",
46
+ name: "aaa",
47
+ value: "aaa",
48
+ },
49
+ ],
50
+ };
51
+
52
+ const v2 = await savedFileMigrator.migrate(v1, {
53
+ debug: true,
54
+ target: "2.0.0",
55
+ });
56
+
57
+ expect(v2).toStrictEqual({
58
+ canvas: {
59
+ blocks: [
60
+ {
61
+ disabled: false,
62
+ origin: {
63
+ nodeId: "aaa",
64
+ pluginId: "aaa",
65
+ },
66
+ params: {
67
+ aaa: {
68
+ foo: "bar",
69
+ },
70
+ nodata: undefined,
71
+ },
72
+ type: "action",
73
+ uid: "aaa",
74
+ },
75
+ ],
76
+ triggers: [
77
+ {
78
+ origin: {
79
+ nodeId: "aaa",
80
+ pluginId: "aaa",
81
+ },
82
+ params: {
83
+ aaa: {
84
+ foo: "bar",
85
+ },
86
+ },
87
+ type: "event",
88
+ uid: "aaa",
89
+ },
90
+ ],
91
+ },
92
+ description: "aaa",
93
+ name: "aaa",
94
+ variables: [
95
+ {
96
+ description: "aaa",
97
+ id: "aaa",
98
+ name: "aaa",
99
+ value: "aaa",
100
+ },
101
+ ],
102
+ version: "2.0.0",
103
+ } satisfies SavedFileV2);
104
+ });
105
+
106
+ it("should migrate 2.0.0 to 3.0.0", async () => {
107
+ const v2: SavedFileV2 = {
108
+ canvas: {
109
+ blocks: [
110
+ {
111
+ disabled: false,
112
+ origin: {
113
+ nodeId: "aaa",
114
+ pluginId: "aaa",
115
+ },
116
+ params: {
117
+ aaa: {
118
+ foo: "bar",
119
+ },
120
+ nodata: undefined,
121
+ },
122
+ type: "action",
123
+ uid: "aaa",
124
+ },
125
+ ],
126
+ triggers: [
127
+ {
128
+ origin: {
129
+ nodeId: "aaa",
130
+ pluginId: "aaa",
131
+ },
132
+ params: {
133
+ aaa: {
134
+ foo: "bar",
135
+ },
136
+ },
137
+ type: "event",
138
+ uid: "aaa",
139
+ },
140
+ ],
141
+ },
142
+ description: "aaa",
143
+ name: "aaa",
144
+ variables: [
145
+ {
146
+ description: "aaa",
147
+ id: "aaa",
148
+ name: "aaa",
149
+ value: "aaa",
150
+ },
151
+ ],
152
+ version: "2.0.0",
153
+ };
154
+
155
+ const v3 = await savedFileMigrator.migrate(v2, {
156
+ debug: true,
157
+ target: "3.0.0",
158
+ });
159
+
160
+ expect(v3).toStrictEqual({
161
+ canvas: {
162
+ blocks: [
163
+ {
164
+ disabled: false,
165
+ origin: {
166
+ nodeId: "aaa",
167
+ pluginId: "aaa",
168
+ },
169
+ params: {
170
+ aaa: {
171
+ editor: "editor",
172
+ value: {
173
+ foo: "bar",
174
+ },
175
+ },
176
+ nodata: {
177
+ editor: "editor",
178
+ value: undefined,
179
+ },
180
+ },
181
+ type: "action",
182
+ uid: "aaa",
183
+ },
184
+ ],
185
+ triggers: [
186
+ {
187
+ origin: {
188
+ nodeId: "aaa",
189
+ pluginId: "aaa",
190
+ },
191
+ params: {
192
+ aaa: {
193
+ foo: "bar",
194
+ },
195
+ },
196
+ type: "event",
197
+ uid: "aaa",
198
+ },
199
+ ],
200
+ },
201
+ description: "aaa",
202
+ name: "aaa",
203
+ variables: [
204
+ {
205
+ description: "aaa",
206
+ id: "aaa",
207
+ name: "aaa",
208
+ value: "aaa",
209
+ },
210
+ ],
211
+ version: "3.0.0",
212
+ } satisfies SavedFileV3);
213
+ });
214
+ });
package/src/model.ts ADDED
@@ -0,0 +1,233 @@
1
+ import { Variable } from "./variables";
2
+ import { WithId } from "./utils";
3
+ import { SaveLocation } from "./save-location";
4
+ import type { Simplify } from "type-fest";
5
+ import {
6
+ any,
7
+ array,
8
+ boolean,
9
+ custom,
10
+ description,
11
+ GenericSchema,
12
+ InferOutput,
13
+ lazy,
14
+ literal,
15
+ object,
16
+ optional,
17
+ pipe,
18
+ record,
19
+ string,
20
+ union,
21
+ unknown,
22
+ variant,
23
+ } from "valibot";
24
+
25
+ export type NodeId = string;
26
+
27
+ export type Position = {
28
+ x: number;
29
+ y: number;
30
+ };
31
+
32
+ export const OriginValidator = object({
33
+ pluginId: string(),
34
+ nodeId: string(),
35
+ });
36
+
37
+ export type Origin = InferOutput<typeof OriginValidator>;
38
+
39
+ const BlockActionValidatorV1 = object({
40
+ type: literal("action"),
41
+ uid: string(),
42
+ disabled: optional(boolean()),
43
+ params: record(string(), any()),
44
+ origin: OriginValidator,
45
+ });
46
+
47
+ export const EditorParamValidatorV3 = union([literal("simple"), literal("editor")]);
48
+ export type EditorParam = InferOutput<typeof EditorParamValidatorV3>;
49
+ const BlockActionValidatorV3 = object({
50
+ type: literal("action"),
51
+ uid: string(),
52
+ name: pipe(optional(string()), description("A custom name provided by the user")),
53
+ disabled: optional(boolean()),
54
+ params: record(
55
+ string(),
56
+ object({
57
+ editor: EditorParamValidatorV3,
58
+ value: unknown(),
59
+ }),
60
+ ),
61
+ origin: OriginValidator,
62
+ });
63
+
64
+ export type BlockCondition = {
65
+ type: "condition";
66
+ uid: string;
67
+ origin: Origin;
68
+ params: Record<string, any>;
69
+ branchTrue: Array<Block>;
70
+ branchFalse: Array<Block>;
71
+ };
72
+
73
+ const BlockConditionValidator: GenericSchema<BlockCondition> = object({
74
+ type: literal("condition"),
75
+ uid: string(),
76
+ origin: OriginValidator,
77
+ params: record(string(), any()),
78
+ branchTrue: lazy(() => array(BlockValidator)),
79
+ branchFalse: lazy(() => array(BlockValidator)),
80
+ });
81
+
82
+ export type BlockLoop = {
83
+ type: "loop";
84
+ uid: string;
85
+ origin: Origin;
86
+ params: Record<string, any>;
87
+ children: Array<Block>;
88
+ };
89
+ const BlockLoopValidator: GenericSchema<BlockLoop> = object({
90
+ type: literal("loop"),
91
+ uid: string(),
92
+ origin: OriginValidator,
93
+ params: record(string(), any()),
94
+ children: lazy(() => array(BlockValidator)),
95
+ });
96
+
97
+ const BlockEventValidator = object({
98
+ type: literal("event"),
99
+ uid: string(),
100
+ origin: OriginValidator,
101
+ params: record(string(), any()),
102
+ });
103
+
104
+ const BlockCommentValidator = object({
105
+ type: literal("comment"),
106
+ uid: string(),
107
+ origin: OriginValidator,
108
+ comment: string(),
109
+ });
110
+
111
+ const BlockValidatorV1 = variant("type", [
112
+ BlockActionValidatorV1,
113
+ // BlockConditionValidator,
114
+ BlockEventValidator,
115
+ // BlockLoopValidator,
116
+ // BlockCommentValidator
117
+ ]);
118
+
119
+ const BlockValidatorV2 = variant("type", [
120
+ BlockActionValidatorV1,
121
+ // BlockConditionValidator,
122
+ // BlockEventValidator,
123
+ // BlockLoopValidator,
124
+ // BlockCommentValidator
125
+ ]);
126
+
127
+ const BlockValidatorV3 = variant("type", [
128
+ BlockActionValidatorV3,
129
+ // BlockConditionValidator,
130
+ // BlockEventValidator,
131
+ // BlockLoopValidator,
132
+ // BlockCommentValidator
133
+ ]);
134
+
135
+ const BlockValidator = BlockValidatorV3;
136
+
137
+ export type BlockAction = Simplify<InferOutput<typeof BlockActionValidatorV3>>;
138
+ export type BlockEvent = InferOutput<typeof BlockEventValidator>;
139
+ export type BlockComment = InferOutput<typeof BlockCommentValidator>;
140
+
141
+ export type Block = InferOutput<typeof BlockValidatorV3>;
142
+
143
+ const CanvasValidatorV1 = object({
144
+ blocks: array(BlockValidatorV1),
145
+ });
146
+
147
+ const CanvasValidatorV2 = object({
148
+ blocks: array(BlockValidatorV2),
149
+ triggers: array(BlockEventValidator),
150
+ });
151
+
152
+ const CanvasValidatorV3 = object({
153
+ blocks: array(BlockValidatorV3),
154
+ triggers: array(BlockEventValidator),
155
+ });
156
+
157
+ export const VariableValidatorV1 = custom<Variable>(() => true);
158
+
159
+ export const SavedFileValidatorV1 = object({
160
+ version: literal("1.0.0"),
161
+ name: string(),
162
+ description: string(),
163
+ canvas: CanvasValidatorV1,
164
+ variables: array(VariableValidatorV1),
165
+ });
166
+
167
+ export const SavedFileValidatorV2 = object({
168
+ version: literal("2.0.0"),
169
+ name: string(),
170
+ description: string(),
171
+ canvas: CanvasValidatorV2,
172
+ variables: array(VariableValidatorV1),
173
+ });
174
+
175
+ export const SavedFileValidatorV3 = object({
176
+ version: literal("3.0.0"),
177
+ name: string(),
178
+ description: string(),
179
+ canvas: CanvasValidatorV3,
180
+ variables: array(VariableValidatorV1),
181
+ });
182
+
183
+ export const SavedFileDefaultValidator = object({
184
+ version: literal("4.0.0"),
185
+ type: literal("default"),
186
+ name: string(),
187
+ description: string(),
188
+ canvas: CanvasValidatorV3,
189
+ variables: array(VariableValidatorV1),
190
+ });
191
+
192
+ export const SavedFileSimpleValidator = object({
193
+ version: literal("4.0.0"),
194
+ type: literal("simple"),
195
+ name: string(),
196
+ description: string(),
197
+ source: object({
198
+ type: union([literal("c3-html"), literal("c3-nwjs"), literal("godot"), literal("html")]),
199
+ path: string(),
200
+ }),
201
+ packaging: object({
202
+ enabled: boolean(),
203
+ }),
204
+ publishing: object({
205
+ steam: object({ enabled: boolean(), appId: optional(string()) }),
206
+ itch: object({ enabled: boolean(), project: optional(string()) }),
207
+ poki: object({ enabled: boolean(), gameId: optional(string()) }),
208
+ }),
209
+ });
210
+
211
+ export type SavedFileDefault = InferOutput<typeof SavedFileDefaultValidator>;
212
+ export type SavedFileSimple = InferOutput<typeof SavedFileSimpleValidator>;
213
+ export const SavedFileValidatorV4 = union([SavedFileDefaultValidator, SavedFileSimpleValidator]);
214
+
215
+ export type SavedFileV1 = InferOutput<typeof SavedFileValidatorV1>;
216
+ export type SavedFileV2 = InferOutput<typeof SavedFileValidatorV2>;
217
+ export type SavedFileV3 = InferOutput<typeof SavedFileValidatorV3>;
218
+ export type SavedFileV4 = InferOutput<typeof SavedFileValidatorV4>;
219
+ export type SavedFile = SavedFileV4;
220
+ export const SavedFileValidator = SavedFileValidatorV4;
221
+
222
+ export type Preset = SavedFile;
223
+ export type PresetResult = { data: SavedFile; hightlight?: boolean; disabled?: boolean };
224
+ export type PresetFn = () => Promise<PresetResult>;
225
+
226
+ export type Steps = Record<
227
+ string,
228
+ {
229
+ outputs: Record<string, unknown>;
230
+ }
231
+ >;
232
+
233
+ export type EnhancedFile<T extends SavedFile = SavedFile> = WithId<SaveLocation> & { content: T };