-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from getodk/features/engine/submission-serial…
…ization Initial engine support for submissions
- Loading branch information
Showing
63 changed files
with
2,419 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@getodk/xforms-engine': minor | ||
'@getodk/scenario': minor | ||
'@getodk/ui-solid': patch | ||
'@getodk/common': patch | ||
--- | ||
|
||
Initial engine support for preparing submissions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type AssertNull = (value: unknown) => asserts value is null; | ||
|
||
export const assertNull: AssertNull = (value) => { | ||
if (value !== null) { | ||
throw new Error('Not null'); | ||
} | ||
}; |
9 changes: 9 additions & 0 deletions
9
packages/common/src/lib/type-assertions/assertUnknownArray.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type UnknownArray = readonly unknown[]; | ||
|
||
type AssertUnknownArray = (value: unknown) => asserts value is UnknownArray; | ||
|
||
export const assertUnknownArray: AssertUnknownArray = (value) => { | ||
if (!Array.isArray(value)) { | ||
throw new Error('Not an array'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/common/src/test/assertions/vitest/AsyncAsymmetricTypedExpectExtension.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { SyncExpectationResult } from 'vitest'; | ||
import type { AssertIs } from '../../../../types/assertions/AssertIs.ts'; | ||
import { expandAsyncExpectExtensionResult } from './expandAsyncExpectExtensionResult.ts'; | ||
import type { ExpectExtensionMethod, SimpleAssertionResult } from './shared-extension-types.ts'; | ||
import { validatedExtensionMethod } from './validatedExtensionMethod.ts'; | ||
|
||
/** | ||
* Generalizes definition of a Vitest `expect` API extension where the assertion | ||
* expects differing types for its `actual` and `expected` parameters, and: | ||
* | ||
* - Automatically perfoms runtime validation of those parameters, helping to | ||
* ensure that the extensions' static types are consistent with the runtime | ||
* values passed in a given test's assertions | ||
* | ||
* - Expands simplified assertion result types to the full interface expected by | ||
* Vitest | ||
* | ||
* - Facilitates deriving and defining corresponding static types on the base | ||
* `expect` type | ||
*/ | ||
export class AsyncAsymmetricTypedExpectExtension< | ||
Actual = unknown, | ||
Expected = Actual, | ||
Result extends SimpleAssertionResult = SimpleAssertionResult, | ||
> { | ||
readonly extensionMethod: ExpectExtensionMethod<unknown, unknown, Promise<SyncExpectationResult>>; | ||
|
||
constructor( | ||
readonly validateActualArgument: AssertIs<Actual>, | ||
readonly validateExpectedArgument: AssertIs<Expected>, | ||
extensionMethod: ExpectExtensionMethod<Actual, Expected, Promise<Result>> | ||
) { | ||
const validatedMethod = validatedExtensionMethod( | ||
validateActualArgument, | ||
validateExpectedArgument, | ||
extensionMethod | ||
); | ||
|
||
this.extensionMethod = expandAsyncExpectExtensionResult(validatedMethod); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/common/src/test/assertions/vitest/expandAsyncExpectExtensionResult.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { SyncExpectationResult } from 'vitest'; | ||
import type { expandSimpleExpectExtensionResult } from './expandSimpleExpectExtensionResult.ts'; | ||
import { isErrorLike } from './isErrorLike.ts'; | ||
import type { ExpectExtensionMethod, SimpleAssertionResult } from './shared-extension-types.ts'; | ||
|
||
/** | ||
* Asynchronous counterpart to {@link expandSimpleExpectExtensionResult} | ||
*/ | ||
export const expandAsyncExpectExtensionResult = <Actual, Expected>( | ||
simpleMethod: ExpectExtensionMethod<Actual, Expected, Promise<SimpleAssertionResult>> | ||
): ExpectExtensionMethod<Actual, Expected, Promise<SyncExpectationResult>> => { | ||
return async (actual, expected) => { | ||
const simpleResult = await simpleMethod(actual, expected); | ||
|
||
const pass = simpleResult === true; | ||
|
||
if (pass) { | ||
return { | ||
pass, | ||
/** | ||
* @todo It was previously assumed that it would never occur that an | ||
* assertion would pass, and that Vitest would then produce a message | ||
* for that. In hindsight, it makes sense that this case occurs in | ||
* negated assertions (e.g. | ||
* `expect(...).not.toPassSomeCustomAssertion`). It seems | ||
* {@link SimpleAssertionResult} is not a good way to model the | ||
* generalization, and that we may want a more uniform `AssertionResult` | ||
* type which always includes both `pass` and `message` capabilities. | ||
* This is should probably be addressed before we merge the big JR port | ||
* PR, but is being temporarily put aside to focus on porting tests in | ||
* bulk in anticipation of a scope change/hopefully-temporary | ||
* interruption of momentum. | ||
*/ | ||
message: () => { | ||
throw new Error('Unsupported `SimpleAssertionResult` runtime value'); | ||
}, | ||
}; | ||
} | ||
|
||
let message: () => string; | ||
|
||
if (isErrorLike(simpleResult)) { | ||
message = () => simpleResult.message; | ||
} else { | ||
message = () => simpleResult; | ||
} | ||
|
||
return { | ||
pass, | ||
message, | ||
}; | ||
}; | ||
}; |
11 changes: 2 additions & 9 deletions
11
packages/common/src/test/assertions/vitest/expandSimpleExpectExtensionResult.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { ErrorLike, SimpleAssertionResult } from './shared-extension-types.ts'; | ||
|
||
export const isErrorLike = (result: SimpleAssertionResult): result is ErrorLike => { | ||
return typeof result === 'object' && typeof result.message === 'string'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.