@superblocksteam/util 2.0.162 → 2.0.163-next.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.
Files changed (109) hide show
  1. package/dist/api-files/api.d.mts +8 -0
  2. package/dist/api-files/api.d.mts.map +1 -0
  3. package/dist/api-files/api.mjs +262 -0
  4. package/dist/api-files/api.mjs.map +1 -0
  5. package/dist/api-files/constants.d.ts +6 -0
  6. package/dist/api-files/constants.d.ts.map +1 -0
  7. package/dist/api-files/constants.js +9 -0
  8. package/dist/api-files/constants.js.map +1 -0
  9. package/dist/api-files/index.d.ts +8 -0
  10. package/dist/api-files/index.d.ts.map +1 -0
  11. package/dist/api-files/index.js +18 -0
  12. package/dist/api-files/index.js.map +1 -0
  13. package/dist/api-files/types.d.ts +115 -0
  14. package/dist/api-files/types.d.ts.map +1 -0
  15. package/dist/api-files/types.js +14 -0
  16. package/dist/api-files/types.js.map +1 -0
  17. package/dist/component-configs.d.ts +6 -0
  18. package/dist/component-configs.d.ts.map +1 -0
  19. package/dist/component-configs.js +178 -0
  20. package/dist/component-configs.js.map +1 -0
  21. package/dist/constants.d.ts +18 -0
  22. package/dist/constants.d.ts.map +1 -0
  23. package/dist/constants.js +37 -0
  24. package/dist/constants.js.map +1 -0
  25. package/dist/data-types.d.ts +8 -0
  26. package/dist/data-types.d.ts.map +1 -0
  27. package/dist/data-types.js +22 -0
  28. package/dist/data-types.js.map +1 -0
  29. package/dist/events.d.ts +13 -0
  30. package/dist/events.d.ts.map +1 -0
  31. package/dist/events.js +17 -0
  32. package/dist/events.js.map +1 -0
  33. package/dist/file-uploader.d.ts +3 -0
  34. package/dist/file-uploader.d.ts.map +1 -0
  35. package/dist/file-uploader.js +41 -0
  36. package/dist/file-uploader.js.map +1 -0
  37. package/dist/file-uploader.test.d.ts +2 -0
  38. package/dist/file-uploader.test.d.ts.map +1 -0
  39. package/dist/file-uploader.test.js +43 -0
  40. package/dist/file-uploader.test.js.map +1 -0
  41. package/dist/generate-component-types.d.ts +3 -0
  42. package/dist/generate-component-types.d.ts.map +1 -0
  43. package/dist/generate-component-types.js +45 -0
  44. package/dist/generate-component-types.js.map +1 -0
  45. package/dist/identifiers.d.ts +9 -0
  46. package/dist/identifiers.d.ts.map +1 -0
  47. package/dist/identifiers.js +68 -0
  48. package/dist/identifiers.js.map +1 -0
  49. package/{src/index.ts → dist/index.d.ts} +1 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/localGitRepoState.d.ts +20 -0
  53. package/dist/localGitRepoState.d.ts.map +1 -0
  54. package/dist/localGitRepoState.js +3 -0
  55. package/dist/localGitRepoState.js.map +1 -0
  56. package/dist/login.d.ts +17 -0
  57. package/dist/login.d.ts.map +1 -0
  58. package/dist/login.js +74 -0
  59. package/dist/login.js.map +1 -0
  60. package/dist/mask-unix-signals.d.ts +28 -0
  61. package/dist/mask-unix-signals.d.ts.map +1 -0
  62. package/dist/mask-unix-signals.js +81 -0
  63. package/dist/mask-unix-signals.js.map +1 -0
  64. package/dist/resource-configs.d.ts +73 -0
  65. package/dist/resource-configs.d.ts.map +1 -0
  66. package/dist/resource-configs.js +224 -0
  67. package/dist/resource-configs.js.map +1 -0
  68. package/dist/token-manager.d.ts +22 -0
  69. package/dist/token-manager.d.ts.map +1 -0
  70. package/dist/token-manager.js +3 -0
  71. package/dist/token-manager.js.map +1 -0
  72. package/dist/types.d.ts +105 -0
  73. package/dist/types.d.ts.map +1 -0
  74. package/dist/types.js +3 -0
  75. package/dist/types.js.map +1 -0
  76. package/dist/unreachable.d.ts +2 -0
  77. package/dist/unreachable.d.ts.map +1 -0
  78. package/dist/unreachable.js +7 -0
  79. package/dist/unreachable.js.map +1 -0
  80. package/dist/validation.d.ts +5 -0
  81. package/dist/validation.d.ts.map +1 -0
  82. package/dist/validation.js +152 -0
  83. package/dist/validation.js.map +1 -0
  84. package/package.json +5 -2
  85. package/eslint.config.mjs +0 -67
  86. package/lint-staged.config.mjs +0 -6
  87. package/src/api-files/api.mts +0 -506
  88. package/src/api-files/constants.ts +0 -6
  89. package/src/api-files/index.ts +0 -22
  90. package/src/api-files/types.ts +0 -131
  91. package/src/component-configs.ts +0 -163
  92. package/src/constants.ts +0 -34
  93. package/src/data-types.ts +0 -25
  94. package/src/events.ts +0 -12
  95. package/src/file-uploader.test.ts +0 -69
  96. package/src/file-uploader.ts +0 -42
  97. package/src/generate-component-types.ts +0 -53
  98. package/src/identifiers.ts +0 -70
  99. package/src/localGitRepoState.ts +0 -20
  100. package/src/login.ts +0 -82
  101. package/src/mask-unix-signals.ts +0 -86
  102. package/src/resource-configs.ts +0 -356
  103. package/src/token-manager.ts +0 -26
  104. package/src/types.ts +0 -138
  105. package/src/unreachable.ts +0 -5
  106. package/src/validation.ts +0 -155
  107. package/tsconfig.json +0 -21
  108. package/turbo.json +0 -9
  109. package/vitest.config.ts +0 -7
@@ -1,356 +0,0 @@
1
- import path from "path";
2
-
3
- import fs from "fs-extra";
4
-
5
- import {
6
- DEV_ENVIRONMENT_CONFIG_PATH,
7
- RESOURCE_CONFIG_PATH,
8
- } from "./constants.js";
9
-
10
- type SuperblocksMetadata = {
11
- cliVersion: string;
12
- };
13
-
14
- // Resource type is the type of the resource in the Superblocks platform
15
- export type SuperblocksResourceType = "APPLICATION" | "BACKEND";
16
-
17
- // Resource-specific config
18
- export type SuperblocksConfigType =
19
- | "APPLICATION"
20
- | "APPLICATION_V2"
21
- | "BACKEND";
22
-
23
- export type VersionedResourceConfig = {
24
- location: string;
25
- resourceType: SuperblocksResourceType;
26
- };
27
-
28
- export type SuperblocksResourceConfigMetadata = {
29
- fileVersion?: string;
30
- };
31
-
32
- export type SuperblocksResourceConfig = {
33
- id: string;
34
- configType: SuperblocksConfigType;
35
- metadata?: SuperblocksResourceConfigMetadata;
36
- };
37
-
38
- export type SuperblocksBackendConfig = SuperblocksResourceConfig &
39
- SourceFilesContanier & {
40
- configType: "BACKEND";
41
- };
42
-
43
- export type SuperblocksApplicationConfig = SuperblocksResourceConfig & {
44
- configType: "APPLICATION";
45
- defaultPageId?: string;
46
- // @deprecated use pageApis appApis for new format
47
- apis?: Record<string, string>; // used for pre-0.2.0 format
48
- appApis?: Record<string, ApiInfo>; // used for 0.2.0+ format
49
- pages?: Record<string, PageInfo>;
50
- };
51
-
52
- export type PageInfo = {
53
- id: string;
54
- name: string;
55
- // @deprecated use pageApis instead
56
- apis?: Record<string, string>; // used for pre-0.2.0 format
57
- pageApis?: Record<string, ApiInfo>; // used for 0.2.0+ format
58
- };
59
-
60
- type SourceFilesContanier = {
61
- sourceFiles?: string[];
62
- };
63
-
64
- export type ApiInfo = SourceFilesContanier & {
65
- name: string;
66
- };
67
-
68
- export type SuperblocksApplicationV2Config = SuperblocksResourceConfig & {
69
- configType: "APPLICATION_V2";
70
- };
71
-
72
- export type SuperblocksMonorepoConfig = {
73
- configType: "ROOT";
74
- resources: Record<string, VersionedResourceConfig>;
75
- metadata: SuperblocksMetadata;
76
- };
77
-
78
- export type SuperblocksConfig =
79
- | SuperblocksMonorepoConfig
80
- | SuperblocksApplicationConfig
81
- | SuperblocksApplicationV2Config
82
- | SuperblocksBackendConfig;
83
-
84
- type DevEnvironmentConfigType = "DEV_ENVIRONMENT";
85
-
86
- export type SuperblocksDevEnvironmentConfig = {
87
- configType: DevEnvironmentConfigType;
88
- branch?: string;
89
- };
90
-
91
- /**
92
- * Get the Superblocks dev environment config file from the current directory (and optionally) hierarchy
93
- * @param checkParentDir Whether to recursively check the parent directory for a Superblocks dev environment config file
94
- * @param pathPrefix The path prefix to use for the search
95
- * @returns The Superblocks dev environment config and the path to the config file
96
- */
97
- export async function getSuperblocksDevEnvironmentConfigJson(
98
- checkParentDir = false,
99
- pathPrefix = "",
100
- ): Promise<[SuperblocksDevEnvironmentConfig, string]> {
101
- const absolutePath = path.resolve(pathPrefix);
102
-
103
- let hasReachedFilesystemRoot = false;
104
- try {
105
- hasReachedFilesystemRoot = path.parse(absolutePath).root == absolutePath;
106
- } catch {
107
- throw new Error("Could not parse path " + absolutePath);
108
- }
109
-
110
- if (
111
- (pathPrefix && !fs.existsSync(absolutePath)) ||
112
- hasReachedFilesystemRoot
113
- ) {
114
- throw new Error(
115
- "No Superblocks config file found in current directory hierarchy " +
116
- pathPrefix,
117
- );
118
- }
119
-
120
- const attemptedPath = path.join(absolutePath, DEV_ENVIRONMENT_CONFIG_PATH);
121
- try {
122
- const devEnvironmentConfig = await fs.readJSON(attemptedPath);
123
- if (devEnvironmentConfig.configType !== "DEV_ENVIRONMENT") {
124
- throw new Error("Not the dev environment Superblocks config file");
125
- }
126
- return [
127
- devEnvironmentConfig as SuperblocksDevEnvironmentConfig,
128
- attemptedPath,
129
- ];
130
- } catch {
131
- if (!checkParentDir) {
132
- // no superblocks config file found
133
- throw new Error(
134
- "No Superblocks config file found in current directory " +
135
- attemptedPath,
136
- );
137
- }
138
- return getSuperblocksDevEnvironmentConfigJson(true, "../" + pathPrefix);
139
- }
140
- }
141
-
142
- /**
143
- * Get the Superblocks config file from the current directory (and optionally) hierarchy
144
- * @param checkParentDir Whether to recursively check the parent directory for a Superblocks config file
145
- */
146
- export async function getSuperblocksMonorepoConfigJson(
147
- checkParentDir = false,
148
- pathPrefix = "",
149
- ): Promise<[SuperblocksMonorepoConfig, string]> {
150
- const absolutePath = path.resolve(pathPrefix);
151
-
152
- let hasReachedFilesystemRoot = false;
153
- try {
154
- hasReachedFilesystemRoot = path.parse(absolutePath).root == absolutePath;
155
- } catch {
156
- throw new Error("Could not parse path " + absolutePath);
157
- }
158
-
159
- let superblocksConfig;
160
- if (
161
- (pathPrefix && !fs.existsSync(absolutePath)) ||
162
- hasReachedFilesystemRoot
163
- ) {
164
- throw new Error(
165
- "No Superblocks config file found in current directory hierarchy " +
166
- pathPrefix,
167
- );
168
- }
169
-
170
- const attemptedPath = path.join(absolutePath, RESOURCE_CONFIG_PATH);
171
- try {
172
- superblocksConfig = await fs.readJSON(attemptedPath);
173
- if (superblocksConfig.configType !== "ROOT") {
174
- throw new Error("Not the root Superblocks config file");
175
- }
176
- return [superblocksConfig as SuperblocksMonorepoConfig, attemptedPath];
177
- } catch {
178
- if (!checkParentDir) {
179
- // no superblocks config file found
180
- throw new Error(
181
- "No Superblocks config file found in current directory " +
182
- attemptedPath,
183
- );
184
- }
185
- return getSuperblocksMonorepoConfigJson(true, "../" + pathPrefix);
186
- }
187
- }
188
-
189
- export async function getSuperblocksApplicationConfigJson(
190
- applicationPath?: string,
191
- ): Promise<SuperblocksApplicationConfig> {
192
- let superblocksConfig;
193
- try {
194
- const configPath = applicationPath
195
- ? path.join(applicationPath, RESOURCE_CONFIG_PATH)
196
- : RESOURCE_CONFIG_PATH;
197
- superblocksConfig = await fs.readJSON(configPath);
198
- } catch {
199
- // no superblocks config file found
200
- throw new Error(
201
- "This command must be run within a Superblocks app directory.",
202
- );
203
- }
204
-
205
- if (superblocksConfig.configType !== "APPLICATION") {
206
- throw new Error(
207
- "Please execute this command within a Superblocks application directory.",
208
- );
209
- }
210
-
211
- return superblocksConfig as SuperblocksApplicationConfig;
212
- }
213
-
214
- export async function getSuperblocksApplicationConfigIfExists(
215
- applicationPath: string,
216
- ): Promise<SuperblocksApplicationConfig | undefined> {
217
- let superblocksConfig: SuperblocksApplicationConfig | undefined;
218
- try {
219
- const configPath = applicationPath
220
- ? path.join(applicationPath, RESOURCE_CONFIG_PATH)
221
- : RESOURCE_CONFIG_PATH;
222
- superblocksConfig = await fs.readJSON(configPath);
223
- } catch {
224
- // no superblocks config file found
225
- }
226
-
227
- if (superblocksConfig?.configType !== "APPLICATION") {
228
- return undefined;
229
- }
230
-
231
- return superblocksConfig as SuperblocksApplicationConfig;
232
- }
233
-
234
- export async function getSuperblocksApplicationV2ConfigJson(
235
- applicationPath?: string,
236
- ): Promise<SuperblocksApplicationV2Config> {
237
- let superblocksConfig;
238
- try {
239
- const configPath = applicationPath
240
- ? path.join(applicationPath, RESOURCE_CONFIG_PATH)
241
- : RESOURCE_CONFIG_PATH;
242
- superblocksConfig = await fs.readJSON(configPath);
243
- } catch {
244
- // no superblocks config file found
245
- throw new Error(
246
- "This command must be run within a Superblocks app directory.",
247
- );
248
- }
249
-
250
- if (superblocksConfig.configType !== "APPLICATION_V2") {
251
- throw new Error(
252
- "Please execute this command within a Superblocks application directory.",
253
- );
254
- }
255
-
256
- return superblocksConfig as SuperblocksApplicationV2Config;
257
- }
258
-
259
- export async function getSuperblocksBackendConfigIfExists(
260
- backendPath: string,
261
- ): Promise<SuperblocksBackendConfig | undefined> {
262
- let superblocksConfig: SuperblocksBackendConfig | undefined;
263
- try {
264
- const configPath = backendPath
265
- ? path.join(backendPath, RESOURCE_CONFIG_PATH)
266
- : RESOURCE_CONFIG_PATH;
267
- superblocksConfig = await fs.readJSON(configPath);
268
- } catch {
269
- // no superblocks config file found
270
- }
271
-
272
- if (superblocksConfig?.configType !== "BACKEND") {
273
- return undefined;
274
- }
275
-
276
- return superblocksConfig as SuperblocksBackendConfig;
277
- }
278
-
279
- async function getSuperblocksBackendConfigJson(): Promise<SuperblocksBackendConfig> {
280
- let superblocksConfig;
281
- try {
282
- superblocksConfig = await fs.readJSON(RESOURCE_CONFIG_PATH);
283
- } catch {
284
- // no superblocks config file found
285
- throw new Error(
286
- "This command must be run within a Superblocks backend resource (workflow/job) directory.",
287
- );
288
- }
289
-
290
- if (superblocksConfig.configType !== "BACKEND") {
291
- throw new Error(
292
- "Please execute this command within a Superblocks backend resource (workflow/job) directory.",
293
- );
294
- }
295
-
296
- return superblocksConfig as SuperblocksBackendConfig;
297
- }
298
-
299
- export async function getSuperblocksResourceConfigIfExists(): Promise<
300
- SuperblocksResourceConfig | undefined
301
- > {
302
- let config: SuperblocksResourceConfig | undefined;
303
- try {
304
- config = await getSuperblocksApplicationConfigJson();
305
- } catch {
306
- // Noop
307
- }
308
- try {
309
- config = await getSuperblocksApplicationV2ConfigJson();
310
- } catch {
311
- // Noop
312
- }
313
- try {
314
- config = await getSuperblocksBackendConfigJson();
315
- } catch {
316
- // Noop
317
- }
318
- return config;
319
- }
320
-
321
- export function getResourceIdFromUrl(
322
- resourceUrl: any,
323
- ): [string, SuperblocksResourceType] {
324
- const url = new URL(resourceUrl);
325
- if (url.pathname.startsWith("/code-mode")) {
326
- // find the first uuid in the url
327
- const tokens = url.pathname.split("/");
328
- const uuid = tokens.find((token) =>
329
- token.match(
330
- /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
331
- ),
332
- );
333
- if (!uuid) {
334
- throw new Error(`Failed to parse resource URL: ${resourceUrl}`);
335
- }
336
- return [uuid, "APPLICATION"];
337
- }
338
- if (url.pathname.startsWith("/applications")) {
339
- const tokens = url.pathname.split("/");
340
- if (tokens.length < 2) {
341
- throw new Error(`Failed to parse resource URL: ${resourceUrl}`);
342
- }
343
- if (tokens[2] === "edit") {
344
- return [tokens[3], "APPLICATION"];
345
- } else {
346
- return [tokens[2], "APPLICATION"];
347
- }
348
- } else if (
349
- url.pathname.startsWith("/workflows") ||
350
- url.pathname.startsWith("/scheduled_jobs")
351
- ) {
352
- return [url.pathname.split("/")[2], "BACKEND"];
353
- }
354
-
355
- throw new Error(`Failed to parse resource URL: ${resourceUrl}`);
356
- }
@@ -1,26 +0,0 @@
1
- import type { EventEmitter } from "node:events";
2
-
3
- export interface TokenUpdateEvent {
4
- token: string;
5
- }
6
-
7
- export interface ITokenManager extends EventEmitter {
8
- updateToken(newToken: string): void;
9
- /**
10
- * Returns the most recently set token, or `undefined` if `updateToken`
11
- * has never been called. Consumers that need to seed themselves at
12
- * construction time read this synchronously rather than waiting on the
13
- * next `tokenUpdated` event — the event stream stays as the refresh
14
- * channel and is not replayed for late subscribers.
15
- *
16
- * Closes the cold-start gap where a listener attached after a prior
17
- * emission would observe nothing (Node `EventEmitter` has no replay).
18
- */
19
- getCurrentToken(): string | undefined;
20
- on(event: "tokenUpdated", listener: (event: TokenUpdateEvent) => void): this;
21
- once(
22
- event: "tokenUpdated",
23
- listener: (event: TokenUpdateEvent) => void,
24
- ): this;
25
- off(event: "tokenUpdated", listener: (event: TokenUpdateEvent) => void): this;
26
- }
package/src/types.ts DELETED
@@ -1,138 +0,0 @@
1
- import type { UUID } from "node:crypto";
2
-
3
- import type { DataType } from "./data-types.js";
4
-
5
- interface PropertiesPanelDisplay<T extends DataType> {
6
- /**
7
- * Determines what form item type is shown in the Superblocks properties panel.
8
- *
9
- * Only booleans are allowed to use the "switch" control
10
- */
11
- controlType: T extends "boolean"
12
- ? "text" | "js-expr" | "switch"
13
- : "text" | "js-expr";
14
-
15
- /**
16
- * Determines form item label in the Superblocks properties panel.
17
- */
18
- label: string;
19
-
20
- /**
21
- * Placeholder text appears as gray text in the properties panel. This only applies
22
- * to text-like inputs.
23
- */
24
- placeholder?: string;
25
-
26
- /**
27
- * This shows up in the popover as a user types into the properties panel.
28
- * This is a documentation field that helps users understand what type of data is accepted
29
- * by this property. You should give a specific example, not a generic type
30
- *
31
- * @example {
32
- * label: "My Label",
33
- * value: "myValue"
34
- * }
35
- */
36
- exampleData?: string;
37
-
38
- /**
39
- * This shows up in the popover as a user types into the properties panel.
40
- * This is a documentation field that helps users understand what type of data is accepted
41
- * by this property. Typescript notation is recommended.
42
- *
43
- * @example "Array<{ label: string; value: string; }>"
44
- */
45
- expectedType?: string;
46
-
47
- /**
48
- * The default value should match the dataType of the property.
49
- */
50
- defaultValue?: T;
51
-
52
- /**
53
- * The default value to use when adding a property.
54
- */
55
- defaultOnAdd?: T;
56
- }
57
-
58
- interface PropertyForData<T extends DataType> {
59
- path: string;
60
- dataType: T;
61
-
62
- /**
63
- * The presence of this object determines whether or not this property
64
- * shows up in the Superblocks properties panel.
65
- **/
66
- propertiesPanelDisplay?: PropertiesPanelDisplay<T>;
67
-
68
- /**
69
- * A description of this property. This is used in the Superblocks properties panel
70
- * as well as in the custom component's autocomplete.
71
- **/
72
- description?: string;
73
-
74
- /**
75
- * By default, all your properties are readable from anywhere in Superblocks using dot notation
76
- * (e.g. `myComponent.myProperty`). If you want to hide a property from the outside world,
77
- * set this to true
78
- * @default false
79
- */
80
- isExternallyReadable?: boolean;
81
-
82
- /**
83
- * By default, all properties can have be used with Set Component Property and Reset Component to Default.
84
- * @default true
85
- **/
86
- isExternallySettable?: boolean;
87
- }
88
-
89
- export type Property =
90
- | PropertyForData<"string">
91
- | PropertyForData<"number">
92
- | PropertyForData<"boolean">
93
- | PropertyForData<"any">;
94
-
95
- export interface ComponentConfig {
96
- id: UUID;
97
-
98
- /**
99
- * @example: "myComponent"
100
- */
101
- name: string;
102
-
103
- /**
104
- * @example "My Component"
105
- */
106
- displayName: string;
107
-
108
- /**
109
- * @example "components/myComponent/component.tsx"
110
- */
111
- componentPath: string;
112
-
113
- properties: Array<
114
- // Note to devs: The reason we are duplicating the Property type above is that it produces a better
115
- // error message. The user will see 'is not assignable to type PropertyForData<"string"> | PropertyForData<"number">'
116
- // instead of seeing "is not assignable to type Property"
117
- | PropertyForData<"string">
118
- | PropertyForData<"number">
119
- | PropertyForData<"boolean">
120
- | PropertyForData<"any">
121
- >;
122
-
123
- /**
124
- * @example [{
125
- * label: "On Click",
126
- * path: "onClick",
127
- * }]
128
- */
129
- events: Array<{
130
- label: string;
131
- path: string;
132
- }>;
133
-
134
- gridDimensions?: {
135
- initialColumns: number;
136
- initialRows: number;
137
- };
138
- }
@@ -1,5 +0,0 @@
1
- export function unreachable(value: never, errMsg?: string): never {
2
- throw new TypeError(
3
- errMsg ?? "Encountered impossible value: " + JSON.stringify(value),
4
- );
5
- }
package/src/validation.ts DELETED
@@ -1,155 +0,0 @@
1
- import Ajv from "ajv";
2
- import type { Schema } from "ajv";
3
- import type { DataValidateFunction } from "ajv/dist/types";
4
- import betterAjvErrors from "better-ajv-errors";
5
-
6
- import { isReservedPropertyName, isValidIdentifier } from "./identifiers.js";
7
-
8
- const ajv = new Ajv();
9
-
10
- ajv.addKeyword({
11
- keyword: "stringFormat",
12
- compile: (schema: any) => {
13
- let validateFunc: DataValidateFunction;
14
- // schema is the value assigned to stringFormat in the schema
15
- if (schema === "identifier") {
16
- validateFunc = (data: any) => {
17
- if (typeof data != "string") return false;
18
- if (!isValidIdentifier(data)) {
19
- validateFunc.errors = [
20
- {
21
- keyword: "format",
22
- message:
23
- "must be a valid identifier starting with a-z or underscore and containing only a-z, 0-9, and underscores",
24
- },
25
- ];
26
- return false;
27
- }
28
- if (isReservedPropertyName(data)) {
29
- validateFunc.errors = [
30
- {
31
- keyword: "format",
32
- message: "must not match a reserved property path",
33
- },
34
- ];
35
- return false;
36
- }
37
- return true;
38
- };
39
- } else {
40
- throw new Error(`Unknown stringFormat: ${schema}`);
41
- }
42
- return validateFunc;
43
- },
44
- errors: true,
45
- });
46
-
47
- const componentSchema: Schema = {
48
- type: "object",
49
- properties: {
50
- id: { type: "string" },
51
- name: { type: "string" },
52
- displayName: { type: "string" },
53
- componentPath: { type: "string" },
54
- properties: {
55
- type: "array",
56
- items: {
57
- $ref: "#/definitions/Property",
58
- },
59
- },
60
- events: {
61
- type: "array",
62
- items: {
63
- $ref: "#/definitions/EventHandler",
64
- },
65
- },
66
- gridDimensions: {
67
- type: "object",
68
- properties: {
69
- initialColumns: { type: "number" },
70
- initialRows: { type: "number" },
71
- },
72
- additionalProperties: false,
73
- required: ["initialColumns", "initialRows"],
74
- },
75
- },
76
- required: [
77
- "id",
78
- "name",
79
- "displayName",
80
- "componentPath",
81
- "properties",
82
- "events",
83
- ],
84
- additionalProperties: false,
85
- definitions: {
86
- Property: {
87
- properties: {
88
- path: { $ref: "#/definitions/Identifier" },
89
- dataType: { enum: ["number", "boolean", "string", "any"] },
90
- propertiesPanelDisplay: {
91
- type: "object",
92
- properties: {
93
- label: { type: "string" },
94
- controlType: { enum: ["text", "js-expr", "switch"] },
95
- defaultValue: {
96
- oneOf: [
97
- {
98
- type: "string",
99
- },
100
- {
101
- type: "boolean",
102
- },
103
- {
104
- type: "number",
105
- },
106
- ],
107
- },
108
- placeholder: { type: "string" },
109
- exampleData: { type: "string" },
110
- expectedType: { type: "string" },
111
- },
112
- required: ["controlType", "label"],
113
- additionalProperties: false,
114
- },
115
- description: { type: "string" },
116
- isExternallySettable: { type: "boolean" },
117
- isExternallyReadable: { type: "boolean" },
118
- },
119
- type: "object",
120
- additionalProperties: false,
121
- required: ["path", "dataType"],
122
- },
123
- EventHandler: {
124
- properties: {
125
- label: { type: "string" },
126
- path: { $ref: "#/definitions/Identifier" },
127
- },
128
- type: "object",
129
- additionalProperties: false,
130
- required: ["label", "path"],
131
- },
132
- Identifier: {
133
- type: "string",
134
- stringFormat: "identifier",
135
- },
136
- },
137
- };
138
-
139
- const validate = ajv.compile(componentSchema);
140
-
141
- export function validateCustomComponents(data: any): {
142
- valid: boolean;
143
- message?: string;
144
- } {
145
- const valid = validate(data);
146
- if (!valid) {
147
- return {
148
- valid: false,
149
- message: betterAjvErrors(componentSchema, data, validate.errors as any, {
150
- indent: 2,
151
- }),
152
- };
153
- }
154
- return { valid: true };
155
- }
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "declaration": true,
4
- "module": "nodenext",
5
- "moduleDetection": "force",
6
- "moduleResolution": "nodenext",
7
- "isolatedModules": true,
8
- "outDir": "dist",
9
- "rootDir": "src",
10
- "strict": true,
11
- "composite": true,
12
- "target": "es2024",
13
- "lib": ["es2024", "ESNext.Array", "ESNext.Collection", "ESNext.Promise"],
14
-
15
- "sourceMap": true,
16
- "declarationMap": true,
17
- "esModuleInterop": true,
18
- "skipLibCheck": true
19
- },
20
- "include": ["src/**/*"]
21
- }