@powerhousedao/academy 5.0.0-staging.8 → 5.0.1-staging.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.
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +404 -0
- package/README.md +3 -3
- package/babel.config.js +1 -1
- package/blog/BeyondCommunication-ABlueprintForDevelopment.md +25 -24
- package/blog/TheChallengeOfChange.md +21 -21
- package/docs/academy/01-GetStarted/00-ExploreDemoPackage.mdx +67 -30
- package/docs/academy/01-GetStarted/01-CreateNewPowerhouseProject.md +38 -21
- package/docs/academy/01-GetStarted/02-DefineToDoListDocumentModel.md +24 -19
- package/docs/academy/01-GetStarted/03-ImplementOperationReducers.md +44 -41
- package/docs/academy/01-GetStarted/04-BuildToDoListEditor.md +10 -10
- package/docs/academy/01-GetStarted/05-VetraStudio.md +164 -0
- package/docs/academy/01-GetStarted/06-ReactorMCP.md +58 -0
- package/docs/academy/01-GetStarted/home.mdx +185 -90
- package/docs/academy/01-GetStarted/images/Modules.png +0 -0
- package/docs/academy/01-GetStarted/images/VetraStudioDrive.png +0 -0
- package/docs/academy/01-GetStarted/styles.module.css +5 -5
- package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/01-Prerequisites.md +46 -18
- package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/02-StandardDocumentModelWorkflow.md +118 -68
- package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/03-BuilderTools.md +75 -33
- package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/_category_.json +6 -6
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/01-WhatIsADocumentModel.md +30 -21
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/02-SpecifyTheStateSchema.md +41 -37
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/03-SpecifyDocumentOperations.md +29 -25
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/04-UseTheDocumentModelGenerator.md +36 -37
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/05-ImplementDocumentReducers.md +128 -109
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/06-ImplementDocumentModelTests.md +95 -86
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/07-ExampleToDoListRepository.md +7 -9
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/_category_.json +6 -6
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/01-BuildingDocumentEditors.md +65 -47
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/02-ConfiguringDrives.md +77 -62
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/03-BuildingADriveExplorer.md +360 -349
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/00-DocumentToolbar.mdx +16 -10
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/01-OperationHistory.md +10 -7
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/02-RevisionHistoryTimeline.md +25 -17
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/_category_.json +6 -6
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/07-Authorization/01-RenownAuthenticationFlow.md +14 -7
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/07-Authorization/02-Authorization.md +0 -1
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/07-Authorization/_category_.json +5 -5
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/_category_.json +1 -1
- package/docs/academy/02-MasteryTrack/04-WorkWithData/01-GraphQLAtPowerhouse.md +45 -33
- package/docs/academy/02-MasteryTrack/04-WorkWithData/02-UsingTheAPI.mdx +61 -18
- package/docs/academy/02-MasteryTrack/04-WorkWithData/03-UsingSubgraphs.md +50 -54
- package/docs/academy/02-MasteryTrack/04-WorkWithData/04-analytics-processor.md +126 -110
- package/docs/academy/02-MasteryTrack/04-WorkWithData/05-RelationalDbProcessor.md +75 -45
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/GraphQL References/QueryingADocumentWithGraphQL.md +23 -21
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/best-practices.md +9 -9
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/graphql/index.md +11 -23
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/graphql/integration.md +25 -9
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/intro.md +10 -10
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/typescript/benchmarks.md +1 -1
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/typescript/index.md +16 -11
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/typescript/memory.md +6 -5
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/typescript/schema.md +2 -2
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/typescript/utilities.md +7 -5
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/use-cases/maker.md +32 -58
- package/docs/academy/02-MasteryTrack/04-WorkWithData/06-Analytics Engine/use-cases/processors.md +1 -1
- package/docs/academy/02-MasteryTrack/04-WorkWithData/07-drive-analytics.md +105 -71
- package/docs/academy/02-MasteryTrack/04-WorkWithData/_ARCHIVE-AnalyticsProcessorTutorial/_01-SetupBuilderEnvironment.md +22 -0
- package/docs/academy/02-MasteryTrack/04-WorkWithData/_ARCHIVE-AnalyticsProcessorTutorial/_02-CreateNewPowerhouseProject.md +9 -8
- package/docs/academy/02-MasteryTrack/04-WorkWithData/_ARCHIVE-AnalyticsProcessorTutorial/_03-GenerateAnAnalyticsProcessor.md +28 -32
- package/docs/academy/02-MasteryTrack/04-WorkWithData/_ARCHIVE-AnalyticsProcessorTutorial/_04-UpdateAnalyticsProcessor.md +25 -26
- package/docs/academy/02-MasteryTrack/04-WorkWithData/_ARCHIVE-AnalyticsProcessorTutorial/_category_.json +1 -1
- package/docs/academy/02-MasteryTrack/04-WorkWithData/_category_.json +7 -7
- package/docs/academy/02-MasteryTrack/05-Launch/01-IntroductionToPackages.md +3 -4
- package/docs/academy/02-MasteryTrack/05-Launch/02-PublishYourProject.md +69 -45
- package/docs/academy/02-MasteryTrack/05-Launch/03-SetupEnvironment.md +70 -40
- package/docs/academy/02-MasteryTrack/05-Launch/04-ConfigureEnvironment.md +1 -0
- package/docs/academy/02-MasteryTrack/05-Launch/_category_.json +7 -7
- package/docs/academy/02-MasteryTrack/_category_.json +6 -6
- package/docs/academy/03-ExampleUsecases/Chatroom/02-CreateNewPowerhouseProject.md +5 -3
- package/docs/academy/03-ExampleUsecases/Chatroom/03-DefineChatroomDocumentModel.md +38 -37
- package/docs/academy/03-ExampleUsecases/Chatroom/04-ImplementOperationReducers.md +45 -41
- package/docs/academy/03-ExampleUsecases/Chatroom/05-ImplementChatroomEditor.md +14 -14
- package/docs/academy/03-ExampleUsecases/Chatroom/06-LaunchALocalReactor.md +6 -6
- package/docs/academy/03-ExampleUsecases/Chatroom/_category_.json +1 -1
- package/docs/academy/04-APIReferences/00-PowerhouseCLI.md +104 -43
- package/docs/academy/04-APIReferences/01-ReactHooks.md +177 -129
- package/docs/academy/04-APIReferences/04-RelationalDatabase.md +121 -113
- package/docs/academy/04-APIReferences/05-PHDocumentMigrationGuide.md +48 -41
- package/docs/academy/04-APIReferences/_category_.json +6 -6
- package/docs/academy/05-Architecture/00-PowerhouseArchitecture.md +1 -2
- package/docs/academy/05-Architecture/01-WorkingWithTheReactor.md +11 -8
- package/docs/academy/05-Architecture/05-DocumentModelTheory/_category_.json +1 -1
- package/docs/academy/05-Architecture/_category_.json +6 -6
- package/docs/academy/06-ComponentLibrary/00-DocumentEngineering.md +25 -23
- package/docs/academy/06-ComponentLibrary/02-CreateCustomScalars.md +105 -93
- package/docs/academy/06-ComponentLibrary/03-IntegrateIntoAReactComponent.md +1 -0
- package/docs/academy/06-ComponentLibrary/_category_.json +7 -7
- package/docs/academy/07-Cookbook.md +268 -35
- package/docs/academy/08-Glossary.md +7 -1
- package/docs/bookofpowerhouse/01-Overview.md +2 -2
- package/docs/bookofpowerhouse/02-GeneralFrameworkAndPhilosophy.md +1 -7
- package/docs/bookofpowerhouse/03-PowerhouseSoftwareArchitecture.md +10 -7
- package/docs/bookofpowerhouse/04-DevelopmentApproaches.md +10 -4
- package/docs/bookofpowerhouse/05-SNOsandANewModelForOSSandPublicGoods.md +23 -30
- package/docs/bookofpowerhouse/06-SNOsInActionAndPlatformEconomies.md +0 -7
- package/docusaurus.config.ts +64 -66
- package/package.json +9 -7
- package/scripts/generate-combined-cli-docs.ts +43 -13
- package/sidebars.ts +2 -0
- package/src/components/HomepageFeatures/index.tsx +171 -78
- package/src/components/HomepageFeatures/styles.module.css +1 -2
- package/src/css/custom.css +89 -89
- package/src/pages/_archive-homepage.tsx +17 -16
- package/src/theme/DocCardList/index.tsx +9 -8
- package/static.json +6 -6
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -14,48 +14,60 @@ Create a new TypeScript file in `src/scalars/graphql/` for your scalar. Use `Ema
|
|
|
14
14
|
**Example: Creating a `PhoneNumber.ts` scalar**
|
|
15
15
|
|
|
16
16
|
```typescript
|
|
17
|
-
import {
|
|
18
|
-
|
|
17
|
+
import {
|
|
18
|
+
GraphQLError,
|
|
19
|
+
GraphQLScalarType,
|
|
20
|
+
type GraphQLScalarTypeConfig,
|
|
21
|
+
Kind,
|
|
22
|
+
} from "graphql";
|
|
23
|
+
import { z } from "zod";
|
|
19
24
|
|
|
20
25
|
export interface ScalarType {
|
|
21
|
-
input: string
|
|
22
|
-
output: string
|
|
26
|
+
input: string;
|
|
27
|
+
output: string;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
export const type =
|
|
30
|
+
export const type = "string"; // TS type in string form
|
|
26
31
|
|
|
27
|
-
export const typedef =
|
|
32
|
+
export const typedef = "scalar PhoneNumber";
|
|
28
33
|
|
|
29
|
-
export const schema = z
|
|
34
|
+
export const schema = z
|
|
35
|
+
.string()
|
|
36
|
+
.regex(/^\+?[1-9]\d{1,14}$/, "Invalid phone number format");
|
|
30
37
|
|
|
31
|
-
export const stringSchema =
|
|
38
|
+
export const stringSchema =
|
|
39
|
+
'z.string().regex(/^\\+?[1-9]\\d{1,14}$/, "Invalid phone number format")';
|
|
32
40
|
|
|
33
41
|
const phoneValidation = (value: unknown): string => {
|
|
34
|
-
if (typeof value !==
|
|
35
|
-
throw new GraphQLError(`Value is not string: ${JSON.stringify(value)}`)
|
|
42
|
+
if (typeof value !== "string") {
|
|
43
|
+
throw new GraphQLError(`Value is not string: ${JSON.stringify(value)}`);
|
|
36
44
|
}
|
|
37
45
|
|
|
38
|
-
const result = schema.safeParse(value)
|
|
46
|
+
const result = schema.safeParse(value);
|
|
39
47
|
|
|
40
|
-
if (result.success) return result.data
|
|
41
|
-
throw new GraphQLError(result.error.message)
|
|
42
|
-
}
|
|
48
|
+
if (result.success) return result.data;
|
|
49
|
+
throw new GraphQLError(result.error.message);
|
|
50
|
+
};
|
|
43
51
|
|
|
44
52
|
export const config: GraphQLScalarTypeConfig<string, string> = {
|
|
45
|
-
name:
|
|
46
|
-
description:
|
|
53
|
+
name: "PhoneNumber",
|
|
54
|
+
description:
|
|
55
|
+
"A field whose value conforms to international phone number format.",
|
|
47
56
|
serialize: phoneValidation,
|
|
48
57
|
parseValue: phoneValidation,
|
|
49
58
|
parseLiteral: (value) => {
|
|
50
59
|
if (value.kind !== Kind.STRING) {
|
|
51
|
-
throw new GraphQLError(
|
|
60
|
+
throw new GraphQLError(
|
|
61
|
+
`Can only validate strings as phone numbers but got a: ${value.kind}`,
|
|
62
|
+
{ nodes: value },
|
|
63
|
+
);
|
|
52
64
|
}
|
|
53
65
|
|
|
54
|
-
return phoneValidation(value.value)
|
|
66
|
+
return phoneValidation(value.value);
|
|
55
67
|
},
|
|
56
|
-
}
|
|
68
|
+
};
|
|
57
69
|
|
|
58
|
-
export const scalar = new GraphQLScalarType(config)
|
|
70
|
+
export const scalar = new GraphQLScalarType(config);
|
|
59
71
|
```
|
|
60
72
|
|
|
61
73
|
### Key Components to Update:
|
|
@@ -79,11 +91,11 @@ Add your scalar to the namespace imports section (around line 2):
|
|
|
79
91
|
|
|
80
92
|
```typescript
|
|
81
93
|
// namespace imports -- DO NOT REMOVE OR EDIT THIS COMMENT
|
|
82
|
-
import * as Amount from
|
|
83
|
-
import * as AmountCrypto from
|
|
94
|
+
import * as Amount from "./Amount.js";
|
|
95
|
+
import * as AmountCrypto from "./AmountCrypto.js";
|
|
84
96
|
// ... other imports ...
|
|
85
|
-
import * as PhoneNumber from
|
|
86
|
-
import * as URLScalar from
|
|
97
|
+
import * as PhoneNumber from "./PhoneNumber.js"; // ADD THIS LINE
|
|
98
|
+
import * as URLScalar from "./URL.js";
|
|
87
99
|
```
|
|
88
100
|
|
|
89
101
|
### 2.2 Add Type Export
|
|
@@ -92,10 +104,10 @@ Add the type export (around line 22):
|
|
|
92
104
|
|
|
93
105
|
```typescript
|
|
94
106
|
// export types -- DO NOT REMOVE OR EDIT THIS COMMENT
|
|
95
|
-
export type { ScalarType as AmountScalarType } from
|
|
107
|
+
export type { ScalarType as AmountScalarType } from "./Amount.js";
|
|
96
108
|
// ... other type exports ...
|
|
97
|
-
export type { ScalarType as PhoneNumberScalarType } from
|
|
98
|
-
export type { ScalarType as URLScalarType } from
|
|
109
|
+
export type { ScalarType as PhoneNumberScalarType } from "./PhoneNumber.js"; // ADD THIS LINE
|
|
110
|
+
export type { ScalarType as URLScalarType } from "./URL.js";
|
|
99
111
|
```
|
|
100
112
|
|
|
101
113
|
### 2.3 Add to Export Object
|
|
@@ -109,7 +121,7 @@ export {
|
|
|
109
121
|
// ... other exports ...
|
|
110
122
|
PhoneNumber, // ADD THIS LINE
|
|
111
123
|
URLScalar,
|
|
112
|
-
}
|
|
124
|
+
};
|
|
113
125
|
```
|
|
114
126
|
|
|
115
127
|
### 2.4 Add to Custom Scalars
|
|
@@ -121,7 +133,7 @@ export const customScalars: Record<string, BasePHScalar<any>> = {
|
|
|
121
133
|
// ... other scalars ...
|
|
122
134
|
PhoneNumber, // ADD THIS LINE
|
|
123
135
|
URLScalar,
|
|
124
|
-
} as const
|
|
136
|
+
} as const;
|
|
125
137
|
```
|
|
126
138
|
|
|
127
139
|
#### 2.5 Add to Resolvers
|
|
@@ -135,7 +147,7 @@ export const resolvers = {
|
|
|
135
147
|
// ... other resolvers ...
|
|
136
148
|
PhoneNumber: PhoneNumber.scalar, // ADD THIS LINE
|
|
137
149
|
Amount: Amount.scalar,
|
|
138
|
-
}
|
|
150
|
+
};
|
|
139
151
|
```
|
|
140
152
|
|
|
141
153
|
### 2.6 Add to Type Definitions
|
|
@@ -149,7 +161,7 @@ export const typeDefs = [
|
|
|
149
161
|
// ... other typedefs ...
|
|
150
162
|
PhoneNumber.typedef, // ADD THIS LINE
|
|
151
163
|
Amount.typedef,
|
|
152
|
-
]
|
|
164
|
+
];
|
|
153
165
|
```
|
|
154
166
|
|
|
155
167
|
### 2.7 Add to Generator Type Definitions
|
|
@@ -163,7 +175,7 @@ export const generatorTypeDefs = {
|
|
|
163
175
|
// ... other entries ...
|
|
164
176
|
[PhoneNumber.config.name]: PhoneNumber.type, // ADD THIS LINE
|
|
165
177
|
[Amount.config.name]: Amount.type,
|
|
166
|
-
}
|
|
178
|
+
};
|
|
167
179
|
```
|
|
168
180
|
|
|
169
181
|
### 2.8 Add to Validation Schema
|
|
@@ -177,7 +189,7 @@ export const validationSchema = {
|
|
|
177
189
|
// ... other entries ...
|
|
178
190
|
[PhoneNumber.config.name]: PhoneNumber.stringSchema, // ADD THIS LINE
|
|
179
191
|
[Amount.config.name]: Amount.stringSchema,
|
|
180
|
-
}
|
|
192
|
+
};
|
|
181
193
|
```
|
|
182
194
|
|
|
183
195
|
## Step 3: Create Tests for Your Scalar
|
|
@@ -187,79 +199,79 @@ Every scalar must have comprehensive tests to ensure it works correctly. Create
|
|
|
187
199
|
**Example: Creating `PhoneNumber.test.ts`**
|
|
188
200
|
|
|
189
201
|
```typescript
|
|
190
|
-
import { Kind } from
|
|
191
|
-
import { scalar } from
|
|
202
|
+
import { Kind } from "graphql";
|
|
203
|
+
import { scalar } from "../PhoneNumber.js";
|
|
192
204
|
|
|
193
|
-
describe(
|
|
194
|
-
it(
|
|
195
|
-
const phoneNumber =
|
|
205
|
+
describe("PhoneNumber Scalar", () => {
|
|
206
|
+
it("should serialize a phone number", () => {
|
|
207
|
+
const phoneNumber = "+1234567890";
|
|
196
208
|
|
|
197
|
-
expect(scalar.serialize(phoneNumber)).toBe(phoneNumber)
|
|
198
|
-
})
|
|
209
|
+
expect(scalar.serialize(phoneNumber)).toBe(phoneNumber);
|
|
210
|
+
});
|
|
199
211
|
|
|
200
|
-
it(
|
|
201
|
-
const phoneNumber = 123
|
|
212
|
+
it("should throw an error if the value is not a string", () => {
|
|
213
|
+
const phoneNumber = 123;
|
|
202
214
|
|
|
203
|
-
expect(() => scalar.serialize(phoneNumber)).toThrow()
|
|
204
|
-
})
|
|
215
|
+
expect(() => scalar.serialize(phoneNumber)).toThrow();
|
|
216
|
+
});
|
|
205
217
|
|
|
206
|
-
it(
|
|
207
|
-
const phoneNumber =
|
|
218
|
+
it("should throw an error if the value is not a valid phone number", () => {
|
|
219
|
+
const phoneNumber = "invalid-phone";
|
|
208
220
|
|
|
209
|
-
expect(() => scalar.serialize(phoneNumber)).toThrow()
|
|
210
|
-
})
|
|
221
|
+
expect(() => scalar.serialize(phoneNumber)).toThrow();
|
|
222
|
+
});
|
|
211
223
|
|
|
212
|
-
it(
|
|
213
|
-
const phoneNumber =
|
|
224
|
+
it("should parse a valid phone number", () => {
|
|
225
|
+
const phoneNumber = "+1234567890";
|
|
214
226
|
|
|
215
|
-
expect(scalar.parseValue(phoneNumber)).toBe(phoneNumber)
|
|
216
|
-
})
|
|
227
|
+
expect(scalar.parseValue(phoneNumber)).toBe(phoneNumber);
|
|
228
|
+
});
|
|
217
229
|
|
|
218
|
-
it(
|
|
219
|
-
const phoneNumber =
|
|
230
|
+
it("should throw an error if parse a value that is not a valid phone number", () => {
|
|
231
|
+
const phoneNumber = "invalid-phone";
|
|
220
232
|
|
|
221
|
-
expect(() => scalar.parseValue(phoneNumber)).toThrow()
|
|
222
|
-
})
|
|
233
|
+
expect(() => scalar.parseValue(phoneNumber)).toThrow();
|
|
234
|
+
});
|
|
223
235
|
|
|
224
|
-
it(
|
|
225
|
-
const phoneNumber = 123
|
|
236
|
+
it("should throw an error if parse a value that is not a string", () => {
|
|
237
|
+
const phoneNumber = 123;
|
|
226
238
|
|
|
227
|
-
expect(() => scalar.parseValue(phoneNumber)).toThrow()
|
|
228
|
-
})
|
|
239
|
+
expect(() => scalar.parseValue(phoneNumber)).toThrow();
|
|
240
|
+
});
|
|
229
241
|
|
|
230
|
-
it(
|
|
231
|
-
const phoneNumber =
|
|
242
|
+
it("should parse a valid phone number from a literal", () => {
|
|
243
|
+
const phoneNumber = "+1234567890";
|
|
232
244
|
|
|
233
245
|
expect(
|
|
234
246
|
scalar.parseLiteral({
|
|
235
247
|
kind: Kind.STRING,
|
|
236
248
|
value: phoneNumber,
|
|
237
|
-
})
|
|
238
|
-
).toBe(phoneNumber)
|
|
239
|
-
})
|
|
249
|
+
}),
|
|
250
|
+
).toBe(phoneNumber);
|
|
251
|
+
});
|
|
240
252
|
|
|
241
|
-
it(
|
|
242
|
-
const phoneNumber =
|
|
253
|
+
it("should throw an error if parse a literal that is not a valid phone number", () => {
|
|
254
|
+
const phoneNumber = "invalid-phone";
|
|
243
255
|
|
|
244
256
|
expect(() =>
|
|
245
257
|
scalar.parseLiteral({
|
|
246
258
|
kind: Kind.STRING,
|
|
247
259
|
value: phoneNumber,
|
|
248
|
-
})
|
|
249
|
-
).toThrow()
|
|
250
|
-
})
|
|
260
|
+
}),
|
|
261
|
+
).toThrow();
|
|
262
|
+
});
|
|
251
263
|
|
|
252
|
-
it(
|
|
253
|
-
const phoneNumber =
|
|
264
|
+
it("should throw an error if parse a literal that is not a string", () => {
|
|
265
|
+
const phoneNumber = "+1234567890";
|
|
254
266
|
|
|
255
267
|
expect(() =>
|
|
256
268
|
scalar.parseLiteral({
|
|
257
269
|
kind: Kind.INT,
|
|
258
270
|
value: phoneNumber,
|
|
259
|
-
})
|
|
260
|
-
).toThrow()
|
|
261
|
-
})
|
|
262
|
-
})
|
|
271
|
+
}),
|
|
272
|
+
).toThrow();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
263
275
|
```
|
|
264
276
|
|
|
265
277
|
#### Required Test Cases
|
|
@@ -297,37 +309,37 @@ Your scalar tests should cover these essential scenarios:
|
|
|
297
309
|
|
|
298
310
|
```typescript
|
|
299
311
|
// Test empty string
|
|
300
|
-
expect(() => scalar.parseValue(
|
|
312
|
+
expect(() => scalar.parseValue("")).toThrow();
|
|
301
313
|
|
|
302
314
|
// Test too long/short values
|
|
303
|
-
expect(() => scalar.parseValue(
|
|
304
|
-
expect(() => scalar.parseValue(
|
|
315
|
+
expect(() => scalar.parseValue("123")).toThrow();
|
|
316
|
+
expect(() => scalar.parseValue("+" + "1".repeat(20))).toThrow();
|
|
305
317
|
|
|
306
318
|
// Test special characters
|
|
307
|
-
expect(() => scalar.parseValue(
|
|
319
|
+
expect(() => scalar.parseValue("+1-234-567-890")).not.toThrow();
|
|
308
320
|
```
|
|
309
321
|
|
|
310
322
|
**Number-based scalars:**
|
|
311
323
|
|
|
312
324
|
```typescript
|
|
313
325
|
// Test zero
|
|
314
|
-
expect(scalar.parseValue(0)).toBe(0)
|
|
326
|
+
expect(scalar.parseValue(0)).toBe(0);
|
|
315
327
|
|
|
316
328
|
// Test negative numbers
|
|
317
|
-
expect(() => scalar.parseValue(-1)).toThrow()
|
|
329
|
+
expect(() => scalar.parseValue(-1)).toThrow();
|
|
318
330
|
|
|
319
331
|
// Test decimal numbers
|
|
320
|
-
expect(scalar.parseValue(123.45)).toBe(123.45)
|
|
332
|
+
expect(scalar.parseValue(123.45)).toBe(123.45);
|
|
321
333
|
```
|
|
322
334
|
|
|
323
335
|
**Date-based scalars:**
|
|
324
336
|
|
|
325
337
|
```typescript
|
|
326
338
|
// Test valid ISO date
|
|
327
|
-
expect(scalar.parseValue(
|
|
339
|
+
expect(scalar.parseValue("2023-12-25T00:00:00Z")).toBe("2023-12-25T00:00:00Z");
|
|
328
340
|
|
|
329
341
|
// Test invalid date format
|
|
330
|
-
expect(() => scalar.parseValue(
|
|
342
|
+
expect(() => scalar.parseValue("25/12/2023")).toThrow();
|
|
331
343
|
```
|
|
332
344
|
|
|
333
345
|
## Step 4: Validate Your Implementation
|
|
@@ -346,22 +358,22 @@ Here are some common patterns for different types of scalars:
|
|
|
346
358
|
#### String-based Scalars
|
|
347
359
|
|
|
348
360
|
```typescript
|
|
349
|
-
export const type =
|
|
350
|
-
export const schema = z.string().min(1).max(100)
|
|
361
|
+
export const type = "string";
|
|
362
|
+
export const schema = z.string().min(1).max(100);
|
|
351
363
|
```
|
|
352
364
|
|
|
353
365
|
#### Number-based Scalars
|
|
354
366
|
|
|
355
367
|
```typescript
|
|
356
|
-
export const type =
|
|
357
|
-
export const schema = z.number().positive()
|
|
368
|
+
export const type = "number";
|
|
369
|
+
export const schema = z.number().positive();
|
|
358
370
|
```
|
|
359
371
|
|
|
360
372
|
#### Date-based Scalars
|
|
361
373
|
|
|
362
374
|
```typescript
|
|
363
|
-
export const type =
|
|
364
|
-
export const schema = z.string().datetime()
|
|
375
|
+
export const type = "string";
|
|
376
|
+
export const schema = z.string().datetime();
|
|
365
377
|
```
|
|
366
378
|
|
|
367
379
|
:::info
|
|
@@ -370,7 +382,7 @@ export const schema = z.string().datetime()
|
|
|
370
382
|
- **Open Source**: Please submit contributions as a pull request to the Powerhouse team.
|
|
371
383
|
- **UI is Optional but Helpful**: A design or UI for your scalar isn't required, but it helps reviewers understand its purpose.
|
|
372
384
|
- **Semantic Scalars**: Some scalars don't need a unique UI. For instance, `Title` and `Description` might both use a simple text input but serve a semantic role by adding specific meaning and validation to the schema.
|
|
373
|
-
:::
|
|
385
|
+
:::
|
|
374
386
|
|
|
375
387
|
### Tips
|
|
376
388
|
|
|
@@ -379,4 +391,4 @@ export const schema = z.string().datetime()
|
|
|
379
391
|
- Write clear, descriptive error messages
|
|
380
392
|
- Keep the `stringSchema` in sync with your `schema` definition
|
|
381
393
|
- Test edge cases in your validation function
|
|
382
|
-
- Update all required sections in `scalars.ts`
|
|
394
|
+
- Update all required sections in `scalars.ts`
|
|
@@ -80,6 +80,7 @@ export const EthereumAddress: React.FC<EthereumAddressProps> = ({ onChange }) =>
|
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
**Key Points:**
|
|
83
|
+
|
|
83
84
|
- Use the scalar's `.schema.safeParse(value)` for validation.
|
|
84
85
|
- Display error messages if validation fails.
|
|
85
86
|
- Call `onChange` with both the value and its validity.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
"label": "Component Library",
|
|
3
|
+
"position": 4,
|
|
4
|
+
"link": {
|
|
5
|
+
"type": "generated-index",
|
|
6
|
+
"description": "An overview of the components in the Powerhouse Component Library."
|
|
7
|
+
}
|
|
8
|
+
}
|